Skip to content

feat: support Wan2.7 i2v media mapping - #4984

Merged
Calcium-Ion merged 2 commits into
QuantumNous:mainfrom
wxwwt:feature/wan27-i2v-media
Jul 1, 2026
Merged

Calcium-Ion merged 2 commits into
QuantumNous:mainfrom
wxwwt:feature/wan27-i2v-media

Conversation

@wxwwt

@wxwwt wxwwt commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

本次为 Ali 视频生成渠道补充 Wan2.7 图生视频协议适配。

Wan2.7 I2V 使用的是新的 input.media 入参格式,而当前 Ali adaptor 仍主要按旧版 img_url / first_frame_url / last_frame_url 字段组织请求。这个改动在 wan2.7-i2v 场景下将通用视频请求里的 image、images、input_reference 映射为 DashScope 所需的 input.media:

  • 单图会映射为 type: first_frame
  • 双图会映射为 first_frame + last_frame
  • 显式传入的 metadata.input.media 会被保留
  • 旧版 Wan I2V 模型仍继续使用原有 img_url 逻辑

同时补充了 wan2.7-i2v、wan2.7-t2v 到 Ali task model list,并让 direct video request 路径兼容单图 image 字段,避免图生视频请求没有被识别为带图任务。

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

  • N/A

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 Issues 与 PRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

go test ./relay/channel/task/ali ./relay/common

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **New Features**
  * Added support for the “wan2.7-i2v” image-to-video model using a media-based input protocol.
* **Bug Fixes**
  * Improved request normalization for wan2.7-i2v by deriving required frame media from provided images/metadata and returning clearer errors when missing.
  * Enhanced multipart/direct handling so a single `image` value is accepted and normalized consistently.
* **Tests**
  * Expanded unit tests for wan2.7-i2v media derivation, legacy wan2.5 behavior, image precedence, and direct upload normalization.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

@coderabbitai

coderabbitai Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a162b0c6-3594-4786-8922-9e4d921cd9bd

📥 Commits

Reviewing files that changed from the base of the PR and between c19ecd8 and 990242b.

📒 Files selected for processing (4)
  • relay/channel/task/ali/adaptor.go
  • relay/channel/task/ali/adaptor_test.go
  • relay/common/relay_utils.go
  • relay/common/relay_utils_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • relay/common/relay_utils_test.go
  • relay/common/relay_utils.go
  • relay/channel/task/ali/adaptor.go

Walkthrough

Adds Wan2.7-i2v support to the Ali adaptor: new media schema, request normalization for image/audio inputs, model registration, upstream single-image normalization, and tests covering the new protocol plus legacy behavior.

Changes

Wan2.7-i2v Image-to-Video Support

Layer / File(s) Summary
Data structures for media protocol
relay/channel/task/ali/adaptor.go
Introduces AliVideoMedia and adds Media []AliVideoMedia to AliVideoInput and AliMetadata.
Model registration
relay/channel/task/ali/constants.go
Adds "wan2.7-i2v" to the Ali ModelList.
Input normalization for Wan2.7-i2v
relay/channel/task/ali/adaptor.go
Derives first_frame, last_frame, and optional driving_audio media items for wan2.7-i2v, errors when no media can be derived, and clears legacy single-field inputs.
Request conversion and normalization integration
relay/channel/task/ali/adaptor.go
Sets AliVideoInput.ImgURL from the first usable task image and runs normalizeWan27I2VInput before returning the request.
Adaptor tests for media mapping
relay/channel/task/ali/adaptor_test.go
Adds tests for Wan2.7-i2v media construction, precedence and fallback rules, explicit metadata media, missing-image errors, and legacy wan2.5-i2v-preview behavior.
Upstream request validation for single image field
relay/common/relay_utils.go, relay/common/relay_utils_test.go
Normalizes a single image field into images when other image sources are absent, and verifies the stored task request reflects that normalization.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested reviewers: Calcium-Ion, creamlike1024

Poem

🐰 I packed the frames from start to end,
With media paths that bend and blend.
A hop for image, a hop for sound,
And legacy fields are safely bound.
The rabbit cheers: new videos abound!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding Wan2.7 I2V media mapping support.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@relay/channel/task/ali/adaptor.go`:
- Around line 276-287: The helper firstTaskImage currently returns
InputReference before the newer direct-image fields; change its selection order
to prefer req.Image, then the first element of req.Images, and only fall back to
req.InputReference, so direct-image fields win; apply the same ordering change
to the other analogous helper used later (the one with the same logic around the
other task-image extraction) so both places derive img_url/first_frame from
Image/Images first.

In `@relay/common/relay_utils.go`:
- Around line 142-144: The code checks strings.TrimSpace(req.Image) but stores
the raw req.Image, allowing surrounding spaces to propagate; update the branch
that handles single-image compatibility so you store the trimmed value (e.g.,
use the trimmed string of req.Image when assigning to req.Images) — locate the
conditional around req.Images and req.Image in relay_utils.go and replace the
assignment to req.Images with the normalized/trimmed image string.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 32d16b1f-b3a9-456a-96a5-c57880d83d72

📥 Commits

Reviewing files that changed from the base of the PR and between 20d3e73 and e1153ab.

📒 Files selected for processing (5)
  • relay/channel/task/ali/adaptor.go
  • relay/channel/task/ali/adaptor_test.go
  • relay/channel/task/ali/constants.go
  • relay/common/relay_utils.go
  • relay/common/relay_utils_test.go

Comment thread relay/channel/task/ali/adaptor.go Resolved
Comment thread relay/common/relay_utils.go Resolved
@wxwwt
wxwwt force-pushed the feature/wan27-i2v-media branch from e1153ab to e4cbbde Compare May 20, 2026 05:52

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
relay/channel/task/ali/adaptor_test.go (1)

18-121: ⚡ Quick win

Add one regression test for mixed-source precedence (image/images + input_reference).

Current cases are solid, but they don’t lock behavior when both legacy and direct image fields are sent together—the exact edge where source selection can drift.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@relay/channel/task/ali/adaptor_test.go` around lines 18 - 121, Add a
regression test named TestConvertToAliRequestMixedSourcePrecedence in
adaptor_test.go that constructs a TaskAdaptor and a relaycommon.TaskSubmitReq
for model "wan2.7-i2v" with both Image/Images set and Metadata containing an
explicit input.media (or input_reference) entry; call
adaptor.convertToAliRequest(testRelayInfo(), req) and assert no error, then
assert that aliReq.Input.Media equals the metadata-provided media (not the
Image/Images), aliReq.Input.ImgURL is empty, and the marshaled body contains
"media" and does not contain "img_url" to lock precedence of explicit metadata
over image/images.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@relay/channel/task/ali/adaptor_test.go`:
- Around line 18-121: Add a regression test named
TestConvertToAliRequestMixedSourcePrecedence in adaptor_test.go that constructs
a TaskAdaptor and a relaycommon.TaskSubmitReq for model "wan2.7-i2v" with both
Image/Images set and Metadata containing an explicit input.media (or
input_reference) entry; call adaptor.convertToAliRequest(testRelayInfo(), req)
and assert no error, then assert that aliReq.Input.Media equals the
metadata-provided media (not the Image/Images), aliReq.Input.ImgURL is empty,
and the marshaled body contains "media" and does not contain "img_url" to lock
precedence of explicit metadata over image/images.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 22828849-f2f5-4463-80b4-ed50c1ac891b

📥 Commits

Reviewing files that changed from the base of the PR and between e1153ab and e4cbbde.

📒 Files selected for processing (5)
  • relay/channel/task/ali/adaptor.go
  • relay/channel/task/ali/adaptor_test.go
  • relay/channel/task/ali/constants.go
  • relay/common/relay_utils.go
  • relay/common/relay_utils_test.go

@wxwwt
wxwwt force-pushed the feature/wan27-i2v-media branch from e4cbbde to c19ecd8 Compare May 20, 2026 05:57

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (2)
relay/common/relay_utils.go (1)

142-144: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Trim the normalized single-image value before storing it.

Line 142 trims for validation, but Line 144 stores the raw string. This can propagate leading/trailing spaces into req.Images.

Suggested patch
-	} else if len(req.Images) == 0 && strings.TrimSpace(req.Image) != "" {
+	} else if len(req.Images) == 0 && strings.TrimSpace(req.Image) != "" {
 		// 兼容单图上传
-		req.Images = []string{req.Image}
+		req.Images = []string{strings.TrimSpace(req.Image)}
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@relay/common/relay_utils.go` around lines 142 - 144, The code validates with
strings.TrimSpace(req.Image) but then stores the untrimmed value into
req.Images, so update the branch that handles single-image compatibility to
assign the trimmed value: compute trimmed := strings.TrimSpace(req.Image) (or
reuse the trimmed value used for validation) and set req.Images =
[]string{trimmed} instead of using req.Image; ensure req.Image remains unchanged
only if needed elsewhere or optionally overwrite req.Image with the trimmed
value for consistency.
relay/channel/task/ali/adaptor.go (1)

276-287: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Prefer image/images over input_reference in firstTaskImage.

This still picks input_reference first, so when a request carries both the new direct-image fields and the legacy reference, Wan2.7 media derivation can send the wrong first frame. Because Line 348 reuses this helper, the legacy img_url path inherits the same bug. Reorder the fallback to image → images[0] → input_reference, and trim whitespace so blank values do not block later candidates.

Suggested fix
 func firstTaskImage(req relaycommon.TaskSubmitReq) string {
-	if req.InputReference != "" {
-		return req.InputReference
-	}
-	if req.Image != "" {
+	if strings.TrimSpace(req.Image) != "" {
 		return req.Image
 	}
-	if len(req.Images) > 0 {
+	if len(req.Images) > 0 && strings.TrimSpace(req.Images[0]) != "" {
 		return req.Images[0]
 	}
+	if strings.TrimSpace(req.InputReference) != "" {
+		return req.InputReference
+	}
 	return ""
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@relay/channel/task/ali/adaptor.go` around lines 276 - 287, The helper
firstTaskImage currently prefers input_reference first and doesn't trim blanks;
change its fallback order to prefer req.Image, then req.Images[0], then
req.InputReference, and ensure you trim whitespace from each candidate so empty
or whitespace-only values don't block later options; update the logic in
function firstTaskImage (used elsewhere, e.g., the legacy img_url path) to check
strings.TrimSpace(req.Image), iterate images checking strings.TrimSpace on each
entry, and finally use strings.TrimSpace(req.InputReference) as the last resort.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@relay/channel/task/ali/adaptor.go`:
- Around line 276-287: The helper firstTaskImage currently prefers
input_reference first and doesn't trim blanks; change its fallback order to
prefer req.Image, then req.Images[0], then req.InputReference, and ensure you
trim whitespace from each candidate so empty or whitespace-only values don't
block later options; update the logic in function firstTaskImage (used
elsewhere, e.g., the legacy img_url path) to check strings.TrimSpace(req.Image),
iterate images checking strings.TrimSpace on each entry, and finally use
strings.TrimSpace(req.InputReference) as the last resort.

In `@relay/common/relay_utils.go`:
- Around line 142-144: The code validates with strings.TrimSpace(req.Image) but
then stores the untrimmed value into req.Images, so update the branch that
handles single-image compatibility to assign the trimmed value: compute trimmed
:= strings.TrimSpace(req.Image) (or reuse the trimmed value used for validation)
and set req.Images = []string{trimmed} instead of using req.Image; ensure
req.Image remains unchanged only if needed elsewhere or optionally overwrite
req.Image with the trimmed value for consistency.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 807d1228-441b-4f1f-a65a-7b8b46fda618

📥 Commits

Reviewing files that changed from the base of the PR and between e4cbbde and c19ecd8.

📒 Files selected for processing (5)
  • relay/channel/task/ali/adaptor.go
  • relay/channel/task/ali/adaptor_test.go
  • relay/channel/task/ali/constants.go
  • relay/common/relay_utils.go
  • relay/common/relay_utils_test.go
✅ Files skipped from review due to trivial changes (1)
  • relay/channel/task/ali/constants.go

@wxwwt

wxwwt commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@Calcium-Ion @creamlike1024 麻烦有空帮忙看一下这个 PR,谢谢。

我看了下最新 main 还没有包含 wan2.7-i2v 的 input.media 映射逻辑。这个 PR 范围比较小,只补 Ali Wan2.7 i2v 的 media mapping 和对应测试

@Calcium-Ion

Copy link
Copy Markdown
Member

好的

@Calcium-Ion Calcium-Ion self-assigned this Jul 1, 2026
@Calcium-Ion
Calcium-Ion merged commit 52858ad into QuantumNous:main Jul 1, 2026
henrydontbbai added a commit to henrydontbbai/henry-newapi that referenced this pull request Jul 2, 2026
* feat: improve advanced custom route editor

* Bump Electron lockfile dependencies

* feat: bill doubao seedance-2.0 by output resolution and video input (QuantumNous#5300)

* feat: support doubao seedance 2.0 safety_identifier/priority and 4k billing (QuantumNous#5824)

* feat: support safety_identifier and priority for doubao video

* feat: add 4k resolution billing tier for doubao video

* chore: run `bun format` to automatically format the frontend code

* fix(web): 修复自定义 HTML 样式被过滤及排版间距异常的问题 (QuantumNous#5795)

* fix(web): 修复自定义 HTML 样式被过滤及排版间距异常的问题

* fix(web): isolate custom HTML rendering

---------

Co-authored-by: CaIon <[email protected]>

* feat: support Wan2.7 i2v media mapping (QuantumNous#4984)

* feat: support Wan2.7 i2v media mapping

* fix: normalize wan2.7 i2v image inputs

* perf(web): optimize web Rsbuild and Tailwind build pipeline (QuantumNous#5786)

* fix(dev): run only default frontend in dev-web

- simplify make dev-web to install default dependencies and start web/default only.
- keep dev-web-classic as the standalone classic entry and scope its install to classic.

* chore(build): align make targets with web naming

- rename frontend make targets and variables to use the web terminology consistently.
- keep default and classic dev port overrides available under the updated names.

* fix(web): inject app styles into isolated HTML (QuantumNous#5860)

- clone loaded application style nodes into the Shadow DOM for custom HTML rendering.
- keep HTML rendering isolated while restoring layout and typography that depend on app CSS.

* fix: keep page state when switching tabs within the same route (QuantumNous#5796)

AnimatedOutlet keyed its motion container by the full pathname, so
navigating between params of the same route (e.g. the dashboard tabs
under /dashboard/$section) changed the key and remounted the route
component, discarding its in-memory state. The most visible symptom:
the dashboard time range resets to the default every time you switch
sub-tabs (Model Analytics / Flow / User Analytics).

Key the transition by the matched route id instead, so param-only
navigation re-renders in place while real page-to-page navigation
still plays the enter animation. This also preserves state across the
other $section tab pages (usage logs, models, system settings).

* 支持服务优雅关闭,避免重启回复中断和面板缓存数据丢失 (QuantumNous#4258)

* feat: add graceful shutdown with configurable timeout

* fix: flush quota dashboard cache on graceful shutdown

Persist the in-memory CacheQuotaData aggregation to the quota_data table
before process exit, so a restart no longer drops up to one DataExportInterval
window of dashboard data (issue QuantumNous#5679).

* docs: update AGENTS.md

* Make quota logging synchronous and delay startup log

---------

Co-authored-by: CaIon <[email protected]>
Co-authored-by: feitianbubu <[email protected]>
Co-authored-by: t0ng7u <[email protected]>
Co-authored-by: olwater <[email protected]>
Co-authored-by: Scott <[email protected]>
Co-authored-by: QuentinHsu <[email protected]>
Co-authored-by: henrydontbbai <[email protected]>
liulixin-lex pushed a commit to liulixin-lex/xy-api that referenced this pull request Jul 7, 2026
* feat: support Wan2.7 i2v media mapping

* fix: normalize wan2.7 i2v image inputs
0401lucky pushed a commit to 0401lucky/new-api that referenced this pull request Jul 7, 2026
* feat: support Wan2.7 i2v media mapping

* fix: normalize wan2.7 i2v image inputs

(cherry picked from commit 52858ad)
fran0220 pushed a commit to fran0220/you-box that referenced this pull request Jul 9, 2026
* feat: support Wan2.7 i2v media mapping

* fix: normalize wan2.7 i2v image inputs

(cherry picked from commit 52858ad)
ruanhangjian pushed a commit to ruanhangjian/new-api that referenced this pull request Jul 11, 2026
* feat: support Wan2.7 i2v media mapping

* fix: normalize wan2.7 i2v image inputs
noah-wung pushed a commit to noah-wung/new-api that referenced this pull request Jul 17, 2026
* feat: support Wan2.7 i2v media mapping

* fix: normalize wan2.7 i2v image inputs
zhaodechao2008 pushed a commit to zhaodechao2008/new-api that referenced this pull request Jul 27, 2026
* feat: support Wan2.7 i2v media mapping

* fix: normalize wan2.7 i2v image inputs
330079598 pushed a commit to 330079598/new-api that referenced this pull request Aug 19, 2026
* feat: support Wan2.7 i2v media mapping

* fix: normalize wan2.7 i2v image inputs
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
* feat: support Wan2.7 i2v media mapping

* fix: normalize wan2.7 i2v image inputs
dofastted pushed a commit to dofastted/new-api that referenced this pull request Sep 16, 2026
* feat: support Wan2.7 i2v media mapping

* fix: normalize wan2.7 i2v image inputs

(cherry picked from commit 52858ad)
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
* feat: support Wan2.7 i2v media mapping

* fix: normalize wan2.7 i2v image inputs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants