Skip to content

alpha search - #30

Merged
CSCITech merged 10 commits into
mainfrom
cscitech
Aug 10, 2026
Merged

CSCITech merged 10 commits into
mainfrom
cscitech

Conversation

@CSCITech

@CSCITech CSCITech commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

⚠️ 提交说明 / PR Notice

Important

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

📝 变更描述 / Description

(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)

🚀 变更类型 / Type of change

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

🔗 关联任务 / Related Issue

  • Closes # (如有)

✅ 提交前检查项 / Checklist

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

📸 运行证明 / Proof of Work

(请在此粘贴截图、关键日志或测试报告,以证明变更生效)

@coderabbitai

coderabbitai Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a0ab5882-34f1-4cdb-9359-579d1d132d6a

📥 Commits

Reviewing files that changed from the base of the PR and between 2d89c82 and bb40ae8.

📒 Files selected for processing (5)
  • controller/misc.go
  • controller/misc_test.go
  • model/main.go
  • service/midjourney.go
  • service/midjourney_test.go
📜 Recent review details
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.go: In Go business code, all JSON marshal/unmarshal operations must use the wrapper functions in common/json.go (common.Marshal, common.Unmarshal, common.UnmarshalJsonStr, common.DecodeJson, common.GetJsonType) and must not directly call encoding/json for actual encode/decode work.
All database code must be compatible with SQLite, MySQL 5.7.8+, and PostgreSQL 9.6+; prefer GORM abstractions over raw SQL, avoid direct AUTO_INCREMENT/SERIAL, use commonGroupCol/commonKeyCol and commonTrueVal/commonFalseVal for DB-specific SQL, branch with common.UsingPostgreSQL/common.UsingSQLite/common.UsingMySQL, avoid unsupported DB-specific functions/operators without fallback, and make migrations work across all three databases.
When implementing a new relay channel, confirm whether the provider supports StreamOptions; if it does, add that channel to streamSupportedChannels.
For request structs parsed from client JSON and re-marshaled to upstream providers, optional scalar fields must use pointer types with omitempty so explicit zero/false values are preserved instead of dropped.
When working on tiered/dynamic billing expression code, read pkg/billingexpr/expr.md first and follow its documented expression language, architecture, token normalization, quota conversion, and versioning patterns.

**/*.go: All JSON marshal/unmarshal operations in Go business code must use the wrapper functions in common/json.go (common.Marshal, common.Unmarshal, common.UnmarshalJsonStr, common.DecodeJson, common.GetJsonType) instead of directly importing or calling encoding/json for actual marshal/unmarshal work.
All database code in Go must remain compatible with SQLite, MySQL >= 5.7.8, and PostgreSQL >= 9.6; prefer GORM abstractions, avoid raw SQL unless necessary, use the shared DB helper variables for reserved words and boolean literals, branch with the common.UsingPostgreSQL / common.UsingSQLite / common.UsingMySQL flags when need...

Files:

  • service/midjourney.go
  • controller/misc_test.go
  • service/midjourney_test.go
  • controller/misc.go
  • model/main.go
🔇 Additional comments (13)
controller/misc.go (4)

4-9: LGTM!


45-58: LGTM!


60-63: LGTM!


73-84: LGTM!

model/main.go (2)

4-4: LGTM!


1134-1163: LGTM!

controller/misc_test.go (5)

1-35: LGTM!


37-60: LGTM!


62-80: LGTM!


82-110: LGTM!


112-133: LGTM!

service/midjourney.go (1)

87-147: LGTM!

Also applies to: 171-171, 180-190

service/midjourney_test.go (1)

13-14: LGTM!

Also applies to: 87-115, 117-125, 127-143, 145-165, 167-185, 186-194


📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added OpenAI Alpha Search through POST /v1/alpha/search, with Codex and compatible custom-channel support.
    • Added cURL, Python, JavaScript, and TypeScript API examples.
    • Added localized endpoint labels and descriptions.
    • Added public health, liveness, and readiness checks.
  • Billing

    • Added quota tracking for web-search activity, including surcharge-only usage.
  • Bug Fixes

    • Improved endpoint selection, validation, and quota calculations.
    • Improved billing error handling, malformed Midjourney action handling, and user credential cleanup.

Walkthrough

The change adds OpenAI Alpha Search support through /v1/alpha/search, including validation, routing, Codex forwarding, channel selection, billing, pricing, web configuration, tests, and request samples. It also validates billing display settings, adds health endpoints, strengthens user deletion cleanup, and validates Midjourney custom IDs.

Changes

OpenAI Alpha Search

Layer / File(s) Summary
Endpoint contracts and ingress
constant/*, types/*, relay/constant/*, dto/*, relay/helper/*, relay/common/*, router/*, common/endpoint_defaults.go
Adds Alpha Search constants, request validation, relay metadata, default mapping, and the POST route.
Channel selection and endpoint pricing
common/endpoint_type.go, model/ability.go, model/channel_cache.go, model/pricing.go, model/*_test.go, tools/jsonwrapcheck/allowlist.txt
Adds endpoint priority, path filtering, advanced-custom route resolution, and pricing endpoint derivation.
Alpha Search relay forwarding
relay/alpha_search_handler.go, relay/channel/codex/*, controller/relay.go, controller/channel-test.go, relay/*_test.go, controller/*_test.go
Maps and forwards requests, handles responses, records web-search usage, and updates channel tests.
Alpha Search quota billing
service/alpha_search_billing.go, service/text_quota.go, service/tiered_settle.go, service/*_test.go
Adds quota pre-consumption and integrates tool surcharges with standard and tiered settlement.
Web endpoint configuration
web/default/src/features/channels/*, web/default/src/features/pricing/*, web/default/src/i18n/locales/*
Adds endpoint options, pricing metadata, request samples, labels, text-input metadata, and translations.

Billing display validation

Layer / File(s) Summary
Validated billing responses
controller/billing.go, controller/billing_test.go
Validates quota display conversion and returns structured errors from subscription and usage endpoints.

Health check endpoints

Layer / File(s) Summary
Health handlers and routes
controller/misc.go, controller/misc_test.go, model/main.go, router/api-router.go, router/api_router_test.go
Adds health and liveness responses, uncached database readiness probes, public routes, and route and handler tests.

User deletion cleanup

Layer / File(s) Summary
Credential and subscription cleanup
model/user.go, model/user_delete_test.go, model/task_cas_test.go
Cleans OAuth bindings, subscriptions, access tokens, and user tokens during soft and hard deletion.

Midjourney custom ID validation

Layer / File(s) Summary
Safe custom ID conversion
service/midjourney.go, service/midjourney_test.go
Validates custom ID segments and indexes before converting actions.

Estimated code review effort: 5 (Critical) | ~100 minutes

Possibly related PRs

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant RelayRouter
  participant AlphaSearchHelper
  participant CodexAdaptor
  participant UpstreamAlphaSearch
  participant QuotaService
  Client->>RelayRouter: POST /v1/alpha/search
  RelayRouter->>AlphaSearchHelper: Validate AlphaSearchRequest
  AlphaSearchHelper->>CodexAdaptor: Build and send mapped JSON
  CodexAdaptor->>UpstreamAlphaSearch: POST /backend-api/codex/alpha/search
  UpstreamAlphaSearch-->>AlphaSearchHelper: Return non-streaming response
  AlphaSearchHelper->>QuotaService: Record web-search usage and consume quota
  AlphaSearchHelper-->>Client: Forward response
Loading

Poem

A rabbit mapped the Alpha route,
Search fields hopped in and out.
Models flowed and quotas tallied,
Unknown JSON stayed safely carried.
“POST is live!” the rabbit cried.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description contains only an unfilled template and does not explain the implemented changes, rationale, or validation. Replace the template with a concise summary of the Alpha Search changes, their rationale, and the tests or validation performed.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title identifies the primary Alpha Search feature added by the changeset.
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 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cscitech

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

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/alpha_search_handler.go`:
- Around line 92-110: Move the web-search usage initialization for
dto.BuildInToolWebSearchPreview and the service.PostTextConsumeQuota call in the
Alpha Search handler to immediately after the successful upstream status check,
before c.Writer.WriteHeader and io.Copy. Ensure billing is settled even when
response-body copying fails, while preserving the existing usage metadata and
error return behavior.
- Line 58: Replace the complete request-body logging in the Alpha Search handler
with debug metadata only, such as the model name and serialized body size; do
not pass jsonData or any equivalent prompt/request contents to logger.LogDebug.
🪄 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: ASSERTIVE

Plan: Pro Plus

Run ID: 3e339a67-d6ae-4cee-bc9f-07939537e3ea

📥 Commits

Reviewing files that changed from the base of the PR and between c2ef01d and c0ee2ad.

📒 Files selected for processing (37)
  • common/endpoint_defaults.go
  • common/endpoint_type.go
  • common/endpoint_type_test.go
  • constant/endpoint_type.go
  • controller/channel-test.go
  • controller/channel_test_internal_test.go
  • controller/relay.go
  • dto/alpha_search_request.go
  • relay/alpha_search_handler.go
  • relay/alpha_search_handler_test.go
  • relay/channel/codex/adaptor.go
  • relay/channel/codex/adaptor_test.go
  • relay/common/relay_info.go
  • relay/constant/relay_mode.go
  • relay/constant/relay_mode_test.go
  • relay/helper/alpha_search_request_test.go
  • relay/helper/valid_request.go
  • router/relay-router.go
  • router/relay_router_test.go
  • service/alpha_search_billing.go
  • service/alpha_search_billing_test.go
  • service/text_quota.go
  • service/text_quota_test.go
  • service/tiered_settle.go
  • types/relay_format.go
  • web/default/src/features/channels/components/dialogs/channel-test-dialog.tsx
  • web/default/src/features/channels/lib/advanced-custom.test.ts
  • web/default/src/features/channels/lib/advanced-custom.ts
  • web/default/src/features/pricing/components/model-details-api.tsx
  • web/default/src/features/pricing/constants.ts
  • web/default/src/features/pricing/lib/model-metadata.ts
  • web/default/src/i18n/locales/en.json
  • web/default/src/i18n/locales/fr.json
  • web/default/src/i18n/locales/ja.json
  • web/default/src/i18n/locales/ru.json
  • web/default/src/i18n/locales/vi.json
  • web/default/src/i18n/locales/zh.json
📜 Review details
🧰 Additional context used
📓 Path-based instructions (8)
**/*.go

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.go: In Go business code, all JSON marshal/unmarshal operations must use the wrapper functions in common/json.go (common.Marshal, common.Unmarshal, common.UnmarshalJsonStr, common.DecodeJson, common.GetJsonType) and must not directly call encoding/json for actual encode/decode work.
All database code must be compatible with SQLite, MySQL 5.7.8+, and PostgreSQL 9.6+; prefer GORM abstractions over raw SQL, avoid direct AUTO_INCREMENT/SERIAL, use commonGroupCol/commonKeyCol and commonTrueVal/commonFalseVal for DB-specific SQL, branch with common.UsingPostgreSQL/common.UsingSQLite/common.UsingMySQL, avoid unsupported DB-specific functions/operators without fallback, and make migrations work across all three databases.
When implementing a new relay channel, confirm whether the provider supports StreamOptions; if it does, add that channel to streamSupportedChannels.
For request structs parsed from client JSON and re-marshaled to upstream providers, optional scalar fields must use pointer types with omitempty so explicit zero/false values are preserved instead of dropped.
When working on tiered/dynamic billing expression code, read pkg/billingexpr/expr.md first and follow its documented expression language, architecture, token normalization, quota conversion, and versioning patterns.

**/*.go: All JSON marshal/unmarshal operations in Go business code must use the wrapper functions in common/json.go (common.Marshal, common.Unmarshal, common.UnmarshalJsonStr, common.DecodeJson, common.GetJsonType) instead of directly importing or calling encoding/json for actual marshal/unmarshal work.
All database code in Go must remain compatible with SQLite, MySQL >= 5.7.8, and PostgreSQL >= 9.6; prefer GORM abstractions, avoid raw SQL unless necessary, use the shared DB helper variables for reserved words and boolean literals, branch with the common.UsingPostgreSQL / common.UsingSQLite / common.UsingMySQL flags when need...

Files:

  • relay/constant/relay_mode_test.go
  • router/relay_router_test.go
  • common/endpoint_type_test.go
  • common/endpoint_defaults.go
  • types/relay_format.go
  • common/endpoint_type.go
  • router/relay-router.go
  • relay/channel/codex/adaptor_test.go
  • relay/constant/relay_mode.go
  • service/text_quota_test.go
  • relay/common/relay_info.go
  • relay/channel/codex/adaptor.go
  • relay/alpha_search_handler.go
  • dto/alpha_search_request.go
  • controller/channel_test_internal_test.go
  • relay/helper/alpha_search_request_test.go
  • service/alpha_search_billing.go
  • controller/relay.go
  • relay/alpha_search_handler_test.go
  • controller/channel-test.go
  • service/text_quota.go
  • relay/helper/valid_request.go
  • constant/endpoint_type.go
  • service/alpha_search_billing_test.go
  • service/tiered_settle.go
web/default/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (web/default/AGENTS.md)

web/default/src/**/*.{ts,tsx}: 前端页面文本与组件内文案必须支持 i18n:React 组件中应使用 useTranslation() 取得 t,并通过 t() 渲染用户可见文本;子组件也应自行使用 useTranslation() 保持独立性。
禁止使用两层及以上嵌套三元表达式;复杂逻辑应改用 if-else、提前返回或抽取函数。
控制函数圈复杂度,复杂逻辑应拆成更小的函数;变量与函数命名应有意义并遵循驼峰等常规命名约定。
TypeScript 代码应避免使用 any,优先使用具体类型或 unknown;参数与返回值应显式标注类型;仅类型用途的导入应使用 import type。
修改 TypeScript 或 TSX 代码后必须执行类型检查,并修复所有类型错误,不得遗留。
对象非必要不要解构,尤其是组件 props;优先直接使用 props.xxx 以保持代码清晰。
组件应使用函数式组件与 Hooks,遵循单一职责;组件 props 必须有明确类型(接口或类型别名)。
单文件超过约 200 行时应考虑拆分子组件或抽取自定义 Hooks;类型定义可与组件同文件或放在同模块的 types 中。
在 React 中应合理使用 useMemo、useCallback、React.memo,避免在渲染路径中创建新对象或数组;必要时进行代码分割与动态 import。
React Query 的数据获取应使用 useQuery、变更应使用 useMutation;每个查询需配置唯一 queryKey,并在成功后对相关查询执行 invalidateQueries;服务端错误应统一交给 handleServerError。
Axios 请求应使用项目统一的 api 实例;GET 请求默认去重,特殊请求可显式关闭;认证与通用错误应在拦截器中统一处理。
服务端错误应统一使用 handleServerError,展示层应使用 toast.error 等统一方式;文案需走 i18n;路由级错误应由 errorComponent 承接;表单错误应通过 form.setError 等方式映射到字段。
样式应以 Tailwind 工具类为主,动态类名使用 cn() 合并;非动态场景避免内联样式;响应式采用移动优先与 Tailwind 断点,主题与暗色模式通过 CSS 变量与 dark: 处理。
应使用语义化 HTML、正确关联 label 与输入、保证键盘可操作与合理焦点顺序;必要时添加 ARIA 属性,装饰性图标应使用 aria-hidden="true"。
认证与权限应在路由与接口层校验;前后端都应做数据校验(如 Zod);敏感信息不得落前端存储;避免使用 dangerouslySetInnerHTML;跨域与 Cookie 需配合 withCredentials 并按后端要求处理 CSRF。
组件测试应使用 React Testing Library,关注交互与行为,避免测试实现细节;关键流程可补充集成与 E2E 测试。
环境变量应通过 .env 读取,并使用 VITE_ 前缀;代码中不得硬编码密钥。

Files:

  • web/default/src/features/pricing/lib/model-metadata.ts
  • web/default/src/features/channels/lib/advanced-custom.test.ts
  • web/default/src/features/channels/lib/advanced-custom.ts
  • web/default/src/features/channels/components/dialogs/channel-test-dialog.tsx
  • web/default/src/features/pricing/constants.ts
  • web/default/src/features/pricing/components/model-details-api.tsx
web/default/src/features/**/lib/**/*.ts

📄 CodeRabbit inference engine (web/default/AGENTS.md)

表单应使用 React Hook Form + Zod:在功能模块的 lib/ 下定义 schema,并用 z.infer 导出表单类型;useForm 应配合 @hookform/resolvers/zod 进行校验。

Files:

  • web/default/src/features/pricing/lib/model-metadata.ts
  • web/default/src/features/channels/lib/advanced-custom.test.ts
  • web/default/src/features/channels/lib/advanced-custom.ts
web/default/src/features/**

📄 CodeRabbit inference engine (web/default/AGENTS.md)

功能模块应放在 src/features/<feature>/,并按需包含 components/、lib/、hooks/、api.ts、types.ts、constants.ts 等;通用组件应放在 src/components/,通用工具与类型应放在 src/lib/。

Files:

  • web/default/src/features/pricing/lib/model-metadata.ts
  • web/default/src/features/channels/lib/advanced-custom.test.ts
  • web/default/src/features/channels/lib/advanced-custom.ts
  • web/default/src/features/channels/components/dialogs/channel-test-dialog.tsx
  • web/default/src/features/pricing/constants.ts
  • web/default/src/features/pricing/components/model-details-api.tsx
web/default/src/**/*.test.ts

📄 CodeRabbit inference engine (web/default/AGENTS.md)

工具函数与纯逻辑应优先编写单元测试;测试文件应命名为 *.test.ts。

Files:

  • web/default/src/features/channels/lib/advanced-custom.test.ts
relay/channel/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

When implementing a new channel, confirm whether the provider supports StreamOptions; if it does, add the channel to streamSupportedChannels.

Files:

  • relay/channel/codex/adaptor_test.go
  • relay/channel/codex/adaptor.go
web/default/src/features/**/constants.ts

📄 CodeRabbit inference engine (web/default/AGENTS.md)

各 feature 的 constants.ts 中,成功/错误/提示类消息常量应仅保存 i18n 键,展示时必须通过 t() 渲染;状态/选项的 label 应统一使用 labelKey 或 label(二选一且同一 feature 内保持一致);新增此类常量时应同步登记翻译键。

Files:

  • web/default/src/features/pricing/constants.ts
dto/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

For request structs parsed from client JSON and then re-marshaled to upstream providers, especially in relay/convert paths, optional scalar fields must use pointer types with omitempty so that absent fields stay omitted while explicit zero/false values are preserved.

Files:

  • dto/alpha_search_request.go
🔇 Additional comments (36)
constant/endpoint_type.go (1)

9-9: LGTM!

common/endpoint_defaults.go (1)

23-23: LGTM!

common/endpoint_type.go (1)

33-38: LGTM!

common/endpoint_type_test.go (1)

1-16: LGTM!

relay/helper/alpha_search_request_test.go (1)

13-38: LGTM!

relay/channel/codex/adaptor_test.go (1)

12-26: LGTM!

controller/channel-test.go (1)

200-201: LGTM!

Also applies to: 239-241, 382-396, 485-510, 786-803

controller/channel_test_internal_test.go (1)

8-10: LGTM!

Also applies to: 86-98

controller/relay.go (1)

52-53: LGTM!

Also applies to: 160-173

types/relay_format.go (1)

11-11: LGTM!

relay/constant/relay_mode.go (1)

55-55: LGTM!

Also applies to: 80-81

relay/constant/relay_mode_test.go (1)

9-20: LGTM!

dto/alpha_search_request.go (1)

12-38: LGTM!

relay/helper/valid_request.go (1)

40-41: LGTM!

Also applies to: 59-77

relay/alpha_search_handler_test.go (1)

10-48: LGTM!

relay/channel/codex/adaptor.go (1)

115-127: LGTM!

Also applies to: 139-148

router/relay-router.go (1)

107-109: LGTM!

router/relay_router_test.go (1)

11-25: LGTM!

relay/alpha_search_handler.go (1)

21-56: LGTM!

Also applies to: 66-87, 114-127

service/alpha_search_billing.go (1)

16-49: LGTM!

service/alpha_search_billing_test.go (1)

18-96: LGTM!

service/text_quota.go (1)

60-62: LGTM!

Also applies to: 306-328, 418-419

service/text_quota_test.go (1)

9-9: LGTM!

Also applies to: 767-823

service/tiered_settle.go (1)

11-11: LGTM!

Also applies to: 151-184

web/default/src/features/channels/components/dialogs/channel-test-dialog.tsx (1)

137-140: LGTM!

Also applies to: 159-159

web/default/src/features/channels/lib/advanced-custom.ts (1)

95-98: LGTM!

web/default/src/features/channels/lib/advanced-custom.test.ts (1)

1-23: LGTM!

web/default/src/features/pricing/constants.ts (1)

67-78: LGTM!

Also applies to: 84-99

web/default/src/features/pricing/components/model-details-api.tsx (1)

167-224: LGTM!

Also applies to: 496-497

web/default/src/features/pricing/lib/model-metadata.ts (1)

36-44: LGTM!

web/default/src/i18n/locales/en.json (1)

3240-3241: LGTM!

web/default/src/i18n/locales/fr.json (1)

3240-3241: LGTM!

web/default/src/i18n/locales/ja.json (1)

3240-3241: LGTM!

web/default/src/i18n/locales/ru.json (1)

3240-3241: LGTM!

web/default/src/i18n/locales/vi.json (1)

3240-3241: LGTM!

web/default/src/i18n/locales/zh.json (1)

3240-3241: LGTM!

Comment thread relay/alpha_search_handler.go Outdated
Comment thread relay/alpha_search_handler.go Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
web/default/src/features/pricing/components/model-details-api.tsx (1)

168-226: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add direct tests for buildAlphaSearchSample.

model-details-api.test.ts only tests buildResponsesCompactSample. It does not verify the Alpha Search endpoint, search_query payload, or authentication syntax for curl, Python, and JavaScript.

Move buildAlphaSearchSample to model-details-api-samples.ts, or export an equivalent pure builder. Add focused assertions for /v1/alpha/search and the generated request body in each supported language.

As per coding guidelines, “工具函数与纯逻辑应优先编写单元测试;测试文件应命名为 *.test.ts。”

🤖 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 `@web/default/src/features/pricing/components/model-details-api.tsx` around
lines 168 - 226, Make buildAlphaSearchSample directly testable by moving it to
model-details-api-samples.ts or exporting an equivalent pure builder, then add
focused model-details-api.test.ts coverage for curl, Python, and JavaScript.
Assert each output targets /v1/alpha/search, includes the search_query payload,
and uses the expected language-specific authentication syntax and request body.

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 `@model/channel_selection_test.go`:
- Around line 162-200: Extend
TestAlphaSearchSelectionUsesOnlySupportedChannelTypes with an Advanced Custom
channel configured with a validated /v1/alpha/search route, then verify it is
selected by both GetChannel and GetRandomSatisfiedChannel. Keep the existing
OpenAI rejection and Codex assertions, and ensure the added direct and cached
cases exercise the route-specific support branch.

---

Outside diff comments:
In `@web/default/src/features/pricing/components/model-details-api.tsx`:
- Around line 168-226: Make buildAlphaSearchSample directly testable by moving
it to model-details-api-samples.ts or exporting an equivalent pure builder, then
add focused model-details-api.test.ts coverage for curl, Python, and JavaScript.
Assert each output targets /v1/alpha/search, includes the search_query payload,
and uses the expected language-specific authentication syntax and request body.
🪄 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: ASSERTIVE

Plan: Pro Plus

Run ID: 05c0825e-fee5-49d1-8fd6-4041f0cbc0a2

📥 Commits

Reviewing files that changed from the base of the PR and between c0ee2ad and 41aadc7.

📒 Files selected for processing (14)
  • common/endpoint_defaults.go
  • model/ability.go
  • model/channel_cache.go
  • model/channel_selection_test.go
  • model/pricing.go
  • model/pricing_test.go
  • relay/alpha_search_handler.go
  • relay/alpha_search_handler_test.go
  • service/text_quota.go
  • service/text_quota_test.go
  • tools/jsonwrapcheck/allowlist.txt
  • web/default/src/features/pricing/components/model-details-api-samples.ts
  • web/default/src/features/pricing/components/model-details-api.test.ts
  • web/default/src/features/pricing/components/model-details-api.tsx
💤 Files with no reviewable changes (1)
  • tools/jsonwrapcheck/allowlist.txt
📜 Review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: Backend checks
🧰 Additional context used
📓 Path-based instructions (4)
**/*.go

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.go: In Go business code, all JSON marshal/unmarshal operations must use the wrapper functions in common/json.go (common.Marshal, common.Unmarshal, common.UnmarshalJsonStr, common.DecodeJson, common.GetJsonType) and must not directly call encoding/json for actual encode/decode work.
All database code must be compatible with SQLite, MySQL 5.7.8+, and PostgreSQL 9.6+; prefer GORM abstractions over raw SQL, avoid direct AUTO_INCREMENT/SERIAL, use commonGroupCol/commonKeyCol and commonTrueVal/commonFalseVal for DB-specific SQL, branch with common.UsingPostgreSQL/common.UsingSQLite/common.UsingMySQL, avoid unsupported DB-specific functions/operators without fallback, and make migrations work across all three databases.
When implementing a new relay channel, confirm whether the provider supports StreamOptions; if it does, add that channel to streamSupportedChannels.
For request structs parsed from client JSON and re-marshaled to upstream providers, optional scalar fields must use pointer types with omitempty so explicit zero/false values are preserved instead of dropped.
When working on tiered/dynamic billing expression code, read pkg/billingexpr/expr.md first and follow its documented expression language, architecture, token normalization, quota conversion, and versioning patterns.

**/*.go: All JSON marshal/unmarshal operations in Go business code must use the wrapper functions in common/json.go (common.Marshal, common.Unmarshal, common.UnmarshalJsonStr, common.DecodeJson, common.GetJsonType) instead of directly importing or calling encoding/json for actual marshal/unmarshal work.
All database code in Go must remain compatible with SQLite, MySQL >= 5.7.8, and PostgreSQL >= 9.6; prefer GORM abstractions, avoid raw SQL unless necessary, use the shared DB helper variables for reserved words and boolean literals, branch with the common.UsingPostgreSQL / common.UsingSQLite / common.UsingMySQL flags when need...

Files:

  • model/pricing_test.go
  • model/channel_selection_test.go
  • common/endpoint_defaults.go
  • relay/alpha_search_handler_test.go
  • model/ability.go
  • service/text_quota_test.go
  • model/channel_cache.go
  • service/text_quota.go
  • model/pricing.go
  • relay/alpha_search_handler.go
web/default/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (web/default/AGENTS.md)

web/default/src/**/*.{ts,tsx}: 前端页面文本与组件内文案必须支持 i18n:React 组件中应使用 useTranslation() 取得 t,并通过 t() 渲染用户可见文本;子组件也应自行使用 useTranslation() 保持独立性。
禁止使用两层及以上嵌套三元表达式;复杂逻辑应改用 if-else、提前返回或抽取函数。
控制函数圈复杂度,复杂逻辑应拆成更小的函数;变量与函数命名应有意义并遵循驼峰等常规命名约定。
TypeScript 代码应避免使用 any,优先使用具体类型或 unknown;参数与返回值应显式标注类型;仅类型用途的导入应使用 import type。
修改 TypeScript 或 TSX 代码后必须执行类型检查,并修复所有类型错误,不得遗留。
对象非必要不要解构,尤其是组件 props;优先直接使用 props.xxx 以保持代码清晰。
组件应使用函数式组件与 Hooks,遵循单一职责;组件 props 必须有明确类型(接口或类型别名)。
单文件超过约 200 行时应考虑拆分子组件或抽取自定义 Hooks;类型定义可与组件同文件或放在同模块的 types 中。
在 React 中应合理使用 useMemo、useCallback、React.memo,避免在渲染路径中创建新对象或数组;必要时进行代码分割与动态 import。
React Query 的数据获取应使用 useQuery、变更应使用 useMutation;每个查询需配置唯一 queryKey,并在成功后对相关查询执行 invalidateQueries;服务端错误应统一交给 handleServerError。
Axios 请求应使用项目统一的 api 实例;GET 请求默认去重,特殊请求可显式关闭;认证与通用错误应在拦截器中统一处理。
服务端错误应统一使用 handleServerError,展示层应使用 toast.error 等统一方式;文案需走 i18n;路由级错误应由 errorComponent 承接;表单错误应通过 form.setError 等方式映射到字段。
样式应以 Tailwind 工具类为主,动态类名使用 cn() 合并;非动态场景避免内联样式;响应式采用移动优先与 Tailwind 断点,主题与暗色模式通过 CSS 变量与 dark: 处理。
应使用语义化 HTML、正确关联 label 与输入、保证键盘可操作与合理焦点顺序;必要时添加 ARIA 属性,装饰性图标应使用 aria-hidden="true"。
认证与权限应在路由与接口层校验;前后端都应做数据校验(如 Zod);敏感信息不得落前端存储;避免使用 dangerouslySetInnerHTML;跨域与 Cookie 需配合 withCredentials 并按后端要求处理 CSRF。
组件测试应使用 React Testing Library,关注交互与行为,避免测试实现细节;关键流程可补充集成与 E2E 测试。
环境变量应通过 .env 读取,并使用 VITE_ 前缀;代码中不得硬编码密钥。

Files:

  • web/default/src/features/pricing/components/model-details-api.test.ts
  • web/default/src/features/pricing/components/model-details-api.tsx
  • web/default/src/features/pricing/components/model-details-api-samples.ts
web/default/src/features/**

📄 CodeRabbit inference engine (web/default/AGENTS.md)

功能模块应放在 src/features/<feature>/,并按需包含 components/、lib/、hooks/、api.ts、types.ts、constants.ts 等;通用组件应放在 src/components/,通用工具与类型应放在 src/lib/。

Files:

  • web/default/src/features/pricing/components/model-details-api.test.ts
  • web/default/src/features/pricing/components/model-details-api.tsx
  • web/default/src/features/pricing/components/model-details-api-samples.ts
web/default/src/**/*.test.ts

📄 CodeRabbit inference engine (web/default/AGENTS.md)

工具函数与纯逻辑应优先编写单元测试;测试文件应命名为 *.test.ts。

Files:

  • web/default/src/features/pricing/components/model-details-api.test.ts
🔇 Additional comments (12)
web/default/src/features/pricing/components/model-details-api-samples.ts (1)

1-65: LGTM!

web/default/src/features/pricing/components/model-details-api.test.ts (1)

1-26: LGTM!

web/default/src/features/pricing/components/model-details-api.tsx (1)

57-57: LGTM!

Also applies to: 497-500

common/endpoint_defaults.go (1)

37-45: LGTM!

model/ability.go (1)

257-262: LGTM!

Also applies to: 278-287

model/channel_cache.go (1)

249-254: LGTM!

Also applies to: 271-284

model/pricing.go (1)

12-12: LGTM!

Also applies to: 131-198, 293-298, 313-313, 357-357

model/pricing_test.go (1)

1-42: LGTM!

relay/alpha_search_handler.go (1)

58-58: LGTM!

Also applies to: 89-116

relay/alpha_search_handler_test.go (1)

4-56: LGTM!

Also applies to: 97-160

service/text_quota.go (1)

16-16: LGTM!

Also applies to: 61-68, 177-182, 312-341, 431-432

service/text_quota_test.go (1)

15-18: LGTM!

Also applies to: 799-835, 939-965

Comment thread model/channel_selection_test.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 `@web/default/src/features/pricing/components/model-details-api-samples.ts`:
- Around line 114-125: Update the Alpha Search sample generation near the
response parsing to check response.ok and handle non-success responses
consistently with buildResponsesCompactSample before reading or logging the
response body. Add matching TypeScript and JavaScript coverage in
model-details-api.test.ts for the non-success branch, preserving existing
successful-response behavior.
🪄 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: ASSERTIVE

Plan: Pro Plus

Run ID: 1721c87c-3888-4be3-b8ac-f9ee5a941286

📥 Commits

Reviewing files that changed from the base of the PR and between 41aadc7 and f1b5fb0.

📒 Files selected for processing (4)
  • model/channel_selection_test.go
  • web/default/src/features/pricing/components/model-details-api-samples.ts
  • web/default/src/features/pricing/components/model-details-api.test.ts
  • web/default/src/features/pricing/components/model-details-api.tsx
📜 Review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: Backend checks
🧰 Additional context used
📓 Path-based instructions (4)
web/default/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (web/default/AGENTS.md)

web/default/src/**/*.{ts,tsx}: 前端页面文本与组件内文案必须支持 i18n:React 组件中应使用 useTranslation() 取得 t,并通过 t() 渲染用户可见文本;子组件也应自行使用 useTranslation() 保持独立性。
禁止使用两层及以上嵌套三元表达式;复杂逻辑应改用 if-else、提前返回或抽取函数。
控制函数圈复杂度,复杂逻辑应拆成更小的函数;变量与函数命名应有意义并遵循驼峰等常规命名约定。
TypeScript 代码应避免使用 any,优先使用具体类型或 unknown;参数与返回值应显式标注类型;仅类型用途的导入应使用 import type。
修改 TypeScript 或 TSX 代码后必须执行类型检查,并修复所有类型错误,不得遗留。
对象非必要不要解构,尤其是组件 props;优先直接使用 props.xxx 以保持代码清晰。
组件应使用函数式组件与 Hooks,遵循单一职责;组件 props 必须有明确类型(接口或类型别名)。
单文件超过约 200 行时应考虑拆分子组件或抽取自定义 Hooks;类型定义可与组件同文件或放在同模块的 types 中。
在 React 中应合理使用 useMemo、useCallback、React.memo,避免在渲染路径中创建新对象或数组;必要时进行代码分割与动态 import。
React Query 的数据获取应使用 useQuery、变更应使用 useMutation;每个查询需配置唯一 queryKey,并在成功后对相关查询执行 invalidateQueries;服务端错误应统一交给 handleServerError。
Axios 请求应使用项目统一的 api 实例;GET 请求默认去重,特殊请求可显式关闭;认证与通用错误应在拦截器中统一处理。
服务端错误应统一使用 handleServerError,展示层应使用 toast.error 等统一方式;文案需走 i18n;路由级错误应由 errorComponent 承接;表单错误应通过 form.setError 等方式映射到字段。
样式应以 Tailwind 工具类为主,动态类名使用 cn() 合并;非动态场景避免内联样式;响应式采用移动优先与 Tailwind 断点,主题与暗色模式通过 CSS 变量与 dark: 处理。
应使用语义化 HTML、正确关联 label 与输入、保证键盘可操作与合理焦点顺序;必要时添加 ARIA 属性,装饰性图标应使用 aria-hidden="true"。
认证与权限应在路由与接口层校验;前后端都应做数据校验(如 Zod);敏感信息不得落前端存储;避免使用 dangerouslySetInnerHTML;跨域与 Cookie 需配合 withCredentials 并按后端要求处理 CSRF。
组件测试应使用 React Testing Library,关注交互与行为,避免测试实现细节;关键流程可补充集成与 E2E 测试。
环境变量应通过 .env 读取,并使用 VITE_ 前缀;代码中不得硬编码密钥。

Files:

  • web/default/src/features/pricing/components/model-details-api.tsx
  • web/default/src/features/pricing/components/model-details-api.test.ts
  • web/default/src/features/pricing/components/model-details-api-samples.ts
web/default/src/features/**

📄 CodeRabbit inference engine (web/default/AGENTS.md)

功能模块应放在 src/features/<feature>/,并按需包含 components/、lib/、hooks/、api.ts、types.ts、constants.ts 等;通用组件应放在 src/components/,通用工具与类型应放在 src/lib/。

Files:

  • web/default/src/features/pricing/components/model-details-api.tsx
  • web/default/src/features/pricing/components/model-details-api.test.ts
  • web/default/src/features/pricing/components/model-details-api-samples.ts
web/default/src/**/*.test.ts

📄 CodeRabbit inference engine (web/default/AGENTS.md)

工具函数与纯逻辑应优先编写单元测试;测试文件应命名为 *.test.ts。

Files:

  • web/default/src/features/pricing/components/model-details-api.test.ts
**/*.go

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.go: In Go business code, all JSON marshal/unmarshal operations must use the wrapper functions in common/json.go (common.Marshal, common.Unmarshal, common.UnmarshalJsonStr, common.DecodeJson, common.GetJsonType) and must not directly call encoding/json for actual encode/decode work.
All database code must be compatible with SQLite, MySQL 5.7.8+, and PostgreSQL 9.6+; prefer GORM abstractions over raw SQL, avoid direct AUTO_INCREMENT/SERIAL, use commonGroupCol/commonKeyCol and commonTrueVal/commonFalseVal for DB-specific SQL, branch with common.UsingPostgreSQL/common.UsingSQLite/common.UsingMySQL, avoid unsupported DB-specific functions/operators without fallback, and make migrations work across all three databases.
When implementing a new relay channel, confirm whether the provider supports StreamOptions; if it does, add that channel to streamSupportedChannels.
For request structs parsed from client JSON and re-marshaled to upstream providers, optional scalar fields must use pointer types with omitempty so explicit zero/false values are preserved instead of dropped.
When working on tiered/dynamic billing expression code, read pkg/billingexpr/expr.md first and follow its documented expression language, architecture, token normalization, quota conversion, and versioning patterns.

**/*.go: All JSON marshal/unmarshal operations in Go business code must use the wrapper functions in common/json.go (common.Marshal, common.Unmarshal, common.UnmarshalJsonStr, common.DecodeJson, common.GetJsonType) instead of directly importing or calling encoding/json for actual marshal/unmarshal work.
All database code in Go must remain compatible with SQLite, MySQL >= 5.7.8, and PostgreSQL >= 9.6; prefer GORM abstractions, avoid raw SQL unless necessary, use the shared DB helper variables for reserved words and boolean literals, branch with the common.UsingPostgreSQL / common.UsingSQLite / common.UsingMySQL flags when need...

Files:

  • model/channel_selection_test.go
🔇 Additional comments (4)
model/channel_selection_test.go (1)

175-189: LGTM!

Also applies to: 203-222

web/default/src/features/pricing/components/model-details-api-samples.ts (1)

7-65: LGTM!

web/default/src/features/pricing/components/model-details-api.test.ts (1)

3-28: LGTM!

Also applies to: 30-58

web/default/src/features/pricing/components/model-details-api.tsx (1)

57-60: LGTM!

Also applies to: 441-444

@CSCITech

CSCITech commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Already reviewed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@CSCITech

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Already reviewed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 `@controller/billing.go`:
- Around line 23-24: Validate operation_setting.USDExchangeRate before the CNY
conversion in the quota calculation, rejecting zero, negative, NaN, and infinite
values through the same error path used for invalid QuotaPerUnit. Preserve the
existing conversion for valid rates, and add table-driven cases covering each
invalid USDExchangeRate with QuotaDisplayTypeCNY.

In `@service/midjourney.go`:
- Around line 122-127: Update the variation handling branch in the action parser
to reject unsupported action values: when strings.Contains(action, "variation")
matches but action is not an exact supported variation action, return the
existing unknown_action response instead of succeeding with no action set. Also
add MJ::JOB::unsupported_variation::1 to the malformed-ID test cases.
🪄 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: ASSERTIVE

Plan: Pro Plus

Run ID: 45a68fbb-4ad3-405e-8e68-0a4c8270c631

📥 Commits

Reviewing files that changed from the base of the PR and between 9b8e086 and 4ed6355.

📒 Files selected for processing (4)
  • controller/billing.go
  • controller/billing_test.go
  • service/midjourney.go
  • service/midjourney_test.go
📜 Review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: Backend checks
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.go: In Go business code, all JSON marshal/unmarshal operations must use the wrapper functions in common/json.go (common.Marshal, common.Unmarshal, common.UnmarshalJsonStr, common.DecodeJson, common.GetJsonType) and must not directly call encoding/json for actual encode/decode work.
All database code must be compatible with SQLite, MySQL 5.7.8+, and PostgreSQL 9.6+; prefer GORM abstractions over raw SQL, avoid direct AUTO_INCREMENT/SERIAL, use commonGroupCol/commonKeyCol and commonTrueVal/commonFalseVal for DB-specific SQL, branch with common.UsingPostgreSQL/common.UsingSQLite/common.UsingMySQL, avoid unsupported DB-specific functions/operators without fallback, and make migrations work across all three databases.
When implementing a new relay channel, confirm whether the provider supports StreamOptions; if it does, add that channel to streamSupportedChannels.
For request structs parsed from client JSON and re-marshaled to upstream providers, optional scalar fields must use pointer types with omitempty so explicit zero/false values are preserved instead of dropped.
When working on tiered/dynamic billing expression code, read pkg/billingexpr/expr.md first and follow its documented expression language, architecture, token normalization, quota conversion, and versioning patterns.

**/*.go: All JSON marshal/unmarshal operations in Go business code must use the wrapper functions in common/json.go (common.Marshal, common.Unmarshal, common.UnmarshalJsonStr, common.DecodeJson, common.GetJsonType) instead of directly importing or calling encoding/json for actual marshal/unmarshal work.
All database code in Go must remain compatible with SQLite, MySQL >= 5.7.8, and PostgreSQL >= 9.6; prefer GORM abstractions, avoid raw SQL unless necessary, use the shared DB helper variables for reserved words and boolean literals, branch with the common.UsingPostgreSQL / common.UsingSQLite / common.UsingMySQL flags when need...

Files:

  • controller/billing_test.go
  • service/midjourney_test.go
  • service/midjourney.go
  • controller/billing.go
🔇 Additional comments (3)
controller/billing.go (1)

47-76: LGTM!

Also applies to: 88-88, 99-122

controller/billing_test.go (1)

12-47: LGTM!

service/midjourney_test.go (1)

13-14: LGTM!

Also applies to: 87-119

Comment thread controller/billing.go
Comment thread service/midjourney.go
@CSCITech

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 `@controller/billing.go`:
- Around line 57-75: In controller/billing.go, update all token, quota, and
used-quota lookup error branches at lines 57-75 and 106-117 to log the original
errors server-side, while passing the same fixed client-safe billing retrieval
message to writeBillingOpenAIError instead of err.Error().

In `@service/midjourney.go`:
- Around line 105-113: Update the parseIndex closure to reject parsed indexes
less than 1 before returning or assigning midjRequest.Index, preserving the
existing index_parse_failed error for invalid values. Add malformed custom-ID
coverage for upsample IDs containing index 0 and -1.
🪄 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: ASSERTIVE

Plan: Pro Plus

Run ID: 2632ce46-9c11-4b57-b378-7b1c711260a8

📥 Commits

Reviewing files that changed from the base of the PR and between 9b8e086 and b6b491e.

⛔ Files ignored due to path filters (1)
  • web/default/public/favicon.ico is excluded by !**/*.ico
📒 Files selected for processing (4)
  • controller/billing.go
  • controller/billing_test.go
  • service/midjourney.go
  • service/midjourney_test.go
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.go: In Go business code, all JSON marshal/unmarshal operations must use the wrapper functions in common/json.go (common.Marshal, common.Unmarshal, common.UnmarshalJsonStr, common.DecodeJson, common.GetJsonType) and must not directly call encoding/json for actual encode/decode work.
All database code must be compatible with SQLite, MySQL 5.7.8+, and PostgreSQL 9.6+; prefer GORM abstractions over raw SQL, avoid direct AUTO_INCREMENT/SERIAL, use commonGroupCol/commonKeyCol and commonTrueVal/commonFalseVal for DB-specific SQL, branch with common.UsingPostgreSQL/common.UsingSQLite/common.UsingMySQL, avoid unsupported DB-specific functions/operators without fallback, and make migrations work across all three databases.
When implementing a new relay channel, confirm whether the provider supports StreamOptions; if it does, add that channel to streamSupportedChannels.
For request structs parsed from client JSON and re-marshaled to upstream providers, optional scalar fields must use pointer types with omitempty so explicit zero/false values are preserved instead of dropped.
When working on tiered/dynamic billing expression code, read pkg/billingexpr/expr.md first and follow its documented expression language, architecture, token normalization, quota conversion, and versioning patterns.

**/*.go: All JSON marshal/unmarshal operations in Go business code must use the wrapper functions in common/json.go (common.Marshal, common.Unmarshal, common.UnmarshalJsonStr, common.DecodeJson, common.GetJsonType) instead of directly importing or calling encoding/json for actual marshal/unmarshal work.
All database code in Go must remain compatible with SQLite, MySQL >= 5.7.8, and PostgreSQL >= 9.6; prefer GORM abstractions, avoid raw SQL unless necessary, use the shared DB helper variables for reserved words and boolean literals, branch with the common.UsingPostgreSQL / common.UsingSQLite / common.UsingMySQL flags when need...

Files:

  • controller/billing.go
  • service/midjourney.go
  • controller/billing_test.go
  • service/midjourney_test.go
🔇 Additional comments (2)
controller/billing.go (1)

4-47: LGTM!

Also applies to: 77-81, 95-95, 119-129

controller/billing_test.go (1)

1-118: LGTM!

Comment thread controller/billing.go
Comment thread service/midjourney.go Outdated
@CSCITech

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
service/midjourney.go (2)

118-124: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Reject unsupported upsample action tokens.

At Line 118, strings.Contains(action, "upsample") accepts unsupported_upsample. The parser then sets constant.MjActionUpscale and returns success.

Use an exact comparison or an explicit allow-list for supported upsample actions. Add MJ::JOB::unsupported_upsample::1 to the malformed-ID tests.

🤖 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 `@service/midjourney.go` around lines 118 - 124, Update the upsample branch in
the action parser to match only explicitly supported upsample action tokens,
rather than using strings.Contains, so unsupported_upsample is rejected as
malformed. Add MJ::JOB::unsupported_upsample::1 to the malformed-ID test cases
and preserve valid upsample parsing.

104-115: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Derive indexPosition from actionIndex.

At Line 104, indexPosition is hard-coded to 3. For MJ::upsample::2::task-id, actionIndex is 1, so the index is at splits[2]. The parser reads splits[3] (task-id) and returns index_parse_failed. This breaks the legacy upsample test in service/midjourney_test.go Lines 124-132.

Set indexPosition := actionIndex + 1.

Proposed fix
-	indexPosition := 3
+	indexPosition := actionIndex + 1
🤖 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 `@service/midjourney.go` around lines 104 - 115, Update indexPosition in the
parseIndex logic to derive it from actionIndex by setting it to the action index
plus one, so legacy upsample actions parse the numeric index from the correct
splits element.
🤖 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/misc.go`:
- Around line 68-75: Update GetHealthReady to use a dedicated uncached database
readiness probe instead of healthReadyPingDB/model.PingDB, ensuring every
readiness request checks the database directly and returns HTTP 503 on failure.
Preserve the throttled PingDB behavior for non-readiness status checks, and add
a test covering a database failure immediately after a successful check.

In `@model/user_delete_test.go`:
- Around line 82-85: Strengthen the assertions in model/user_delete_test.go at
lines 82-85 and 131-134: capture timestamps immediately before and after each
deletion, then verify the stored subscription EndTime falls within that
interval, proving cancellation updates it rather than retaining the original
expiration. Apply this to both the soft-deletion and hard-deletion test paths.

---

Outside diff comments:
In `@service/midjourney.go`:
- Around line 118-124: Update the upsample branch in the action parser to match
only explicitly supported upsample action tokens, rather than using
strings.Contains, so unsupported_upsample is rejected as malformed. Add
MJ::JOB::unsupported_upsample::1 to the malformed-ID test cases and preserve
valid upsample parsing.
- Around line 104-115: Update indexPosition in the parseIndex logic to derive it
from actionIndex by setting it to the action index plus one, so legacy upsample
actions parse the numeric index from the correct splits element.
🪄 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: ASSERTIVE

Plan: Pro Plus

Run ID: 2a9e219e-ad1c-40ef-8808-cf546fe0643b

📥 Commits

Reviewing files that changed from the base of the PR and between b6b491e and 09654cc.

📒 Files selected for processing (10)
  • controller/billing.go
  • controller/misc.go
  • controller/misc_test.go
  • model/task_cas_test.go
  • model/user.go
  • model/user_delete_test.go
  • router/api-router.go
  • router/api_router_test.go
  • service/midjourney.go
  • service/midjourney_test.go
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.go: In Go business code, all JSON marshal/unmarshal operations must use the wrapper functions in common/json.go (common.Marshal, common.Unmarshal, common.UnmarshalJsonStr, common.DecodeJson, common.GetJsonType) and must not directly call encoding/json for actual encode/decode work.
All database code must be compatible with SQLite, MySQL 5.7.8+, and PostgreSQL 9.6+; prefer GORM abstractions over raw SQL, avoid direct AUTO_INCREMENT/SERIAL, use commonGroupCol/commonKeyCol and commonTrueVal/commonFalseVal for DB-specific SQL, branch with common.UsingPostgreSQL/common.UsingSQLite/common.UsingMySQL, avoid unsupported DB-specific functions/operators without fallback, and make migrations work across all three databases.
When implementing a new relay channel, confirm whether the provider supports StreamOptions; if it does, add that channel to streamSupportedChannels.
For request structs parsed from client JSON and re-marshaled to upstream providers, optional scalar fields must use pointer types with omitempty so explicit zero/false values are preserved instead of dropped.
When working on tiered/dynamic billing expression code, read pkg/billingexpr/expr.md first and follow its documented expression language, architecture, token normalization, quota conversion, and versioning patterns.

**/*.go: All JSON marshal/unmarshal operations in Go business code must use the wrapper functions in common/json.go (common.Marshal, common.Unmarshal, common.UnmarshalJsonStr, common.DecodeJson, common.GetJsonType) instead of directly importing or calling encoding/json for actual marshal/unmarshal work.
All database code in Go must remain compatible with SQLite, MySQL >= 5.7.8, and PostgreSQL >= 9.6; prefer GORM abstractions, avoid raw SQL unless necessary, use the shared DB helper variables for reserved words and boolean literals, branch with the common.UsingPostgreSQL / common.UsingSQLite / common.UsingMySQL flags when need...

Files:

  • router/api-router.go
  • router/api_router_test.go
  • model/task_cas_test.go
  • model/user_delete_test.go
  • model/user.go
  • service/midjourney.go
  • service/midjourney_test.go
  • controller/billing.go
  • controller/misc_test.go
  • controller/misc.go
🔇 Additional comments (12)
model/user.go (1)

1306-1355: LGTM!

model/task_cas_test.go (1)

58-58: LGTM!

Also applies to: 90-90

model/user_delete_test.go (1)

7-7: LGTM!

Also applies to: 37-80, 88-129

controller/misc.go (1)

43-66: LGTM!

router/api-router.go (1)

15-17: LGTM!

controller/misc_test.go (1)

15-78: LGTM!

router/api_router_test.go (1)

118-140: LGTM!

controller/billing.go (4)

15-15: LGTM!


60-78: LGTM!


100-100: LGTM!


112-122: LGTM!

service/midjourney_test.go (1)

13-14: LGTM!

Also applies to: 87-112, 114-122, 124-132

Comment thread controller/misc.go
Comment thread model/user_delete_test.go Outdated
@CSCITech

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
model/main.go (1)

1142-1155: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Use a bounded timeout for the readiness database ping.

PingDBUncached calls sqlDB.Ping(), and /health/ready maps this directly to every readiness check. A stalled connection or driver ping can hold the handler until the request times out. Change readiness to create a short timeout context and call PingContext; add a test that simulates timeout failure.

🤖 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 `@model/main.go` around lines 1142 - 1155, Update PingDBUncached to create a
short, bounded timeout context and use sqlDB.PingContext instead of sqlDB.Ping,
preserving the existing error logging and return behavior. Add a test covering a
simulated ping timeout failure and verify the readiness check returns the
resulting error promptly.
🤖 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 `@service/midjourney.go`:
- Around line 104-125: The fallback in parseIndex must handle the legacy
upsam­ple format by trying splits[indexPosition+1] when actionIndex is 1 and the
first candidate at indexPosition is non-numeric. Relax the current guard so this
fallback is reached for the legacy field layout, while preserving normal parsing
and bounds validation through parseIndexAt.

---

Outside diff comments:
In `@model/main.go`:
- Around line 1142-1155: Update PingDBUncached to create a short, bounded
timeout context and use sqlDB.PingContext instead of sqlDB.Ping, preserving the
existing error logging and return behavior. Add a test covering a simulated ping
timeout failure and verify the readiness check returns the resulting error
promptly.
🪄 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: ASSERTIVE

Plan: Pro Plus

Run ID: 2d7b3194-4fec-48aa-af09-cec528893b2e

📥 Commits

Reviewing files that changed from the base of the PR and between 09654cc and 2d89c82.

📒 Files selected for processing (6)
  • controller/misc.go
  • controller/misc_test.go
  • model/main.go
  • model/user_delete_test.go
  • service/midjourney.go
  • service/midjourney_test.go
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.go: In Go business code, all JSON marshal/unmarshal operations must use the wrapper functions in common/json.go (common.Marshal, common.Unmarshal, common.UnmarshalJsonStr, common.DecodeJson, common.GetJsonType) and must not directly call encoding/json for actual encode/decode work.
All database code must be compatible with SQLite, MySQL 5.7.8+, and PostgreSQL 9.6+; prefer GORM abstractions over raw SQL, avoid direct AUTO_INCREMENT/SERIAL, use commonGroupCol/commonKeyCol and commonTrueVal/commonFalseVal for DB-specific SQL, branch with common.UsingPostgreSQL/common.UsingSQLite/common.UsingMySQL, avoid unsupported DB-specific functions/operators without fallback, and make migrations work across all three databases.
When implementing a new relay channel, confirm whether the provider supports StreamOptions; if it does, add that channel to streamSupportedChannels.
For request structs parsed from client JSON and re-marshaled to upstream providers, optional scalar fields must use pointer types with omitempty so explicit zero/false values are preserved instead of dropped.
When working on tiered/dynamic billing expression code, read pkg/billingexpr/expr.md first and follow its documented expression language, architecture, token normalization, quota conversion, and versioning patterns.

**/*.go: All JSON marshal/unmarshal operations in Go business code must use the wrapper functions in common/json.go (common.Marshal, common.Unmarshal, common.UnmarshalJsonStr, common.DecodeJson, common.GetJsonType) instead of directly importing or calling encoding/json for actual marshal/unmarshal work.
All database code in Go must remain compatible with SQLite, MySQL >= 5.7.8, and PostgreSQL >= 9.6; prefer GORM abstractions, avoid raw SQL unless necessary, use the shared DB helper variables for reserved words and boolean literals, branch with the common.UsingPostgreSQL / common.UsingSQLite / common.UsingMySQL flags when need...

Files:

  • controller/misc_test.go
  • controller/misc.go
  • model/main.go
  • service/midjourney_test.go
  • service/midjourney.go
  • model/user_delete_test.go
🔇 Additional comments (6)
model/user_delete_test.go (1)

7-7: LGTM!

Also applies to: 36-89, 91-141

controller/misc.go (1)

58-58: LGTM!

Also applies to: 69-69

controller/misc_test.go (1)

63-68: LGTM!

Also applies to: 80-108

model/main.go (1)

1133-1140: LGTM!

service/midjourney.go (1)

87-103: LGTM!

Also applies to: 126-147, 171-171, 180-190

service/midjourney_test.go (1)

13-14: LGTM!

Also applies to: 87-115, 117-125, 127-165, 167-185

Comment thread service/midjourney.go
@CSCITech

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@CSCITech
CSCITech merged commit 0aed3fd into main Aug 10, 2026
3 checks passed
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