@cadraos/sdk 0.1.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.
@@ -0,0 +1,1904 @@
1
+ /**
2
+ * Retry utility with exponential backoff
3
+ */
4
+ /**
5
+ * Retry configuration
6
+ */
7
+ interface RetryConfig {
8
+ /** Maximum number of retry attempts (default: 3) */
9
+ maxRetries: number;
10
+ /** Base delay in milliseconds (default: 1000) */
11
+ baseDelayMs: number;
12
+ /** Maximum delay in milliseconds (default: 30000) */
13
+ maxDelayMs: number;
14
+ /** Jitter factor (0-1, default: 0.1) */
15
+ jitterFactor: number;
16
+ }
17
+
18
+ /**
19
+ * HTTP Client
20
+ *
21
+ * Handles all HTTP requests with authentication, retry logic, and error handling.
22
+ */
23
+
24
+ /**
25
+ * HTTP Client configuration
26
+ */
27
+ interface HttpClientConfig {
28
+ /** Base URL for API requests */
29
+ baseUrl: string;
30
+ /** API key for authentication */
31
+ apiKey?: string;
32
+ /** OAuth token for authentication */
33
+ token?: string;
34
+ /** Token provider callback (called before each request) */
35
+ tokenProvider?: () => Promise<string>;
36
+ /** Organization ID */
37
+ orgId: number;
38
+ /** Request timeout in milliseconds (default: 30000) */
39
+ timeout: number;
40
+ /** Retry configuration */
41
+ retry: RetryConfig;
42
+ /** Custom headers */
43
+ headers?: Record<string, string>;
44
+ }
45
+ /**
46
+ * Request options
47
+ */
48
+ interface RequestOptions {
49
+ /** HTTP method */
50
+ method: 'GET' | 'POST' | 'PATCH' | 'DELETE' | 'PUT';
51
+ /** Request path (appended to base URL) */
52
+ path: string;
53
+ /** Request body */
54
+ body?: unknown;
55
+ /** Query parameters */
56
+ query?: Record<string, string | number | boolean | undefined>;
57
+ /** Additional headers */
58
+ headers?: Record<string, string>;
59
+ /** Skip retry (for non-idempotent operations) */
60
+ skipRetry?: boolean;
61
+ /** Idempotency key */
62
+ idempotencyKey?: string;
63
+ }
64
+ /**
65
+ * HTTP Client class
66
+ */
67
+ declare class HttpClient {
68
+ private config;
69
+ private tokenRefreshAttempts;
70
+ private readonly maxTokenRefreshAttempts;
71
+ constructor(config: HttpClientConfig);
72
+ /**
73
+ * Get authorization header value
74
+ */
75
+ private getAuthHeader;
76
+ /**
77
+ * Build full URL with query parameters
78
+ */
79
+ private buildUrl;
80
+ /**
81
+ * Make an HTTP request
82
+ */
83
+ request<T>(options: RequestOptions): Promise<T>;
84
+ /**
85
+ * GET request
86
+ */
87
+ get<T>(path: string, query?: Record<string, string | number | boolean | undefined>): Promise<T>;
88
+ /**
89
+ * POST request
90
+ */
91
+ post<T>(path: string, body?: unknown, options?: {
92
+ idempotencyKey?: string;
93
+ skipRetry?: boolean;
94
+ }): Promise<T>;
95
+ /**
96
+ * PATCH request
97
+ */
98
+ patch<T>(path: string, body?: unknown, options?: {
99
+ idempotencyKey?: string;
100
+ }): Promise<T>;
101
+ /**
102
+ * DELETE request
103
+ */
104
+ delete<T>(path: string): Promise<T>;
105
+ /**
106
+ * Update configuration
107
+ */
108
+ updateConfig(config: Partial<HttpClientConfig>): void;
109
+ }
110
+
111
+ /**
112
+ * Common types shared across all resources
113
+ */
114
+ /**
115
+ * JSON Schema type for tool input/output schemas
116
+ */
117
+ type JSONSchema = {
118
+ type: string;
119
+ properties?: Record<string, JSONSchema>;
120
+ required?: string[];
121
+ items?: JSONSchema;
122
+ description?: string;
123
+ [key: string]: unknown;
124
+ };
125
+ /**
126
+ * Pagination options for list operations
127
+ */
128
+ interface ListOptions {
129
+ /** Maximum number of items to return (default: 20) */
130
+ limit?: number;
131
+ /** Number of items to skip (pagination offset) */
132
+ offset?: number;
133
+ /** Field to sort by (e.g., 'createdAt') */
134
+ sort?: string;
135
+ /** Sort order */
136
+ order?: 'asc' | 'desc';
137
+ }
138
+ /**
139
+ * Pagination metadata in list responses
140
+ */
141
+ interface PaginationInfo {
142
+ /** Total number of items */
143
+ total: number;
144
+ /** Number of items returned */
145
+ limit: number;
146
+ /** Number of items skipped */
147
+ offset: number;
148
+ /** Whether there are more items */
149
+ hasMore: boolean;
150
+ }
151
+ /**
152
+ * Paginated list response
153
+ */
154
+ interface PaginatedResponse<T> {
155
+ data: T[];
156
+ pagination: PaginationInfo;
157
+ }
158
+ /**
159
+ * Execute operation options
160
+ */
161
+ interface ExecuteOptions {
162
+ /** Maximum number of agent iterations */
163
+ maxIterations?: number;
164
+ /** Maximum tokens for the response */
165
+ maxTokens?: number;
166
+ /** Execution timeout in milliseconds */
167
+ timeout?: number;
168
+ /** Idempotency key for retry safety */
169
+ idempotencyKey?: string;
170
+ }
171
+ /**
172
+ * Execute input for agent/skill operations
173
+ */
174
+ interface ExecuteInput {
175
+ /** The task or prompt to execute */
176
+ task: string;
177
+ /** Additional context for the execution */
178
+ context?: Record<string, unknown>;
179
+ /** Execution options */
180
+ options?: ExecuteOptions;
181
+ }
182
+ /**
183
+ * Execution status
184
+ */
185
+ type ExecutionStatus = 'queued' | 'running' | 'completed' | 'failed' | 'cancelled';
186
+ /**
187
+ * Token usage information
188
+ */
189
+ interface TokenUsage {
190
+ /** Input tokens consumed */
191
+ input: number;
192
+ /** Output tokens generated */
193
+ output: number;
194
+ /** Total tokens */
195
+ total: number;
196
+ }
197
+
198
+ /**
199
+ * Agent types
200
+ */
201
+
202
+ /**
203
+ * Agent type
204
+ */
205
+ type AgentType = 'simple' | 'workflow' | 'orchestrator';
206
+ /**
207
+ * Agent status
208
+ */
209
+ type AgentStatus = 'active' | 'inactive' | 'draft';
210
+ /**
211
+ * Agent configuration
212
+ */
213
+ interface AgentConfig {
214
+ /** LLM model to use */
215
+ model?: string;
216
+ /** Temperature for generation */
217
+ temperature?: number;
218
+ /** Maximum iterations for agent loop */
219
+ maxIterations?: number;
220
+ /** System prompt for the agent */
221
+ systemPrompt?: string;
222
+ }
223
+ /**
224
+ * Agent resource
225
+ */
226
+ interface Agent {
227
+ /** Unique identifier */
228
+ uuid: string;
229
+ /** Agent name */
230
+ name: string;
231
+ /** Agent description */
232
+ description: string | null;
233
+ /** Agent type */
234
+ type: AgentType;
235
+ /** Agent status */
236
+ status: AgentStatus;
237
+ /** Creation timestamp */
238
+ createdAt: string;
239
+ /** Last update timestamp */
240
+ updatedAt: string;
241
+ /** Agent configuration (included in get, not list) */
242
+ config?: AgentConfig;
243
+ }
244
+ /**
245
+ * Agent list options
246
+ */
247
+ interface AgentListOptions extends ListOptions {
248
+ /** Filter by status */
249
+ status?: AgentStatus;
250
+ /** Filter by type */
251
+ type?: AgentType;
252
+ }
253
+ /**
254
+ * Execution log entry
255
+ */
256
+ interface ExecutionLog {
257
+ /** Unique identifier */
258
+ uuid: string;
259
+ /** Log type */
260
+ type: 'info' | 'think' | 'tool_call' | 'tool_result' | 'error' | 'system';
261
+ /** Log title/summary */
262
+ title: string;
263
+ /** Log content/details */
264
+ content?: string;
265
+ /** Additional metadata */
266
+ metadata?: Record<string, unknown>;
267
+ /** Timestamp */
268
+ timestamp: string;
269
+ /** Duration in milliseconds (if applicable) */
270
+ durationMs?: number;
271
+ }
272
+ /**
273
+ * Agent execution result
274
+ */
275
+ interface AgentExecution {
276
+ /** Execution ID */
277
+ uuid: string;
278
+ /** Agent ID */
279
+ agentUuid: string;
280
+ /** Execution status */
281
+ status: ExecutionStatus;
282
+ /** Input provided */
283
+ input: {
284
+ task: string;
285
+ context?: Record<string, unknown>;
286
+ };
287
+ /** Output result */
288
+ output?: string;
289
+ /** Error message if failed */
290
+ error?: string;
291
+ /** Execution logs */
292
+ logs: ExecutionLog[];
293
+ /** Token usage */
294
+ tokenUsage?: TokenUsage;
295
+ /** Cost in USD */
296
+ cost?: number;
297
+ /** Number of iterations */
298
+ iterations?: number;
299
+ /** When execution was queued */
300
+ queuedAt: string;
301
+ /** When execution started */
302
+ startedAt?: string;
303
+ /** When execution completed */
304
+ completedAt?: string;
305
+ /** Total duration in milliseconds */
306
+ durationMs?: number;
307
+ }
308
+ /**
309
+ * Agent update input
310
+ */
311
+ interface AgentUpdateInput {
312
+ /** New name */
313
+ name?: string;
314
+ /** New description */
315
+ description?: string;
316
+ /** New status */
317
+ status?: AgentStatus;
318
+ }
319
+ /**
320
+ * Agent config update input
321
+ */
322
+ interface AgentConfigUpdateInput {
323
+ /** LLM model */
324
+ model?: string;
325
+ /** Temperature */
326
+ temperature?: number;
327
+ /** Max iterations */
328
+ maxIterations?: number;
329
+ /** System prompt */
330
+ systemPrompt?: string;
331
+ }
332
+ /**
333
+ * Execute response (async)
334
+ */
335
+ interface ExecuteResponse {
336
+ /** Execution ID */
337
+ executionId: string;
338
+ /** Initial status */
339
+ status: ExecutionStatus;
340
+ }
341
+
342
+ /**
343
+ * Skill types
344
+ */
345
+
346
+ /**
347
+ * Skill tool reference
348
+ */
349
+ interface SkillTool {
350
+ /** Tool UUID */
351
+ uuid: string;
352
+ /** Tool name */
353
+ name: string;
354
+ /** Tool description */
355
+ description: string;
356
+ }
357
+ /**
358
+ * Skill variable definition
359
+ */
360
+ interface SkillVariable {
361
+ /** Variable name */
362
+ name: string;
363
+ /** Variable type */
364
+ type: 'string' | 'number' | 'boolean' | 'object';
365
+ /** Variable description */
366
+ description: string;
367
+ /** Whether the variable is required */
368
+ required: boolean;
369
+ /** Default value */
370
+ default?: unknown;
371
+ }
372
+ /**
373
+ * Skill resource (list view)
374
+ */
375
+ interface Skill {
376
+ /** Unique identifier */
377
+ uuid: string;
378
+ /** Skill name */
379
+ name: string;
380
+ /** Skill description */
381
+ description: string | null;
382
+ /** Category */
383
+ category: string | null;
384
+ /** Tags */
385
+ tags: string[];
386
+ /** Version string */
387
+ version: string;
388
+ /** Whether skill is public */
389
+ isPublic: boolean;
390
+ /** Creation timestamp */
391
+ createdAt: string;
392
+ /** Last update timestamp */
393
+ updatedAt: string;
394
+ }
395
+ /**
396
+ * Skill details (get view, includes prompt template)
397
+ */
398
+ interface SkillDetails extends Skill {
399
+ /** Prompt template */
400
+ promptTemplate: string;
401
+ /** Associated tools */
402
+ tools: SkillTool[];
403
+ /** Variable definitions */
404
+ variables: SkillVariable[];
405
+ }
406
+ /**
407
+ * Skill list options
408
+ */
409
+ interface SkillListOptions extends ListOptions {
410
+ /** Filter by category */
411
+ category?: string;
412
+ /** Filter by tags (any match) */
413
+ tags?: string[];
414
+ }
415
+ /**
416
+ * Skill execute input
417
+ */
418
+ interface SkillExecuteInput {
419
+ /** Variable values for the prompt template */
420
+ variables?: Record<string, unknown>;
421
+ /** Additional context */
422
+ context?: Record<string, unknown>;
423
+ }
424
+ /**
425
+ * Skill execution result
426
+ */
427
+ interface SkillExecution {
428
+ /** Execution ID */
429
+ uuid: string;
430
+ /** Skill ID */
431
+ skillUuid: string;
432
+ /** Execution status */
433
+ status: 'success' | 'error';
434
+ /** Input variables */
435
+ input: Record<string, unknown>;
436
+ /** Generated prompt output */
437
+ output?: string;
438
+ /** Error message */
439
+ error?: string;
440
+ /** Execution timestamp */
441
+ executedAt: string;
442
+ /** Duration in milliseconds */
443
+ durationMs: number;
444
+ }
445
+ /**
446
+ * Skill update input
447
+ */
448
+ interface SkillUpdateInput {
449
+ /** New name */
450
+ name?: string;
451
+ /** New description */
452
+ description?: string;
453
+ /** New category */
454
+ category?: string;
455
+ /** New tags */
456
+ tags?: string[];
457
+ }
458
+
459
+ /**
460
+ * Tool types
461
+ */
462
+
463
+ /**
464
+ * Tool resource
465
+ */
466
+ interface Tool {
467
+ /** Unique identifier */
468
+ uuid: string;
469
+ /** Tool name */
470
+ name: string;
471
+ /** Tool description */
472
+ description: string;
473
+ /** Category */
474
+ category: string | null;
475
+ /** Input JSON schema */
476
+ inputSchema: JSONSchema;
477
+ /** Output JSON schema */
478
+ outputSchema?: JSONSchema;
479
+ /** Whether tool is enabled */
480
+ isEnabled: boolean;
481
+ /** Creation timestamp */
482
+ createdAt: string;
483
+ /** Last update timestamp */
484
+ updatedAt: string;
485
+ }
486
+ /**
487
+ * Tool list options
488
+ */
489
+ interface ToolListOptions extends ListOptions {
490
+ /** Filter by category */
491
+ category?: string;
492
+ /** Filter by enabled status */
493
+ isEnabled?: boolean;
494
+ }
495
+ /**
496
+ * Tool execution result
497
+ */
498
+ interface ToolExecution {
499
+ /** Execution ID */
500
+ uuid: string;
501
+ /** Tool ID */
502
+ toolUuid: string;
503
+ /** Execution status */
504
+ status: 'success' | 'error';
505
+ /** Input provided */
506
+ input: Record<string, unknown>;
507
+ /** Output result */
508
+ output?: unknown;
509
+ /** Error message */
510
+ error?: string;
511
+ /** Duration in milliseconds */
512
+ durationMs: number;
513
+ /** Execution timestamp */
514
+ executedAt: string;
515
+ }
516
+ /**
517
+ * Tool input validation result
518
+ */
519
+ interface ToolValidationResult {
520
+ /** Whether the input is valid */
521
+ valid: boolean;
522
+ /** Validation errors (if invalid) */
523
+ errors?: Array<{
524
+ field: string;
525
+ message: string;
526
+ }>;
527
+ }
528
+ /**
529
+ * Tool update input
530
+ */
531
+ interface ToolUpdateInput {
532
+ /** New name */
533
+ name?: string;
534
+ /** New description */
535
+ description?: string;
536
+ /** New category */
537
+ category?: string;
538
+ }
539
+ /**
540
+ * Tool config update input
541
+ */
542
+ interface ToolConfigUpdateInput {
543
+ /** Tool-specific configuration */
544
+ config?: Record<string, unknown>;
545
+ /** Enable/disable tool */
546
+ isEnabled?: boolean;
547
+ }
548
+
549
+ /**
550
+ * Artifact types
551
+ */
552
+
553
+ /**
554
+ * Artifact type
555
+ */
556
+ type ArtifactType = 'file' | 'data' | 'log';
557
+ /**
558
+ * Artifact resource
559
+ */
560
+ interface Artifact {
561
+ /** Unique identifier */
562
+ uuid: string;
563
+ /** Associated execution ID */
564
+ executionUuid: string;
565
+ /** Artifact name */
566
+ name: string;
567
+ /** Artifact type */
568
+ type: ArtifactType;
569
+ /** MIME type */
570
+ mimeType: string;
571
+ /** Size in bytes */
572
+ size: number;
573
+ /** Creation timestamp */
574
+ createdAt: string;
575
+ /** Additional metadata */
576
+ metadata?: Record<string, unknown>;
577
+ }
578
+ /**
579
+ * Artifact list options
580
+ */
581
+ interface ArtifactListOptions extends ListOptions {
582
+ /** Filter by type */
583
+ type?: ArtifactType;
584
+ }
585
+ /**
586
+ * Artifact download options
587
+ */
588
+ interface ArtifactDownloadOptions {
589
+ /** Response format (only for getSignedUrl) */
590
+ format?: 'buffer' | 'stream' | 'url';
591
+ /** Expiration time in seconds for signed URL (default: 3600) */
592
+ expiresIn?: number;
593
+ }
594
+ /**
595
+ * Signed URL response
596
+ */
597
+ interface SignedUrlResponse {
598
+ /** The signed URL */
599
+ url: string;
600
+ /** When the URL expires */
601
+ expiresAt: string;
602
+ }
603
+ /**
604
+ * Artifact upload input
605
+ */
606
+ interface ArtifactUploadInput {
607
+ /** File name */
608
+ name: string;
609
+ /** File content (Buffer in Node.js, Blob in browser) */
610
+ content: Buffer | Blob | ReadableStream<Uint8Array>;
611
+ /** MIME type */
612
+ mimeType?: string;
613
+ /** Artifact type */
614
+ type?: ArtifactType;
615
+ /** Additional metadata */
616
+ metadata?: Record<string, unknown>;
617
+ }
618
+
619
+ /**
620
+ * Session types
621
+ */
622
+
623
+ /**
624
+ * Session resource
625
+ */
626
+ interface Session {
627
+ /** Session ID */
628
+ id: string;
629
+ /** Associated agent ID */
630
+ agentUuid: string;
631
+ /** Creation timestamp */
632
+ createdAt: string;
633
+ /** Last message timestamp */
634
+ lastMessageAt: string;
635
+ /** Number of messages in session */
636
+ messageCount: number;
637
+ /** Last user message (for session list preview) */
638
+ lastUserMessage?: string | null;
639
+ }
640
+ /**
641
+ * Session message
642
+ */
643
+ interface SessionMessage {
644
+ /** Message ID */
645
+ id: string;
646
+ /** Message role */
647
+ role: 'user' | 'assistant' | 'system';
648
+ /** Message content */
649
+ content: string;
650
+ /** Associated execution ID (for assistant messages) */
651
+ executionUuid?: string;
652
+ /** Message timestamp */
653
+ timestamp: string;
654
+ }
655
+ /**
656
+ * Session history with messages
657
+ */
658
+ interface SessionHistory {
659
+ /** Session info */
660
+ session: Session;
661
+ /** Messages in chronological order */
662
+ messages: SessionMessage[];
663
+ }
664
+ /**
665
+ * Session list options
666
+ */
667
+ interface SessionListOptions extends ListOptions {
668
+ /** Filter by agent */
669
+ agentUuid?: string;
670
+ }
671
+ /**
672
+ * Session create input
673
+ */
674
+ interface SessionCreateInput {
675
+ /** Agent to associate with the session */
676
+ agentUuid: string;
677
+ /** Initial system message (optional) */
678
+ systemMessage?: string;
679
+ }
680
+ /**
681
+ * Send message input
682
+ */
683
+ interface SendMessageInput {
684
+ /** Message content */
685
+ message: string;
686
+ /** Additional context */
687
+ context?: Record<string, unknown>;
688
+ }
689
+ /**
690
+ * Session artifact type
691
+ */
692
+ type SessionArtifactType = 'file' | 'image' | 'code' | 'data' | 'log' | 'report';
693
+ /**
694
+ * Session artifact variant type
695
+ */
696
+ type SessionArtifactVariantType = 'original' | 'thumbnail';
697
+ /**
698
+ * Session artifact resource
699
+ * Represents an artifact generated during a session execution
700
+ */
701
+ interface SessionArtifact {
702
+ /** Unique identifier */
703
+ uuid: string;
704
+ /** Associated execution ID */
705
+ executionId: string;
706
+ /** Artifact type */
707
+ type: SessionArtifactType;
708
+ /** Variant type (original or thumbnail) */
709
+ variantType: SessionArtifactVariantType;
710
+ /** Original filename */
711
+ filename: string;
712
+ /** MIME type */
713
+ mimeType: string;
714
+ /** Size in bytes */
715
+ size: number;
716
+ /** Pre-signed URL for accessing the artifact */
717
+ url: string;
718
+ /** Thumbnail URL (for images) */
719
+ thumbnailUrl?: string;
720
+ /** Image dimensions (for images) */
721
+ dimensions?: {
722
+ width: number;
723
+ height: number;
724
+ };
725
+ /** Description */
726
+ description?: string | null;
727
+ /** Additional metadata */
728
+ metadata?: Record<string, unknown> | null;
729
+ /** Creation timestamp */
730
+ createdAt: string;
731
+ }
732
+ /**
733
+ * Session artifact list options
734
+ */
735
+ interface SessionArtifactListOptions extends ListOptions {
736
+ /** Filter by artifact type */
737
+ type?: SessionArtifactType;
738
+ /** Include thumbnail variants (default: false) */
739
+ includeVariants?: boolean;
740
+ }
741
+
742
+ /**
743
+ * Streaming types
744
+ */
745
+
746
+ /**
747
+ * Tool call event
748
+ */
749
+ interface ToolCallEvent {
750
+ /** Tool call ID */
751
+ toolCallId: string;
752
+ /** Tool name */
753
+ toolName: string;
754
+ /** Tool inputs */
755
+ inputs: Record<string, unknown>;
756
+ /** Step/iteration index */
757
+ stepIndex: number;
758
+ }
759
+ /**
760
+ * Tool result event
761
+ */
762
+ interface ToolResultEvent {
763
+ /** Tool call ID */
764
+ toolCallId: string;
765
+ /** Tool name */
766
+ toolName: string;
767
+ /** Tool result */
768
+ result: unknown;
769
+ /** Duration in milliseconds */
770
+ durationMs: number;
771
+ }
772
+ /**
773
+ * Plan event
774
+ */
775
+ interface PlanEvent {
776
+ /** Planned tasks */
777
+ tasks: Array<{
778
+ title: string;
779
+ status: 'pending' | 'in_progress' | 'completed' | 'failed';
780
+ }>;
781
+ }
782
+ /**
783
+ * Complete event
784
+ */
785
+ interface CompleteEvent {
786
+ /** Final execution result */
787
+ execution: AgentExecution;
788
+ }
789
+ /**
790
+ * Error event
791
+ */
792
+ interface ErrorEvent {
793
+ /** Error message */
794
+ error: string;
795
+ /** Error code */
796
+ errorCode?: string;
797
+ }
798
+ /**
799
+ * Connection change event
800
+ */
801
+ interface ConnectionChangeEvent {
802
+ /** Whether connected */
803
+ connected: boolean;
804
+ /** Whether using fallback polling */
805
+ usingFallback?: boolean;
806
+ }
807
+ /**
808
+ * Stream event map for type-safe event handlers
809
+ */
810
+ interface StreamEventMap {
811
+ log: ExecutionLog;
812
+ toolCall: ToolCallEvent;
813
+ toolResult: ToolResultEvent;
814
+ plan: PlanEvent;
815
+ complete: CompleteEvent;
816
+ error: ErrorEvent;
817
+ connectionChange: ConnectionChangeEvent;
818
+ }
819
+ /**
820
+ * Stream controller interface
821
+ */
822
+ interface StreamController {
823
+ /** Listen for log events */
824
+ on(event: 'log', callback: (log: ExecutionLog) => void): void;
825
+ /** Listen for tool call events */
826
+ on(event: 'toolCall', callback: (data: ToolCallEvent) => void): void;
827
+ /** Listen for tool result events */
828
+ on(event: 'toolResult', callback: (data: ToolResultEvent) => void): void;
829
+ /** Listen for plan updates */
830
+ on(event: 'plan', callback: (data: PlanEvent) => void): void;
831
+ /** Listen for completion */
832
+ on(event: 'complete', callback: (data: CompleteEvent) => void): void;
833
+ /** Listen for errors */
834
+ on(event: 'error', callback: (error: ErrorEvent) => void): void;
835
+ /** Listen for connection state changes */
836
+ on(event: 'connectionChange', callback: (data: ConnectionChangeEvent) => void): void;
837
+ /** Cancel the stream */
838
+ cancel(): void;
839
+ /** Wait for completion, returns final execution result */
840
+ wait(): Promise<AgentExecution>;
841
+ }
842
+ /**
843
+ * Streaming configuration
844
+ */
845
+ interface StreamingConfig {
846
+ /** Maximum reconnection attempts */
847
+ maxReconnectAttempts: number;
848
+ /** Base delay for reconnection (ms) */
849
+ reconnectBaseDelayMs: number;
850
+ /** Maximum delay for reconnection (ms) */
851
+ reconnectMaxDelayMs: number;
852
+ /** Activity timeout - no events for this long triggers reconnect (ms) */
853
+ activityTimeoutMs: number;
854
+ /** Polling interval for fallback mode (ms) */
855
+ pollingIntervalMs: number;
856
+ }
857
+
858
+ /**
859
+ * Base Resource API
860
+ *
861
+ * Abstract base class for all resource APIs.
862
+ * Provides common HTTP methods and path handling.
863
+ */
864
+
865
+ /**
866
+ * Base Resource API class
867
+ */
868
+ declare abstract class BaseResourceAPI {
869
+ protected readonly http: HttpClient;
870
+ protected readonly basePath: string;
871
+ constructor(http: HttpClient, basePath: string);
872
+ /**
873
+ * Build query parameters from list options
874
+ */
875
+ protected buildListQuery(options?: ListOptions): Record<string, string | number | boolean | undefined>;
876
+ /**
877
+ * HTTP GET request helper
878
+ */
879
+ protected httpGet<T>(path: string, query?: Record<string, string | number | boolean | undefined>): Promise<T>;
880
+ /**
881
+ * HTTP POST request helper
882
+ */
883
+ protected httpPost<T>(path: string, body?: unknown, options?: {
884
+ idempotencyKey?: string;
885
+ skipRetry?: boolean;
886
+ }): Promise<T>;
887
+ /**
888
+ * HTTP PATCH request helper
889
+ */
890
+ protected httpPatch<T>(path: string, body?: unknown, options?: {
891
+ idempotencyKey?: string;
892
+ }): Promise<T>;
893
+ /**
894
+ * HTTP DELETE request helper
895
+ */
896
+ protected httpDelete<T>(path: string): Promise<T>;
897
+ /**
898
+ * List resources with pagination
899
+ */
900
+ protected listResources<T>(path: string, options?: ListOptions): Promise<PaginatedResponse<T>>;
901
+ }
902
+
903
+ /**
904
+ * Stream Controller
905
+ *
906
+ * Manages execution streaming with automatic reconnection and fallback to polling.
907
+ * Implements the StreamController interface for type-safe event handling.
908
+ */
909
+
910
+ /**
911
+ * Stream controller creation options
912
+ */
913
+ interface ExecutionStreamControllerOptions {
914
+ /** Execution ID to stream */
915
+ executionId: string;
916
+ /** Base URL for API */
917
+ baseUrl: string;
918
+ /** API key or token */
919
+ apiKey?: string;
920
+ /** Organization ID */
921
+ orgId: number;
922
+ /** Function to get execution status (for polling fallback) */
923
+ getExecution: (executionId: string) => Promise<AgentExecution>;
924
+ /** Streaming configuration */
925
+ config?: Partial<StreamingConfig>;
926
+ }
927
+ /**
928
+ * Execution Stream Controller
929
+ *
930
+ * Manages the lifecycle of an execution stream, including:
931
+ * - SSE connection management
932
+ * - Automatic reconnection with exponential backoff
933
+ * - Fallback to polling on connection failure
934
+ * - Event deduplication
935
+ */
936
+ interface ExecutionStreamController extends StreamController {
937
+ /** Connect to the stream */
938
+ connect(): Promise<void>;
939
+ }
940
+
941
+ /**
942
+ * Agents Resource API
943
+ *
944
+ * Provides all agent-related operations:
945
+ * - List: list(), get()
946
+ * - Execute: execute(), executeSync(), stream()
947
+ * - Receive: getExecution()
948
+ * - Edit: update(), updateConfig(), cancelExecution()
949
+ */
950
+
951
+ /**
952
+ * Agents API class
953
+ */
954
+ declare class AgentsAPI extends BaseResourceAPI {
955
+ private readonly getStreamConfig;
956
+ constructor(http: HttpClient, getStreamConfig: () => StreamConfig);
957
+ /**
958
+ * List all agents in the organization
959
+ *
960
+ * @param options - List options (pagination, filtering)
961
+ * @returns Paginated list of agents
962
+ *
963
+ * @example
964
+ * ```typescript
965
+ * const { data: agents, pagination } = await client.agents.list({ limit: 10 });
966
+ * ```
967
+ */
968
+ list(options?: AgentListOptions): Promise<PaginatedResponse<Agent>>;
969
+ /**
970
+ * Get a single agent by UUID
971
+ *
972
+ * @param uuid - Agent UUID
973
+ * @returns Agent with configuration
974
+ *
975
+ * @example
976
+ * ```typescript
977
+ * const agent = await client.agents.get('agent-uuid');
978
+ * console.log(agent.config);
979
+ * ```
980
+ */
981
+ get(uuid: string): Promise<Agent>;
982
+ /**
983
+ * Start an agent execution (async)
984
+ *
985
+ * Returns immediately with execution ID. Use getExecution() to poll
986
+ * for results, or use stream() for real-time updates.
987
+ *
988
+ * @param uuid - Agent UUID
989
+ * @param input - Execution input (task, context, options)
990
+ * @returns Execution ID and initial status
991
+ *
992
+ * @example
993
+ * ```typescript
994
+ * const { executionId, status } = await client.agents.execute('agent-uuid', {
995
+ * task: 'Summarize the latest news about AI',
996
+ * });
997
+ * ```
998
+ */
999
+ execute(uuid: string, input: ExecuteInput): Promise<ExecuteResponse>;
1000
+ /**
1001
+ * Execute an agent and wait for completion (sync)
1002
+ *
1003
+ * Polls the execution status until completion or failure.
1004
+ *
1005
+ * @param uuid - Agent UUID
1006
+ * @param input - Execution input
1007
+ * @param pollInterval - Polling interval in ms (default: 1000)
1008
+ * @returns Final execution result
1009
+ *
1010
+ * @example
1011
+ * ```typescript
1012
+ * const execution = await client.agents.executeSync('agent-uuid', {
1013
+ * task: 'Write a haiku about coding',
1014
+ * });
1015
+ * console.log(execution.output);
1016
+ * ```
1017
+ */
1018
+ executeSync(uuid: string, input: ExecuteInput, pollInterval?: number): Promise<AgentExecution>;
1019
+ /**
1020
+ * Stream an agent execution
1021
+ *
1022
+ * Returns a StreamController for real-time event handling.
1023
+ *
1024
+ * @param uuid - Agent UUID
1025
+ * @param input - Execution input
1026
+ * @returns Stream controller for event handling
1027
+ *
1028
+ * @example
1029
+ * ```typescript
1030
+ * const stream = await client.agents.stream('agent-uuid', {
1031
+ * task: 'Research climate change',
1032
+ * });
1033
+ *
1034
+ * stream.on('log', (log) => console.log(log.title));
1035
+ * stream.on('toolCall', ({ toolName }) => console.log(`Calling ${toolName}`));
1036
+ * stream.on('complete', ({ execution }) => console.log(execution.output));
1037
+ *
1038
+ * const result = await stream.wait();
1039
+ * ```
1040
+ */
1041
+ stream(uuid: string, input: ExecuteInput): Promise<ExecutionStreamController>;
1042
+ /**
1043
+ * Get execution result by ID
1044
+ *
1045
+ * @param executionId - Execution UUID
1046
+ * @returns Execution details including status, output, logs
1047
+ *
1048
+ * @example
1049
+ * ```typescript
1050
+ * const execution = await client.agents.getExecution('exec-uuid');
1051
+ * if (execution.status === 'completed') {
1052
+ * console.log(execution.output);
1053
+ * }
1054
+ * ```
1055
+ */
1056
+ getExecution(executionId: string): Promise<AgentExecution>;
1057
+ /**
1058
+ * Update agent details
1059
+ *
1060
+ * @param uuid - Agent UUID
1061
+ * @param data - Fields to update
1062
+ * @returns Updated agent
1063
+ *
1064
+ * @example
1065
+ * ```typescript
1066
+ * const agent = await client.agents.update('agent-uuid', {
1067
+ * name: 'My Updated Agent',
1068
+ * description: 'New description',
1069
+ * });
1070
+ * ```
1071
+ */
1072
+ update(uuid: string, data: AgentUpdateInput): Promise<Agent>;
1073
+ /**
1074
+ * Update agent configuration
1075
+ *
1076
+ * @param uuid - Agent UUID
1077
+ * @param config - Configuration fields to update
1078
+ * @returns Updated agent
1079
+ *
1080
+ * @example
1081
+ * ```typescript
1082
+ * const agent = await client.agents.updateConfig('agent-uuid', {
1083
+ * temperature: 0.7,
1084
+ * maxIterations: 5,
1085
+ * });
1086
+ * ```
1087
+ */
1088
+ updateConfig(uuid: string, config: AgentConfigUpdateInput): Promise<Agent>;
1089
+ /**
1090
+ * Cancel a running execution
1091
+ *
1092
+ * @param executionId - Execution UUID
1093
+ * @returns Updated execution with cancelled status
1094
+ *
1095
+ * @example
1096
+ * ```typescript
1097
+ * const execution = await client.agents.cancelExecution('exec-uuid');
1098
+ * console.log(execution.status); // 'cancelled'
1099
+ * ```
1100
+ */
1101
+ cancelExecution(executionId: string): Promise<AgentExecution>;
1102
+ /**
1103
+ * Poll execution until completion
1104
+ */
1105
+ private pollExecution;
1106
+ }
1107
+ /**
1108
+ * Stream configuration passed from client
1109
+ */
1110
+ interface StreamConfig {
1111
+ baseUrl: string;
1112
+ apiKey?: string;
1113
+ token?: string;
1114
+ orgId: number;
1115
+ }
1116
+
1117
+ /**
1118
+ * Skills Resource API
1119
+ *
1120
+ * Provides all skill-related operations:
1121
+ * - List: list(), get(), getTools()
1122
+ * - Execute: execute()
1123
+ * - Receive: getExecution()
1124
+ * - Edit: update(), updatePrompt()
1125
+ */
1126
+
1127
+ /**
1128
+ * Skills API class
1129
+ */
1130
+ declare class SkillsAPI extends BaseResourceAPI {
1131
+ constructor(http: HttpClient);
1132
+ /**
1133
+ * List all skills in the organization
1134
+ *
1135
+ * @param options - List options (pagination, filtering by category/tags)
1136
+ * @returns Paginated list of skills
1137
+ *
1138
+ * @example
1139
+ * ```typescript
1140
+ * const { data: skills } = await client.skills.list({
1141
+ * category: 'writing',
1142
+ * tags: ['seo', 'blog'],
1143
+ * });
1144
+ * ```
1145
+ */
1146
+ list(options?: SkillListOptions): Promise<PaginatedResponse<Skill>>;
1147
+ /**
1148
+ * Get a single skill by UUID with full details
1149
+ *
1150
+ * @param uuid - Skill UUID
1151
+ * @returns Skill with prompt template and tools
1152
+ *
1153
+ * @example
1154
+ * ```typescript
1155
+ * const skill = await client.skills.get('skill-uuid');
1156
+ * console.log(skill.promptTemplate);
1157
+ * ```
1158
+ */
1159
+ get(uuid: string): Promise<SkillDetails>;
1160
+ /**
1161
+ * Get tools associated with a skill
1162
+ *
1163
+ * @param uuid - Skill UUID
1164
+ * @returns Array of tools used by the skill
1165
+ *
1166
+ * @example
1167
+ * ```typescript
1168
+ * const tools = await client.skills.getTools('skill-uuid');
1169
+ * tools.forEach(tool => console.log(tool.name));
1170
+ * ```
1171
+ */
1172
+ getTools(uuid: string): Promise<SkillTool[]>;
1173
+ /**
1174
+ * Execute a skill with variables
1175
+ *
1176
+ * @param uuid - Skill UUID
1177
+ * @param input - Variables and context for execution
1178
+ * @returns Skill execution result
1179
+ *
1180
+ * @example
1181
+ * ```typescript
1182
+ * const result = await client.skills.execute('skill-uuid', {
1183
+ * variables: {
1184
+ * topic: 'AI in healthcare',
1185
+ * tone: 'professional',
1186
+ * },
1187
+ * });
1188
+ * console.log(result.output);
1189
+ * ```
1190
+ */
1191
+ execute(uuid: string, input: SkillExecuteInput): Promise<SkillExecution>;
1192
+ /**
1193
+ * Get skill execution result by ID
1194
+ *
1195
+ * @param executionId - Execution UUID
1196
+ * @returns Skill execution details
1197
+ *
1198
+ * @example
1199
+ * ```typescript
1200
+ * const execution = await client.skills.getExecution('exec-uuid');
1201
+ * ```
1202
+ */
1203
+ getExecution(executionId: string): Promise<SkillExecution>;
1204
+ /**
1205
+ * Update skill details
1206
+ *
1207
+ * @param uuid - Skill UUID
1208
+ * @param data - Fields to update
1209
+ * @returns Updated skill
1210
+ *
1211
+ * @example
1212
+ * ```typescript
1213
+ * const skill = await client.skills.update('skill-uuid', {
1214
+ * name: 'Updated Skill Name',
1215
+ * tags: ['new-tag'],
1216
+ * });
1217
+ * ```
1218
+ */
1219
+ update(uuid: string, data: SkillUpdateInput): Promise<Skill>;
1220
+ /**
1221
+ * Update skill prompt template
1222
+ *
1223
+ * @param uuid - Skill UUID
1224
+ * @param prompt - New prompt template
1225
+ * @returns Updated skill with new version
1226
+ *
1227
+ * @example
1228
+ * ```typescript
1229
+ * const skill = await client.skills.updatePrompt('skill-uuid',
1230
+ * 'Write a {{tone}} article about {{topic}}...'
1231
+ * );
1232
+ * console.log(skill.version); // Version incremented
1233
+ * ```
1234
+ */
1235
+ updatePrompt(uuid: string, prompt: string): Promise<SkillDetails>;
1236
+ }
1237
+
1238
+ /**
1239
+ * Tools Resource API
1240
+ *
1241
+ * Provides all tool-related operations:
1242
+ * - List: list(), get()
1243
+ * - Execute: execute(), validateInput()
1244
+ * - Receive: getExecution()
1245
+ * - Edit: update(), updateConfig()
1246
+ */
1247
+
1248
+ /**
1249
+ * Tools API class
1250
+ */
1251
+ declare class ToolsAPI extends BaseResourceAPI {
1252
+ constructor(http: HttpClient);
1253
+ /**
1254
+ * List all tools in the organization
1255
+ *
1256
+ * @param options - List options (pagination, filtering)
1257
+ * @returns Paginated list of tools
1258
+ *
1259
+ * @example
1260
+ * ```typescript
1261
+ * const { data: tools } = await client.tools.list({
1262
+ * category: 'data',
1263
+ * isEnabled: true,
1264
+ * });
1265
+ * ```
1266
+ */
1267
+ list(options?: ToolListOptions): Promise<PaginatedResponse<Tool>>;
1268
+ /**
1269
+ * Get a single tool by UUID with schema
1270
+ *
1271
+ * @param uuid - Tool UUID
1272
+ * @returns Tool with input/output schemas
1273
+ *
1274
+ * @example
1275
+ * ```typescript
1276
+ * const tool = await client.tools.get('tool-uuid');
1277
+ * console.log(tool.inputSchema);
1278
+ * ```
1279
+ */
1280
+ get(uuid: string): Promise<Tool>;
1281
+ /**
1282
+ * Execute a tool directly
1283
+ *
1284
+ * @param uuid - Tool UUID
1285
+ * @param input - Tool input (validated against inputSchema)
1286
+ * @returns Tool execution result
1287
+ *
1288
+ * @example
1289
+ * ```typescript
1290
+ * const result = await client.tools.execute('tool-uuid', {
1291
+ * query: 'weather in London',
1292
+ * limit: 5,
1293
+ * });
1294
+ * console.log(result.output);
1295
+ * ```
1296
+ */
1297
+ execute(uuid: string, input: Record<string, unknown>): Promise<ToolExecution>;
1298
+ /**
1299
+ * Validate input against tool schema
1300
+ *
1301
+ * @param uuid - Tool UUID
1302
+ * @param input - Input to validate
1303
+ * @returns Validation result with errors if invalid
1304
+ *
1305
+ * @example
1306
+ * ```typescript
1307
+ * const validation = await client.tools.validateInput('tool-uuid', {
1308
+ * query: 'test',
1309
+ * });
1310
+ * if (!validation.valid) {
1311
+ * console.log(validation.errors);
1312
+ * }
1313
+ * ```
1314
+ */
1315
+ validateInput(uuid: string, input: Record<string, unknown>): Promise<ToolValidationResult>;
1316
+ /**
1317
+ * Get tool execution result by ID
1318
+ *
1319
+ * @param executionId - Execution UUID
1320
+ * @returns Tool execution details
1321
+ *
1322
+ * @example
1323
+ * ```typescript
1324
+ * const execution = await client.tools.getExecution('exec-uuid');
1325
+ * ```
1326
+ */
1327
+ getExecution(executionId: string): Promise<ToolExecution>;
1328
+ /**
1329
+ * Update tool details
1330
+ *
1331
+ * @param uuid - Tool UUID
1332
+ * @param data - Fields to update
1333
+ * @returns Updated tool
1334
+ *
1335
+ * @example
1336
+ * ```typescript
1337
+ * const tool = await client.tools.update('tool-uuid', {
1338
+ * name: 'Updated Tool Name',
1339
+ * description: 'New description',
1340
+ * });
1341
+ * ```
1342
+ */
1343
+ update(uuid: string, data: ToolUpdateInput): Promise<Tool>;
1344
+ /**
1345
+ * Update tool configuration
1346
+ *
1347
+ * @param uuid - Tool UUID
1348
+ * @param config - Configuration to update
1349
+ * @returns Updated tool
1350
+ *
1351
+ * @example
1352
+ * ```typescript
1353
+ * const tool = await client.tools.updateConfig('tool-uuid', {
1354
+ * isEnabled: false,
1355
+ * config: { apiKey: 'new-key' },
1356
+ * });
1357
+ * ```
1358
+ */
1359
+ updateConfig(uuid: string, config: ToolConfigUpdateInput): Promise<Tool>;
1360
+ }
1361
+
1362
+ /**
1363
+ * Artifacts Resource API
1364
+ *
1365
+ * Provides all artifact-related operations:
1366
+ * - List: list(), get()
1367
+ * - Receive: download(), downloadStream(), getSignedUrl()
1368
+ * - Edit: upload(), delete()
1369
+ */
1370
+
1371
+ /**
1372
+ * Artifacts API class
1373
+ */
1374
+ declare class ArtifactsAPI extends BaseResourceAPI {
1375
+ constructor(http: HttpClient);
1376
+ /**
1377
+ * List artifacts for an execution
1378
+ *
1379
+ * @param executionId - Execution UUID
1380
+ * @param options - List options (pagination, filtering by type)
1381
+ * @returns Paginated list of artifacts
1382
+ *
1383
+ * @example
1384
+ * ```typescript
1385
+ * const { data: artifacts } = await client.artifacts.list('exec-uuid', {
1386
+ * type: 'file',
1387
+ * });
1388
+ * ```
1389
+ */
1390
+ list(executionId: string, options?: ArtifactListOptions): Promise<PaginatedResponse<Artifact>>;
1391
+ /**
1392
+ * Get artifact metadata by UUID
1393
+ *
1394
+ * @param uuid - Artifact UUID
1395
+ * @returns Artifact metadata
1396
+ *
1397
+ * @example
1398
+ * ```typescript
1399
+ * const artifact = await client.artifacts.get('artifact-uuid');
1400
+ * console.log(artifact.name, artifact.size);
1401
+ * ```
1402
+ */
1403
+ get(uuid: string): Promise<Artifact>;
1404
+ /**
1405
+ * Download artifact content
1406
+ *
1407
+ * In Node.js returns Buffer, in browser returns Blob.
1408
+ *
1409
+ * @param uuid - Artifact UUID
1410
+ * @returns Artifact content as Buffer (Node.js) or Blob (browser)
1411
+ *
1412
+ * @example
1413
+ * ```typescript
1414
+ * const content = await client.artifacts.download('artifact-uuid');
1415
+ * // Node.js: Buffer
1416
+ * // Browser: Blob
1417
+ * ```
1418
+ */
1419
+ download(uuid: string): Promise<Buffer | Blob>;
1420
+ /**
1421
+ * Download artifact as a stream
1422
+ *
1423
+ * In Node.js returns Readable stream, in browser returns ReadableStream.
1424
+ *
1425
+ * @param uuid - Artifact UUID
1426
+ * @returns Readable stream
1427
+ *
1428
+ * @example
1429
+ * ```typescript
1430
+ * const stream = await client.artifacts.downloadStream('artifact-uuid');
1431
+ * // Pipe to file or process incrementally
1432
+ * ```
1433
+ */
1434
+ downloadStream(uuid: string): Promise<ReadableStream<Uint8Array>>;
1435
+ /**
1436
+ * Get a signed URL for direct download
1437
+ *
1438
+ * @param uuid - Artifact UUID
1439
+ * @param options - Options including expiration time
1440
+ * @returns Signed URL and expiration time
1441
+ *
1442
+ * @example
1443
+ * ```typescript
1444
+ * const { url, expiresAt } = await client.artifacts.getSignedUrl('artifact-uuid', {
1445
+ * expiresIn: 3600, // 1 hour
1446
+ * });
1447
+ * // Use URL for direct download
1448
+ * ```
1449
+ */
1450
+ getSignedUrl(uuid: string, options?: ArtifactDownloadOptions): Promise<SignedUrlResponse>;
1451
+ /**
1452
+ * Upload a new artifact for an execution
1453
+ *
1454
+ * @param executionId - Execution UUID
1455
+ * @param input - Upload input (name, content, mime type)
1456
+ * @returns Created artifact metadata
1457
+ *
1458
+ * @example
1459
+ * ```typescript
1460
+ * const artifact = await client.artifacts.upload('exec-uuid', {
1461
+ * name: 'report.pdf',
1462
+ * content: fileBuffer,
1463
+ * mimeType: 'application/pdf',
1464
+ * });
1465
+ * ```
1466
+ */
1467
+ upload(executionId: string, input: ArtifactUploadInput): Promise<Artifact>;
1468
+ /**
1469
+ * Delete an artifact
1470
+ *
1471
+ * @param uuid - Artifact UUID
1472
+ *
1473
+ * @example
1474
+ * ```typescript
1475
+ * await client.artifacts.delete('artifact-uuid');
1476
+ * ```
1477
+ */
1478
+ delete(uuid: string): Promise<void>;
1479
+ }
1480
+
1481
+ /**
1482
+ * Sessions Resource API
1483
+ *
1484
+ * Provides all session-related operations:
1485
+ * - List: list(), get()
1486
+ * - Execute: sendMessage(), stream()
1487
+ * - Receive: getHistory(), listArtifacts()
1488
+ * - Edit: create(), delete()
1489
+ */
1490
+
1491
+ /**
1492
+ * Sessions API class
1493
+ */
1494
+ declare class SessionsAPI extends BaseResourceAPI {
1495
+ private readonly getStreamConfig;
1496
+ constructor(http: HttpClient, getStreamConfig: () => StreamConfig);
1497
+ /**
1498
+ * List all sessions in the organization
1499
+ *
1500
+ * @param options - List options (pagination, filtering by agent)
1501
+ * @returns Paginated list of sessions
1502
+ *
1503
+ * @example
1504
+ * ```typescript
1505
+ * const { data: sessions } = await client.sessions.list({
1506
+ * agentUuid: 'agent-uuid',
1507
+ * });
1508
+ * ```
1509
+ */
1510
+ list(options?: SessionListOptions): Promise<PaginatedResponse<Session>>;
1511
+ /**
1512
+ * Get session details by ID
1513
+ *
1514
+ * @param sessionId - Session ID
1515
+ * @returns Session details
1516
+ *
1517
+ * @example
1518
+ * ```typescript
1519
+ * const session = await client.sessions.get('session-id');
1520
+ * console.log(session.messageCount);
1521
+ * ```
1522
+ */
1523
+ get(sessionId: string): Promise<Session>;
1524
+ /**
1525
+ * Send a message to a session
1526
+ *
1527
+ * Triggers an agent execution in the context of the session.
1528
+ * Returns immediately with execution ID. Use getHistory() to get
1529
+ * the response, or use stream() for real-time updates.
1530
+ *
1531
+ * @param sessionId - Session ID
1532
+ * @param input - Message content and optional context
1533
+ * @returns Execution ID and status
1534
+ *
1535
+ * @example
1536
+ * ```typescript
1537
+ * const { executionId } = await client.sessions.sendMessage('session-id', {
1538
+ * message: 'What is the capital of France?',
1539
+ * });
1540
+ * ```
1541
+ */
1542
+ sendMessage(sessionId: string, input: SendMessageInput): Promise<ExecuteResponse>;
1543
+ /**
1544
+ * Send a message and wait for response (sync)
1545
+ *
1546
+ * @param sessionId - Session ID
1547
+ * @param input - Message content and optional context
1548
+ * @param pollInterval - Polling interval in ms (default: 1000)
1549
+ * @returns Final execution result
1550
+ *
1551
+ * @example
1552
+ * ```typescript
1553
+ * const execution = await client.sessions.sendMessageSync('session-id', {
1554
+ * message: 'What is the capital of France?',
1555
+ * });
1556
+ * console.log(execution.output);
1557
+ * ```
1558
+ */
1559
+ sendMessageSync(sessionId: string, input: SendMessageInput, pollInterval?: number): Promise<AgentExecution>;
1560
+ /**
1561
+ * Stream a message response
1562
+ *
1563
+ * Returns a StreamController for real-time event handling.
1564
+ *
1565
+ * @param sessionId - Session ID
1566
+ * @param input - Message content and optional context
1567
+ * @returns Stream controller
1568
+ *
1569
+ * @example
1570
+ * ```typescript
1571
+ * const stream = await client.sessions.stream('session-id', {
1572
+ * message: 'Tell me more about that',
1573
+ * });
1574
+ *
1575
+ * stream.on('log', (log) => console.log(log.title));
1576
+ * stream.on('complete', ({ execution }) => console.log(execution.output));
1577
+ *
1578
+ * const result = await stream.wait();
1579
+ * ```
1580
+ */
1581
+ stream(sessionId: string, input: SendMessageInput): Promise<ExecutionStreamController>;
1582
+ /**
1583
+ * Get session conversation history
1584
+ *
1585
+ * @param sessionId - Session ID
1586
+ * @returns Session with all messages
1587
+ *
1588
+ * @example
1589
+ * ```typescript
1590
+ * const history = await client.sessions.getHistory('session-id');
1591
+ * history.messages.forEach(msg => {
1592
+ * console.log(`${msg.role}: ${msg.content}`);
1593
+ * });
1594
+ * ```
1595
+ */
1596
+ getHistory(sessionId: string): Promise<SessionHistory>;
1597
+ /**
1598
+ * List artifacts for a session
1599
+ *
1600
+ * Returns all artifacts generated across all executions in the session.
1601
+ * Useful for retrieving images, files, and other outputs created during
1602
+ * agent interactions.
1603
+ *
1604
+ * @param sessionId - Session ID
1605
+ * @param options - List options (filtering by type, pagination)
1606
+ * @returns Paginated list of session artifacts
1607
+ *
1608
+ * @example
1609
+ * ```typescript
1610
+ * // Get all images from a session
1611
+ * const { data: artifacts } = await client.sessions.listArtifacts('session-id', {
1612
+ * type: 'image',
1613
+ * });
1614
+ *
1615
+ * artifacts.forEach(artifact => {
1616
+ * console.log(artifact.filename, artifact.url);
1617
+ * });
1618
+ * ```
1619
+ */
1620
+ listArtifacts(sessionId: string, options?: SessionArtifactListOptions): Promise<PaginatedResponse<SessionArtifact>>;
1621
+ /**
1622
+ * Get execution result
1623
+ */
1624
+ private getExecution;
1625
+ /**
1626
+ * Create a new session for an agent
1627
+ *
1628
+ * @param agentUuid - Agent UUID to associate with session
1629
+ * @param options - Optional system message
1630
+ * @returns Created session
1631
+ *
1632
+ * @example
1633
+ * ```typescript
1634
+ * const session = await client.sessions.create({
1635
+ * agentUuid: 'agent-uuid',
1636
+ * systemMessage: 'You are a helpful assistant.',
1637
+ * });
1638
+ * console.log(session.id);
1639
+ * ```
1640
+ */
1641
+ create(input: SessionCreateInput): Promise<Session>;
1642
+ /**
1643
+ * Delete a session and all its messages
1644
+ *
1645
+ * @param sessionId - Session ID
1646
+ *
1647
+ * @example
1648
+ * ```typescript
1649
+ * await client.sessions.delete('session-id');
1650
+ * ```
1651
+ */
1652
+ delete(sessionId: string): Promise<void>;
1653
+ /**
1654
+ * Poll execution until completion
1655
+ */
1656
+ private pollExecution;
1657
+ }
1658
+
1659
+ /**
1660
+ * AI SaaS Client
1661
+ *
1662
+ * Main entry point for the SDK. Provides access to all resource APIs.
1663
+ *
1664
+ * @example
1665
+ * ```typescript
1666
+ * import { AISaaSClient } from '@cadraos/sdk';
1667
+ *
1668
+ * const client = new AISaaSClient({
1669
+ * apiKey: process.env.AISAAS_API_KEY,
1670
+ * orgId: Number(process.env.AISAAS_ORG_ID),
1671
+ * });
1672
+ *
1673
+ * // List agents
1674
+ * const { data: agents } = await client.agents.list();
1675
+ *
1676
+ * // Execute an agent
1677
+ * const execution = await client.agents.executeSync(agents[0].uuid, {
1678
+ * task: 'Summarize the latest news',
1679
+ * });
1680
+ *
1681
+ * // Stream an agent execution
1682
+ * const stream = await client.agents.stream(agents[0].uuid, {
1683
+ * task: 'Research climate change',
1684
+ * });
1685
+ *
1686
+ * stream.on('log', (log) => console.log(log.title));
1687
+ * stream.on('complete', ({ execution }) => console.log(execution.output));
1688
+ *
1689
+ * const result = await stream.wait();
1690
+ * ```
1691
+ */
1692
+
1693
+ /**
1694
+ * Client options for API key authentication
1695
+ */
1696
+ interface AISaaSClientOptionsApiKey {
1697
+ /** API key for authentication */
1698
+ apiKey: string;
1699
+ /** Organization ID */
1700
+ orgId: number;
1701
+ /** Base URL for API (default: https://api.aisaas.com/v1) */
1702
+ baseUrl?: string;
1703
+ /** Request timeout in milliseconds (default: 30000) */
1704
+ timeout?: number;
1705
+ /** Maximum retry attempts (default: 3) */
1706
+ maxRetries?: number;
1707
+ /** Custom headers to include in all requests */
1708
+ headers?: Record<string, string>;
1709
+ }
1710
+ /**
1711
+ * Client options for OAuth token authentication
1712
+ */
1713
+ interface AISaaSClientOptionsToken {
1714
+ /** OAuth token for authentication */
1715
+ token: string;
1716
+ /** Organization ID */
1717
+ orgId: number;
1718
+ /** Base URL for API (default: https://api.aisaas.com/v1) */
1719
+ baseUrl?: string;
1720
+ /** Request timeout in milliseconds (default: 30000) */
1721
+ timeout?: number;
1722
+ /** Maximum retry attempts (default: 3) */
1723
+ maxRetries?: number;
1724
+ /** Custom headers to include in all requests */
1725
+ headers?: Record<string, string>;
1726
+ }
1727
+ /**
1728
+ * Client options for token provider authentication
1729
+ */
1730
+ interface AISaaSClientOptionsTokenProvider {
1731
+ /** Token provider callback (called before each request) */
1732
+ tokenProvider: () => Promise<string>;
1733
+ /** Organization ID */
1734
+ orgId: number;
1735
+ /** Base URL for API (default: https://api.aisaas.com/v1) */
1736
+ baseUrl?: string;
1737
+ /** Request timeout in milliseconds (default: 30000) */
1738
+ timeout?: number;
1739
+ /** Maximum retry attempts (default: 3) */
1740
+ maxRetries?: number;
1741
+ /** Custom headers to include in all requests */
1742
+ headers?: Record<string, string>;
1743
+ }
1744
+ /**
1745
+ * All client options
1746
+ */
1747
+ type AISaaSClientOptions = AISaaSClientOptionsApiKey | AISaaSClientOptionsToken | AISaaSClientOptionsTokenProvider;
1748
+ /**
1749
+ * AI SaaS Client
1750
+ *
1751
+ * Main class for interacting with the AI SaaS API.
1752
+ * Provides access to all resource APIs (agents, skills, tools, artifacts, sessions).
1753
+ */
1754
+ declare class AISaaSClient {
1755
+ private readonly httpClient;
1756
+ private readonly config;
1757
+ /**
1758
+ * Agent operations (list, execute, stream, update)
1759
+ */
1760
+ readonly agents: AgentsAPI;
1761
+ /**
1762
+ * Skill operations (list, get, execute, update)
1763
+ */
1764
+ readonly skills: SkillsAPI;
1765
+ /**
1766
+ * Tool operations (list, get, execute, validate, update)
1767
+ */
1768
+ readonly tools: ToolsAPI;
1769
+ /**
1770
+ * Artifact operations (list, get, download, upload, delete)
1771
+ */
1772
+ readonly artifacts: ArtifactsAPI;
1773
+ /**
1774
+ * Session operations (list, get, create, message, delete)
1775
+ */
1776
+ readonly sessions: SessionsAPI;
1777
+ /**
1778
+ * Create a new AI SaaS client
1779
+ *
1780
+ * @param options - Client configuration options
1781
+ *
1782
+ * @example
1783
+ * ```typescript
1784
+ * // API key authentication
1785
+ * const client = new AISaaSClient({
1786
+ * apiKey: 'sk_...',
1787
+ * orgId: 123,
1788
+ * });
1789
+ *
1790
+ * // OAuth token authentication
1791
+ * const client = new AISaaSClient({
1792
+ * token: 'eyJ...',
1793
+ * orgId: 123,
1794
+ * });
1795
+ *
1796
+ * // Token provider (for automatic refresh)
1797
+ * const client = new AISaaSClient({
1798
+ * tokenProvider: async () => myAuth.getAccessToken(),
1799
+ * orgId: 123,
1800
+ * });
1801
+ * ```
1802
+ */
1803
+ constructor(options: AISaaSClientOptions);
1804
+ /**
1805
+ * Validate client options
1806
+ */
1807
+ private validateOptions;
1808
+ }
1809
+
1810
+ /**
1811
+ * SDK Error Classes
1812
+ *
1813
+ * Typed error hierarchy for all SDK operations.
1814
+ * All errors extend AISaaSError and include code, status, and optional details.
1815
+ */
1816
+ /**
1817
+ * Base error class for all SDK errors
1818
+ */
1819
+ declare class AISaaSError extends Error {
1820
+ /** Error code */
1821
+ readonly code: string;
1822
+ /** HTTP status code */
1823
+ readonly status: number;
1824
+ /** Additional error details */
1825
+ readonly details?: Record<string, unknown>;
1826
+ /** Request ID from server (for debugging) */
1827
+ readonly requestId?: string;
1828
+ constructor(message: string, code: string, status: number, details?: Record<string, unknown>, requestId?: string);
1829
+ }
1830
+ /**
1831
+ * Authentication error (401)
1832
+ * Thrown when API key is invalid, expired, or missing
1833
+ */
1834
+ declare class AuthenticationError extends AISaaSError {
1835
+ constructor(message?: string, code?: string, details?: Record<string, unknown>, requestId?: string);
1836
+ }
1837
+ /**
1838
+ * Authorization error (403)
1839
+ * Thrown when user lacks permission for the requested operation
1840
+ */
1841
+ declare class AuthorizationError extends AISaaSError {
1842
+ constructor(message?: string, code?: string, details?: Record<string, unknown>, requestId?: string);
1843
+ }
1844
+ /**
1845
+ * Not found error (404)
1846
+ * Thrown when requested resource does not exist
1847
+ */
1848
+ declare class NotFoundError extends AISaaSError {
1849
+ constructor(message?: string, code?: string, details?: Record<string, unknown>, requestId?: string);
1850
+ }
1851
+ /**
1852
+ * Validation error (400/422)
1853
+ * Thrown when request input is invalid
1854
+ */
1855
+ declare class ValidationError extends AISaaSError {
1856
+ /** Field-level validation errors */
1857
+ readonly errors: Array<{
1858
+ field: string;
1859
+ message: string;
1860
+ }>;
1861
+ constructor(message?: string, errors?: Array<{
1862
+ field: string;
1863
+ message: string;
1864
+ }>, details?: Record<string, unknown>, requestId?: string);
1865
+ }
1866
+ /**
1867
+ * Rate limit error (429)
1868
+ * Thrown when rate limit is exceeded
1869
+ */
1870
+ declare class RateLimitError extends AISaaSError {
1871
+ /** Seconds until rate limit resets */
1872
+ readonly retryAfter?: number;
1873
+ constructor(message?: string, retryAfter?: number, details?: Record<string, unknown>, requestId?: string);
1874
+ }
1875
+ /**
1876
+ * Server error (5xx)
1877
+ * Thrown for server-side errors
1878
+ */
1879
+ declare class ServerError extends AISaaSError {
1880
+ constructor(message?: string, status?: number, details?: Record<string, unknown>, requestId?: string);
1881
+ }
1882
+ /**
1883
+ * Conflict error (409)
1884
+ * Thrown when there is a resource conflict
1885
+ */
1886
+ declare class ConflictError extends AISaaSError {
1887
+ constructor(message?: string, details?: Record<string, unknown>, requestId?: string);
1888
+ }
1889
+ /**
1890
+ * Timeout error
1891
+ * Thrown when a request or operation times out
1892
+ */
1893
+ declare class TimeoutError extends AISaaSError {
1894
+ constructor(message?: string, details?: Record<string, unknown>, requestId?: string);
1895
+ }
1896
+ /**
1897
+ * Network error
1898
+ * Thrown when there is a network connectivity issue
1899
+ */
1900
+ declare class NetworkError extends AISaaSError {
1901
+ constructor(message?: string, details?: Record<string, unknown>);
1902
+ }
1903
+
1904
+ export { AISaaSClient, type AISaaSClientOptions, AISaaSError, type Agent, type AgentConfig, type AgentConfigUpdateInput, type AgentExecution, type AgentListOptions, type AgentStatus, type AgentType, type AgentUpdateInput, type Artifact, type ArtifactDownloadOptions, type ArtifactListOptions, type ArtifactType, type ArtifactUploadInput, AuthenticationError, AuthorizationError, type CompleteEvent, ConflictError, type ConnectionChangeEvent, type ErrorEvent, type ExecuteInput, type ExecuteOptions, type ExecuteResponse, type ExecutionLog, type ExecutionStatus, type ExecutionStreamController, type ExecutionStreamControllerOptions, type JSONSchema, type ListOptions, NetworkError, NotFoundError, type PaginatedResponse, type PaginationInfo, type PlanEvent, RateLimitError, type SendMessageInput, ServerError, type Session, type SessionArtifact, type SessionArtifactListOptions, type SessionArtifactType, type SessionArtifactVariantType, type SessionCreateInput, type SessionHistory, type SessionListOptions, type SessionMessage, type SignedUrlResponse, type Skill, type SkillDetails, type SkillExecuteInput, type SkillExecution, type SkillListOptions, type SkillTool, type SkillUpdateInput, type SkillVariable, type StreamController, type StreamEventMap, TimeoutError, type TokenUsage, type Tool, type ToolCallEvent, type ToolConfigUpdateInput, type ToolExecution, type ToolListOptions, type ToolResultEvent, type ToolUpdateInput, type ToolValidationResult, ValidationError };