sonilo 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -51,6 +51,11 @@ interface TextToMusicParams {
51
51
  prompt: string;
52
52
  duration: number;
53
53
  segments?: Segment[];
54
+ /** Bounds the stream: aborting this cancels the in-flight generation.
55
+ * Passed straight through to `fetch` — it is never rewrapped as
56
+ * RequestTimeoutError, since the client's own absolute timeout does not
57
+ * apply to streaming music generation. */
58
+ signal?: AbortSignal;
54
59
  }
55
60
  /** string = file path (Node.js only). */
56
61
  type VideoInput = File | Blob | Uint8Array | ArrayBuffer | ReadableStream<Uint8Array> | string;
@@ -59,6 +64,11 @@ interface VideoToMusicParams {
59
64
  videoUrl?: string;
60
65
  prompt?: string;
61
66
  segments?: Segment[];
67
+ /** Bounds the stream: aborting this cancels the in-flight generation.
68
+ * Passed straight through to `fetch` — it is never rewrapped as
69
+ * RequestTimeoutError, since the client's own absolute timeout does not
70
+ * apply to streaming music generation. */
71
+ signal?: AbortSignal;
62
72
  }
63
73
  interface AccountServices {
64
74
  available_services: string[];
@@ -87,6 +97,61 @@ interface UsageResponse {
87
97
  }
88
98
  declare function isAudioChunkEvent(event: StreamEvent): event is AudioChunkEvent;
89
99
  declare function isErrorEvent(event: StreamEvent): event is ErrorEvent;
100
+ /** SFX segments (unlike music `Segment`) require `end`, must start at 0,
101
+ * and be contiguous; validated server-side. */
102
+ interface SfxSegment {
103
+ start: number;
104
+ end: number;
105
+ prompt: string;
106
+ }
107
+ type SfxAudioFormat = "wav" | "mp3" | "aac" | "flac";
108
+ /** Submission ack for the async SFX endpoints. */
109
+ interface SfxTask {
110
+ task_id: string;
111
+ status: string;
112
+ }
113
+ /** A generated file re-hosted on R2 behind a presigned URL. */
114
+ interface SfxMedia {
115
+ url: string;
116
+ content_type?: string;
117
+ file_size?: number;
118
+ }
119
+ interface SfxError {
120
+ code?: string;
121
+ message?: string;
122
+ }
123
+ /** State of an SFX task (`tasks.get`) or its final result (`wait`/`generate`). */
124
+ interface SfxResult {
125
+ task_id: string;
126
+ type?: string;
127
+ status: "processing" | "succeeded" | "failed" | (string & {});
128
+ audio?: SfxMedia;
129
+ /** Kept for backward compatibility; no longer populated — video-to-sfx returns audio only. */
130
+ video?: SfxMedia;
131
+ /** Only present when the account's task-field whitelist enables cost. */
132
+ cost?: number;
133
+ error?: SfxError;
134
+ refunded?: boolean;
135
+ [key: string]: unknown;
136
+ }
137
+ interface TextToSfxParams {
138
+ prompt: string;
139
+ duration: number;
140
+ audioFormat?: SfxAudioFormat;
141
+ }
142
+ interface VideoToSfxParams {
143
+ video?: VideoInput;
144
+ videoUrl?: string;
145
+ prompt?: string;
146
+ segments?: SfxSegment[];
147
+ audioFormat?: SfxAudioFormat;
148
+ }
149
+ interface WaitOptions {
150
+ /** Milliseconds between polls. Default 2000. */
151
+ pollInterval?: number;
152
+ /** Overall deadline in milliseconds. Default 600000. */
153
+ timeout?: number;
154
+ }
90
155
 
91
156
  declare class Account {
92
157
  private readonly client;
@@ -97,6 +162,15 @@ declare class Account {
97
162
  }): Promise<UsageResponse>;
98
163
  }
99
164
 
165
+ declare class Tasks {
166
+ private readonly client;
167
+ constructor(client: SoniloClient);
168
+ /** Fetch current task state. Never throws on a failed status. */
169
+ get(taskId: string): Promise<SfxResult>;
170
+ /** Poll until the task is terminal; throw on failure or deadline. */
171
+ wait(taskId: string, opts?: WaitOptions): Promise<SfxResult>;
172
+ }
173
+
100
174
  declare class TextToMusic {
101
175
  private readonly client;
102
176
  constructor(client: SoniloClient);
@@ -113,6 +187,20 @@ declare class VideoToMusic {
113
187
  generate(params: VideoToMusicParams): Promise<Track>;
114
188
  }
115
189
 
190
+ declare class TextToSfx {
191
+ private readonly client;
192
+ constructor(client: SoniloClient);
193
+ submit(params: TextToSfxParams): Promise<SfxTask>;
194
+ generate(params: TextToSfxParams, opts?: WaitOptions): Promise<SfxResult>;
195
+ }
196
+
197
+ declare class VideoToSfx {
198
+ private readonly client;
199
+ constructor(client: SoniloClient);
200
+ submit(params: VideoToSfxParams): Promise<SfxTask>;
201
+ generate(params: VideoToSfxParams, opts?: WaitOptions): Promise<SfxResult>;
202
+ }
203
+
116
204
  interface SoniloClientOptions {
117
205
  /** Defaults to the SONILO_API_KEY environment variable (Node.js only). */
118
206
  apiKey?: string;
@@ -120,17 +208,34 @@ interface SoniloClientOptions {
120
208
  baseUrl?: string;
121
209
  /** Injection point for tests and custom transports. */
122
210
  fetch?: typeof globalThis.fetch;
211
+ /** Milliseconds before an in-flight request is aborted. Default 600000. */
212
+ timeout?: number;
123
213
  }
214
+ /** Milliseconds before an in-flight request is aborted, unless overridden. */
215
+ declare const DEFAULT_TIMEOUT_MS = 600000;
124
216
  declare class SoniloClient {
125
217
  readonly baseUrl: string;
126
218
  private readonly apiKey;
127
219
  private readonly fetchFn;
220
+ private readonly timeout;
128
221
  readonly account: Account;
222
+ readonly tasks: Tasks;
129
223
  readonly textToMusic: TextToMusic;
130
224
  readonly videoToMusic: VideoToMusic;
225
+ readonly textToSfx: TextToSfx;
226
+ readonly videoToSfx: VideoToSfx;
131
227
  constructor(options?: SoniloClientOptions);
132
- /** Perform an authenticated request; throws a typed error on non-2xx. */
133
- request(path: string, init?: RequestInit): Promise<Response>;
228
+ /**
229
+ * Perform an authenticated request; throws a typed error on non-2xx.
230
+ *
231
+ * `opts.timeout` overrides the client's default timeout for this call;
232
+ * pass `null` to disable the abort-on-timeout behavior entirely (used by
233
+ * the streaming music endpoints — see textToMusic.ts / videoToMusic.ts).
234
+ * A caller-supplied `init.signal` always wins over any timeout signal.
235
+ */
236
+ request(path: string, init?: RequestInit, opts?: {
237
+ timeout?: number | null;
238
+ }): Promise<Response>;
134
239
  }
135
240
 
136
241
  declare class SoniloError extends Error {
@@ -139,6 +244,10 @@ declare class SoniloError extends Error {
139
244
  declare class APIError extends SoniloError {
140
245
  readonly status: number;
141
246
  readonly body: unknown;
247
+ /** The API's typed error code (e.g. "rate_limit_exceeded"), distinct from the HTTP status. */
248
+ readonly code?: string;
249
+ /** Per-field validation details, present on a 422. */
250
+ readonly errors?: unknown[];
142
251
  constructor(message: string, status: number, body?: unknown);
143
252
  }
144
253
  declare class AuthenticationError extends APIError {
@@ -157,7 +266,32 @@ declare class GenerationError extends SoniloError {
157
266
  readonly code?: string;
158
267
  constructor(message: string, code?: string);
159
268
  }
269
+ /** Raised by tasks.wait()/generate() when an SFX task reaches `failed`. */
270
+ declare class TaskFailedError extends SoniloError {
271
+ readonly code?: string;
272
+ readonly taskId: string;
273
+ readonly refunded?: boolean;
274
+ constructor(message: string, opts: {
275
+ code?: string;
276
+ taskId: string;
277
+ refunded?: boolean;
278
+ });
279
+ }
280
+ /** Poll deadline passed. The task may still finish server-side — resume with
281
+ * tasks.wait(taskId) or tasks.get(taskId). */
282
+ declare class TaskTimeoutError extends SoniloError {
283
+ readonly taskId: string;
284
+ constructor(message: string, taskId: string);
285
+ }
286
+ /** Raised when a one-shot request or download is aborted by its own timeout
287
+ * signal (as opposed to a caller-supplied AbortSignal, which propagates
288
+ * untouched). */
289
+ declare class RequestTimeoutError extends SoniloError {
290
+ }
291
+
292
+ /** Fetch a result media file. The URL is presigned — no API key is sent. */
293
+ declare function download(media: SfxMedia | undefined, fetchFn?: typeof globalThis.fetch, timeout?: number): Promise<Uint8Array>;
160
294
 
161
- declare const VERSION = "0.1.0";
295
+ declare const VERSION = "0.2.0";
162
296
 
163
- export { APIError, type AccountServices, type AudioChunkEvent, AuthenticationError, BadRequestError, type CompleteEvent, type CostEvent, type CostInfo, type DailyUsage, type ErrorEvent, GenerationError, PaymentRequiredError, RateLimitError, type Segment, type SegmentLabel, SoniloClient, type SoniloClientOptions, SoniloError, type StreamEvent, type TextToMusicParams, type TitleEvent, type Track, type UnknownEvent, type UsageResponse, type UsageSummary, VERSION, type VideoInput, type VideoToMusicParams, isAudioChunkEvent, isErrorEvent };
297
+ export { APIError, type AccountServices, type AudioChunkEvent, AuthenticationError, BadRequestError, type CompleteEvent, type CostEvent, type CostInfo, DEFAULT_TIMEOUT_MS, type DailyUsage, type ErrorEvent, GenerationError, PaymentRequiredError, RateLimitError, RequestTimeoutError, type Segment, type SegmentLabel, type SfxAudioFormat, type SfxError, type SfxMedia, type SfxResult, type SfxSegment, type SfxTask, SoniloClient, type SoniloClientOptions, SoniloError, type StreamEvent, TaskFailedError, TaskTimeoutError, type TextToMusicParams, type TextToSfxParams, type TitleEvent, type Track, type UnknownEvent, type UsageResponse, type UsageSummary, VERSION, type VideoInput, type VideoToMusicParams, type VideoToSfxParams, type WaitOptions, download, isAudioChunkEvent, isErrorEvent };
package/dist/index.d.ts CHANGED
@@ -51,6 +51,11 @@ interface TextToMusicParams {
51
51
  prompt: string;
52
52
  duration: number;
53
53
  segments?: Segment[];
54
+ /** Bounds the stream: aborting this cancels the in-flight generation.
55
+ * Passed straight through to `fetch` — it is never rewrapped as
56
+ * RequestTimeoutError, since the client's own absolute timeout does not
57
+ * apply to streaming music generation. */
58
+ signal?: AbortSignal;
54
59
  }
55
60
  /** string = file path (Node.js only). */
56
61
  type VideoInput = File | Blob | Uint8Array | ArrayBuffer | ReadableStream<Uint8Array> | string;
@@ -59,6 +64,11 @@ interface VideoToMusicParams {
59
64
  videoUrl?: string;
60
65
  prompt?: string;
61
66
  segments?: Segment[];
67
+ /** Bounds the stream: aborting this cancels the in-flight generation.
68
+ * Passed straight through to `fetch` — it is never rewrapped as
69
+ * RequestTimeoutError, since the client's own absolute timeout does not
70
+ * apply to streaming music generation. */
71
+ signal?: AbortSignal;
62
72
  }
63
73
  interface AccountServices {
64
74
  available_services: string[];
@@ -87,6 +97,61 @@ interface UsageResponse {
87
97
  }
88
98
  declare function isAudioChunkEvent(event: StreamEvent): event is AudioChunkEvent;
89
99
  declare function isErrorEvent(event: StreamEvent): event is ErrorEvent;
100
+ /** SFX segments (unlike music `Segment`) require `end`, must start at 0,
101
+ * and be contiguous; validated server-side. */
102
+ interface SfxSegment {
103
+ start: number;
104
+ end: number;
105
+ prompt: string;
106
+ }
107
+ type SfxAudioFormat = "wav" | "mp3" | "aac" | "flac";
108
+ /** Submission ack for the async SFX endpoints. */
109
+ interface SfxTask {
110
+ task_id: string;
111
+ status: string;
112
+ }
113
+ /** A generated file re-hosted on R2 behind a presigned URL. */
114
+ interface SfxMedia {
115
+ url: string;
116
+ content_type?: string;
117
+ file_size?: number;
118
+ }
119
+ interface SfxError {
120
+ code?: string;
121
+ message?: string;
122
+ }
123
+ /** State of an SFX task (`tasks.get`) or its final result (`wait`/`generate`). */
124
+ interface SfxResult {
125
+ task_id: string;
126
+ type?: string;
127
+ status: "processing" | "succeeded" | "failed" | (string & {});
128
+ audio?: SfxMedia;
129
+ /** Kept for backward compatibility; no longer populated — video-to-sfx returns audio only. */
130
+ video?: SfxMedia;
131
+ /** Only present when the account's task-field whitelist enables cost. */
132
+ cost?: number;
133
+ error?: SfxError;
134
+ refunded?: boolean;
135
+ [key: string]: unknown;
136
+ }
137
+ interface TextToSfxParams {
138
+ prompt: string;
139
+ duration: number;
140
+ audioFormat?: SfxAudioFormat;
141
+ }
142
+ interface VideoToSfxParams {
143
+ video?: VideoInput;
144
+ videoUrl?: string;
145
+ prompt?: string;
146
+ segments?: SfxSegment[];
147
+ audioFormat?: SfxAudioFormat;
148
+ }
149
+ interface WaitOptions {
150
+ /** Milliseconds between polls. Default 2000. */
151
+ pollInterval?: number;
152
+ /** Overall deadline in milliseconds. Default 600000. */
153
+ timeout?: number;
154
+ }
90
155
 
91
156
  declare class Account {
92
157
  private readonly client;
@@ -97,6 +162,15 @@ declare class Account {
97
162
  }): Promise<UsageResponse>;
98
163
  }
99
164
 
165
+ declare class Tasks {
166
+ private readonly client;
167
+ constructor(client: SoniloClient);
168
+ /** Fetch current task state. Never throws on a failed status. */
169
+ get(taskId: string): Promise<SfxResult>;
170
+ /** Poll until the task is terminal; throw on failure or deadline. */
171
+ wait(taskId: string, opts?: WaitOptions): Promise<SfxResult>;
172
+ }
173
+
100
174
  declare class TextToMusic {
101
175
  private readonly client;
102
176
  constructor(client: SoniloClient);
@@ -113,6 +187,20 @@ declare class VideoToMusic {
113
187
  generate(params: VideoToMusicParams): Promise<Track>;
114
188
  }
115
189
 
190
+ declare class TextToSfx {
191
+ private readonly client;
192
+ constructor(client: SoniloClient);
193
+ submit(params: TextToSfxParams): Promise<SfxTask>;
194
+ generate(params: TextToSfxParams, opts?: WaitOptions): Promise<SfxResult>;
195
+ }
196
+
197
+ declare class VideoToSfx {
198
+ private readonly client;
199
+ constructor(client: SoniloClient);
200
+ submit(params: VideoToSfxParams): Promise<SfxTask>;
201
+ generate(params: VideoToSfxParams, opts?: WaitOptions): Promise<SfxResult>;
202
+ }
203
+
116
204
  interface SoniloClientOptions {
117
205
  /** Defaults to the SONILO_API_KEY environment variable (Node.js only). */
118
206
  apiKey?: string;
@@ -120,17 +208,34 @@ interface SoniloClientOptions {
120
208
  baseUrl?: string;
121
209
  /** Injection point for tests and custom transports. */
122
210
  fetch?: typeof globalThis.fetch;
211
+ /** Milliseconds before an in-flight request is aborted. Default 600000. */
212
+ timeout?: number;
123
213
  }
214
+ /** Milliseconds before an in-flight request is aborted, unless overridden. */
215
+ declare const DEFAULT_TIMEOUT_MS = 600000;
124
216
  declare class SoniloClient {
125
217
  readonly baseUrl: string;
126
218
  private readonly apiKey;
127
219
  private readonly fetchFn;
220
+ private readonly timeout;
128
221
  readonly account: Account;
222
+ readonly tasks: Tasks;
129
223
  readonly textToMusic: TextToMusic;
130
224
  readonly videoToMusic: VideoToMusic;
225
+ readonly textToSfx: TextToSfx;
226
+ readonly videoToSfx: VideoToSfx;
131
227
  constructor(options?: SoniloClientOptions);
132
- /** Perform an authenticated request; throws a typed error on non-2xx. */
133
- request(path: string, init?: RequestInit): Promise<Response>;
228
+ /**
229
+ * Perform an authenticated request; throws a typed error on non-2xx.
230
+ *
231
+ * `opts.timeout` overrides the client's default timeout for this call;
232
+ * pass `null` to disable the abort-on-timeout behavior entirely (used by
233
+ * the streaming music endpoints — see textToMusic.ts / videoToMusic.ts).
234
+ * A caller-supplied `init.signal` always wins over any timeout signal.
235
+ */
236
+ request(path: string, init?: RequestInit, opts?: {
237
+ timeout?: number | null;
238
+ }): Promise<Response>;
134
239
  }
135
240
 
136
241
  declare class SoniloError extends Error {
@@ -139,6 +244,10 @@ declare class SoniloError extends Error {
139
244
  declare class APIError extends SoniloError {
140
245
  readonly status: number;
141
246
  readonly body: unknown;
247
+ /** The API's typed error code (e.g. "rate_limit_exceeded"), distinct from the HTTP status. */
248
+ readonly code?: string;
249
+ /** Per-field validation details, present on a 422. */
250
+ readonly errors?: unknown[];
142
251
  constructor(message: string, status: number, body?: unknown);
143
252
  }
144
253
  declare class AuthenticationError extends APIError {
@@ -157,7 +266,32 @@ declare class GenerationError extends SoniloError {
157
266
  readonly code?: string;
158
267
  constructor(message: string, code?: string);
159
268
  }
269
+ /** Raised by tasks.wait()/generate() when an SFX task reaches `failed`. */
270
+ declare class TaskFailedError extends SoniloError {
271
+ readonly code?: string;
272
+ readonly taskId: string;
273
+ readonly refunded?: boolean;
274
+ constructor(message: string, opts: {
275
+ code?: string;
276
+ taskId: string;
277
+ refunded?: boolean;
278
+ });
279
+ }
280
+ /** Poll deadline passed. The task may still finish server-side — resume with
281
+ * tasks.wait(taskId) or tasks.get(taskId). */
282
+ declare class TaskTimeoutError extends SoniloError {
283
+ readonly taskId: string;
284
+ constructor(message: string, taskId: string);
285
+ }
286
+ /** Raised when a one-shot request or download is aborted by its own timeout
287
+ * signal (as opposed to a caller-supplied AbortSignal, which propagates
288
+ * untouched). */
289
+ declare class RequestTimeoutError extends SoniloError {
290
+ }
291
+
292
+ /** Fetch a result media file. The URL is presigned — no API key is sent. */
293
+ declare function download(media: SfxMedia | undefined, fetchFn?: typeof globalThis.fetch, timeout?: number): Promise<Uint8Array>;
160
294
 
161
- declare const VERSION = "0.1.0";
295
+ declare const VERSION = "0.2.0";
162
296
 
163
- export { APIError, type AccountServices, type AudioChunkEvent, AuthenticationError, BadRequestError, type CompleteEvent, type CostEvent, type CostInfo, type DailyUsage, type ErrorEvent, GenerationError, PaymentRequiredError, RateLimitError, type Segment, type SegmentLabel, SoniloClient, type SoniloClientOptions, SoniloError, type StreamEvent, type TextToMusicParams, type TitleEvent, type Track, type UnknownEvent, type UsageResponse, type UsageSummary, VERSION, type VideoInput, type VideoToMusicParams, isAudioChunkEvent, isErrorEvent };
297
+ export { APIError, type AccountServices, type AudioChunkEvent, AuthenticationError, BadRequestError, type CompleteEvent, type CostEvent, type CostInfo, DEFAULT_TIMEOUT_MS, type DailyUsage, type ErrorEvent, GenerationError, PaymentRequiredError, RateLimitError, RequestTimeoutError, type Segment, type SegmentLabel, type SfxAudioFormat, type SfxError, type SfxMedia, type SfxResult, type SfxSegment, type SfxTask, SoniloClient, type SoniloClientOptions, SoniloError, type StreamEvent, TaskFailedError, TaskTimeoutError, type TextToMusicParams, type TextToSfxParams, type TitleEvent, type Track, type UnknownEvent, type UsageResponse, type UsageSummary, VERSION, type VideoInput, type VideoToMusicParams, type VideoToSfxParams, type WaitOptions, download, isAudioChunkEvent, isErrorEvent };