hit-cxf
2026-06-02 6f5bcb60d0a71678c79c1450e5cc81eb8ee757bd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
 
from .api_media import generate_video_api
from .storage import append_artifact, task_output_dir, update_task
from .utils import artifact, copy_input_file, run_blocking, write_json
 
 
def required_param(params: dict, key: str) -> str:
    value = params.get(key)
    if not value:
        raise ValueError(f"action_transfer pipeline requires {key}")
    return str(value)
 
 
async def run(task_id: str, params: dict) -> tuple[dict, list[dict]]:
    output_dir = task_output_dir(task_id)
    os.makedirs(output_dir, exist_ok=True)
 
    prompt = params.get("prompt_text") or params.get("prompt") or ""
    image_path = params.get("image_path") or params.get("image_asset")
    video_path = params.get("video_path") or params.get("video_asset")
    if not prompt.strip():
        raise ValueError("action_transfer requires prompt_text")
    if not image_path:
        raise ValueError("action_transfer requires image_path")
    if not video_path:
        raise ValueError("action_transfer requires video_path")
 
    image_path = copy_input_file(image_path, output_dir, "input_image")
    video_path = copy_input_file(video_path, output_dir, "input_video")
    final_video_path = os.path.join(output_dir, "final.mp4")
    video_model = required_param(params, "video_model")
 
    update_task(task_id, progress=20, message="Calling action-transfer video API")
    await run_blocking(
        generate_video_api,
        prompt=prompt,
        model=video_model,
        output_path=final_video_path,
        image_path=None,
        duration=int(params.get("duration") or 5),
        video_ratio=params.get("video_ratio") or "9:16",
        first_clip_path=video_path,
        reference_image_path=image_path,
        negative_prompt=params.get("negative_prompt"),
        video_resolution=params.get("video_resolution") or params.get("resolution"),
        watermark=params.get("watermark"),
        prompt_extend=params.get("prompt_extend"),
    )
 
    request_path = write_json(os.path.join(output_dir, "request.json"), {
        "prompt": prompt,
        "image_path": image_path,
        "video_path": video_path,
        "video_model": video_model,
    })
    artifacts = [
        artifact(request_path, "text", "request"),
        artifact(image_path, "image", "input_image"),
        artifact(video_path, "video", "input_video"),
        artifact(final_video_path, "video", "final"),
    ]
    for item in artifacts:
        append_artifact(task_id, item)
    return {"video_path": final_video_path, "request_path": request_path}, artifacts