@tanstack/ai-byteplus 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -166,7 +166,8 @@ Result URLs expire after 24 hours; pass `response_format: 'b64_json'` in
166
166
  - **Chat** — `dola-seed-2-1-turbo-260628`, the `seed-2-0-*` family,
167
167
  `seed-1-8-251228`, the `seed-1-6-*` family, plus `glm-*`, `deepseek-*` and
168
168
  `gpt-oss-120b-250805`.
169
- - **Video** — `dreamina-seedance-2-0-260128` (and `-fast-`/`-mini-`),
169
+ - **Video** — `dreamina-seedance-2-5-260628`,
170
+ `dreamina-seedance-2-0-260128` (and `-fast-`/`-mini-`),
170
171
  `seedance-1-5-pro-251215`, `seedance-1-0-pro-250528`,
171
172
  `seedance-1-0-pro-fast-251015`.
172
173
  - **Image** — `dola-seedream-5-0-pro-260628`, `seedream-5-0-260128`,
@@ -184,21 +184,20 @@ var BytePlusTextAdapter = class extends OpenAIBaseChatCompletionsTextAdapter {
184
184
  async *structuredOutputStream(options) {
185
185
  const unsupported = this.structuredOutputUnsupportedMessage();
186
186
  if (unsupported) {
187
- const timestamp = Date.now();
188
187
  const runId = generateId(this.name);
189
188
  yield {
190
189
  type: EventType.RUN_STARTED,
191
190
  runId,
192
191
  threadId: options.chatOptions.threadId ?? generateId(this.name),
193
192
  model: options.chatOptions.model,
194
- timestamp,
193
+ timestamp: Date.now(),
195
194
  parentRunId: options.chatOptions.parentRunId
196
195
  };
197
196
  yield {
198
197
  type: EventType.RUN_ERROR,
199
198
  runId,
200
199
  model: options.chatOptions.model,
201
- timestamp,
200
+ timestamp: Date.now(),
202
201
  message: unsupported,
203
202
  code: "unsupported-structured-output",
204
203
  error: {
@@ -1 +1 @@
1
- {"version":3,"file":"text.js","names":[],"sources":["../../../src/adapters/text.ts"],"sourcesContent":["import OpenAI from 'openai'\nimport { EventType } from '@tanstack/ai'\nimport { OpenAIBaseChatCompletionsTextAdapter } from '@tanstack/openai-base'\nimport { generateId } from '@tanstack/ai-utils'\nimport {\n BYTEPLUS_STRUCTURED_OUTPUT_CHAT_MODELS,\n emitsEncryptedContent,\n supportsStructuredOutput,\n} from '../model-meta'\nimport {\n getBytePlusArkApiKeyFromEnv,\n withBytePlusArkDefaults,\n} from '../utils/client'\nimport type {\n StructuredOutputOptions,\n StructuredOutputResult,\n} from '@tanstack/ai/adapters'\nimport type {\n ContentPart,\n ContentPartSource,\n Modality,\n ModelMessage,\n StreamChunk,\n TextOptions,\n} from '@tanstack/ai'\nimport type {\n ChatCompletionContentPart,\n ChatCompletionMessageParam,\n} from 'openai/resources/chat/completions/completions'\nimport type {\n BYTEPLUS_CHAT_MODELS,\n BytePlusChatModelToolCapabilitiesByName,\n ResolveInputModalities,\n ResolveProviderOptions,\n} from '../model-meta'\nimport type {\n BytePlusAudioMetadata,\n BytePlusChatContentPart,\n BytePlusEncryptedContentFields,\n BytePlusImageMetadata,\n BytePlusInputAudioContentPart,\n BytePlusMessageMetadataByModality,\n BytePlusStreamDeltaExtras,\n BytePlusVideoMetadata,\n} from '../message-types'\nimport type { BytePlusArkConfig } from '../utils/client'\n\ntype ResolveToolCapabilities<TModel extends string> =\n TModel extends keyof BytePlusChatModelToolCapabilitiesByName\n ? NonNullable<BytePlusChatModelToolCapabilitiesByName[TModel]>\n : readonly []\n\n/**\n * Configuration for the BytePlus text adapter.\n */\nexport interface BytePlusTextConfig extends BytePlusArkConfig {}\n\n/**\n * Re-export of the public provider options type.\n */\nexport type { BytePlusTextProviderOptions } from '../text/text-provider-options'\n\n/**\n * BytePlus ModelArk Text (Chat) Adapter\n *\n * Tree-shakeable adapter for the Seed / GLM / DeepSeek / gpt-oss chat models\n * on BytePlus ModelArk. Ark serves an OpenAI-compatible Chat Completions\n * endpoint, so this drives the OpenAI SDK against Ark's `baseURL` — the same\n * pattern as `ai-groq` and `ai-grok`.\n *\n * Three Ark behaviours are handled on top of the shared base:\n *\n * 1. **`reasoning_content` deltas** — Ark streams reasoning under\n * `delta.reasoning_content` rather than the OpenAI `reasoning` field.\n * 2. **`encrypted_content` round-trip** — thinking-summary models emit an\n * opaque signature over the reasoning trace. See\n * {@link BytePlusTextAdapter.processStreamChunks} and\n * {@link BytePlusTextAdapter.convertMessage}.\n * 3. **Per-model structured-output gating** — only 10 of the 18 shipped chat\n * models honour `response_format: json_schema` (glm-4-7 accepts it and then\n * ignores the schema), and Ark rejects `json_object` everywhere, so there\n * is no JSON-mode fallback.\n */\nexport class BytePlusTextAdapter<\n TModel extends (typeof BYTEPLUS_CHAT_MODELS)[number],\n // `Record<string, any>` (not `unknown`) mirrors the OpenAI/Groq/Grok text\n // adapters: the resolved provider options are an interface with no index\n // signature, assignable to `Record<string, any>` but not to\n // `Record<string, unknown>`. See issue #821.\n TProviderOptions extends Record<string, any> = ResolveProviderOptions<TModel>,\n TInputModalities extends ReadonlyArray<Modality> =\n ResolveInputModalities<TModel>,\n TToolCapabilities extends ReadonlyArray<string> =\n ResolveToolCapabilities<TModel>,\n> extends OpenAIBaseChatCompletionsTextAdapter<\n TModel,\n TProviderOptions,\n TInputModalities,\n BytePlusMessageMetadataByModality,\n TToolCapabilities\n> {\n override readonly kind = 'text' as const\n override readonly name = 'byteplus' as const\n\n constructor(config: BytePlusTextConfig, model: TModel) {\n super(model, 'byteplus', new OpenAI(withBytePlusArkDefaults(config)))\n }\n\n /**\n * Surfaces Ark's reasoning deltas. Thinking-enabled models stream the\n * reasoning trace as `delta.reasoning_content` (the OpenAI chunk shape has\n * no reasoning field); the base routes this hook through both `chatStream`\n * and `structuredOutputStream`.\n */\n protected override extractReasoning(\n chunk: OpenAI.Chat.Completions.ChatCompletionChunk,\n ): { text: string } | undefined {\n const delta = chunk.choices[0]?.delta as\n | BytePlusStreamDeltaExtras\n | undefined\n const raw = delta?.reasoning_content\n if (typeof raw === 'string' && raw.length > 0) {\n return { text: raw }\n }\n return undefined\n }\n\n /**\n * Captures Ark's `encrypted_content` and attaches it to the reasoning\n * step's `STEP_FINISHED` event as its `signature`.\n *\n * On a thinking-summary model Ark streams the whole blob as one dedicated\n * chunk (empty `content` and `reasoning_content`) sitting between the\n * reasoning deltas and the content deltas — so it is always captured before\n * the base closes the reasoning lifecycle at the first content delta.\n *\n * `signature` is the framework's existing provider-signature seam: the chat\n * engine stores it on the `ThinkingPart`, which\n * `buildAssistantMessages` carries into `ModelMessage.thinking[].signature`,\n * which {@link BytePlusTextAdapter.convertMessage} echoes back to Ark on the\n * next turn. No base-class change is needed — this is the same round-trip\n * Anthropic's thinking signatures use.\n *\n * Only `chatStream` is covered: `structuredOutputStream` drives the SDK\n * directly in the base with no per-chunk seam, so a structured-output turn\n * does not capture the blob. Ark accepts a following turn without it, so the\n * consequence is a lost reasoning-cache hit, not a failed request.\n */\n protected override async *processStreamChunks(\n stream: AsyncIterable<OpenAI.Chat.Completions.ChatCompletionChunk>,\n options: TextOptions,\n aguiState: {\n runId: string\n threadId: string\n messageId: string\n hasEmittedRunStarted: boolean\n },\n ): AsyncIterable<StreamChunk> {\n const captured: { encryptedContent?: string } = {}\n\n for await (const event of super.processStreamChunks(\n captureEncryptedContent(stream, captured),\n options,\n aguiState,\n )) {\n if (\n event.type === EventType.STEP_FINISHED &&\n captured.encryptedContent !== undefined &&\n event.signature === undefined\n ) {\n // `delta` is stamped alongside the signature because the two consumers\n // read this event differently. `chat()`'s server agent loop accumulates\n // thinking ONLY from `STEP_FINISHED.delta` and then drops the whole\n // step — signature included — when the accumulated content is empty\n // (`finalizeCurrentThinkingStep`); the OpenAI base emits `content` but\n // never `delta`, so without this the blob never reaches the\n // continuation message. The client `StreamProcessor` can't double-count\n // it: it short-circuits STEP_FINISHED content once\n // `hasSeenReasoningEvents` is set, which the REASONING_MESSAGE_CONTENT\n // events preceding every STEP_FINISHED here always set.\n yield {\n ...event,\n signature: captured.encryptedContent,\n delta: event.delta ?? event.content ?? '',\n }\n continue\n }\n yield event\n }\n }\n\n /**\n * Echoes a captured `encrypted_content` blob back on outgoing assistant\n * messages so multi-turn conversations replay it verbatim, as Ark's\n * thinking-summary docs require.\n *\n * The gate is `emitsEncryptedContent(this.model)` — the model being called\n * now, not the provenance of the history. That guarantees a signature is\n * never sent to a model that has no `encrypted_content` concept. It does\n * NOT identify who produced the signature: `ModelMessage` carries no\n * provider field, so a foreign signature (e.g. an Anthropic thinking\n * signature in replayed cross-provider history) WILL be forwarded when the\n * current model is a thinking-summary model. No shape guard is attempted —\n * the blob is opaque and Ark is the only party that can validate it.\n *\n * Absence is never an error: a live probe confirmed Ark accepts a turn whose\n * assistant message omits `encrypted_content`.\n */\n protected override convertMessage(\n message: ModelMessage,\n ): ChatCompletionMessageParam {\n const converted = super.convertMessage(message)\n if (converted.role !== 'assistant' || !emitsEncryptedContent(this.model)) {\n return converted\n }\n\n const encryptedContent = lastThinkingSignature(message)\n if (encryptedContent === undefined) return converted\n\n // Intersection rather than a cast: `encrypted_content` is an Ark-only\n // field with no slot on the OpenAI message param, and the intersection is\n // still assignable to `ChatCompletionMessageParam`.\n const withEncrypted: typeof converted & BytePlusEncryptedContentFields = {\n ...converted,\n encrypted_content: encryptedContent,\n }\n return withEncrypted\n }\n\n /**\n * Adds the Ark-only content parts on top of the base's text/image handling:\n * `video_url`, URL-addressed `input_audio`, and the extra `image_url`\n * fields (`detail: 'xhigh'`, `image_pixel_limit`).\n */\n protected override convertContentPart(\n part: ContentPart,\n ): ChatCompletionContentPart | null {\n if (part.type === 'image') {\n const metadata = part.metadata as BytePlusImageMetadata | undefined\n return asChatContentPart({\n type: 'image_url',\n image_url: {\n url: toUrlOrDataUri(part.source),\n detail: metadata?.detail ?? 'auto',\n ...(metadata?.image_pixel_limit && {\n image_pixel_limit: metadata.image_pixel_limit,\n }),\n },\n })\n }\n\n if (part.type === 'video') {\n const metadata = part.metadata as BytePlusVideoMetadata | undefined\n return asChatContentPart({\n type: 'video_url',\n video_url: {\n url: toUrlOrDataUri(part.source),\n ...(metadata?.fps !== undefined && { fps: metadata.fps }),\n },\n })\n }\n\n if (part.type === 'audio') {\n const metadata = part.metadata as BytePlusAudioMetadata | undefined\n // Ark takes audio either by URL or as inline base64 with an explicit\n // container format; unlike images there is no data-URI form.\n if (part.source.type === 'url') {\n return asChatContentPart({\n type: 'input_audio',\n input_audio: { url: part.source.value },\n })\n }\n const format = metadata?.format ?? audioFormatFromMimeType(part.source)\n if (format === undefined) {\n throw new Error(\n `Audio content part for ${this.name} has an unrecognised mimeType ` +\n `(${part.source.mimeType || 'none'}). Set the container format ` +\n `explicitly via the part's metadata.format, or supply a URL source.`,\n )\n }\n return asChatContentPart({\n type: 'input_audio',\n input_audio: { data: stripDataUriPrefix(part.source.value), format },\n })\n }\n\n return super.convertContentPart(part)\n }\n\n /**\n * Only the models in {@link BYTEPLUS_STRUCTURED_OUTPUT_CHAT_MODELS} accept\n * `response_format: json_schema`; the rest reject it with a 400.\n *\n * Returning `false` for a rejecting model does not make structured output\n * work — Ark has no `json_object` fallback to downgrade to. What it buys is\n * keeping `response_format` out of the request the engine would otherwise\n * build: with the hook false the engine takes its separate finalization\n * path, and the guard in {@link BytePlusTextAdapter.structuredOutput} /\n * {@link BytePlusTextAdapter.structuredOutputStream} stops that *before*\n * any HTTP call. So a `chat({ outputSchema })` on a rejecting model fails\n * loudly, named, without a schema Ark would 400 on ever leaving the\n * process — rather than 400-ing on every turn, or (worse) parsing prose as\n * if it were JSON.\n *\n * Tools without a schema are unaffected: `tools` alone never involves\n * `response_format`.\n */\n override supportsCombinedToolsAndSchema(): boolean {\n return supportsStructuredOutput(this.model)\n }\n\n override async structuredOutput(\n options: StructuredOutputOptions<TProviderOptions>,\n ): Promise<StructuredOutputResult<unknown>> {\n const unsupported = this.structuredOutputUnsupportedMessage()\n if (unsupported) {\n options.chatOptions.logger.errors(\n `${this.name}.structuredOutput unsupported model`,\n {\n error: { message: unsupported },\n source: `${this.name}.structuredOutput`,\n },\n )\n throw new Error(unsupported)\n }\n return await super.structuredOutput(options)\n }\n\n override async *structuredOutputStream(\n options: StructuredOutputOptions<TProviderOptions>,\n ): AsyncIterable<StreamChunk> {\n const unsupported = this.structuredOutputUnsupportedMessage()\n if (unsupported) {\n // Mirror the base's contract: failures inside structuredOutputStream\n // surface as a RUN_STARTED → RUN_ERROR pair rather than a throw, so\n // consumers keep a single error-handling path.\n const timestamp = Date.now()\n const runId = generateId(this.name)\n yield {\n type: EventType.RUN_STARTED,\n runId,\n threadId: options.chatOptions.threadId ?? generateId(this.name),\n model: options.chatOptions.model,\n timestamp,\n parentRunId: options.chatOptions.parentRunId,\n }\n yield {\n type: EventType.RUN_ERROR,\n runId,\n model: options.chatOptions.model,\n timestamp,\n message: unsupported,\n code: 'unsupported-structured-output',\n error: { message: unsupported, code: 'unsupported-structured-output' },\n }\n options.chatOptions.logger.errors(\n `${this.name}.structuredOutputStream unsupported model`,\n {\n error: { message: unsupported },\n source: `${this.name}.structuredOutputStream`,\n },\n )\n return\n }\n yield* super.structuredOutputStream(options)\n }\n\n /**\n * Explains why structured output is unavailable, or `undefined` when the\n * model supports it. Ark rejects `response_format: json_object` on every\n * model, so there is no JSON-mode fallback to degrade to — failing loud\n * here beats a raw upstream 400.\n */\n private structuredOutputUnsupportedMessage(): string | undefined {\n if (supportsStructuredOutput(this.model)) return undefined\n return (\n `BytePlus model ${this.model} does not support structured output — Ark ` +\n `rejects both response_format json_schema and json_object on it. Use ` +\n `one of: ${BYTEPLUS_STRUCTURED_OUTPUT_CHAT_MODELS.join(', ')}.`\n )\n }\n}\n\n/**\n * Passes Ark's chunks through untouched while recording the single\n * `encrypted_content` blob a thinking-summary model emits.\n */\nasync function* captureEncryptedContent(\n stream: AsyncIterable<OpenAI.Chat.Completions.ChatCompletionChunk>,\n captured: { encryptedContent?: string },\n): AsyncIterable<OpenAI.Chat.Completions.ChatCompletionChunk> {\n for await (const chunk of stream) {\n const delta = chunk.choices[0]?.delta as\n | BytePlusStreamDeltaExtras\n | undefined\n const blob = delta?.encrypted_content\n if (typeof blob === 'string' && blob.length > 0) {\n captured.encryptedContent = blob\n }\n yield chunk\n }\n}\n\n/**\n * The blob to echo back for an assistant message: the last thinking step that\n * carries a signature.\n */\nfunction lastThinkingSignature(message: ModelMessage): string | undefined {\n const thinking = message.thinking\n if (!thinking) return undefined\n for (let i = thinking.length - 1; i >= 0; i--) {\n const signature = thinking[i]?.signature\n if (signature) return signature\n }\n return undefined\n}\n\n/**\n * The one place the Ark content-part dialect meets the OpenAI SDK's request\n * types.\n *\n * Ark's union is a superset of OpenAI's: `video_url` has no OpenAI arm at all,\n * `input_audio` additionally accepts a `url`, and `image_url` carries\n * `detail: 'xhigh'` and `image_pixel_limit`. `ChatCompletionContentPart` is a\n * closed type alias in the SDK, so no interface augmentation can admit those\n * arms and no narrowing can produce them — widening to `object` keeps this to\n * a single downcast rather than spreading one through each branch of\n * {@link BytePlusTextAdapter.convertContentPart}.\n */\nfunction asChatContentPart(\n part: BytePlusChatContentPart,\n): ChatCompletionContentPart {\n const arkPart: object = part\n return arkPart as ChatCompletionContentPart\n}\n\n/**\n * Renders a content source as the URL string Ark expects: URLs pass through,\n * inline base64 becomes a `data:` URI.\n */\nfunction toUrlOrDataUri(source: ContentPartSource): string {\n if (source.type !== 'data' || source.value.startsWith('data:')) {\n return source.value\n }\n // A missing mimeType would interpolate as \"data:undefined;base64,…\" and be\n // rejected, so fall back the same way the OpenAI base does.\n return `data:${source.mimeType || 'application/octet-stream'};base64,${source.value}`\n}\n\n/**\n * Strips a `data:` prefix so inline audio is sent as bare base64.\n */\nfunction stripDataUriPrefix(value: string): string {\n const comma = value.startsWith('data:') ? value.indexOf(',') : -1\n return comma === -1 ? value : value.slice(comma + 1)\n}\n\nconst AUDIO_FORMAT_BY_MIME_SUBTYPE: Record<\n string,\n NonNullable<BytePlusInputAudioContentPart['input_audio']['format']>\n> = {\n mpeg: 'mp3',\n mp3: 'mp3',\n wav: 'wav',\n 'x-wav': 'wav',\n wave: 'wav',\n ogg: 'ogg',\n flac: 'flac',\n 'x-flac': 'flac',\n mp4: 'm4a',\n m4a: 'm4a',\n 'x-m4a': 'm4a',\n aac: 'aac',\n pcm: 'pcm',\n l16: 'pcm',\n}\n\n/**\n * Maps an audio part's mimeType to Ark's container format token.\n */\nfunction audioFormatFromMimeType(\n source: ContentPartSource,\n):\n | NonNullable<BytePlusInputAudioContentPart['input_audio']['format']>\n | undefined {\n const mimeType = source.mimeType\n if (!mimeType) return undefined\n const subtype = mimeType.split(';')[0]?.split('/')[1]?.toLowerCase()\n return subtype ? AUDIO_FORMAT_BY_MIME_SUBTYPE[subtype] : undefined\n}\n\n/**\n * Creates a BytePlus text adapter with an explicit API key.\n *\n * @param model - The chat model id (e.g., `'seed-2-0-lite-260428'`)\n * @param apiKey - Your BytePlus Ark API key\n * @param config - Optional additional configuration\n *\n * @example\n * ```typescript\n * const adapter = createBytePlusText('seed-2-0-lite-260428', 'ark-...')\n * ```\n */\nexport function createBytePlusText<\n TModel extends (typeof BYTEPLUS_CHAT_MODELS)[number],\n>(\n model: TModel,\n apiKey: string,\n config?: Omit<BytePlusTextConfig, 'apiKey'>,\n): BytePlusTextAdapter<TModel> {\n return new BytePlusTextAdapter({ apiKey, ...config }, model)\n}\n\n/**\n * Creates a BytePlus text adapter with the API key read from `ARK_API_KEY`.\n *\n * @param model - The chat model id (e.g., `'seed-2-0-lite-260428'`)\n * @param config - Optional configuration (excluding `apiKey`)\n * @throws Error if `ARK_API_KEY` is not set\n *\n * @example\n * ```typescript\n * const adapter = byteplusText('seed-2-0-lite-260428')\n *\n * const stream = chat({\n * adapter,\n * messages: [{ role: 'user', content: 'Hello!' }],\n * })\n * ```\n */\nexport function byteplusText<\n TModel extends (typeof BYTEPLUS_CHAT_MODELS)[number],\n>(\n model: TModel,\n config?: Omit<BytePlusTextConfig, 'apiKey'>,\n): BytePlusTextAdapter<TModel> {\n const apiKey = getBytePlusArkApiKeyFromEnv()\n return createBytePlusText(model, apiKey, config)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmFA,IAAa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AmB,OAAuB;CACjD,MAAM,QAAQ,MAAM,WAAW,OAAO,IAAI,MAAM,QAAQ,GAAG,IAAI;CAC/D,OAAO,UAAU,KAAK,QAAQ,MAAM,MAAM,QAAQ,CAAC;AACrD;AAEA,IAAM,+BAGF;CACF,MAAM;CACN,KAAK;CACL,KAAK;CACL,SAAS;CACT,MAAM;CACN,KAAK;CACL,MAAM;CACN,UAAU;CACV,KAAK;CACL,KAAK;CACL,SAAS;CACT,KAAK;CACL,KAAK;CACL,KAAK;AACP;;;;AAKA,SAAS,wBACP,QAGY;CACZ,MAAM,WAAW,OAAO;CACxB,IAAI,CAAC,UAAU,OAAO,KAAA;CACtB,MAAM,UAAU,SAAS,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,YAAY;CACnE,OAAO,UAAU,6BAA6B,WAAW,KAAA;AAC3D;;;;;;;;;;;;;AAcA,SAAgB,mBAGd,OACA,QACA,QAC6B;CAC7B,OAAO,IAAI,oBAAoB;EAAE;EAAQ,GAAG;CAAO,GAAG,KAAK;AAC7D;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,aAGd,OACA,QAC6B;CAE7B,OAAO,mBAAmB,OADX,4BACkB,GAAQ,MAAM;AACjD"}
1
+ {"version":3,"file":"text.js","names":[],"sources":["../../../src/adapters/text.ts"],"sourcesContent":["import OpenAI from 'openai'\nimport { EventType } from '@tanstack/ai'\nimport { OpenAIBaseChatCompletionsTextAdapter } from '@tanstack/openai-base'\nimport { generateId } from '@tanstack/ai-utils'\nimport {\n BYTEPLUS_STRUCTURED_OUTPUT_CHAT_MODELS,\n emitsEncryptedContent,\n supportsStructuredOutput,\n} from '../model-meta'\nimport {\n getBytePlusArkApiKeyFromEnv,\n withBytePlusArkDefaults,\n} from '../utils/client'\nimport type {\n StructuredOutputOptions,\n StructuredOutputResult,\n} from '@tanstack/ai/adapters'\nimport type {\n ContentPart,\n ContentPartSource,\n Modality,\n ModelMessage,\n StreamChunk,\n TextOptions,\n} from '@tanstack/ai'\nimport type {\n ChatCompletionContentPart,\n ChatCompletionMessageParam,\n} from 'openai/resources/chat/completions/completions'\nimport type {\n BYTEPLUS_CHAT_MODELS,\n BytePlusChatModelToolCapabilitiesByName,\n ResolveInputModalities,\n ResolveProviderOptions,\n} from '../model-meta'\nimport type {\n BytePlusAudioMetadata,\n BytePlusChatContentPart,\n BytePlusEncryptedContentFields,\n BytePlusImageMetadata,\n BytePlusInputAudioContentPart,\n BytePlusMessageMetadataByModality,\n BytePlusStreamDeltaExtras,\n BytePlusVideoMetadata,\n} from '../message-types'\nimport type { BytePlusArkConfig } from '../utils/client'\n\ntype ResolveToolCapabilities<TModel extends string> =\n TModel extends keyof BytePlusChatModelToolCapabilitiesByName\n ? NonNullable<BytePlusChatModelToolCapabilitiesByName[TModel]>\n : readonly []\n\n/**\n * Configuration for the BytePlus text adapter.\n */\nexport interface BytePlusTextConfig extends BytePlusArkConfig {}\n\n/**\n * Re-export of the public provider options type.\n */\nexport type { BytePlusTextProviderOptions } from '../text/text-provider-options'\n\n/**\n * BytePlus ModelArk Text (Chat) Adapter\n *\n * Tree-shakeable adapter for the Seed / GLM / DeepSeek / gpt-oss chat models\n * on BytePlus ModelArk. Ark serves an OpenAI-compatible Chat Completions\n * endpoint, so this drives the OpenAI SDK against Ark's `baseURL` — the same\n * pattern as `ai-groq` and `ai-grok`.\n *\n * Three Ark behaviours are handled on top of the shared base:\n *\n * 1. **`reasoning_content` deltas** — Ark streams reasoning under\n * `delta.reasoning_content` rather than the OpenAI `reasoning` field.\n * 2. **`encrypted_content` round-trip** — thinking-summary models emit an\n * opaque signature over the reasoning trace. See\n * {@link BytePlusTextAdapter.processStreamChunks} and\n * {@link BytePlusTextAdapter.convertMessage}.\n * 3. **Per-model structured-output gating** — only 10 of the 18 shipped chat\n * models honour `response_format: json_schema` (glm-4-7 accepts it and then\n * ignores the schema), and Ark rejects `json_object` everywhere, so there\n * is no JSON-mode fallback.\n */\nexport class BytePlusTextAdapter<\n TModel extends (typeof BYTEPLUS_CHAT_MODELS)[number],\n // `Record<string, any>` (not `unknown`) mirrors the OpenAI/Groq/Grok text\n // adapters: the resolved provider options are an interface with no index\n // signature, assignable to `Record<string, any>` but not to\n // `Record<string, unknown>`. See issue #821.\n TProviderOptions extends Record<string, any> = ResolveProviderOptions<TModel>,\n TInputModalities extends ReadonlyArray<Modality> =\n ResolveInputModalities<TModel>,\n TToolCapabilities extends ReadonlyArray<string> =\n ResolveToolCapabilities<TModel>,\n> extends OpenAIBaseChatCompletionsTextAdapter<\n TModel,\n TProviderOptions,\n TInputModalities,\n BytePlusMessageMetadataByModality,\n TToolCapabilities\n> {\n override readonly kind = 'text' as const\n override readonly name = 'byteplus' as const\n\n constructor(config: BytePlusTextConfig, model: TModel) {\n super(model, 'byteplus', new OpenAI(withBytePlusArkDefaults(config)))\n }\n\n /**\n * Surfaces Ark's reasoning deltas. Thinking-enabled models stream the\n * reasoning trace as `delta.reasoning_content` (the OpenAI chunk shape has\n * no reasoning field); the base routes this hook through both `chatStream`\n * and `structuredOutputStream`.\n */\n protected override extractReasoning(\n chunk: OpenAI.Chat.Completions.ChatCompletionChunk,\n ): { text: string } | undefined {\n const delta = chunk.choices[0]?.delta as\n | BytePlusStreamDeltaExtras\n | undefined\n const raw = delta?.reasoning_content\n if (typeof raw === 'string' && raw.length > 0) {\n return { text: raw }\n }\n return undefined\n }\n\n /**\n * Captures Ark's `encrypted_content` and attaches it to the reasoning\n * step's `STEP_FINISHED` event as its `signature`.\n *\n * On a thinking-summary model Ark streams the whole blob as one dedicated\n * chunk (empty `content` and `reasoning_content`) sitting between the\n * reasoning deltas and the content deltas — so it is always captured before\n * the base closes the reasoning lifecycle at the first content delta.\n *\n * `signature` is the framework's existing provider-signature seam: the chat\n * engine stores it on the `ThinkingPart`, which\n * `buildAssistantMessages` carries into `ModelMessage.thinking[].signature`,\n * which {@link BytePlusTextAdapter.convertMessage} echoes back to Ark on the\n * next turn. No base-class change is needed — this is the same round-trip\n * Anthropic's thinking signatures use.\n *\n * Only `chatStream` is covered: `structuredOutputStream` drives the SDK\n * directly in the base with no per-chunk seam, so a structured-output turn\n * does not capture the blob. Ark accepts a following turn without it, so the\n * consequence is a lost reasoning-cache hit, not a failed request.\n */\n protected override async *processStreamChunks(\n stream: AsyncIterable<OpenAI.Chat.Completions.ChatCompletionChunk>,\n options: TextOptions,\n aguiState: {\n runId: string\n threadId: string\n messageId: string\n hasEmittedRunStarted: boolean\n },\n ): AsyncIterable<StreamChunk> {\n const captured: { encryptedContent?: string } = {}\n\n for await (const event of super.processStreamChunks(\n captureEncryptedContent(stream, captured),\n options,\n aguiState,\n )) {\n if (\n event.type === EventType.STEP_FINISHED &&\n captured.encryptedContent !== undefined &&\n event.signature === undefined\n ) {\n // `delta` is stamped alongside the signature because the two consumers\n // read this event differently. `chat()`'s server agent loop accumulates\n // thinking ONLY from `STEP_FINISHED.delta` and then drops the whole\n // step — signature included — when the accumulated content is empty\n // (`finalizeCurrentThinkingStep`); the OpenAI base emits `content` but\n // never `delta`, so without this the blob never reaches the\n // continuation message. The client `StreamProcessor` can't double-count\n // it: it short-circuits STEP_FINISHED content once\n // `hasSeenReasoningEvents` is set, which the REASONING_MESSAGE_CONTENT\n // events preceding every STEP_FINISHED here always set.\n yield {\n ...event,\n signature: captured.encryptedContent,\n delta: event.delta ?? event.content ?? '',\n }\n continue\n }\n yield event\n }\n }\n\n /**\n * Echoes a captured `encrypted_content` blob back on outgoing assistant\n * messages so multi-turn conversations replay it verbatim, as Ark's\n * thinking-summary docs require.\n *\n * The gate is `emitsEncryptedContent(this.model)` — the model being called\n * now, not the provenance of the history. That guarantees a signature is\n * never sent to a model that has no `encrypted_content` concept. It does\n * NOT identify who produced the signature: `ModelMessage` carries no\n * provider field, so a foreign signature (e.g. an Anthropic thinking\n * signature in replayed cross-provider history) WILL be forwarded when the\n * current model is a thinking-summary model. No shape guard is attempted —\n * the blob is opaque and Ark is the only party that can validate it.\n *\n * Absence is never an error: a live probe confirmed Ark accepts a turn whose\n * assistant message omits `encrypted_content`.\n */\n protected override convertMessage(\n message: ModelMessage,\n ): ChatCompletionMessageParam {\n const converted = super.convertMessage(message)\n if (converted.role !== 'assistant' || !emitsEncryptedContent(this.model)) {\n return converted\n }\n\n const encryptedContent = lastThinkingSignature(message)\n if (encryptedContent === undefined) return converted\n\n // Intersection rather than a cast: `encrypted_content` is an Ark-only\n // field with no slot on the OpenAI message param, and the intersection is\n // still assignable to `ChatCompletionMessageParam`.\n const withEncrypted: typeof converted & BytePlusEncryptedContentFields = {\n ...converted,\n encrypted_content: encryptedContent,\n }\n return withEncrypted\n }\n\n /**\n * Adds the Ark-only content parts on top of the base's text/image handling:\n * `video_url`, URL-addressed `input_audio`, and the extra `image_url`\n * fields (`detail: 'xhigh'`, `image_pixel_limit`).\n */\n protected override convertContentPart(\n part: ContentPart,\n ): ChatCompletionContentPart | null {\n if (part.type === 'image') {\n const metadata = part.metadata as BytePlusImageMetadata | undefined\n return asChatContentPart({\n type: 'image_url',\n image_url: {\n url: toUrlOrDataUri(part.source),\n detail: metadata?.detail ?? 'auto',\n ...(metadata?.image_pixel_limit && {\n image_pixel_limit: metadata.image_pixel_limit,\n }),\n },\n })\n }\n\n if (part.type === 'video') {\n const metadata = part.metadata as BytePlusVideoMetadata | undefined\n return asChatContentPart({\n type: 'video_url',\n video_url: {\n url: toUrlOrDataUri(part.source),\n ...(metadata?.fps !== undefined && { fps: metadata.fps }),\n },\n })\n }\n\n if (part.type === 'audio') {\n const metadata = part.metadata as BytePlusAudioMetadata | undefined\n // Ark takes audio either by URL or as inline base64 with an explicit\n // container format; unlike images there is no data-URI form.\n if (part.source.type === 'url') {\n return asChatContentPart({\n type: 'input_audio',\n input_audio: { url: part.source.value },\n })\n }\n const format = metadata?.format ?? audioFormatFromMimeType(part.source)\n if (format === undefined) {\n throw new Error(\n `Audio content part for ${this.name} has an unrecognised mimeType ` +\n `(${part.source.mimeType || 'none'}). Set the container format ` +\n `explicitly via the part's metadata.format, or supply a URL source.`,\n )\n }\n return asChatContentPart({\n type: 'input_audio',\n input_audio: { data: stripDataUriPrefix(part.source.value), format },\n })\n }\n\n return super.convertContentPart(part)\n }\n\n /**\n * Only the models in {@link BYTEPLUS_STRUCTURED_OUTPUT_CHAT_MODELS} accept\n * `response_format: json_schema`; the rest reject it with a 400.\n *\n * Returning `false` for a rejecting model does not make structured output\n * work — Ark has no `json_object` fallback to downgrade to. What it buys is\n * keeping `response_format` out of the request the engine would otherwise\n * build: with the hook false the engine takes its separate finalization\n * path, and the guard in {@link BytePlusTextAdapter.structuredOutput} /\n * {@link BytePlusTextAdapter.structuredOutputStream} stops that *before*\n * any HTTP call. So a `chat({ outputSchema })` on a rejecting model fails\n * loudly, named, without a schema Ark would 400 on ever leaving the\n * process — rather than 400-ing on every turn, or (worse) parsing prose as\n * if it were JSON.\n *\n * Tools without a schema are unaffected: `tools` alone never involves\n * `response_format`.\n */\n override supportsCombinedToolsAndSchema(): boolean {\n return supportsStructuredOutput(this.model)\n }\n\n override async structuredOutput(\n options: StructuredOutputOptions<TProviderOptions>,\n ): Promise<StructuredOutputResult<unknown>> {\n const unsupported = this.structuredOutputUnsupportedMessage()\n if (unsupported) {\n options.chatOptions.logger.errors(\n `${this.name}.structuredOutput unsupported model`,\n {\n error: { message: unsupported },\n source: `${this.name}.structuredOutput`,\n },\n )\n throw new Error(unsupported)\n }\n return await super.structuredOutput(options)\n }\n\n override async *structuredOutputStream(\n options: StructuredOutputOptions<TProviderOptions>,\n ): AsyncIterable<StreamChunk> {\n const unsupported = this.structuredOutputUnsupportedMessage()\n if (unsupported) {\n // Mirror the base's contract: failures inside structuredOutputStream\n // surface as a RUN_STARTED → RUN_ERROR pair rather than a throw, so\n // consumers keep a single error-handling path.\n const runId = generateId(this.name)\n yield {\n type: EventType.RUN_STARTED,\n runId,\n threadId: options.chatOptions.threadId ?? generateId(this.name),\n model: options.chatOptions.model,\n timestamp: Date.now(),\n parentRunId: options.chatOptions.parentRunId,\n }\n yield {\n type: EventType.RUN_ERROR,\n runId,\n model: options.chatOptions.model,\n timestamp: Date.now(),\n message: unsupported,\n code: 'unsupported-structured-output',\n error: { message: unsupported, code: 'unsupported-structured-output' },\n }\n options.chatOptions.logger.errors(\n `${this.name}.structuredOutputStream unsupported model`,\n {\n error: { message: unsupported },\n source: `${this.name}.structuredOutputStream`,\n },\n )\n return\n }\n yield* super.structuredOutputStream(options)\n }\n\n /**\n * Explains why structured output is unavailable, or `undefined` when the\n * model supports it. Ark rejects `response_format: json_object` on every\n * model, so there is no JSON-mode fallback to degrade to — failing loud\n * here beats a raw upstream 400.\n */\n private structuredOutputUnsupportedMessage(): string | undefined {\n if (supportsStructuredOutput(this.model)) return undefined\n return (\n `BytePlus model ${this.model} does not support structured output — Ark ` +\n `rejects both response_format json_schema and json_object on it. Use ` +\n `one of: ${BYTEPLUS_STRUCTURED_OUTPUT_CHAT_MODELS.join(', ')}.`\n )\n }\n}\n\n/**\n * Passes Ark's chunks through untouched while recording the single\n * `encrypted_content` blob a thinking-summary model emits.\n */\nasync function* captureEncryptedContent(\n stream: AsyncIterable<OpenAI.Chat.Completions.ChatCompletionChunk>,\n captured: { encryptedContent?: string },\n): AsyncIterable<OpenAI.Chat.Completions.ChatCompletionChunk> {\n for await (const chunk of stream) {\n const delta = chunk.choices[0]?.delta as\n | BytePlusStreamDeltaExtras\n | undefined\n const blob = delta?.encrypted_content\n if (typeof blob === 'string' && blob.length > 0) {\n captured.encryptedContent = blob\n }\n yield chunk\n }\n}\n\n/**\n * The blob to echo back for an assistant message: the last thinking step that\n * carries a signature.\n */\nfunction lastThinkingSignature(message: ModelMessage): string | undefined {\n const thinking = message.thinking\n if (!thinking) return undefined\n for (let i = thinking.length - 1; i >= 0; i--) {\n const signature = thinking[i]?.signature\n if (signature) return signature\n }\n return undefined\n}\n\n/**\n * The one place the Ark content-part dialect meets the OpenAI SDK's request\n * types.\n *\n * Ark's union is a superset of OpenAI's: `video_url` has no OpenAI arm at all,\n * `input_audio` additionally accepts a `url`, and `image_url` carries\n * `detail: 'xhigh'` and `image_pixel_limit`. `ChatCompletionContentPart` is a\n * closed type alias in the SDK, so no interface augmentation can admit those\n * arms and no narrowing can produce them — widening to `object` keeps this to\n * a single downcast rather than spreading one through each branch of\n * {@link BytePlusTextAdapter.convertContentPart}.\n */\nfunction asChatContentPart(\n part: BytePlusChatContentPart,\n): ChatCompletionContentPart {\n const arkPart: object = part\n return arkPart as ChatCompletionContentPart\n}\n\n/**\n * Renders a content source as the URL string Ark expects: URLs pass through,\n * inline base64 becomes a `data:` URI.\n */\nfunction toUrlOrDataUri(source: ContentPartSource): string {\n if (source.type !== 'data' || source.value.startsWith('data:')) {\n return source.value\n }\n // A missing mimeType would interpolate as \"data:undefined;base64,…\" and be\n // rejected, so fall back the same way the OpenAI base does.\n return `data:${source.mimeType || 'application/octet-stream'};base64,${source.value}`\n}\n\n/**\n * Strips a `data:` prefix so inline audio is sent as bare base64.\n */\nfunction stripDataUriPrefix(value: string): string {\n const comma = value.startsWith('data:') ? value.indexOf(',') : -1\n return comma === -1 ? value : value.slice(comma + 1)\n}\n\nconst AUDIO_FORMAT_BY_MIME_SUBTYPE: Record<\n string,\n NonNullable<BytePlusInputAudioContentPart['input_audio']['format']>\n> = {\n mpeg: 'mp3',\n mp3: 'mp3',\n wav: 'wav',\n 'x-wav': 'wav',\n wave: 'wav',\n ogg: 'ogg',\n flac: 'flac',\n 'x-flac': 'flac',\n mp4: 'm4a',\n m4a: 'm4a',\n 'x-m4a': 'm4a',\n aac: 'aac',\n pcm: 'pcm',\n l16: 'pcm',\n}\n\n/**\n * Maps an audio part's mimeType to Ark's container format token.\n */\nfunction audioFormatFromMimeType(\n source: ContentPartSource,\n):\n | NonNullable<BytePlusInputAudioContentPart['input_audio']['format']>\n | undefined {\n const mimeType = source.mimeType\n if (!mimeType) return undefined\n const subtype = mimeType.split(';')[0]?.split('/')[1]?.toLowerCase()\n return subtype ? AUDIO_FORMAT_BY_MIME_SUBTYPE[subtype] : undefined\n}\n\n/**\n * Creates a BytePlus text adapter with an explicit API key.\n *\n * @param model - The chat model id (e.g., `'seed-2-0-lite-260428'`)\n * @param apiKey - Your BytePlus Ark API key\n * @param config - Optional additional configuration\n *\n * @example\n * ```typescript\n * const adapter = createBytePlusText('seed-2-0-lite-260428', 'ark-...')\n * ```\n */\nexport function createBytePlusText<\n TModel extends (typeof BYTEPLUS_CHAT_MODELS)[number],\n>(\n model: TModel,\n apiKey: string,\n config?: Omit<BytePlusTextConfig, 'apiKey'>,\n): BytePlusTextAdapter<TModel> {\n return new BytePlusTextAdapter({ apiKey, ...config }, model)\n}\n\n/**\n * Creates a BytePlus text adapter with the API key read from `ARK_API_KEY`.\n *\n * @param model - The chat model id (e.g., `'seed-2-0-lite-260428'`)\n * @param config - Optional configuration (excluding `apiKey`)\n * @throws Error if `ARK_API_KEY` is not set\n *\n * @example\n * ```typescript\n * const adapter = byteplusText('seed-2-0-lite-260428')\n *\n * const stream = chat({\n * adapter,\n * messages: [{ role: 'user', content: 'Hello!' }],\n * })\n * ```\n */\nexport function byteplusText<\n TModel extends (typeof BYTEPLUS_CHAT_MODELS)[number],\n>(\n model: TModel,\n config?: Omit<BytePlusTextConfig, 'apiKey'>,\n): BytePlusTextAdapter<TModel> {\n const apiKey = getBytePlusArkApiKeyFromEnv()\n return createBytePlusText(model, apiKey, config)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmFA,IAAa,sBAAb,cAWU,qCAMR;CACA,OAAyB;CACzB,OAAyB;CAEzB,YAAY,QAA4B,OAAe;EACrD,MAAM,OAAO,YAAY,IAAI,OAAO,wBAAwB,MAAM,CAAC,CAAC;CACtE;;;;;;;CAQA,iBACE,OAC8B;EAI9B,MAAM,OAHQ,MAAM,QAAQ,EAAE,EAAE,MAAA,EAGb;EACnB,IAAI,OAAO,QAAQ,YAAY,IAAI,SAAS,GAC1C,OAAO,EAAE,MAAM,IAAI;CAGvB;;;;;;;;;;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AK;AACP;;;;AAKA,SAAS,wBACP,QAGY;CACZ,MAAM,WAAW,OAAO;CACxB,IAAI,CAAC,UAAU,OAAO,KAAA;CACtB,MAAM,UAAU,SAAS,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,YAAY;CACnE,OAAO,UAAU,6BAA6B,WAAW,KAAA;AAC3D;;;;;;;;;;;;;AAcA,SAAgB,mBAGd,OACA,QACA,QAC6B;CAC7B,OAAO,IAAI,oBAAoB;EAAE;EAAQ,GAAG;CAAO,GAAG,KAAK;AAC7D;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,aAGd,OACA,QAC6B;CAE7B,OAAO,mBAAmB,OADX,4BACkB,GAAQ,MAAM;AACjD"}
@@ -29,7 +29,8 @@ export interface BytePlusVideoConfig extends BytePlusArkConfig {
29
29
  * `seedance-1-0-pro-fast-251015` does not support it at all.
30
30
  * - `'reference'` / `'character'` → `reference_image`, video parts →
31
31
  * `reference_video`, audio parts → `reference_audio` — subject and style
32
- * references the model draws on (`r2v`, Seedance 2.0 family only).
32
+ * references the model draws on (`r2v`, Seedance 2.5 and 2.0 family).
33
+ * Seedance 2.5 also accepts audio-only reference input; 2.0 does not.
33
34
  *
34
35
  * Frame roles and reference roles cannot be combined in one request, so the
35
36
  * adapter rejects a mix up front rather than surfacing a raw 400.
@@ -1,6 +1,6 @@
1
1
  import { bytePlusArkError, bytePlusArkHeaders, bytePlusTimeoutSignal, getBytePlusArkApiKeyFromEnv, readJsonBody, toHeaderRecord, withBytePlusArkDefaults } from "../utils/client.js";
2
2
  import { getBytePlusVideoDurationOptions, isKnownBytePlusVideoModel } from "../model-meta.js";
3
- import { resolveBytePlusVideoResolution, resolveBytePlusVideoSize, supportsLastFrame, supportsReferenceMedia } from "../video/video-provider-options.js";
3
+ import { resolveBytePlusVideoResolution, resolveBytePlusVideoSize, supportsAudioOnlyReference, supportsLastFrame, supportsReferenceMedia } from "../video/video-provider-options.js";
4
4
  import { resolveMediaPrompt } from "@tanstack/ai";
5
5
  import { BaseVideoAdapter, snapToDurationOption } from "@tanstack/ai/adapters";
6
6
  import { toRunErrorPayload } from "@tanstack/ai/adapter-internals";
@@ -11,7 +11,7 @@ var TASKS_PATH = "/contents/generations/tasks";
11
11
  * `content.video_url` and `content.last_frame_url` are deleted 24 hours after
12
12
  * the task produces them.
13
13
  */
14
- var VIDEO_URL_TTL_MS = 1440 * 60 * 1e3;
14
+ var VIDEO_URL_TTL_MS = 864e5;
15
15
  /**
16
16
  * Converts a media prompt part into the URL string Seedance's `content[]`
17
17
  * takes: public URLs pass through (BytePlus fetches them server-side), data
@@ -87,7 +87,8 @@ function describeTaskFailure(task) {
87
87
  * `seedance-1-0-pro-fast-251015` does not support it at all.
88
88
  * - `'reference'` / `'character'` → `reference_image`, video parts →
89
89
  * `reference_video`, audio parts → `reference_audio` — subject and style
90
- * references the model draws on (`r2v`, Seedance 2.0 family only).
90
+ * references the model draws on (`r2v`, Seedance 2.5 and 2.0 family).
91
+ * Seedance 2.5 also accepts audio-only reference input; 2.0 does not.
91
92
  *
92
93
  * Frame roles and reference roles cannot be combined in one request, so the
93
94
  * adapter rejects a mix up front rather than surfacing a raw 400.
@@ -160,7 +161,7 @@ var BytePlusVideoAdapter = class extends BaseVideoAdapter {
160
161
  break;
161
162
  case "reference":
162
163
  case "character":
163
- if (gated && !supportsReferenceMedia(model)) throw new Error(`byteplus: ${model} does not support reference images. Reference media is available on the Seedance 2.0 family; on this model use 'start_frame' / 'end_frame' images instead.`);
164
+ if (gated && !supportsReferenceMedia(model)) throw new Error(`byteplus: ${model} does not support reference images. Reference media is available on Seedance 2.5 and the 2.0 family; on this model use 'start_frame' / 'end_frame' images instead.`);
164
165
  visualReferences++;
165
166
  content.push({
166
167
  type: "image_url",
@@ -176,11 +177,10 @@ var BytePlusVideoAdapter = class extends BaseVideoAdapter {
176
177
  image_url: { url: mediaPartToUrl(part) },
177
178
  role: "first_frame"
178
179
  });
179
- break;
180
180
  }
181
181
  }
182
182
  for (const part of resolved.videos) {
183
- if (gated && !supportsReferenceMedia(model)) throw new Error(`byteplus: ${model} does not accept video prompt parts. Reference video is available on the Seedance 2.0 family only.`);
183
+ if (gated && !supportsReferenceMedia(model)) throw new Error(`byteplus: ${model} does not accept video prompt parts. Reference video is available on Seedance 2.5 and the 2.0 family only.`);
184
184
  visualReferences++;
185
185
  content.push({
186
186
  type: "video_url",
@@ -189,7 +189,7 @@ var BytePlusVideoAdapter = class extends BaseVideoAdapter {
189
189
  });
190
190
  }
191
191
  for (const part of resolved.audios) {
192
- if (gated && !supportsReferenceMedia(model)) throw new Error(`byteplus: ${model} does not accept audio prompt parts. Reference audio is available on the Seedance 2.0 family only.`);
192
+ if (gated && !supportsReferenceMedia(model)) throw new Error(`byteplus: ${model} does not accept audio prompt parts. Reference audio is available on Seedance 2.5 and the 2.0 family only.`);
193
193
  audioReferences++;
194
194
  content.push({
195
195
  type: "audio_url",
@@ -202,7 +202,7 @@ var BytePlusVideoAdapter = class extends BaseVideoAdapter {
202
202
  if (gated && firstFrames > 1) throw new Error(`byteplus: ${model} accepts at most one opening frame; received ${firstFrames} un-roled or 'start_frame' images. Use metadata.role ('end_frame', 'reference') to disambiguate the others.`);
203
203
  if (gated && lastFrames > 1) throw new Error(`byteplus: ${model} accepts at most one closing frame; received ${lastFrames} 'end_frame' images.`);
204
204
  if (gated && lastFrames > 0 && firstFrames === 0) throw new Error(`byteplus: a closing frame needs an opening frame alongside it on model ${model}. Add a 'start_frame' image, or drop the 'end_frame' role.`);
205
- if (gated && audioReferences > 0 && visualReferences === 0) throw new Error(`byteplus: a reference audio input cannot be the only reference on model ${model}. Pair it with a reference image or video.`);
205
+ if (gated && audioReferences > 0 && visualReferences === 0 && !supportsAudioOnlyReference(model)) throw new Error(`byteplus: a reference audio input cannot be the only reference on model ${model}. Pair it with a reference image or video, or use Seedance 2.5 which accepts audio-only reference input.`);
206
206
  if (content.length === 0) throw new Error(`byteplus: a video prompt must carry text or at least one media input (model: ${model}).`);
207
207
  return content;
208
208
  }
@@ -1 +1 @@
1
- {"version":3,"file":"video.js","names":[],"sources":["../../../src/adapters/video.ts"],"sourcesContent":["import { resolveMediaPrompt } from '@tanstack/ai'\nimport { BaseVideoAdapter, snapToDurationOption } from '@tanstack/ai/adapters'\nimport { toRunErrorPayload } from '@tanstack/ai/adapter-internals'\nimport {\n bytePlusArkError,\n bytePlusArkHeaders,\n bytePlusTimeoutSignal,\n getBytePlusArkApiKeyFromEnv,\n readJsonBody,\n toHeaderRecord,\n withBytePlusArkDefaults,\n} from '../utils/client'\nimport {\n getBytePlusVideoDurationOptions,\n isKnownBytePlusVideoModel,\n} from '../model-meta'\nimport {\n resolveBytePlusVideoResolution,\n resolveBytePlusVideoSize,\n supportsLastFrame,\n supportsReferenceMedia,\n} from '../video/video-provider-options'\nimport type { DurationOptions } from '@tanstack/ai/adapters'\nimport type {\n AudioPart,\n ImagePart,\n MediaInputMetadata,\n TokenUsage,\n VideoGenerationOptions,\n VideoJobResult,\n VideoPart,\n VideoStatusResult,\n VideoUrlResult,\n} from '@tanstack/ai'\nimport type {\n BytePlusVideoContentPart,\n BytePlusVideoCreateRequest,\n BytePlusVideoCreateResponse,\n BytePlusVideoTask,\n BytePlusVideoTaskStatus,\n BytePlusVideoTaskUsage,\n} from '../video/wire-types'\nimport type { BytePlusVideoProviderOptions } from '../video/video-provider-options'\nimport type {\n BytePlusVideoModelOrString,\n ResolveBytePlusVideoInputModalities,\n ResolveBytePlusVideoSize,\n} from '../model-meta'\nimport type { BytePlusArkConfig } from '../utils/client'\n\n/**\n * Configuration for the BytePlus Seedance video adapter.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport interface BytePlusVideoConfig extends BytePlusArkConfig {}\n\n/** Path of the Seedance task API, relative to the Ark base URL. */\nconst TASKS_PATH = '/contents/generations/tasks'\n\n/**\n * `content.video_url` and `content.last_frame_url` are deleted 24 hours after\n * the task produces them.\n */\nconst VIDEO_URL_TTL_MS = 24 * 60 * 60 * 1000\n\n/**\n * Converts a media prompt part into the URL string Seedance's `content[]`\n * takes: public URLs pass through (BytePlus fetches them server-side), data\n * sources become base64 data URIs.\n */\nfunction mediaPartToUrl(\n part:\n | ImagePart<MediaInputMetadata>\n | VideoPart<MediaInputMetadata>\n | AudioPart<MediaInputMetadata>,\n): string {\n const { source } = part\n if (source.type === 'url') return source.value\n if (source.value.startsWith('data:')) return source.value\n return `data:${source.mimeType.toLowerCase()};base64,${source.value}`\n}\n\n/** Coerces a usage count that the API types as a string but sends as a number. */\nfunction toTokenCount(value: number | string | undefined): number | undefined {\n if (typeof value === 'number') return value\n if (typeof value === 'string') {\n const parsed = Number(value)\n return Number.isFinite(parsed) ? parsed : undefined\n }\n return undefined\n}\n\n/**\n * Maps a finished task's usage onto `TokenUsage`.\n *\n * Seedance bills output only — the API documents input tokens as always 0 and\n * `total_tokens` as equal to `completion_tokens` — so `promptTokens` is 0 and\n * the completion count doubles as `unitsBilled`.\n */\nfunction buildBytePlusVideoUsage(\n usage: BytePlusVideoTaskUsage | undefined,\n): TokenUsage | undefined {\n if (!usage) return undefined\n\n const completionTokens = toTokenCount(usage.completion_tokens)\n const totalTokens = toTokenCount(usage.total_tokens)\n if (completionTokens === undefined && totalTokens === undefined) {\n return undefined\n }\n\n const completion = completionTokens ?? totalTokens ?? 0\n return {\n promptTokens: 0,\n completionTokens: completion,\n totalTokens: totalTokens ?? completion,\n unitsBilled: completion,\n }\n}\n\n/**\n * Formats a terminal task's error detail for a status / failure message.\n *\n * Always returns a string. Core surfaces a failed job as\n * `throw new Error(statusResult.error || 'Video generation failed')`, so\n * returning `undefined` for a failure Ark reported without an `error` block\n * would hand the caller an unattributable error. The final fallback is a\n * snapshot of the identifying fields instead.\n */\nfunction describeTaskFailure(task: BytePlusVideoTask): string {\n const { code, message } = task.error ?? {}\n if (code && message) return `${code}: ${message}`\n if (message) return message\n if (code) return code\n // `expired` and `cancelled` are terminal without an `error` block.\n if (task.status === 'expired') {\n return 'Task expired before it finished (execution_expires_after elapsed).'\n }\n if (task.status === 'cancelled') return 'Task was cancelled.'\n return (\n `Task reported status \"${task.status ?? 'unknown'}\" with no error detail ` +\n `(id=${task.id ?? 'unknown'}, model=${task.model ?? 'unknown'}).`\n )\n}\n\n/**\n * BytePlus Seedance video generation adapter.\n *\n * Drives Ark's asynchronous task API — `POST /contents/generations/tasks` to\n * submit, `GET /contents/generations/tasks/{id}` to poll and to read the\n * finished video URL. Core owns the polling loop; this adapter implements the\n * three primitives plus the duration metadata.\n *\n * Prompt parts map onto Seedance's `content[]` roles, which the API sorts into\n * mutually exclusive task types:\n *\n * - `'start_frame'` (or a single un-roled image) → `first_frame` — the frame\n * the video opens on (`i2v`).\n * - `'end_frame'` → `last_frame` — the frame it closes on (`flf2v`); Seedance\n * requires a `first_frame` alongside it, and\n * `seedance-1-0-pro-fast-251015` does not support it at all.\n * - `'reference'` / `'character'` → `reference_image`, video parts →\n * `reference_video`, audio parts → `reference_audio` — subject and style\n * references the model draws on (`r2v`, Seedance 2.0 family only).\n *\n * Frame roles and reference roles cannot be combined in one request, so the\n * adapter rejects a mix up front rather than surfacing a raw 400.\n *\n * @experimental Video generation is an experimental feature and may change.\n *\n * @example\n * ```typescript\n * const adapter = byteplusVideo('seedance-1-0-pro-fast-251015')\n *\n * const { jobId } = await generateVideo({\n * adapter,\n * prompt: 'a guitar being played in a store',\n * size: '16:9_720p',\n * duration: 4,\n * modelOptions: { service_tier: 'flex' },\n * })\n * ```\n */\nexport class BytePlusVideoAdapter<\n TModel extends BytePlusVideoModelOrString,\n> extends BaseVideoAdapter<\n TModel,\n BytePlusVideoProviderOptions,\n Record<TModel, BytePlusVideoProviderOptions>,\n Record<TModel, ResolveBytePlusVideoSize<TModel>>,\n Record<TModel, ResolveBytePlusVideoInputModalities<TModel>>,\n Record<TModel, number>\n> {\n readonly name = 'byteplus' as const\n\n /** Config with the Ark base URL resolved and its trailing slashes trimmed. */\n private readonly clientConfig: Omit<BytePlusVideoConfig, 'baseURL'> & {\n baseURL: string\n }\n\n constructor(config: BytePlusVideoConfig, model: TModel) {\n super({}, model)\n this.clientConfig = withBytePlusArkDefaults(config)\n }\n\n private async request(\n path: string,\n init?: Omit<RequestInit, 'headers'>,\n ): Promise<{ response: Response; body: unknown }> {\n const fetchImpl = this.clientConfig.fetch ?? fetch\n const signal = bytePlusTimeoutSignal(this.clientConfig.timeout)\n const response = await fetchImpl(`${this.clientConfig.baseURL}${path}`, {\n ...init,\n ...(signal && { signal }),\n headers: bytePlusArkHeaders(\n this.clientConfig.apiKey,\n toHeaderRecord(this.clientConfig.defaultHeaders),\n ),\n })\n return { response, body: await readJsonBody(response) }\n }\n\n /**\n * Builds the `content[]` array from the resolved prompt, enforcing\n * Seedance's role vocabulary and mode exclusivity.\n */\n private buildContent(\n resolved: ReturnType<typeof resolveMediaPrompt>,\n ): Array<BytePlusVideoContentPart> {\n const model = this.model\n const content: Array<BytePlusVideoContentPart> = []\n if (resolved.text) content.push({ type: 'text', text: resolved.text })\n\n // Every rule below except the role vocabulary itself is a claim about a\n // *specific* model's capabilities, drawn from probing the six models that\n // exist today. None of it can be true of a model that does not exist yet,\n // so for an unknown id the guards stand down and Ark rules — otherwise the\n // escape hatch would block exactly the requests it exists to enable (see\n // BytePlusVideoModelOrString). 'mask' / 'control' still throw: Seedance's\n // wire format has no field to carry them on any model.\n const gated = isKnownBytePlusVideoModel(model)\n\n let firstFrames = 0\n let lastFrames = 0\n // Audio counts as a reference for the mode-exclusivity check but not for\n // the \"audio can't be the only reference\" rule, which wants a visual.\n let visualReferences = 0\n let audioReferences = 0\n\n for (const part of resolved.images) {\n const role = part.metadata?.role\n switch (role) {\n case 'mask':\n case 'control':\n throw new Error(\n `byteplus: Seedance has no '${role}' image input on model ${model}. ` +\n `Use 'start_frame', 'end_frame' or 'reference'.`,\n )\n case 'end_frame': {\n if (gated && !supportsLastFrame(model)) {\n throw new Error(\n `byteplus: ${model} does not support a closing frame — it does ` +\n `text-to-video and first-frame image-to-video only. Drop the ` +\n `'end_frame' image or switch to a model with first-and-last-frame support.`,\n )\n }\n lastFrames++\n content.push({\n type: 'image_url',\n image_url: { url: mediaPartToUrl(part) },\n role: 'last_frame',\n })\n break\n }\n case 'reference':\n case 'character': {\n if (gated && !supportsReferenceMedia(model)) {\n throw new Error(\n `byteplus: ${model} does not support reference images. Reference ` +\n `media is available on the Seedance 2.0 family; on this model use ` +\n `'start_frame' / 'end_frame' images instead.`,\n )\n }\n visualReferences++\n content.push({\n type: 'image_url',\n image_url: { url: mediaPartToUrl(part) },\n role: 'reference_image',\n })\n break\n }\n // An un-roled image is the opening frame, matching the API's own\n // default and the fal / Veo adapters' positional convention.\n case 'start_frame':\n case undefined: {\n firstFrames++\n content.push({\n type: 'image_url',\n image_url: { url: mediaPartToUrl(part) },\n role: 'first_frame',\n })\n break\n }\n }\n }\n\n // Video and audio parts only exist in reference mode: Seedance rejects an\n // un-roled video with \"reference media mode requires video role to be\n // reference_video\", and has no frame-style role for either modality.\n for (const part of resolved.videos) {\n if (gated && !supportsReferenceMedia(model)) {\n throw new Error(\n `byteplus: ${model} does not accept video prompt parts. Reference ` +\n `video is available on the Seedance 2.0 family only.`,\n )\n }\n visualReferences++\n content.push({\n type: 'video_url',\n video_url: { url: mediaPartToUrl(part) },\n role: 'reference_video',\n })\n }\n\n for (const part of resolved.audios) {\n if (gated && !supportsReferenceMedia(model)) {\n throw new Error(\n `byteplus: ${model} does not accept audio prompt parts. Reference ` +\n `audio is available on the Seedance 2.0 family only.`,\n )\n }\n audioReferences++\n content.push({\n type: 'audio_url',\n audio_url: { url: mediaPartToUrl(part) },\n role: 'reference_audio',\n })\n }\n\n const frames = firstFrames + lastFrames\n if (gated && frames > 0 && visualReferences + audioReferences > 0) {\n throw new Error(\n `byteplus: first/last frame inputs cannot be combined with reference ` +\n `media on model ${model}. Use either frame roles ('start_frame', ` +\n `'end_frame') or reference roles ('reference', 'character', video, ` +\n `audio) — not both.`,\n )\n }\n\n if (gated && firstFrames > 1) {\n throw new Error(\n `byteplus: ${model} accepts at most one opening frame; received ` +\n `${firstFrames} un-roled or 'start_frame' images. Use metadata.role ` +\n `('end_frame', 'reference') to disambiguate the others.`,\n )\n }\n\n if (gated && lastFrames > 1) {\n throw new Error(\n `byteplus: ${model} accepts at most one closing frame; received ` +\n `${lastFrames} 'end_frame' images.`,\n )\n }\n\n // Seedance treats a closing frame as the second half of first-and-last-\n // frame mode: on its own it fails with \"last frame image content cannot be\n // mixed with first frame or reference image content\".\n if (gated && lastFrames > 0 && firstFrames === 0) {\n throw new Error(\n `byteplus: a closing frame needs an opening frame alongside it on ` +\n `model ${model}. Add a 'start_frame' image, or drop the 'end_frame' role.`,\n )\n }\n\n if (gated && audioReferences > 0 && visualReferences === 0) {\n throw new Error(\n `byteplus: a reference audio input cannot be the only reference on ` +\n `model ${model}. Pair it with a reference image or video.`,\n )\n }\n\n if (content.length === 0) {\n throw new Error(\n `byteplus: a video prompt must carry text or at least one media input ` +\n `(model: ${model}).`,\n )\n }\n\n return content\n }\n\n async createVideoJob(\n options: VideoGenerationOptions<\n BytePlusVideoProviderOptions,\n ResolveBytePlusVideoSize<TModel>,\n number\n >,\n ): Promise<VideoJobResult> {\n const { size, modelOptions, logger } = options\n const model = this.model\n\n const content = this.buildContent(resolveMediaPrompt(options.prompt))\n\n // The generic `size` carries a \"ratio_resolution\" template and splits back\n // into Seedance's separate fields. Explicit modelOptions win below.\n const parsedSize =\n size !== undefined ? resolveBytePlusVideoSize(model, size) : undefined\n\n // Coerce the requested duration into the model's range rather than letting\n // the API reject it. `modelOptions.duration` is deliberately not snapped:\n // it is the escape hatch for `-1` (model picks the length).\n //\n // An unknown model's duration goes through verbatim. Snapping it would\n // mean clamping against the ranges today's models happen to have, so a\n // future model's legitimate 20-second request would silently become 15 —\n // corrupting the request instead of protecting it.\n const duration =\n options.duration !== undefined\n ? isKnownBytePlusVideoModel(model)\n ? this.snapDuration(options.duration)\n : options.duration\n : undefined\n\n const request: BytePlusVideoCreateRequest = {\n ...(parsedSize && {\n ratio: parsedSize.ratio,\n ...(parsedSize.resolution !== undefined && {\n resolution: parsedSize.resolution,\n }),\n }),\n ...(duration !== undefined && { duration }),\n // Explicit provider options win over everything derived above.\n ...modelOptions,\n model,\n content,\n }\n\n // Validate what actually ships, not just what `size` contributed: a\n // `modelOptions.resolution` overriding an already-checked size would\n // otherwise reach Ark unchecked.\n if (request.resolution !== undefined) {\n request.resolution = resolveBytePlusVideoResolution(\n model,\n request.resolution,\n )\n }\n\n try {\n logger.request(\n `activity=video.create provider=${this.name} model=${model} size=${size ?? 'default'} duration=${request.duration ?? 'default'}`,\n { provider: this.name, model },\n )\n\n const { response, body } = await this.request(TASKS_PATH, {\n method: 'POST',\n body: JSON.stringify(request),\n })\n if (!response.ok) {\n throw bytePlusArkError(response.status, body, 'video task creation')\n }\n\n const { id } = (body ?? {}) as BytePlusVideoCreateResponse\n if (!id) {\n throw new Error('byteplus: video task creation returned no task id.')\n }\n\n return { jobId: id, model }\n } catch (error: unknown) {\n logger.errors(`${this.name}.createVideoJob fatal`, {\n error: toRunErrorPayload(error, `${this.name}.createVideoJob failed`),\n source: `${this.name}.createVideoJob`,\n })\n throw error\n }\n }\n\n /**\n * Fetches a task, tagging the thrown error with the HTTP status.\n *\n * The 200 body is validated rather than cast. `readJsonBody` returns\n * `undefined` for an empty body and the raw text for a non-JSON one — both\n * documented failure modes of these hosts (an HTML error page from a proxy\n * in front of the API). Casting either to `BytePlusVideoTask` yields a task\n * whose `status` is `undefined`, which {@link mapStatus} would have to\n * interpret; the honest answer is that the response was not a task at all,\n * so say so while the body is still in hand.\n */\n private async retrieveTask(jobId: string): Promise<BytePlusVideoTask> {\n const { response, body } = await this.request(\n `${TASKS_PATH}/${encodeURIComponent(jobId)}`,\n )\n if (!response.ok) {\n const error = bytePlusArkError(response.status, body, 'video task lookup')\n ;(error as { status?: number }).status = response.status\n throw error\n }\n if (typeof body !== 'object' || body === null) {\n throw bytePlusArkError(\n response.status,\n body,\n `video task lookup (job ${jobId}) returned a non-object body`,\n )\n }\n return body as BytePlusVideoTask\n }\n\n async getVideoStatus(jobId: string): Promise<VideoStatusResult> {\n let task: BytePlusVideoTask\n try {\n task = await this.retrieveTask(jobId)\n } catch (error) {\n // A task record lives 7 days from creation; past that the id 404s. Keep\n // Ark's own code/message: a 404 from a wrong baseURL, a proxy, or a\n // region mismatch is not an expired job id, and collapsing them all to\n // \"Job not found\" sends the caller hunting the wrong thing.\n if ((error as { status?: number }).status === 404) {\n return {\n jobId,\n status: 'failed',\n error: `Job not found: ${jobId} (${(error as Error).message})`,\n }\n }\n throw error\n }\n\n const status = this.mapStatus(task.status)\n const failure = status === 'failed' ? describeTaskFailure(task) : undefined\n return {\n jobId,\n status,\n ...(failure !== undefined && { error: failure }),\n }\n }\n\n async getVideoUrl(jobId: string): Promise<VideoUrlResult> {\n let task: BytePlusVideoTask\n try {\n task = await this.retrieveTask(jobId)\n } catch (error) {\n // See getVideoStatus: Ark's detail distinguishes an expired id from a\n // misrouted request.\n if ((error as { status?: number }).status === 404) {\n throw new Error(\n `Video job not found: ${jobId} (${(error as Error).message})`,\n )\n }\n throw error\n }\n\n const status = this.mapStatus(task.status)\n if (status === 'failed') {\n throw new Error(\n `Video generation failed: ${describeTaskFailure(task)}. Job ID: ${jobId}`,\n )\n }\n\n const url = task.content?.video_url\n if (!url) {\n throw new Error(\n `Video is not ready for download. Check status first. Job ID: ${jobId}`,\n )\n }\n\n // The 24-hour window runs from when the output was produced, which is the\n // last status change on a succeeded task — `created_at` anchors the\n // separate 7-day retention of the task record itself, and can be far\n // earlier (a live `flex` task sat queued ~15 minutes). Corroborated by the\n // signed TOS link itself, which carries `X-Tos-Expires=86400` from an\n // `X-Tos-Date` matching `updated_at`. Fall back to `created_at` only when\n // `updated_at` is missing.\n const anchorSeconds = task.updated_at ?? task.created_at\n const expiresAt =\n anchorSeconds !== undefined\n ? new Date(anchorSeconds * 1000 + VIDEO_URL_TTL_MS)\n : undefined\n\n const usage = buildBytePlusVideoUsage(task.usage)\n return {\n jobId,\n url,\n ...(expiresAt && { expiresAt }),\n ...(usage && { usage }),\n }\n }\n\n /**\n * Maps Seedance task states onto the generic video status set. `expired`\n * (the task outlived `execution_expires_after`) and `cancelled` are\n * terminal non-successes, so both report as failed.\n *\n * An unrecognized state throws rather than defaulting to `processing`.\n * Core's poll loop treats `processing` as \"keep waiting\", so mapping an\n * unknown state — a missing `status`, or a terminal one Ark adds later such\n * as `rejected` — onto it means polling until `maxDuration` and then\n * reporting a generic timeout, with the state Ark actually sent never\n * reaching the caller. Failing here names it.\n */\n protected mapStatus(\n apiStatus: BytePlusVideoTaskStatus | string | undefined,\n ): VideoStatusResult['status'] {\n switch (apiStatus) {\n case 'queued':\n return 'pending'\n case 'running':\n return 'processing'\n case 'succeeded':\n return 'completed'\n case 'failed':\n case 'expired':\n case 'cancelled':\n return 'failed'\n case undefined:\n default:\n throw new Error(\n `byteplus: unrecognized Seedance task status ` +\n `${apiStatus === undefined ? '(missing)' : `\"${apiStatus}\"`}. ` +\n `Known states: queued, running, succeeded, failed, expired, cancelled.`,\n )\n }\n }\n\n /**\n * Seedance accepts any whole second inside a per-model range: 4–15s on the\n * 2.0 family, 4–12s on 1.5-pro, 2–12s on the 1.0 models. An unknown model\n * reports the union of those ranges as a UI hint — see\n * `BYTEPLUS_VIDEO_FALLBACK_DURATIONS`, which `createVideoJob` does not snap\n * against.\n */\n override availableDurations(): DurationOptions<number> {\n return getBytePlusVideoDurationOptions(this.model)\n }\n\n /**\n * Coerce a raw seconds value to the closest duration this model accepts\n * (clamped to its range and rounded to whole seconds).\n */\n override snapDuration(seconds: number): number | undefined {\n return snapToDurationOption(seconds, this.availableDurations())\n }\n}\n\n/**\n * Creates a BytePlus Seedance video adapter with an explicit API key.\n * Type resolution happens here at the call site.\n *\n * @experimental Video generation is an experimental feature and may change.\n *\n * @param model - The model name (e.g., 'seedance-1-0-pro-fast-251015')\n * @param apiKey - Your BytePlus Ark API key\n * @param config - Optional additional configuration\n * @returns Configured BytePlus video adapter instance with resolved types\n *\n * @example\n * ```typescript\n * const adapter = createBytePlusVideo('seedance-1-5-pro-251215', 'ark-...')\n *\n * const { jobId } = await generateVideo({\n * adapter,\n * prompt: 'a guitar being played in a store',\n * size: '16:9_1080p',\n * duration: 5,\n * })\n * ```\n */\nexport function createBytePlusVideo<TModel extends BytePlusVideoModelOrString>(\n model: TModel,\n apiKey: string,\n config?: Omit<BytePlusVideoConfig, 'apiKey'>,\n): BytePlusVideoAdapter<TModel> {\n return new BytePlusVideoAdapter({ apiKey, ...config }, model)\n}\n\n/**\n * Creates a BytePlus Seedance video adapter, reading `ARK_API_KEY` from the\n * environment. Type resolution happens here at the call site.\n *\n * Note that Ark keys are region-isolated and Seedance is only served from the\n * Asia-Pacific endpoint — an EU key will not work here.\n *\n * @experimental Video generation is an experimental feature and may change.\n *\n * @param model - The model name (e.g., 'dreamina-seedance-2-0-260128')\n * @param config - Optional configuration (excluding apiKey, auto-detected)\n * @returns Configured BytePlus video adapter instance with resolved types\n * @throws Error if ARK_API_KEY is not found in environment\n *\n * @example\n * ```typescript\n * const adapter = byteplusVideo('dreamina-seedance-2-0-260128')\n *\n * // Image-to-video: an un-roled image is the opening frame.\n * const { jobId } = await generateVideo({\n * adapter,\n * prompt: [\n * { type: 'text', content: 'the guitarist starts playing' },\n * { type: 'image', source: { type: 'url', value: 'https://example.com/shop.jpg' } },\n * ],\n * })\n *\n * const status = await getVideoJobStatus({ adapter, jobId })\n * ```\n *\n * ## Models this package does not know yet\n *\n * `model` also accepts any string, so a Seedance id BytePlus publishes after\n * this release works without upgrading. **Seedance 2.5 is the case this exists\n * for**: `dreamina-seedance-2-5-260628` is real and reachable, but its\n * capability cells could not be probed from this repo's account (Ark answers\n * 404 `ModelNotOpen` until the model is activated in the Ark Console), so it\n * is deliberately absent from the narrowed model tables. Passing it here works\n * for an account that has activated it.\n *\n * An unknown id relaxes both halves of the adapter: the `size` type widens to\n * any string, provider options are ungated, and the runtime guards that encode\n * per-model capabilities — resolution tiers, closing-frame and reference-media\n * support, frame cardinality and mode exclusivity, duration snapping — stand\n * down so Ark decides. Known ids are unaffected. See\n * {@link BytePlusVideoModelOrString} for how to discover and probe an id.\n *\n * @example\n * ```typescript\n * // Seedance 2.5, before this package ships probe-verified metadata for it:\n * const adapter = byteplusVideo('dreamina-seedance-2-5-260628')\n * ```\n */\nexport function byteplusVideo<TModel extends BytePlusVideoModelOrString>(\n model: TModel,\n config?: Omit<BytePlusVideoConfig, 'apiKey'>,\n): BytePlusVideoAdapter<TModel> {\n const apiKey = getBytePlusArkApiKeyFromEnv()\n return createBytePlusVideo(model, apiKey, config)\n}\n"],"mappings":";;;;;;;;AA0DA,IAAM,aAAa;;;;;AAMnB,IAAM,mBAAmB,OAAU,KAAK;;;;;;AAOxC,SAAS,eACP,MAIQ;CACR,MAAM,EAAE,WAAW;CACnB,IAAI,OAAO,SAAS,OAAO,OAAO,OAAO;CACzC,IAAI,OAAO,MAAM,WAAW,OAAO,GAAG,OAAO,OAAO;CACpD,OAAO,QAAQ,OAAO,SAAS,YAAY,EAAE,UAAU,OAAO;AAChE;;AAGA,SAAS,aAAa,OAAwD;CAC5E,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,OAAO,UAAU,UAAU;EAC7B,MAAM,SAAS,OAAO,KAAK;EAC3B,OAAO,OAAO,SAAS,MAAM,IAAI,SAAS,KAAA;CAC5C;AAEF;;;;;;;;AASA,SAAS,wBACP,OACwB;CACxB,IAAI,CAAC,OAAO,OAAO,KAAA;CAEnB,MAAM,mBAAmB,aAAa,MAAM,iBAAiB;CAC7D,MAAM,cAAc,aAAa,MAAM,YAAY;CACnD,IAAI,qBAAqB,KAAA,KAAa,gBAAgB,KAAA,GACpD;CAGF,MAAM,aAAa,oBAAoB,eAAe;CACtD,OAAO;EACL,cAAc;EACd,kBAAkB;EAClB,aAAa,eAAe;EAC5B,aAAa;CACf;AACF;;;;;;;;;;AAWA,SAAS,oBAAoB,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MAAM;AAClD"}
1
+ {"version":3,"file":"video.js","names":[],"sources":["../../../src/adapters/video.ts"],"sourcesContent":["import { resolveMediaPrompt } from '@tanstack/ai'\nimport { BaseVideoAdapter, snapToDurationOption } from '@tanstack/ai/adapters'\nimport { toRunErrorPayload } from '@tanstack/ai/adapter-internals'\nimport {\n bytePlusArkError,\n bytePlusArkHeaders,\n bytePlusTimeoutSignal,\n getBytePlusArkApiKeyFromEnv,\n readJsonBody,\n toHeaderRecord,\n withBytePlusArkDefaults,\n} from '../utils/client'\nimport {\n getBytePlusVideoDurationOptions,\n isKnownBytePlusVideoModel,\n} from '../model-meta'\nimport {\n resolveBytePlusVideoResolution,\n resolveBytePlusVideoSize,\n supportsAudioOnlyReference,\n supportsLastFrame,\n supportsReferenceMedia,\n} from '../video/video-provider-options'\nimport type { DurationOptions } from '@tanstack/ai/adapters'\nimport type {\n AudioPart,\n ImagePart,\n MediaInputMetadata,\n TokenUsage,\n VideoGenerationOptions,\n VideoJobResult,\n VideoPart,\n VideoStatusResult,\n VideoUrlResult,\n} from '@tanstack/ai'\nimport type {\n BytePlusVideoContentPart,\n BytePlusVideoCreateRequest,\n BytePlusVideoCreateResponse,\n BytePlusVideoTask,\n BytePlusVideoTaskStatus,\n BytePlusVideoTaskUsage,\n} from '../video/wire-types'\nimport type { BytePlusVideoProviderOptions } from '../video/video-provider-options'\nimport type {\n BytePlusVideoModelOrString,\n ResolveBytePlusVideoInputModalities,\n ResolveBytePlusVideoSize,\n} from '../model-meta'\nimport type { BytePlusArkConfig } from '../utils/client'\n\n/**\n * Configuration for the BytePlus Seedance video adapter.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport interface BytePlusVideoConfig extends BytePlusArkConfig {}\n\n/** Path of the Seedance task API, relative to the Ark base URL. */\nconst TASKS_PATH = '/contents/generations/tasks'\n\n/**\n * `content.video_url` and `content.last_frame_url` are deleted 24 hours after\n * the task produces them.\n */\nconst VIDEO_URL_TTL_MS = 24 * 60 * 60 * 1000\n\n/**\n * Converts a media prompt part into the URL string Seedance's `content[]`\n * takes: public URLs pass through (BytePlus fetches them server-side), data\n * sources become base64 data URIs.\n */\nfunction mediaPartToUrl(\n part:\n | ImagePart<MediaInputMetadata>\n | VideoPart<MediaInputMetadata>\n | AudioPart<MediaInputMetadata>,\n): string {\n const { source } = part\n if (source.type === 'url') return source.value\n if (source.value.startsWith('data:')) return source.value\n return `data:${source.mimeType.toLowerCase()};base64,${source.value}`\n}\n\n/** Coerces a usage count that the API types as a string but sends as a number. */\nfunction toTokenCount(value: number | string | undefined): number | undefined {\n if (typeof value === 'number') return value\n if (typeof value === 'string') {\n const parsed = Number(value)\n return Number.isFinite(parsed) ? parsed : undefined\n }\n return undefined\n}\n\n/**\n * Maps a finished task's usage onto `TokenUsage`.\n *\n * Seedance bills output only — the API documents input tokens as always 0 and\n * `total_tokens` as equal to `completion_tokens` — so `promptTokens` is 0 and\n * the completion count doubles as `unitsBilled`.\n */\nfunction buildBytePlusVideoUsage(\n usage: BytePlusVideoTaskUsage | undefined,\n): TokenUsage | undefined {\n if (!usage) return undefined\n\n const completionTokens = toTokenCount(usage.completion_tokens)\n const totalTokens = toTokenCount(usage.total_tokens)\n if (completionTokens === undefined && totalTokens === undefined) {\n return undefined\n }\n\n const completion = completionTokens ?? totalTokens ?? 0\n return {\n promptTokens: 0,\n completionTokens: completion,\n totalTokens: totalTokens ?? completion,\n unitsBilled: completion,\n }\n}\n\n/**\n * Formats a terminal task's error detail for a status / failure message.\n *\n * Always returns a string. Core surfaces a failed job as\n * `throw new Error(statusResult.error || 'Video generation failed')`, so\n * returning `undefined` for a failure Ark reported without an `error` block\n * would hand the caller an unattributable error. The final fallback is a\n * snapshot of the identifying fields instead.\n */\nfunction describeTaskFailure(task: BytePlusVideoTask): string {\n const { code, message } = task.error ?? {}\n if (code && message) return `${code}: ${message}`\n if (message) return message\n if (code) return code\n // `expired` and `cancelled` are terminal without an `error` block.\n if (task.status === 'expired') {\n return 'Task expired before it finished (execution_expires_after elapsed).'\n }\n if (task.status === 'cancelled') return 'Task was cancelled.'\n return (\n `Task reported status \"${task.status ?? 'unknown'}\" with no error detail ` +\n `(id=${task.id ?? 'unknown'}, model=${task.model ?? 'unknown'}).`\n )\n}\n\n/**\n * BytePlus Seedance video generation adapter.\n *\n * Drives Ark's asynchronous task API — `POST /contents/generations/tasks` to\n * submit, `GET /contents/generations/tasks/{id}` to poll and to read the\n * finished video URL. Core owns the polling loop; this adapter implements the\n * three primitives plus the duration metadata.\n *\n * Prompt parts map onto Seedance's `content[]` roles, which the API sorts into\n * mutually exclusive task types:\n *\n * - `'start_frame'` (or a single un-roled image) → `first_frame` — the frame\n * the video opens on (`i2v`).\n * - `'end_frame'` → `last_frame` — the frame it closes on (`flf2v`); Seedance\n * requires a `first_frame` alongside it, and\n * `seedance-1-0-pro-fast-251015` does not support it at all.\n * - `'reference'` / `'character'` → `reference_image`, video parts →\n * `reference_video`, audio parts → `reference_audio` — subject and style\n * references the model draws on (`r2v`, Seedance 2.5 and 2.0 family).\n * Seedance 2.5 also accepts audio-only reference input; 2.0 does not.\n *\n * Frame roles and reference roles cannot be combined in one request, so the\n * adapter rejects a mix up front rather than surfacing a raw 400.\n *\n * @experimental Video generation is an experimental feature and may change.\n *\n * @example\n * ```typescript\n * const adapter = byteplusVideo('seedance-1-0-pro-fast-251015')\n *\n * const { jobId } = await generateVideo({\n * adapter,\n * prompt: 'a guitar being played in a store',\n * size: '16:9_720p',\n * duration: 4,\n * modelOptions: { service_tier: 'flex' },\n * })\n * ```\n */\nexport class BytePlusVideoAdapter<\n TModel extends BytePlusVideoModelOrString,\n> extends BaseVideoAdapter<\n TModel,\n BytePlusVideoProviderOptions,\n Record<TModel, BytePlusVideoProviderOptions>,\n Record<TModel, ResolveBytePlusVideoSize<TModel>>,\n Record<TModel, ResolveBytePlusVideoInputModalities<TModel>>,\n Record<TModel, number>\n> {\n readonly name = 'byteplus' as const\n\n /** Config with the Ark base URL resolved and its trailing slashes trimmed. */\n private readonly clientConfig: Omit<BytePlusVideoConfig, 'baseURL'> & {\n baseURL: string\n }\n\n constructor(config: BytePlusVideoConfig, model: TModel) {\n super({}, model)\n this.clientConfig = withBytePlusArkDefaults(config)\n }\n\n private async request(\n path: string,\n init?: Omit<RequestInit, 'headers'>,\n ): Promise<{ response: Response; body: unknown }> {\n const fetchImpl = this.clientConfig.fetch ?? fetch\n const signal = bytePlusTimeoutSignal(this.clientConfig.timeout)\n const response = await fetchImpl(`${this.clientConfig.baseURL}${path}`, {\n ...init,\n ...(signal && { signal }),\n headers: bytePlusArkHeaders(\n this.clientConfig.apiKey,\n toHeaderRecord(this.clientConfig.defaultHeaders),\n ),\n })\n return { response, body: await readJsonBody(response) }\n }\n\n /**\n * Builds the `content[]` array from the resolved prompt, enforcing\n * Seedance's role vocabulary and mode exclusivity.\n */\n private buildContent(\n resolved: ReturnType<typeof resolveMediaPrompt>,\n ): Array<BytePlusVideoContentPart> {\n const model = this.model\n const content: Array<BytePlusVideoContentPart> = []\n if (resolved.text) content.push({ type: 'text', text: resolved.text })\n\n // Every rule below except the role vocabulary itself is a claim about a\n // *specific* model's capabilities, drawn from the known Seedance catalog.\n // None of it can be true of a model that does not exist yet, so for an\n // unknown id the guards stand down and Ark rules — otherwise the escape\n // hatch would block exactly the requests it exists to enable (see\n // BytePlusVideoModelOrString). 'mask' / 'control' still throw: Seedance's\n // wire format has no field to carry them on any model.\n const gated = isKnownBytePlusVideoModel(model)\n\n let firstFrames = 0\n let lastFrames = 0\n // Audio counts as a reference for the mode-exclusivity check. On Seedance\n // 2.0 it also needs a visual reference; 2.5 allows audio-only.\n let visualReferences = 0\n let audioReferences = 0\n\n for (const part of resolved.images) {\n const role = part.metadata?.role\n switch (role) {\n case 'mask':\n case 'control':\n throw new Error(\n `byteplus: Seedance has no '${role}' image input on model ${model}. ` +\n `Use 'start_frame', 'end_frame' or 'reference'.`,\n )\n case 'end_frame': {\n if (gated && !supportsLastFrame(model)) {\n throw new Error(\n `byteplus: ${model} does not support a closing frame — it does ` +\n `text-to-video and first-frame image-to-video only. Drop the ` +\n `'end_frame' image or switch to a model with first-and-last-frame support.`,\n )\n }\n lastFrames++\n content.push({\n type: 'image_url',\n image_url: { url: mediaPartToUrl(part) },\n role: 'last_frame',\n })\n break\n }\n case 'reference':\n case 'character': {\n if (gated && !supportsReferenceMedia(model)) {\n throw new Error(\n `byteplus: ${model} does not support reference images. Reference ` +\n `media is available on Seedance 2.5 and the 2.0 family; on this ` +\n `model use 'start_frame' / 'end_frame' images instead.`,\n )\n }\n visualReferences++\n content.push({\n type: 'image_url',\n image_url: { url: mediaPartToUrl(part) },\n role: 'reference_image',\n })\n break\n }\n // An un-roled image is the opening frame, matching the API's own\n // default and the fal / Veo adapters' positional convention.\n case 'start_frame':\n case undefined: {\n firstFrames++\n content.push({\n type: 'image_url',\n image_url: { url: mediaPartToUrl(part) },\n role: 'first_frame',\n })\n break\n }\n }\n }\n\n // Video and audio parts only exist in reference mode: Seedance rejects an\n // un-roled video with \"reference media mode requires video role to be\n // reference_video\", and has no frame-style role for either modality.\n for (const part of resolved.videos) {\n if (gated && !supportsReferenceMedia(model)) {\n throw new Error(\n `byteplus: ${model} does not accept video prompt parts. Reference ` +\n `video is available on Seedance 2.5 and the 2.0 family only.`,\n )\n }\n visualReferences++\n content.push({\n type: 'video_url',\n video_url: { url: mediaPartToUrl(part) },\n role: 'reference_video',\n })\n }\n\n for (const part of resolved.audios) {\n if (gated && !supportsReferenceMedia(model)) {\n throw new Error(\n `byteplus: ${model} does not accept audio prompt parts. Reference ` +\n `audio is available on Seedance 2.5 and the 2.0 family only.`,\n )\n }\n audioReferences++\n content.push({\n type: 'audio_url',\n audio_url: { url: mediaPartToUrl(part) },\n role: 'reference_audio',\n })\n }\n\n const frames = firstFrames + lastFrames\n if (gated && frames > 0 && visualReferences + audioReferences > 0) {\n throw new Error(\n `byteplus: first/last frame inputs cannot be combined with reference ` +\n `media on model ${model}. Use either frame roles ('start_frame', ` +\n `'end_frame') or reference roles ('reference', 'character', video, ` +\n `audio) — not both.`,\n )\n }\n\n if (gated && firstFrames > 1) {\n throw new Error(\n `byteplus: ${model} accepts at most one opening frame; received ` +\n `${firstFrames} un-roled or 'start_frame' images. Use metadata.role ` +\n `('end_frame', 'reference') to disambiguate the others.`,\n )\n }\n\n if (gated && lastFrames > 1) {\n throw new Error(\n `byteplus: ${model} accepts at most one closing frame; received ` +\n `${lastFrames} 'end_frame' images.`,\n )\n }\n\n // Seedance treats a closing frame as the second half of first-and-last-\n // frame mode: on its own it fails with \"last frame image content cannot be\n // mixed with first frame or reference image content\".\n if (gated && lastFrames > 0 && firstFrames === 0) {\n throw new Error(\n `byteplus: a closing frame needs an opening frame alongside it on ` +\n `model ${model}. Add a 'start_frame' image, or drop the 'end_frame' role.`,\n )\n }\n\n if (\n gated &&\n audioReferences > 0 &&\n visualReferences === 0 &&\n !supportsAudioOnlyReference(model)\n ) {\n throw new Error(\n `byteplus: a reference audio input cannot be the only reference on ` +\n `model ${model}. Pair it with a reference image or video, or use ` +\n `Seedance 2.5 which accepts audio-only reference input.`,\n )\n }\n\n if (content.length === 0) {\n throw new Error(\n `byteplus: a video prompt must carry text or at least one media input ` +\n `(model: ${model}).`,\n )\n }\n\n return content\n }\n\n async createVideoJob(\n options: VideoGenerationOptions<\n BytePlusVideoProviderOptions,\n ResolveBytePlusVideoSize<TModel>,\n number\n >,\n ): Promise<VideoJobResult> {\n const { size, modelOptions, logger } = options\n const model = this.model\n\n const content = this.buildContent(resolveMediaPrompt(options.prompt))\n\n // The generic `size` carries a \"ratio_resolution\" template and splits back\n // into Seedance's separate fields. Explicit modelOptions win below.\n const parsedSize =\n size !== undefined ? resolveBytePlusVideoSize(model, size) : undefined\n\n // Coerce the requested duration into the model's range rather than letting\n // the API reject it. `modelOptions.duration` is deliberately not snapped:\n // it is the escape hatch for `-1` (model picks the length).\n //\n // An unknown model's duration goes through verbatim. Snapping it would\n // mean clamping against the ranges today's models happen to have, so a\n // future model's legitimate 20-second request would silently become 15 —\n // corrupting the request instead of protecting it.\n const duration =\n options.duration !== undefined\n ? isKnownBytePlusVideoModel(model)\n ? this.snapDuration(options.duration)\n : options.duration\n : undefined\n\n const request: BytePlusVideoCreateRequest = {\n ...(parsedSize && {\n ratio: parsedSize.ratio,\n ...(parsedSize.resolution !== undefined && {\n resolution: parsedSize.resolution,\n }),\n }),\n ...(duration !== undefined && { duration }),\n // Explicit provider options win over everything derived above.\n ...modelOptions,\n model,\n content,\n }\n\n // Validate what actually ships, not just what `size` contributed: a\n // `modelOptions.resolution` overriding an already-checked size would\n // otherwise reach Ark unchecked.\n if (request.resolution !== undefined) {\n request.resolution = resolveBytePlusVideoResolution(\n model,\n request.resolution,\n )\n }\n\n try {\n logger.request(\n `activity=video.create provider=${this.name} model=${model} size=${size ?? 'default'} duration=${request.duration ?? 'default'}`,\n { provider: this.name, model },\n )\n\n const { response, body } = await this.request(TASKS_PATH, {\n method: 'POST',\n body: JSON.stringify(request),\n })\n if (!response.ok) {\n throw bytePlusArkError(response.status, body, 'video task creation')\n }\n\n const { id } = (body ?? {}) as BytePlusVideoCreateResponse\n if (!id) {\n throw new Error('byteplus: video task creation returned no task id.')\n }\n\n return { jobId: id, model }\n } catch (error: unknown) {\n logger.errors(`${this.name}.createVideoJob fatal`, {\n error: toRunErrorPayload(error, `${this.name}.createVideoJob failed`),\n source: `${this.name}.createVideoJob`,\n })\n throw error\n }\n }\n\n /**\n * Fetches a task, tagging the thrown error with the HTTP status.\n *\n * The 200 body is validated rather than cast. `readJsonBody` returns\n * `undefined` for an empty body and the raw text for a non-JSON one — both\n * documented failure modes of these hosts (an HTML error page from a proxy\n * in front of the API). Casting either to `BytePlusVideoTask` yields a task\n * whose `status` is `undefined`, which {@link mapStatus} would have to\n * interpret; the honest answer is that the response was not a task at all,\n * so say so while the body is still in hand.\n */\n private async retrieveTask(jobId: string): Promise<BytePlusVideoTask> {\n const { response, body } = await this.request(\n `${TASKS_PATH}/${encodeURIComponent(jobId)}`,\n )\n if (!response.ok) {\n const error = bytePlusArkError(response.status, body, 'video task lookup')\n ;(error as { status?: number }).status = response.status\n throw error\n }\n if (typeof body !== 'object' || body === null) {\n throw bytePlusArkError(\n response.status,\n body,\n `video task lookup (job ${jobId}) returned a non-object body`,\n )\n }\n return body as BytePlusVideoTask\n }\n\n async getVideoStatus(jobId: string): Promise<VideoStatusResult> {\n let task: BytePlusVideoTask\n try {\n task = await this.retrieveTask(jobId)\n } catch (error) {\n // A task record lives 7 days from creation; past that the id 404s. Keep\n // Ark's own code/message: a 404 from a wrong baseURL, a proxy, or a\n // region mismatch is not an expired job id, and collapsing them all to\n // \"Job not found\" sends the caller hunting the wrong thing.\n if ((error as { status?: number }).status === 404) {\n return {\n jobId,\n status: 'failed',\n error: `Job not found: ${jobId} (${(error as Error).message})`,\n }\n }\n throw error\n }\n\n const status = this.mapStatus(task.status)\n const failure = status === 'failed' ? describeTaskFailure(task) : undefined\n return {\n jobId,\n status,\n ...(failure !== undefined && { error: failure }),\n }\n }\n\n async getVideoUrl(jobId: string): Promise<VideoUrlResult> {\n let task: BytePlusVideoTask\n try {\n task = await this.retrieveTask(jobId)\n } catch (error) {\n // See getVideoStatus: Ark's detail distinguishes an expired id from a\n // misrouted request.\n if ((error as { status?: number }).status === 404) {\n throw new Error(\n `Video job not found: ${jobId} (${(error as Error).message})`,\n )\n }\n throw error\n }\n\n const status = this.mapStatus(task.status)\n if (status === 'failed') {\n throw new Error(\n `Video generation failed: ${describeTaskFailure(task)}. Job ID: ${jobId}`,\n )\n }\n\n const url = task.content?.video_url\n if (!url) {\n throw new Error(\n `Video is not ready for download. Check status first. Job ID: ${jobId}`,\n )\n }\n\n // The 24-hour window runs from when the output was produced, which is the\n // last status change on a succeeded task — `created_at` anchors the\n // separate 7-day retention of the task record itself, and can be far\n // earlier (a live `flex` task sat queued ~15 minutes). Corroborated by the\n // signed TOS link itself, which carries `X-Tos-Expires=86400` from an\n // `X-Tos-Date` matching `updated_at`. Fall back to `created_at` only when\n // `updated_at` is missing.\n const anchorSeconds = task.updated_at ?? task.created_at\n const expiresAt =\n anchorSeconds !== undefined\n ? new Date(anchorSeconds * 1000 + VIDEO_URL_TTL_MS)\n : undefined\n\n const usage = buildBytePlusVideoUsage(task.usage)\n return {\n jobId,\n url,\n ...(expiresAt && { expiresAt }),\n ...(usage && { usage }),\n }\n }\n\n /**\n * Maps Seedance task states onto the generic video status set. `expired`\n * (the task outlived `execution_expires_after`) and `cancelled` are\n * terminal non-successes, so both report as failed.\n *\n * An unrecognized state throws rather than defaulting to `processing`.\n * Core's poll loop treats `processing` as \"keep waiting\", so mapping an\n * unknown state — a missing `status`, or a terminal one Ark adds later such\n * as `rejected` — onto it means polling until `maxDuration` and then\n * reporting a generic timeout, with the state Ark actually sent never\n * reaching the caller. Failing here names it.\n */\n protected mapStatus(\n apiStatus: BytePlusVideoTaskStatus | string | undefined,\n ): VideoStatusResult['status'] {\n switch (apiStatus) {\n case 'queued':\n return 'pending'\n case 'running':\n return 'processing'\n case 'succeeded':\n return 'completed'\n case 'failed':\n case 'expired':\n case 'cancelled':\n return 'failed'\n case undefined:\n default:\n throw new Error(\n `byteplus: unrecognized Seedance task status ` +\n `${apiStatus === undefined ? '(missing)' : `\"${apiStatus}\"`}. ` +\n `Known states: queued, running, succeeded, failed, expired, cancelled.`,\n )\n }\n }\n\n /**\n * Seedance accepts any whole second inside a per-model range: 4–15s on the\n * 2.0 family, 4–12s on 1.5-pro, 2–12s on the 1.0 models. An unknown model\n * reports the union of those ranges as a UI hint — see\n * `BYTEPLUS_VIDEO_FALLBACK_DURATIONS`, which `createVideoJob` does not snap\n * against.\n */\n override availableDurations(): DurationOptions<number> {\n return getBytePlusVideoDurationOptions(this.model)\n }\n\n /**\n * Coerce a raw seconds value to the closest duration this model accepts\n * (clamped to its range and rounded to whole seconds).\n */\n override snapDuration(seconds: number): number | undefined {\n return snapToDurationOption(seconds, this.availableDurations())\n }\n}\n\n/**\n * Creates a BytePlus Seedance video adapter with an explicit API key.\n * Type resolution happens here at the call site.\n *\n * @experimental Video generation is an experimental feature and may change.\n *\n * @param model - The model name (e.g., 'seedance-1-0-pro-fast-251015')\n * @param apiKey - Your BytePlus Ark API key\n * @param config - Optional additional configuration\n * @returns Configured BytePlus video adapter instance with resolved types\n *\n * @example\n * ```typescript\n * const adapter = createBytePlusVideo('seedance-1-5-pro-251215', 'ark-...')\n *\n * const { jobId } = await generateVideo({\n * adapter,\n * prompt: 'a guitar being played in a store',\n * size: '16:9_1080p',\n * duration: 5,\n * })\n * ```\n */\nexport function createBytePlusVideo<TModel extends BytePlusVideoModelOrString>(\n model: TModel,\n apiKey: string,\n config?: Omit<BytePlusVideoConfig, 'apiKey'>,\n): BytePlusVideoAdapter<TModel> {\n return new BytePlusVideoAdapter({ apiKey, ...config }, model)\n}\n\n/**\n * Creates a BytePlus Seedance video adapter, reading `ARK_API_KEY` from the\n * environment. Type resolution happens here at the call site.\n *\n * Note that Ark keys are region-isolated and Seedance is only served from the\n * Asia-Pacific endpoint — an EU key will not work here.\n *\n * @experimental Video generation is an experimental feature and may change.\n *\n * @param model - The model name (e.g., 'dreamina-seedance-2-0-260128')\n * @param config - Optional configuration (excluding apiKey, auto-detected)\n * @returns Configured BytePlus video adapter instance with resolved types\n * @throws Error if ARK_API_KEY is not found in environment\n *\n * @example\n * ```typescript\n * const adapter = byteplusVideo('dreamina-seedance-2-0-260128')\n *\n * // Image-to-video: an un-roled image is the opening frame.\n * const { jobId } = await generateVideo({\n * adapter,\n * prompt: [\n * { type: 'text', content: 'the guitarist starts playing' },\n * { type: 'image', source: { type: 'url', value: 'https://example.com/shop.jpg' } },\n * ],\n * })\n *\n * const status = await getVideoJobStatus({ adapter, jobId })\n * ```\n *\n * ## Models this package does not know yet\n *\n * `model` also accepts any string, so a Seedance id BytePlus publishes after\n * this release works without upgrading. **Seedance 2.5 is the case this exists\n * for**: `dreamina-seedance-2-5-260628` is real and reachable, but its\n * capability cells could not be probed from this repo's account (Ark answers\n * 404 `ModelNotOpen` until the model is activated in the Ark Console), so it\n * is deliberately absent from the narrowed model tables. Passing it here works\n * for an account that has activated it.\n *\n * An unknown id relaxes both halves of the adapter: the `size` type widens to\n * any string, provider options are ungated, and the runtime guards that encode\n * per-model capabilities — resolution tiers, closing-frame and reference-media\n * support, frame cardinality and mode exclusivity, duration snapping — stand\n * down so Ark decides. Known ids are unaffected. See\n * {@link BytePlusVideoModelOrString} for how to discover and probe an id.\n *\n * @example\n * ```typescript\n * // Seedance 2.5, before this package ships probe-verified metadata for it:\n * const adapter = byteplusVideo('dreamina-seedance-2-5-260628')\n * ```\n */\nexport function byteplusVideo<TModel extends BytePlusVideoModelOrString>(\n model: TModel,\n config?: Omit<BytePlusVideoConfig, 'apiKey'>,\n): BytePlusVideoAdapter<TModel> {\n const apiKey = getBytePlusArkApiKeyFromEnv()\n return createBytePlusVideo(model, apiKey, config)\n}\n"],"mappings":";;;;;;;;AA2DA,IAAM,aAAa;;;;;AAMnB,IAAM,mBAAmB;;;;;;AAOzB,SAAS,eACP,MAIQ;CACR,MAAM,EAAE,WAAW;CACnB,IAAI,OAAO,SAAS,OAAO,OAAO,OAAO;CACzC,IAAI,OAAO,MAAM,WAAW,OAAO,GAAG,OAAO,OAAO;CACpD,OAAO,QAAQ,OAAO,SAAS,YAAY,EAAE,UAAU,OAAO;AAChE;;AAGA,SAAS,aAAa,OAAwD;CAC5E,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,OAAO,UAAU,UAAU;EAC7B,MAAM,SAAS,OAAO,KAAK;EAC3B,OAAO,OAAO,SAAS,MAAM,IAAI,SAAS,KAAA;CAC5C;AAEF;;;;;;;;AASA,SAAS,wBACP,OACwB;CACxB,IAAI,CAAC,OAAO,OAAO,KAAA;CAEnB,MAAM,mBAAmB,aAAa,MAAM,iBAAiB;CAC7D,MAAM,cAAc,aAAa,MAAM,YAAY;CACnD,IAAI,qBAAqB,KAAA,KAAa,gBAAgB,KAAA,GACpD;CAGF,MAAM,aAAa,oBAAoB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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,SAAgB,cACd,OACA,QAC8B;CAE9B,OAAO,oBAAoB,OADZ,4BACmB,GAAQ,MAAM;AAClD"}
@@ -1,7 +1,7 @@
1
1
  export { BytePlusVideoAdapter, byteplusVideo, createBytePlusVideo, } from './adapters/video.js';
2
2
  export type { BytePlusVideoConfig } from './adapters/video.js';
3
- export { parseBytePlusVideoSize, resolveBytePlusVideoResolution, resolveBytePlusVideoSize, supportsLastFrame, supportsReferenceMedia, } from './video/video-provider-options.js';
4
- export type { BytePlusVideoModelProviderOptionsByName, BytePlusVideoProviderOptions, BytePlusVideoServiceTier, } from './video/video-provider-options.js';
3
+ export { parseBytePlusVideoSize, resolveBytePlusVideoResolution, resolveBytePlusVideoSize, supportsAudioOnlyReference, supportsLastFrame, supportsReferenceMedia, } from './video/video-provider-options.js';
4
+ export type { BytePlusVideoModelProviderOptionsByName, BytePlusVideoOutputFormat, BytePlusVideoProviderOptions, BytePlusVideoServiceTier, } from './video/video-provider-options.js';
5
5
  export type { BytePlusVideoContentPart, BytePlusVideoContentRole, BytePlusVideoCreateRequest, BytePlusVideoCreateResponse, BytePlusVideoTask, BytePlusVideoTaskContent, BytePlusVideoTaskError, BytePlusVideoTaskListItem, BytePlusVideoTaskListResponse, BytePlusVideoTaskStatus, BytePlusVideoTaskUsage, } from './video/wire-types.js';
6
6
  export { BYTEPLUS_DEFAULT_TTS_SPEAKER, BYTEPLUS_TTS_MAX_OUTPUT_SECONDS, BytePlusTTSAdapter, byteplusSpeech, createBytePlusSpeech, toSpeechRate, } from './adapters/tts.js';
7
7
  export type { BytePlusTTSProviderOptions, BytePlusTTSResult, BytePlusTTSVoice, } from './audio/tts-provider-options.js';
package/dist/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { BYTEPLUS_ARK_BASE_URL, BYTEPLUS_VOICE_BASE_URL, bytePlusArkError, bytePlusArkHeaders, bytePlusVoiceError, bytePlusVoiceHeaders, getBytePlusArkApiKeyFromEnv, getBytePlusVoiceApiKeyFromEnv, withBytePlusArkDefaults, withBytePlusVoiceDefaults } from "./utils/client.js";
2
2
  import { BYTEPLUS_CHAT_MODELS, BYTEPLUS_IMAGE_MAX_REFERENCE_IMAGES, BYTEPLUS_IMAGE_MODELS, BYTEPLUS_STRUCTURED_OUTPUT_CHAT_MODELS, BYTEPLUS_THINKING_SUMMARY_MODELS, BYTEPLUS_TRANSCRIPTION_MODELS, BYTEPLUS_TTS_MODELS, BYTEPLUS_VIDEO_DURATIONS, BYTEPLUS_VIDEO_FALLBACK_DURATIONS, BYTEPLUS_VIDEO_MODELS, emitsEncryptedContent, getBytePlusVideoDurationOptions, isKnownBytePlusVideoModel, supportsStructuredOutput } from "./model-meta.js";
3
- import { parseBytePlusVideoSize, resolveBytePlusVideoResolution, resolveBytePlusVideoSize, supportsLastFrame, supportsReferenceMedia } from "./video/video-provider-options.js";
3
+ import { parseBytePlusVideoSize, resolveBytePlusVideoResolution, resolveBytePlusVideoSize, supportsAudioOnlyReference, supportsLastFrame, supportsReferenceMedia } from "./video/video-provider-options.js";
4
4
  import { BytePlusVideoAdapter, byteplusVideo, createBytePlusVideo } from "./adapters/video.js";
5
5
  import { BYTEPLUS_DEFAULT_TTS_SPEAKER, BYTEPLUS_TTS_MAX_OUTPUT_SECONDS, BytePlusTTSAdapter, byteplusSpeech, createBytePlusSpeech, toSpeechRate } from "./adapters/tts.js";
6
6
  import { BYTEPLUS_ASR_RESOURCE_HEADER, BYTEPLUS_ASR_RESOURCE_ID, BYTEPLUS_TTS_SAMPLE_RATES } from "./audio/wire-types.js";
@@ -8,4 +8,4 @@ import { BytePlusTranscriptionAdapter, byteplusTranscription, createBytePlusTran
8
8
  import { BYTEPLUS_IMAGE_MAX_PROMPT_WORDS, BYTEPLUS_IMAGE_MAX_SEQUENTIAL_IMAGES, BYTEPLUS_OUTPUT_FORMAT_IMAGE_MODELS, parseBytePlusImageSize } from "./image/image-provider-options.js";
9
9
  import { BytePlusImageAdapter, byteplusImage, createBytePlusImage } from "./adapters/image.js";
10
10
  import { BytePlusTextAdapter, byteplusText, createBytePlusText } from "./adapters/text.js";
11
- export { BYTEPLUS_ARK_BASE_URL, BYTEPLUS_ASR_RESOURCE_HEADER, BYTEPLUS_ASR_RESOURCE_ID, BYTEPLUS_CHAT_MODELS, BYTEPLUS_DEFAULT_TTS_SPEAKER, BYTEPLUS_IMAGE_MAX_PROMPT_WORDS, BYTEPLUS_IMAGE_MAX_REFERENCE_IMAGES, BYTEPLUS_IMAGE_MAX_SEQUENTIAL_IMAGES, BYTEPLUS_IMAGE_MODELS, BYTEPLUS_OUTPUT_FORMAT_IMAGE_MODELS, BYTEPLUS_STRUCTURED_OUTPUT_CHAT_MODELS, BYTEPLUS_THINKING_SUMMARY_MODELS, BYTEPLUS_TRANSCRIPTION_MODELS, BYTEPLUS_TTS_MAX_OUTPUT_SECONDS, BYTEPLUS_TTS_MODELS, BYTEPLUS_TTS_SAMPLE_RATES, BYTEPLUS_VIDEO_DURATIONS, BYTEPLUS_VIDEO_FALLBACK_DURATIONS, BYTEPLUS_VIDEO_MODELS, BYTEPLUS_VOICE_BASE_URL, BytePlusImageAdapter, BytePlusTTSAdapter, BytePlusTextAdapter, BytePlusTranscriptionAdapter, BytePlusVideoAdapter, bytePlusArkError, bytePlusArkHeaders, bytePlusVoiceError, bytePlusVoiceHeaders, byteplusImage, byteplusSpeech, byteplusText, byteplusTranscription, byteplusVideo, createBytePlusImage, createBytePlusSpeech, createBytePlusText, createBytePlusTranscription, createBytePlusVideo, emitsEncryptedContent, getBytePlusArkApiKeyFromEnv, getBytePlusVideoDurationOptions, getBytePlusVoiceApiKeyFromEnv, isKnownBytePlusVideoModel, parseBytePlusImageSize, parseBytePlusVideoSize, resolveBytePlusVideoResolution, resolveBytePlusVideoSize, supportsLastFrame, supportsReferenceMedia, supportsStructuredOutput, toSpeechRate, withBytePlusArkDefaults, withBytePlusVoiceDefaults };
11
+ export { BYTEPLUS_ARK_BASE_URL, BYTEPLUS_ASR_RESOURCE_HEADER, BYTEPLUS_ASR_RESOURCE_ID, BYTEPLUS_CHAT_MODELS, BYTEPLUS_DEFAULT_TTS_SPEAKER, BYTEPLUS_IMAGE_MAX_PROMPT_WORDS, BYTEPLUS_IMAGE_MAX_REFERENCE_IMAGES, BYTEPLUS_IMAGE_MAX_SEQUENTIAL_IMAGES, BYTEPLUS_IMAGE_MODELS, BYTEPLUS_OUTPUT_FORMAT_IMAGE_MODELS, BYTEPLUS_STRUCTURED_OUTPUT_CHAT_MODELS, BYTEPLUS_THINKING_SUMMARY_MODELS, BYTEPLUS_TRANSCRIPTION_MODELS, BYTEPLUS_TTS_MAX_OUTPUT_SECONDS, BYTEPLUS_TTS_MODELS, BYTEPLUS_TTS_SAMPLE_RATES, BYTEPLUS_VIDEO_DURATIONS, BYTEPLUS_VIDEO_FALLBACK_DURATIONS, BYTEPLUS_VIDEO_MODELS, BYTEPLUS_VOICE_BASE_URL, BytePlusImageAdapter, BytePlusTTSAdapter, BytePlusTextAdapter, BytePlusTranscriptionAdapter, BytePlusVideoAdapter, bytePlusArkError, bytePlusArkHeaders, bytePlusVoiceError, bytePlusVoiceHeaders, byteplusImage, byteplusSpeech, byteplusText, byteplusTranscription, byteplusVideo, createBytePlusImage, createBytePlusSpeech, createBytePlusText, createBytePlusTranscription, createBytePlusVideo, emitsEncryptedContent, getBytePlusArkApiKeyFromEnv, getBytePlusVideoDurationOptions, getBytePlusVoiceApiKeyFromEnv, isKnownBytePlusVideoModel, parseBytePlusImageSize, parseBytePlusVideoSize, resolveBytePlusVideoResolution, resolveBytePlusVideoSize, supportsAudioOnlyReference, supportsLastFrame, supportsReferenceMedia, supportsStructuredOutput, toSpeechRate, withBytePlusArkDefaults, withBytePlusVoiceDefaults };
@@ -336,10 +336,11 @@ export type BytePlusVideoRatio = '16:9' | '9:16' | '4:3' | '3:4' | '1:1' | '21:9
336
336
  /**
337
337
  * Resolution tiers accepted by the Seedance task API.
338
338
  *
339
- * All four are probe-verified per model (2026-07-31). Two findings contradict
340
- * the BytePlus prose docs: there is **no 2K tier on any Seedance model** —
341
- * `2k`/`2K` is rejected everywhere, including on the 2.0 flagship documented
342
- * as reaching 4K — and `4k` exists only on `dreamina-seedance-2-0-260128`.
339
+ * Resolution tiers are model-specific (see
340
+ * {@link BytePlusVideoModelResolutionByName}). Two findings that still
341
+ * contradict older BytePlus prose: there is **no 2K tier on any Seedance
342
+ * model**, and `4k` exists only on `dreamina-seedance-2-0-260128` (Seedance
343
+ * 2.5 is 480p/720p only, per the live ModelArk docs).
343
344
  *
344
345
  * The API matches this field case-insensitively (`4K`, `4k` and `1080P` are
345
346
  * all accepted), so this package standardizes on the lowercase spelling.
@@ -352,6 +353,13 @@ export type BytePlusVideoResolution = '480p' | '720p' | '1080p' | '4k';
352
353
  * template back apart.
353
354
  */
354
355
  export type BytePlusVideoSize<TResolution extends BytePlusVideoResolution = BytePlusVideoResolution> = BytePlusVideoRatio | `${BytePlusVideoRatio}_${TResolution}`;
356
+ declare const DREAMINA_SEEDANCE_2_5: {
357
+ readonly name: "dreamina-seedance-2-5-260628";
358
+ readonly supports: {
359
+ readonly input: readonly ["text", "image", "video", "audio"];
360
+ readonly output: readonly ["video", "audio"];
361
+ };
362
+ };
355
363
  declare const DREAMINA_SEEDANCE_2_0: {
356
364
  readonly name: "dreamina-seedance-2-0-260128";
357
365
  readonly supports: {
@@ -397,18 +405,19 @@ declare const SEEDANCE_1_0_PRO_FAST: {
397
405
  /**
398
406
  * All supported Seedance video model identifiers.
399
407
  */
400
- export declare const BYTEPLUS_VIDEO_MODELS: readonly ["dreamina-seedance-2-0-260128", "dreamina-seedance-2-0-fast-260128", "dreamina-seedance-2-0-mini-260615", "seedance-1-5-pro-251215", "seedance-1-0-pro-250528", "seedance-1-0-pro-fast-251015"];
408
+ export declare const BYTEPLUS_VIDEO_MODELS: readonly ["dreamina-seedance-2-5-260628", "dreamina-seedance-2-0-260128", "dreamina-seedance-2-0-fast-260128", "dreamina-seedance-2-0-mini-260615", "seedance-1-5-pro-251215", "seedance-1-0-pro-250528", "seedance-1-0-pro-fast-251015"];
401
409
  /**
402
410
  * Union of all supported Seedance video model names.
403
411
  */
404
412
  export type BytePlusVideoModel = (typeof BYTEPLUS_VIDEO_MODELS)[number];
405
413
  /**
406
414
  * Type-only map from video model name to the non-text prompt modalities it
407
- * accepts. The Seedance 2.0 family takes multimodal references (start/end
408
- * frames, reference images, reference video and audio); the 1.x models take
409
- * start/end frames only.
415
+ * accepts. Seedance 2.5 and the 2.0 family take multimodal references
416
+ * (start/end frames, reference images, reference video and audio); the 1.x
417
+ * models take start/end frames only.
410
418
  */
411
419
  export type BytePlusVideoModelInputModalitiesByName = {
420
+ [DREAMINA_SEEDANCE_2_5.name]: readonly ['image', 'video', 'audio'];
412
421
  [DREAMINA_SEEDANCE_2_0.name]: readonly ['image', 'video', 'audio'];
413
422
  [DREAMINA_SEEDANCE_2_0_FAST.name]: readonly ['image', 'video', 'audio'];
414
423
  [DREAMINA_SEEDANCE_2_0_MINI.name]: readonly ['image', 'video', 'audio'];
@@ -419,10 +428,13 @@ export type BytePlusVideoModelInputModalitiesByName = {
419
428
  /**
420
429
  * Type-only map from video model name to the resolutions it accepts.
421
430
  *
422
- * Probe-verified per model on 2026-07-31. Note `seedance-1-0-pro-fast-251015`
423
- * does accept `1080p`, despite the BytePlus docs listing it as 480p/720p.
431
+ * 2.0 / 1.x cells were probe-verified on 2026-07-31; 2.5 comes from the
432
+ * public ModelArk create-task docs (2026-08-07). Note
433
+ * `seedance-1-0-pro-fast-251015` does accept `1080p`, despite older BytePlus
434
+ * prose listing it as 480p/720p.
424
435
  */
425
436
  export type BytePlusVideoModelResolutionByName = {
437
+ [DREAMINA_SEEDANCE_2_5.name]: '480p' | '720p';
426
438
  [DREAMINA_SEEDANCE_2_0.name]: '480p' | '720p' | '1080p' | '4k';
427
439
  [DREAMINA_SEEDANCE_2_0_FAST.name]: '480p' | '720p';
428
440
  [DREAMINA_SEEDANCE_2_0_MINI.name]: '480p' | '720p';
@@ -440,24 +452,16 @@ export type BytePlusVideoModelSizeByName = {
440
452
  * A Seedance model id: one this package knows, or any other string.
441
453
  *
442
454
  * The open half is a deliberate escape hatch for models BytePlus ships between
443
- * releases of this package. **Seedance 2.5 is the live example.** Its real id
444
- * is `dreamina-seedance-2-5-260628` — note the June date suffix, which is why
445
- * guessing ids around its 2026-07-31 announcement never landed. It is absent
446
- * from the table below because its capability cells are unverified, not
447
- * because it is unreachable: probing it returns 404 `ModelNotOpen` ("your
448
- * account has not activated the model"), so no capability question can be
449
- * answered until someone enables it in the Ark Console. Passing it through
450
- * the escape hatch works today for an account that has.
451
- *
452
- * Adding a model here *narrows* it — the adapter's guards switch on and reject
453
- * against this file's tables. For a model whose real limits are unknown that
454
- * is strictly worse than the open path, which lets Ark judge. So an id lands
455
- * here only once probed.
455
+ * releases of this package. Adding a model to {@link BYTEPLUS_VIDEO_MODELS}
456
+ * *narrows* it — the adapter's guards switch on and reject against this
457
+ * file's tables. For a model whose real limits are unknown that is strictly
458
+ * worse than the open path, which lets Ark judge. So an id lands in the
459
+ * known table only once its capability cells are documented or probed.
456
460
  *
457
461
  * Discovering ids: `GET /models` on the Ark data plane enumerates the catalog
458
- * (id, `task_type`, `modalities`, `status`) and is how 2.5 was found. It is
459
- * not exhaustive — `seedream-5-0-lite-260128` answers requests but is missing
460
- * from the listing — so absence there is not evidence of absence. The ModelArk
462
+ * (id, `task_type`, `modalities`, `status`). It is not exhaustive —
463
+ * `seedream-5-0-lite-260128` answers requests but is missing from the
464
+ * listing — so absence there is not evidence of absence. The ModelArk
461
465
  * release notes (https://docs.byteplus.com/en/docs/ModelArk/1159178) are the
462
466
  * other watch surface.
463
467
  *
@@ -470,7 +474,7 @@ export type BytePlusVideoModelSizeByName = {
470
474
  * Unknown ids trade compile-time narrowing for reach: the full size surface is
471
475
  * accepted, provider options are ungated, and the adapter's model-specific
472
476
  * runtime guards stand down so a new model's legitimate request reaches Ark.
473
- * Known ids keep their probe-verified narrowing.
477
+ * Known ids keep their documented / probe-verified narrowing.
474
478
  */
475
479
  export type BytePlusVideoModelOrString = BytePlusVideoModel | (string & {});
476
480
  /**
@@ -497,8 +501,8 @@ export declare function isKnownBytePlusVideoModel(model: string): model is ByteP
497
501
  * Per-model duration type. Seedance accepts any integer second inside the
498
502
  * model's range, so this is a continuous range expressed as `number` — a
499
503
  * literal union cannot represent it. (The API also accepts `duration: -1` on
500
- * Seedance 2.0 and 1.5-pro to let the model choose; that is reachable through
501
- * provider options, not through the generic `duration`.)
504
+ * Seedance 2.5, 2.0 and 1.5-pro to let the model choose; that is reachable
505
+ * through provider options, not through the generic `duration`.)
502
506
  */
503
507
  export type BytePlusVideoModelDurationByName = {
504
508
  [K in BytePlusVideoModel]: number;
@@ -513,10 +517,10 @@ export declare const BYTEPLUS_VIDEO_DURATIONS: {
513
517
  * Duration hint for a model this package has no table for.
514
518
  *
515
519
  * Spans every range Seedance has shipped so far (2s on the 1.0 models through
516
- * 15s on the 2.0 family) so `availableDurations()` can still drive a UI. It is
520
+ * 30s on Seedance 2.5) so `availableDurations()` can still drive a UI. It is
517
521
  * a hint, not a contract: the adapter does **not** snap an unknown model's
518
- * duration against it, because clamping a future model's legitimate 20-second
519
- * request down to 15 would corrupt the request rather than protect it.
522
+ * duration against it, because clamping a future model's legitimate longer
523
+ * request down to 30 would corrupt the request rather than protect it.
520
524
  */
521
525
  export declare const BYTEPLUS_VIDEO_FALLBACK_DURATIONS: DurationOptions<number>;
522
526
  /**