feat: add initial model provider adapters
This commit is contained in:
1 parent
7f35960ba6
commit
547f7c0977
16 files changed
+577
-21
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import { SeedanceProvider, SeedanceProviderError, mapSeedanceTask } from '../src/providers/seedance.js'
|
||||
|
||||
test('Seedance adapter creates an official asynchronous video generation task', async () => {
|
||||
const requests: Array<{ url: string; init: RequestInit | undefined }> = []
|
||||
const provider = new SeedanceProvider({
|
||||
apiKey: 'test-volcengine-key',
|
||||
fetcher: async (url, init) => {
|
||||
requests.push({ url: String(url), init })
|
||||
return new Response(JSON.stringify({ id: 'cgt-20260828-demo', status: 'queued' }), { status: 200 })
|
||||
},
|
||||
})
|
||||
|
||||
const taskId = await provider.createTextToVideo({ model: 'doubao-seedance-1-0-pro-250528', prompt: 'a cinematic product video' })
|
||||
|
||||
assert.equal(taskId, 'cgt-20260828-demo')
|
||||
assert.equal(requests[0]?.url, 'https://ark.cn-beijing.volces.com/api/v3/contents/generations/tasks')
|
||||
assert.equal(new Headers(requests[0]?.init?.headers).get('Authorization'), 'Bearer test-volcengine-key')
|
||||
assert.deepEqual(JSON.parse(String(requests[0]?.init?.body)), {
|
||||
model: 'doubao-seedance-1-0-pro-250528',
|
||||
content: [{ type: 'text', text: 'a cinematic product video' }],
|
||||
})
|
||||
})
|
||||
|
||||
test('Seedance task response maps video output and timestamps to MOYI task view', () => {
|
||||
const mapped = mapSeedanceTask({
|
||||
id: 'cgt-20260828-demo',
|
||||
model: 'doubao-seedance-1-0-pro-250528',
|
||||
status: 'succeeded',
|
||||
created_at: 1787880000,
|
||||
updated_at: 1787880060,
|
||||
content: { video_url: 'https://example.test/result.mp4' },
|
||||
})
|
||||
|
||||
assert.equal(mapped.status, 'succeeded')
|
||||
assert.equal(mapped.progress, 100)
|
||||
assert.equal(mapped.output?.videoUrl, 'https://example.test/result.mp4')
|
||||
assert.match(mapped.createdAt || '', /^2026-/)
|
||||
})
|
||||
|
||||
test('Seedance adapter validates task identifiers before making requests', async () => {
|
||||
const provider = new SeedanceProvider({ apiKey: 'test-key', fetcher: async () => new Response('{}') })
|
||||
await assert.rejects(provider.getTask('../invalid'), (error: unknown) => error instanceof SeedanceProviderError)
|
||||
})
|
||||
Reference in new issue
Block a user