Repository navigation
h3 - #6662
h3#6662guanguan669 wants to merge 9 commits into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughThis change adds Kuocai as channel 61. It registers OpenAI-compatible video mappings, discovers video models from ChangesKuocai video channel
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant RelayAdaptor
participant TaskAdaptor
participant KuocaiAPI
Client->>RelayAdaptor: Submit video request
RelayAdaptor->>TaskAdaptor: Build and send Kuocai task
TaskAdaptor->>KuocaiAPI: Authenticated task submission
KuocaiAPI-->>TaskAdaptor: Task ID and pending status
TaskAdaptor-->>Client: OpenAI-compatible pending video
Client->>TaskAdaptor: Fetch task by task ID
TaskAdaptor->>KuocaiAPI: Authenticated task polling request
KuocaiAPI-->>TaskAdaptor: Status, progress, and result URL
TaskAdaptor-->>Client: OpenAI-compatible video result
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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/kuocai/adaptor_test.go`:
- Around line 18-30: The TestConvertRequestUsesConfiguredNumericModelID test
should include metadata containing model_id set to 39 while the configured model
mapping remains "51", then assert body.ModelID is still 51 after convertRequest.
Keep the existing assertions for duration, count, and resolution unchanged.
In `@relay/channel/task/kuocai/adaptor.go`:
- Around line 35-48: Update the request struct containing ModelID, Size,
Seconds, Resolution, and Count so optional scalar fields use pointer types with
omitempty, preserving explicit zero and empty-string values during
common.Marshal; keep pointers nil only when metadata is absent. Apply the same
treatment to any other optional scalar fields in this struct, while retaining
existing non-scalar fields and tags.
🪄 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: b6659591-dbc2-43db-8fde-d826f4fad617
📒 Files selected for processing (7)
common/api_type.gocommon/endpoint_type.goconstant/channel.gorelay/channel/task/kuocai/adaptor.gorelay/channel/task/kuocai/adaptor_test.gorelay/relay_adaptor.goweb/src/features/channels/constants.ts
| func TestConvertRequestUsesConfiguredNumericModelID(t *testing.T) { | ||
| body, err := convertRequest(relaycommon.TaskSubmitReq{ | ||
| Prompt: "A sunset over the sea", | ||
| Size: "16:9", | ||
| Duration: 8, | ||
| Metadata: map[string]interface{}{"resolution": "720P", "count": 2}, | ||
| }, "51") | ||
| require.NoError(t, err) | ||
| require.Equal(t, 51, body.ModelID) | ||
| require.Equal(t, 8, body.Seconds) | ||
| require.Equal(t, 2, body.Count) | ||
| require.Equal(t, "720P", body.Resolution) | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Test metadata cannot override the configured model ID.
Add a case with metadata model_id: 39 and configured model mapping "51". Assert that body.ModelID remains 51.
This protects the configured upstream model selection after metadata unmarshaling.
As per coding guidelines, “Backend tests must protect real behavior, API contracts, billing/accounting invariants, compatibility, or regression paths.”
🤖 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/kuocai/adaptor_test.go` around lines 18 - 30, The
TestConvertRequestUsesConfiguredNumericModelID test should include metadata
containing model_id set to 39 while the configured model mapping remains "51",
then assert body.ModelID is still 51 after convertRequest. Keep the existing
assertions for duration, count, and resolution unchanged.
Source: Coding guidelines
| ModelID int `json:"model_id,omitempty"` | ||
| Prompt string `json:"prompt"` | ||
| Size string `json:"size,omitempty"` | ||
| Seconds int `json:"seconds,omitempty"` | ||
| Resolution string `json:"resolution,omitempty"` | ||
| Count int `json:"count,omitempty"` | ||
| ReferenceImage string `json:"reference_image,omitempty"` | ||
| ReferenceImages []string `json:"reference_images,omitempty"` | ||
| FrameStart string `json:"frame_start,omitempty"` | ||
| FrameEnd string `json:"frame_end,omitempty"` | ||
| ReferenceAudio string `json:"reference_audio,omitempty"` | ||
| ReferenceAudios []string `json:"reference_audios,omitempty"` | ||
| ReferenceVideo string `json:"reference_video,omitempty"` | ||
| ReferenceVideos []string `json:"reference_videos,omitempty"` |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Preserve explicit optional scalar values.
These fields combine non-pointer scalar types with omitempty. An explicit metadata value such as count: 0, seconds: 0, or resolution: "" is dropped when common.Marshal creates the upstream request.
Use pointer types for optional scalar fields. Set nil only when the field is absent. Remove omitempty from fields that must always be sent.
As per coding guidelines, “Optional scalar fields in client-parsed and upstream-remarshaled request structs must use pointer types with omitempty.”
🤖 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/kuocai/adaptor.go` around lines 35 - 48, Update the
request struct containing ModelID, Size, Seconds, Resolution, and Count so
optional scalar fields use pointer types with omitempty, preserving explicit
zero and empty-string values during common.Marshal; keep pointers nil only when
metadata is absent. Apply the same treatment to any other optional scalar fields
in this struct, while retaining existing non-scalar fields and tags.
Source: Coding guidelines
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
controller/channel_upstream_update_test.go (1)
411-437: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winStrengthen the Kuocai discovery contract test.
Initialize the channel setting explicitly before calling
fetchChannelUpstreamModelIDs; this path reacheschannel.GetSetting().Proxy. Also assertr.Method == http.MethodGetand add deterministic cases for malformed JSON, non-200 HTTP or application status, no video models, and non-positivemodel_idvalues. The current test covers only the successful response.As per coding guidelines, backend tests must initialize settings explicitly and protect real behavior with deterministic contract coverage.
🤖 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/channel_upstream_update_test.go` around lines 411 - 437, Strengthen TestFetchKuocaiModelsUsesHealthAndExcludesImages by initializing the channel’s setting before calling fetchChannelUpstreamModelIDs, and assert the health request uses http.MethodGet. Add deterministic table-driven coverage for malformed JSON, non-200 HTTP/application status, no video models, and non-positive model_id values, verifying the expected error or empty result for each case.Source: Coding guidelines
🤖 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/channel_upstream_update.go`:
- Around line 433-443: Bound the Kuocai health request in
fetchKuocaiUpstreamModelIDs so it cannot stall indefinitely, using a
timeout-aware request/client path for getFetchModelsResponseBody. Before
common.Unmarshal processes the response, cap the readable body size and reject
oversized payloads rather than loading the full response into memory. Preserve
the existing error propagation for request and decoding failures.
---
Nitpick comments:
In `@controller/channel_upstream_update_test.go`:
- Around line 411-437: Strengthen
TestFetchKuocaiModelsUsesHealthAndExcludesImages by initializing the channel’s
setting before calling fetchChannelUpstreamModelIDs, and assert the health
request uses http.MethodGet. Add deterministic table-driven coverage for
malformed JSON, non-200 HTTP/application status, no video models, and
non-positive model_id values, verifying the expected error or empty result for
each case.
🪄 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: 52db11f1-ca0d-4139-b478-4babba569486
📒 Files selected for processing (2)
controller/channel_upstream_update.gocontroller/channel_upstream_update_test.go
| func fetchKuocaiUpstreamModelIDs(channel *model.Channel, baseURL string) ([]string, error) { | ||
| body, err := getFetchModelsResponseBody( | ||
| http.MethodGet, | ||
| strings.TrimRight(baseURL, "/")+"/health", | ||
| channel, | ||
| http.Header{}, | ||
| ) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n -C 10 'func NewProxyHttpClient|NewProxyHttpClient|io\.ReadAll' --glob '*.go'Repository: QuantumNous/new-api
Length of output: 157
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'Go files matching likely names:\n'
fd -e go . | sed -n '1,120p'
printf '\nFind file:\n'
fd 'channel_upstream_update\.go$|.*channel.*upstream.*\.go$|.*proxy.*http.*\.go$|.*service.*\.go$' . -d 4
printf '\nSearch exact symbols and request helpers:\n'
rg -n -C 8 'fetchKuocaiUpstreamModelIDs|getFetchModelsResponseBody|FetchUpstreamModels|ReadAll|NewClient|Timeout|context\.Deadline|context\.WithTimeout|http\.Request' --glob '*.go' | sed -n '1,240p'Repository: QuantumNous/new-api
Length of output: 3300
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'channel_upstream_update outline:\n'
ast-grep outline controller/channel_upstream_update.go --view compact || true
printf '\nRelevant controller sections:\n'
rg -n -C 15 'fetchKuocaiUpstreamModelIDs|getFetchModelsResponseBody|FetchUpstreamModels|service\.NewProxyHttpClient|NewProxyHttpClient|ReadAll|NewRequestWithContext|Timeout|context\.WithTimeout' controller/channel_upstream_update.go common service relay --glob '*.go' | sed -n '1,320p'
printf '\nRead target file length and focused sections:\n'
wc -l controller/channel_upstream_update.go
sed -n '1,140p' controller/channel_upstream_update.go
sed -n '380,490p' controller/channel_upstream_update.go
sed -n '490,540p' controller/channel_upstream_update.goRepository: QuantumNous/new-api
Length of output: 28339
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'service.go files:\n'
fd -e go . | rg '/service/|/service' || true
printf '\nSearch NewProxyHttpClient in all tracked files:\n'
git ls-files | xargs rg -n -C 12 'func NewProxyHttpClient|NewProxyHttpClient|ProxyHttpClient'\
| sed -n '1,260p'
printf '\nSearch response body limits in channel_upstream_update and common:\n'
rg -n -C 8 'ReadAll|LimitReader|max.*response|response.*limit|ReadCloser|NewProxyHttpClient|context\.WithTimeout|context\.Deadline' --glob '*.go' controller/common | sed -n '1,320p'Repository: QuantumNous/new-api
Length of output: 4811
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'service/http_client relevant sections:\n'
wc -l service/http_client.go
sed -n '1,180p' service/http_client.go
sed -n '360,455p' service/http_client.go
printf '\nGetHttpClientWithProxy and transport policy callers:\n'
rg -n -C 8 'func GetHttpClientWithProxy|defaultHTTPTransportPolicy|HTTPTimeout|Timeout|IdleConnTimeout|MaxIdleConnsPerHost|MaxConnsPerHost' service relay controller --glob '*.go' | sed -n '1,400p'Repository: QuantumNous/new-api
Length of output: 34370
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'service/http_client.go mid-section:\n'
sed -n '180,355p' service/http_client.go
printf '\nservice/http_client.go later sections:\n'
sed -n '355,446p' service/http_client.go
printf '\nFetch models endpoint for Kuocai /health:\n'
rg -n -C 6 'ChannelTypeKuocai|kuocai|/health|fetchKuocaiUpstreamModelIDs|FetchUpstreamModels' controller/common service relay --glob '*.go' | sed -n '1,260p'
printf '\nRelevant controller test references:\n'
rg -n -C 8 'Kuocai|fetchKuocaiUpstreamModelIDs|health|FetchUpstreamModels' controller/channel_upstream_update_test.go --glob '*.go' | sed -n '1,220p'Repository: QuantumNous/new-api
Length of output: 13294
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'http transport/policy definitions:\n'
rg -n -C 12 'type HTTPTransportPolicy|defaultHTTPTransportPolicy|NormalizeHTTPTransportPolicy|HTTPTimeout|ClientTimeout|Timeout|RespBodyLimit|applyHTTPTransportPolicy' --glob '*.go' service common relaykit setting constant --glob '*.go' | sed -n '1,320p'
printf '\nAll response body reader helper patterns:\n'
rg -n -C 8 'ReadAll|io\.LimitReader|RespBodyLimit|Max.*Response|response.*size|body.*limit|ReadCloser' --glob '*.go' controller service relaykit relay common constant setting | sed -n '1,400p'
printf '\nFetchUpstreamModels callers:\n'
rg -n -C 12 'FetchUpstreamModels|ctx, cancel := context\.WithTimeout|time\.After|go\s+collect' --glob '*.go' controller service relaykit relay common | sed -n '1,260p'Repository: QuantumNous/new-api
Length of output: 50375
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'http transport policy struct and implementation:\n'
rg -n -C 16 'type HTTPTransportPolicy struct|HTTPTimeout|ClientTimeout|ApplyHTTPTransportPolicy|applyHTTPTransportPolicy|ResetTimeout|DialContext|TLSHandshakeTimeout' service/http_client.go --glob '*.go' | sed -n '1,320p'
printf '\nRelevant service/http_client.go ranges around transport factory implementation:\n'
wc -l service/http_client.go
sed -n '230,330p' service/http_client.go
sed -n '360,425p' service/http_client.go
printf '\ncontroller/channel_upstream_update.go relevant handler range:\n'
sed -n '540,740p' controller/channel_upstream_update.goRepository: QuantumNous/new-api
Length of output: 17141
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'http_client.go top-level imports and policy-related symbols:\n'
sed -n '1,85p' service/http_client.go
rg -n -C 10 'type HTTPTransportPolicy struct|HTTPHTTP1|HTTP2|HTTP3|HTTPS|Timeout|ResponseHeaderTimeout|DisableCompression|MaxIdleConns|EnableCompression|ResetTimeout|ResetIdleConnTimeout|Dialer|context\.WithTimeout|DialContext' service/http_client.go --glob '*.go' | sed -n '1,420p'
printf '\nSearch for transport policy file or DTO:\n'
fd -e go . | rg 'http_client|transport|policy|dto' | sed -n '1,120p'
rg -n -C 8 'DefaultHTTPTimeout|HTTPTimeout|MaxIdleConnTimeout|HTTPIdleConnTimeout|HTTP2|HTTP3|HTTP1' --glob '*.go' | sed -n '1,320p'Repository: QuantumNous/new-api
Length of output: 7220
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'service/http_transport_policy.go:\n'
sed -n '1,240p' service/http_transport_policy.go
printf '\nservice/http_transport_sharded.go relevant range:\n'
sed -n '1,220p' service/http_transport_sharded.go
printf '\nchannel_upstream_update FetchUpstreamModels exact section:\n'
rg -n -C 20 'func FetchUpstreamModels|runChannelUpstreamModelUpdateTaskOnce|collectPendingUpstreamModelChanges|FetchUpstreamModels' controller/channel_upstream_update.go | sed -n '1,260p'
printf '\ncontroller/channel_upstream_update_test Kuocai/model fetch tests:\n'
rg -n -C 20 'kuocai|Kuocai|health|FetchUpstreamModels|upstream model' controller/channel_upstream_update_test.go | sed -n '1,260p'Repository: QuantumNous/new-api
Length of output: 14963
Bound the Kuocai health response before unmarshaling.
getFetchModelsResponseBody uses a client with no configured Timeout, so the synchronous Cuocai /health request can stall indefinitely. Also, line 333 reads the full response.Body into memory; use a response-size limit before common.Unmarshal.
🤖 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/channel_upstream_update.go` around lines 433 - 443, Bound the
Kuocai health request in fetchKuocaiUpstreamModelIDs so it cannot stall
indefinitely, using a timeout-aware request/client path for
getFetchModelsResponseBody. Before common.Unmarshal processes the response, cap
the readable body size and reject oversized payloads rather than loading the
full response into memory. Preserve the existing error propagation for request
and decoding failures.
51fdfc5 to
2b6f1df
Compare
Important
📝 变更描述 / Description
(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
(请在此粘贴截图、关键日志或测试报告,以证明变更生效)
Summary by CodeRabbit
New Features
Bug Fixes
Tests