@synova-cloud/sdk 1.0.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,564 @@
1
+ type TSynovaMessageRole = 'system' | 'user' | 'assistant' | 'tool';
2
+ type TSynovaResponseType = 'message' | 'tool_calls' | 'image' | 'error';
3
+ type TSynovaModelType = 'text' | 'image';
4
+ interface ISynovaLogger {
5
+ debug: (message: string, ...args: unknown[]) => void;
6
+ info: (message: string, ...args: unknown[]) => void;
7
+ warn: (message: string, ...args: unknown[]) => void;
8
+ error: (messageOrError: string | Error, ...args: unknown[]) => void;
9
+ }
10
+ type TSynovaRetryStrategy = 'exponential' | 'linear';
11
+ interface ISynovaRetryConfig {
12
+ /** Maximum retry attempts (default: 3) */
13
+ maxRetries?: number;
14
+ /** Retry strategy: 'exponential' or 'linear' (default: 'exponential') */
15
+ strategy?: TSynovaRetryStrategy;
16
+ /** Initial delay in milliseconds (default: 1000) */
17
+ initialDelayMs?: number;
18
+ /** Maximum delay in milliseconds (default: 30000) */
19
+ maxDelayMs?: number;
20
+ /** Multiplier for exponential backoff (default: 2) */
21
+ backoffMultiplier?: number;
22
+ }
23
+ interface ISynovaConfig {
24
+ /** Base URL for API (default: https://api.synova.cloud) */
25
+ baseUrl?: string;
26
+ /** Request timeout in milliseconds (default: 30000) */
27
+ timeout?: number;
28
+ /** Retry configuration */
29
+ retry?: ISynovaRetryConfig;
30
+ /** Enable debug logging (default: false) */
31
+ debug?: boolean;
32
+ /** Custom logger (default: console) */
33
+ logger?: ISynovaLogger;
34
+ }
35
+ interface ISynovaPromptVariable {
36
+ name: string;
37
+ type: string;
38
+ description?: string;
39
+ defaultValue?: string;
40
+ }
41
+ interface ISynovaPrompt {
42
+ promptId: string;
43
+ name: string;
44
+ version: string;
45
+ messages: ISynovaMessage[];
46
+ variables: ISynovaPromptVariable[];
47
+ tags: string[];
48
+ createdAt: string;
49
+ }
50
+ interface ISynovaGetPromptOptions {
51
+ /** Tag to retrieve (e.g., 'latest', 'production') */
52
+ tag?: string;
53
+ /** Version to retrieve (e.g., '1.0.0') */
54
+ version?: string;
55
+ }
56
+ interface ISynovaToolCall {
57
+ id: string;
58
+ name: string;
59
+ arguments: Record<string, unknown>;
60
+ }
61
+ interface ISynovaToolResult {
62
+ /** ID of the tool call this result responds to */
63
+ toolCallId: string;
64
+ /** Result content (typically JSON stringified) */
65
+ content: string;
66
+ }
67
+ interface ISynovaMessage {
68
+ role: TSynovaMessageRole;
69
+ /** Message content (required for user/assistant, optional for tool) */
70
+ content?: string;
71
+ /** Structured object (for assistant messages with responseSchema) */
72
+ object?: unknown;
73
+ /** Tool call ID (for tool messages) */
74
+ toolCallId?: string;
75
+ /** Tool calls requested by assistant (when role='assistant') */
76
+ toolCalls?: ISynovaToolCall[];
77
+ /** Tool execution results (when role='tool') */
78
+ toolResults?: ISynovaToolResult[];
79
+ /** File attachments (images, PDFs, text files) */
80
+ files?: ISynovaFileAttachment[];
81
+ }
82
+ interface ISynovaExecuteOptions {
83
+ /** LLM provider (e.g., 'openai', 'anthropic', 'google', 'azure_openai', 'deepseek') */
84
+ provider: string;
85
+ /** LLM model to use (e.g., 'gpt-4o', 'claude-sonnet-4-20250514') */
86
+ model: string;
87
+ /** Variables to substitute in prompt template */
88
+ variables?: Record<string, unknown>;
89
+ /** Previous messages for multi-turn conversation */
90
+ messages?: ISynovaMessage[];
91
+ /** Version tag (e.g., 'latest', 'production', 'staging') */
92
+ tag?: string;
93
+ /** Specific version number (e.g., '1.2.0') - takes precedence over tag */
94
+ version?: string;
95
+ /** Custom metadata for tracking/filtering in analytics */
96
+ metadata?: Record<string, string>;
97
+ /** Model parameters (temperature, maxTokens, topP, topK, etc.) */
98
+ parameters?: Record<string, unknown>;
99
+ /** JSON Schema for structured output */
100
+ responseSchema?: Record<string, unknown>;
101
+ }
102
+ interface ISynovaUsage {
103
+ inputTokens: number;
104
+ outputTokens: number;
105
+ totalTokens: number;
106
+ }
107
+ interface ISynovaExecutionError {
108
+ code: string;
109
+ message: string;
110
+ provider?: string;
111
+ retryable: boolean;
112
+ retryAfterMs?: number;
113
+ details?: unknown;
114
+ }
115
+ interface ISynovaFileThumbnails {
116
+ /** Small thumbnail URL (120px width) */
117
+ small?: string;
118
+ /** Medium thumbnail URL (240px width) */
119
+ medium?: string;
120
+ /** Large thumbnail URL (480px width) */
121
+ large?: string;
122
+ }
123
+ interface ISynovaFileAttachment {
124
+ /** Reference to uploaded file by ID */
125
+ fileId?: string;
126
+ /** File URL */
127
+ url?: string;
128
+ /** MIME type (e.g., 'image/png', 'application/pdf') */
129
+ mimeType?: string;
130
+ /** Thumbnail URLs for images */
131
+ thumbnails?: ISynovaFileThumbnails;
132
+ }
133
+ interface ISynovaExecuteResponse {
134
+ type: TSynovaResponseType;
135
+ /** Text content (when type='message') */
136
+ content?: string;
137
+ /** Structured output object (when responseSchema provided) */
138
+ object?: unknown;
139
+ /** Tool calls requested by LLM (when type='tool_calls') */
140
+ toolCalls?: ISynovaToolCall[];
141
+ /** Generated files/images (when type='image') */
142
+ files?: ISynovaFileAttachment[];
143
+ /** Error details (when type='error') */
144
+ error?: ISynovaExecutionError;
145
+ /** Token usage statistics */
146
+ usage?: ISynovaUsage;
147
+ }
148
+ interface ISynovaModelCapabilities {
149
+ text_generation?: boolean;
150
+ function_calling?: boolean;
151
+ vision?: boolean;
152
+ json_mode?: boolean;
153
+ streaming?: boolean;
154
+ reasoning?: boolean;
155
+ extended_thinking?: boolean;
156
+ text_to_image?: boolean;
157
+ image_to_image?: boolean;
158
+ }
159
+ interface ISynovaModelLimits {
160
+ context_window?: number;
161
+ max_output_tokens?: number;
162
+ }
163
+ interface ISynovaModelPricing {
164
+ effective_from: string;
165
+ input?: number;
166
+ output?: number;
167
+ per_image?: number;
168
+ }
169
+ interface ISynovaModel {
170
+ id: string;
171
+ provider: string;
172
+ display_name: string;
173
+ type: TSynovaModelType;
174
+ capabilities: ISynovaModelCapabilities;
175
+ limits: ISynovaModelLimits;
176
+ pricing?: ISynovaModelPricing[];
177
+ deprecated_from?: string;
178
+ }
179
+ interface ISynovaProvider {
180
+ id: string;
181
+ display_name: string;
182
+ models: ISynovaModel[];
183
+ }
184
+ interface ISynovaModelsResponse {
185
+ providers: ISynovaProvider[];
186
+ }
187
+ interface ISynovaListModelsOptions {
188
+ /** Filter by model type */
189
+ type?: TSynovaModelType;
190
+ /** Filter by capability */
191
+ capability?: keyof ISynovaModelCapabilities;
192
+ /** Filter by provider */
193
+ provider?: string;
194
+ }
195
+ interface ISynovaUploadedFile {
196
+ /** File ID */
197
+ id: string;
198
+ /** URL for file access */
199
+ url: string;
200
+ /** Thumbnail URL for preview */
201
+ thumbnailUrl?: string;
202
+ /** Original file name */
203
+ originalName: string;
204
+ /** MIME type (e.g., 'image/png', 'application/pdf') */
205
+ mimeType: string;
206
+ /** File size in bytes */
207
+ size: number;
208
+ /** File category ('image', 'video', 'audio', 'document', 'other') */
209
+ fileCategory: string;
210
+ /** Creation date (ISO 8601) */
211
+ createdAt: string;
212
+ }
213
+ interface ISynovaUploadResponse {
214
+ /** Uploaded files */
215
+ data: ISynovaUploadedFile[];
216
+ }
217
+ interface ISynovaUploadOptions {
218
+ /** Project ID to associate files with */
219
+ projectId: string;
220
+ }
221
+ interface IApiErrorResponse {
222
+ code: string;
223
+ httpCode: number;
224
+ message: string;
225
+ requestId: string;
226
+ timestamp: string;
227
+ }
228
+
229
+ interface IRetryOptions {
230
+ maxRetries: number;
231
+ strategy: TSynovaRetryStrategy;
232
+ initialDelayMs: number;
233
+ maxDelayMs: number;
234
+ backoffMultiplier: number;
235
+ }
236
+ interface IHttpClientConfig {
237
+ baseUrl: string;
238
+ apiKey: string;
239
+ timeout: number;
240
+ retry: IRetryOptions;
241
+ debug: boolean;
242
+ logger: ISynovaLogger;
243
+ }
244
+ interface IRequestOptions {
245
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE';
246
+ path: string;
247
+ body?: unknown;
248
+ query?: Record<string, string | undefined>;
249
+ }
250
+ interface IUploadOptions {
251
+ path: string;
252
+ formData: FormData;
253
+ }
254
+ declare class HttpClient {
255
+ private readonly config;
256
+ constructor(config: IHttpClientConfig);
257
+ request<T>(options: IRequestOptions): Promise<T>;
258
+ upload<T>(options: IUploadOptions): Promise<T>;
259
+ private makeRequest;
260
+ private makeUploadRequest;
261
+ private handleErrorResponse;
262
+ private buildUrl;
263
+ private isRetryable;
264
+ private calculateRetryDelay;
265
+ private sleep;
266
+ private log;
267
+ }
268
+
269
+ declare class PromptsResource {
270
+ private readonly http;
271
+ constructor(http: HttpClient);
272
+ /**
273
+ * Get a prompt by ID (returns version with 'latest' tag)
274
+ *
275
+ * @param promptId - The prompt ID (e.g., 'prm_abc123')
276
+ * @param options - Optional settings
277
+ * @returns The prompt data
278
+ *
279
+ * @example
280
+ * ```ts
281
+ * // Get default (latest) version
282
+ * const prompt = await client.prompts.get('prm_abc123');
283
+ *
284
+ * // Get by specific tag
285
+ * const production = await client.prompts.get('prm_abc123', { tag: 'production' });
286
+ *
287
+ * // Get specific version
288
+ * const v2 = await client.prompts.get('prm_abc123', { version: '2.0.0' });
289
+ * ```
290
+ */
291
+ get(promptId: string, options?: ISynovaGetPromptOptions): Promise<ISynovaPrompt>;
292
+ /**
293
+ * Execute a prompt with 'latest' tag
294
+ *
295
+ * @param promptId - The prompt ID
296
+ * @param options - Execution options including provider, model and variables
297
+ * @returns The execution response
298
+ *
299
+ * @example
300
+ * ```ts
301
+ * const result = await client.prompts.execute('prm_abc123', {
302
+ * provider: 'openai',
303
+ * model: 'gpt-4o',
304
+ * variables: { topic: 'TypeScript' },
305
+ * });
306
+ *
307
+ * if (result.type === 'message') {
308
+ * console.log(result.content);
309
+ * }
310
+ *
311
+ * // Image generation
312
+ * const imageResult = await client.prompts.execute('prm_image123', {
313
+ * provider: 'google',
314
+ * model: 'gemini-2.0-flash-exp',
315
+ * variables: { style: 'modern' },
316
+ * });
317
+ *
318
+ * if (imageResult.type === 'image') {
319
+ * console.log('Generated images:', imageResult.files);
320
+ * }
321
+ * ```
322
+ */
323
+ execute(promptId: string, options: ISynovaExecuteOptions): Promise<ISynovaExecuteResponse>;
324
+ /**
325
+ * Execute a prompt by tag
326
+ *
327
+ * @param promptId - The prompt ID
328
+ * @param tag - The tag (e.g., 'latest', 'production', 'staging')
329
+ * @param options - Execution options
330
+ * @returns The execution response
331
+ *
332
+ * @example
333
+ * ```ts
334
+ * const result = await client.prompts.executeByTag('prm_abc123', 'production', {
335
+ * provider: 'openai',
336
+ * model: 'gpt-4o',
337
+ * variables: { topic: 'TypeScript' },
338
+ * });
339
+ * ```
340
+ */
341
+ executeByTag(promptId: string, tag: string, options: ISynovaExecuteOptions): Promise<ISynovaExecuteResponse>;
342
+ /**
343
+ * Execute a prompt by version
344
+ *
345
+ * @param promptId - The prompt ID
346
+ * @param version - The semantic version (e.g., '1.0.0', '2.1.0')
347
+ * @param options - Execution options
348
+ * @returns The execution response
349
+ *
350
+ * @example
351
+ * ```ts
352
+ * const result = await client.prompts.executeByVersion('prm_abc123', '1.2.0', {
353
+ * provider: 'openai',
354
+ * model: 'gpt-4o',
355
+ * variables: { topic: 'TypeScript' },
356
+ * });
357
+ * ```
358
+ */
359
+ executeByVersion(promptId: string, version: string, options: ISynovaExecuteOptions): Promise<ISynovaExecuteResponse>;
360
+ }
361
+
362
+ declare class ModelsResource {
363
+ private readonly http;
364
+ constructor(http: HttpClient);
365
+ /**
366
+ * List all available models
367
+ *
368
+ * @param options - Optional filters
369
+ * @returns List of providers with their models
370
+ *
371
+ * @example
372
+ * ```ts
373
+ * // Get all models
374
+ * const { providers } = await client.models.list();
375
+ *
376
+ * // Filter by type
377
+ * const imageModels = await client.models.list({ type: 'image' });
378
+ *
379
+ * // Filter by capability
380
+ * const functionCallingModels = await client.models.list({
381
+ * capability: 'function_calling',
382
+ * });
383
+ *
384
+ * // Filter by provider
385
+ * const openaiModels = await client.models.list({ provider: 'openai' });
386
+ * ```
387
+ */
388
+ list(options?: ISynovaListModelsOptions): Promise<ISynovaModelsResponse>;
389
+ /**
390
+ * Get models for a specific provider
391
+ *
392
+ * @param provider - Provider ID (e.g., 'openai', 'anthropic')
393
+ * @returns List of models for the provider
394
+ *
395
+ * @example
396
+ * ```ts
397
+ * const { models } = await client.models.getByProvider('openai');
398
+ * ```
399
+ */
400
+ getByProvider(provider: string): Promise<ISynovaModel[]>;
401
+ /**
402
+ * Get a specific model
403
+ *
404
+ * @param provider - Provider ID
405
+ * @param model - Model ID
406
+ * @returns Model details
407
+ *
408
+ * @example
409
+ * ```ts
410
+ * const model = await client.models.get('openai', 'gpt-4o');
411
+ * console.log(model.capabilities);
412
+ * console.log(model.limits);
413
+ * ```
414
+ */
415
+ get(provider: string, model: string): Promise<ISynovaModel>;
416
+ }
417
+
418
+ declare class FilesResource {
419
+ private readonly http;
420
+ constructor(http: HttpClient);
421
+ /**
422
+ * Upload files for use in prompt execution
423
+ *
424
+ * @param files - Array of File or Blob objects to upload
425
+ * @param options - Upload options including projectId
426
+ * @returns Upload response with file metadata
427
+ *
428
+ * @example
429
+ * ```ts
430
+ * // Upload files
431
+ * const result = await client.files.upload(
432
+ * [file1, file2],
433
+ * { projectId: 'prj_abc123' }
434
+ * );
435
+ *
436
+ * console.log('Uploaded files:', result.data);
437
+ *
438
+ * // Use uploaded file in prompt execution
439
+ * const response = await client.prompts.execute('prm_abc123', {
440
+ * provider: 'openai',
441
+ * model: 'gpt-4o',
442
+ * messages: [
443
+ * {
444
+ * role: 'user',
445
+ * content: 'Describe this image',
446
+ * files: [{ fileId: result.data[0].id }],
447
+ * },
448
+ * ],
449
+ * });
450
+ * ```
451
+ */
452
+ upload(files: (File | Blob)[], options: ISynovaUploadOptions): Promise<ISynovaUploadResponse>;
453
+ }
454
+
455
+ /**
456
+ * Synova Cloud SDK client
457
+ *
458
+ * @example
459
+ * ```ts
460
+ * import { SynovaCloudSdk } from '@synova-cloud/sdk';
461
+ *
462
+ * const client = new SynovaCloudSdk('your-api-key');
463
+ *
464
+ * // Get a prompt
465
+ * const prompt = await client.prompts.get('prm_abc123');
466
+ *
467
+ * // Execute a prompt
468
+ * const result = await client.prompts.execute('prm_abc123', {
469
+ * provider: 'openai',
470
+ * model: 'gpt-4o',
471
+ * variables: { topic: 'TypeScript' },
472
+ * });
473
+ *
474
+ * // List available models
475
+ * const { providers } = await client.models.list();
476
+ *
477
+ * // Get models for a specific provider
478
+ * const openaiModels = await client.models.getByProvider('openai');
479
+ *
480
+ * // With custom retry config
481
+ * const clientWithRetry = new SynovaCloudSdk('your-api-key', {
482
+ * retry: {
483
+ * maxRetries: 5,
484
+ * strategy: 'linear',
485
+ * initialDelayMs: 500,
486
+ * },
487
+ * });
488
+ * ```
489
+ */
490
+ declare class SynovaCloudSdk {
491
+ readonly prompts: PromptsResource;
492
+ readonly models: ModelsResource;
493
+ readonly files: FilesResource;
494
+ private readonly http;
495
+ /**
496
+ * Create a new Synova Cloud SDK client
497
+ *
498
+ * @param apiKey - Your Synova API key
499
+ * @param config - Optional configuration
500
+ */
501
+ constructor(apiKey: string, config?: ISynovaConfig);
502
+ }
503
+
504
+ /**
505
+ * Base error class for all Synova SDK errors
506
+ */
507
+ declare class SynovaError extends Error {
508
+ constructor(message: string);
509
+ }
510
+ /**
511
+ * Error thrown when API returns an error response
512
+ */
513
+ declare class ApiSynovaError extends SynovaError {
514
+ readonly code: string;
515
+ readonly httpCode: number;
516
+ readonly requestId: string;
517
+ readonly timestamp: string;
518
+ constructor(response: IApiErrorResponse);
519
+ }
520
+ /**
521
+ * Error thrown when authentication fails
522
+ */
523
+ declare class AuthSynovaError extends SynovaError {
524
+ constructor(message?: string);
525
+ }
526
+ /**
527
+ * Error thrown when resource is not found
528
+ */
529
+ declare class NotFoundSynovaError extends SynovaError {
530
+ readonly resourceType: string;
531
+ readonly resourceId: string;
532
+ constructor(resourceType: string, resourceId: string);
533
+ }
534
+ /**
535
+ * Error thrown when rate limit is exceeded
536
+ */
537
+ declare class RateLimitSynovaError extends SynovaError {
538
+ readonly retryAfterMs?: number;
539
+ constructor(message?: string, retryAfterMs?: number);
540
+ }
541
+ /**
542
+ * Error thrown when request times out
543
+ */
544
+ declare class TimeoutSynovaError extends SynovaError {
545
+ readonly timeoutMs: number;
546
+ constructor(timeoutMs: number);
547
+ }
548
+ /**
549
+ * Error thrown when network request fails
550
+ */
551
+ declare class NetworkSynovaError extends SynovaError {
552
+ readonly cause?: Error;
553
+ constructor(message: string, cause?: Error);
554
+ }
555
+ /**
556
+ * Error thrown when server returns 5xx error
557
+ */
558
+ declare class ServerSynovaError extends SynovaError {
559
+ readonly httpCode: number;
560
+ readonly retryable: boolean;
561
+ constructor(httpCode: number, message?: string);
562
+ }
563
+
564
+ export { ApiSynovaError, AuthSynovaError, type ISynovaConfig, type ISynovaExecuteOptions, type ISynovaExecuteResponse, type ISynovaExecutionError, type ISynovaFileAttachment, type ISynovaFileThumbnails, type ISynovaGetPromptOptions, type ISynovaListModelsOptions, type ISynovaLogger, type ISynovaMessage, type ISynovaModel, type ISynovaModelCapabilities, type ISynovaModelLimits, type ISynovaModelPricing, type ISynovaModelsResponse, type ISynovaPrompt, type ISynovaPromptVariable, type ISynovaProvider, type ISynovaRetryConfig, type ISynovaToolCall, type ISynovaToolResult, type ISynovaUploadOptions, type ISynovaUploadResponse, type ISynovaUploadedFile, type ISynovaUsage, NetworkSynovaError, NotFoundSynovaError, RateLimitSynovaError, ServerSynovaError, SynovaCloudSdk, SynovaError, type TSynovaMessageRole, type TSynovaModelType, type TSynovaResponseType, type TSynovaRetryStrategy, TimeoutSynovaError };