Repository navigation
feat(kimi): support multiple official accounts in Auth Center - #8726
Conversation
Isolate account credentials, providers and model aliases; preserve native logins and protect official OAuth nodes. Fix session image access, drop unpublished usage repair paths and the kimi-cli alias, and synchronize all four READMEs.
farion1231
left a comment
There was a problem hiding this comment.
感谢跟进!每个账号独立凭据文件和模型别名、写 config.toml 时按键名逐项改写、写入失败回滚这几处都做得很扎实,后端测试在本地合并到最新 main 后全部通过。下面三个问题需要处理:
[P2] 前端 CI 失败
isOfficialAccount 新增了 type === "kimi" 条件(providerCapabilities.ts#L100),但 src/utils/providerCapabilities.test.ts 第 16–27 行的三个用例夹具只有 oauth.key、没有 type,因此全部失败(CI Frontend Checks 与本地 vitest 都是这 3 条)。给这三个夹具补上 type: "kimi" 即可,顺便可以加一条非 managed:kimi-code ID 的官方账号识别断言。
[P2] 新账号从不使用默认凭据槽位,Kimi 本身未登录时联网搜索 / 网页抓取会认证失败
现在新登录一律生成 kimi-code-ccs-<uuid> 供应商和同名凭据槽位(kimi_oauth.rs#L517)。而 main 上这条登录写的是 managed:kimi-code + oauth/kimi-code(kimi_config.rs#L552)。
我们用 Kimi Code 2.3.0 实测过:对话请求按各供应商自己的 oauth.key 取凭据,多账号对话没问题;但 moonshot_search / moonshot_fetch 会忽略 services 里写的 oauth.key,运行时一律改回默认槽位 oauth/kimi-code。所以:
- 没在 Kimi 里登录过、只通过 CC Switch 登录的用户(之前在 main 上是正常的),现在对话可用,但联网搜索和网页抓取会报认证失败;
- 切换账号时
select_oauth_services(kimi_config.rs#L481)改写 services 不会改变搜索 / 抓取实际使用的账号,文档里「受管联网搜索和抓取服务也跟随所选账号」与实际行为不符。
修法:登录时如果默认槽位还没有凭据(managed:kimi-code 不存在或 credentials/kimi-code.json 缺失),第一个账号沿用 managed:kimi-code + 官方默认 oauth 引用(与 Kimi 自带登录一致),之后的账号再用独立槽位。
[P2] 官方账号被外部移除后,卡片在 CC Switch 里删不掉
供应商列表会把每个原生节点存进数据库(provider/mod.rs#L5488)。如果之后节点从 config.toml 消失——例如在 Kimi 里执行 /logout,官方登出会删除 managed:kimi-code 供应商及其模型——数据库里那一行仍是官方 OAuth 配置,ensure_kimi_provider_editable(provider/mod.rs#L6626)按数据库记录拒绝删除和移除,而授权中心只读 config.toml、不会列出这个账号。结果是一张既不在 Kimi 配置里、又无法删除的卡片(kimi_official_accounts_reject_provider_mutations_even_after_external_removal 正好断言了这个行为)。main 上这种卡片可以删除。
修法:只按当前 config.toml 里的节点判断是否受保护;节点已不在原生配置中时,允许删除数据库里的记录。
以上三处修掉后我会尽快复审。
Restore the native default credential slot for the first account, stop rewriting tool services on account switches, allow deleting profiles removed from native config, and fix official-account test fixtures and documentation.
Use fixed official hosts for mainland and global sign-ins, keep existing account regions and credential slots during reauthentication, and preserve sanitized transport error causes. Add regional routing and network-error regression coverage.
Follow-up to #8726, which lets the Authorization Center hold several Kimi official subscriptions, each with its own provider and credential slot. Identity: after sign-in (and for logins found on disk) read /me to show the account's nickname on its row and card. Signing in to an account that is already listed writes back to its slot instead of adding a duplicate, and the slot is chosen when the login completes, so a native Kimi login made meanwhile is never overwritten. New separate slots are named from a hash of region and user id, stable across devices. Opening the Kimi page reads identities too, so card names carry the nickname without a visit to the Authorization Center first. Remove instead of sign out: a separate account is deleted together with its provider node, models, credential and card (refused while in use); web search/fetch pointing at it moves to Kimi's own default login. Kimi's own login is only hidden from the list - CC Switch never logs Kimi out - and stays hidden across Kimi's token rotations until the user signs in to it again here. An empty list caused by that says so instead of "signed out". Quota: each account row and official card shows its quota. Tokens close to expiry are refreshed under the same proper-lockfile-compatible lock Kimi uses (mkdir <slot>.lock, 5 s stale takeover), with Kimi's revoked token recovery. Windows, where Kimi takes no lock, only reads. Also: re-login keeps custom fields such as custom_headers on the node; deleting a card whose node was removed elsewhere deletes the leftover CC Switch-owned credential; the card's switch button works for official accounts after checking they are signed in on this machine; account rows use the same compact layout as the other Authorization Center groups.
Summary / 概述
为 Kimi Code 增加授权中心多账号管理,每个账号使用独立的凭据文件、原生供应商节点和模型别名。支持添加账号、逐账号重新登录、退出和选择使用;已有
managed:kimi-code登录保留原来的节点、模型别名和凭据引用。managed:kimi-code和官方默认 OAuth 引用;默认登录已存在时,新增账号使用独立槽位。services。auth.kimi.com/api.kimi.com,海外版使用auth.kimi.ai/api.kimi.ai;不使用进程环境变量覆盖登录地址,已有账号重新登录保留其区域和凭据槽位。type: "kimi",增加独立供应商 ID 的识别断言和外部移除后的档案删除回归测试。session_manager/content.rs的项目目录解析补齐 Kimi 分支。agent-loop旧用量修复分支及对应测试,更新接入说明。AppType::FromStr移除kimi-cli别名,保留kimi和kimi-code。Related Issue / 关联 Issue
Follow-up to #8710.
Validation / 实测验证
pnpm test:unit -- --maxWorkers=2 --minWorkers=1:251 个文件、3217 项测试全部通过。tests/components/KimiAccountLogin.test.tsx:11 项通过。cargo test --manifest-path src-tauri/Cargo.toml --lib kimi -- --test-threads=1:53 项通过,包含区域选择、重新登录及连接错误信息的新增回归测试。cargo test --manifest-path src-tauri/Cargo.toml --test kimi_commands -- --test-threads=1:7 项通过。pnpm build:renderer:通过。cargo fmt --manifest-path src-tauri/Cargo.toml -- --check:通过。git diff --check:通过。OAuth 后端测试使用本地模拟 HTTP 服务,覆盖默认槽位初始化、后续账号隔离、重新登录、单账号退出、凭据损坏隔离、取消授权和写入失败回滚;账号切换测试同时检查
services保持原配置。Checklist / 检查清单
pnpm typecheck通过。pnpm format:check通过。