feat(agents): 模型改为页面可选(方案 A)+ 修引擎模型读不到的静默 bug(版本 2.5.4 → 2.6.0)
推翻旧结论:模型不是全局唯一,而是每个 profile 各存一份 active_model (PUT /api/models/active scope=agent → workspaces/<profile>/agent.json), 改完即时生效不用重启 —— 实测切模型后真对话 turn_usage 的 model_name 确实变了。 真 bug:refresh_engine_live() 读的是 /api/providers/active,那条是 404, 异常被吞 → engine_live['model'] 恒为空串 → 配置页模型栏一直显示「—」。 改用 ACTIVE_MODEL_PATH=/api/models/active + get_active_model()。 新增: - 适配器 get_active_model / set_active_model(4xx 抛 EngineError 并透传引擎原文) - GET /agents/engine/models(只列真能用的;实时 current,不走 TTL 缓存) - PUT /agents/engine/model(带防自指护栏,不得指向 agent/*) - 前端配置页模型栏:只读 → 可搜索下拉(按供应商分组 + 视觉标)+ 刷新;失败回滚 - i18n 删过期键、加 5 新键(中英 883/883 对称) - 测试 +5(端点/路径常量回归/body 与头/4xx 抛错/防自指),224 passed 语义:方案 A = 所有智能体共用这一个模型(一个 profile 一个 active_model), 做不到 A 用 flash 且 B 用 pro 并存;那需方案 B(一智能体一 profile)。
This commit is contained in:
1 parent
a9b74ef5d5
commit
a77b1fcf92
9 files changed
+428
-27
No files matched your search
@@ -89,6 +89,29 @@ export const testAgent = (slug: string) =>
|
||||
export const agentSessions = (slug: string) =>
|
||||
req<{ slug: string; kind: string; items: any[] }>(`/agents/${slug}/sessions`)
|
||||
|
||||
/** 引擎可选模型清单 + 当前生效模型(第四十轮 · 方案 A:所有智能体共用)。 */
|
||||
export interface EngineModelOption {
|
||||
provider_id: string
|
||||
provider_name: string
|
||||
model: string
|
||||
vision: boolean
|
||||
}
|
||||
export interface EngineModelsResp {
|
||||
options: EngineModelOption[]
|
||||
current: { provider_id: string; model: string }
|
||||
engine: { base_url: string; agent_id: string; ready: boolean }
|
||||
scope_note: string
|
||||
}
|
||||
|
||||
export const engineModels = () => req<EngineModelsResp>('/agents/engine/models')
|
||||
|
||||
/** 切换引擎模型(即时生效,不用重启)。 */
|
||||
export const setEngineModel = (providerId: string, model: string) =>
|
||||
req<{ status: string; current: { provider_id: string; model: string } }>(
|
||||
'/agents/engine/model',
|
||||
{ method: 'PUT', body: JSON.stringify({ provider_id: providerId, model }) },
|
||||
)
|
||||
|
||||
export const stopAgent = (slug: string, chatId: string) =>
|
||||
req<{ status: string }>(`/agents/${slug}/stop?chat_id=${encodeURIComponent(chatId)}`, { method: 'POST' })
|
||||
|
||||
|
||||
@@ -411,8 +411,11 @@ export default {
|
||||
cfgDesc: 'Description',
|
||||
cfgModel: 'Model',
|
||||
cfgModelSub: 'From the gateway models',
|
||||
cfgModelReadonly: 'Model is set by QwenPaw profile {profile}',
|
||||
cfgModelHint: 'Engine model is a profile-level setting — all agents share one model. Change it in QwenPaw:',
|
||||
cfgModelPick: 'Pick a model',
|
||||
cfgModelRefresh: 'Refresh',
|
||||
cfgModelVision: 'vision',
|
||||
cfgModelSwitched: 'Switched to {model} (shared by all agents, takes effect immediately)',
|
||||
cfgModelHintShared: 'All agents share this one model (the engine stores it per profile). Switching takes effect immediately, no restart. You can also change it in QwenPaw:',
|
||||
cfgOpenQwenpaw: 'Open QwenPaw',
|
||||
cfgExec: 'Execution',
|
||||
cfgExecSub: 'Affects server safety, read-only for now',
|
||||
|
||||
@@ -414,8 +414,11 @@ export default {
|
||||
cfgDesc: '描述',
|
||||
cfgModel: '模型',
|
||||
cfgModelSub: '从网关的模型里选',
|
||||
cfgModelReadonly: '模型由 QwenPaw 的 {profile} profile 决定',
|
||||
cfgModelHint: '引擎的模型是 profile 级设置 —— 所有智能体共用同一个模型。要改请去 QwenPaw:',
|
||||
cfgModelPick: '选择模型',
|
||||
cfgModelRefresh: '刷新',
|
||||
cfgModelVision: '视觉',
|
||||
cfgModelSwitched: '已切换到 {model}(所有智能体共用,即时生效)',
|
||||
cfgModelHintShared: '所有智能体共用这一个模型(引擎按 profile 存模型)。切换即时生效,不用重启引擎。也可以去 QwenPaw 改:',
|
||||
cfgOpenQwenpaw: '打开 QwenPaw',
|
||||
cfgExec: '执行',
|
||||
cfgExecSub: '影响服务器安全,一期只读',
|
||||
|
||||
@@ -101,7 +101,7 @@
|
||||
|
||||
<div class="ag-tabs">
|
||||
<span :class="{ on: tab === 'chat' }" @click="tab = 'chat'">{{ t('agents.tabChat') }}</span>
|
||||
<span :class="{ on: tab === 'config' }" @click="tab = 'config'">{{ t('agents.tabConfig') }}</span>
|
||||
<span :class="{ on: tab === 'config' }" @click="tab = 'config'; loadEngineModels()">{{ t('agents.tabConfig') }}</span>
|
||||
<span :class="{ on: tab === 'runs' }" @click="tab = 'runs'; loadRuns()">{{ t('agents.tabRuns') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -255,13 +255,36 @@
|
||||
<div class="card-h"><b>{{ t('agents.cfgModel') }}</b><span class="sub">{{ t('agents.cfgModelSub') }}</span></div>
|
||||
<div class="frow">
|
||||
<div class="f-lab">{{ t('agents.cfgModel') }}</div>
|
||||
<div class="f-val">
|
||||
<span class="code">{{ cur.engine_model || '—' }}</span>
|
||||
<span class="f-lock"><Icon name="lock" :size="12" />{{ t('agents.cfgReadonly') }}</span>
|
||||
<div class="f-val model-pick">
|
||||
<el-select
|
||||
v-model="enginePick"
|
||||
size="small"
|
||||
filterable
|
||||
:loading="engineLoading"
|
||||
:placeholder="t('agents.cfgModelPick')"
|
||||
style="flex:1;min-width:0"
|
||||
@change="doSetModel"
|
||||
>
|
||||
<el-option-group
|
||||
v-for="g in engineGroups" :key="g.provider_id"
|
||||
:label="g.provider_name"
|
||||
>
|
||||
<el-option
|
||||
v-for="o in g.items" :key="o.provider_id + '/' + o.model"
|
||||
:label="o.model" :value="o.provider_id + '/' + o.model"
|
||||
>
|
||||
<span>{{ o.model }}</span>
|
||||
<span v-if="o.vision" class="opt-vision">{{ t('agents.cfgModelVision') }}</span>
|
||||
</el-option>
|
||||
</el-option-group>
|
||||
</el-select>
|
||||
<el-button size="small" :loading="engineLoading" @click="loadEngineModels">
|
||||
{{ t('agents.cfgModelRefresh') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="f-hint">
|
||||
{{ t('agents.cfgModelHint') }}
|
||||
{{ t('agents.cfgModelHintShared') }}
|
||||
<a :href="qwenpawUrl" target="_blank" rel="noopener">{{ t('agents.cfgOpenQwenpaw') }} ↗</a>
|
||||
</div>
|
||||
<div class="card-h" style="margin-top:var(--gap)">
|
||||
@@ -373,9 +396,9 @@ import { useI18n } from 'vue-i18n'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import Icon from '../components/Icon.vue'
|
||||
import {
|
||||
type AgentEvent, type AgentItem, type AgentRun,
|
||||
agentRuns, agentSessions, createAgent, listAgents,
|
||||
restoreAgent, retireAgent, streamAgentChat, testAgent, updateAgent,
|
||||
type AgentEvent, type AgentItem, type AgentRun, type EngineModelOption,
|
||||
agentRuns, agentSessions, createAgent, engineModels, listAgents,
|
||||
restoreAgent, retireAgent, setEngineModel, streamAgentChat, testAgent, updateAgent,
|
||||
} from '../lib/agents'
|
||||
import { renderMarkdown } from '../lib/markdown'
|
||||
import { PRESETS, pickImage } from '../lib/upload'
|
||||
@@ -416,6 +439,19 @@ const create = reactive({ display_name: '', slug: '', description: '', system_su
|
||||
const testing = ref(false)
|
||||
const testResult = ref<{ ok: boolean; ms: number; detail: string } | null>(null)
|
||||
|
||||
// 引擎模型选择(第四十轮 · 方案 A):清单 + 当前值。`enginePick` 形如 "provider/model"。
|
||||
const engineOptions = ref<EngineModelOption[]>([])
|
||||
const enginePick = ref('')
|
||||
const engineLoading = ref(false)
|
||||
const engineGroups = computed(() => {
|
||||
const by: Record<string, { provider_id: string; provider_name: string; items: EngineModelOption[] }> = {}
|
||||
for (const o of engineOptions.value) {
|
||||
if (!by[o.provider_id]) by[o.provider_id] = { provider_id: o.provider_id, provider_name: o.provider_name, items: [] }
|
||||
by[o.provider_id].items.push(o)
|
||||
}
|
||||
return Object.values(by)
|
||||
})
|
||||
|
||||
const cur = computed(() => data.agents.find((a) => a.slug === current.value) || null)
|
||||
const hasRetired = computed(() => data.agents.some((a) => a.status === 'retired'))
|
||||
const activeCount = computed(() => data.agents.filter((a) => a.status !== 'retired').length)
|
||||
@@ -645,6 +681,38 @@ async function doTest() {
|
||||
finally { testing.value = false }
|
||||
}
|
||||
|
||||
/** 拉可选模型清单 + 当前生效模型(第四十轮 · 方案 A)。 */
|
||||
async function loadEngineModels() {
|
||||
engineLoading.value = true
|
||||
try {
|
||||
const j = await engineModels()
|
||||
engineOptions.value = j.options || []
|
||||
const c = j.current || {}
|
||||
enginePick.value = c.model ? `${c.provider_id}/${c.model}` : ''
|
||||
} catch (e: any) {
|
||||
ElMessage.error(String(e?.message || e))
|
||||
} finally { engineLoading.value = false }
|
||||
}
|
||||
|
||||
/** 切换引擎模型 —— 即时生效(不用重启引擎)。 */
|
||||
async function doSetModel(v: string) {
|
||||
const i = String(v || '').indexOf('/')
|
||||
if (i < 0) return
|
||||
const provider_id = v.slice(0, i)
|
||||
const model = v.slice(i + 1)
|
||||
const prev = enginePick.value
|
||||
try {
|
||||
const j = await setEngineModel(provider_id, model)
|
||||
const c = j.current || {}
|
||||
enginePick.value = c.model ? `${c.provider_id}/${c.model}` : ''
|
||||
ElMessage.success(t('agents.cfgModelSwitched', { model }))
|
||||
await load() // 让列表页 / 头部同步新模型名
|
||||
} catch (e: any) {
|
||||
enginePick.value = prev // 失败回滚选中值
|
||||
ElMessage.error(String(e?.message || e))
|
||||
}
|
||||
}
|
||||
|
||||
async function doRetire() {
|
||||
if (!cur.value || !confirm(t('agents.confirmDelete'))) return
|
||||
try { await retireAgent(cur.value.slug); await load(); pick(data.agents[0]?.slug || '') }
|
||||
@@ -790,6 +858,10 @@ onMounted(load)
|
||||
.f-val { flex: 1; min-width: 0; display: flex; align-items: center; gap: 7px; font-size: 12.5px; padding: 8px 10px; border-radius: 9px; background: var(--chip); }
|
||||
.f-val.code { font-family: ui-monospace, Menlo, monospace; font-size: 11.5px; }
|
||||
.f-lock { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; font-size: 10.5px; color: var(--muted-2); }
|
||||
/* 模型下拉(第四十轮):撑满 f-val,右侧留刷新按钮 */
|
||||
.model-pick { gap: var(--gap-sm); padding: 4px 6px 4px 4px; }
|
||||
.model-pick .el-select { flex: 1; min-width: 0; }
|
||||
.opt-vision { float: right; margin-left: 10px; font-size: 10.5px; color: var(--primary); opacity: .8; }
|
||||
.f-hint { font-size: 11px; color: var(--muted-2); line-height: 1.65; margin: var(--gap-xs) 0 0 88px; }
|
||||
.f-row-note { font-size: 11.5px; color: var(--muted); line-height: 1.6; margin-top: var(--gap-s); }
|
||||
.row-actions { display: flex; align-items: center; gap: var(--gap-sm); margin-top: var(--gap-lg); }
|
||||
|
||||
Reference in new issue
Block a user