diff --git a/docs/development/validation.md b/docs/development/validation.md index c62a5dea9..d7a128349 100644 --- a/docs/development/validation.md +++ b/docs/development/validation.md @@ -230,6 +230,10 @@ Initial classification: deterministic CLI discovery is ready; native-runtime sub ## 输入数量与助手参数 / Input counts and assistant parameters +火山 Seedance 的生成能力查询应使用配置前缀下的 `/contents/generations/tasks`,包含文生视频和图生视频;未检查网关时状态保持 unknown,不能显示为适配器未匹配,也不能宣称真实生成已通过。运行 `python -m pytest tests/test_ark_availability.py tests/test_creation_parameters.py -k 'ark or seedance' -q`,核对 JSON 参数名、首帧用途、路由前缀及实际任务提交。该生成路径不代表独立视频工具已具备 Ark 适配器。 + +Ark Seedance generation discovery uses `/contents/generations/tasks` under the configured base prefix for text and image inputs. An unchecked gateway remains unknown rather than unmapped or proven available. Run `python -m pytest tests/test_ark_availability.py tests/test_creation_parameters.py -k 'ark or seedance' -q` to verify JSON parameter names, first-frame roles, route prefixes and task submission. This generation path does not imply an Ark adapter exists for standalone video tools. + `tests/continuationAvailability.test.ts` 与 `tests/imageAvailability.test.ts` 检查页面使用实际发送的素材数量:续写来源不计作视频上传,多图请求读取多图能力与数量限制。`tests/test_assistant_capability_parameters.py` 通过助手 HTTP 接口和真实回环网关检查接受前的两次校验,覆盖固定回答上限、连接变化、声明刷新与过期。`tests/test_request_capability_acceptance.py` 检查图片要求在业务服务、HTTP 和 Agent 入口一致,核对上传文件与保存记录。 The frontend tests distinguish cached continuation from video uploads and use the multi-image entry for transmitted multi-image inputs. The assistant test checks both admission points against the gateway's output ceiling, including changed connections, refreshed limits and expired declarations. Image acceptance tests compare the service, HTTP and Agent entry points with serialized uploads and saved execution inputs. @@ -723,3 +727,8 @@ Timing JSON includes per-case hardware and aggregate hardware counts. 比较两份 profile 的原始 ID 和层级;当前全 CPU 套件应完全一致,收集结果 不代表测试执行通过。耗时 JSON 同时记录逐用例机型和机型汇总数量。 + + +Ark duration normalization is shared by capability admission and the submitted JSON through `normalize_ark_parameters`. Verify actual serialized POST values against admission for integral floats, integers, fractional values, booleans, strings and omitted duration in `tests/test_ark_availability.py`; do not round fractional durations or mutate saved intent. + +Ark 能力检查和发送 JSON 共用 `normalize_ark_parameters` 归一化时长。在 `tests/test_ark_availability.py` 中比对实际 POST 序列化参数与检查参数,覆盖整数浮点数、整数、小数、布尔值、字符串及省略时长;不对小数时长取整,不修改原始生成意图。 diff --git a/feature-assets/issue-675/README.md b/feature-assets/issue-675/README.md new file mode 100644 index 000000000..aeb527726 --- /dev/null +++ b/feature-assets/issue-675/README.md @@ -0,0 +1,33 @@ +# Ark video availability regression evidence + +Issue: https://github.com/ThinkFlowLab/OpenDirector/issues/675 + +This evidence covers generation capability discovery and parameter projection. It does not claim a successful real-provider video generation or new standalone video tools. + +## Reproduction + +Configure a video model with protocol `volcengine`, model ID `doubao-seedance-2-0-260128`, a synthetic base URL `https://gateway.example/doubao/api/v3`, and automatic capability checks disabled. No real credentials are used. + +On base `461f31e44249fcccc12f152adc1e2b79b3348b50`, availability returns `unknown/adapter_not_mapped` and no operations. The five tests in `tests/test_ark_availability.py` all fail on that base. + +With this fix, availability returns `unknown/not_checked`, with `text_to_video` and `image_to_video` requests at `/doubao/api/v3/contents/generations/tasks`. [The sanitized receipt](availability-receipt.json) records both results for the same input. + +## Visible result + +Start the API with an isolated temporary data directory, configure the synthetic model above, and open Settings > Model access > Video > Service capabilities. [The screenshot](ark-availability-after.png) shows the actual OpenDirector capability card: both video operations are listed and the service remains unchecked. The existing frontend production build is used with the candidate backend; no frontend code changes are part of this fix. + +![Ark video capability card](ark-availability-after.png) + +## Validation + +The following selection passed 196 tests on Windows with FFmpeg and ffprobe on PATH: + +```sh +python -m pytest tests/test_ark_availability.py tests/test_model_availability.py tests/test_capability_contract_integration.py tests/test_video_resolution.py tests/test_creation_parameters.py -q --tb=short +``` + +The existing generation tests use HTTP model doubles and real local test media. No paid provider call was made for this validation. UI copy, generation transport, persistence and standalone video tool support are unchanged. + +## Duration normalization follow-up + +The follow-up extracts `normalize_ark_parameters` for both admission and the Ark POST payload. It changes no UI behavior. The screenshot above was captured on the original PR revision `29c7d53e017d2eacc60a4f668b85f5c89ded5b80`; it is historical UI evidence, not a new screenshot of the follow-up. Six new HTTP-double cases compare the actual JSON duration against admission for integer floats, integers, fractional values, booleans, strings and omitted duration, and verify input is not mutated. No real gateway task was created. diff --git a/feature-assets/issue-675/ark-availability-after.png b/feature-assets/issue-675/ark-availability-after.png new file mode 100644 index 000000000..5e28283d4 Binary files /dev/null and b/feature-assets/issue-675/ark-availability-after.png differ diff --git a/feature-assets/issue-675/availability-receipt.json b/feature-assets/issue-675/availability-receipt.json new file mode 100644 index 000000000..e52cc1977 --- /dev/null +++ b/feature-assets/issue-675/availability-receipt.json @@ -0,0 +1,59 @@ +{ + "before": { + "modelId": "doubao-seedance-2-0-260128", + "status": "unknown", + "reasonCode": "adapter_not_mapped", + "operations": [] + }, + "after": { + "modelId": "doubao-seedance-2-0-260128", + "status": "unknown", + "reasonCode": "not_checked", + "operations": [ + { + "operation": "video_generation", + "profile": "text_to_video", + "method": "POST", + "path": "/doubao/api/v3/contents/generations/tasks", + "output": "video", + "status": "unknown", + "reasonCode": "not_checked", + "checkedAt": null, + "expiresAt": null, + "inputDetails": [], + "declaration": { + "status": "unknown", + "reasonCode": "not_checked", + "checkedAt": null, + "expiresAt": null + } + }, + { + "operation": "video_generation", + "profile": "image_to_video", + "method": "POST", + "path": "/doubao/api/v3/contents/generations/tasks", + "output": "video", + "status": "unknown", + "reasonCode": "not_checked", + "checkedAt": null, + "expiresAt": null, + "inputDetails": [], + "declaration": { + "status": "unknown", + "reasonCode": "not_checked", + "checkedAt": null, + "expiresAt": null + } + } + ] + }, + "fixture": { + "kind": "video", + "protocol": "volcengine", + "modelId": "doubao-seedance-2-0-260128", + "url": "https://gateway.example/doubao/api/v3", + "capabilityAutoCheck": false + }, + "base": "461f31e44249fcccc12f152adc1e2b79b3348b50" +} diff --git a/packages/core/src/opendirector/application/model_availability.py b/packages/core/src/opendirector/application/model_availability.py index 5675a4764..69a4105c3 100644 --- a/packages/core/src/opendirector/application/model_availability.py +++ b/packages/core/src/opendirector/application/model_availability.py @@ -56,6 +56,9 @@ def request(operation, profile, suffix, output): if kind == 'image' and protocol == 'openai': return [request('image_generation', 'text_to_image', '/images/generations', 'image'), request('image_edit', 'image_to_image', '/images/edits', 'image')] + if kind == 'video' and protocol == 'volcengine': + return [request('video_generation', profile, '/contents/generations/tasks', 'video') + for profile in ('text_to_video', 'image_to_video')] if kind == 'video' and protocol == 'vllm_omni': profiles = ['text_to_video', 'image_to_video', 'video_to_video'] # Continuation uses a cached job, not a video upload. Publish its own @@ -66,8 +69,6 @@ def request(operation, profile, suffix, output): for profile in profiles] if kind == 'audio' and protocol in {'openai', 'vllm_omni_music'}: return [request('speech', 'lyrics_to_music' if protocol == 'vllm_omni_music' else 'text_to_speech', '/audio/speech', 'audio')] - # Ark/Minimax and specialized segmentation, depth, score protocols have - # different wire contracts. A shared media label proves no Omni operation. return [] @@ -145,6 +146,8 @@ def generation_request(config, spec, references, *, parameters=None): def tool_request(config, capability, *, actual=False): + if config['kind'] == 'video' and config.get('protocol') == 'volcengine': + return None # RGBA cutout sends an image edit with background=transparent. Its adapter # still decides whether cutout is offered; the contract has no cutout profile. upstream_capability = 'image.edit' if capability == 'image.cutout' else capability diff --git a/packages/core/src/opendirector/integrations/ark_parameters.py b/packages/core/src/opendirector/integrations/ark_parameters.py new file mode 100644 index 000000000..97aeeb846 --- /dev/null +++ b/packages/core/src/opendirector/integrations/ark_parameters.py @@ -0,0 +1,9 @@ +"""Ark JSON parameter normalization shared by admission and submission.""" + + +def normalize_ark_parameters(parameters): + result = dict(parameters) + seconds = result.get('duration') + if type(seconds) in {int, float} and float(seconds).is_integer(): + result['duration'] = int(seconds) + return result diff --git a/packages/core/src/opendirector/integrations/generation_capability_parameters.py b/packages/core/src/opendirector/integrations/generation_capability_parameters.py index 3e32f085a..cd568fd34 100644 --- a/packages/core/src/opendirector/integrations/generation_capability_parameters.py +++ b/packages/core/src/opendirector/integrations/generation_capability_parameters.py @@ -6,6 +6,7 @@ from opendirector.domain.input_rules import input_rules from opendirector.domain.rule_facts import MUSIC_SECONDS_INITIAL from opendirector.domain.voices import effective_speech_voice +from opendirector.integrations.ark_parameters import normalize_ark_parameters def generation_capability_parameters(config, kind, parameters, *, has_images=False, @@ -48,7 +49,9 @@ def generation_capability_parameters(config, kind, parameters, *, has_images=Fal else: result['voice'] = effective_speech_voice(config, parameters.get('voice')) elif kind == 'video': - if profile == 'vllm-omni-h3': + if config.get('protocol') == 'volcengine': + result = normalize_ark_parameters(parameters) + elif profile == 'vllm-omni-h3': from opendirector.integrations.vllm_omni import capability_parameters, generation_fields, timeline_guide_fields result = capability_parameters(*generation_fields(parameters, video_mode, has_images=has_images, has_audio=has_audio, continue_size=continue_size)) diff --git a/packages/core/src/opendirector/integrations/volcengine.py b/packages/core/src/opendirector/integrations/volcengine.py index d574b8328..ed5ab1a3d 100644 --- a/packages/core/src/opendirector/integrations/volcengine.py +++ b/packages/core/src/opendirector/integrations/volcengine.py @@ -8,6 +8,7 @@ import httpx +from opendirector.integrations.ark_parameters import normalize_ark_parameters from opendirector.integrations.http_settings import MODEL_HTTP_HOOKS, public_target, trust_environment from opendirector.domain.assets import MAX_ASSET_BYTES @@ -167,13 +168,7 @@ async def generate(self, config, task, submitted, *, result_ready=None): for image, role in zip(refs, prepared['imageRoles']): content.append({'type': 'image_url', 'image_url': {'url': image}, 'role': role}) content.extend({'type': 'audio_url', 'audio_url': {'url': audio}, 'role': 'reference_audio'} for audio in prepared['audios']) - parameters = dict(task['parameters']) - # Ark accepts whole seconds only, while the editor stores - # durationSeconds as a float (4.0) and rejects it as - # InvalidParameter instead of rounding. - seconds = parameters.get('duration') - if isinstance(seconds, (int, float)) and not isinstance(seconds, bool) and float(seconds).is_integer(): - parameters['duration'] = int(seconds) + parameters = normalize_ark_parameters(task['parameters']) payload = {'model': config['modelId'], 'content': content, **parameters} request_size(payload, prepared['rules']['requestBytes']) async with client.stream("POST", url, headers=headers, json=payload) as response: diff --git a/tests/test_ark_availability.py b/tests/test_ark_availability.py new file mode 100644 index 000000000..e64619d2b --- /dev/null +++ b/tests/test_ark_availability.py @@ -0,0 +1,111 @@ +"""Ark generation has its own task route, separate from standalone video tools.""" +from types import SimpleNamespace + +import pytest + +from opendirector.application.model_availability import ModelAvailability, generation_request, requests_for, tool_request +from opendirector.integrations.generation_capability_parameters import generation_capability_parameters +from test_model_availability import document, service + + +pytestmark = pytest.mark.cpu + + +def config(): + return {'kind': 'video', 'protocol': 'volcengine', 'modelId': 'doubao-seedance-2-0-260128', + 'url': 'https://gateway.test/doubao/api/v3', 'apiKey': 'fixture-key'} + + +def test_ark_catalogue_maps_the_configured_task_route_without_claiming_remote_success(): + availability = ModelAvailability(None) + try: + model = availability.model(config()) + assert model['status'] == 'unknown' + assert model['reasonCode'] == 'not_checked' + assert {item['profile'] for item in model['operations']} == {'text_to_video', 'image_to_video'} + assert all(item['path'] == '/doubao/api/v3/contents/generations/tasks' + and item['method'] == 'POST' for item in model['operations']) + for request in requests_for(config()): + availability.require(config(), request) + assert tool_request(config(), 'video.first_frame') is None + finally: + availability.probe.close() + + +@pytest.mark.parametrize('first_frame', [False, True]) +def test_ark_admission_uses_its_json_fields_and_first_frame_role(first_frame): + spec = SimpleNamespace(kind='video', parameters=SimpleNamespace(videoMode='first_frame')) + references = [SimpleNamespace(transmission='content', role='first_frame', + asset=SimpleNamespace(kind='image'))] if first_frame else [] + parameters = dict(duration=8.0, ratio='16:9', resolution='720p', generate_audio=False, watermark=False) + request = generation_request(config(), spec, references, parameters=parameters) + assert request.profile == ('image_to_video' if first_frame else 'text_to_video') + assert request.path == '/doubao/api/v3/contents/generations/tasks' + assert dict(request.parameters) == parameters + assert type(dict(request.parameters)['duration']) is int + assert 'seconds' not in dict(request.parameters) + assert dict(request.input_counts) == ({'text': 1, 'image': 1, 'first_frame': 1} if first_frame else {'text': 1}) + assert generation_capability_parameters(config(), 'video', parameters) == dict(request.parameters) + + +@pytest.mark.parametrize('path,accepted', [('/doubao/api/v3/contents/generations/tasks', False), + ('/doubao/api/v3/videos', True)]) +def test_ark_checks_duration_only_on_its_actual_json_route(service, path, accepted): + _, _, state, availability = service + selected = config() + declaration = document('video_generation', 'text_to_video', path, 'video', + model=selected['modelId'], now=state['clock']) + declaration['models'][0]['operations']['video_generation']['profiles'][0]['routes'][0]['request'] = { + 'parameters': {'duration': {'type': 'integer', 'maximum': 5}}} + state['document'] = declaration + availability.prepare(selected, manual=True) + request = generation_request(selected, SimpleNamespace(kind='video', + parameters=SimpleNamespace(videoMode='first_frame')), [], parameters={'duration': 8.0}) + if accepted: + availability.require(selected, request) + assert availability.decision(selected, request)['reasonCode'] == 'route_not_declared' + else: + from opendirector.domain.projects import ProjectError + with pytest.raises(ProjectError): + availability.require(selected, request) + + +@pytest.mark.parametrize('parameters', [ + {'duration': 5.0}, {'duration': 5}, {'duration': 5.5}, + {'duration': False}, {'duration': '5'}, {}, +]) +def test_ark_checked_duration_matches_actual_json_without_mutating_intent(parameters, monkeypatch): + import asyncio + import json + import httpx + from opendirector.domain.generation import GenerationError + from opendirector.integrations.volcengine import VolcengineGeneration + selected = config() + original = dict(parameters) + checked = generation_capability_parameters(selected, 'video', parameters) + payloads = [] + def handle(request): + payloads.append(json.loads(request.content)) + return httpx.Response(400, json={'error': {'code': 'InvalidParameter'}}) + monkeypatch.setattr('opendirector.integrations.volcengine.generation_references', + lambda *args, **kwargs: dict(prompt='fixture', images=[], imageRoles=[], audios=[], + rules={'requestBytes': 1024 * 1024})) + async def run(): + with pytest.raises(GenerationError): + await VolcengineGeneration(None, httpx.MockTransport(handle)).generate(selected, + dict(kind='video', prompt='fixture', parameters=parameters), None) + asyncio.run(run()) + assert len(payloads) == 1 + sent = payloads[0] + assert ('duration' in checked) == ('duration' in sent) + if 'duration' in checked: + assert checked['duration'] == sent['duration'] + assert type(checked['duration']) is type(sent['duration']) + if type(original['duration']) in {int, float} and original['duration'] == 5: + assert type(sent['duration']) is int + else: + assert type(sent['duration']) is type(original['duration']) + assert sent['duration'] == original['duration'] + assert parameters == original + if 'duration' in original: + assert type(parameters['duration']) is type(original['duration'])