Skip to content

feat(video): support Agnes task status and result URLs - #6699

Open
linuxroc wants to merge 1 commit into
QuantumNous:mainfrom
linuxroc:fix/agnes-video-status
Open

feat(video): support Agnes task status and result URLs#6699
linuxroc wants to merge 1 commit into
QuantumNous:mainfrom
linuxroc:fix/agnes-video-status

Conversation

@linuxroc

@linuxroc linuxroc commented Aug 7, 2026

Copy link
Copy Markdown

⚠️ 提交说明 / PR Notice

Important

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

📝 变更描述 / Description

为 Agnes 官方 API 主机 apihub.agnes-ai.com 补充异步视频任务兼容:

  • 状态轮询改用 /agnesapi?video_id=<id>
  • 任务完成后读取 metadata.url,并由现有视频代理在 SSRF 校验后转发该绝对 URL。
  • 转发 Agnes CDN 结果时不携带渠道密钥。
  • 使用 URL 解析后的精确 hostname 判断 Agnes;其他 OpenAI/Sora 渠道继续使用原有 /v1/videos/{id}/content 路径和鉴权逻辑。

AI assistance disclosure: This change was prepared with AI assistance. The scope constraints, implementation, and tests were reviewed during preparation; no credentials or deployment changes are included.

🚀 变更类型 / Type of change

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

🔗 关联任务 / Related Issue

  • N/A

✅ 提交前检查项 / Checklist

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

📸 运行证明 / Proof of Work

go test ./relay/channel/task/taskcommon ./relay/channel/task/sora ./controller
ok github.com/QuantumNous/new-api/relay/channel/task/taskcommon
ok github.com/QuantumNous/new-api/relay/channel/task/sora
ok github.com/QuantumNous/new-api/controller

go test ./relay/channel/task/... ./service
# all task adapter packages passed; the one unrelated service package failure passed when rerun in isolation
go test ./service -run TestObserveChannelAffinityUsageCacheByRelayFormat_UnsupportedModeKeepsEmpty -count=1
ok github.com/QuantumNous/new-api/service

Summary by CodeRabbit

  • Bug Fixes
    • Improved video task handling for Agnes API endpoints.
    • Completed Agnes video tasks now use the returned video URL when available.
    • Agnes tasks use the appropriate status endpoint for reliable progress updates.
    • Preserved standard video URL and authentication behavior for other providers.
    • Added safeguards to prevent lookalike or invalid domains from being treated as Agnes endpoints.
    • Improved reliability when retrieving and displaying completed video results.

@coderabbitai

coderabbitai Bot commented Aug 7, 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 Plus

Run ID: c122ac36-f31a-4b30-984f-6f6546fcf649

📥 Commits

Reviewing files that changed from the base of the PR and between b941253 and 6ea8f13.

📒 Files selected for processing (6)
  • controller/video_proxy.go
  • controller/video_proxy_test.go
  • relay/channel/task/sora/adaptor.go
  • relay/channel/task/sora/adaptor_test.go
  • relay/channel/task/taskcommon/provider.go
  • relay/channel/task/taskcommon/provider_test.go
🚧 Files skipped from review as they are similar to previous changes (6)
  • controller/video_proxy.go
  • relay/channel/task/sora/adaptor_test.go
  • relay/channel/task/taskcommon/provider_test.go
  • relay/channel/task/taskcommon/provider.go
  • controller/video_proxy_test.go
  • relay/channel/task/sora/adaptor.go

Walkthrough

The Sora adapter now uses Agnes-specific status URLs and extracts Agnes metadata video URLs. The video proxy accepts validated Agnes result URLs without channel authentication. Other providers retain their standard endpoints and bearer authentication.

Changes

Agnes video URL handling

Layer / File(s) Summary
Provider classification and URL contract
relay/channel/task/taskcommon/provider.go, relay/channel/task/taskcommon/provider_test.go
Adds IsAgnesAPIBaseURL with URL parsing, hostname validation, trimming, case-insensitive matching, and lookalike-domain tests.
Task fetching and result parsing
relay/channel/task/sora/adaptor.go, relay/channel/task/sora/adaptor_test.go
Uses /agnesapi?video_id={taskID} for Agnes. Extracts metadata.url for completed Agnes tasks. Preserves standard behavior for other providers.
Video content URL resolution
controller/video_proxy.go, controller/video_proxy_test.go
Uses valid Agnes result URLs without channel authentication. Uses the standard content endpoint and authentication for other cases. Tests cover fallback and lookalike domains.

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

Sequence Diagram(s)

sequenceDiagram
  participant VideoProxy
  participant TaskAdapter
  participant AgnesAPI
  VideoProxy->>TaskAdapter: resolve task result URL
  TaskAdapter->>AgnesAPI: fetch /agnesapi?video_id={taskID}
  AgnesAPI-->>TaskAdapter: return metadata.url
  TaskAdapter-->>VideoProxy: provide validated result URL
  VideoProxy->>AgnesAPI: request result URL without channel authentication
Loading

Poem

A rabbit checks the Agnes gate,
Builds the path and waits in state.
A video URL hops in view,
With trusted hosts and tests held true.
Other providers keep their track—
Their bearer path still leads them back.

🚥 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 clearly summarizes the main change: adding Agnes task status and result URL support for video tasks.
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: 1

🤖 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 `@controller/video_proxy.go`:
- Around line 116-120: Update the Authorization header assignment in the
content-request flow around resolveOpenAIVideoContentURL to prefer
task.PrivateData.Key when present, falling back to channel.Key only when the
stored task key is unavailable. Preserve the existing Bearer format and apply
this credential selection for both non-Agnes content and Agnes fallback
requests.
🪄 Autofix

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 Plus

Run ID: f48fa880-bbd4-4f95-9832-90c740f362f1

📥 Commits

Reviewing files that changed from the base of the PR and between c9bc038 and b2183c2.

📒 Files selected for processing (6)
  • controller/video_proxy.go
  • controller/video_proxy_test.go
  • relay/channel/task/sora/adaptor.go
  • relay/channel/task/sora/adaptor_test.go
  • relay/channel/task/taskcommon/provider.go
  • relay/channel/task/taskcommon/provider_test.go

Comment thread controller/video_proxy.go
Comment on lines +116 to +120
var useChannelAuth bool
videoURL, useChannelAuth = resolveOpenAIVideoContentURL(baseURL, task.GetUpstreamTaskID(), task.GetResultURL())
if useChannelAuth {
req.Header.Set("Authorization", "Bearer "+channel.Key)
}

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Reuse the stored task credential for content requests.

For non-Agnes content and Agnes fallback requests, Line 119 uses mutable channel.Key. A key rotation or per-task key causes the content request to use a different credential than task submission.

Use task.PrivateData.Key when it is present. Use channel.Key only as a legacy fallback.

Proposed fix
 case constant.ChannelTypeOpenAI, constant.ChannelTypeSora:
 	var useChannelAuth bool
 	videoURL, useChannelAuth = resolveOpenAIVideoContentURL(baseURL, task.GetUpstreamTaskID(), task.GetResultURL())
 	if useChannelAuth {
-		req.Header.Set("Authorization", "Bearer "+channel.Key)
+		apiKey := task.PrivateData.Key
+		if apiKey == "" {
+			apiKey = channel.Key
+		}
+		req.Header.Set("Authorization", "Bearer "+apiKey)
 	}

Based on learnings, follow-up requests must reuse authentication captured at task submission time and prefer task.PrivateData.Key.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
var useChannelAuth bool
videoURL, useChannelAuth = resolveOpenAIVideoContentURL(baseURL, task.GetUpstreamTaskID(), task.GetResultURL())
if useChannelAuth {
req.Header.Set("Authorization", "Bearer "+channel.Key)
}
var useChannelAuth bool
videoURL, useChannelAuth = resolveOpenAIVideoContentURL(baseURL, task.GetUpstreamTaskID(), task.GetResultURL())
if useChannelAuth {
apiKey := task.PrivateData.Key
if apiKey == "" {
apiKey = channel.Key
}
req.Header.Set("Authorization", "Bearer "+apiKey)
}
🤖 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 `@controller/video_proxy.go` around lines 116 - 120, Update the Authorization
header assignment in the content-request flow around
resolveOpenAIVideoContentURL to prefer task.PrivateData.Key when present,
falling back to channel.Key only when the stored task key is unavailable.
Preserve the existing Bearer format and apply this credential selection for both
non-Agnes content and Agnes fallback requests.

Source: Learnings

@linuxroc
linuxroc force-pushed the fix/agnes-video-status branch from b2183c2 to 77f2b2e Compare August 7, 2026 05:55
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@linuxroc
linuxroc force-pushed the fix/agnes-video-status branch from 77f2b2e to 6ea8f13 Compare August 7, 2026 05:57
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

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.

1 participant