feat: add Seedance 2.0 models

This commit is contained in:
saturn
2026-04-02 19:16:00 +08:00
parent 9703714b69
commit 71ef6ff818
21 changed files with 811 additions and 38 deletions

View File

@@ -393,11 +393,32 @@ const DIRECT_CASES: ReadonlyArray<DirectRouteCase> = [
},
{
routeFile: 'src/app/api/novel-promotion/[projectId]/generate-video/route.ts',
body: { videoModel: 'fal::video-model', storyboardId: 'storyboard-1', panelIndex: 0 },
body: {
videoModel: 'ark::doubao-seedance-2-0-260128',
storyboardId: 'storyboard-1',
panelIndex: 0,
generationOptions: {
resolution: '720p',
duration: 5,
},
firstLastFrame: {
flModel: 'ark::doubao-seedance-2-0-260128',
},
},
params: { projectId: 'project-1' },
expectedTaskType: TASK_TYPE.VIDEO_PANEL,
expectedTargetType: 'NovelPromotionPanel',
expectedProjectId: 'project-1',
expectedPayloadSubset: {
videoModel: 'ark::doubao-seedance-2-0-260128',
generationOptions: {
resolution: '720p',
duration: 5,
},
firstLastFrame: {
flModel: 'ark::doubao-seedance-2-0-260128',
},
},
},
{
routeFile: 'src/app/api/novel-promotion/[projectId]/insert-panel/route.ts',

View File

@@ -0,0 +1,105 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { arkCreateVideoTask } from '@/lib/ark-api'
import { querySeedanceVideoStatus } from '@/lib/async-task-utils'
describe('provider contract - ark seedance', () => {
beforeEach(() => {
vi.clearAllMocks()
})
afterEach(() => {
vi.unstubAllGlobals()
})
it('submits Seedance 2.0 multimodal create payload with official request fields', async () => {
const fetchMock = vi.fn(async () => new Response(JSON.stringify({ id: 'cgt-task-1' }), {
status: 200,
headers: { 'Content-Type': 'application/json' },
}))
vi.stubGlobal('fetch', fetchMock as unknown as typeof fetch)
const result = await arkCreateVideoTask({
model: 'doubao-seedance-2-0-260128',
content: [
{ type: 'text', text: 'reference 视频1 的运镜参考音频1 的节奏' },
{ type: 'image_url', image_url: { url: 'https://example.com/first.png' }, role: 'reference_image' },
{ type: 'video_url', video_url: { url: 'https://example.com/ref.mp4' }, role: 'reference_video' },
{ type: 'audio_url', audio_url: { url: 'https://example.com/ref.mp3' }, role: 'reference_audio' },
],
resolution: '720p',
ratio: '16:9',
duration: 15,
generate_audio: true,
watermark: true,
tools: [{ type: 'web_search' }],
}, {
apiKey: 'ark-key',
maxRetries: 1,
timeoutMs: 1000,
logPrefix: '[Ark Test]',
})
expect(result.id).toBe('cgt-task-1')
expect(fetchMock).toHaveBeenCalledTimes(1)
const firstCall = fetchMock.mock.calls[0]
expect(firstCall).toBeTruthy()
const [url, init] = firstCall as unknown as [string, RequestInit]
expect(url).toBe('https://ark.cn-beijing.volces.com/api/v3/contents/generations/tasks')
expect(init.method).toBe('POST')
expect(init.headers).toEqual({
'Content-Type': 'application/json',
'Authorization': 'Bearer ark-key',
})
expect(JSON.parse(String(init.body))).toEqual({
model: 'doubao-seedance-2-0-260128',
content: [
{ type: 'text', text: 'reference 视频1 的运镜参考音频1 的节奏' },
{ type: 'image_url', image_url: { url: 'https://example.com/first.png' }, role: 'reference_image' },
{ type: 'video_url', video_url: { url: 'https://example.com/ref.mp4' }, role: 'reference_video' },
{ type: 'audio_url', audio_url: { url: 'https://example.com/ref.mp3' }, role: 'reference_audio' },
],
resolution: '720p',
ratio: '16:9',
duration: 15,
generate_audio: true,
watermark: true,
tools: [{ type: 'web_search' }],
})
})
it('reads Ark task usage.total_tokens from status query', async () => {
const fetchMock = vi.fn(async () => new Response(JSON.stringify({
status: 'succeeded',
content: {
video_url: 'https://example.com/result.mp4',
},
usage: {
total_tokens: 108000,
completion_tokens: 108000,
},
}), {
status: 200,
headers: { 'Content-Type': 'application/json' },
}))
vi.stubGlobal('fetch', fetchMock as unknown as typeof fetch)
const result = await querySeedanceVideoStatus('cgt-task-2', 'ark-key')
expect(result).toEqual({
status: 'completed',
videoUrl: 'https://example.com/result.mp4',
actualVideoTokens: 108000,
})
expect(fetchMock).toHaveBeenCalledWith(
'https://ark.cn-beijing.volces.com/api/v3/contents/generations/tasks/cgt-task-2',
{
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ark-key',
},
cache: 'no-store',
},
)
})
})