sonilo 0.5.0 → 0.6.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.cjs +6 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -2
- package/dist/index.d.ts +21 -2
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -666,10 +666,11 @@ var VideoToVideoSound = class {
|
|
|
666
666
|
};
|
|
667
667
|
|
|
668
668
|
// src/version.ts
|
|
669
|
-
var VERSION = "0.
|
|
669
|
+
var VERSION = "0.6.0";
|
|
670
670
|
|
|
671
671
|
// src/client.ts
|
|
672
672
|
var DEFAULT_BASE_URL = "https://api.sonilo.com";
|
|
673
|
+
var DEFAULT_CLIENT_NAME = "sdk-js";
|
|
673
674
|
var DEFAULT_TIMEOUT_MS = 6e5;
|
|
674
675
|
var SoniloClient = class {
|
|
675
676
|
constructor(options = {}) {
|
|
@@ -684,6 +685,8 @@ var SoniloClient = class {
|
|
|
684
685
|
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
685
686
|
this.fetchFn = (options.fetch ?? globalThis.fetch).bind(globalThis);
|
|
686
687
|
this.timeout = options.timeout ?? DEFAULT_TIMEOUT_MS;
|
|
688
|
+
this.clientName = options.clientName ?? DEFAULT_CLIENT_NAME;
|
|
689
|
+
this.clientVersion = options.clientVersion ?? VERSION;
|
|
687
690
|
this.account = new Account(this);
|
|
688
691
|
this.tasks = new Tasks(this);
|
|
689
692
|
this.textToMusic = new TextToMusic(this);
|
|
@@ -706,8 +709,8 @@ var SoniloClient = class {
|
|
|
706
709
|
async request(path, init = {}, opts = {}) {
|
|
707
710
|
const headers = new Headers(init.headers);
|
|
708
711
|
headers.set("Authorization", `Bearer ${this.apiKey}`);
|
|
709
|
-
headers.set("X-Sonilo-Client",
|
|
710
|
-
headers.set("X-Sonilo-Client-Version",
|
|
712
|
+
headers.set("X-Sonilo-Client", this.clientName);
|
|
713
|
+
headers.set("X-Sonilo-Client-Version", this.clientVersion);
|
|
711
714
|
const timeout = opts.timeout === void 0 ? this.timeout : opts.timeout;
|
|
712
715
|
const ownsSignal = init.signal == null && timeout !== null;
|
|
713
716
|
const signal = init.signal ?? (timeout === null ? void 0 : AbortSignal.timeout(timeout));
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/resources/account.ts","../src/resources/tasks.ts","../src/streaming.ts","../src/resources/textToMusic.ts","../src/upload.ts","../src/resources/videoToMusic.ts","../src/resources/textToSfx.ts","../src/resources/videoToSfx.ts","../src/resources/videoToVideoMusic.ts","../src/resources/videoToVideoSfx.ts","../src/resources/soundForm.ts","../src/resources/videoToSound.ts","../src/resources/videoToVideoSound.ts","../src/version.ts","../src/client.ts","../src/download.ts","../src/types.ts"],"sourcesContent":["export { DEFAULT_TIMEOUT_MS, SoniloClient, type SoniloClientOptions } from \"./client.js\";\nexport {\n APIError,\n AuthenticationError,\n BadRequestError,\n GenerationError,\n PaymentRequiredError,\n RateLimitError,\n RequestTimeoutError,\n SoniloError,\n TaskFailedError,\n TaskTimeoutError,\n} from \"./errors.js\";\nexport { download } from \"./download.js\";\nexport { VERSION } from \"./version.js\";\nexport type {\n AccountServices,\n AudioChunkEvent,\n BaseTaskResult,\n CompleteEvent,\n CostEvent,\n CostInfo,\n DailyUsage,\n ErrorEvent,\n MusicMediaEntry,\n MusicMuxEntry,\n MusicTaskResult,\n MusicTitle,\n Segment,\n SegmentLabel,\n SfxAudioFormat,\n SfxError,\n SfxMedia,\n SfxResult,\n SfxSegment,\n SfxTask,\n SoundResult,\n StreamEvent,\n TextToMusicParams,\n TextToSfxParams,\n TitleEvent,\n Track,\n UnknownEvent,\n UsageResponse,\n UsageSummary,\n VideoInput,\n VideoResult,\n VideoToMusicParams,\n VideoToSfxParams,\n VideoToSoundParams,\n VideoToVideoMusicParams,\n VideoToVideoSfxParams,\n WaitOptions,\n} from \"./types.js\";\nexport { isAudioChunkEvent, isErrorEvent } from \"./types.js\";\n","export class SoniloError extends Error {\n constructor(message: string) {\n super(message);\n this.name = new.target.name;\n }\n}\n\nexport class APIError extends SoniloError {\n readonly status: number;\n readonly body: unknown;\n /** The API's typed error code (e.g. \"rate_limit_exceeded\"), distinct from the HTTP status. */\n readonly code?: string;\n /** Per-field validation details, present on a 422. */\n readonly errors?: unknown[];\n\n constructor(message: string, status: number, body?: unknown) {\n super(message);\n this.status = status;\n this.body = body;\n const parsed = body as { code?: unknown; errors?: unknown } | undefined;\n this.code = typeof parsed?.code === \"string\" ? parsed.code : undefined;\n this.errors = Array.isArray(parsed?.errors) ? parsed.errors : undefined;\n }\n}\n\nexport class AuthenticationError extends APIError {}\n\nexport class PaymentRequiredError extends APIError {}\n\nexport class BadRequestError extends APIError {\n get detail(): string | undefined {\n const body = this.body as { message?: unknown; detail?: unknown } | undefined;\n if (typeof body?.message === \"string\" && body.message) {\n return body.message;\n }\n return typeof body?.detail === \"string\" ? body.detail : undefined;\n }\n}\n\nexport class RateLimitError extends APIError {\n readonly retryAfter?: number;\n\n constructor(message: string, status: number, body?: unknown, retryAfter?: number) {\n super(message, status, body);\n this.retryAfter = retryAfter;\n }\n}\n\n/** Raised by generate() when an `error` event arrives mid-stream. */\nexport class GenerationError extends SoniloError {\n readonly code?: string;\n\n constructor(message: string, code?: string) {\n super(message);\n this.code = code;\n }\n}\n\n/** Raised by tasks.wait()/generate() when an SFX task reaches `failed`. */\nexport class TaskFailedError extends SoniloError {\n readonly code?: string;\n readonly taskId: string;\n readonly refunded?: boolean;\n\n constructor(\n message: string,\n opts: { code?: string; taskId: string; refunded?: boolean },\n ) {\n super(message);\n this.code = opts.code;\n this.taskId = opts.taskId;\n this.refunded = opts.refunded;\n }\n}\n\n/** Poll deadline passed. The task may still finish server-side — resume with\n * tasks.wait(taskId) or tasks.get(taskId). */\nexport class TaskTimeoutError extends SoniloError {\n readonly taskId: string;\n\n constructor(message: string, taskId: string) {\n super(message);\n this.taskId = taskId;\n }\n}\n\n/** Raised when a one-shot request or download is aborted by its own timeout\n * signal (as opposed to a caller-supplied AbortSignal, which propagates\n * untouched). */\nexport class RequestTimeoutError extends SoniloError {}\n\n/**\n * True if `err` is the rejection produced when an `AbortSignal.timeout()`\n * we created fires. Used to distinguish \"our\" timeout aborts (which should be\n * rethrown as `RequestTimeoutError`) from a caller-supplied signal's abort\n * (which must propagate untouched).\n */\nexport function isTimeoutSignalError(err: unknown): boolean {\n return err instanceof Error && (err.name === \"TimeoutError\" || err.name === \"AbortError\");\n}\n\nexport async function errorFromResponse(res: Response): Promise<APIError> {\n const text = await res.text().catch(() => \"\");\n let body: unknown = text;\n try {\n body = JSON.parse(text);\n } catch {\n // keep raw text\n }\n const parsed = body as { message?: unknown; detail?: unknown } | undefined;\n const rawMessage = typeof parsed?.message === \"string\" && parsed.message ? parsed.message : undefined;\n const rawDetail = parsed?.detail;\n const isDetailAbsent = rawDetail === undefined || rawDetail === null || rawDetail === \"\";\n let reason: string;\n if (rawMessage !== undefined) {\n reason = rawMessage;\n } else if (isDetailAbsent) {\n reason = res.statusText || \"request failed\";\n } else if (typeof rawDetail === \"string\") {\n reason = rawDetail;\n } else {\n try {\n reason = JSON.stringify(rawDetail);\n } catch {\n reason = res.statusText || \"request failed\";\n }\n }\n const message = `HTTP ${res.status}: ${reason}`;\n\n switch (res.status) {\n case 401:\n return new AuthenticationError(message, res.status, body);\n case 402:\n return new PaymentRequiredError(message, res.status, body);\n case 429: {\n const ra = res.headers.get(\"retry-after\");\n const retryAfter = ra !== null && ra !== \"\" && !Number.isNaN(Number(ra)) ? Number(ra) : undefined;\n return new RateLimitError(message, res.status, body, retryAfter);\n }\n case 400:\n case 413:\n case 422:\n return new BadRequestError(message, res.status, body);\n default:\n return new APIError(message, res.status, body);\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport type { AccountServices, UsageResponse } from \"../types.js\";\n\nexport class Account {\n constructor(private readonly client: SoniloClient) {}\n\n async services(): Promise<AccountServices> {\n const res = await this.client.request(\"/v1/account/services\");\n return (await res.json()) as AccountServices;\n }\n\n async usage(params: { days?: number } = {}): Promise<UsageResponse> {\n const query = params.days !== undefined ? `?days=${params.days}` : \"\";\n const res = await this.client.request(`/v1/account/usage${query}`);\n return (await res.json()) as UsageResponse;\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError, TaskFailedError, TaskTimeoutError } from \"../errors.js\";\nimport type { BaseTaskResult, SfxResult, WaitOptions } from \"../types.js\";\n\nexport const DEFAULT_POLL_INTERVAL_MS = 2000;\nexport const DEFAULT_WAIT_TIMEOUT_MS = 600_000;\n\nconst sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));\n\n/** A negative delay is clamped to 0 by setTimeout, which would turn the poll\n * loop into a busy loop hammering the API until the deadline. */\nfunction validateWaitArgs(pollInterval: number, timeout: number): void {\n if (pollInterval < 0) {\n throw new SoniloError(`pollInterval must be >= 0, got ${pollInterval}`);\n }\n if (timeout < 0) {\n throw new SoniloError(`timeout must be >= 0, got ${timeout}`);\n }\n}\n\nexport class Tasks {\n constructor(private readonly client: SoniloClient) {}\n\n /**\n * Fetch current task state. Never throws on a failed status.\n *\n * Generic over the result shape so callers can request the endpoint-\n * specific type, e.g. `client.tasks.get<MusicTaskResult>(taskId)`.\n * Defaults to `SfxResult` for back-compat.\n */\n async get<T extends BaseTaskResult = SfxResult>(taskId: string): Promise<T> {\n const res = await this.client.request(`/v1/tasks/${encodeURIComponent(taskId)}`);\n return (await res.json()) as T;\n }\n\n /**\n * Poll until the task is terminal; throw on failure or deadline.\n *\n * Generic over the result shape, e.g.\n * `client.tasks.wait<MusicTaskResult>(taskId)`. Defaults to `SfxResult`\n * for back-compat.\n */\n async wait<T extends BaseTaskResult = SfxResult>(\n taskId: string,\n opts: WaitOptions = {},\n ): Promise<T> {\n const pollInterval = opts.pollInterval ?? DEFAULT_POLL_INTERVAL_MS;\n const timeout = opts.timeout ?? DEFAULT_WAIT_TIMEOUT_MS;\n validateWaitArgs(pollInterval, timeout);\n const deadline = performance.now() + timeout;\n for (;;) {\n const result = await this.get<T>(taskId);\n if (result.status === \"succeeded\") return result;\n if (result.status === \"failed\") {\n const message = result.error?.message || \"Generation failed\";\n throw new TaskFailedError(`Task ${taskId} failed: ${message}`, {\n code: result.error?.code,\n taskId,\n refunded: result.refunded,\n });\n }\n const remaining = deadline - performance.now();\n if (remaining <= 0) {\n throw new TaskTimeoutError(\n `Task ${taskId} still processing after ${timeout}ms; ` +\n \"it may finish later — resume with tasks.wait or tasks.get\",\n taskId,\n );\n }\n await sleep(Math.min(pollInterval, remaining));\n }\n }\n}\n","import { GenerationError } from \"./errors.js\";\nimport type { CostInfo, StreamEvent, Track } from \"./types.js\";\n\nexport function decodeBase64(b64: string): Uint8Array {\n const bin = atob(b64);\n const out = new Uint8Array(bin.length);\n for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);\n return out;\n}\n\n/** Returns `null` for a valid-JSON-but-non-object line (e.g. a bare `null`\n * or a number/string), which carries no event `type` and is skipped like any\n * other junk line rather than crashing on a `.type` read off `null`. */\nfunction toEvent(line: string): StreamEvent | null {\n const parsed: unknown = JSON.parse(line);\n if (typeof parsed !== \"object\" || parsed === null) return null;\n const raw = parsed as { type: string; [key: string]: unknown };\n if (raw.type === \"audio_chunk\" && typeof raw.data === \"string\") {\n try {\n return { ...raw, type: \"audio_chunk\", data: decodeBase64(raw.data) };\n } catch {\n // Don't raise here: this must reach collectTrack's malformed-chunk\n // check, which turns undecodable data into a typed GenerationError.\n // Raising in place would let a raw DOMException escape\n // stream()/generate(), breaking the SDK's \"all errors extend\n // SoniloError\" contract.\n }\n }\n return raw as StreamEvent;\n}\n\nexport async function* parseNdjson(\n body: ReadableStream<Uint8Array>,\n): AsyncGenerator<StreamEvent, void, undefined> {\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n buffer += decoder.decode(value, { stream: true });\n let nl: number;\n while ((nl = buffer.indexOf(\"\\n\")) !== -1) {\n const line = buffer.slice(0, nl).trim();\n buffer = buffer.slice(nl + 1);\n if (line) {\n const ev = toEvent(line);\n if (ev !== null) yield ev;\n }\n }\n }\n buffer += decoder.decode();\n const tail = buffer.trim();\n if (tail) {\n const ev = toEvent(tail);\n if (ev !== null) yield ev;\n }\n } finally {\n await reader.cancel().catch(() => {});\n }\n}\n\nexport async function collectTrack(events: AsyncIterable<StreamEvent>): Promise<Track> {\n const chunks: Uint8Array[] = [];\n let title: string | undefined;\n let cost: CostInfo | undefined;\n let sawComplete = false;\n\n for await (const ev of events) {\n if (ev.type === \"audio_chunk\") {\n // A malformed chunk (missing/non-decodable `data`) must not be\n // silently dropped: that would hand back a \"successful\" Track with\n // empty or truncated audio and no indication anything went wrong.\n if (!(ev.data instanceof Uint8Array)) {\n throw new GenerationError(\n \"received a malformed audio_chunk event (missing or non-decodable data)\",\n );\n }\n chunks.push(ev.data);\n } else if (ev.type === \"title\" && typeof ev.title === \"string\") {\n title = ev.title;\n } else if (ev.type === \"cost\") {\n const { type: _type, ...rest } = ev;\n cost = rest as CostInfo;\n } else if (ev.type === \"error\") {\n const message = typeof ev.message === \"string\" && ev.message !== \"\" ? ev.message : \"generation failed\";\n const code = typeof ev.code === \"string\" ? ev.code : undefined;\n throw new GenerationError(message, code);\n } else if (ev.type === \"complete\") {\n sawComplete = true;\n }\n // unknown event types: ignored\n }\n\n if (!sawComplete) {\n throw new GenerationError(\"stream ended before a 'complete' event (truncated response)\");\n }\n\n const total = chunks.reduce((n, c) => n + c.length, 0);\n const audio = new Uint8Array(total);\n let offset = 0;\n for (const c of chunks) {\n audio.set(c, offset);\n offset += c.length;\n }\n return { audio, title, cost };\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError } from \"../errors.js\";\nimport { collectTrack, parseNdjson } from \"../streaming.js\";\nimport type { SfxTask, StreamEvent, TextToMusicParams, Track } from \"../types.js\";\n\nexport class TextToMusic {\n constructor(private readonly client: SoniloClient) {}\n\n /** Stream raw generation events (audio chunks pre-decoded to bytes). */\n async *stream(params: TextToMusicParams): AsyncGenerator<StreamEvent, void, undefined> {\n const form = new FormData();\n form.set(\"prompt\", params.prompt);\n form.set(\"duration\", String(params.duration));\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n // Opt out of the client's absolute request timeout: this holds the\n // response body open and reads NDJSON chunks for as long as generation\n // takes, so an AbortSignal keyed to elapsed time would kill a healthy,\n // still-streaming, long-duration track. Pass `params.signal` yourself to\n // bound or cancel the stream instead — it is forwarded to `fetch` as-is.\n const res = await this.client.request(\n \"/v1/text-to-music\",\n { method: \"POST\", body: form, signal: params.signal },\n { timeout: null },\n );\n if (!res.body) throw new SoniloError(\"Response has no body\");\n yield* parseNdjson(res.body);\n }\n\n /** Generate and buffer the whole track; throws GenerationError on stream errors. */\n generate(params: TextToMusicParams): Promise<Track> {\n return collectTrack(this.stream(params));\n }\n\n /**\n * Submit an async text-to-music task; poll with\n * `client.tasks.wait<MusicTaskResult>(task.task_id)`. Required for\n * `outputFormat: \"wav\"`. `stream()`/`generate()` remain the streaming path.\n */\n async submit(params: TextToMusicParams): Promise<SfxTask> {\n const mode = params.mode ?? \"async\";\n if (mode !== \"async\") {\n throw new SoniloError('submit() requires mode: \"async\"');\n }\n const form = new FormData();\n form.set(\"prompt\", params.prompt);\n form.set(\"duration\", String(params.duration));\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n form.set(\"mode\", mode);\n if (params.outputFormat !== undefined) {\n form.set(\"output_format\", params.outputFormat);\n }\n const res = await this.client.request(\"/v1/text-to-music\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n}\n","import { SoniloError } from \"./errors.js\";\nimport type { VideoInput } from \"./types.js\";\n\nconst DEFAULT_FILENAME = \"video.mp4\";\n\n/**\n * Normalize every accepted video input into a FormData-ready Blob.\n * String inputs are file paths and work only in Node.js; browsers must\n * pass File/Blob/bytes/streams.\n */\nexport async function toUploadBlob(\n video: VideoInput,\n): Promise<{ blob: Blob; filename: string }> {\n if (typeof video === \"string\") {\n const isNode =\n typeof process !== \"undefined\" && Boolean((process as { versions?: { node?: string } }).versions?.node);\n if (!isNode) {\n throw new SoniloError(\n \"File paths are only supported in Node.js; pass a File or Blob in the browser\",\n );\n }\n const fsModule = \"node:fs/promises\";\n const { readFile } = (await import(\n /* webpackIgnore: true */ /* @vite-ignore */ fsModule\n )) as typeof import(\"node:fs/promises\");\n const data = await readFile(video);\n const filename = video.split(/[\\\\/]/).pop() || DEFAULT_FILENAME;\n return { blob: new Blob([data]), filename };\n }\n if (typeof File !== \"undefined\" && video instanceof File) {\n return { blob: video, filename: video.name || DEFAULT_FILENAME };\n }\n if (video instanceof Blob) {\n return { blob: video, filename: DEFAULT_FILENAME };\n }\n if (video instanceof Uint8Array) {\n return { blob: new Blob([video as unknown as BlobPart]), filename: DEFAULT_FILENAME };\n }\n if (video instanceof ArrayBuffer) {\n return { blob: new Blob([video]), filename: DEFAULT_FILENAME };\n }\n if (video instanceof ReadableStream) {\n return { blob: await new Response(video).blob(), filename: DEFAULT_FILENAME };\n }\n throw new SoniloError(\"Unsupported video input type\");\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError } from \"../errors.js\";\nimport { collectTrack, parseNdjson } from \"../streaming.js\";\nimport { toUploadBlob } from \"../upload.js\";\nimport type { SfxTask, StreamEvent, Track, VideoToMusicParams } from \"../types.js\";\n\nexport class VideoToMusic {\n constructor(private readonly client: SoniloClient) {}\n\n async *stream(params: VideoToMusicParams): AsyncGenerator<StreamEvent, void, undefined> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.prompt !== undefined) form.set(\"prompt\", params.prompt);\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n // Opt out of the client's absolute request timeout: this holds the\n // response body open and reads NDJSON chunks for as long as generation\n // takes, so an AbortSignal keyed to elapsed time would kill a healthy,\n // still-streaming request (e.g. a slow video upload or long track). Pass\n // `params.signal` yourself to bound or cancel the stream instead — it is\n // forwarded to `fetch` as-is.\n const res = await this.client.request(\n \"/v1/video-to-music\",\n { method: \"POST\", body: form, signal: params.signal },\n { timeout: null },\n );\n if (!res.body) throw new SoniloError(\"Response has no body\");\n yield* parseNdjson(res.body);\n }\n\n generate(params: VideoToMusicParams): Promise<Track> {\n return collectTrack(this.stream(params));\n }\n\n /**\n * Submit an async video-to-music task; poll its result with\n * `client.tasks.wait<MusicTaskResult>(task.task_id)`. Required for\n * `isolateVocals` — the backend rejects vocal isolation on the plain\n * stream, and it only ever runs in async mode.\n */\n async submit(params: VideoToMusicParams): Promise<SfxTask> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n let mode = params.mode;\n const needsAsync =\n params.isolateVocals ||\n params.preserveSpeech ||\n params.ducking !== undefined ||\n params.outputFormat === \"wav\";\n // submit() always wants an async task ack, never a stream. Default to\n // async; only object if the caller explicitly asked for stream while\n // also requesting an async-only feature.\n if (mode === undefined) mode = \"async\";\n if (needsAsync && mode !== \"async\") {\n throw new SoniloError(\n 'isolateVocals/preserveSpeech/ducking/outputFormat \"wav\" require mode: \"async\"',\n );\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.prompt !== undefined) form.set(\"prompt\", params.prompt);\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n form.set(\"mode\", mode);\n if (params.preserveSpeech !== undefined) {\n form.set(\"preserve_speech\", String(params.preserveSpeech));\n }\n if (params.isolateVocals !== undefined) {\n form.set(\"isolate_vocals\", String(params.isolateVocals));\n }\n if (params.outputFormat !== undefined) {\n form.set(\"output_format\", params.outputFormat);\n }\n if (params.ducking !== undefined) {\n form.set(\"ducking\", String(params.ducking));\n }\n const res = await this.client.request(\"/v1/video-to-music\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport type { SfxResult, SfxTask, TextToSfxParams, WaitOptions } from \"../types.js\";\n\nexport class TextToSfx {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: TextToSfxParams): Promise<SfxTask> {\n const form = new FormData();\n form.set(\"prompt\", params.prompt);\n form.set(\"duration\", String(params.duration));\n if (params.audioFormat !== undefined) form.set(\"audio_format\", params.audioFormat);\n const res = await this.client.request(\"/v1/text-to-sfx\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: TextToSfxParams, opts?: WaitOptions): Promise<SfxResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait(task.task_id, opts);\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError } from \"../errors.js\";\nimport { toUploadBlob } from \"../upload.js\";\nimport type { SfxResult, SfxTask, VideoToSfxParams, WaitOptions } from \"../types.js\";\n\nexport class VideoToSfx {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: VideoToSfxParams): Promise<SfxTask> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.prompt !== undefined) form.set(\"prompt\", params.prompt);\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n if (params.audioFormat !== undefined) form.set(\"audio_format\", params.audioFormat);\n const res = await this.client.request(\"/v1/video-to-sfx\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: VideoToSfxParams, opts?: WaitOptions): Promise<SfxResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait(task.task_id, opts);\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError } from \"../errors.js\";\nimport { toUploadBlob } from \"../upload.js\";\nimport type { SfxTask, VideoResult, VideoToVideoMusicParams, WaitOptions } from \"../types.js\";\n\n/** Generate an original score for a video and get back a re-hosted video with\n * the music muxed in. Async only: `submit()` returns a task ack; poll with\n * `client.tasks.wait<VideoResult>(id)`, or use `generate()` to do both. */\nexport class VideoToVideoMusic {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: VideoToVideoMusicParams): Promise<SfxTask> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.prompt !== undefined) form.set(\"prompt\", params.prompt);\n if (params.preserveSpeech !== undefined) {\n form.set(\"preserve_speech\", String(params.preserveSpeech));\n }\n if (params.isolateVocals !== undefined) {\n form.set(\"isolate_vocals\", String(params.isolateVocals));\n }\n const res = await this.client.request(\"/v1/video-to-video-music\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: VideoToVideoMusicParams, opts?: WaitOptions): Promise<VideoResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait<VideoResult>(task.task_id, opts);\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError } from \"../errors.js\";\nimport { toUploadBlob } from \"../upload.js\";\nimport type { SfxTask, VideoResult, VideoToVideoSfxParams, WaitOptions } from \"../types.js\";\n\n/** Generate sound effects for a video and get back a re-hosted video with the\n * SFX muxed in. Async only. */\nexport class VideoToVideoSfx {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: VideoToVideoSfxParams): Promise<SfxTask> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.prompt !== undefined) form.set(\"prompt\", params.prompt);\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n const res = await this.client.request(\"/v1/video-to-video-sfx\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: VideoToVideoSfxParams, opts?: WaitOptions): Promise<VideoResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait<VideoResult>(task.task_id, opts);\n }\n}\n","import { SoniloError } from \"../errors.js\";\nimport { toUploadBlob } from \"../upload.js\";\nimport type { VideoToSoundParams } from \"../types.js\";\n\n/** Build the multipart body shared by /v1/video-to-sound and\n * /v1/video-to-video-sound — their form fields are identical, so the two\n * resources differ only in the path they POST to.\n *\n * Every optional field is omitted when unset rather than sent with a default:\n * `ducking` in particular is default-ON server-side, so an unset value must\n * not become an explicit \"false\" on the wire. */\nexport async function buildSoundForm(params: VideoToSoundParams): Promise<FormData> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.musicPrompt !== undefined) form.set(\"music_prompt\", params.musicPrompt);\n if (params.sfxPrompt !== undefined) form.set(\"sfx_prompt\", params.sfxPrompt);\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n if (params.preserveSpeech !== undefined) {\n form.set(\"preserve_speech\", String(params.preserveSpeech));\n }\n if (params.ducking !== undefined) form.set(\"ducking\", String(params.ducking));\n return form;\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { buildSoundForm } from \"./soundForm.js\";\nimport type { SfxTask, SoundResult, VideoToSoundParams, WaitOptions } from \"../types.js\";\n\n/** Generate a combined music + sound-effects track for a video and get back\n * the mixed audio. Async only. */\nexport class VideoToSound {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: VideoToSoundParams): Promise<SfxTask> {\n const res = await this.client.request(\"/v1/video-to-sound\", {\n method: \"POST\",\n body: await buildSoundForm(params),\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: VideoToSoundParams, opts?: WaitOptions): Promise<SoundResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait<SoundResult>(task.task_id, opts);\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { buildSoundForm } from \"./soundForm.js\";\nimport type { SfxTask, SoundResult, VideoToSoundParams, WaitOptions } from \"../types.js\";\n\n/** Generate a combined music + sound-effects track for a video and get back a\n * re-hosted video with that track muxed in. Async only. */\nexport class VideoToVideoSound {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: VideoToSoundParams): Promise<SfxTask> {\n const res = await this.client.request(\"/v1/video-to-video-sound\", {\n method: \"POST\",\n body: await buildSoundForm(params),\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: VideoToSoundParams, opts?: WaitOptions): Promise<SoundResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait<SoundResult>(task.task_id, opts);\n }\n}\n","export const VERSION = \"0.4.0\";\n","import { RequestTimeoutError, SoniloError, errorFromResponse, isTimeoutSignalError } from \"./errors.js\";\nimport { Account } from \"./resources/account.js\";\nimport { Tasks } from \"./resources/tasks.js\";\nimport { TextToMusic } from \"./resources/textToMusic.js\";\nimport { VideoToMusic } from \"./resources/videoToMusic.js\";\nimport { TextToSfx } from \"./resources/textToSfx.js\";\nimport { VideoToSfx } from \"./resources/videoToSfx.js\";\nimport { VideoToVideoMusic } from \"./resources/videoToVideoMusic.js\";\nimport { VideoToVideoSfx } from \"./resources/videoToVideoSfx.js\";\nimport { VideoToSound } from \"./resources/videoToSound.js\";\nimport { VideoToVideoSound } from \"./resources/videoToVideoSound.js\";\nimport { VERSION } from \"./version.js\";\n\nexport interface SoniloClientOptions {\n /** Defaults to the SONILO_API_KEY environment variable (Node.js only). */\n apiKey?: string;\n /** Defaults to https://api.sonilo.com */\n baseUrl?: string;\n /** Injection point for tests and custom transports. */\n fetch?: typeof globalThis.fetch;\n /** Milliseconds before an in-flight request is aborted. Default 600000. */\n timeout?: number;\n}\n\nconst DEFAULT_BASE_URL = \"https://api.sonilo.com\";\n\n/** Milliseconds before an in-flight request is aborted, unless overridden. */\nexport const DEFAULT_TIMEOUT_MS = 600_000;\n\nexport class SoniloClient {\n readonly baseUrl: string;\n private readonly apiKey: string;\n private readonly fetchFn: typeof globalThis.fetch;\n private readonly timeout: number;\n readonly account: Account;\n readonly tasks: Tasks;\n readonly textToMusic: TextToMusic;\n readonly videoToMusic: VideoToMusic;\n readonly textToSfx: TextToSfx;\n readonly videoToSfx: VideoToSfx;\n readonly videoToVideoMusic: VideoToVideoMusic;\n readonly videoToVideoSfx: VideoToVideoSfx;\n readonly videoToSound: VideoToSound;\n readonly videoToVideoSound: VideoToVideoSound;\n\n constructor(options: SoniloClientOptions = {}) {\n const envKey =\n typeof process !== \"undefined\" ? process.env?.SONILO_API_KEY : undefined;\n const apiKey = options.apiKey ?? envKey;\n if (!apiKey) {\n throw new SoniloError(\n \"Missing API key: pass { apiKey } or set the SONILO_API_KEY environment variable\",\n );\n }\n this.apiKey = apiKey;\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.fetchFn = (options.fetch ?? globalThis.fetch).bind(globalThis);\n this.timeout = options.timeout ?? DEFAULT_TIMEOUT_MS;\n this.account = new Account(this);\n this.tasks = new Tasks(this);\n this.textToMusic = new TextToMusic(this);\n this.videoToMusic = new VideoToMusic(this);\n this.textToSfx = new TextToSfx(this);\n this.videoToSfx = new VideoToSfx(this);\n this.videoToVideoMusic = new VideoToVideoMusic(this);\n this.videoToVideoSfx = new VideoToVideoSfx(this);\n this.videoToSound = new VideoToSound(this);\n this.videoToVideoSound = new VideoToVideoSound(this);\n }\n\n /**\n * Perform an authenticated request; throws a typed error on non-2xx.\n *\n * `opts.timeout` overrides the client's default timeout for this call;\n * pass `null` to disable the abort-on-timeout behavior entirely (used by\n * the streaming music endpoints — see textToMusic.ts / videoToMusic.ts).\n * A caller-supplied `init.signal` always wins over any timeout signal.\n */\n async request(\n path: string,\n init: RequestInit = {},\n opts: { timeout?: number | null } = {},\n ): Promise<Response> {\n const headers = new Headers(init.headers);\n headers.set(\"Authorization\", `Bearer ${this.apiKey}`);\n headers.set(\"X-Sonilo-Client\", \"sdk-js\");\n headers.set(\"X-Sonilo-Client-Version\", VERSION);\n const timeout = opts.timeout === undefined ? this.timeout : opts.timeout;\n // We only \"own\" the signal (and may later rewrap its abort as a\n // RequestTimeoutError) when the caller didn't supply one and a timeout\n // is actually enabled.\n const ownsSignal = init.signal == null && timeout !== null;\n const signal = init.signal ?? (timeout === null ? undefined : AbortSignal.timeout(timeout));\n try {\n const res = await this.fetchFn(`${this.baseUrl}${path}`, { ...init, headers, signal });\n if (!res.ok) throw await errorFromResponse(res);\n return res;\n } catch (err) {\n if (ownsSignal && isTimeoutSignalError(err)) {\n throw new RequestTimeoutError(`Request to ${path} timed out after ${timeout}ms`);\n }\n throw err;\n }\n }\n}\n","import { DEFAULT_TIMEOUT_MS } from \"./client.js\";\nimport { RequestTimeoutError, SoniloError, isTimeoutSignalError } from \"./errors.js\";\nimport type { SfxMedia } from \"./types.js\";\n\n/** Fetch a result media file. The URL is presigned — no API key is sent.\n *\n * Accepts either a media object (`result.audio`, `result.music`, …) or a bare\n * URL string, which is what the combined video-to-sound endpoints return as\n * `output_url`. */\nexport async function download(\n media: SfxMedia | string | undefined,\n fetchFn: typeof globalThis.fetch = globalThis.fetch,\n timeout: number = DEFAULT_TIMEOUT_MS,\n): Promise<Uint8Array> {\n const url = typeof media === \"string\" ? media : media?.url;\n if (!url) {\n throw new SoniloError(\"No media to download\");\n }\n let res: Response;\n try {\n res = await fetchFn(url, { signal: AbortSignal.timeout(timeout) });\n } catch (err) {\n if (isTimeoutSignalError(err)) {\n throw new RequestTimeoutError(`Download of ${url} timed out after ${timeout}ms`);\n }\n throw err;\n }\n if (!res.ok) {\n throw new SoniloError(`Download failed: HTTP ${res.status}`);\n }\n return new Uint8Array(await res.arrayBuffer());\n}\n","export type SegmentLabel =\n | \"intro\"\n | \"verse\"\n | \"pre-chorus\"\n | \"chorus\"\n | \"bridge\"\n | \"break\"\n | \"silence\"\n | \"outro\"\n | \"none\";\n\nexport interface Segment {\n start: number;\n prompt: string;\n label?: SegmentLabel;\n}\n\n/** Monetary fields are strings, exactly as the backend serializes them. */\nexport interface CostInfo {\n billing_rate_per_sec: string;\n billing_before_discount: string;\n billing_after_discount: string;\n discount_factor: string;\n}\n\nexport interface AudioChunkEvent {\n type: \"audio_chunk\";\n /** Decoded from the wire's base64 by the SDK. */\n data: Uint8Array;\n}\n\nexport interface TitleEvent {\n type: \"title\";\n title: string;\n summary?: string;\n display_tags?: string[];\n [key: string]: unknown;\n}\n\nexport interface CompleteEvent {\n type: \"complete\";\n [key: string]: unknown;\n}\n\nexport interface ErrorEvent {\n type: \"error\";\n code?: string;\n message?: string;\n [key: string]: unknown;\n}\n\nexport interface CostEvent extends CostInfo {\n type: \"cost\";\n}\n\n/** Forward-compatibility: unrecognized event types are passed through. */\nexport interface UnknownEvent {\n type: string;\n [key: string]: unknown;\n}\n\nexport type StreamEvent =\n | AudioChunkEvent\n | TitleEvent\n | CompleteEvent\n | ErrorEvent\n | CostEvent\n | UnknownEvent;\n\nexport interface Track {\n audio: Uint8Array;\n title?: string;\n cost?: CostInfo;\n}\n\nexport interface TextToMusicParams {\n prompt: string;\n duration: number;\n segments?: Segment[];\n /** \"stream\" (default) or \"async\" (required by `submit()` and `output_format: \"wav\"`). */\n mode?: \"stream\" | \"async\";\n /** Container for the async result. `wav` requires `mode: \"async\"`. Defaults to m4a server-side. */\n outputFormat?: \"m4a\" | \"wav\";\n /** Bounds the stream: aborting this cancels the in-flight generation.\n * Passed straight through to `fetch` — it is never rewrapped as\n * RequestTimeoutError, since the client's own absolute timeout does not\n * apply to streaming music generation. */\n signal?: AbortSignal;\n}\n\n/** string = file path (Node.js only). */\nexport type VideoInput =\n | File\n | Blob\n | Uint8Array\n | ArrayBuffer\n | ReadableStream<Uint8Array>\n | string;\n\nexport interface VideoToMusicParams {\n video?: VideoInput;\n videoUrl?: string;\n prompt?: string;\n segments?: Segment[];\n /** Bounds the stream: aborting this cancels the in-flight generation.\n * Passed straight through to `fetch` — it is never rewrapped as\n * RequestTimeoutError, since the client's own absolute timeout does not\n * apply to streaming music generation. Only meaningful for `stream()`/\n * `generate()`; `submit()` ignores it. */\n signal?: AbortSignal;\n /** \"stream\" (the default, used by `stream()`/`generate()`) or \"async\"\n * (required for `submit()`, and for `isolateVocals`). Only consulted by\n * `submit()` — `stream()`/`generate()` always request a stream. */\n mode?: \"stream\" | \"async\";\n /** Split the generated track into a vocals-only stem alongside the mix.\n * Requires `mode: \"async\"`; if `mode` is left unset it defaults to\n * \"async\" automatically. Only usable via `submit()` — the backend\n * rejects it on the plain stream. */\n isolateVocals?: boolean;\n /** Keep the source speech/vocals in the async result. Current name for\n * `isolateVocals`; both are accepted and OR'd server-side. Requires\n * `mode: \"async\"` (auto-selected by `submit()`). */\n preserveSpeech?: boolean;\n /** Container for the async result. `wav` requires async. Defaults to m4a. */\n outputFormat?: \"m4a\" | \"wav\";\n /** Duck the generated music under the source voice at finalize time.\n * Default-ON server-side in async mode: leave unset to keep it on, pass\n * `false` to opt out. Free, best-effort; only valid on `submit()`. */\n ducking?: boolean;\n}\n\nexport interface AccountServices {\n available_services: string[];\n rpm_limit: number;\n concurrency_limit: number;\n discount_factor: number | string;\n max_upload_size_mb: number | null;\n}\n\nexport interface UsageSummary {\n total_requests: number;\n total_duration_seconds: number;\n total_cost: number | string;\n period_start: string;\n period_end: string;\n [key: string]: unknown;\n}\n\nexport interface DailyUsage {\n date: string;\n requests: number;\n duration_seconds: number;\n cost: number | string;\n}\n\nexport interface UsageResponse {\n summary: UsageSummary;\n daily: DailyUsage[];\n}\n\nexport function isAudioChunkEvent(event: StreamEvent): event is AudioChunkEvent {\n return event.type === \"audio_chunk\" && (event as AudioChunkEvent).data instanceof Uint8Array;\n}\n\nexport function isErrorEvent(event: StreamEvent): event is ErrorEvent {\n return event.type === \"error\";\n}\n\n/** SFX segments (unlike music `Segment`) require `end`, must start at 0,\n * and be contiguous; validated server-side. */\nexport interface SfxSegment {\n start: number;\n end: number;\n prompt: string;\n}\n\nexport type SfxAudioFormat = \"wav\" | \"mp3\" | \"aac\" | \"flac\";\n\n/** Submission ack for the async SFX endpoints. */\nexport interface SfxTask {\n task_id: string;\n status: string;\n}\n\n/** A generated file re-hosted on R2 behind a presigned URL. */\nexport interface SfxMedia {\n url: string;\n content_type?: string;\n file_size?: number;\n}\n\nexport interface SfxError {\n code?: string;\n message?: string;\n}\n\n/**\n * Common shape of any polled task (`tasks.get`/`tasks.wait`), regardless of\n * which endpoint created it. `Tasks.get`/`Tasks.wait` are generic over this so\n * each endpoint's result type (e.g. `SfxResult`, `MusicTaskResult`) can add\n * its own `audio`/media fields while sharing the status/error/refund\n * bookkeeping the poller relies on.\n */\nexport interface BaseTaskResult {\n task_id: string;\n type?: string;\n status: \"processing\" | \"succeeded\" | \"failed\" | (string & {});\n /** Only present when the account's task-field whitelist enables cost. */\n cost?: number;\n error?: SfxError;\n refunded?: boolean;\n [key: string]: unknown;\n}\n\n/** State of an SFX task (`tasks.get`) or its final result (`wait`/`generate`). */\nexport interface SfxResult extends BaseTaskResult {\n audio?: SfxMedia;\n /** Kept for backward compatibility; no longer populated — video-to-sfx returns audio only. */\n video?: SfxMedia;\n}\n\nexport interface TextToSfxParams {\n prompt: string;\n duration: number;\n audioFormat?: SfxAudioFormat;\n}\n\nexport interface VideoToSfxParams {\n video?: VideoInput;\n videoUrl?: string;\n prompt?: string;\n segments?: SfxSegment[];\n audioFormat?: SfxAudioFormat;\n}\n\n/** One decoded audio stream of an async video-to-music result. Unlike SFX,\n * `audio` on a music task is always an array — even without `isolateVocals` —\n * since a music generation can carry more than one output stream. */\nexport interface MusicMediaEntry extends SfxMedia {\n stream_index: number;\n sample_rate?: number;\n channels?: number;\n}\n\n/** One muxed audio+video-aligned output, present only when `isolateVocals`\n * is set. */\nexport interface MusicMuxEntry extends SfxMedia {\n stream_index: number;\n}\n\nexport interface MusicTitle {\n title: string;\n summary?: string;\n display_tags?: string[];\n}\n\n/** State of an async video-to-music task (`tasks.get`) or its final result\n * (`tasks.wait<MusicTaskResult>()`). Only reachable via `videoToMusic.submit()`\n * with `mode: \"async\"`. */\nexport interface MusicTaskResult extends BaseTaskResult {\n audio?: MusicMediaEntry[];\n /** Vocals-only stem; present only when `isolateVocals` was requested. */\n vocals?: SfxMedia;\n /** Muxed output per stream; present only when `isolateVocals` was requested. */\n mux?: MusicMuxEntry[];\n /** Music ducked under the source voice; present only when `ducking` ran. */\n ducked?: MusicMediaEntry[];\n title?: MusicTitle;\n duration_seconds?: number;\n}\n\nexport interface WaitOptions {\n /** Milliseconds between polls. Default 2000. */\n pollInterval?: number;\n /** Overall deadline in milliseconds. Default 600000. */\n timeout?: number;\n}\n\n/** Result of an async video-to-video task (`videoToVideoMusic`/`videoToVideoSfx`):\n * a re-hosted video with generated music or SFX muxed in. */\nexport interface VideoResult extends BaseTaskResult {\n video?: SfxMedia;\n duration_seconds?: number;\n}\n\nexport interface VideoToVideoMusicParams {\n video?: VideoInput;\n videoUrl?: string;\n prompt?: string;\n /** Keep the source speech/vocals in the output. Both this and the legacy\n * `isolateVocals` are accepted and OR'd server-side. */\n preserveSpeech?: boolean;\n /** @deprecated Legacy alias for `preserveSpeech`. */\n isolateVocals?: boolean;\n}\n\nexport interface VideoToVideoSfxParams {\n video?: VideoInput;\n videoUrl?: string;\n prompt?: string;\n segments?: SfxSegment[];\n}\n\n/** Params for `videoToSound` and `videoToVideoSound`. Both endpoints take the\n * identical form, so they share one params type. */\nexport interface VideoToSoundParams {\n video?: VideoInput;\n videoUrl?: string;\n /** Style hint for the generated music bed. */\n musicPrompt?: string;\n /** Description of the sound effects layered over the music. */\n sfxPrompt?: string;\n /** Per-segment SFX descriptions; must start at 0 and be contiguous. */\n segments?: SfxSegment[];\n /** Keep the source speech in the result. */\n preserveSpeech?: boolean;\n /** Duck the generated music under the source speech. Default-ON\n * server-side: leave unset to keep it on, pass `false` to opt out. */\n ducking?: boolean;\n}\n\n/** Result of a `videoToSound` / `videoToVideoSound` task (`tasks.get`) or its\n * final state (`generate`).\n *\n * The combined music+SFX result is `output_url` — a bare presigned URL rather\n * than a media object, since these endpoints render one artifact whose kind is\n * announced by `output_type` (\"audio\" for video-to-sound, \"video\" for\n * video-to-video-sound). `music`, `music_processed` and `sfx` are the\n * individual stems; pass any of them, or `output_url` itself, to `download()`. */\nexport interface SoundResult extends BaseTaskResult {\n output_url?: string;\n output_type?: \"audio\" | \"video\";\n output_bytes?: number;\n music?: SfxMedia;\n /** Present only when `preserveSpeech`/`ducking` altered the music bed. */\n music_processed?: SfxMedia;\n sfx?: SfxMedia;\n duration_seconds?: number;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,cAAN,cAA0B,MAAM;AAAA,EACrC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO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AC/C;;;ACiIO,SAAS,kBAAkB,OAA8C;AAC9E,SAAO,MAAM,SAAS,iBAAkB,MAA0B,gBAAgB;AACpF;AAEO,SAAS,aAAa,OAAyC;AACpE,SAAO,MAAM,SAAS;AACxB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/resources/account.ts","../src/resources/tasks.ts","../src/streaming.ts","../src/resources/textToMusic.ts","../src/upload.ts","../src/resources/videoToMusic.ts","../src/resources/textToSfx.ts","../src/resources/videoToSfx.ts","../src/resources/videoToVideoMusic.ts","../src/resources/videoToVideoSfx.ts","../src/resources/soundForm.ts","../src/resources/videoToSound.ts","../src/resources/videoToVideoSound.ts","../src/version.ts","../src/client.ts","../src/download.ts","../src/types.ts"],"sourcesContent":["export { DEFAULT_TIMEOUT_MS, SoniloClient, type SoniloClientOptions } from \"./client.js\";\nexport {\n APIError,\n AuthenticationError,\n BadRequestError,\n GenerationError,\n PaymentRequiredError,\n RateLimitError,\n RequestTimeoutError,\n SoniloError,\n TaskFailedError,\n TaskTimeoutError,\n} from \"./errors.js\";\nexport { download } from \"./download.js\";\nexport { VERSION } from \"./version.js\";\nexport type {\n AccountServices,\n AudioChunkEvent,\n BaseTaskResult,\n CompleteEvent,\n CostEvent,\n CostInfo,\n DailyUsage,\n ErrorEvent,\n MusicMediaEntry,\n MusicMuxEntry,\n MusicTaskResult,\n MusicTitle,\n Segment,\n SegmentLabel,\n SfxAudioFormat,\n SfxError,\n SfxMedia,\n SfxResult,\n SfxSegment,\n SfxTask,\n SoundResult,\n StreamEvent,\n TextToMusicParams,\n TextToSfxParams,\n TitleEvent,\n Track,\n TrialQuota,\n UnknownEvent,\n UsageResponse,\n UsageSummary,\n VideoInput,\n VideoResult,\n VideoToMusicParams,\n VideoToSfxParams,\n VideoToSoundParams,\n VideoToVideoMusicParams,\n VideoToVideoSfxParams,\n WaitOptions,\n} from \"./types.js\";\nexport { isAudioChunkEvent, isErrorEvent } from \"./types.js\";\n","export class SoniloError extends Error {\n constructor(message: string) {\n super(message);\n this.name = new.target.name;\n }\n}\n\nexport class APIError extends SoniloError {\n readonly status: number;\n readonly body: unknown;\n /** The API's typed error code (e.g. \"rate_limit_exceeded\"), distinct from the HTTP status. */\n readonly code?: string;\n /** Per-field validation details, present on a 422. */\n readonly errors?: unknown[];\n\n constructor(message: string, status: number, body?: unknown) {\n super(message);\n this.status = status;\n this.body = body;\n const parsed = body as { code?: unknown; errors?: unknown } | undefined;\n this.code = typeof parsed?.code === \"string\" ? parsed.code : undefined;\n this.errors = Array.isArray(parsed?.errors) ? parsed.errors : undefined;\n }\n}\n\nexport class AuthenticationError extends APIError {}\n\nexport class PaymentRequiredError extends APIError {}\n\nexport class BadRequestError extends APIError {\n get detail(): string | undefined {\n const body = this.body as { message?: unknown; detail?: unknown } | undefined;\n if (typeof body?.message === \"string\" && body.message) {\n return body.message;\n }\n return typeof body?.detail === \"string\" ? body.detail : undefined;\n }\n}\n\nexport class RateLimitError extends APIError {\n readonly retryAfter?: number;\n\n constructor(message: string, status: number, body?: unknown, retryAfter?: number) {\n super(message, status, body);\n this.retryAfter = retryAfter;\n }\n}\n\n/** Raised by generate() when an `error` event arrives mid-stream. */\nexport class GenerationError extends SoniloError {\n readonly code?: string;\n\n constructor(message: string, code?: string) {\n super(message);\n this.code = code;\n }\n}\n\n/** Raised by tasks.wait()/generate() when an SFX task reaches `failed`. */\nexport class TaskFailedError extends SoniloError {\n readonly code?: string;\n readonly taskId: string;\n readonly refunded?: boolean;\n\n constructor(\n message: string,\n opts: { code?: string; taskId: string; refunded?: boolean },\n ) {\n super(message);\n this.code = opts.code;\n this.taskId = opts.taskId;\n this.refunded = opts.refunded;\n }\n}\n\n/** Poll deadline passed. The task may still finish server-side — resume with\n * tasks.wait(taskId) or tasks.get(taskId). */\nexport class TaskTimeoutError extends SoniloError {\n readonly taskId: string;\n\n constructor(message: string, taskId: string) {\n super(message);\n this.taskId = taskId;\n }\n}\n\n/** Raised when a one-shot request or download is aborted by its own timeout\n * signal (as opposed to a caller-supplied AbortSignal, which propagates\n * untouched). */\nexport class RequestTimeoutError extends SoniloError {}\n\n/**\n * True if `err` is the rejection produced when an `AbortSignal.timeout()`\n * we created fires. Used to distinguish \"our\" timeout aborts (which should be\n * rethrown as `RequestTimeoutError`) from a caller-supplied signal's abort\n * (which must propagate untouched).\n */\nexport function isTimeoutSignalError(err: unknown): boolean {\n return err instanceof Error && (err.name === \"TimeoutError\" || err.name === \"AbortError\");\n}\n\nexport async function errorFromResponse(res: Response): Promise<APIError> {\n const text = await res.text().catch(() => \"\");\n let body: unknown = text;\n try {\n body = JSON.parse(text);\n } catch {\n // keep raw text\n }\n const parsed = body as { message?: unknown; detail?: unknown } | undefined;\n const rawMessage = typeof parsed?.message === \"string\" && parsed.message ? parsed.message : undefined;\n const rawDetail = parsed?.detail;\n const isDetailAbsent = rawDetail === undefined || rawDetail === null || rawDetail === \"\";\n let reason: string;\n if (rawMessage !== undefined) {\n reason = rawMessage;\n } else if (isDetailAbsent) {\n reason = res.statusText || \"request failed\";\n } else if (typeof rawDetail === \"string\") {\n reason = rawDetail;\n } else {\n try {\n reason = JSON.stringify(rawDetail);\n } catch {\n reason = res.statusText || \"request failed\";\n }\n }\n const message = `HTTP ${res.status}: ${reason}`;\n\n switch (res.status) {\n case 401:\n return new AuthenticationError(message, res.status, body);\n case 402:\n return new PaymentRequiredError(message, res.status, body);\n case 429: {\n const ra = res.headers.get(\"retry-after\");\n const retryAfter = ra !== null && ra !== \"\" && !Number.isNaN(Number(ra)) ? Number(ra) : undefined;\n return new RateLimitError(message, res.status, body, retryAfter);\n }\n case 400:\n case 413:\n case 422:\n return new BadRequestError(message, res.status, body);\n default:\n return new APIError(message, res.status, body);\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport type { AccountServices, UsageResponse } from \"../types.js\";\n\nexport class Account {\n constructor(private readonly client: SoniloClient) {}\n\n async services(): Promise<AccountServices> {\n const res = await this.client.request(\"/v1/account/services\");\n return (await res.json()) as AccountServices;\n }\n\n async usage(params: { days?: number } = {}): Promise<UsageResponse> {\n const query = params.days !== undefined ? `?days=${params.days}` : \"\";\n const res = await this.client.request(`/v1/account/usage${query}`);\n return (await res.json()) as UsageResponse;\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError, TaskFailedError, TaskTimeoutError } from \"../errors.js\";\nimport type { BaseTaskResult, SfxResult, WaitOptions } from \"../types.js\";\n\nexport const DEFAULT_POLL_INTERVAL_MS = 2000;\nexport const DEFAULT_WAIT_TIMEOUT_MS = 600_000;\n\nconst sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));\n\n/** A negative delay is clamped to 0 by setTimeout, which would turn the poll\n * loop into a busy loop hammering the API until the deadline. */\nfunction validateWaitArgs(pollInterval: number, timeout: number): void {\n if (pollInterval < 0) {\n throw new SoniloError(`pollInterval must be >= 0, got ${pollInterval}`);\n }\n if (timeout < 0) {\n throw new SoniloError(`timeout must be >= 0, got ${timeout}`);\n }\n}\n\nexport class Tasks {\n constructor(private readonly client: SoniloClient) {}\n\n /**\n * Fetch current task state. Never throws on a failed status.\n *\n * Generic over the result shape so callers can request the endpoint-\n * specific type, e.g. `client.tasks.get<MusicTaskResult>(taskId)`.\n * Defaults to `SfxResult` for back-compat.\n */\n async get<T extends BaseTaskResult = SfxResult>(taskId: string): Promise<T> {\n const res = await this.client.request(`/v1/tasks/${encodeURIComponent(taskId)}`);\n return (await res.json()) as T;\n }\n\n /**\n * Poll until the task is terminal; throw on failure or deadline.\n *\n * Generic over the result shape, e.g.\n * `client.tasks.wait<MusicTaskResult>(taskId)`. Defaults to `SfxResult`\n * for back-compat.\n */\n async wait<T extends BaseTaskResult = SfxResult>(\n taskId: string,\n opts: WaitOptions = {},\n ): Promise<T> {\n const pollInterval = opts.pollInterval ?? DEFAULT_POLL_INTERVAL_MS;\n const timeout = opts.timeout ?? DEFAULT_WAIT_TIMEOUT_MS;\n validateWaitArgs(pollInterval, timeout);\n const deadline = performance.now() + timeout;\n for (;;) {\n const result = await this.get<T>(taskId);\n if (result.status === \"succeeded\") return result;\n if (result.status === \"failed\") {\n const message = result.error?.message || \"Generation failed\";\n throw new TaskFailedError(`Task ${taskId} failed: ${message}`, {\n code: result.error?.code,\n taskId,\n refunded: result.refunded,\n });\n }\n const remaining = deadline - performance.now();\n if (remaining <= 0) {\n throw new TaskTimeoutError(\n `Task ${taskId} still processing after ${timeout}ms; ` +\n \"it may finish later — resume with tasks.wait or tasks.get\",\n taskId,\n );\n }\n await sleep(Math.min(pollInterval, remaining));\n }\n }\n}\n","import { GenerationError } from \"./errors.js\";\nimport type { CostInfo, StreamEvent, Track } from \"./types.js\";\n\nexport function decodeBase64(b64: string): Uint8Array {\n const bin = atob(b64);\n const out = new Uint8Array(bin.length);\n for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);\n return out;\n}\n\n/** Returns `null` for a valid-JSON-but-non-object line (e.g. a bare `null`\n * or a number/string), which carries no event `type` and is skipped like any\n * other junk line rather than crashing on a `.type` read off `null`. */\nfunction toEvent(line: string): StreamEvent | null {\n const parsed: unknown = JSON.parse(line);\n if (typeof parsed !== \"object\" || parsed === null) return null;\n const raw = parsed as { type: string; [key: string]: unknown };\n if (raw.type === \"audio_chunk\" && typeof raw.data === \"string\") {\n try {\n return { ...raw, type: \"audio_chunk\", data: decodeBase64(raw.data) };\n } catch {\n // Don't raise here: this must reach collectTrack's malformed-chunk\n // check, which turns undecodable data into a typed GenerationError.\n // Raising in place would let a raw DOMException escape\n // stream()/generate(), breaking the SDK's \"all errors extend\n // SoniloError\" contract.\n }\n }\n return raw as StreamEvent;\n}\n\nexport async function* parseNdjson(\n body: ReadableStream<Uint8Array>,\n): AsyncGenerator<StreamEvent, void, undefined> {\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n buffer += decoder.decode(value, { stream: true });\n let nl: number;\n while ((nl = buffer.indexOf(\"\\n\")) !== -1) {\n const line = buffer.slice(0, nl).trim();\n buffer = buffer.slice(nl + 1);\n if (line) {\n const ev = toEvent(line);\n if (ev !== null) yield ev;\n }\n }\n }\n buffer += decoder.decode();\n const tail = buffer.trim();\n if (tail) {\n const ev = toEvent(tail);\n if (ev !== null) yield ev;\n }\n } finally {\n await reader.cancel().catch(() => {});\n }\n}\n\nexport async function collectTrack(events: AsyncIterable<StreamEvent>): Promise<Track> {\n const chunks: Uint8Array[] = [];\n let title: string | undefined;\n let cost: CostInfo | undefined;\n let sawComplete = false;\n\n for await (const ev of events) {\n if (ev.type === \"audio_chunk\") {\n // A malformed chunk (missing/non-decodable `data`) must not be\n // silently dropped: that would hand back a \"successful\" Track with\n // empty or truncated audio and no indication anything went wrong.\n if (!(ev.data instanceof Uint8Array)) {\n throw new GenerationError(\n \"received a malformed audio_chunk event (missing or non-decodable data)\",\n );\n }\n chunks.push(ev.data);\n } else if (ev.type === \"title\" && typeof ev.title === \"string\") {\n title = ev.title;\n } else if (ev.type === \"cost\") {\n const { type: _type, ...rest } = ev;\n cost = rest as CostInfo;\n } else if (ev.type === \"error\") {\n const message = typeof ev.message === \"string\" && ev.message !== \"\" ? ev.message : \"generation failed\";\n const code = typeof ev.code === \"string\" ? ev.code : undefined;\n throw new GenerationError(message, code);\n } else if (ev.type === \"complete\") {\n sawComplete = true;\n }\n // unknown event types: ignored\n }\n\n if (!sawComplete) {\n throw new GenerationError(\"stream ended before a 'complete' event (truncated response)\");\n }\n\n const total = chunks.reduce((n, c) => n + c.length, 0);\n const audio = new Uint8Array(total);\n let offset = 0;\n for (const c of chunks) {\n audio.set(c, offset);\n offset += c.length;\n }\n return { audio, title, cost };\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError } from \"../errors.js\";\nimport { collectTrack, parseNdjson } from \"../streaming.js\";\nimport type { SfxTask, StreamEvent, TextToMusicParams, Track } from \"../types.js\";\n\nexport class TextToMusic {\n constructor(private readonly client: SoniloClient) {}\n\n /** Stream raw generation events (audio chunks pre-decoded to bytes). */\n async *stream(params: TextToMusicParams): AsyncGenerator<StreamEvent, void, undefined> {\n const form = new FormData();\n form.set(\"prompt\", params.prompt);\n form.set(\"duration\", String(params.duration));\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n // Opt out of the client's absolute request timeout: this holds the\n // response body open and reads NDJSON chunks for as long as generation\n // takes, so an AbortSignal keyed to elapsed time would kill a healthy,\n // still-streaming, long-duration track. Pass `params.signal` yourself to\n // bound or cancel the stream instead — it is forwarded to `fetch` as-is.\n const res = await this.client.request(\n \"/v1/text-to-music\",\n { method: \"POST\", body: form, signal: params.signal },\n { timeout: null },\n );\n if (!res.body) throw new SoniloError(\"Response has no body\");\n yield* parseNdjson(res.body);\n }\n\n /** Generate and buffer the whole track; throws GenerationError on stream errors. */\n generate(params: TextToMusicParams): Promise<Track> {\n return collectTrack(this.stream(params));\n }\n\n /**\n * Submit an async text-to-music task; poll with\n * `client.tasks.wait<MusicTaskResult>(task.task_id)`. Required for\n * `outputFormat: \"wav\"`. `stream()`/`generate()` remain the streaming path.\n */\n async submit(params: TextToMusicParams): Promise<SfxTask> {\n const mode = params.mode ?? \"async\";\n if (mode !== \"async\") {\n throw new SoniloError('submit() requires mode: \"async\"');\n }\n const form = new FormData();\n form.set(\"prompt\", params.prompt);\n form.set(\"duration\", String(params.duration));\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n form.set(\"mode\", mode);\n if (params.outputFormat !== undefined) {\n form.set(\"output_format\", params.outputFormat);\n }\n const res = await this.client.request(\"/v1/text-to-music\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n}\n","import { SoniloError } from \"./errors.js\";\nimport type { VideoInput } from \"./types.js\";\n\nconst DEFAULT_FILENAME = \"video.mp4\";\n\n/**\n * Normalize every accepted video input into a FormData-ready Blob.\n * String inputs are file paths and work only in Node.js; browsers must\n * pass File/Blob/bytes/streams.\n */\nexport async function toUploadBlob(\n video: VideoInput,\n): Promise<{ blob: Blob; filename: string }> {\n if (typeof video === \"string\") {\n const isNode =\n typeof process !== \"undefined\" && Boolean((process as { versions?: { node?: string } }).versions?.node);\n if (!isNode) {\n throw new SoniloError(\n \"File paths are only supported in Node.js; pass a File or Blob in the browser\",\n );\n }\n const fsModule = \"node:fs/promises\";\n const { readFile } = (await import(\n /* webpackIgnore: true */ /* @vite-ignore */ fsModule\n )) as typeof import(\"node:fs/promises\");\n const data = await readFile(video);\n const filename = video.split(/[\\\\/]/).pop() || DEFAULT_FILENAME;\n return { blob: new Blob([data]), filename };\n }\n if (typeof File !== \"undefined\" && video instanceof File) {\n return { blob: video, filename: video.name || DEFAULT_FILENAME };\n }\n if (video instanceof Blob) {\n return { blob: video, filename: DEFAULT_FILENAME };\n }\n if (video instanceof Uint8Array) {\n return { blob: new Blob([video as unknown as BlobPart]), filename: DEFAULT_FILENAME };\n }\n if (video instanceof ArrayBuffer) {\n return { blob: new Blob([video]), filename: DEFAULT_FILENAME };\n }\n if (video instanceof ReadableStream) {\n return { blob: await new Response(video).blob(), filename: DEFAULT_FILENAME };\n }\n throw new SoniloError(\"Unsupported video input type\");\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError } from \"../errors.js\";\nimport { collectTrack, parseNdjson } from \"../streaming.js\";\nimport { toUploadBlob } from \"../upload.js\";\nimport type { SfxTask, StreamEvent, Track, VideoToMusicParams } from \"../types.js\";\n\nexport class VideoToMusic {\n constructor(private readonly client: SoniloClient) {}\n\n async *stream(params: VideoToMusicParams): AsyncGenerator<StreamEvent, void, undefined> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.prompt !== undefined) form.set(\"prompt\", params.prompt);\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n // Opt out of the client's absolute request timeout: this holds the\n // response body open and reads NDJSON chunks for as long as generation\n // takes, so an AbortSignal keyed to elapsed time would kill a healthy,\n // still-streaming request (e.g. a slow video upload or long track). Pass\n // `params.signal` yourself to bound or cancel the stream instead — it is\n // forwarded to `fetch` as-is.\n const res = await this.client.request(\n \"/v1/video-to-music\",\n { method: \"POST\", body: form, signal: params.signal },\n { timeout: null },\n );\n if (!res.body) throw new SoniloError(\"Response has no body\");\n yield* parseNdjson(res.body);\n }\n\n generate(params: VideoToMusicParams): Promise<Track> {\n return collectTrack(this.stream(params));\n }\n\n /**\n * Submit an async video-to-music task; poll its result with\n * `client.tasks.wait<MusicTaskResult>(task.task_id)`. Required for\n * `isolateVocals` — the backend rejects vocal isolation on the plain\n * stream, and it only ever runs in async mode.\n */\n async submit(params: VideoToMusicParams): Promise<SfxTask> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n let mode = params.mode;\n const needsAsync =\n params.isolateVocals ||\n params.preserveSpeech ||\n params.ducking !== undefined ||\n params.outputFormat === \"wav\";\n // submit() always wants an async task ack, never a stream. Default to\n // async; only object if the caller explicitly asked for stream while\n // also requesting an async-only feature.\n if (mode === undefined) mode = \"async\";\n if (needsAsync && mode !== \"async\") {\n throw new SoniloError(\n 'isolateVocals/preserveSpeech/ducking/outputFormat \"wav\" require mode: \"async\"',\n );\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.prompt !== undefined) form.set(\"prompt\", params.prompt);\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n form.set(\"mode\", mode);\n if (params.preserveSpeech !== undefined) {\n form.set(\"preserve_speech\", String(params.preserveSpeech));\n }\n if (params.isolateVocals !== undefined) {\n form.set(\"isolate_vocals\", String(params.isolateVocals));\n }\n if (params.outputFormat !== undefined) {\n form.set(\"output_format\", params.outputFormat);\n }\n if (params.ducking !== undefined) {\n form.set(\"ducking\", String(params.ducking));\n }\n const res = await this.client.request(\"/v1/video-to-music\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport type { SfxResult, SfxTask, TextToSfxParams, WaitOptions } from \"../types.js\";\n\nexport class TextToSfx {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: TextToSfxParams): Promise<SfxTask> {\n const form = new FormData();\n form.set(\"prompt\", params.prompt);\n form.set(\"duration\", String(params.duration));\n if (params.audioFormat !== undefined) form.set(\"audio_format\", params.audioFormat);\n const res = await this.client.request(\"/v1/text-to-sfx\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: TextToSfxParams, opts?: WaitOptions): Promise<SfxResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait(task.task_id, opts);\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError } from \"../errors.js\";\nimport { toUploadBlob } from \"../upload.js\";\nimport type { SfxResult, SfxTask, VideoToSfxParams, WaitOptions } from \"../types.js\";\n\nexport class VideoToSfx {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: VideoToSfxParams): Promise<SfxTask> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.prompt !== undefined) form.set(\"prompt\", params.prompt);\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n if (params.audioFormat !== undefined) form.set(\"audio_format\", params.audioFormat);\n const res = await this.client.request(\"/v1/video-to-sfx\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: VideoToSfxParams, opts?: WaitOptions): Promise<SfxResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait(task.task_id, opts);\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError } from \"../errors.js\";\nimport { toUploadBlob } from \"../upload.js\";\nimport type { SfxTask, VideoResult, VideoToVideoMusicParams, WaitOptions } from \"../types.js\";\n\n/** Generate an original score for a video and get back a re-hosted video with\n * the music muxed in. Async only: `submit()` returns a task ack; poll with\n * `client.tasks.wait<VideoResult>(id)`, or use `generate()` to do both. */\nexport class VideoToVideoMusic {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: VideoToVideoMusicParams): Promise<SfxTask> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.prompt !== undefined) form.set(\"prompt\", params.prompt);\n if (params.preserveSpeech !== undefined) {\n form.set(\"preserve_speech\", String(params.preserveSpeech));\n }\n if (params.isolateVocals !== undefined) {\n form.set(\"isolate_vocals\", String(params.isolateVocals));\n }\n const res = await this.client.request(\"/v1/video-to-video-music\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: VideoToVideoMusicParams, opts?: WaitOptions): Promise<VideoResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait<VideoResult>(task.task_id, opts);\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError } from \"../errors.js\";\nimport { toUploadBlob } from \"../upload.js\";\nimport type { SfxTask, VideoResult, VideoToVideoSfxParams, WaitOptions } from \"../types.js\";\n\n/** Generate sound effects for a video and get back a re-hosted video with the\n * SFX muxed in. Async only. */\nexport class VideoToVideoSfx {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: VideoToVideoSfxParams): Promise<SfxTask> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.prompt !== undefined) form.set(\"prompt\", params.prompt);\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n const res = await this.client.request(\"/v1/video-to-video-sfx\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: VideoToVideoSfxParams, opts?: WaitOptions): Promise<VideoResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait<VideoResult>(task.task_id, opts);\n }\n}\n","import { SoniloError } from \"../errors.js\";\nimport { toUploadBlob } from \"../upload.js\";\nimport type { VideoToSoundParams } from \"../types.js\";\n\n/** Build the multipart body shared by /v1/video-to-sound and\n * /v1/video-to-video-sound — their form fields are identical, so the two\n * resources differ only in the path they POST to.\n *\n * Every optional field is omitted when unset rather than sent with a default:\n * `ducking` in particular is default-ON server-side, so an unset value must\n * not become an explicit \"false\" on the wire. */\nexport async function buildSoundForm(params: VideoToSoundParams): Promise<FormData> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.musicPrompt !== undefined) form.set(\"music_prompt\", params.musicPrompt);\n if (params.sfxPrompt !== undefined) form.set(\"sfx_prompt\", params.sfxPrompt);\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n if (params.preserveSpeech !== undefined) {\n form.set(\"preserve_speech\", String(params.preserveSpeech));\n }\n if (params.ducking !== undefined) form.set(\"ducking\", String(params.ducking));\n return form;\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { buildSoundForm } from \"./soundForm.js\";\nimport type { SfxTask, SoundResult, VideoToSoundParams, WaitOptions } from \"../types.js\";\n\n/** Generate a combined music + sound-effects track for a video and get back\n * the mixed audio. Async only. */\nexport class VideoToSound {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: VideoToSoundParams): Promise<SfxTask> {\n const res = await this.client.request(\"/v1/video-to-sound\", {\n method: \"POST\",\n body: await buildSoundForm(params),\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: VideoToSoundParams, opts?: WaitOptions): Promise<SoundResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait<SoundResult>(task.task_id, opts);\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { buildSoundForm } from \"./soundForm.js\";\nimport type { SfxTask, SoundResult, VideoToSoundParams, WaitOptions } from \"../types.js\";\n\n/** Generate a combined music + sound-effects track for a video and get back a\n * re-hosted video with that track muxed in. Async only. */\nexport class VideoToVideoSound {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: VideoToSoundParams): Promise<SfxTask> {\n const res = await this.client.request(\"/v1/video-to-video-sound\", {\n method: \"POST\",\n body: await buildSoundForm(params),\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: VideoToSoundParams, opts?: WaitOptions): Promise<SoundResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait<SoundResult>(task.task_id, opts);\n }\n}\n","/** The SDK's own version. Generated by scripts/sync-versions.mjs — do not edit. */\nexport const VERSION = \"0.6.0\";\n","import { RequestTimeoutError, SoniloError, errorFromResponse, isTimeoutSignalError } from \"./errors.js\";\nimport { Account } from \"./resources/account.js\";\nimport { Tasks } from \"./resources/tasks.js\";\nimport { TextToMusic } from \"./resources/textToMusic.js\";\nimport { VideoToMusic } from \"./resources/videoToMusic.js\";\nimport { TextToSfx } from \"./resources/textToSfx.js\";\nimport { VideoToSfx } from \"./resources/videoToSfx.js\";\nimport { VideoToVideoMusic } from \"./resources/videoToVideoMusic.js\";\nimport { VideoToVideoSfx } from \"./resources/videoToVideoSfx.js\";\nimport { VideoToSound } from \"./resources/videoToSound.js\";\nimport { VideoToVideoSound } from \"./resources/videoToVideoSound.js\";\nimport { VERSION } from \"./version.js\";\n\nexport interface SoniloClientOptions {\n /** Defaults to the SONILO_API_KEY environment variable (Node.js only). */\n apiKey?: string;\n /** Defaults to https://api.sonilo.com */\n baseUrl?: string;\n /** Injection point for tests and custom transports. */\n fetch?: typeof globalThis.fetch;\n /** Milliseconds before an in-flight request is aborted. Default 600000. */\n timeout?: number;\n /**\n * Identifies a wrapper built on this SDK (the CLI, the video kit) in the\n * `X-Sonilo-Client` header. Leave unset for direct SDK use — without an\n * override a wrapper's traffic is indistinguishable from the SDK's own.\n */\n clientName?: string;\n /** Version reported alongside `clientName`. Defaults to the SDK's version. */\n clientVersion?: string;\n}\n\nconst DEFAULT_BASE_URL = \"https://api.sonilo.com\";\n\n/**\n * Reported in `X-Sonilo-Client` unless a wrapper overrides it. First-party\n * wrappers (the CLI, the video kit) pass their own name so their traffic stays\n * distinguishable from direct SDK use in server-side analytics.\n */\nexport const DEFAULT_CLIENT_NAME = \"sdk-js\";\n\n/** Milliseconds before an in-flight request is aborted, unless overridden. */\nexport const DEFAULT_TIMEOUT_MS = 600_000;\n\nexport class SoniloClient {\n readonly baseUrl: string;\n private readonly apiKey: string;\n private readonly fetchFn: typeof globalThis.fetch;\n private readonly timeout: number;\n private readonly clientName: string;\n private readonly clientVersion: string;\n readonly account: Account;\n readonly tasks: Tasks;\n readonly textToMusic: TextToMusic;\n readonly videoToMusic: VideoToMusic;\n readonly textToSfx: TextToSfx;\n readonly videoToSfx: VideoToSfx;\n readonly videoToVideoMusic: VideoToVideoMusic;\n readonly videoToVideoSfx: VideoToVideoSfx;\n readonly videoToSound: VideoToSound;\n readonly videoToVideoSound: VideoToVideoSound;\n\n constructor(options: SoniloClientOptions = {}) {\n const envKey =\n typeof process !== \"undefined\" ? process.env?.SONILO_API_KEY : undefined;\n const apiKey = options.apiKey ?? envKey;\n if (!apiKey) {\n throw new SoniloError(\n \"Missing API key: pass { apiKey } or set the SONILO_API_KEY environment variable\",\n );\n }\n this.apiKey = apiKey;\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.fetchFn = (options.fetch ?? globalThis.fetch).bind(globalThis);\n this.timeout = options.timeout ?? DEFAULT_TIMEOUT_MS;\n this.clientName = options.clientName ?? DEFAULT_CLIENT_NAME;\n this.clientVersion = options.clientVersion ?? VERSION;\n this.account = new Account(this);\n this.tasks = new Tasks(this);\n this.textToMusic = new TextToMusic(this);\n this.videoToMusic = new VideoToMusic(this);\n this.textToSfx = new TextToSfx(this);\n this.videoToSfx = new VideoToSfx(this);\n this.videoToVideoMusic = new VideoToVideoMusic(this);\n this.videoToVideoSfx = new VideoToVideoSfx(this);\n this.videoToSound = new VideoToSound(this);\n this.videoToVideoSound = new VideoToVideoSound(this);\n }\n\n /**\n * Perform an authenticated request; throws a typed error on non-2xx.\n *\n * `opts.timeout` overrides the client's default timeout for this call;\n * pass `null` to disable the abort-on-timeout behavior entirely (used by\n * the streaming music endpoints — see textToMusic.ts / videoToMusic.ts).\n * A caller-supplied `init.signal` always wins over any timeout signal.\n */\n async request(\n path: string,\n init: RequestInit = {},\n opts: { timeout?: number | null } = {},\n ): Promise<Response> {\n const headers = new Headers(init.headers);\n headers.set(\"Authorization\", `Bearer ${this.apiKey}`);\n headers.set(\"X-Sonilo-Client\", this.clientName);\n headers.set(\"X-Sonilo-Client-Version\", this.clientVersion);\n const timeout = opts.timeout === undefined ? this.timeout : opts.timeout;\n // We only \"own\" the signal (and may later rewrap its abort as a\n // RequestTimeoutError) when the caller didn't supply one and a timeout\n // is actually enabled.\n const ownsSignal = init.signal == null && timeout !== null;\n const signal = init.signal ?? (timeout === null ? undefined : AbortSignal.timeout(timeout));\n try {\n const res = await this.fetchFn(`${this.baseUrl}${path}`, { ...init, headers, signal });\n if (!res.ok) throw await errorFromResponse(res);\n return res;\n } catch (err) {\n if (ownsSignal && isTimeoutSignalError(err)) {\n throw new RequestTimeoutError(`Request to ${path} timed out after ${timeout}ms`);\n }\n throw err;\n }\n }\n}\n","import { DEFAULT_TIMEOUT_MS } from \"./client.js\";\nimport { RequestTimeoutError, SoniloError, isTimeoutSignalError } from \"./errors.js\";\nimport type { SfxMedia } from \"./types.js\";\n\n/** Fetch a result media file. The URL is presigned — no API key is sent.\n *\n * Accepts either a media object (`result.audio`, `result.music`, …) or a bare\n * URL string, which is what the combined video-to-sound endpoints return as\n * `output_url`. */\nexport async function download(\n media: SfxMedia | string | undefined,\n fetchFn: typeof globalThis.fetch = globalThis.fetch,\n timeout: number = DEFAULT_TIMEOUT_MS,\n): Promise<Uint8Array> {\n const url = typeof media === \"string\" ? media : media?.url;\n if (!url) {\n throw new SoniloError(\"No media to download\");\n }\n let res: Response;\n try {\n res = await fetchFn(url, { signal: AbortSignal.timeout(timeout) });\n } catch (err) {\n if (isTimeoutSignalError(err)) {\n throw new RequestTimeoutError(`Download of ${url} timed out after ${timeout}ms`);\n }\n throw err;\n }\n if (!res.ok) {\n throw new SoniloError(`Download failed: HTTP ${res.status}`);\n }\n return new Uint8Array(await res.arrayBuffer());\n}\n","export type SegmentLabel =\n | \"intro\"\n | \"verse\"\n | \"pre-chorus\"\n | \"chorus\"\n | \"bridge\"\n | \"break\"\n | \"silence\"\n | \"outro\"\n | \"none\";\n\nexport interface Segment {\n start: number;\n prompt: string;\n label?: SegmentLabel;\n}\n\n/** Monetary fields are strings, exactly as the backend serializes them. */\nexport interface CostInfo {\n billing_rate_per_sec: string;\n billing_before_discount: string;\n billing_after_discount: string;\n discount_factor: string;\n}\n\nexport interface AudioChunkEvent {\n type: \"audio_chunk\";\n /** Decoded from the wire's base64 by the SDK. */\n data: Uint8Array;\n}\n\nexport interface TitleEvent {\n type: \"title\";\n title: string;\n summary?: string;\n display_tags?: string[];\n [key: string]: unknown;\n}\n\nexport interface CompleteEvent {\n type: \"complete\";\n [key: string]: unknown;\n}\n\nexport interface ErrorEvent {\n type: \"error\";\n code?: string;\n message?: string;\n [key: string]: unknown;\n}\n\nexport interface CostEvent extends CostInfo {\n type: \"cost\";\n}\n\n/** Forward-compatibility: unrecognized event types are passed through. */\nexport interface UnknownEvent {\n type: string;\n [key: string]: unknown;\n}\n\nexport type StreamEvent =\n | AudioChunkEvent\n | TitleEvent\n | CompleteEvent\n | ErrorEvent\n | CostEvent\n | UnknownEvent;\n\nexport interface Track {\n audio: Uint8Array;\n title?: string;\n cost?: CostInfo;\n}\n\nexport interface TextToMusicParams {\n prompt: string;\n duration: number;\n segments?: Segment[];\n /** \"stream\" (default) or \"async\" (required by `submit()` and `output_format: \"wav\"`). */\n mode?: \"stream\" | \"async\";\n /** Container for the async result. `wav` requires `mode: \"async\"`. Defaults to m4a server-side. */\n outputFormat?: \"m4a\" | \"wav\";\n /** Bounds the stream: aborting this cancels the in-flight generation.\n * Passed straight through to `fetch` — it is never rewrapped as\n * RequestTimeoutError, since the client's own absolute timeout does not\n * apply to streaming music generation. */\n signal?: AbortSignal;\n}\n\n/** string = file path (Node.js only). */\nexport type VideoInput =\n | File\n | Blob\n | Uint8Array\n | ArrayBuffer\n | ReadableStream<Uint8Array>\n | string;\n\nexport interface VideoToMusicParams {\n video?: VideoInput;\n videoUrl?: string;\n prompt?: string;\n segments?: Segment[];\n /** Bounds the stream: aborting this cancels the in-flight generation.\n * Passed straight through to `fetch` — it is never rewrapped as\n * RequestTimeoutError, since the client's own absolute timeout does not\n * apply to streaming music generation. Only meaningful for `stream()`/\n * `generate()`; `submit()` ignores it. */\n signal?: AbortSignal;\n /** \"stream\" (the default, used by `stream()`/`generate()`) or \"async\"\n * (required for `submit()`, and for `isolateVocals`). Only consulted by\n * `submit()` — `stream()`/`generate()` always request a stream. */\n mode?: \"stream\" | \"async\";\n /** Split the generated track into a vocals-only stem alongside the mix.\n * Requires `mode: \"async\"`; if `mode` is left unset it defaults to\n * \"async\" automatically. Only usable via `submit()` — the backend\n * rejects it on the plain stream. */\n isolateVocals?: boolean;\n /** Keep the source speech/vocals in the async result. Current name for\n * `isolateVocals`; both are accepted and OR'd server-side. Requires\n * `mode: \"async\"` (auto-selected by `submit()`). */\n preserveSpeech?: boolean;\n /** Container for the async result. `wav` requires async. Defaults to m4a. */\n outputFormat?: \"m4a\" | \"wav\";\n /** Duck the generated music under the source voice at finalize time.\n * Default-ON server-side in async mode: leave unset to keep it on, pass\n * `false` to opt out. Free, best-effort; only valid on `submit()`. */\n ducking?: boolean;\n}\n\nexport interface TrialQuota {\n granted: number;\n used: number;\n remaining: number;\n}\n\nexport interface AccountServices {\n available_services: string[];\n rpm_limit: number;\n concurrency_limit: number;\n discount_factor: number | string;\n max_upload_size_mb: number | null;\n /** Free-trial allowance keyed by service. Returned only for self-serve\n * accounts; absent entirely for invoiced accounts. */\n trial?: Record<string, TrialQuota>;\n}\n\nexport interface UsageSummary {\n total_requests: number;\n total_duration_seconds: number;\n total_cost: number | string;\n period_start: string;\n period_end: string;\n [key: string]: unknown;\n}\n\nexport interface DailyUsage {\n date: string;\n requests: number;\n duration_seconds: number;\n cost: number | string;\n}\n\nexport interface UsageResponse {\n summary: UsageSummary;\n daily: DailyUsage[];\n}\n\nexport function isAudioChunkEvent(event: StreamEvent): event is AudioChunkEvent {\n return event.type === \"audio_chunk\" && (event as AudioChunkEvent).data instanceof Uint8Array;\n}\n\nexport function isErrorEvent(event: StreamEvent): event is ErrorEvent {\n return event.type === \"error\";\n}\n\n/** SFX segments (unlike music `Segment`) require `end`, must start at 0,\n * and be contiguous; validated server-side. */\nexport interface SfxSegment {\n start: number;\n end: number;\n prompt: string;\n}\n\nexport type SfxAudioFormat = \"wav\" | \"mp3\" | \"aac\" | \"flac\";\n\n/** Submission ack for the async SFX endpoints. */\nexport interface SfxTask {\n task_id: string;\n status: string;\n}\n\n/** A generated file re-hosted on R2 behind a presigned URL. */\nexport interface SfxMedia {\n url: string;\n content_type?: string;\n file_size?: number;\n}\n\nexport interface SfxError {\n code?: string;\n message?: string;\n}\n\n/**\n * Common shape of any polled task (`tasks.get`/`tasks.wait`), regardless of\n * which endpoint created it. `Tasks.get`/`Tasks.wait` are generic over this so\n * each endpoint's result type (e.g. `SfxResult`, `MusicTaskResult`) can add\n * its own `audio`/media fields while sharing the status/error/refund\n * bookkeeping the poller relies on.\n */\nexport interface BaseTaskResult {\n task_id: string;\n type?: string;\n status: \"processing\" | \"succeeded\" | \"failed\" | (string & {});\n /** Only present when the account's task-field whitelist enables cost. */\n cost?: number;\n error?: SfxError;\n refunded?: boolean;\n [key: string]: unknown;\n}\n\n/** State of an SFX task (`tasks.get`) or its final result (`wait`/`generate`). */\nexport interface SfxResult extends BaseTaskResult {\n audio?: SfxMedia;\n /** Kept for backward compatibility; no longer populated — video-to-sfx returns audio only. */\n video?: SfxMedia;\n}\n\nexport interface TextToSfxParams {\n prompt: string;\n duration: number;\n audioFormat?: SfxAudioFormat;\n}\n\nexport interface VideoToSfxParams {\n video?: VideoInput;\n videoUrl?: string;\n prompt?: string;\n segments?: SfxSegment[];\n audioFormat?: SfxAudioFormat;\n}\n\n/** One decoded audio stream of an async video-to-music result. Unlike SFX,\n * `audio` on a music task is always an array — even without `isolateVocals` —\n * since a music generation can carry more than one output stream. */\nexport interface MusicMediaEntry extends SfxMedia {\n stream_index: number;\n sample_rate?: number;\n channels?: number;\n}\n\n/** One muxed audio+video-aligned output, present only when `isolateVocals`\n * is set. */\nexport interface MusicMuxEntry extends SfxMedia {\n stream_index: number;\n}\n\nexport interface MusicTitle {\n title: string;\n summary?: string;\n display_tags?: string[];\n}\n\n/** State of an async video-to-music task (`tasks.get`) or its final result\n * (`tasks.wait<MusicTaskResult>()`). Only reachable via `videoToMusic.submit()`\n * with `mode: \"async\"`. */\nexport interface MusicTaskResult extends BaseTaskResult {\n audio?: MusicMediaEntry[];\n /** Vocals-only stem; present only when `isolateVocals` was requested. */\n vocals?: SfxMedia;\n /** Muxed output per stream; present only when `isolateVocals` was requested. */\n mux?: MusicMuxEntry[];\n /** Music ducked under the source voice; present only when `ducking` ran. */\n ducked?: MusicMediaEntry[];\n title?: MusicTitle;\n duration_seconds?: number;\n}\n\nexport interface WaitOptions {\n /** Milliseconds between polls. Default 2000. */\n pollInterval?: number;\n /** Overall deadline in milliseconds. Default 600000. */\n timeout?: number;\n}\n\n/** Result of an async video-to-video task (`videoToVideoMusic`/`videoToVideoSfx`):\n * a re-hosted video with generated music or SFX muxed in. */\nexport interface VideoResult extends BaseTaskResult {\n video?: SfxMedia;\n duration_seconds?: number;\n}\n\nexport interface VideoToVideoMusicParams {\n video?: VideoInput;\n videoUrl?: string;\n prompt?: string;\n /** Keep the source speech/vocals in the output. Both this and the legacy\n * `isolateVocals` are accepted and OR'd server-side. */\n preserveSpeech?: boolean;\n /** @deprecated Legacy alias for `preserveSpeech`. */\n isolateVocals?: boolean;\n}\n\nexport interface VideoToVideoSfxParams {\n video?: VideoInput;\n videoUrl?: string;\n prompt?: string;\n segments?: SfxSegment[];\n}\n\n/** Params for `videoToSound` and `videoToVideoSound`. Both endpoints take the\n * identical form, so they share one params type. */\nexport interface VideoToSoundParams {\n video?: VideoInput;\n videoUrl?: string;\n /** Style hint for the generated music bed. */\n musicPrompt?: string;\n /** Description of the sound effects layered over the music. */\n sfxPrompt?: string;\n /** Per-segment SFX descriptions; must start at 0 and be contiguous. */\n segments?: SfxSegment[];\n /** Keep the source speech in the result. */\n preserveSpeech?: boolean;\n /** Duck the generated music under the source speech. Default-ON\n * server-side: leave unset to keep it on, pass `false` to opt out. */\n ducking?: boolean;\n}\n\n/** Result of a `videoToSound` / `videoToVideoSound` task (`tasks.get`) or its\n * final state (`generate`).\n *\n * The combined music+SFX result is `output_url` — a bare presigned URL rather\n * than a media object, since these endpoints render one artifact whose kind is\n * announced by `output_type` (\"audio\" for video-to-sound, \"video\" for\n * video-to-video-sound). `music`, `music_processed` and `sfx` are the\n * individual stems; pass any of them, or `output_url` itself, to `download()`. */\nexport interface SoundResult extends BaseTaskResult {\n output_url?: string;\n output_type?: \"audio\" | \"video\";\n output_bytes?: number;\n music?: SfxMedia;\n /** Present only when `preserveSpeech`/`ducking` altered the music bed. */\n music_processed?: SfxMedia;\n sfx?: SfxMedia;\n duration_seconds?: number;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,cAAN,cAA0B,MAAM;AAAA,EACrC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO,WAAW;AAAA,EACzB;AACF;AAEO,IAAM,WAAN,cAAuB,YAAY;AAAA,EAQxC,YAAY,SAAiB,QAAgB,MAAgB;AAC3D,UAAM,OAAO;AACb,SAAK,SAAS;AACd,SAAK,OAAO;AACZ,UAAM,SAAS;AACf,SAAK,OAAO,OAAO,QAAQ,SAAS,WAAW,OAAO,OAAO;AAC7D,SAAK,SAAS,MAAM,QAAQ,QAAQ,MAAM,IAAI,OAAO,SAAS;AAAA,EAChE;AACF;AAEO,IAAM,sBAAN,cAAkC,SAAS;AAAC;AAE5C,IAAM,uBAAN,cAAmC,SAAS;AAAC;AAE7C,IAAM,kBAAN,cAA8B,SAAS;AAAA,EAC5C,IAAI,SAA6B;AAC/B,UAAM,OAAO,KAAK;AAClB,QAAI,OAAO,MAAM,YAAY,YAAY,KAAK,SAAS;AACrD,aAAO,KAAK;AAAA,IACd;AACA,WAAO,OAAO,MAAM,WAAW,WAAW,KAAK,SAAS;AAAA,EAC1D;AACF;AAEO,IAAM,iBAAN,cAA6B,SAAS;AAAA,EAG3C,YAAY,SAAiB,QAAgB,MAAgB,YAAqB;AAChF,UAAM,SAAS,QAAQ,IAAI;AAC3B,SAAK,aAAa;AAA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AA,IACR;AAAA,EACF;AACF;;;AClHA,eAAsB,SACpB,OACA,UAAmC,WAAW,OAC9C,UAAkB,oBACG;AACrB,QAAM,MAAM,OAAO,UAAU,WAAW,QAAQ,OAAO;AACvD,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,YAAY,sBAAsB;AAAA,EAC9C;AACA,MAAI;AACJ,MAAI;AACF,UAAM,MAAM,QAAQ,KAAK,EAAE,QAAQ,YAAY,QAAQ,OAAO,EAAE,CAAC;AAAA,EACnE,SAAS,KAAK;AACZ,QAAI,qBAAqB,GAAG,GAAG;AAC7B,YAAM,IAAI,oBAAoB,eAAe,GAAG,oBAAoB,OAAO,IAAI;AAAA,IACjF;AACA,UAAM;AAAA,EACR;AACA,MAAI,CAAC,IAAI,IAAI;AACX,UAAM,IAAI,YAAY,yBAAyB,IAAI,MAAM,EAAE;AAAA,EAC7D;AACA,SAAO,IAAI,WAAW,MAAM,IAAI,YAAY,CAAC;AAC/C;;;AC0IO,SAAS,kBAAkB,OAA8C;AAC9E,SAAO,MAAM,SAAS,iBAAkB,MAA0B,gBAAgB;AACpF;AAEO,SAAS,aAAa,OAAyC;AACpE,SAAO,MAAM,SAAS;AACxB;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -94,12 +94,20 @@ interface VideoToMusicParams {
|
|
|
94
94
|
* `false` to opt out. Free, best-effort; only valid on `submit()`. */
|
|
95
95
|
ducking?: boolean;
|
|
96
96
|
}
|
|
97
|
+
interface TrialQuota {
|
|
98
|
+
granted: number;
|
|
99
|
+
used: number;
|
|
100
|
+
remaining: number;
|
|
101
|
+
}
|
|
97
102
|
interface AccountServices {
|
|
98
103
|
available_services: string[];
|
|
99
104
|
rpm_limit: number;
|
|
100
105
|
concurrency_limit: number;
|
|
101
106
|
discount_factor: number | string;
|
|
102
107
|
max_upload_size_mb: number | null;
|
|
108
|
+
/** Free-trial allowance keyed by service. Returned only for self-serve
|
|
109
|
+
* accounts; absent entirely for invoiced accounts. */
|
|
110
|
+
trial?: Record<string, TrialQuota>;
|
|
103
111
|
}
|
|
104
112
|
interface UsageSummary {
|
|
105
113
|
total_requests: number;
|
|
@@ -394,6 +402,14 @@ interface SoniloClientOptions {
|
|
|
394
402
|
fetch?: typeof globalThis.fetch;
|
|
395
403
|
/** Milliseconds before an in-flight request is aborted. Default 600000. */
|
|
396
404
|
timeout?: number;
|
|
405
|
+
/**
|
|
406
|
+
* Identifies a wrapper built on this SDK (the CLI, the video kit) in the
|
|
407
|
+
* `X-Sonilo-Client` header. Leave unset for direct SDK use — without an
|
|
408
|
+
* override a wrapper's traffic is indistinguishable from the SDK's own.
|
|
409
|
+
*/
|
|
410
|
+
clientName?: string;
|
|
411
|
+
/** Version reported alongside `clientName`. Defaults to the SDK's version. */
|
|
412
|
+
clientVersion?: string;
|
|
397
413
|
}
|
|
398
414
|
/** Milliseconds before an in-flight request is aborted, unless overridden. */
|
|
399
415
|
declare const DEFAULT_TIMEOUT_MS = 600000;
|
|
@@ -402,6 +418,8 @@ declare class SoniloClient {
|
|
|
402
418
|
private readonly apiKey;
|
|
403
419
|
private readonly fetchFn;
|
|
404
420
|
private readonly timeout;
|
|
421
|
+
private readonly clientName;
|
|
422
|
+
private readonly clientVersion;
|
|
405
423
|
readonly account: Account;
|
|
406
424
|
readonly tasks: Tasks;
|
|
407
425
|
readonly textToMusic: TextToMusic;
|
|
@@ -484,6 +502,7 @@ declare class RequestTimeoutError extends SoniloError {
|
|
|
484
502
|
* `output_url`. */
|
|
485
503
|
declare function download(media: SfxMedia | string | undefined, fetchFn?: typeof globalThis.fetch, timeout?: number): Promise<Uint8Array>;
|
|
486
504
|
|
|
487
|
-
|
|
505
|
+
/** The SDK's own version. Generated by scripts/sync-versions.mjs — do not edit. */
|
|
506
|
+
declare const VERSION = "0.6.0";
|
|
488
507
|
|
|
489
|
-
export { APIError, type AccountServices, type AudioChunkEvent, AuthenticationError, BadRequestError, type BaseTaskResult, type CompleteEvent, type CostEvent, type CostInfo, DEFAULT_TIMEOUT_MS, type DailyUsage, type ErrorEvent, GenerationError, type MusicMediaEntry, type MusicMuxEntry, type MusicTaskResult, type MusicTitle, PaymentRequiredError, RateLimitError, RequestTimeoutError, type Segment, type SegmentLabel, type SfxAudioFormat, type SfxError, type SfxMedia, type SfxResult, type SfxSegment, type SfxTask, SoniloClient, type SoniloClientOptions, SoniloError, type SoundResult, type StreamEvent, TaskFailedError, TaskTimeoutError, type TextToMusicParams, type TextToSfxParams, type TitleEvent, type Track, type UnknownEvent, type UsageResponse, type UsageSummary, VERSION, type VideoInput, type VideoResult, type VideoToMusicParams, type VideoToSfxParams, type VideoToSoundParams, type VideoToVideoMusicParams, type VideoToVideoSfxParams, type WaitOptions, download, isAudioChunkEvent, isErrorEvent };
|
|
508
|
+
export { APIError, type AccountServices, type AudioChunkEvent, AuthenticationError, BadRequestError, type BaseTaskResult, type CompleteEvent, type CostEvent, type CostInfo, DEFAULT_TIMEOUT_MS, type DailyUsage, type ErrorEvent, GenerationError, type MusicMediaEntry, type MusicMuxEntry, type MusicTaskResult, type MusicTitle, PaymentRequiredError, RateLimitError, RequestTimeoutError, type Segment, type SegmentLabel, type SfxAudioFormat, type SfxError, type SfxMedia, type SfxResult, type SfxSegment, type SfxTask, SoniloClient, type SoniloClientOptions, SoniloError, type SoundResult, type StreamEvent, TaskFailedError, TaskTimeoutError, type TextToMusicParams, type TextToSfxParams, type TitleEvent, type Track, type TrialQuota, type UnknownEvent, type UsageResponse, type UsageSummary, VERSION, type VideoInput, type VideoResult, type VideoToMusicParams, type VideoToSfxParams, type VideoToSoundParams, type VideoToVideoMusicParams, type VideoToVideoSfxParams, type WaitOptions, download, isAudioChunkEvent, isErrorEvent };
|
package/dist/index.d.ts
CHANGED
|
@@ -94,12 +94,20 @@ interface VideoToMusicParams {
|
|
|
94
94
|
* `false` to opt out. Free, best-effort; only valid on `submit()`. */
|
|
95
95
|
ducking?: boolean;
|
|
96
96
|
}
|
|
97
|
+
interface TrialQuota {
|
|
98
|
+
granted: number;
|
|
99
|
+
used: number;
|
|
100
|
+
remaining: number;
|
|
101
|
+
}
|
|
97
102
|
interface AccountServices {
|
|
98
103
|
available_services: string[];
|
|
99
104
|
rpm_limit: number;
|
|
100
105
|
concurrency_limit: number;
|
|
101
106
|
discount_factor: number | string;
|
|
102
107
|
max_upload_size_mb: number | null;
|
|
108
|
+
/** Free-trial allowance keyed by service. Returned only for self-serve
|
|
109
|
+
* accounts; absent entirely for invoiced accounts. */
|
|
110
|
+
trial?: Record<string, TrialQuota>;
|
|
103
111
|
}
|
|
104
112
|
interface UsageSummary {
|
|
105
113
|
total_requests: number;
|
|
@@ -394,6 +402,14 @@ interface SoniloClientOptions {
|
|
|
394
402
|
fetch?: typeof globalThis.fetch;
|
|
395
403
|
/** Milliseconds before an in-flight request is aborted. Default 600000. */
|
|
396
404
|
timeout?: number;
|
|
405
|
+
/**
|
|
406
|
+
* Identifies a wrapper built on this SDK (the CLI, the video kit) in the
|
|
407
|
+
* `X-Sonilo-Client` header. Leave unset for direct SDK use — without an
|
|
408
|
+
* override a wrapper's traffic is indistinguishable from the SDK's own.
|
|
409
|
+
*/
|
|
410
|
+
clientName?: string;
|
|
411
|
+
/** Version reported alongside `clientName`. Defaults to the SDK's version. */
|
|
412
|
+
clientVersion?: string;
|
|
397
413
|
}
|
|
398
414
|
/** Milliseconds before an in-flight request is aborted, unless overridden. */
|
|
399
415
|
declare const DEFAULT_TIMEOUT_MS = 600000;
|
|
@@ -402,6 +418,8 @@ declare class SoniloClient {
|
|
|
402
418
|
private readonly apiKey;
|
|
403
419
|
private readonly fetchFn;
|
|
404
420
|
private readonly timeout;
|
|
421
|
+
private readonly clientName;
|
|
422
|
+
private readonly clientVersion;
|
|
405
423
|
readonly account: Account;
|
|
406
424
|
readonly tasks: Tasks;
|
|
407
425
|
readonly textToMusic: TextToMusic;
|
|
@@ -484,6 +502,7 @@ declare class RequestTimeoutError extends SoniloError {
|
|
|
484
502
|
* `output_url`. */
|
|
485
503
|
declare function download(media: SfxMedia | string | undefined, fetchFn?: typeof globalThis.fetch, timeout?: number): Promise<Uint8Array>;
|
|
486
504
|
|
|
487
|
-
|
|
505
|
+
/** The SDK's own version. Generated by scripts/sync-versions.mjs — do not edit. */
|
|
506
|
+
declare const VERSION = "0.6.0";
|
|
488
507
|
|
|
489
|
-
export { APIError, type AccountServices, type AudioChunkEvent, AuthenticationError, BadRequestError, type BaseTaskResult, type CompleteEvent, type CostEvent, type CostInfo, DEFAULT_TIMEOUT_MS, type DailyUsage, type ErrorEvent, GenerationError, type MusicMediaEntry, type MusicMuxEntry, type MusicTaskResult, type MusicTitle, PaymentRequiredError, RateLimitError, RequestTimeoutError, type Segment, type SegmentLabel, type SfxAudioFormat, type SfxError, type SfxMedia, type SfxResult, type SfxSegment, type SfxTask, SoniloClient, type SoniloClientOptions, SoniloError, type SoundResult, type StreamEvent, TaskFailedError, TaskTimeoutError, type TextToMusicParams, type TextToSfxParams, type TitleEvent, type Track, type UnknownEvent, type UsageResponse, type UsageSummary, VERSION, type VideoInput, type VideoResult, type VideoToMusicParams, type VideoToSfxParams, type VideoToSoundParams, type VideoToVideoMusicParams, type VideoToVideoSfxParams, type WaitOptions, download, isAudioChunkEvent, isErrorEvent };
|
|
508
|
+
export { APIError, type AccountServices, type AudioChunkEvent, AuthenticationError, BadRequestError, type BaseTaskResult, type CompleteEvent, type CostEvent, type CostInfo, DEFAULT_TIMEOUT_MS, type DailyUsage, type ErrorEvent, GenerationError, type MusicMediaEntry, type MusicMuxEntry, type MusicTaskResult, type MusicTitle, PaymentRequiredError, RateLimitError, RequestTimeoutError, type Segment, type SegmentLabel, type SfxAudioFormat, type SfxError, type SfxMedia, type SfxResult, type SfxSegment, type SfxTask, SoniloClient, type SoniloClientOptions, SoniloError, type SoundResult, type StreamEvent, TaskFailedError, TaskTimeoutError, type TextToMusicParams, type TextToSfxParams, type TitleEvent, type Track, type TrialQuota, type UnknownEvent, type UsageResponse, type UsageSummary, VERSION, type VideoInput, type VideoResult, type VideoToMusicParams, type VideoToSfxParams, type VideoToSoundParams, type VideoToVideoMusicParams, type VideoToVideoSfxParams, type WaitOptions, download, isAudioChunkEvent, isErrorEvent };
|
package/dist/index.js
CHANGED
|
@@ -625,10 +625,11 @@ var VideoToVideoSound = class {
|
|
|
625
625
|
};
|
|
626
626
|
|
|
627
627
|
// src/version.ts
|
|
628
|
-
var VERSION = "0.
|
|
628
|
+
var VERSION = "0.6.0";
|
|
629
629
|
|
|
630
630
|
// src/client.ts
|
|
631
631
|
var DEFAULT_BASE_URL = "https://api.sonilo.com";
|
|
632
|
+
var DEFAULT_CLIENT_NAME = "sdk-js";
|
|
632
633
|
var DEFAULT_TIMEOUT_MS = 6e5;
|
|
633
634
|
var SoniloClient = class {
|
|
634
635
|
constructor(options = {}) {
|
|
@@ -643,6 +644,8 @@ var SoniloClient = class {
|
|
|
643
644
|
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
644
645
|
this.fetchFn = (options.fetch ?? globalThis.fetch).bind(globalThis);
|
|
645
646
|
this.timeout = options.timeout ?? DEFAULT_TIMEOUT_MS;
|
|
647
|
+
this.clientName = options.clientName ?? DEFAULT_CLIENT_NAME;
|
|
648
|
+
this.clientVersion = options.clientVersion ?? VERSION;
|
|
646
649
|
this.account = new Account(this);
|
|
647
650
|
this.tasks = new Tasks(this);
|
|
648
651
|
this.textToMusic = new TextToMusic(this);
|
|
@@ -665,8 +668,8 @@ var SoniloClient = class {
|
|
|
665
668
|
async request(path, init = {}, opts = {}) {
|
|
666
669
|
const headers = new Headers(init.headers);
|
|
667
670
|
headers.set("Authorization", `Bearer ${this.apiKey}`);
|
|
668
|
-
headers.set("X-Sonilo-Client",
|
|
669
|
-
headers.set("X-Sonilo-Client-Version",
|
|
671
|
+
headers.set("X-Sonilo-Client", this.clientName);
|
|
672
|
+
headers.set("X-Sonilo-Client-Version", this.clientVersion);
|
|
670
673
|
const timeout = opts.timeout === void 0 ? this.timeout : opts.timeout;
|
|
671
674
|
const ownsSignal = init.signal == null && timeout !== null;
|
|
672
675
|
const signal = init.signal ?? (timeout === null ? void 0 : AbortSignal.timeout(timeout));
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts","../src/resources/account.ts","../src/resources/tasks.ts","../src/streaming.ts","../src/resources/textToMusic.ts","../src/upload.ts","../src/resources/videoToMusic.ts","../src/resources/textToSfx.ts","../src/resources/videoToSfx.ts","../src/resources/videoToVideoMusic.ts","../src/resources/videoToVideoSfx.ts","../src/resources/soundForm.ts","../src/resources/videoToSound.ts","../src/resources/videoToVideoSound.ts","../src/version.ts","../src/client.ts","../src/download.ts","../src/types.ts"],"sourcesContent":["export class SoniloError extends Error {\n constructor(message: string) {\n super(message);\n this.name = new.target.name;\n }\n}\n\nexport class APIError extends SoniloError {\n readonly status: number;\n readonly body: unknown;\n /** The API's typed error code (e.g. \"rate_limit_exceeded\"), distinct from the HTTP status. */\n readonly code?: string;\n /** Per-field validation details, present on a 422. */\n readonly errors?: unknown[];\n\n constructor(message: string, status: number, body?: unknown) {\n super(message);\n this.status = status;\n this.body = body;\n const parsed = body as { code?: unknown; errors?: unknown } | undefined;\n this.code = typeof parsed?.code === \"string\" ? parsed.code : undefined;\n this.errors = Array.isArray(parsed?.errors) ? parsed.errors : undefined;\n }\n}\n\nexport class AuthenticationError extends APIError {}\n\nexport class PaymentRequiredError extends APIError {}\n\nexport class BadRequestError extends APIError {\n get detail(): string | undefined {\n const body = this.body as { message?: unknown; detail?: unknown } | undefined;\n if (typeof body?.message === \"string\" && body.message) {\n return body.message;\n }\n return typeof body?.detail === \"string\" ? body.detail : undefined;\n }\n}\n\nexport class RateLimitError extends APIError {\n readonly retryAfter?: number;\n\n constructor(message: string, status: number, body?: unknown, retryAfter?: number) {\n super(message, status, body);\n this.retryAfter = retryAfter;\n }\n}\n\n/** Raised by generate() when an `error` event arrives mid-stream. */\nexport class GenerationError extends SoniloError {\n readonly code?: string;\n\n constructor(message: string, code?: string) {\n super(message);\n this.code = code;\n }\n}\n\n/** Raised by tasks.wait()/generate() when an SFX task reaches `failed`. */\nexport class TaskFailedError extends SoniloError {\n readonly code?: string;\n readonly taskId: string;\n readonly refunded?: boolean;\n\n constructor(\n message: string,\n opts: { code?: string; taskId: string; refunded?: boolean },\n ) {\n super(message);\n this.code = opts.code;\n this.taskId = opts.taskId;\n this.refunded = opts.refunded;\n }\n}\n\n/** Poll deadline passed. The task may still finish server-side — resume with\n * tasks.wait(taskId) or tasks.get(taskId). */\nexport class TaskTimeoutError extends SoniloError {\n readonly taskId: string;\n\n constructor(message: string, taskId: string) {\n super(message);\n this.taskId = taskId;\n }\n}\n\n/** Raised when a one-shot request or download is aborted by its own timeout\n * signal (as opposed to a caller-supplied AbortSignal, which propagates\n * untouched). */\nexport class RequestTimeoutError extends SoniloError {}\n\n/**\n * True if `err` is the rejection produced when an `AbortSignal.timeout()`\n * we created fires. Used to distinguish \"our\" timeout aborts (which should be\n * rethrown as `RequestTimeoutError`) from a caller-supplied signal's abort\n * (which must propagate untouched).\n */\nexport function isTimeoutSignalError(err: unknown): boolean {\n return err instanceof Error && (err.name === \"TimeoutError\" || err.name === \"AbortError\");\n}\n\nexport async function errorFromResponse(res: Response): Promise<APIError> {\n const text = await res.text().catch(() => \"\");\n let body: unknown = text;\n try {\n body = JSON.parse(text);\n } catch {\n // keep raw text\n }\n const parsed = body as { message?: unknown; detail?: unknown } | undefined;\n const rawMessage = typeof parsed?.message === \"string\" && parsed.message ? parsed.message : undefined;\n const rawDetail = parsed?.detail;\n const isDetailAbsent = rawDetail === undefined || rawDetail === null || rawDetail === \"\";\n let reason: string;\n if (rawMessage !== undefined) {\n reason = rawMessage;\n } else if (isDetailAbsent) {\n reason = res.statusText || \"request failed\";\n } else if (typeof rawDetail === \"string\") {\n reason = rawDetail;\n } else {\n try {\n reason = JSON.stringify(rawDetail);\n } catch {\n reason = res.statusText || \"request failed\";\n }\n }\n const message = `HTTP ${res.status}: ${reason}`;\n\n switch (res.status) {\n case 401:\n return new AuthenticationError(message, res.status, body);\n case 402:\n return new PaymentRequiredError(message, res.status, body);\n case 429: {\n const ra = res.headers.get(\"retry-after\");\n const retryAfter = ra !== null && ra !== \"\" && !Number.isNaN(Number(ra)) ? Number(ra) : undefined;\n return new RateLimitError(message, res.status, body, retryAfter);\n }\n case 400:\n case 413:\n case 422:\n return new BadRequestError(message, res.status, body);\n default:\n return new APIError(message, res.status, body);\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport type { AccountServices, UsageResponse } from \"../types.js\";\n\nexport class Account {\n constructor(private readonly client: SoniloClient) {}\n\n async services(): Promise<AccountServices> {\n const res = await this.client.request(\"/v1/account/services\");\n return (await res.json()) as AccountServices;\n }\n\n async usage(params: { days?: number } = {}): Promise<UsageResponse> {\n const query = params.days !== undefined ? `?days=${params.days}` : \"\";\n const res = await this.client.request(`/v1/account/usage${query}`);\n return (await res.json()) as UsageResponse;\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError, TaskFailedError, TaskTimeoutError } from \"../errors.js\";\nimport type { BaseTaskResult, SfxResult, WaitOptions } from \"../types.js\";\n\nexport const DEFAULT_POLL_INTERVAL_MS = 2000;\nexport const DEFAULT_WAIT_TIMEOUT_MS = 600_000;\n\nconst sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));\n\n/** A negative delay is clamped to 0 by setTimeout, which would turn the poll\n * loop into a busy loop hammering the API until the deadline. */\nfunction validateWaitArgs(pollInterval: number, timeout: number): void {\n if (pollInterval < 0) {\n throw new SoniloError(`pollInterval must be >= 0, got ${pollInterval}`);\n }\n if (timeout < 0) {\n throw new SoniloError(`timeout must be >= 0, got ${timeout}`);\n }\n}\n\nexport class Tasks {\n constructor(private readonly client: SoniloClient) {}\n\n /**\n * Fetch current task state. Never throws on a failed status.\n *\n * Generic over the result shape so callers can request the endpoint-\n * specific type, e.g. `client.tasks.get<MusicTaskResult>(taskId)`.\n * Defaults to `SfxResult` for back-compat.\n */\n async get<T extends BaseTaskResult = SfxResult>(taskId: string): Promise<T> {\n const res = await this.client.request(`/v1/tasks/${encodeURIComponent(taskId)}`);\n return (await res.json()) as T;\n }\n\n /**\n * Poll until the task is terminal; throw on failure or deadline.\n *\n * Generic over the result shape, e.g.\n * `client.tasks.wait<MusicTaskResult>(taskId)`. Defaults to `SfxResult`\n * for back-compat.\n */\n async wait<T extends BaseTaskResult = SfxResult>(\n taskId: string,\n opts: WaitOptions = {},\n ): Promise<T> {\n const pollInterval = opts.pollInterval ?? DEFAULT_POLL_INTERVAL_MS;\n const timeout = opts.timeout ?? DEFAULT_WAIT_TIMEOUT_MS;\n validateWaitArgs(pollInterval, timeout);\n const deadline = performance.now() + timeout;\n for (;;) {\n const result = await this.get<T>(taskId);\n if (result.status === \"succeeded\") return result;\n if (result.status === \"failed\") {\n const message = result.error?.message || \"Generation failed\";\n throw new TaskFailedError(`Task ${taskId} failed: ${message}`, {\n code: result.error?.code,\n taskId,\n refunded: result.refunded,\n });\n }\n const remaining = deadline - performance.now();\n if (remaining <= 0) {\n throw new TaskTimeoutError(\n `Task ${taskId} still processing after ${timeout}ms; ` +\n \"it may finish later — resume with tasks.wait or tasks.get\",\n taskId,\n );\n }\n await sleep(Math.min(pollInterval, remaining));\n }\n }\n}\n","import { GenerationError } from \"./errors.js\";\nimport type { CostInfo, StreamEvent, Track } from \"./types.js\";\n\nexport function decodeBase64(b64: string): Uint8Array {\n const bin = atob(b64);\n const out = new Uint8Array(bin.length);\n for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);\n return out;\n}\n\n/** Returns `null` for a valid-JSON-but-non-object line (e.g. a bare `null`\n * or a number/string), which carries no event `type` and is skipped like any\n * other junk line rather than crashing on a `.type` read off `null`. */\nfunction toEvent(line: string): StreamEvent | null {\n const parsed: unknown = JSON.parse(line);\n if (typeof parsed !== \"object\" || parsed === null) return null;\n const raw = parsed as { type: string; [key: string]: unknown };\n if (raw.type === \"audio_chunk\" && typeof raw.data === \"string\") {\n try {\n return { ...raw, type: \"audio_chunk\", data: decodeBase64(raw.data) };\n } catch {\n // Don't raise here: this must reach collectTrack's malformed-chunk\n // check, which turns undecodable data into a typed GenerationError.\n // Raising in place would let a raw DOMException escape\n // stream()/generate(), breaking the SDK's \"all errors extend\n // SoniloError\" contract.\n }\n }\n return raw as StreamEvent;\n}\n\nexport async function* parseNdjson(\n body: ReadableStream<Uint8Array>,\n): AsyncGenerator<StreamEvent, void, undefined> {\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n buffer += decoder.decode(value, { stream: true });\n let nl: number;\n while ((nl = buffer.indexOf(\"\\n\")) !== -1) {\n const line = buffer.slice(0, nl).trim();\n buffer = buffer.slice(nl + 1);\n if (line) {\n const ev = toEvent(line);\n if (ev !== null) yield ev;\n }\n }\n }\n buffer += decoder.decode();\n const tail = buffer.trim();\n if (tail) {\n const ev = toEvent(tail);\n if (ev !== null) yield ev;\n }\n } finally {\n await reader.cancel().catch(() => {});\n }\n}\n\nexport async function collectTrack(events: AsyncIterable<StreamEvent>): Promise<Track> {\n const chunks: Uint8Array[] = [];\n let title: string | undefined;\n let cost: CostInfo | undefined;\n let sawComplete = false;\n\n for await (const ev of events) {\n if (ev.type === \"audio_chunk\") {\n // A malformed chunk (missing/non-decodable `data`) must not be\n // silently dropped: that would hand back a \"successful\" Track with\n // empty or truncated audio and no indication anything went wrong.\n if (!(ev.data instanceof Uint8Array)) {\n throw new GenerationError(\n \"received a malformed audio_chunk event (missing or non-decodable data)\",\n );\n }\n chunks.push(ev.data);\n } else if (ev.type === \"title\" && typeof ev.title === \"string\") {\n title = ev.title;\n } else if (ev.type === \"cost\") {\n const { type: _type, ...rest } = ev;\n cost = rest as CostInfo;\n } else if (ev.type === \"error\") {\n const message = typeof ev.message === \"string\" && ev.message !== \"\" ? ev.message : \"generation failed\";\n const code = typeof ev.code === \"string\" ? ev.code : undefined;\n throw new GenerationError(message, code);\n } else if (ev.type === \"complete\") {\n sawComplete = true;\n }\n // unknown event types: ignored\n }\n\n if (!sawComplete) {\n throw new GenerationError(\"stream ended before a 'complete' event (truncated response)\");\n }\n\n const total = chunks.reduce((n, c) => n + c.length, 0);\n const audio = new Uint8Array(total);\n let offset = 0;\n for (const c of chunks) {\n audio.set(c, offset);\n offset += c.length;\n }\n return { audio, title, cost };\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError } from \"../errors.js\";\nimport { collectTrack, parseNdjson } from \"../streaming.js\";\nimport type { SfxTask, StreamEvent, TextToMusicParams, Track } from \"../types.js\";\n\nexport class TextToMusic {\n constructor(private readonly client: SoniloClient) {}\n\n /** Stream raw generation events (audio chunks pre-decoded to bytes). */\n async *stream(params: TextToMusicParams): AsyncGenerator<StreamEvent, void, undefined> {\n const form = new FormData();\n form.set(\"prompt\", params.prompt);\n form.set(\"duration\", String(params.duration));\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n // Opt out of the client's absolute request timeout: this holds the\n // response body open and reads NDJSON chunks for as long as generation\n // takes, so an AbortSignal keyed to elapsed time would kill a healthy,\n // still-streaming, long-duration track. Pass `params.signal` yourself to\n // bound or cancel the stream instead — it is forwarded to `fetch` as-is.\n const res = await this.client.request(\n \"/v1/text-to-music\",\n { method: \"POST\", body: form, signal: params.signal },\n { timeout: null },\n );\n if (!res.body) throw new SoniloError(\"Response has no body\");\n yield* parseNdjson(res.body);\n }\n\n /** Generate and buffer the whole track; throws GenerationError on stream errors. */\n generate(params: TextToMusicParams): Promise<Track> {\n return collectTrack(this.stream(params));\n }\n\n /**\n * Submit an async text-to-music task; poll with\n * `client.tasks.wait<MusicTaskResult>(task.task_id)`. Required for\n * `outputFormat: \"wav\"`. `stream()`/`generate()` remain the streaming path.\n */\n async submit(params: TextToMusicParams): Promise<SfxTask> {\n const mode = params.mode ?? \"async\";\n if (mode !== \"async\") {\n throw new SoniloError('submit() requires mode: \"async\"');\n }\n const form = new FormData();\n form.set(\"prompt\", params.prompt);\n form.set(\"duration\", String(params.duration));\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n form.set(\"mode\", mode);\n if (params.outputFormat !== undefined) {\n form.set(\"output_format\", params.outputFormat);\n }\n const res = await this.client.request(\"/v1/text-to-music\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n}\n","import { SoniloError } from \"./errors.js\";\nimport type { VideoInput } from \"./types.js\";\n\nconst DEFAULT_FILENAME = \"video.mp4\";\n\n/**\n * Normalize every accepted video input into a FormData-ready Blob.\n * String inputs are file paths and work only in Node.js; browsers must\n * pass File/Blob/bytes/streams.\n */\nexport async function toUploadBlob(\n video: VideoInput,\n): Promise<{ blob: Blob; filename: string }> {\n if (typeof video === \"string\") {\n const isNode =\n typeof process !== \"undefined\" && Boolean((process as { versions?: { node?: string } }).versions?.node);\n if (!isNode) {\n throw new SoniloError(\n \"File paths are only supported in Node.js; pass a File or Blob in the browser\",\n );\n }\n const fsModule = \"node:fs/promises\";\n const { readFile } = (await import(\n /* webpackIgnore: true */ /* @vite-ignore */ fsModule\n )) as typeof import(\"node:fs/promises\");\n const data = await readFile(video);\n const filename = video.split(/[\\\\/]/).pop() || DEFAULT_FILENAME;\n return { blob: new Blob([data]), filename };\n }\n if (typeof File !== \"undefined\" && video instanceof File) {\n return { blob: video, filename: video.name || DEFAULT_FILENAME };\n }\n if (video instanceof Blob) {\n return { blob: video, filename: DEFAULT_FILENAME };\n }\n if (video instanceof Uint8Array) {\n return { blob: new Blob([video as unknown as BlobPart]), filename: DEFAULT_FILENAME };\n }\n if (video instanceof ArrayBuffer) {\n return { blob: new Blob([video]), filename: DEFAULT_FILENAME };\n }\n if (video instanceof ReadableStream) {\n return { blob: await new Response(video).blob(), filename: DEFAULT_FILENAME };\n }\n throw new SoniloError(\"Unsupported video input type\");\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError } from \"../errors.js\";\nimport { collectTrack, parseNdjson } from \"../streaming.js\";\nimport { toUploadBlob } from \"../upload.js\";\nimport type { SfxTask, StreamEvent, Track, VideoToMusicParams } from \"../types.js\";\n\nexport class VideoToMusic {\n constructor(private readonly client: SoniloClient) {}\n\n async *stream(params: VideoToMusicParams): AsyncGenerator<StreamEvent, void, undefined> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.prompt !== undefined) form.set(\"prompt\", params.prompt);\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n // Opt out of the client's absolute request timeout: this holds the\n // response body open and reads NDJSON chunks for as long as generation\n // takes, so an AbortSignal keyed to elapsed time would kill a healthy,\n // still-streaming request (e.g. a slow video upload or long track). Pass\n // `params.signal` yourself to bound or cancel the stream instead — it is\n // forwarded to `fetch` as-is.\n const res = await this.client.request(\n \"/v1/video-to-music\",\n { method: \"POST\", body: form, signal: params.signal },\n { timeout: null },\n );\n if (!res.body) throw new SoniloError(\"Response has no body\");\n yield* parseNdjson(res.body);\n }\n\n generate(params: VideoToMusicParams): Promise<Track> {\n return collectTrack(this.stream(params));\n }\n\n /**\n * Submit an async video-to-music task; poll its result with\n * `client.tasks.wait<MusicTaskResult>(task.task_id)`. Required for\n * `isolateVocals` — the backend rejects vocal isolation on the plain\n * stream, and it only ever runs in async mode.\n */\n async submit(params: VideoToMusicParams): Promise<SfxTask> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n let mode = params.mode;\n const needsAsync =\n params.isolateVocals ||\n params.preserveSpeech ||\n params.ducking !== undefined ||\n params.outputFormat === \"wav\";\n // submit() always wants an async task ack, never a stream. Default to\n // async; only object if the caller explicitly asked for stream while\n // also requesting an async-only feature.\n if (mode === undefined) mode = \"async\";\n if (needsAsync && mode !== \"async\") {\n throw new SoniloError(\n 'isolateVocals/preserveSpeech/ducking/outputFormat \"wav\" require mode: \"async\"',\n );\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.prompt !== undefined) form.set(\"prompt\", params.prompt);\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n form.set(\"mode\", mode);\n if (params.preserveSpeech !== undefined) {\n form.set(\"preserve_speech\", String(params.preserveSpeech));\n }\n if (params.isolateVocals !== undefined) {\n form.set(\"isolate_vocals\", String(params.isolateVocals));\n }\n if (params.outputFormat !== undefined) {\n form.set(\"output_format\", params.outputFormat);\n }\n if (params.ducking !== undefined) {\n form.set(\"ducking\", String(params.ducking));\n }\n const res = await this.client.request(\"/v1/video-to-music\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport type { SfxResult, SfxTask, TextToSfxParams, WaitOptions } from \"../types.js\";\n\nexport class TextToSfx {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: TextToSfxParams): Promise<SfxTask> {\n const form = new FormData();\n form.set(\"prompt\", params.prompt);\n form.set(\"duration\", String(params.duration));\n if (params.audioFormat !== undefined) form.set(\"audio_format\", params.audioFormat);\n const res = await this.client.request(\"/v1/text-to-sfx\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: TextToSfxParams, opts?: WaitOptions): Promise<SfxResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait(task.task_id, opts);\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError } from \"../errors.js\";\nimport { toUploadBlob } from \"../upload.js\";\nimport type { SfxResult, SfxTask, VideoToSfxParams, WaitOptions } from \"../types.js\";\n\nexport class VideoToSfx {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: VideoToSfxParams): Promise<SfxTask> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.prompt !== undefined) form.set(\"prompt\", params.prompt);\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n if (params.audioFormat !== undefined) form.set(\"audio_format\", params.audioFormat);\n const res = await this.client.request(\"/v1/video-to-sfx\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: VideoToSfxParams, opts?: WaitOptions): Promise<SfxResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait(task.task_id, opts);\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError } from \"../errors.js\";\nimport { toUploadBlob } from \"../upload.js\";\nimport type { SfxTask, VideoResult, VideoToVideoMusicParams, WaitOptions } from \"../types.js\";\n\n/** Generate an original score for a video and get back a re-hosted video with\n * the music muxed in. Async only: `submit()` returns a task ack; poll with\n * `client.tasks.wait<VideoResult>(id)`, or use `generate()` to do both. */\nexport class VideoToVideoMusic {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: VideoToVideoMusicParams): Promise<SfxTask> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.prompt !== undefined) form.set(\"prompt\", params.prompt);\n if (params.preserveSpeech !== undefined) {\n form.set(\"preserve_speech\", String(params.preserveSpeech));\n }\n if (params.isolateVocals !== undefined) {\n form.set(\"isolate_vocals\", String(params.isolateVocals));\n }\n const res = await this.client.request(\"/v1/video-to-video-music\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: VideoToVideoMusicParams, opts?: WaitOptions): Promise<VideoResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait<VideoResult>(task.task_id, opts);\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError } from \"../errors.js\";\nimport { toUploadBlob } from \"../upload.js\";\nimport type { SfxTask, VideoResult, VideoToVideoSfxParams, WaitOptions } from \"../types.js\";\n\n/** Generate sound effects for a video and get back a re-hosted video with the\n * SFX muxed in. Async only. */\nexport class VideoToVideoSfx {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: VideoToVideoSfxParams): Promise<SfxTask> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.prompt !== undefined) form.set(\"prompt\", params.prompt);\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n const res = await this.client.request(\"/v1/video-to-video-sfx\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: VideoToVideoSfxParams, opts?: WaitOptions): Promise<VideoResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait<VideoResult>(task.task_id, opts);\n }\n}\n","import { SoniloError } from \"../errors.js\";\nimport { toUploadBlob } from \"../upload.js\";\nimport type { VideoToSoundParams } from \"../types.js\";\n\n/** Build the multipart body shared by /v1/video-to-sound and\n * /v1/video-to-video-sound — their form fields are identical, so the two\n * resources differ only in the path they POST to.\n *\n * Every optional field is omitted when unset rather than sent with a default:\n * `ducking` in particular is default-ON server-side, so an unset value must\n * not become an explicit \"false\" on the wire. */\nexport async function buildSoundForm(params: VideoToSoundParams): Promise<FormData> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.musicPrompt !== undefined) form.set(\"music_prompt\", params.musicPrompt);\n if (params.sfxPrompt !== undefined) form.set(\"sfx_prompt\", params.sfxPrompt);\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n if (params.preserveSpeech !== undefined) {\n form.set(\"preserve_speech\", String(params.preserveSpeech));\n }\n if (params.ducking !== undefined) form.set(\"ducking\", String(params.ducking));\n return form;\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { buildSoundForm } from \"./soundForm.js\";\nimport type { SfxTask, SoundResult, VideoToSoundParams, WaitOptions } from \"../types.js\";\n\n/** Generate a combined music + sound-effects track for a video and get back\n * the mixed audio. Async only. */\nexport class VideoToSound {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: VideoToSoundParams): Promise<SfxTask> {\n const res = await this.client.request(\"/v1/video-to-sound\", {\n method: \"POST\",\n body: await buildSoundForm(params),\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: VideoToSoundParams, opts?: WaitOptions): Promise<SoundResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait<SoundResult>(task.task_id, opts);\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { buildSoundForm } from \"./soundForm.js\";\nimport type { SfxTask, SoundResult, VideoToSoundParams, WaitOptions } from \"../types.js\";\n\n/** Generate a combined music + sound-effects track for a video and get back a\n * re-hosted video with that track muxed in. Async only. */\nexport class VideoToVideoSound {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: VideoToSoundParams): Promise<SfxTask> {\n const res = await this.client.request(\"/v1/video-to-video-sound\", {\n method: \"POST\",\n body: await buildSoundForm(params),\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: VideoToSoundParams, opts?: WaitOptions): Promise<SoundResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait<SoundResult>(task.task_id, opts);\n }\n}\n","export const VERSION = \"0.4.0\";\n","import { RequestTimeoutError, SoniloError, errorFromResponse, isTimeoutSignalError } from \"./errors.js\";\nimport { Account } from \"./resources/account.js\";\nimport { Tasks } from \"./resources/tasks.js\";\nimport { TextToMusic } from \"./resources/textToMusic.js\";\nimport { VideoToMusic } from \"./resources/videoToMusic.js\";\nimport { TextToSfx } from \"./resources/textToSfx.js\";\nimport { VideoToSfx } from \"./resources/videoToSfx.js\";\nimport { VideoToVideoMusic } from \"./resources/videoToVideoMusic.js\";\nimport { VideoToVideoSfx } from \"./resources/videoToVideoSfx.js\";\nimport { VideoToSound } from \"./resources/videoToSound.js\";\nimport { VideoToVideoSound } from \"./resources/videoToVideoSound.js\";\nimport { VERSION } from \"./version.js\";\n\nexport interface SoniloClientOptions {\n /** Defaults to the SONILO_API_KEY environment variable (Node.js only). */\n apiKey?: string;\n /** Defaults to https://api.sonilo.com */\n baseUrl?: string;\n /** Injection point for tests and custom transports. */\n fetch?: typeof globalThis.fetch;\n /** Milliseconds before an in-flight request is aborted. Default 600000. */\n timeout?: number;\n}\n\nconst DEFAULT_BASE_URL = \"https://api.sonilo.com\";\n\n/** Milliseconds before an in-flight request is aborted, unless overridden. */\nexport const DEFAULT_TIMEOUT_MS = 600_000;\n\nexport class SoniloClient {\n readonly baseUrl: string;\n private readonly apiKey: string;\n private readonly fetchFn: typeof globalThis.fetch;\n private readonly timeout: number;\n readonly account: Account;\n readonly tasks: Tasks;\n readonly textToMusic: TextToMusic;\n readonly videoToMusic: VideoToMusic;\n readonly textToSfx: TextToSfx;\n readonly videoToSfx: VideoToSfx;\n readonly videoToVideoMusic: VideoToVideoMusic;\n readonly videoToVideoSfx: VideoToVideoSfx;\n readonly videoToSound: VideoToSound;\n readonly videoToVideoSound: VideoToVideoSound;\n\n constructor(options: SoniloClientOptions = {}) {\n const envKey =\n typeof process !== \"undefined\" ? process.env?.SONILO_API_KEY : undefined;\n const apiKey = options.apiKey ?? envKey;\n if (!apiKey) {\n throw new SoniloError(\n \"Missing API key: pass { apiKey } or set the SONILO_API_KEY environment variable\",\n );\n }\n this.apiKey = apiKey;\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.fetchFn = (options.fetch ?? globalThis.fetch).bind(globalThis);\n this.timeout = options.timeout ?? DEFAULT_TIMEOUT_MS;\n this.account = new Account(this);\n this.tasks = new Tasks(this);\n this.textToMusic = new TextToMusic(this);\n this.videoToMusic = new VideoToMusic(this);\n this.textToSfx = new TextToSfx(this);\n this.videoToSfx = new VideoToSfx(this);\n this.videoToVideoMusic = new VideoToVideoMusic(this);\n this.videoToVideoSfx = new VideoToVideoSfx(this);\n this.videoToSound = new VideoToSound(this);\n this.videoToVideoSound = new VideoToVideoSound(this);\n }\n\n /**\n * Perform an authenticated request; throws a typed error on non-2xx.\n *\n * `opts.timeout` overrides the client's default timeout for this call;\n * pass `null` to disable the abort-on-timeout behavior entirely (used by\n * the streaming music endpoints — see textToMusic.ts / videoToMusic.ts).\n * A caller-supplied `init.signal` always wins over any timeout signal.\n */\n async request(\n path: string,\n init: RequestInit = {},\n opts: { timeout?: number | null } = {},\n ): Promise<Response> {\n const headers = new Headers(init.headers);\n headers.set(\"Authorization\", `Bearer ${this.apiKey}`);\n headers.set(\"X-Sonilo-Client\", \"sdk-js\");\n headers.set(\"X-Sonilo-Client-Version\", VERSION);\n const timeout = opts.timeout === undefined ? this.timeout : opts.timeout;\n // We only \"own\" the signal (and may later rewrap its abort as a\n // RequestTimeoutError) when the caller didn't supply one and a timeout\n // is actually enabled.\n const ownsSignal = init.signal == null && timeout !== null;\n const signal = init.signal ?? (timeout === null ? undefined : AbortSignal.timeout(timeout));\n try {\n const res = await this.fetchFn(`${this.baseUrl}${path}`, { ...init, headers, signal });\n if (!res.ok) throw await errorFromResponse(res);\n return res;\n } catch (err) {\n if (ownsSignal && isTimeoutSignalError(err)) {\n throw new RequestTimeoutError(`Request to ${path} timed out after ${timeout}ms`);\n }\n throw err;\n }\n }\n}\n","import { DEFAULT_TIMEOUT_MS } from \"./client.js\";\nimport { RequestTimeoutError, SoniloError, isTimeoutSignalError } from \"./errors.js\";\nimport type { SfxMedia } from \"./types.js\";\n\n/** Fetch a result media file. The URL is presigned — no API key is sent.\n *\n * Accepts either a media object (`result.audio`, `result.music`, …) or a bare\n * URL string, which is what the combined video-to-sound endpoints return as\n * `output_url`. */\nexport async function download(\n media: SfxMedia | string | undefined,\n fetchFn: typeof globalThis.fetch = globalThis.fetch,\n timeout: number = DEFAULT_TIMEOUT_MS,\n): Promise<Uint8Array> {\n const url = typeof media === \"string\" ? media : media?.url;\n if (!url) {\n throw new SoniloError(\"No media to download\");\n }\n let res: Response;\n try {\n res = await fetchFn(url, { signal: AbortSignal.timeout(timeout) });\n } catch (err) {\n if (isTimeoutSignalError(err)) {\n throw new RequestTimeoutError(`Download of ${url} timed out after ${timeout}ms`);\n }\n throw err;\n }\n if (!res.ok) {\n throw new SoniloError(`Download failed: HTTP ${res.status}`);\n }\n return new Uint8Array(await res.arrayBuffer());\n}\n","export type SegmentLabel =\n | \"intro\"\n | \"verse\"\n | \"pre-chorus\"\n | \"chorus\"\n | \"bridge\"\n | \"break\"\n | \"silence\"\n | \"outro\"\n | \"none\";\n\nexport interface Segment {\n start: number;\n prompt: string;\n label?: SegmentLabel;\n}\n\n/** Monetary fields are strings, exactly as the backend serializes them. */\nexport interface CostInfo {\n billing_rate_per_sec: string;\n billing_before_discount: string;\n billing_after_discount: string;\n discount_factor: string;\n}\n\nexport interface AudioChunkEvent {\n type: \"audio_chunk\";\n /** Decoded from the wire's base64 by the SDK. */\n data: Uint8Array;\n}\n\nexport interface TitleEvent {\n type: \"title\";\n title: string;\n summary?: string;\n display_tags?: string[];\n [key: string]: unknown;\n}\n\nexport interface CompleteEvent {\n type: \"complete\";\n [key: string]: unknown;\n}\n\nexport interface ErrorEvent {\n type: \"error\";\n code?: string;\n message?: string;\n [key: string]: unknown;\n}\n\nexport interface CostEvent extends CostInfo {\n type: \"cost\";\n}\n\n/** Forward-compatibility: unrecognized event types are passed through. */\nexport interface UnknownEvent {\n type: string;\n [key: string]: unknown;\n}\n\nexport type StreamEvent =\n | AudioChunkEvent\n | TitleEvent\n | CompleteEvent\n | ErrorEvent\n | CostEvent\n | UnknownEvent;\n\nexport interface Track {\n audio: Uint8Array;\n title?: string;\n cost?: CostInfo;\n}\n\nexport interface TextToMusicParams {\n prompt: string;\n duration: number;\n segments?: Segment[];\n /** \"stream\" (default) or \"async\" (required by `submit()` and `output_format: \"wav\"`). */\n mode?: \"stream\" | \"async\";\n /** Container for the async result. `wav` requires `mode: \"async\"`. Defaults to m4a server-side. */\n outputFormat?: \"m4a\" | \"wav\";\n /** Bounds the stream: aborting this cancels the in-flight generation.\n * Passed straight through to `fetch` — it is never rewrapped as\n * RequestTimeoutError, since the client's own absolute timeout does not\n * apply to streaming music generation. */\n signal?: AbortSignal;\n}\n\n/** string = file path (Node.js only). */\nexport type VideoInput =\n | File\n | Blob\n | Uint8Array\n | ArrayBuffer\n | ReadableStream<Uint8Array>\n | string;\n\nexport interface VideoToMusicParams {\n video?: VideoInput;\n videoUrl?: string;\n prompt?: string;\n segments?: Segment[];\n /** Bounds the stream: aborting this cancels the in-flight generation.\n * Passed straight through to `fetch` — it is never rewrapped as\n * RequestTimeoutError, since the client's own absolute timeout does not\n * apply to streaming music generation. Only meaningful for `stream()`/\n * `generate()`; `submit()` ignores it. */\n signal?: AbortSignal;\n /** \"stream\" (the default, used by `stream()`/`generate()`) or \"async\"\n * (required for `submit()`, and for `isolateVocals`). Only consulted by\n * `submit()` — `stream()`/`generate()` always request a stream. */\n mode?: \"stream\" | \"async\";\n /** Split the generated track into a vocals-only stem alongside the mix.\n * Requires `mode: \"async\"`; if `mode` is left unset it defaults to\n * \"async\" automatically. Only usable via `submit()` — the backend\n * rejects it on the plain stream. */\n isolateVocals?: boolean;\n /** Keep the source speech/vocals in the async result. Current name for\n * `isolateVocals`; both are accepted and OR'd server-side. Requires\n * `mode: \"async\"` (auto-selected by `submit()`). */\n preserveSpeech?: boolean;\n /** Container for the async result. `wav` requires async. Defaults to m4a. */\n outputFormat?: \"m4a\" | \"wav\";\n /** Duck the generated music under the source voice at finalize time.\n * Default-ON server-side in async mode: leave unset to keep it on, pass\n * `false` to opt out. Free, best-effort; only valid on `submit()`. */\n ducking?: boolean;\n}\n\nexport interface AccountServices {\n available_services: string[];\n rpm_limit: number;\n concurrency_limit: number;\n discount_factor: number | string;\n max_upload_size_mb: number | null;\n}\n\nexport interface UsageSummary {\n total_requests: number;\n total_duration_seconds: number;\n total_cost: number | string;\n period_start: string;\n period_end: string;\n [key: string]: unknown;\n}\n\nexport interface DailyUsage {\n date: string;\n requests: number;\n duration_seconds: number;\n cost: number | string;\n}\n\nexport interface UsageResponse {\n summary: UsageSummary;\n daily: DailyUsage[];\n}\n\nexport function isAudioChunkEvent(event: StreamEvent): event is AudioChunkEvent {\n return event.type === \"audio_chunk\" && (event as AudioChunkEvent).data instanceof Uint8Array;\n}\n\nexport function isErrorEvent(event: StreamEvent): event is ErrorEvent {\n return event.type === \"error\";\n}\n\n/** SFX segments (unlike music `Segment`) require `end`, must start at 0,\n * and be contiguous; validated server-side. */\nexport interface SfxSegment {\n start: number;\n end: number;\n prompt: string;\n}\n\nexport type SfxAudioFormat = \"wav\" | \"mp3\" | \"aac\" | \"flac\";\n\n/** Submission ack for the async SFX endpoints. */\nexport interface SfxTask {\n task_id: string;\n status: string;\n}\n\n/** A generated file re-hosted on R2 behind a presigned URL. */\nexport interface SfxMedia {\n url: string;\n content_type?: string;\n file_size?: number;\n}\n\nexport interface SfxError {\n code?: string;\n message?: string;\n}\n\n/**\n * Common shape of any polled task (`tasks.get`/`tasks.wait`), regardless of\n * which endpoint created it. `Tasks.get`/`Tasks.wait` are generic over this so\n * each endpoint's result type (e.g. `SfxResult`, `MusicTaskResult`) can add\n * its own `audio`/media fields while sharing the status/error/refund\n * bookkeeping the poller relies on.\n */\nexport interface BaseTaskResult {\n task_id: string;\n type?: string;\n status: \"processing\" | \"succeeded\" | \"failed\" | (string & {});\n /** Only present when the account's task-field whitelist enables cost. */\n cost?: number;\n error?: SfxError;\n refunded?: boolean;\n [key: string]: unknown;\n}\n\n/** State of an SFX task (`tasks.get`) or its final result (`wait`/`generate`). */\nexport interface SfxResult extends BaseTaskResult {\n audio?: SfxMedia;\n /** Kept for backward compatibility; no longer populated — video-to-sfx returns audio only. */\n video?: SfxMedia;\n}\n\nexport interface TextToSfxParams {\n prompt: string;\n duration: number;\n audioFormat?: SfxAudioFormat;\n}\n\nexport interface VideoToSfxParams {\n video?: VideoInput;\n videoUrl?: string;\n prompt?: string;\n segments?: SfxSegment[];\n audioFormat?: SfxAudioFormat;\n}\n\n/** One decoded audio stream of an async video-to-music result. Unlike SFX,\n * `audio` on a music task is always an array — even without `isolateVocals` —\n * since a music generation can carry more than one output stream. */\nexport interface MusicMediaEntry extends SfxMedia {\n stream_index: number;\n sample_rate?: number;\n channels?: number;\n}\n\n/** One muxed audio+video-aligned output, present only when `isolateVocals`\n * is set. */\nexport interface MusicMuxEntry extends SfxMedia {\n stream_index: number;\n}\n\nexport interface MusicTitle {\n title: string;\n summary?: string;\n display_tags?: string[];\n}\n\n/** State of an async video-to-music task (`tasks.get`) or its final result\n * (`tasks.wait<MusicTaskResult>()`). Only reachable via `videoToMusic.submit()`\n * with `mode: \"async\"`. */\nexport interface MusicTaskResult extends BaseTaskResult {\n audio?: MusicMediaEntry[];\n /** Vocals-only stem; present only when `isolateVocals` was requested. */\n vocals?: SfxMedia;\n /** Muxed output per stream; present only when `isolateVocals` was requested. */\n mux?: MusicMuxEntry[];\n /** Music ducked under the source voice; present only when `ducking` ran. */\n ducked?: MusicMediaEntry[];\n title?: MusicTitle;\n duration_seconds?: number;\n}\n\nexport interface WaitOptions {\n /** Milliseconds between polls. Default 2000. */\n pollInterval?: number;\n /** Overall deadline in milliseconds. Default 600000. */\n timeout?: number;\n}\n\n/** Result of an async video-to-video task (`videoToVideoMusic`/`videoToVideoSfx`):\n * a re-hosted video with generated music or SFX muxed in. */\nexport interface VideoResult extends BaseTaskResult {\n video?: SfxMedia;\n duration_seconds?: number;\n}\n\nexport interface VideoToVideoMusicParams {\n video?: VideoInput;\n videoUrl?: string;\n prompt?: string;\n /** Keep the source speech/vocals in the output. Both this and the legacy\n * `isolateVocals` are accepted and OR'd server-side. */\n preserveSpeech?: boolean;\n /** @deprecated Legacy alias for `preserveSpeech`. */\n isolateVocals?: boolean;\n}\n\nexport interface VideoToVideoSfxParams {\n video?: VideoInput;\n videoUrl?: string;\n prompt?: string;\n segments?: SfxSegment[];\n}\n\n/** Params for `videoToSound` and `videoToVideoSound`. Both endpoints take the\n * identical form, so they share one params type. */\nexport interface VideoToSoundParams {\n video?: VideoInput;\n videoUrl?: string;\n /** Style hint for the generated music bed. */\n musicPrompt?: string;\n /** Description of the sound effects layered over the music. */\n sfxPrompt?: string;\n /** Per-segment SFX descriptions; must start at 0 and be contiguous. */\n segments?: SfxSegment[];\n /** Keep the source speech in the result. */\n preserveSpeech?: boolean;\n /** Duck the generated music under the source speech. Default-ON\n * server-side: leave unset to keep it on, pass `false` to opt out. */\n ducking?: boolean;\n}\n\n/** Result of a `videoToSound` / `videoToVideoSound` task (`tasks.get`) or its\n * final state (`generate`).\n *\n * The combined music+SFX result is `output_url` — a bare presigned URL rather\n * than a media object, since these endpoints render one artifact whose kind is\n * announced by `output_type` (\"audio\" for video-to-sound, \"video\" for\n * video-to-video-sound). `music`, `music_processed` and `sfx` are the\n * individual stems; pass any of them, or `output_url` itself, to `download()`. */\nexport interface SoundResult extends BaseTaskResult {\n output_url?: string;\n output_type?: \"audio\" | \"video\";\n output_bytes?: number;\n music?: SfxMedia;\n /** Present only when `preserveSpeech`/`ducking` altered the music bed. */\n music_processed?: SfxMedia;\n sfx?: SfxMedia;\n duration_seconds?: number;\n}\n"],"mappings":";AAAO,IAAM,cAAN,cAA0B,MAAM;AAAA,EACrC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO,WAAW;AAAA,EACzB;AACF;AAEO,IAAM,WAAN,cAAuB,YAAY;AAAA,EAQxC,YAAY,SAAiB,QAAgB,MAAgB;AAC3D,UAAM,OAAO;AACb,SAAK,SAAS;AACd,SAAK,OAAO;AACZ,UAAM,SAAS;AACf,SAAK,OAAO,OAAO,QAAQ,SAAS,WAAW,OAAO,OAAO;AAC7D,SAAK,SAAS,MAAM,QAAQ,QAAQ,MAAM,IAAI,OAAO,SAAS;AAAA,EAChE;AACF;AAEO,IAAM,sBAAN,cAAkC,SAAS;AAAC;AAE5C,IAAM,uBAAN,cAAmC,SAAS;AAAC;AAE7C,IAAM,kBAAN,cAA8B,SAAS;AAAA,EAC5C,IAAI,SAA6B;AAC/B,UAAM,OAAO,KAAK;AAClB,QAAI,OAAO,MAAM,YAAY,YAAY,KAAK,SAAS;AACrD,aAAO,KAAK;AAAA,IACd;AACA,WAAO,OAAO,MAAM,WAAW,WAAW,KAAK,SAAS;AAAA,EAC1D;AACF;AAEO,IAAM,iBAAN,cAA6B,SAAS;AAAA,EAG3C,YAAY,SAAiB,QAAgB,MAAgB,YAAqB;AAChF,UAAM,SAAS,QAAQ,IAAI;AAC3B,SAAK,aAAa;AAAA,EACpB;AACF;AAGO,IAAM,kBAAN,cAA8B,YAAY;AAAA,EAG/C,YAAY,SAAiB,MAAe;AAC1C,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAGO,IAAM,kBAAN,cAA8B,YAAY;AAAA,EAK/C,YACE,SACA,MACA;AACA,UAAM,OAAO;AACb,SAAK,OAAO,KAAK;AACjB,SAAK,SAAS,KAAK;AACnB,SAAK,WAAW,KAAK;AAAA,EACvB;AACF;AA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BAAoB,OAAO,IAAI;AAAA,IACjF;AACA,UAAM;AAAA,EACR;AACA,MAAI,CAAC,IAAI,IAAI;AACX,UAAM,IAAI,YAAY,yBAAyB,IAAI,MAAM,EAAE;AAAA,EAC7D;AACA,SAAO,IAAI,WAAW,MAAM,IAAI,YAAY,CAAC;AAC/C;;;ACiIO,SAAS,kBAAkB,OAA8C;AAC9E,SAAO,MAAM,SAAS,iBAAkB,MAA0B,gBAAgB;AACpF;AAEO,SAAS,aAAa,OAAyC;AACpE,SAAO,MAAM,SAAS;AACxB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/resources/account.ts","../src/resources/tasks.ts","../src/streaming.ts","../src/resources/textToMusic.ts","../src/upload.ts","../src/resources/videoToMusic.ts","../src/resources/textToSfx.ts","../src/resources/videoToSfx.ts","../src/resources/videoToVideoMusic.ts","../src/resources/videoToVideoSfx.ts","../src/resources/soundForm.ts","../src/resources/videoToSound.ts","../src/resources/videoToVideoSound.ts","../src/version.ts","../src/client.ts","../src/download.ts","../src/types.ts"],"sourcesContent":["export class SoniloError extends Error {\n constructor(message: string) {\n super(message);\n this.name = new.target.name;\n }\n}\n\nexport class APIError extends SoniloError {\n readonly status: number;\n readonly body: unknown;\n /** The API's typed error code (e.g. \"rate_limit_exceeded\"), distinct from the HTTP status. */\n readonly code?: string;\n /** Per-field validation details, present on a 422. */\n readonly errors?: unknown[];\n\n constructor(message: string, status: number, body?: unknown) {\n super(message);\n this.status = status;\n this.body = body;\n const parsed = body as { code?: unknown; errors?: unknown } | undefined;\n this.code = typeof parsed?.code === \"string\" ? parsed.code : undefined;\n this.errors = Array.isArray(parsed?.errors) ? parsed.errors : undefined;\n }\n}\n\nexport class AuthenticationError extends APIError {}\n\nexport class PaymentRequiredError extends APIError {}\n\nexport class BadRequestError extends APIError {\n get detail(): string | undefined {\n const body = this.body as { message?: unknown; detail?: unknown } | undefined;\n if (typeof body?.message === \"string\" && body.message) {\n return body.message;\n }\n return typeof body?.detail === \"string\" ? body.detail : undefined;\n }\n}\n\nexport class RateLimitError extends APIError {\n readonly retryAfter?: number;\n\n constructor(message: string, status: number, body?: unknown, retryAfter?: number) {\n super(message, status, body);\n this.retryAfter = retryAfter;\n }\n}\n\n/** Raised by generate() when an `error` event arrives mid-stream. */\nexport class GenerationError extends SoniloError {\n readonly code?: string;\n\n constructor(message: string, code?: string) {\n super(message);\n this.code = code;\n }\n}\n\n/** Raised by tasks.wait()/generate() when an SFX task reaches `failed`. */\nexport class TaskFailedError extends SoniloError {\n readonly code?: string;\n readonly taskId: string;\n readonly refunded?: boolean;\n\n constructor(\n message: string,\n opts: { code?: string; taskId: string; refunded?: boolean },\n ) {\n super(message);\n this.code = opts.code;\n this.taskId = opts.taskId;\n this.refunded = opts.refunded;\n }\n}\n\n/** Poll deadline passed. The task may still finish server-side — resume with\n * tasks.wait(taskId) or tasks.get(taskId). */\nexport class TaskTimeoutError extends SoniloError {\n readonly taskId: string;\n\n constructor(message: string, taskId: string) {\n super(message);\n this.taskId = taskId;\n }\n}\n\n/** Raised when a one-shot request or download is aborted by its own timeout\n * signal (as opposed to a caller-supplied AbortSignal, which propagates\n * untouched). */\nexport class RequestTimeoutError extends SoniloError {}\n\n/**\n * True if `err` is the rejection produced when an `AbortSignal.timeout()`\n * we created fires. Used to distinguish \"our\" timeout aborts (which should be\n * rethrown as `RequestTimeoutError`) from a caller-supplied signal's abort\n * (which must propagate untouched).\n */\nexport function isTimeoutSignalError(err: unknown): boolean {\n return err instanceof Error && (err.name === \"TimeoutError\" || err.name === \"AbortError\");\n}\n\nexport async function errorFromResponse(res: Response): Promise<APIError> {\n const text = await res.text().catch(() => \"\");\n let body: unknown = text;\n try {\n body = JSON.parse(text);\n } catch {\n // keep raw text\n }\n const parsed = body as { message?: unknown; detail?: unknown } | undefined;\n const rawMessage = typeof parsed?.message === \"string\" && parsed.message ? parsed.message : undefined;\n const rawDetail = parsed?.detail;\n const isDetailAbsent = rawDetail === undefined || rawDetail === null || rawDetail === \"\";\n let reason: string;\n if (rawMessage !== undefined) {\n reason = rawMessage;\n } else if (isDetailAbsent) {\n reason = res.statusText || \"request failed\";\n } else if (typeof rawDetail === \"string\") {\n reason = rawDetail;\n } else {\n try {\n reason = JSON.stringify(rawDetail);\n } catch {\n reason = res.statusText || \"request failed\";\n }\n }\n const message = `HTTP ${res.status}: ${reason}`;\n\n switch (res.status) {\n case 401:\n return new AuthenticationError(message, res.status, body);\n case 402:\n return new PaymentRequiredError(message, res.status, body);\n case 429: {\n const ra = res.headers.get(\"retry-after\");\n const retryAfter = ra !== null && ra !== \"\" && !Number.isNaN(Number(ra)) ? Number(ra) : undefined;\n return new RateLimitError(message, res.status, body, retryAfter);\n }\n case 400:\n case 413:\n case 422:\n return new BadRequestError(message, res.status, body);\n default:\n return new APIError(message, res.status, body);\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport type { AccountServices, UsageResponse } from \"../types.js\";\n\nexport class Account {\n constructor(private readonly client: SoniloClient) {}\n\n async services(): Promise<AccountServices> {\n const res = await this.client.request(\"/v1/account/services\");\n return (await res.json()) as AccountServices;\n }\n\n async usage(params: { days?: number } = {}): Promise<UsageResponse> {\n const query = params.days !== undefined ? `?days=${params.days}` : \"\";\n const res = await this.client.request(`/v1/account/usage${query}`);\n return (await res.json()) as UsageResponse;\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError, TaskFailedError, TaskTimeoutError } from \"../errors.js\";\nimport type { BaseTaskResult, SfxResult, WaitOptions } from \"../types.js\";\n\nexport const DEFAULT_POLL_INTERVAL_MS = 2000;\nexport const DEFAULT_WAIT_TIMEOUT_MS = 600_000;\n\nconst sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));\n\n/** A negative delay is clamped to 0 by setTimeout, which would turn the poll\n * loop into a busy loop hammering the API until the deadline. */\nfunction validateWaitArgs(pollInterval: number, timeout: number): void {\n if (pollInterval < 0) {\n throw new SoniloError(`pollInterval must be >= 0, got ${pollInterval}`);\n }\n if (timeout < 0) {\n throw new SoniloError(`timeout must be >= 0, got ${timeout}`);\n }\n}\n\nexport class Tasks {\n constructor(private readonly client: SoniloClient) {}\n\n /**\n * Fetch current task state. Never throws on a failed status.\n *\n * Generic over the result shape so callers can request the endpoint-\n * specific type, e.g. `client.tasks.get<MusicTaskResult>(taskId)`.\n * Defaults to `SfxResult` for back-compat.\n */\n async get<T extends BaseTaskResult = SfxResult>(taskId: string): Promise<T> {\n const res = await this.client.request(`/v1/tasks/${encodeURIComponent(taskId)}`);\n return (await res.json()) as T;\n }\n\n /**\n * Poll until the task is terminal; throw on failure or deadline.\n *\n * Generic over the result shape, e.g.\n * `client.tasks.wait<MusicTaskResult>(taskId)`. Defaults to `SfxResult`\n * for back-compat.\n */\n async wait<T extends BaseTaskResult = SfxResult>(\n taskId: string,\n opts: WaitOptions = {},\n ): Promise<T> {\n const pollInterval = opts.pollInterval ?? DEFAULT_POLL_INTERVAL_MS;\n const timeout = opts.timeout ?? DEFAULT_WAIT_TIMEOUT_MS;\n validateWaitArgs(pollInterval, timeout);\n const deadline = performance.now() + timeout;\n for (;;) {\n const result = await this.get<T>(taskId);\n if (result.status === \"succeeded\") return result;\n if (result.status === \"failed\") {\n const message = result.error?.message || \"Generation failed\";\n throw new TaskFailedError(`Task ${taskId} failed: ${message}`, {\n code: result.error?.code,\n taskId,\n refunded: result.refunded,\n });\n }\n const remaining = deadline - performance.now();\n if (remaining <= 0) {\n throw new TaskTimeoutError(\n `Task ${taskId} still processing after ${timeout}ms; ` +\n \"it may finish later — resume with tasks.wait or tasks.get\",\n taskId,\n );\n }\n await sleep(Math.min(pollInterval, remaining));\n }\n }\n}\n","import { GenerationError } from \"./errors.js\";\nimport type { CostInfo, StreamEvent, Track } from \"./types.js\";\n\nexport function decodeBase64(b64: string): Uint8Array {\n const bin = atob(b64);\n const out = new Uint8Array(bin.length);\n for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);\n return out;\n}\n\n/** Returns `null` for a valid-JSON-but-non-object line (e.g. a bare `null`\n * or a number/string), which carries no event `type` and is skipped like any\n * other junk line rather than crashing on a `.type` read off `null`. */\nfunction toEvent(line: string): StreamEvent | null {\n const parsed: unknown = JSON.parse(line);\n if (typeof parsed !== \"object\" || parsed === null) return null;\n const raw = parsed as { type: string; [key: string]: unknown };\n if (raw.type === \"audio_chunk\" && typeof raw.data === \"string\") {\n try {\n return { ...raw, type: \"audio_chunk\", data: decodeBase64(raw.data) };\n } catch {\n // Don't raise here: this must reach collectTrack's malformed-chunk\n // check, which turns undecodable data into a typed GenerationError.\n // Raising in place would let a raw DOMException escape\n // stream()/generate(), breaking the SDK's \"all errors extend\n // SoniloError\" contract.\n }\n }\n return raw as StreamEvent;\n}\n\nexport async function* parseNdjson(\n body: ReadableStream<Uint8Array>,\n): AsyncGenerator<StreamEvent, void, undefined> {\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n buffer += decoder.decode(value, { stream: true });\n let nl: number;\n while ((nl = buffer.indexOf(\"\\n\")) !== -1) {\n const line = buffer.slice(0, nl).trim();\n buffer = buffer.slice(nl + 1);\n if (line) {\n const ev = toEvent(line);\n if (ev !== null) yield ev;\n }\n }\n }\n buffer += decoder.decode();\n const tail = buffer.trim();\n if (tail) {\n const ev = toEvent(tail);\n if (ev !== null) yield ev;\n }\n } finally {\n await reader.cancel().catch(() => {});\n }\n}\n\nexport async function collectTrack(events: AsyncIterable<StreamEvent>): Promise<Track> {\n const chunks: Uint8Array[] = [];\n let title: string | undefined;\n let cost: CostInfo | undefined;\n let sawComplete = false;\n\n for await (const ev of events) {\n if (ev.type === \"audio_chunk\") {\n // A malformed chunk (missing/non-decodable `data`) must not be\n // silently dropped: that would hand back a \"successful\" Track with\n // empty or truncated audio and no indication anything went wrong.\n if (!(ev.data instanceof Uint8Array)) {\n throw new GenerationError(\n \"received a malformed audio_chunk event (missing or non-decodable data)\",\n );\n }\n chunks.push(ev.data);\n } else if (ev.type === \"title\" && typeof ev.title === \"string\") {\n title = ev.title;\n } else if (ev.type === \"cost\") {\n const { type: _type, ...rest } = ev;\n cost = rest as CostInfo;\n } else if (ev.type === \"error\") {\n const message = typeof ev.message === \"string\" && ev.message !== \"\" ? ev.message : \"generation failed\";\n const code = typeof ev.code === \"string\" ? ev.code : undefined;\n throw new GenerationError(message, code);\n } else if (ev.type === \"complete\") {\n sawComplete = true;\n }\n // unknown event types: ignored\n }\n\n if (!sawComplete) {\n throw new GenerationError(\"stream ended before a 'complete' event (truncated response)\");\n }\n\n const total = chunks.reduce((n, c) => n + c.length, 0);\n const audio = new Uint8Array(total);\n let offset = 0;\n for (const c of chunks) {\n audio.set(c, offset);\n offset += c.length;\n }\n return { audio, title, cost };\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError } from \"../errors.js\";\nimport { collectTrack, parseNdjson } from \"../streaming.js\";\nimport type { SfxTask, StreamEvent, TextToMusicParams, Track } from \"../types.js\";\n\nexport class TextToMusic {\n constructor(private readonly client: SoniloClient) {}\n\n /** Stream raw generation events (audio chunks pre-decoded to bytes). */\n async *stream(params: TextToMusicParams): AsyncGenerator<StreamEvent, void, undefined> {\n const form = new FormData();\n form.set(\"prompt\", params.prompt);\n form.set(\"duration\", String(params.duration));\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n // Opt out of the client's absolute request timeout: this holds the\n // response body open and reads NDJSON chunks for as long as generation\n // takes, so an AbortSignal keyed to elapsed time would kill a healthy,\n // still-streaming, long-duration track. Pass `params.signal` yourself to\n // bound or cancel the stream instead — it is forwarded to `fetch` as-is.\n const res = await this.client.request(\n \"/v1/text-to-music\",\n { method: \"POST\", body: form, signal: params.signal },\n { timeout: null },\n );\n if (!res.body) throw new SoniloError(\"Response has no body\");\n yield* parseNdjson(res.body);\n }\n\n /** Generate and buffer the whole track; throws GenerationError on stream errors. */\n generate(params: TextToMusicParams): Promise<Track> {\n return collectTrack(this.stream(params));\n }\n\n /**\n * Submit an async text-to-music task; poll with\n * `client.tasks.wait<MusicTaskResult>(task.task_id)`. Required for\n * `outputFormat: \"wav\"`. `stream()`/`generate()` remain the streaming path.\n */\n async submit(params: TextToMusicParams): Promise<SfxTask> {\n const mode = params.mode ?? \"async\";\n if (mode !== \"async\") {\n throw new SoniloError('submit() requires mode: \"async\"');\n }\n const form = new FormData();\n form.set(\"prompt\", params.prompt);\n form.set(\"duration\", String(params.duration));\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n form.set(\"mode\", mode);\n if (params.outputFormat !== undefined) {\n form.set(\"output_format\", params.outputFormat);\n }\n const res = await this.client.request(\"/v1/text-to-music\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n}\n","import { SoniloError } from \"./errors.js\";\nimport type { VideoInput } from \"./types.js\";\n\nconst DEFAULT_FILENAME = \"video.mp4\";\n\n/**\n * Normalize every accepted video input into a FormData-ready Blob.\n * String inputs are file paths and work only in Node.js; browsers must\n * pass File/Blob/bytes/streams.\n */\nexport async function toUploadBlob(\n video: VideoInput,\n): Promise<{ blob: Blob; filename: string }> {\n if (typeof video === \"string\") {\n const isNode =\n typeof process !== \"undefined\" && Boolean((process as { versions?: { node?: string } }).versions?.node);\n if (!isNode) {\n throw new SoniloError(\n \"File paths are only supported in Node.js; pass a File or Blob in the browser\",\n );\n }\n const fsModule = \"node:fs/promises\";\n const { readFile } = (await import(\n /* webpackIgnore: true */ /* @vite-ignore */ fsModule\n )) as typeof import(\"node:fs/promises\");\n const data = await readFile(video);\n const filename = video.split(/[\\\\/]/).pop() || DEFAULT_FILENAME;\n return { blob: new Blob([data]), filename };\n }\n if (typeof File !== \"undefined\" && video instanceof File) {\n return { blob: video, filename: video.name || DEFAULT_FILENAME };\n }\n if (video instanceof Blob) {\n return { blob: video, filename: DEFAULT_FILENAME };\n }\n if (video instanceof Uint8Array) {\n return { blob: new Blob([video as unknown as BlobPart]), filename: DEFAULT_FILENAME };\n }\n if (video instanceof ArrayBuffer) {\n return { blob: new Blob([video]), filename: DEFAULT_FILENAME };\n }\n if (video instanceof ReadableStream) {\n return { blob: await new Response(video).blob(), filename: DEFAULT_FILENAME };\n }\n throw new SoniloError(\"Unsupported video input type\");\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError } from \"../errors.js\";\nimport { collectTrack, parseNdjson } from \"../streaming.js\";\nimport { toUploadBlob } from \"../upload.js\";\nimport type { SfxTask, StreamEvent, Track, VideoToMusicParams } from \"../types.js\";\n\nexport class VideoToMusic {\n constructor(private readonly client: SoniloClient) {}\n\n async *stream(params: VideoToMusicParams): AsyncGenerator<StreamEvent, void, undefined> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.prompt !== undefined) form.set(\"prompt\", params.prompt);\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n // Opt out of the client's absolute request timeout: this holds the\n // response body open and reads NDJSON chunks for as long as generation\n // takes, so an AbortSignal keyed to elapsed time would kill a healthy,\n // still-streaming request (e.g. a slow video upload or long track). Pass\n // `params.signal` yourself to bound or cancel the stream instead — it is\n // forwarded to `fetch` as-is.\n const res = await this.client.request(\n \"/v1/video-to-music\",\n { method: \"POST\", body: form, signal: params.signal },\n { timeout: null },\n );\n if (!res.body) throw new SoniloError(\"Response has no body\");\n yield* parseNdjson(res.body);\n }\n\n generate(params: VideoToMusicParams): Promise<Track> {\n return collectTrack(this.stream(params));\n }\n\n /**\n * Submit an async video-to-music task; poll its result with\n * `client.tasks.wait<MusicTaskResult>(task.task_id)`. Required for\n * `isolateVocals` — the backend rejects vocal isolation on the plain\n * stream, and it only ever runs in async mode.\n */\n async submit(params: VideoToMusicParams): Promise<SfxTask> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n let mode = params.mode;\n const needsAsync =\n params.isolateVocals ||\n params.preserveSpeech ||\n params.ducking !== undefined ||\n params.outputFormat === \"wav\";\n // submit() always wants an async task ack, never a stream. Default to\n // async; only object if the caller explicitly asked for stream while\n // also requesting an async-only feature.\n if (mode === undefined) mode = \"async\";\n if (needsAsync && mode !== \"async\") {\n throw new SoniloError(\n 'isolateVocals/preserveSpeech/ducking/outputFormat \"wav\" require mode: \"async\"',\n );\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.prompt !== undefined) form.set(\"prompt\", params.prompt);\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n form.set(\"mode\", mode);\n if (params.preserveSpeech !== undefined) {\n form.set(\"preserve_speech\", String(params.preserveSpeech));\n }\n if (params.isolateVocals !== undefined) {\n form.set(\"isolate_vocals\", String(params.isolateVocals));\n }\n if (params.outputFormat !== undefined) {\n form.set(\"output_format\", params.outputFormat);\n }\n if (params.ducking !== undefined) {\n form.set(\"ducking\", String(params.ducking));\n }\n const res = await this.client.request(\"/v1/video-to-music\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport type { SfxResult, SfxTask, TextToSfxParams, WaitOptions } from \"../types.js\";\n\nexport class TextToSfx {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: TextToSfxParams): Promise<SfxTask> {\n const form = new FormData();\n form.set(\"prompt\", params.prompt);\n form.set(\"duration\", String(params.duration));\n if (params.audioFormat !== undefined) form.set(\"audio_format\", params.audioFormat);\n const res = await this.client.request(\"/v1/text-to-sfx\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: TextToSfxParams, opts?: WaitOptions): Promise<SfxResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait(task.task_id, opts);\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError } from \"../errors.js\";\nimport { toUploadBlob } from \"../upload.js\";\nimport type { SfxResult, SfxTask, VideoToSfxParams, WaitOptions } from \"../types.js\";\n\nexport class VideoToSfx {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: VideoToSfxParams): Promise<SfxTask> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.prompt !== undefined) form.set(\"prompt\", params.prompt);\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n if (params.audioFormat !== undefined) form.set(\"audio_format\", params.audioFormat);\n const res = await this.client.request(\"/v1/video-to-sfx\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: VideoToSfxParams, opts?: WaitOptions): Promise<SfxResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait(task.task_id, opts);\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError } from \"../errors.js\";\nimport { toUploadBlob } from \"../upload.js\";\nimport type { SfxTask, VideoResult, VideoToVideoMusicParams, WaitOptions } from \"../types.js\";\n\n/** Generate an original score for a video and get back a re-hosted video with\n * the music muxed in. Async only: `submit()` returns a task ack; poll with\n * `client.tasks.wait<VideoResult>(id)`, or use `generate()` to do both. */\nexport class VideoToVideoMusic {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: VideoToVideoMusicParams): Promise<SfxTask> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.prompt !== undefined) form.set(\"prompt\", params.prompt);\n if (params.preserveSpeech !== undefined) {\n form.set(\"preserve_speech\", String(params.preserveSpeech));\n }\n if (params.isolateVocals !== undefined) {\n form.set(\"isolate_vocals\", String(params.isolateVocals));\n }\n const res = await this.client.request(\"/v1/video-to-video-music\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: VideoToVideoMusicParams, opts?: WaitOptions): Promise<VideoResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait<VideoResult>(task.task_id, opts);\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { SoniloError } from \"../errors.js\";\nimport { toUploadBlob } from \"../upload.js\";\nimport type { SfxTask, VideoResult, VideoToVideoSfxParams, WaitOptions } from \"../types.js\";\n\n/** Generate sound effects for a video and get back a re-hosted video with the\n * SFX muxed in. Async only. */\nexport class VideoToVideoSfx {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: VideoToVideoSfxParams): Promise<SfxTask> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.prompt !== undefined) form.set(\"prompt\", params.prompt);\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n const res = await this.client.request(\"/v1/video-to-video-sfx\", {\n method: \"POST\",\n body: form,\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: VideoToVideoSfxParams, opts?: WaitOptions): Promise<VideoResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait<VideoResult>(task.task_id, opts);\n }\n}\n","import { SoniloError } from \"../errors.js\";\nimport { toUploadBlob } from \"../upload.js\";\nimport type { VideoToSoundParams } from \"../types.js\";\n\n/** Build the multipart body shared by /v1/video-to-sound and\n * /v1/video-to-video-sound — their form fields are identical, so the two\n * resources differ only in the path they POST to.\n *\n * Every optional field is omitted when unset rather than sent with a default:\n * `ducking` in particular is default-ON server-side, so an unset value must\n * not become an explicit \"false\" on the wire. */\nexport async function buildSoundForm(params: VideoToSoundParams): Promise<FormData> {\n if ((params.video === undefined) === (params.videoUrl === undefined)) {\n throw new SoniloError(\"Provide exactly one of video or videoUrl\");\n }\n const form = new FormData();\n if (params.video !== undefined) {\n const { blob, filename } = await toUploadBlob(params.video);\n form.set(\"video\", blob, filename);\n } else {\n form.set(\"video_url\", params.videoUrl as string);\n }\n if (params.musicPrompt !== undefined) form.set(\"music_prompt\", params.musicPrompt);\n if (params.sfxPrompt !== undefined) form.set(\"sfx_prompt\", params.sfxPrompt);\n if (params.segments !== undefined) {\n form.set(\"segments\", JSON.stringify(params.segments));\n }\n if (params.preserveSpeech !== undefined) {\n form.set(\"preserve_speech\", String(params.preserveSpeech));\n }\n if (params.ducking !== undefined) form.set(\"ducking\", String(params.ducking));\n return form;\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { buildSoundForm } from \"./soundForm.js\";\nimport type { SfxTask, SoundResult, VideoToSoundParams, WaitOptions } from \"../types.js\";\n\n/** Generate a combined music + sound-effects track for a video and get back\n * the mixed audio. Async only. */\nexport class VideoToSound {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: VideoToSoundParams): Promise<SfxTask> {\n const res = await this.client.request(\"/v1/video-to-sound\", {\n method: \"POST\",\n body: await buildSoundForm(params),\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: VideoToSoundParams, opts?: WaitOptions): Promise<SoundResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait<SoundResult>(task.task_id, opts);\n }\n}\n","import type { SoniloClient } from \"../client.js\";\nimport { buildSoundForm } from \"./soundForm.js\";\nimport type { SfxTask, SoundResult, VideoToSoundParams, WaitOptions } from \"../types.js\";\n\n/** Generate a combined music + sound-effects track for a video and get back a\n * re-hosted video with that track muxed in. Async only. */\nexport class VideoToVideoSound {\n constructor(private readonly client: SoniloClient) {}\n\n async submit(params: VideoToSoundParams): Promise<SfxTask> {\n const res = await this.client.request(\"/v1/video-to-video-sound\", {\n method: \"POST\",\n body: await buildSoundForm(params),\n });\n return (await res.json()) as SfxTask;\n }\n\n async generate(params: VideoToSoundParams, opts?: WaitOptions): Promise<SoundResult> {\n const task = await this.submit(params);\n return this.client.tasks.wait<SoundResult>(task.task_id, opts);\n }\n}\n","/** The SDK's own version. Generated by scripts/sync-versions.mjs — do not edit. */\nexport const VERSION = \"0.6.0\";\n","import { RequestTimeoutError, SoniloError, errorFromResponse, isTimeoutSignalError } from \"./errors.js\";\nimport { Account } from \"./resources/account.js\";\nimport { Tasks } from \"./resources/tasks.js\";\nimport { TextToMusic } from \"./resources/textToMusic.js\";\nimport { VideoToMusic } from \"./resources/videoToMusic.js\";\nimport { TextToSfx } from \"./resources/textToSfx.js\";\nimport { VideoToSfx } from \"./resources/videoToSfx.js\";\nimport { VideoToVideoMusic } from \"./resources/videoToVideoMusic.js\";\nimport { VideoToVideoSfx } from \"./resources/videoToVideoSfx.js\";\nimport { VideoToSound } from \"./resources/videoToSound.js\";\nimport { VideoToVideoSound } from \"./resources/videoToVideoSound.js\";\nimport { VERSION } from \"./version.js\";\n\nexport interface SoniloClientOptions {\n /** Defaults to the SONILO_API_KEY environment variable (Node.js only). */\n apiKey?: string;\n /** Defaults to https://api.sonilo.com */\n baseUrl?: string;\n /** Injection point for tests and custom transports. */\n fetch?: typeof globalThis.fetch;\n /** Milliseconds before an in-flight request is aborted. Default 600000. */\n timeout?: number;\n /**\n * Identifies a wrapper built on this SDK (the CLI, the video kit) in the\n * `X-Sonilo-Client` header. Leave unset for direct SDK use — without an\n * override a wrapper's traffic is indistinguishable from the SDK's own.\n */\n clientName?: string;\n /** Version reported alongside `clientName`. Defaults to the SDK's version. */\n clientVersion?: string;\n}\n\nconst DEFAULT_BASE_URL = \"https://api.sonilo.com\";\n\n/**\n * Reported in `X-Sonilo-Client` unless a wrapper overrides it. First-party\n * wrappers (the CLI, the video kit) pass their own name so their traffic stays\n * distinguishable from direct SDK use in server-side analytics.\n */\nexport const DEFAULT_CLIENT_NAME = \"sdk-js\";\n\n/** Milliseconds before an in-flight request is aborted, unless overridden. */\nexport const DEFAULT_TIMEOUT_MS = 600_000;\n\nexport class SoniloClient {\n readonly baseUrl: string;\n private readonly apiKey: string;\n private readonly fetchFn: typeof globalThis.fetch;\n private readonly timeout: number;\n private readonly clientName: string;\n private readonly clientVersion: string;\n readonly account: Account;\n readonly tasks: Tasks;\n readonly textToMusic: TextToMusic;\n readonly videoToMusic: VideoToMusic;\n readonly textToSfx: TextToSfx;\n readonly videoToSfx: VideoToSfx;\n readonly videoToVideoMusic: VideoToVideoMusic;\n readonly videoToVideoSfx: VideoToVideoSfx;\n readonly videoToSound: VideoToSound;\n readonly videoToVideoSound: VideoToVideoSound;\n\n constructor(options: SoniloClientOptions = {}) {\n const envKey =\n typeof process !== \"undefined\" ? process.env?.SONILO_API_KEY : undefined;\n const apiKey = options.apiKey ?? envKey;\n if (!apiKey) {\n throw new SoniloError(\n \"Missing API key: pass { apiKey } or set the SONILO_API_KEY environment variable\",\n );\n }\n this.apiKey = apiKey;\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.fetchFn = (options.fetch ?? globalThis.fetch).bind(globalThis);\n this.timeout = options.timeout ?? DEFAULT_TIMEOUT_MS;\n this.clientName = options.clientName ?? DEFAULT_CLIENT_NAME;\n this.clientVersion = options.clientVersion ?? VERSION;\n this.account = new Account(this);\n this.tasks = new Tasks(this);\n this.textToMusic = new TextToMusic(this);\n this.videoToMusic = new VideoToMusic(this);\n this.textToSfx = new TextToSfx(this);\n this.videoToSfx = new VideoToSfx(this);\n this.videoToVideoMusic = new VideoToVideoMusic(this);\n this.videoToVideoSfx = new VideoToVideoSfx(this);\n this.videoToSound = new VideoToSound(this);\n this.videoToVideoSound = new VideoToVideoSound(this);\n }\n\n /**\n * Perform an authenticated request; throws a typed error on non-2xx.\n *\n * `opts.timeout` overrides the client's default timeout for this call;\n * pass `null` to disable the abort-on-timeout behavior entirely (used by\n * the streaming music endpoints — see textToMusic.ts / videoToMusic.ts).\n * A caller-supplied `init.signal` always wins over any timeout signal.\n */\n async request(\n path: string,\n init: RequestInit = {},\n opts: { timeout?: number | null } = {},\n ): Promise<Response> {\n const headers = new Headers(init.headers);\n headers.set(\"Authorization\", `Bearer ${this.apiKey}`);\n headers.set(\"X-Sonilo-Client\", this.clientName);\n headers.set(\"X-Sonilo-Client-Version\", this.clientVersion);\n const timeout = opts.timeout === undefined ? this.timeout : opts.timeout;\n // We only \"own\" the signal (and may later rewrap its abort as a\n // RequestTimeoutError) when the caller didn't supply one and a timeout\n // is actually enabled.\n const ownsSignal = init.signal == null && timeout !== null;\n const signal = init.signal ?? (timeout === null ? undefined : AbortSignal.timeout(timeout));\n try {\n const res = await this.fetchFn(`${this.baseUrl}${path}`, { ...init, headers, signal });\n if (!res.ok) throw await errorFromResponse(res);\n return res;\n } catch (err) {\n if (ownsSignal && isTimeoutSignalError(err)) {\n throw new RequestTimeoutError(`Request to ${path} timed out after ${timeout}ms`);\n }\n throw err;\n }\n }\n}\n","import { DEFAULT_TIMEOUT_MS } from \"./client.js\";\nimport { RequestTimeoutError, SoniloError, isTimeoutSignalError } from \"./errors.js\";\nimport type { SfxMedia } from \"./types.js\";\n\n/** Fetch a result media file. The URL is presigned — no API key is sent.\n *\n * Accepts either a media object (`result.audio`, `result.music`, …) or a bare\n * URL string, which is what the combined video-to-sound endpoints return as\n * `output_url`. */\nexport async function download(\n media: SfxMedia | string | undefined,\n fetchFn: typeof globalThis.fetch = globalThis.fetch,\n timeout: number = DEFAULT_TIMEOUT_MS,\n): Promise<Uint8Array> {\n const url = typeof media === \"string\" ? media : media?.url;\n if (!url) {\n throw new SoniloError(\"No media to download\");\n }\n let res: Response;\n try {\n res = await fetchFn(url, { signal: AbortSignal.timeout(timeout) });\n } catch (err) {\n if (isTimeoutSignalError(err)) {\n throw new RequestTimeoutError(`Download of ${url} timed out after ${timeout}ms`);\n }\n throw err;\n }\n if (!res.ok) {\n throw new SoniloError(`Download failed: HTTP ${res.status}`);\n }\n return new Uint8Array(await res.arrayBuffer());\n}\n","export type SegmentLabel =\n | \"intro\"\n | \"verse\"\n | \"pre-chorus\"\n | \"chorus\"\n | \"bridge\"\n | \"break\"\n | \"silence\"\n | \"outro\"\n | \"none\";\n\nexport interface Segment {\n start: number;\n prompt: string;\n label?: SegmentLabel;\n}\n\n/** Monetary fields are strings, exactly as the backend serializes them. */\nexport interface CostInfo {\n billing_rate_per_sec: string;\n billing_before_discount: string;\n billing_after_discount: string;\n discount_factor: string;\n}\n\nexport interface AudioChunkEvent {\n type: \"audio_chunk\";\n /** Decoded from the wire's base64 by the SDK. */\n data: Uint8Array;\n}\n\nexport interface TitleEvent {\n type: \"title\";\n title: string;\n summary?: string;\n display_tags?: string[];\n [key: string]: unknown;\n}\n\nexport interface CompleteEvent {\n type: \"complete\";\n [key: string]: unknown;\n}\n\nexport interface ErrorEvent {\n type: \"error\";\n code?: string;\n message?: string;\n [key: string]: unknown;\n}\n\nexport interface CostEvent extends CostInfo {\n type: \"cost\";\n}\n\n/** Forward-compatibility: unrecognized event types are passed through. */\nexport interface UnknownEvent {\n type: string;\n [key: string]: unknown;\n}\n\nexport type StreamEvent =\n | AudioChunkEvent\n | TitleEvent\n | CompleteEvent\n | ErrorEvent\n | CostEvent\n | UnknownEvent;\n\nexport interface Track {\n audio: Uint8Array;\n title?: string;\n cost?: CostInfo;\n}\n\nexport interface TextToMusicParams {\n prompt: string;\n duration: number;\n segments?: Segment[];\n /** \"stream\" (default) or \"async\" (required by `submit()` and `output_format: \"wav\"`). */\n mode?: \"stream\" | \"async\";\n /** Container for the async result. `wav` requires `mode: \"async\"`. Defaults to m4a server-side. */\n outputFormat?: \"m4a\" | \"wav\";\n /** Bounds the stream: aborting this cancels the in-flight generation.\n * Passed straight through to `fetch` — it is never rewrapped as\n * RequestTimeoutError, since the client's own absolute timeout does not\n * apply to streaming music generation. */\n signal?: AbortSignal;\n}\n\n/** string = file path (Node.js only). */\nexport type VideoInput =\n | File\n | Blob\n | Uint8Array\n | ArrayBuffer\n | ReadableStream<Uint8Array>\n | string;\n\nexport interface VideoToMusicParams {\n video?: VideoInput;\n videoUrl?: string;\n prompt?: string;\n segments?: Segment[];\n /** Bounds the stream: aborting this cancels the in-flight generation.\n * Passed straight through to `fetch` — it is never rewrapped as\n * RequestTimeoutError, since the client's own absolute timeout does not\n * apply to streaming music generation. Only meaningful for `stream()`/\n * `generate()`; `submit()` ignores it. */\n signal?: AbortSignal;\n /** \"stream\" (the default, used by `stream()`/`generate()`) or \"async\"\n * (required for `submit()`, and for `isolateVocals`). Only consulted by\n * `submit()` — `stream()`/`generate()` always request a stream. */\n mode?: \"stream\" | \"async\";\n /** Split the generated track into a vocals-only stem alongside the mix.\n * Requires `mode: \"async\"`; if `mode` is left unset it defaults to\n * \"async\" automatically. Only usable via `submit()` — the backend\n * rejects it on the plain stream. */\n isolateVocals?: boolean;\n /** Keep the source speech/vocals in the async result. Current name for\n * `isolateVocals`; both are accepted and OR'd server-side. Requires\n * `mode: \"async\"` (auto-selected by `submit()`). */\n preserveSpeech?: boolean;\n /** Container for the async result. `wav` requires async. Defaults to m4a. */\n outputFormat?: \"m4a\" | \"wav\";\n /** Duck the generated music under the source voice at finalize time.\n * Default-ON server-side in async mode: leave unset to keep it on, pass\n * `false` to opt out. Free, best-effort; only valid on `submit()`. */\n ducking?: boolean;\n}\n\nexport interface TrialQuota {\n granted: number;\n used: number;\n remaining: number;\n}\n\nexport interface AccountServices {\n available_services: string[];\n rpm_limit: number;\n concurrency_limit: number;\n discount_factor: number | string;\n max_upload_size_mb: number | null;\n /** Free-trial allowance keyed by service. Returned only for self-serve\n * accounts; absent entirely for invoiced accounts. */\n trial?: Record<string, TrialQuota>;\n}\n\nexport interface UsageSummary {\n total_requests: number;\n total_duration_seconds: number;\n total_cost: number | string;\n period_start: string;\n period_end: string;\n [key: string]: unknown;\n}\n\nexport interface DailyUsage {\n date: string;\n requests: number;\n duration_seconds: number;\n cost: number | string;\n}\n\nexport interface UsageResponse {\n summary: UsageSummary;\n daily: DailyUsage[];\n}\n\nexport function isAudioChunkEvent(event: StreamEvent): event is AudioChunkEvent {\n return event.type === \"audio_chunk\" && (event as AudioChunkEvent).data instanceof Uint8Array;\n}\n\nexport function isErrorEvent(event: StreamEvent): event is ErrorEvent {\n return event.type === \"error\";\n}\n\n/** SFX segments (unlike music `Segment`) require `end`, must start at 0,\n * and be contiguous; validated server-side. */\nexport interface SfxSegment {\n start: number;\n end: number;\n prompt: string;\n}\n\nexport type SfxAudioFormat = \"wav\" | \"mp3\" | \"aac\" | \"flac\";\n\n/** Submission ack for the async SFX endpoints. */\nexport interface SfxTask {\n task_id: string;\n status: string;\n}\n\n/** A generated file re-hosted on R2 behind a presigned URL. */\nexport interface SfxMedia {\n url: string;\n content_type?: string;\n file_size?: number;\n}\n\nexport interface SfxError {\n code?: string;\n message?: string;\n}\n\n/**\n * Common shape of any polled task (`tasks.get`/`tasks.wait`), regardless of\n * which endpoint created it. `Tasks.get`/`Tasks.wait` are generic over this so\n * each endpoint's result type (e.g. `SfxResult`, `MusicTaskResult`) can add\n * its own `audio`/media fields while sharing the status/error/refund\n * bookkeeping the poller relies on.\n */\nexport interface BaseTaskResult {\n task_id: string;\n type?: string;\n status: \"processing\" | \"succeeded\" | \"failed\" | (string & {});\n /** Only present when the account's task-field whitelist enables cost. */\n cost?: number;\n error?: SfxError;\n refunded?: boolean;\n [key: string]: unknown;\n}\n\n/** State of an SFX task (`tasks.get`) or its final result (`wait`/`generate`). */\nexport interface SfxResult extends BaseTaskResult {\n audio?: SfxMedia;\n /** Kept for backward compatibility; no longer populated — video-to-sfx returns audio only. */\n video?: SfxMedia;\n}\n\nexport interface TextToSfxParams {\n prompt: string;\n duration: number;\n audioFormat?: SfxAudioFormat;\n}\n\nexport interface VideoToSfxParams {\n video?: VideoInput;\n videoUrl?: string;\n prompt?: string;\n segments?: SfxSegment[];\n audioFormat?: SfxAudioFormat;\n}\n\n/** One decoded audio stream of an async video-to-music result. Unlike SFX,\n * `audio` on a music task is always an array — even without `isolateVocals` —\n * since a music generation can carry more than one output stream. */\nexport interface MusicMediaEntry extends SfxMedia {\n stream_index: number;\n sample_rate?: number;\n channels?: number;\n}\n\n/** One muxed audio+video-aligned output, present only when `isolateVocals`\n * is set. */\nexport interface MusicMuxEntry extends SfxMedia {\n stream_index: number;\n}\n\nexport interface MusicTitle {\n title: string;\n summary?: string;\n display_tags?: string[];\n}\n\n/** State of an async video-to-music task (`tasks.get`) or its final result\n * (`tasks.wait<MusicTaskResult>()`). Only reachable via `videoToMusic.submit()`\n * with `mode: \"async\"`. */\nexport interface MusicTaskResult extends BaseTaskResult {\n audio?: MusicMediaEntry[];\n /** Vocals-only stem; present only when `isolateVocals` was requested. */\n vocals?: SfxMedia;\n /** Muxed output per stream; present only when `isolateVocals` was requested. */\n mux?: MusicMuxEntry[];\n /** Music ducked under the source voice; present only when `ducking` ran. */\n ducked?: MusicMediaEntry[];\n title?: MusicTitle;\n duration_seconds?: number;\n}\n\nexport interface WaitOptions {\n /** Milliseconds between polls. Default 2000. */\n pollInterval?: number;\n /** Overall deadline in milliseconds. Default 600000. */\n timeout?: number;\n}\n\n/** Result of an async video-to-video task (`videoToVideoMusic`/`videoToVideoSfx`):\n * a re-hosted video with generated music or SFX muxed in. */\nexport interface VideoResult extends BaseTaskResult {\n video?: SfxMedia;\n duration_seconds?: number;\n}\n\nexport interface VideoToVideoMusicParams {\n video?: VideoInput;\n videoUrl?: string;\n prompt?: string;\n /** Keep the source speech/vocals in the output. Both this and the legacy\n * `isolateVocals` are accepted and OR'd server-side. */\n preserveSpeech?: boolean;\n /** @deprecated Legacy alias for `preserveSpeech`. */\n isolateVocals?: boolean;\n}\n\nexport interface VideoToVideoSfxParams {\n video?: VideoInput;\n videoUrl?: string;\n prompt?: string;\n segments?: SfxSegment[];\n}\n\n/** Params for `videoToSound` and `videoToVideoSound`. Both endpoints take the\n * identical form, so they share one params type. */\nexport interface VideoToSoundParams {\n video?: VideoInput;\n videoUrl?: string;\n /** Style hint for the generated music bed. */\n musicPrompt?: string;\n /** Description of the sound effects layered over the music. */\n sfxPrompt?: string;\n /** Per-segment SFX descriptions; must start at 0 and be contiguous. */\n segments?: SfxSegment[];\n /** Keep the source speech in the result. */\n preserveSpeech?: boolean;\n /** Duck the generated music under the source speech. Default-ON\n * server-side: leave unset to keep it on, pass `false` to opt out. */\n ducking?: boolean;\n}\n\n/** Result of a `videoToSound` / `videoToVideoSound` task (`tasks.get`) or its\n * final state (`generate`).\n *\n * The combined music+SFX result is `output_url` — a bare presigned URL rather\n * than a media object, since these endpoints render one artifact whose kind is\n * announced by `output_type` (\"audio\" for video-to-sound, \"video\" for\n * video-to-video-sound). `music`, `music_processed` and `sfx` are the\n * individual stems; pass any of them, or `output_url` itself, to `download()`. */\nexport interface SoundResult extends BaseTaskResult {\n output_url?: string;\n output_type?: \"audio\" | \"video\";\n output_bytes?: number;\n music?: SfxMedia;\n /** Present only when `preserveSpeech`/`ducking` altered the music bed. */\n music_processed?: SfxMedia;\n sfx?: SfxMedia;\n duration_seconds?: number;\n}\n"],"mappings":";AAAO,IAAM,cAAN,cAA0B,MAAM;AAAA,EACrC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO,WAAW;AAAA,EACzB;AACF;AAEO,IAAM,WAAN,cAAuB,YAAY;AAAA,EAQxC,YAAY,SAAiB,QAAgB,MAAgB;AAC3D,UAAM,OAAO;AACb,SAAK,SAAS;AACd,SAAK,OAAO;AACZ,UAAM,SAAS;AACf,SAAK,OAAO,OAAO,QAAQ,SAAS,WAAW,OAAO,OAA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