Skip to content

feat(keys): 支持将 API 密钥导入 Magpie - #861

Merged
ranxi2001 merged 3 commits into
ranxi2001:productionfrom
spake404:feat/magpie-import-upstream
Nov 15, 2026
Merged

ranxi2001 merged 3 commits into
ranxi2001:productionfrom
spake404:feat/magpie-import-upstream

Conversation

@spake404

@spake404 spake404 commented Nov 14, 2026 •

Copy link
Copy Markdown

最终合并验证: head f1e3cbe847242d083696e10c94160fc0cf0668d8,base production。16 项通过、7 项条件跳过,10 个 workflow 全部终态;无失败、取消或运行中检查。CI backend 的 make test-unit、make test-integration 通过;前端、lint、安全检查与页面证据已核对。下方旧验证和等待状态仅归属其历史提交。

解决的问题与行为变化

  • 以前用户要手动把 Sub2API 的 API 地址和密钥填入 Magpie。现在个人「API 密钥」页每条密钥旁都有「导入到 Magpie」,与现有 CCS 按钮互不影响。
  • 按钮根据所选密钥的分组生成对应的 API 端点,并通过 Magpie 现有的 magpie://import 协议打开预填的供应商预览。只有用户在 Magpie 中确认后才保存。未加载到公开设置或无法确定端点的分组不会发起导入。
  • 只改 Sub2API 前端(含中英文文案和测试)。不修改 Magpie、Sub2API 后端或 API 协议,也不包含 Windows 桌面端的启动延迟修复。

关联记录与来源

管理员新功能提示

  • 提示 ID:不适用,仅涉及个人密钥页,无管理员功能或设置。
  • NewFeatureBadge 位置:不适用,未新增管理员入口。
  • 标签关闭及同步:不适用,未新增标签。
  • ID 沿用/重新公告:不适用,未登记提示 ID。
  • A→B 升级仍可见:不适用,未新增提示。
  • B 多入口标签联动:不适用,无管理员标签入口。
  • B 刷新/重新登录仍隐藏:不适用,无隐藏状态。
  • C 新提示/旧提示不复活:不适用,无提示 ID 或持久化改动。

复现与验收

  1. 在安装了支持导入链接的 Magpie 桌面端的电脑上,打开 Sub2API 个人「API 密钥」页(/keys)。可使用隔离环境中的单一 OpenAI 分组、两条测试密钥。
  2. 点击第二条的「导入到 Magpie」。如果浏览器询问是否打开外部应用,选择允许。
  3. Magpie 应打开供应商预览,填入第二条密钥和相应地址;取消预览不会保存。关闭 CCS 按钮的显示设置后,Magpie 入口仍可用。
  4. 地址优先使用公开设置中的 api_base_url,未配置时用当前站点地址。未分组、跨分组或未知平台不猜测端点;提示改用「使用密钥」查看配置。

实际验证

检查 结果 覆盖范围
pnpm --dir frontend install --frozen-lockfile 通过 锁文件安装
pnpm --dir frontend exec vitest run src/utils/__tests__/magpieImport.spec.ts src/views/user/__tests__/KeysView.spec.ts src/utils/__tests__/ccswitchImport.spec.ts src/i18n 通过 13 个文件、193 项;覆盖分组和端点、地址与密钥校验、选中行、设置未就绪、中英文与 CCS 回归
pnpm --dir frontend exec eslint(限定本 PR 的 6 个改动文件) 通过 修改的 Vue、TypeScript、语言文件与测试
pnpm --dir frontend run build 通过 i18n 检查、TypeScript 类型检查和 Vite 构建
git diff --check origin/production...HEAD 通过 补丁空白检查
Windows 浏览器到 Magpie 实机验证 通过(原 fork 版本) 提交者在原 fork 构建上手动确认导入正常;未在本 PR 构建上重跑桌面端验收,也未测量延迟
CI backend:make test-unit、make test-integration;前端关键测试、构建、lint、安全扫描 通过 当前 head 的 主 CI;页面与选中行证据见下方
跨平台桌面端、生产验收 未运行 原 fork 的手动测试仅为作者报告;本轮采用浏览器协议启动拦截

兼容性与运行影响

  • 不增加配置项、数据库迁移或后台请求。未安装 Magpie 或浏览器阻止外部协议时,页面提供说明,原有 CCS 和手动配置流程不变。
  • 密钥仅在用户点击后交给本机系统注册的 Magpie 协议处理程序;这个改动不把密钥写入日志或提交给新的 HTTP 服务。导入链接本身含凭据,不应复制到报告或公开分享。
  • 不改变计费、并发或重试行为;没有性能改善声明。回滚此提交只移除按钮及文案,不会改动已在 Magpie 中保存的供应商。

文档与用户可见变化

  • 个人 API 密钥页新增中英文操作入口及错误提示,无新增部署步骤。合并 PR 不代表已发布或部署。

Agent 使用声明

  • Agent:Claude Code。参与需求分析、前端实现、测试、验证与 PR 撰写。
  • 模型:mythos-magpie-0870153534(当前提交阶段的环境报告值;早期实现阶段如使用不同模型,未单独记录)。
  • 推理强度:未知,当前会话没有提供可核实的配置值。

提交前自查

  • 目标为 ranxi2001/sub2api:production,仅含相关前端改动。
  • 正文与提交未附真实密钥、请求日志或用户数据。
  • 已记录验证结果和未覆盖项。
  • 已检查配置、权限与兼容性,并逐项说明管理员提示不适用的原因。
  • 已填写 Agent 使用声明。

🤖 Generated with Claude Code

实际页面组件前后截图

证据提交 f2365ac2987d9eb93f4d28a82a3bdd8bb9848dbc,其 KeysView、Magpie helper 和中英文语言文件已与原 PR head 逐文件核对一致。前图使用 713cb0f3efe3f838d159cd57998128c2cdaa84b1 的 KeysView;4 张中英文截图已逐张核对,页面脚本错误为 0。

CI 执行 node .github/scripts/magpie-import-preview.mjs,渲染实际 KeysView 与项目 CSS,使用虚构账号/API 适配器;仅外层 AppLayout 替换为容器。点击第二条密钥后,断言实际生成链接包含第二条密钥及正确 Responses 端点。系统协议启动已拦截,未启动真实 Magpie,不代表生产接口或完整导航验收。截图和选中行检查 / 原始产物。

after-en after-zh before-en before-zh

本轮 Agent:Codex,环境标识 GPT-6,完整模型 ID / 推理强度未暴露、未知;参与维护修复、源码复核、CI、截图与合并。子 Agent 调用均返回 502,没有产出审查证据。

Hand off the selected key and its supported gateway endpoints to the existing Magpie desktop confirmation page. Keep the CCS action independent and do not guess endpoints for unsupported groups.

Verified on the v2.21.3 production base: 193 targeted frontend tests (Magpie, key view, CCS and i18n), ESLint on the six changed files, production frontend build, and git diff --check. The contributor also verified the browser-to-desktop flow on Windows on the original fork build; no new native test was run on this PR build.

(cherry picked from commit d9c828b)

Co-Authored-By: Claude Code <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 14, 2026 18:49

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@ranxi2001

ranxi2001 commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

维护定位(固定 head defc4cbb1042):

test check 的失败来自已有后端回归 TestChannelMonitorV3StatusScopesOrdinaryUsersServerSide,不是当前 Magpie 前端实现的失败证据。原始 job 132550511073 显示:测试用整段响应 NotContains("4321") 检查请求量脱敏,却被 generated_at 的纳秒部分偶然包含该串触发;文件为 backend/internal/handler/channel_monitor_v3_handler_test.go:136。正确修复应解析 JSON、检查禁止暴露的字段/统计结构,保留普通用户隔离与泄露负向断言,并对包含同样数字的合法时间戳回归;不能删掉脱敏断言或把重复 green 当成已修复。

该后端测试也存在 production。当前 PR 仍保留失败门槛;维护下一修复槽处理共享测试,避免向外部 fork 分支擅自推送。UI 部分另需按 CONTRIBUTING 和 PR 模板补足真实 CSS 的脱敏前后截图原生附件,以及完整验收/Agent 披露;当前正文没有这些证据。未独审通过,不作 ready/merge。

@ranxi2001
ranxi2001 changed the base branch from production to feat/bps-search-settings-20261115 November 15, 2026 07:39
@ranxi2001
ranxi2001 changed the base branch from feat/bps-search-settings-20261115 to production November 15, 2026 08:05
@ranxi2001
ranxi2001 merged commit ab9b4d9 into ranxi2001:production Nov 15, 2026
23 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.

3 participants