Publish Seedance 2.5 draft mode and video updates
- Add the 样片模式 flow: 480p draft generation, a linkable draft task ID, and pre-flight verification before the 1080p final request. - Allow reference images and audio in video edit/extend requests, matching the provider's 2.5 contract. - Move 主模型 and 样片模式 ahead of 生成模式, default 主模型 to seedance 2.5, and migrate saved widget values. - Refresh the video panel, asset API response logs, and LLM node handling; cover the new behavior with offline tests.
This commit is contained in:
@@ -4,6 +4,7 @@ Seedance 2.0 真人素材(Element)API 客户端
|
||||
"""
|
||||
|
||||
import json
|
||||
import re
|
||||
import aiohttp
|
||||
from typing import Optional
|
||||
from urllib.parse import quote
|
||||
@@ -12,6 +13,53 @@ from ..utils.config import get_api_key_or_raise, get_base_url_by_route
|
||||
from ..utils.video_task import PollDeadline, check_interrupt, interruptible_sleep
|
||||
|
||||
|
||||
_MAX_LOG_RESPONSE_CHARS = 4000
|
||||
_LOG_URL_PATTERN = re.compile(r"https?://[^\s\"'<>]+")
|
||||
_LOG_BASE64_PATTERN = re.compile(r"data:[^,\s]+;base64,[A-Za-z0-9+/=]+")
|
||||
_LOG_TOKEN_PATTERN = re.compile(r"(?i)bearer\s+[^\s\"']+")
|
||||
|
||||
|
||||
def _redact_log_text(text: str) -> str:
|
||||
"""Fold credentials, signed URLs and Base64 media before logging."""
|
||||
|
||||
text = _LOG_URL_PATTERN.sub("<URL 已隐藏>", text)
|
||||
text = _LOG_BASE64_PATTERN.sub("<Base64 已隐藏>", text)
|
||||
return _LOG_TOKEN_PATTERN.sub("Bearer <已隐藏>", text)
|
||||
|
||||
|
||||
def _log_value(value, key: str = "", depth: int = 0):
|
||||
if depth >= 12:
|
||||
return "<嵌套内容已省略>"
|
||||
if isinstance(value, dict):
|
||||
return {
|
||||
_redact_log_text(str(name)[:200]): _log_value(item, str(name), depth + 1)
|
||||
for name, item in value.items()
|
||||
}
|
||||
if isinstance(value, list):
|
||||
items = [_log_value(item, key, depth + 1) for item in value[:50]]
|
||||
if len(value) > 50:
|
||||
items.append(f"<其余 {len(value) - 50} 项已省略>")
|
||||
return items
|
||||
if isinstance(value, str):
|
||||
if len(value) > 1200:
|
||||
return f"<长文本 {len(value)} 字符已省略>"
|
||||
return _redact_log_text(value)
|
||||
return value
|
||||
|
||||
|
||||
def _format_log_response(payload) -> str:
|
||||
"""Render an asset API response for the terminal with only secrets folded."""
|
||||
|
||||
try:
|
||||
rendered = json.dumps(_log_value(payload), ensure_ascii=False, indent=2)
|
||||
except (TypeError, ValueError):
|
||||
rendered = _redact_log_text(str(payload))
|
||||
if len(rendered) > _MAX_LOG_RESPONSE_CHARS:
|
||||
rendered = f"{rendered[:_MAX_LOG_RESPONSE_CHARS]}...<后续内容已省略>"
|
||||
return rendered
|
||||
|
||||
|
||||
|
||||
class SeedanceElementClient:
|
||||
"""Seedance 2.0 真人素材客户端"""
|
||||
|
||||
@@ -172,11 +220,9 @@ class SeedanceElementClient:
|
||||
async with session.post(url, json=body, headers=self._hc_headers()) as resp:
|
||||
result = await self._read_json_response(resp)
|
||||
print(
|
||||
f"[Seedance素材][{request_label}] 创建响应体:\n"
|
||||
+ json.dumps(
|
||||
{"http_status": resp.status, "success": bool(result.get("success"))},
|
||||
ensure_ascii=False,
|
||||
)
|
||||
f"[Seedance素材][{request_label}] 创建响应体 HTTP {resp.status}:\n"
|
||||
+ _format_log_response(result),
|
||||
flush=True,
|
||||
)
|
||||
if resp.status < 200 or resp.status >= 300:
|
||||
message = self._hc_error_message(result, "创建素材失败")
|
||||
@@ -218,13 +264,30 @@ class SeedanceElementClient:
|
||||
headers=self._hc_headers(),
|
||||
) as resp:
|
||||
result = await self._read_json_response(resp)
|
||||
data = result.get("data")
|
||||
status = str(data.get("Status", "")).strip() if isinstance(data, dict) else ""
|
||||
failed = (
|
||||
resp.status < 200
|
||||
or resp.status >= 300
|
||||
or not result.get("success", False)
|
||||
)
|
||||
logged_status = getattr(self, "_logged_asset_status", None)
|
||||
if logged_status is None:
|
||||
logged_status = self._logged_asset_status = {}
|
||||
if failed or logged_status.get(asset_id) != status:
|
||||
logged_status[asset_id] = status
|
||||
print(
|
||||
f"[Seedance素材][{request_label}] 查询响应体 HTTP {resp.status}:\n"
|
||||
+ _format_log_response(result),
|
||||
flush=True,
|
||||
)
|
||||
|
||||
if resp.status < 200 or resp.status >= 300:
|
||||
message = self._hc_error_message(result, "查询素材状态失败")
|
||||
raise RuntimeError(f"查询 {request_label} 素材失败 ({resp.status}): {message}")
|
||||
if not result.get("success", False):
|
||||
raise RuntimeError(self._hc_error_message(result, f"查询 {request_label} 素材失败"))
|
||||
|
||||
data = result.get("data")
|
||||
if not isinstance(data, dict):
|
||||
raise RuntimeError(f"查询 {request_label} 素材未返回 data")
|
||||
return data
|
||||
@@ -237,7 +300,7 @@ class SeedanceElementClient:
|
||||
name: str,
|
||||
asset_url: str,
|
||||
asset_type: str,
|
||||
poll_interval: float = 3.0,
|
||||
poll_interval: float = 1.5,
|
||||
request_type: str = "hc",
|
||||
) -> dict:
|
||||
"""创建 HC 或 Doubao 素材并等待其进入 Active 状态。"""
|
||||
|
||||
Reference in New Issue
Block a user