feat(user-secret): 密钥设置支持 LLM 渠道与代理供应商切换

- 用户密钥新增 channel 列(V180):LLM 行存渠道 longtaitou/t8star,代理行存供应商
  qingguo/jikip;存量与新建默认均回填 t8star/jikip(默认仍走贞贞与极客,手动可切)
- 外观专利/货源查询按任务归属用户的密钥渠道路由 LLM 主机(渠道经 SecretUsageContext
  下到工作线程,不逐层改签名);切到龙抬头时模型映射 gemini-3.1-flash-lite 并补
  enable_thinking + thinking_budget=medium(对齐贞贞现网口径),检测链路刻意不思考
- 代理检测按供应商解析:青果 code 为字符串、隧道端点支持 域名:端口、
  NO_AVAILABLE_CHANNEL 归为可重试;青果只验提取成功(账密只在客户端本地)
- 密钥设置页:每个模块加渠道分段选择、代理卡加供应商选择与青果 Authkey/Authpwd
  (只存本机,不上报),切换渠道未重填密钥时拦住保存;换号继承带渠道与供应商
- 后管密钥管理三列显示渠道/供应商标签
This commit is contained in:
2026-10-30 04:00:38 +08:00
parent eaab173ae9
commit 457af3607f
36 changed files with 1644 additions and 159 deletions
+108
View File
@@ -3,6 +3,7 @@ import assert from 'node:assert/strict'
import { http } from '../src/shared/api/http.ts'
import {
captureApiSecretsForInheritance,
checkApiSecret,
clearApiSecretCache,
confirmApiSecretInheritance,
declineApiSecretInheritance,
@@ -307,11 +308,13 @@ function seedDesktopMirror(
uid: string,
moduleKey: string,
value: string,
channel = '',
) {
localStorage.setItem(`brand:api-secret-cache:${uid}:${moduleKey}`, JSON.stringify({
schema: 2,
value,
masked: '',
channel,
exists: true,
locked: false,
checkStatus: 'passed',
@@ -812,3 +815,108 @@ test('test_secret_store_locked_proxy_not_in_module_cards', async (t) => {
clearApiSecretCache()
assert.equal(getServerProxySnapshot(), null, '登出清理应重置服务端代理状态')
})
test('test_secret_store_save_sends_channel_and_keeps_it', async (t) => {
setupWindow()
clearApiSecretCache()
let body: Record<string, unknown> | null = null
mockRequest(t, (config) => {
body = (config.data || {}) as Record<string, unknown>
return okResponse(serverItem('appearance-patent', { masked: 'sk-a****1234', exists: true, channel: 'longtaitou' }))
})
await saveApiSecret('appearance-patent', 'sk-abc123456', 'longtaitou')
assert.equal(body?.channel, 'longtaitou', '保存必须把渠道一起提交,否则服务端按默认渠道落库')
assert.equal(getStoredApiSecretSnapshot('appearance-patent').channel, 'longtaitou')
})
test('test_secret_store_check_passes_channel', async (t) => {
setupWindow()
clearApiSecretCache()
let body: Record<string, unknown> | null = null
mockRequest(t, (config) => {
body = (config.data || {}) as Record<string, unknown>
return okResponse({
moduleKey: 'similar-asin',
checkStatus: 'passed',
checkCode: 'ok',
checkMessage: '连通正常',
checkLatencyMs: 120,
checkedAt: null,
viaProxy: false,
})
})
const result = await checkApiSecret('similar-asin', 'sk-abc123456', 't8star')
assert.equal(body?.channel, 't8star', '检测要按所选渠道发起,别拿默认渠道的结论冒充')
assert.equal(body?.value, 'sk-abc123456')
assert.equal(result.checkStatus, 'passed')
})
test('test_secret_store_snapshot_without_channel_stays_empty', async (t) => {
setupWindow()
clearApiSecretCache()
mockRequest(t, () => bundleResponse([
serverItem('appearance-patent', { exists: true, masked: 'sk-a****1234' }),
serverItem('similar-asin'),
]))
await loadApiSecrets({ force: true })
assert.equal(
getStoredApiSecretSnapshot('appearance-patent').channel,
'',
'老版本后端不下发渠道时保留空串,由界面按默认值展示',
)
})
test('test_secret_store_inheritance_keeps_channel_and_proxy_provider', async (t) => {
const { localStorage } = setupWindow()
clearApiSecretCache()
const aliceProxy = 'https://overseas.proxy.qg.net/get?key=alice&format=json'
let config: Record<string, unknown> = {
current_uid: '42',
proxy_users: { '42': { proxy_url: aliceProxy, proxy_mode: 1, proxy_provider: 'qingguo' } },
}
attachDesktopBridge(
() => config,
(patch) => {
config = mergeDesktopConfig(config, patch)
return config
},
)
localStorage.setItem('username', 'alice')
// 龙抬头的密钥:换号继承时必须把渠道一起带走,否则下一个账号会把它按「存量=贞贞」落库
seedDesktopMirror(localStorage, '42', 'appearance-patent', 'sk-alice-longtaitou', 'longtaitou')
await captureApiSecretsForInheritance()
clearApiSecretCache()
localStorage.removeItem('uid')
localStorage.setItem('uid', '43')
localStorage.setItem('username', 'bob')
let migratePayload: Record<string, unknown> | null = null
mockRequest(t, (req) => {
if ((req.url || '').includes('/migrate')) {
migratePayload = req.data as Record<string, unknown>
return okResponse({ migrated: 1 })
}
return bundleResponse([
serverItem('appearance-patent'),
serverItem('similar-asin', { exists: true, masked: 'sk-c****9999' }),
])
})
await loadApiSecrets({ force: true })
await confirmApiSecretInheritance()
const items = ((migratePayload?.items || []) as Array<Record<string, unknown>>)
const appearance = items.find((item) => item.moduleKey === 'appearance-patent')
assert.equal(appearance?.channel, 'longtaitou', '继承要带上渠道,不能按新建默认落库')
const proxy = items.find((item) => item.moduleKey === 'proxy')
assert.equal(proxy?.channel, 'qingguo', '代理继承要带上供应商')
const users = (config.proxy_users || {}) as Record<string, Record<string, unknown>>
assert.equal(users['43']?.proxy_provider, 'qingguo', '写回本机配置时供应商不能丢')
})