sonilo 0.1.0 → 0.2.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.
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,60 @@ 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
+ video?: SfxMedia;
130
+ /** Only present when the account's task-field whitelist enables cost. */
131
+ cost?: number;
132
+ error?: SfxError;
133
+ refunded?: boolean;
134
+ [key: string]: unknown;
135
+ }
136
+ interface TextToSfxParams {
137
+ prompt: string;
138
+ duration: number;
139
+ audioFormat?: SfxAudioFormat;
140
+ }
141
+ interface VideoToSfxParams {
142
+ video?: VideoInput;
143
+ videoUrl?: string;
144
+ prompt?: string;
145
+ segments?: SfxSegment[];
146
+ audioFormat?: SfxAudioFormat;
147
+ }
148
+ interface WaitOptions {
149
+ /** Milliseconds between polls. Default 2000. */
150
+ pollInterval?: number;
151
+ /** Overall deadline in milliseconds. Default 600000. */
152
+ timeout?: number;
153
+ }
90
154
 
91
155
  declare class Account {
92
156
  private readonly client;
@@ -97,6 +161,15 @@ declare class Account {
97
161
  }): Promise<UsageResponse>;
98
162
  }
99
163
 
164
+ declare class Tasks {
165
+ private readonly client;
166
+ constructor(client: SoniloClient);
167
+ /** Fetch current task state. Never throws on a failed status. */
168
+ get(taskId: string): Promise<SfxResult>;
169
+ /** Poll until the task is terminal; throw on failure or deadline. */
170
+ wait(taskId: string, opts?: WaitOptions): Promise<SfxResult>;
171
+ }
172
+
100
173
  declare class TextToMusic {
101
174
  private readonly client;
102
175
  constructor(client: SoniloClient);
@@ -113,6 +186,20 @@ declare class VideoToMusic {
113
186
  generate(params: VideoToMusicParams): Promise<Track>;
114
187
  }
115
188
 
189
+ declare class TextToSfx {
190
+ private readonly client;
191
+ constructor(client: SoniloClient);
192
+ submit(params: TextToSfxParams): Promise<SfxTask>;
193
+ generate(params: TextToSfxParams, opts?: WaitOptions): Promise<SfxResult>;
194
+ }
195
+
196
+ declare class VideoToSfx {
197
+ private readonly client;
198
+ constructor(client: SoniloClient);
199
+ submit(params: VideoToSfxParams): Promise<SfxTask>;
200
+ generate(params: VideoToSfxParams, opts?: WaitOptions): Promise<SfxResult>;
201
+ }
202
+
116
203
  interface SoniloClientOptions {
117
204
  /** Defaults to the SONILO_API_KEY environment variable (Node.js only). */
118
205
  apiKey?: string;
@@ -120,17 +207,34 @@ interface SoniloClientOptions {
120
207
  baseUrl?: string;
121
208
  /** Injection point for tests and custom transports. */
122
209
  fetch?: typeof globalThis.fetch;
210
+ /** Milliseconds before an in-flight request is aborted. Default 600000. */
211
+ timeout?: number;
123
212
  }
213
+ /** Milliseconds before an in-flight request is aborted, unless overridden. */
214
+ declare const DEFAULT_TIMEOUT_MS = 600000;
124
215
  declare class SoniloClient {
125
216
  readonly baseUrl: string;
126
217
  private readonly apiKey;
127
218
  private readonly fetchFn;
219
+ private readonly timeout;
128
220
  readonly account: Account;
221
+ readonly tasks: Tasks;
129
222
  readonly textToMusic: TextToMusic;
130
223
  readonly videoToMusic: VideoToMusic;
224
+ readonly textToSfx: TextToSfx;
225
+ readonly videoToSfx: VideoToSfx;
131
226
  constructor(options?: SoniloClientOptions);
132
- /** Perform an authenticated request; throws a typed error on non-2xx. */
133
- request(path: string, init?: RequestInit): Promise<Response>;
227
+ /**
228
+ * Perform an authenticated request; throws a typed error on non-2xx.
229
+ *
230
+ * `opts.timeout` overrides the client's default timeout for this call;
231
+ * pass `null` to disable the abort-on-timeout behavior entirely (used by
232
+ * the streaming music endpoints — see textToMusic.ts / videoToMusic.ts).
233
+ * A caller-supplied `init.signal` always wins over any timeout signal.
234
+ */
235
+ request(path: string, init?: RequestInit, opts?: {
236
+ timeout?: number | null;
237
+ }): Promise<Response>;
134
238
  }
135
239
 
136
240
  declare class SoniloError extends Error {
@@ -139,6 +243,10 @@ declare class SoniloError extends Error {
139
243
  declare class APIError extends SoniloError {
140
244
  readonly status: number;
141
245
  readonly body: unknown;
246
+ /** The API's typed error code (e.g. "rate_limit_exceeded"), distinct from the HTTP status. */
247
+ readonly code?: string;
248
+ /** Per-field validation details, present on a 422. */
249
+ readonly errors?: unknown[];
142
250
  constructor(message: string, status: number, body?: unknown);
143
251
  }
144
252
  declare class AuthenticationError extends APIError {
@@ -157,7 +265,32 @@ declare class GenerationError extends SoniloError {
157
265
  readonly code?: string;
158
266
  constructor(message: string, code?: string);
159
267
  }
268
+ /** Raised by tasks.wait()/generate() when an SFX task reaches `failed`. */
269
+ declare class TaskFailedError extends SoniloError {
270
+ readonly code?: string;
271
+ readonly taskId: string;
272
+ readonly refunded?: boolean;
273
+ constructor(message: string, opts: {
274
+ code?: string;
275
+ taskId: string;
276
+ refunded?: boolean;
277
+ });
278
+ }
279
+ /** Poll deadline passed. The task may still finish server-side — resume with
280
+ * tasks.wait(taskId) or tasks.get(taskId). */
281
+ declare class TaskTimeoutError extends SoniloError {
282
+ readonly taskId: string;
283
+ constructor(message: string, taskId: string);
284
+ }
285
+ /** Raised when a one-shot request or download is aborted by its own timeout
286
+ * signal (as opposed to a caller-supplied AbortSignal, which propagates
287
+ * untouched). */
288
+ declare class RequestTimeoutError extends SoniloError {
289
+ }
290
+
291
+ /** Fetch a result media file. The URL is presigned — no API key is sent. */
292
+ declare function download(media: SfxMedia | undefined, fetchFn?: typeof globalThis.fetch, timeout?: number): Promise<Uint8Array>;
160
293
 
161
- declare const VERSION = "0.1.0";
294
+ declare const VERSION = "0.2.0";
162
295
 
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 };
296
+ 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,60 @@ 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
+ video?: SfxMedia;
130
+ /** Only present when the account's task-field whitelist enables cost. */
131
+ cost?: number;
132
+ error?: SfxError;
133
+ refunded?: boolean;
134
+ [key: string]: unknown;
135
+ }
136
+ interface TextToSfxParams {
137
+ prompt: string;
138
+ duration: number;
139
+ audioFormat?: SfxAudioFormat;
140
+ }
141
+ interface VideoToSfxParams {
142
+ video?: VideoInput;
143
+ videoUrl?: string;
144
+ prompt?: string;
145
+ segments?: SfxSegment[];
146
+ audioFormat?: SfxAudioFormat;
147
+ }
148
+ interface WaitOptions {
149
+ /** Milliseconds between polls. Default 2000. */
150
+ pollInterval?: number;
151
+ /** Overall deadline in milliseconds. Default 600000. */
152
+ timeout?: number;
153
+ }
90
154
 
91
155
  declare class Account {
92
156
  private readonly client;
@@ -97,6 +161,15 @@ declare class Account {
97
161
  }): Promise<UsageResponse>;
98
162
  }
99
163
 
164
+ declare class Tasks {
165
+ private readonly client;
166
+ constructor(client: SoniloClient);
167
+ /** Fetch current task state. Never throws on a failed status. */
168
+ get(taskId: string): Promise<SfxResult>;
169
+ /** Poll until the task is terminal; throw on failure or deadline. */
170
+ wait(taskId: string, opts?: WaitOptions): Promise<SfxResult>;
171
+ }
172
+
100
173
  declare class TextToMusic {
101
174
  private readonly client;
102
175
  constructor(client: SoniloClient);
@@ -113,6 +186,20 @@ declare class VideoToMusic {
113
186
  generate(params: VideoToMusicParams): Promise<Track>;
114
187
  }
115
188
 
189
+ declare class TextToSfx {
190
+ private readonly client;
191
+ constructor(client: SoniloClient);
192
+ submit(params: TextToSfxParams): Promise<SfxTask>;
193
+ generate(params: TextToSfxParams, opts?: WaitOptions): Promise<SfxResult>;
194
+ }
195
+
196
+ declare class VideoToSfx {
197
+ private readonly client;
198
+ constructor(client: SoniloClient);
199
+ submit(params: VideoToSfxParams): Promise<SfxTask>;
200
+ generate(params: VideoToSfxParams, opts?: WaitOptions): Promise<SfxResult>;
201
+ }
202
+
116
203
  interface SoniloClientOptions {
117
204
  /** Defaults to the SONILO_API_KEY environment variable (Node.js only). */
118
205
  apiKey?: string;
@@ -120,17 +207,34 @@ interface SoniloClientOptions {
120
207
  baseUrl?: string;
121
208
  /** Injection point for tests and custom transports. */
122
209
  fetch?: typeof globalThis.fetch;
210
+ /** Milliseconds before an in-flight request is aborted. Default 600000. */
211
+ timeout?: number;
123
212
  }
213
+ /** Milliseconds before an in-flight request is aborted, unless overridden. */
214
+ declare const DEFAULT_TIMEOUT_MS = 600000;
124
215
  declare class SoniloClient {
125
216
  readonly baseUrl: string;
126
217
  private readonly apiKey;
127
218
  private readonly fetchFn;
219
+ private readonly timeout;
128
220
  readonly account: Account;
221
+ readonly tasks: Tasks;
129
222
  readonly textToMusic: TextToMusic;
130
223
  readonly videoToMusic: VideoToMusic;
224
+ readonly textToSfx: TextToSfx;
225
+ readonly videoToSfx: VideoToSfx;
131
226
  constructor(options?: SoniloClientOptions);
132
- /** Perform an authenticated request; throws a typed error on non-2xx. */
133
- request(path: string, init?: RequestInit): Promise<Response>;
227
+ /**
228
+ * Perform an authenticated request; throws a typed error on non-2xx.
229
+ *
230
+ * `opts.timeout` overrides the client's default timeout for this call;
231
+ * pass `null` to disable the abort-on-timeout behavior entirely (used by
232
+ * the streaming music endpoints — see textToMusic.ts / videoToMusic.ts).
233
+ * A caller-supplied `init.signal` always wins over any timeout signal.
234
+ */
235
+ request(path: string, init?: RequestInit, opts?: {
236
+ timeout?: number | null;
237
+ }): Promise<Response>;
134
238
  }
135
239
 
136
240
  declare class SoniloError extends Error {
@@ -139,6 +243,10 @@ declare class SoniloError extends Error {
139
243
  declare class APIError extends SoniloError {
140
244
  readonly status: number;
141
245
  readonly body: unknown;
246
+ /** The API's typed error code (e.g. "rate_limit_exceeded"), distinct from the HTTP status. */
247
+ readonly code?: string;
248
+ /** Per-field validation details, present on a 422. */
249
+ readonly errors?: unknown[];
142
250
  constructor(message: string, status: number, body?: unknown);
143
251
  }
144
252
  declare class AuthenticationError extends APIError {
@@ -157,7 +265,32 @@ declare class GenerationError extends SoniloError {
157
265
  readonly code?: string;
158
266
  constructor(message: string, code?: string);
159
267
  }
268
+ /** Raised by tasks.wait()/generate() when an SFX task reaches `failed`. */
269
+ declare class TaskFailedError extends SoniloError {
270
+ readonly code?: string;
271
+ readonly taskId: string;
272
+ readonly refunded?: boolean;
273
+ constructor(message: string, opts: {
274
+ code?: string;
275
+ taskId: string;
276
+ refunded?: boolean;
277
+ });
278
+ }
279
+ /** Poll deadline passed. The task may still finish server-side — resume with
280
+ * tasks.wait(taskId) or tasks.get(taskId). */
281
+ declare class TaskTimeoutError extends SoniloError {
282
+ readonly taskId: string;
283
+ constructor(message: string, taskId: string);
284
+ }
285
+ /** Raised when a one-shot request or download is aborted by its own timeout
286
+ * signal (as opposed to a caller-supplied AbortSignal, which propagates
287
+ * untouched). */
288
+ declare class RequestTimeoutError extends SoniloError {
289
+ }
290
+
291
+ /** Fetch a result media file. The URL is presigned — no API key is sent. */
292
+ declare function download(media: SfxMedia | undefined, fetchFn?: typeof globalThis.fetch, timeout?: number): Promise<Uint8Array>;
160
293
 
161
- declare const VERSION = "0.1.0";
294
+ declare const VERSION = "0.2.0";
162
295
 
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 };
296
+ 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 };