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
@@ -2,8 +2,14 @@
<div class="secret-settings-body">
<section v-for="module in modules" :key="module.moduleKey" class="secret-card">
<div class="secret-card-head">
<div>
<div class="secret-card-title">{{ module.moduleLabel }}</div>
<div class="secret-card-heading">
<div class="secret-card-title">
{{ module.moduleLabel }}
<span class="source-tag">{{ llmChannelLabel(moduleChannels[module.moduleKey]) }}</span>
<span class="status-pill" :class="statusPillClassOf(module.moduleKey)">
{{ statusPillTextOf(module.moduleKey) }}
</span>
</div>
<div class="secret-card-desc">{{ descriptionOf(module.moduleKey) }}</div>
</div>
<button
@@ -17,15 +23,40 @@
</button>
</div>
<input
v-model="moduleStates[module.moduleKey].input"
class="secret-input"
type="password"
:placeholder="placeholderOf(module.moduleKey)"
autocomplete="off"
spellcheck="false"
:disabled="busy"
/>
<div class="source-picker" role="radiogroup" :aria-label="`${module.moduleLabel}渠道`">
<button
v-for="option in LLM_CHANNEL_OPTIONS"
:key="option.key"
type="button"
role="radio"
:aria-checked="moduleChannels[module.moduleKey] === option.key"
class="source-option"
:class="{ 'source-option--active': moduleChannels[module.moduleKey] === option.key }"
:disabled="busy"
@click="selectChannel(module.moduleKey, option.key)"
>
<span class="source-option-label">{{ option.label }}</span>
<span class="source-option-hint">{{ option.hint }}</span>
</button>
</div>
<div class="secret-field">
<label class="field-label" :for="`secret-input-${module.moduleKey}`">接口密钥</label>
<input
:id="`secret-input-${module.moduleKey}`"
v-model="moduleStates[module.moduleKey].input"
class="secret-input"
type="password"
:placeholder="placeholderOf(module.moduleKey)"
autocomplete="off"
spellcheck="false"
:disabled="busy"
/>
</div>
<div v-if="channelSwitchNeedsValue(module.moduleKey)" class="inline-warn">
已切换到「{{ llmChannelLabel(moduleChannels[module.moduleKey]) }}」,请填写该渠道的密钥后再保存(两家渠道的密钥不通用)。
</div>
<div class="secret-actions">
<button
@@ -44,9 +75,10 @@
<section v-if="showProxy" class="secret-card">
<div class="secret-card-head">
<div>
<div class="secret-card-heading">
<div class="secret-card-title">
代理设置
<span class="source-tag">{{ proxyProviderLabel(proxyProvider) }}</span>
<span v-if="proxyLocked" class="lock-tag">后台锁定</span>
</div>
<div class="secret-card-desc">
@@ -57,6 +89,23 @@
</div>
</div>
<div class="source-picker" role="radiogroup" aria-label="代理供应商">
<button
v-for="option in PROXY_PROVIDER_OPTIONS"
:key="option.key"
type="button"
role="radio"
:aria-checked="proxyProvider === option.key"
class="source-option"
:class="{ 'source-option--active': proxyProvider === option.key }"
:disabled="!proxyReady || busy || proxyLocked"
@click="selectProxyProvider(option.key)"
>
<span class="source-option-label">{{ option.label }}</span>
<span class="source-option-hint">{{ option.hint }}</span>
</button>
</div>
<div class="proxy-field">
<label class="field-label" for="proxy-url">代理地址</label>
<input
@@ -64,7 +113,7 @@
v-model="proxyUrl"
class="secret-input"
type="text"
placeholder="如 http://user:pass@host:port 或代理提取链接"
:placeholder="proxyPlaceholder"
autocomplete="off"
spellcheck="false"
:disabled="!proxyReady || busy || proxyLocked"
@@ -72,6 +121,35 @@
/>
</div>
<div v-if="proxyReady && proxyProvider === 'qingguo'" class="retention-block">
<div class="field-label">隧道代理账号(青果 Authkey / Authpwd)</div>
<div class="proxy-plan-row">
<input
v-model="proxyAccount"
class="secret-input"
type="text"
placeholder="Authkey,如 40F79A90"
autocomplete="off"
spellcheck="false"
:disabled="busy || proxyLocked"
@input="proxyDirty = true"
/>
<input
v-model="proxyPassword"
class="secret-input"
type="password"
placeholder="Authpwd"
autocomplete="off"
spellcheck="false"
:disabled="busy || proxyLocked"
@input="proxyDirty = true"
/>
</div>
<div class="proxy-plan-hint">
青果通道提取返回的是隧道端点(如 tunpool-xxx.qg.net:16359),连接时要用这对账密做认证;只存在本机,不上报服务端。
</div>
</div>
<div class="retention-block">
<div class="field-label">代理模式</div>
<div class="retention-options">
@@ -93,7 +171,7 @@
</div>
</div>
<div v-if="proxySupported" class="retention-block">
<div v-if="proxySupported && proxyProvider === 'jikip'" class="retention-block">
<div class="field-label">jikip 套餐信息(用于余量查询与预警)</div>
<div class="proxy-plan-row">
<input
@@ -138,6 +216,9 @@
填写后,下方余量按你自己的 jikip 套餐查询;留空则显示平台默认套餐。套餐 ID / 用户 ID 在 jikip 后台「我的套餐」和「账户信息」查看。
</div>
</div>
<div v-else-if="proxySupported && proxyProvider === 'qingguo'" class="proxy-plan-hint">
青果的账户余量与通道用量请到青果后台查看;本客户端目前只做青果提取链接的连通性检测。
</div>
<div class="secret-actions">
<button
@@ -157,6 +238,7 @@
<span v-if="proxyLoading">正在读取代理配置...</span>
<span v-else-if="proxyLoadFailed">代理配置读取失败,请关闭弹窗后重试</span>
<span v-else-if="!proxySupported">代理设置仅在桌面客户端中可用</span>
<span v-else-if="proxyProvider === 'qingguo'">供应商:青果 · 提取链接示例 https://overseas.proxy.qg.net/get?key=...&format=json</span>
<span v-else-if="balanceLoading">正在查询代理余量...</span>
<span v-else-if="balance">{{ balanceText }}</span>
<span v-else>余额查询暂不可用</span>
@@ -184,6 +266,19 @@ import {
type ServerProxySnapshot,
type UserApiSecretCheckResult,
} from '@/shared/utils/api-secret-store'
import {
DEFAULT_LLM_CHANNEL,
DEFAULT_PROXY_PROVIDER,
LLM_CHANNEL_OPTIONS,
PROXY_PROVIDER_OPTIONS,
detectProxyProviderFromUrl,
llmChannelLabel,
normalizeLlmChannel,
normalizeProxyProvider,
proxyProviderLabel,
type LlmChannelKey,
type ProxyProviderKey,
} from '@/shared/utils/api-secret-channel'
import { getPywebviewApi, type ProxyMode, type DesktopConfigUpdate } from '@/shared/bridges/pywebview'
import { deleteMyApiSecret, putMyApiSecret, fetchProxyPlan, saveProxyPlan, clearProxyPlan } from '@/shared/api/types/modules/user-secret'
import { PROXY_PLAN_CHANGED_EVENT } from '@/shared/utils/proxy-balance-alert'
@@ -209,9 +304,15 @@ type ModuleState = {
const modules = ref(listApiSecretModules())
const moduleStates = reactive<Record<string, ModuleState>>({})
/** 每个模块当前选择的渠道:默认龙抬头,加载后以服务端已存值为准。 */
const moduleChannels = reactive<Record<string, LlmChannelKey>>({})
/** 用户手动切过渠道、但还没为这个渠道填写密钥:保存前必须拦住(两家密钥不通用)。 */
const channelDirty = reactive<Record<string, boolean>>({})
// 首次渲染即需可读:按模块清单预初始化状态(后续 refreshSnapshots 兜底补齐)
for (const module of modules.value) {
moduleStates[module.moduleKey] = { input: '', checking: false, result: null, error: '', lastCheckSource: '' }
moduleChannels[module.moduleKey] = DEFAULT_LLM_CHANNEL
channelDirty[module.moduleKey] = false
}
const snapshots = ref<Record<string, ApiSecretSnapshot>>({})
const busy = ref(false)
@@ -222,6 +323,10 @@ const proxyLocked = computed(() => Boolean(serverProxy.value?.locked && serverPr
const proxyUrl = ref('')
const proxyMode = ref<ProxyMode>(1)
const proxyProvider = ref<ProxyProviderKey>(DEFAULT_PROXY_PROVIDER)
/** 青果隧道端点的代理账密(Authkey/Authpwd):只存本机 app.json,不上报服务端。 */
const proxyAccount = ref('')
const proxyPassword = ref('')
const proxyLoading = ref(false)
const proxyLoadFailed = ref(false)
const proxyReady = ref(false)
@@ -238,6 +343,12 @@ const proxyPlanConfigured = ref(false)
const proxyPlanLoading = ref(false)
const proxyPlanSaving = ref(false)
const proxyPlaceholder = computed(() =>
proxyProvider.value === 'qingguo'
? 'https://overseas.proxy.qg.net/get?key=...&num=1&format=json'
: 'https://api.jikip.com/ip-get?num=1&minute=3&key=... 或 http://user:pass@host:port',
)
const proxyStatusText = computed(() => {
if (proxyChecking.value) return '正在检测...'
if (proxyCheckResult.value) {
@@ -258,6 +369,15 @@ const proxyResultClass = computed(() => {
}
})
/** 切换代理供应商:只改本地选择,保存时与地址一起写入(检测也会按新供应商解析响应)。 */
function selectProxyProvider(provider: ProxyProviderKey) {
if (proxyProvider.value === provider) return
proxyProvider.value = provider
proxyDirty.value = true
proxyCheckResult.value = null
proxyCheckError.value = ''
}
/** 检测代理连通性:地址有改动时检测输入值(不落库),否则检测/落库已存值并刷新状态展示。 */
async function runProxyCheck() {
if (proxyChecking.value) return
@@ -267,7 +387,8 @@ async function runProxyCheck() {
proxyCheckError.value = ''
proxyCheckResult.value = null
try {
proxyCheckResult.value = await checkApiSecret('proxy', dirty ? inputValue : undefined)
// 供应商一起提交:检测要按对应供应商解析提取响应(青果/极客返回体不同)
proxyCheckResult.value = await checkApiSecret('proxy', dirty ? inputValue : undefined, proxyProvider.value)
const result = proxyCheckResult.value
if (result.checkStatus === 'failed') {
ElMessage.warning(
@@ -310,15 +431,34 @@ function ensureModuleState(moduleKey: string) {
if (!moduleStates[moduleKey]) {
moduleStates[moduleKey] = { input: '', checking: false, result: null, error: '', lastCheckSource: '' }
}
if (!moduleChannels[moduleKey]) {
moduleChannels[moduleKey] = DEFAULT_LLM_CHANNEL
}
return moduleStates[moduleKey]
}
/** 用户切换渠道:只改选择,保存时随密钥一起提交;已有密钥但没重新填写时给出提示。 */
function selectChannel(moduleKey: string, channel: LlmChannelKey) {
if (moduleChannels[moduleKey] === channel) return
moduleChannels[moduleKey] = channel
channelDirty[moduleKey] = true
}
/** 切到新渠道但没填新密钥(且已有旧渠道密钥):保存前必须拦住。 */
function channelSwitchNeedsValue(moduleKey: string) {
return Boolean(channelDirty[moduleKey]) && !ensureModuleState(moduleKey).input.trim() && snapshotOf(moduleKey).exists
}
function refreshSnapshots() {
modules.value = listApiSecretModules()
const next: Record<string, ApiSecretSnapshot> = {}
for (const module of modules.value) {
next[module.moduleKey] = getStoredApiSecretSnapshot(module.moduleKey as ApiSecretModuleKey)
ensureModuleState(module.moduleKey)
// 只在用户没主动切换过时跟服务端对齐,避免把手动选择回退掉
if (!channelDirty[module.moduleKey]) {
moduleChannels[module.moduleKey] = normalizeLlmChannel(next[module.moduleKey].channel)
}
}
snapshots.value = next
serverProxy.value = getServerProxySnapshot()
@@ -337,7 +477,9 @@ function placeholderOf(moduleKey: string) {
if (snapshot.exists) {
return `已保存(${snapshot.masked || '****'}),输入新值可覆盖`
}
return '请输入 LLM 接口密钥'
return moduleChannels[moduleKey] === 'longtaitou'
? '请输入龙抬头接口密钥(sk-...)'
: '请输入贞贞接口密钥(sk-...)'
}
const CHECK_STATUS_TEXT: Record<ApiSecretCheckStatus, string> = {
@@ -347,6 +489,26 @@ const CHECK_STATUS_TEXT: Record<ApiSecretCheckStatus, string> = {
unknown: '已保存,未检测',
}
function statusPillTextOf(moduleKey: string) {
const state = ensureModuleState(moduleKey)
if (state.checking) return '检测中'
const status = state.result?.checkStatus || snapshotOf(moduleKey).checkStatus
if (status === 'passed') return '可用'
if (status === 'failed') return '不可用'
if (status === 'error') return '待确认'
return snapshotOf(moduleKey).exists ? '未检测' : '未配置'
}
function statusPillClassOf(moduleKey: string) {
const state = ensureModuleState(moduleKey)
const status = state.result?.checkStatus || snapshotOf(moduleKey).checkStatus
return {
'status-pill--ok': status === 'passed',
'status-pill--fail': status === 'failed',
'status-pill--warn': status === 'error',
}
}
function formatTime(millis: number | null) {
if (!millis) return ''
const date = new Date(millis)
@@ -400,7 +562,8 @@ async function runCheck(moduleKey: ApiSecretModuleKey) {
state.lastCheckSource = inputValue ? 'input' : 'saved'
try {
// 不传 override 时服务端检测的是当前登录用户在密钥配置里保存的密钥(按 uid 绑定)
const result = await checkApiSecret(moduleKey, inputValue || undefined)
// 渠道一起提交:检测必须走所选渠道,否则「连通」是别的渠道的结论
const result = await checkApiSecret(moduleKey, inputValue || undefined, moduleChannels[moduleKey])
state.result = result
if (result.checkStatus === 'failed') {
ElMessage.warning(result.checkMessage || '密钥无效')
@@ -427,6 +590,7 @@ async function clearModule(moduleKey: ApiSecretModuleKey) {
state.input = ''
state.result = null
state.error = ''
channelDirty[moduleKey] = false
refreshSnapshots()
ElMessage.success('已清空密钥')
} catch (error) {
@@ -451,22 +615,42 @@ function readUserProxy(config: Record<string, unknown> | null | undefined) {
const own = (users[uid] ?? {}) as Record<string, unknown>
const ownUrl = typeof own.proxy_url === 'string' ? own.proxy_url.trim() : ''
if (ownUrl) {
return { url: ownUrl, mode: Number(own.proxy_mode) === 2 ? 2 : 1 }
return {
url: ownUrl,
mode: Number(own.proxy_mode) === 2 ? 2 : 1,
provider: normalizeProxyProvider(own.proxy_provider ?? detectProxyProviderFromUrl(ownUrl)),
account: typeof own.proxy_account === 'string' ? own.proxy_account : '',
password: typeof own.proxy_password === 'string' ? own.proxy_password : '',
}
}
}
const url = typeof config?.proxy_url === 'string' ? config.proxy_url : ''
return {
url: typeof config?.proxy_url === 'string' ? config.proxy_url : '',
url,
mode: Number(config?.proxy_mode) === 2 ? 2 : 1,
provider: normalizeProxyProvider(config?.proxy_provider ?? detectProxyProviderFromUrl(url)),
account: typeof config?.proxy_account === 'string' ? config.proxy_account : '',
password: typeof config?.proxy_password === 'string' ? config.proxy_password : '',
}
}
function userProxyPatch(nextProxyUrl: string, nextProxyMode: ProxyMode) {
function userProxyPatch(
nextProxyUrl: string,
nextProxyMode: ProxyMode,
provider: ProxyProviderKey,
account: string,
password: string,
) {
// 极客不需要这对账密:切过去时一并清空,避免残留串到别的供应商
const credentials = provider === 'qingguo'
? { proxy_account: account.trim(), proxy_password: password }
: { proxy_account: '', proxy_password: '' }
const uid = proxyUserId()
if (uid === '0') {
return { proxy_url: nextProxyUrl, proxy_mode: nextProxyMode }
return { proxy_url: nextProxyUrl, proxy_mode: nextProxyMode, proxy_provider: provider, ...credentials }
}
const users: Record<string, unknown> = {}
users[uid] = { proxy_url: nextProxyUrl, proxy_mode: nextProxyMode }
users[uid] = { proxy_url: nextProxyUrl, proxy_mode: nextProxyMode, proxy_provider: provider, ...credentials }
return { proxy_users: users }
}
@@ -477,7 +661,7 @@ async function loadProxyConfig() {
proxyDirty.value = false
const api = getPywebviewApi()
proxySupported.value = Boolean(api?.read_config && api.save_config)
proxySupported.value = Boolean(api?.read_config && api?.save_config)
if (!api?.read_config || !api.save_config) {
proxyUrl.value = ''
proxyMode.value = 1
@@ -490,6 +674,12 @@ async function loadProxyConfig() {
const own = readUserProxy(config as Record<string, unknown>)
proxyUrl.value = own.url
proxyMode.value = (own.mode === 2 ? 2 : 1) as ProxyMode
proxyAccount.value = own.account
proxyPassword.value = own.password
// 本地配置是权威(客户端任务链读的就是它);本地没写过时才用服务端里记的供应商
proxyProvider.value = own.url
? own.provider
: normalizeProxyProvider(serverProxy.value?.channel ?? own.provider)
proxyReady.value = true
} catch (error) {
proxyLoadFailed.value = true
@@ -504,7 +694,8 @@ async function syncProxyToServer(url: string) {
if (proxyUserId() === '0') return
try {
if (url) {
await putMyApiSecret('proxy', url)
// 供应商随地址一起上报:服务端检测要按供应商解析提取响应
await putMyApiSecret('proxy', url, proxyProvider.value)
} else {
await deleteMyApiSecret('proxy')
}
@@ -515,6 +706,10 @@ async function syncProxyToServer(url: string) {
}
async function loadProxyPlan() {
if (proxyProvider.value !== 'jikip') {
proxyPlanConfigured.value = false
return
}
proxyPlanLoading.value = true
try {
const result = await fetchProxyPlan().catch((error) => {
@@ -574,6 +769,11 @@ async function clearProxyPlanInfo() {
}
async function loadBalance() {
// 余量接口目前只有极客口径(jikip find-balance);青果不在客户端查询
if (proxyProvider.value !== 'jikip') {
balance.value = null
return
}
balanceLoading.value = true
try {
const result = await fetchProxyBalanceSafely()
@@ -597,6 +797,14 @@ async function loadBalance() {
*/
async function saveAll(options: { requireAll?: boolean } = {}): Promise<boolean> {
if (busy.value || proxyLoading.value) return false
// 切了渠道却只留着旧渠道的密钥:两家密钥不通用,必须让用户补填,否则保存后必然不可用
const needRefill = modules.value.filter((module) => channelSwitchNeedsValue(module.moduleKey))
if (needRefill.length) {
ElMessage.warning(
`已切换渠道,请填写该渠道的密钥:${needRefill.map((module) => module.moduleLabel).join('、')}`,
)
return false
}
const pendingModules = modules.value.filter((module) => ensureModuleState(module.moduleKey).input.trim())
if (options.requireAll) {
const missing = modules.value.filter(
@@ -614,13 +822,14 @@ async function saveAll(options: { requireAll?: boolean } = {}): Promise<boolean>
for (const module of pendingModules) {
const moduleKey = module.moduleKey as ApiSecretModuleKey
const state = ensureModuleState(module.moduleKey)
await saveApiSecret(moduleKey, state.input.trim())
await saveApiSecret(moduleKey, state.input.trim(), moduleChannels[module.moduleKey])
state.input = ''
// 输入值已保存:本地那次「检测输入值」的结果不再代表当前配置,清掉后展示统一走服务端快照
// (保存前检测过的同一个值,服务端会沿用那次结果,快照里直接是「检测通过」)
state.result = null
state.lastCheckSource = ''
state.error = ''
channelDirty[module.moduleKey] = false
}
secretsSaved = true
refreshSnapshots()
@@ -629,13 +838,17 @@ async function saveAll(options: { requireAll?: boolean } = {}): Promise<boolean>
const api = getPywebviewApi()
if (!api?.save_config) throw new Error('当前客户端未提供代理配置保存能力')
const nextProxyUrl = proxyUrl.value.trim()
await api.save_config(userProxyPatch(nextProxyUrl, proxyMode.value) as DesktopConfigUpdate)
await api.save_config(
userProxyPatch(nextProxyUrl, proxyMode.value, proxyProvider.value, proxyAccount.value, proxyPassword.value) as DesktopConfigUpdate,
)
proxyUrl.value = nextProxyUrl
proxyDirty.value = false
// 同上:地址已保存,本地「未保存」的检测文案不再适用
proxyCheckResult.value = null
proxyCheckError.value = ''
await syncProxyToServer(nextProxyUrl)
void loadProxyPlan()
void loadBalance()
}
// 保存后不再自动检测:检测一律由用户手动点击「检测」触发