修复: 协议层与体验缺陷六件
- temperature 按模型适配,仅收 1 的模型不再 400 - 流式 error 帧不再被 choices 必填整帧丢弃 - 只读缓存写后失效 - git diff 中文截断撞 UTF-8 边界 panic - 非视觉模型纯图片直接拒绝 - 全局快捷键补输入焦点守卫
This commit is contained in:
@@ -521,6 +521,12 @@ async function fetchModels() {
|
||||
apiKey: providerForm.apiKey,
|
||||
providerId: providerForm.editId || null,
|
||||
})
|
||||
// 空列表守卫:拉到 0 个模型时保留现有模型表格(不覆盖),仅提示——
|
||||
// 与后端 ai_fetch_models 空守卫同语义(空结果不清用户配置),防误清后顺手保存落库
|
||||
if (models.length === 0) {
|
||||
emit('toast', t('settings.toastFetchEmpty'), 'warning')
|
||||
return
|
||||
}
|
||||
// 手动优先:探测结果合并已存在的 UserSet 标注——用户手动改过的能力不被「测试连接」覆盖
|
||||
// (对齐后端 ai_fetch_models 合并逻辑:probe_source==UserSet 保留手动能力维度)。
|
||||
// enabled/weight 同理保留旧值:重拉只是刷新能力维度,用户已关掉的模型/调过的权重
|
||||
@@ -599,6 +605,20 @@ async function saveProvider() {
|
||||
} else {
|
||||
providerForm.temperature = null
|
||||
}
|
||||
// 模型权重钳制 [0,100](同温度范式:原生 min/max 只约束步进按钮,手输越界照存)。
|
||||
// 越界/小数 → clamp+取整;清空残留非数值(v-model.number 得 '')→ 归一 50(对齐负载池 NaN 兜底)。
|
||||
// 多行聚合一次 toast,逐行报会刷屏。
|
||||
let weightClamped = false
|
||||
for (const m of providerForm.models) {
|
||||
if (typeof m.weight === 'number' && Number.isFinite(m.weight)) {
|
||||
const c = Math.min(100, Math.max(0, Math.trunc(m.weight)))
|
||||
if (c !== m.weight) { m.weight = c; weightClamped = true }
|
||||
} else {
|
||||
m.weight = 50
|
||||
weightClamped = true
|
||||
}
|
||||
}
|
||||
if (weightClamped) emit('toast', t('settings.toastWeightClamped'), 'warning')
|
||||
providerForm.saving = true
|
||||
try {
|
||||
await aiApi.saveProvider({
|
||||
@@ -672,7 +692,9 @@ async function onPoolToggle(p: AiProviderConfig, enabled: boolean) {
|
||||
const prev = p.enabled
|
||||
p.enabled = enabled
|
||||
try {
|
||||
await aiApi.updateProviderPool(p.id, enabled, p.weight ?? 50)
|
||||
// 防御钳制:p.weight 理论上已被 onPoolWeightChange 钳过,此处兜底防脏数据直传 IPC
|
||||
const w = Math.min(100, Math.max(0, p.weight ?? 50))
|
||||
await aiApi.updateProviderPool(p.id, enabled, w)
|
||||
emit('toast', t('settings.toastPoolUpdateOk'), 'info')
|
||||
} catch (e) {
|
||||
p.enabled = prev // revert
|
||||
|
||||
Reference in New Issue
Block a user