Generating commit message...

This commit is contained in:
2026-06-30 17:15:33 +08:00
parent c18b2300d3
commit d29cdb05ee
7 changed files with 622 additions and 47 deletions
+41 -1
View File
@@ -952,6 +952,38 @@ function buildQueryUrl(config, taskId) {
return base + ep;
}
function encodeAgnesPollId(taskId, videoId) {
const normalizedVideoId = String(videoId || '').trim();
if (normalizedVideoId) return `video:${normalizedVideoId}`;
return String(taskId || '').trim();
}
function buildAgnesPollRequest(config, taskId, modelHint) {
const rawId = String(taskId || '').trim();
const headers = { Authorization: 'Bearer ' + (config.api_key || '') };
const safeModel = encodeURIComponent(String(modelHint || 'agnes-video-v2.0').trim() || 'agnes-video-v2.0');
if (rawId.startsWith('video:')) {
const videoId = rawId.slice('video:'.length);
return {
url: `https://apihub.agnes-ai.com/agnesapi?video_id=${encodeURIComponent(videoId)}&model_name=${safeModel}`,
headers,
};
}
if (/^video_/i.test(rawId)) {
return {
url: `https://apihub.agnes-ai.com/agnesapi?video_id=${encodeURIComponent(rawId)}&model_name=${safeModel}`,
headers,
};
}
return {
url: buildQueryUrl(config, rawId),
headers,
};
}
// ????????? ? API ?? ID ???API ????+???????
const VOLC_MODEL_ALIASES = {
'doubao-seedance-1.0-pro-fast': 'doubao-seedance-1-0-pro-250528',
@@ -2520,7 +2552,10 @@ async function callAgnesVideoApi(db, config, log, opts) {
return { video_url: directUrl };
}
const taskId = data.id || data.task_id || data.data?.id || data.data?.task_id;
const taskId = encodeAgnesPollId(
data.id || data.task_id || data.data?.id || data.data?.task_id,
data.video_id || data.data?.video_id
);
if (taskId) {
log.info('[Agnes] 返回 task_id', { task_id: taskId, status: data.status, video_gen_id });
return { task_id: String(taskId), status: data.status || 'processing' };
@@ -3809,6 +3844,10 @@ async function pollVideoTask(db, log, videoGenId, taskId, config, maxAttempts =
if (!qep.startsWith('/')) qep = '/' + qep;
url = viduBase + qep;
headers = { Authorization: (isOfficialVidu ? 'Token ' : 'Bearer ') + (config.api_key || '') };
} else if (isAgnes) {
const agnesReq = buildAgnesPollRequest(config, taskId, config.model);
url = agnesReq.url;
headers = agnesReq.headers;
} else {
url = queryUrl();
headers = { Authorization: 'Bearer ' + (config.api_key || '') };
@@ -4061,6 +4100,7 @@ module.exports = {
normalizeAspectRatioForApi,
isPlausibleHttpVideoUrl,
pickProxyVideoUrl,
buildAgnesPollRequest,
buildAgnesVideoImagePayload,
formatVideoPostBodyForLog,
};
+26 -1
View File
@@ -1,6 +1,6 @@
const { describe, it } = require('node:test');
const assert = require('node:assert/strict');
const { pickProxyVideoUrl } = require('../src/services/videoClient');
const { pickProxyVideoUrl, buildAgnesPollRequest } = require('../src/services/videoClient');
describe('pickProxyVideoUrl Agnes completed task', () => {
it('reads MP4 from remixed_from_video_id when video_url is absent', () => {
@@ -17,3 +17,28 @@ describe('pickProxyVideoUrl Agnes completed task', () => {
);
});
});
describe('buildAgnesPollRequest', () => {
it('uses recommended video_id query API when provider poll id is video-prefixed', () => {
const req = buildAgnesPollRequest(
{ api_key: 'k', base_url: 'https://apihub.agnes-ai.com/v1' },
'video:video_abc123',
'agnes-video-v2.0'
);
assert.equal(
req.url,
'https://apihub.agnes-ai.com/agnesapi?video_id=video_abc123&model_name=agnes-video-v2.0'
);
assert.deepEqual(req.headers, { Authorization: 'Bearer k' });
});
it('falls back to legacy task query API for task ids', () => {
const req = buildAgnesPollRequest(
{ api_key: 'k', base_url: 'https://apihub.agnes-ai.com/v1', query_endpoint: '/videos/{taskId}' },
'task_abc123',
'agnes-video-v2.0'
);
assert.equal(req.url, 'https://apihub.agnes-ai.com/v1/videos/task_abc123');
assert.deepEqual(req.headers, { Authorization: 'Bearer k' });
});
});