Open History to see the last commit
1/**
2 * Per-model Seedance `duration` bounds.
3 *
4 * The create schema publishes one integer for every model. The limits live
5 * in that field's description ("2-12s on 1.0, 4-12s on 1.5-pro, 4-15s on
6 * 2.0, 4-30s on 2.5"). `-1` lets the model choose on 2.5, 2.5 flash, every
7 * 2.0 id (base, fast, and mini), and 1.5-pro. The capabilities table on
8 * {@link SEEDANCE_DURATION_DOCS} states those rows. 1.0 does not accept
9 * `-1`.
10 *
11 * `?activity=video` copies the shared request once per listed model and
12 * writes these bounds onto `duration`, tagged `x-modelschemas-model`. A
13 * listed id with no row here keeps the stored `duration` and stays its own
14 * branch, so the `anyOf` does not reject it. The poll reports that id.
15 */
16
17/** Capabilities overview. Output duration column, read 2026-11-16. */
18export const SEEDANCE_DURATION_DOCS =
19 'https://ai.byteplus.com/ark/region:ap-southeast-1/docs/seedance-2-5'
20
21export interface SeedanceDuration {
22 min: number
23 max: number
24 /** The create call accepts -1, and the model chooses the length. */
25 auto: boolean
26}
27
28export const SEEDANCE_DURATIONS: Record<string, SeedanceDuration> = {
29 'dreamina-seedance-2-5-260628': { min: 4, max: 30, auto: true },
30 'dreamina-seedance-2-5-flash-261115': { min: 4, max: 30, auto: true },
31 'dreamina-seedance-2-0-260128': { min: 4, max: 15, auto: true },
32 'dreamina-seedance-2-0-fast-260128': { min: 4, max: 15, auto: true },
33 'dreamina-seedance-2-0-mini-260615': { min: 4, max: 15, auto: true },
34 'seedance-1-5-pro-251215': { min: 4, max: 12, auto: true },
35 'seedance-1-0-pro-250528': { min: 2, max: 12, auto: false },
36 'seedance-1-0-pro-fast-251015': { min: 2, max: 12, auto: false },
37}
38
39const CREATE_PATH = '/contents/generations/tasks'
40
41function isObject(value: unknown): value is Record<string, unknown> {
42 return typeof value === 'object' && value !== null && !Array.isArray(value)
43}
44
45/** Copy `base`, then `patch`. A string index signature cannot be spread. */
46function overlay(
47 base: Record<string, unknown>,
48 patch: Record<string, unknown>,
49): Record<string, unknown> {
50 return Object.fromEntries([...Object.entries(base), ...Object.entries(patch)])
51}
52
53/** `duration` for one model: a bounded integer, plus `-1` where allowed. */
54export function seedanceDurationSchema(
55 bounds: SeedanceDuration,
56): Record<string, unknown> {
57 const ranged: Record<string, unknown> = {
58 type: 'integer',
59 minimum: bounds.min,
60 maximum: bounds.max,
61 description: `Whole seconds of output, from ${String(bounds.min)} to ${String(bounds.max)}.`,
62 }
63 if (!bounds.auto) return ranged
64 return {
65 description: `Whole seconds of output, from ${String(bounds.min)} to ${String(bounds.max)}. -1 lets the model choose the length.`,
66 anyOf: [
67 ranged,
68 {
69 type: 'integer',
70 const: -1,
71 description: 'Let the model choose the length.',
72 },
73 ],
74 }
75}
76
77/**
78 * Listed video ids with no {@link SEEDANCE_DURATIONS} row, in order, once
79 * each. The poll names these; the create document still accepts them.
80 */
81export function uncoveredSeedanceIds(
82 rawIds: ReadonlyArray<string>,
83): Array<string> {
84 const missing: Array<string> = []
85 const seen = new Set<string>()
86 for (const rawId of rawIds) {
87 if (seen.has(rawId) || Object.hasOwn(SEEDANCE_DURATIONS, rawId)) continue
88 seen.add(rawId)
89 missing.push(rawId)
90 }
91 return missing
92}
93
94/**
95 * One create-request schema per listed model. Ids in
96 * {@link SEEDANCE_DURATIONS} get that row's bounds. Any other listed id
97 * keeps the stored `duration` and still pins `model`, so a request for it
98 * stays valid. Undefined when this operation is not the shared video create
99 * call, or when `rawIds` is empty.
100 */
101export function seedanceActivityRequests(input: {
102 path: string
103 method: string
104 schema: unknown
105 rawIds: Array<string>
106}): Array<{ rawId: string; schema: unknown }> | undefined {
107 if (input.method !== 'POST' || input.path !== CREATE_PATH) return undefined
108 const schema = input.schema
109 if (!isObject(schema)) return undefined
110 const properties = schema.properties
111 if (!isObject(properties)) return undefined
112 const model = isObject(properties.model)
113 ? properties.model
114 : { type: 'string' }
115 const listed = new Set(input.rawIds)
116 const pin = (
117 rawId: string,
118 duration?: Record<string, unknown>,
119 ): Record<string, unknown> =>
120 overlay(schema, {
121 properties: overlay(properties, {
122 model: overlay(model, { enum: [rawId] }),
123 ...(duration ? { duration } : {}),
124 }),
125 })
126 const variants: Array<{ rawId: string; schema: unknown }> = []
127 for (const rawId of Object.keys(SEEDANCE_DURATIONS)) {
128 if (!listed.has(rawId)) continue
129 const bounds = SEEDANCE_DURATIONS[rawId]
130 if (!bounds) continue
131 variants.push({ rawId, schema: pin(rawId, seedanceDurationSchema(bounds)) })
132 }
133 for (const rawId of uncoveredSeedanceIds(input.rawIds)) {
134 variants.push({ rawId, schema: pin(rawId) })
135 }
136 return variants.length > 0 ? variants : undefined
137}