Skip to content
This repository was archived by the owner on Sep 22, 2026. It is now read-only.

Merge to main branch - #2

Merged
CallmeLins merged 8 commits into
CallmeLins:mainfrom
ChangAn-1314:main
Jul 24, 2026
Merged

CallmeLins merged 8 commits into
CallmeLins:mainfrom
ChangAn-1314:main

Conversation

@CallmeLins

Copy link
Copy Markdown
Owner

Merge some change from ChangAn

@CallmeLins
CallmeLins merged commit 9f5dc75 into CallmeLins:main Jul 24, 2026
7 checks passed
CallmeLins pushed a commit that referenced this pull request Jul 26, 2026
fix(proxy): allow bounded large model requests
heihei0299 pushed a commit to heihei0299/pi-switch that referenced this pull request Aug 30, 2026
- 代理与 Web 服务启动不再自动写网关,改为 health_check/start_placeholder 仅告警不阻断
- 健康检查独立可查:running/mode/has_models_file/last_notify/upstreams_total/gateway_id
- 预览返回 pending_count 与 conflicts,正确反映新增/移除/变更差异
- 前端首屏仅横幅提示不一致,不自动落盘,需用户显式 Apply to Pi
- 网关缺失时健康与预览仍可用,供应商侧不受影响
- 对齐 README/WEBUI_GUIDE:启动不再自动写,仅显式发布
heihei0299 pushed a commit to heihei0299/pi-switch that referenced this pull request Aug 30, 2026
- 新增 isCreditsSupported 按主上游 baseUrl 含 opencode.ai 判定
- 新增 api.getCredits 代理 GET /api/profiles/:name/credits 归一化结构
- 新增 SupplierCreditsPanel 组件:余额/已用/总额/过期 + percent 进度条 + 刷新 + 主上游小字,挂载自动 fetch,loading spinner,错误内联红字+重试,不弹 toast
- ProfilesPanel 每张卡片内联余量区,非命中不渲染,多上游仅主上游单面板单请求,错误隔离不阻断编辑/删除/暴露
- 紧凑 tailwind+zinc 风格,无新依赖

Tests: 196 vitest 全绿 (新增 19), cargo 318 全绿
Seams: 6 (api.getCredits, isCreditsSupported, 余量区展示, 挂载+刷新+spinner, 错误重试隔离, 非命中+多上游隔离)
heihei0299 pushed a commit to heihei0299/pi-switch that referenced this pull request Aug 30, 2026
heihei0299 pushed a commit to heihei0299/pi-switch that referenced this pull request Aug 30, 2026
根因:OpencodeGoFetcher 拼 url 为 {baseUrl}/v1/credits 且未剥离
已含的 /v1,导致 https://opencode.ai/zen/go/v1 → /v1/v1/credits 404
HTML;且 Go 真实端点为 /zen/go/v1/usage(返回 usage.rolling/
weekly/monthly),原归一化期望 balance/total 与前端余量视图
完全失配。

修复:
- credits.rs 新增 UsageWindow/GoUsage,NormalizedCredits 增加
  usage 字段,normalize_opencode_go 优先解析 usage 三窗口
  (兼容旧 balance 形态),新增 normalize_base_url/build_credits_url
  统一剥离尾部 /v1 后拼 /v1/usage
- OpencodeGoFetcher 改用 build_credits_url,web.rs mock 兼容
  /v1/usage 与 /v1/credits 双路径,测试覆盖真实 Go 响应
- 前端 NormalizedCredits 扩展 usage,SupplierCreditsPanel 按
  hasUsage 分支渲染 5小时/每周/每月三进度条(用量·主上游)
  兼容旧余量四字段视图

验证:GET /api/profiles/oc/credits 由 404 HTML → 200
{"usage":{"rolling":{"percent":7,…},…}};cargo 322 passed,
webui 196 passed;被验证假设 CallmeLins#1 路径重复 + CallmeLins#2 端点语义错误
heihei0299 pushed a commit to heihei0299/pi-switch that referenced this pull request Sep 11, 2026
上一轮 review 的 Spec CallmeLins#2/CallmeLins#3 与 Standards CallmeLins#1。

- basicAuthMiddleware 改为由调用方传入本面的 401 信封:管理面仍是
  {"error":"Unauthorized"},/v1 推理面改为 OpenAI
  {"error":{"message":"Unauthorized","type":"invalid_request_error"}},
  补上 system-contract §2.8 唯一未遵守的路径(共享 middleware 此前把管理面
  信封用在了推理面)
- config 删除 rejectNullExposedModels 影子 schema:`exposedModels:null` 的
  拒绝规则移到 Upstream.UnmarshalJSON,字段名只有一个 owner,不再存在
  「字段改名后守卫静默失效」的风险
  取舍:错误信息由 profiles.<name>.upstreams[i].exposedModels 变为
  `profiles: exposedModels must not be null`;仍点名字段(满足 §2.2
  「报出字段错误」),但不再带 profile/index 索引路径
- 测试:/v1 401 断言 OpenAI 信封、管理面 401 断言字符串信封、config 断言
  null 错误点名字段

验证:gofmt -l / go vet 无输出;scripts/test-limited.sh go 全绿。

review-fixes-2
heihei0299 pushed a commit to heihei0299/pi-switch that referenced this pull request Sep 11, 2026
上一轮 review 的 Spec CallmeLins#5、Standards CallmeLins#1/CallmeLins#2、Spec CallmeLins#4。

- Spec CallmeLins#5:推理面的框架默认响应也走 OpenAI 信封
  - 新增 inferenceNoRoute:/v1 未匹配路由与错误方法返回
    {"error":{"message":"not found: <path>","type":"invalid_request_error"}}
  - 两个 router 的 gin.Recovery() 换成 CustomRecovery:/v1 panic → 推理信封,
    /api panic → 管理面字符串信封(此前都是空 body)
- Standards CallmeLins#1:新增 internal/server/error_envelope.go 作为两种信封的单一 owner
  (managementError / inferenceError / 两个 unauthorized / 两个 recovery /
  inferenceNoRoute);proxy 里 21 处内联嵌套信封、config loader、notImplemented、
  failover 全部改走 helper,嵌套字面量只剩 inferenceError 内部一处
- Standards CallmeLins#2:basicAuthMiddleware 改为接收 func() gin.H,不再跨请求共享可变 map
- Spec CallmeLins#4:恢复完整字段路径。ProviderProfile.UnmarshalJSON 在解码失败时回查
  upstream 下标,ParseConfig 逐 profile 解码以带上 profile 名;happy path 只解析
  一次,仅出错时重走。错误现在是
  profiles.p: upstreams[1]: exposedModels must not be null
- 测试:新增 404/panic 契约用例(推理面两个信封、管理面 panic 字符串),
  并把 null 用例收紧为断言 profiles.p + upstreams[0] + exposedModels

未做(判断项):管理面既有的 ~60 处 `gin.H{"error": <string>}` 仍内联;形状平凡
且已全部合规,未做机械替换以免 churn。少数错误信息里的类型名会显示
providerProfileAlias/upstreamAlias(Go alias 惯用写法的代价),仅影响文案。

验证:gofmt -l / go vet 无输出;scripts/test-limited.sh go 全绿;契约用例
(/v1 404、/v1 panic、/api panic、/v1 401、/api 401、config 500)全部通过。

review-fixes-3
heihei0299 pushed a commit to heihei0299/pi-switch that referenced this pull request Sep 11, 2026
上一轮 review 的 Spec CallmeLins#2 与 Standards CallmeLins#1/CallmeLins#2。

- Spec CallmeLins#2:ProfilesPanel 的 Responses mode 下拉改为按
  allowedResponsesModes(caps, apiType) 渲染,当前值不在允许集时保留一个选项
  以便纠正;不再无条件列出 auto/passthrough/convert
- Standards CallmeLins#1:fallback 不再是手写第二份清单。新增
  webui/src/lib/protocol-capabilities.json(由 protocol.Capabilities() 生成),
  前端直接 import;Go 侧 TestCapabilitiesMatchWebUIFallbackFixture 校验 fixture
  与 Capabilities() 完全一致,改后端能力而不同步 fixture 会失败并打印新 JSON
- Standards CallmeLins#2:删除模块级可变单例 setProtocolCapabilities;能力经
  ProtocolProvider/useProtocolCapabilities 从 state.protocol 下发,纯 helper 显式
  接收 caps;useProfileDraft 经 context 取 apiIds,validateProfileJson 增加
  可选 apiIds 参数(默认取 fixture,测试无需 provider)
- 测试:Go 增加 fixture parity 用例;webui 新增 protocolCapabilities fixture
  用例、responsesMode 按 caps 取值用例、以及“anthropic 只提供 auto 选项”的
  UI 用例(防止下拉退回硬编码)

验证:gofmt -l / go vet 无输出;scripts/test-limited.sh go 全绿;
scripts/test-limited.sh tsc 通过;scripts/test-limited.sh webui 36 文件
284 用例全绿。

responses-mode-followup
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants