feat: 自定义 OpenAI 兼容上游聚合 + 权重/并发调度

- custom provider:把任意 v1 端点当账号(base_url+key),按 model id 路由,
  直连不走代理;支持 images/generations、images/edits、Sora 式异步视频
- 调度器全局权重优先 + 每账号并发感知(上游账号可配并发,其余系统固定)
- 后台:添加/编辑上游、自定义模型表单(每档普通/代理价,留空=不支持)、
  账号权重/并发列与导入权重
- grok-video / nano-banana-2(runway) 写入硬编码目录(开源自带);
  去掉 540p,Adobe 视频最低 720p
- UI:SelectMenu 与输入框等高、测试耗时改用秒

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-28 21:59:46 +08:00
co-authored by Claude Opus 4.8
parent d289ec378d
commit 3ef84bb9b3
17 changed files with 1149 additions and 64 deletions
+123
View File
@@ -0,0 +1,123 @@
<script setup>
import { ref, onMounted } from 'vue'
import { api, jsonBody } from '../api'
import Icon from './Icon.vue'
const props = defineProps({ account: { type: Object, default: null } }) // edit mode when set
const emit = defineEmits(['close', 'imported'])
const isEdit = !!props.account
const name = ref(props.account?.email || '')
const baseUrl = ref(props.account?.base_url || '')
const key = ref('') // edit: blank = keep existing key
const allModels = ref([]) // existing models to pick from
const selected = ref(props.account?.models ? String(props.account.models).split(',').map((x) => x.trim()).filter(Boolean) : [])
const weight = ref(Number(props.account?.weight) || 0)
const concurrency = ref(Number(props.account?.concurrency) || 1)
const status = ref('')
const isError = ref(false)
const submitting = ref(false)
onMounted(async () => {
try {
const r = await api('/managed-models')
allModels.value = (r.data?.data || []).map((m) => ({ id: m.id, type: m.type }))
} catch (_) {}
})
function toggle(id) {
const i = selected.value.indexOf(id)
if (i >= 0) selected.value.splice(i, 1)
else selected.value.push(id)
}
async function submit() {
if (!baseUrl.value.trim() || (!isEdit && !key.value.trim())) {
status.value = isEdit ? '请填写 URL' : '请填写 URL 和 Key'; isError.value = true; return
}
submitting.value = true; status.value = ''; isError.value = false
try {
const r = await api('/tokens/import-custom-account', jsonBody('POST', {
id: isEdit ? props.account.id : undefined,
name: name.value.trim(),
base_url: baseUrl.value.trim(),
key: key.value.trim(), // blank in edit = keep existing
models: selected.value.join(','),
weight: Number(weight.value) || 0,
concurrency: Number(concurrency.value) || 1,
}))
if (r.ok) {
status.value = isEdit ? '✓ 已保存' : '✓ 已添加上游'; emit('imported')
setTimeout(() => emit('close'), 700)
} else {
status.value = r.data?.detail || '保存失败'; isError.value = true
}
} catch (e) {
status.value = String(e); isError.value = true
} finally {
submitting.value = false
}
}
</script>
<template>
<div class="fixed inset-0 z-50 bg-slate-900/40 backdrop-blur-sm flex items-start justify-center overflow-y-auto p-4"
@click.self="emit('close')">
<div class="card !shadow-xl mt-14 mb-14 w-full max-w-lg">
<div class="px-5 py-4 border-b border-slate-100 flex items-center justify-between">
<h2 class="text-sm font-semibold">{{ isEdit ? '编辑上游' : '添加上游(自定义 OpenAI 兼容)' }}</h2>
<button @click="emit('close')" class="text-slate-400 hover:text-slate-700 transition-colors">
<Icon name="close" class="w-5 h-5" />
</button>
</div>
<div class="p-5 space-y-3">
<p class="text-xs text-slate-500 leading-relaxed">
上游就是一个账号: v1 URL + Key模型按 <strong class="text-slate-700">id 相同</strong>自动路由
模型管理加一个 provider=customid 与上游一致的模型即可从这个上游调用调用<strong class="text-slate-700">直连不走代理</strong>
</p>
<div>
<label class="text-xs text-slate-500">备注名</label>
<input v-model="name" class="field" placeholder="例如:我的中转 / xx-api" />
</div>
<div>
<label class="text-xs text-slate-500">v1 URL <span class="text-rose-500">*</span></label>
<input v-model="baseUrl" class="field font-mono text-xs" placeholder="https://api.example.com(无需 /v1 结尾)" />
</div>
<div>
<label class="text-xs text-slate-500">Key <span v-if="!isEdit" class="text-rose-500">*</span><span v-else class="text-white/40">(留空=不改)</span></label>
<input v-model="key" class="field font-mono text-xs" :placeholder="isEdit ? '留空保持原 key' : 'sk-...'" />
</div>
<div>
<div class="flex items-center justify-between mb-1.5">
<label class="text-xs text-slate-500">支持的模型(多选,不选 = 全部)</label>
<span class="text-[11px] text-slate-400">{{ selected.length ? `已选 ${selected.length}` : '全部' }}</span>
</div>
<div v-if="!allModels.length" class="text-xs text-slate-400 rounded-lg ring-1 ring-slate-200 bg-slate-50/60 p-3">
暂无模型 可先去模型管理加自定义模型
</div>
<div v-else class="flex flex-wrap gap-1.5 max-h-44 overflow-y-auto rounded-lg ring-1 ring-slate-200 bg-slate-50/60 p-2">
<button v-for="m in allModels" :key="m.id" type="button" @click="toggle(m.id)"
class="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs ring-1 transition-colors"
:class="selected.includes(m.id) ? 'bg-indigo-500/15 text-indigo-700 ring-indigo-300 font-medium' : 'bg-white text-slate-600 ring-slate-200 hover:ring-slate-300'">
<span class="w-1.5 h-1.5 rounded-full" :class="m.type === 'video' ? 'bg-violet-400' : 'bg-emerald-400'"></span>{{ m.id }}
</button>
</div>
</div>
<div class="flex gap-3">
<div class="flex-1">
<label class="text-xs text-slate-500">权重(高的优先)</label>
<input v-model.number="weight" type="number" class="field" placeholder="0" />
</div>
<div class="flex-1">
<label class="text-xs text-slate-500">并发数(单账号)</label>
<input v-model.number="concurrency" type="number" min="1" class="field" placeholder="1" />
</div>
</div>
<button @click="submit" :disabled="submitting" class="btn-primary w-full mt-1">
{{ submitting ? '保存中…' : (isEdit ? '保存' : '添加上游') }}
</button>
<p v-if="status" class="text-xs" :class="isError ? 'text-rose-600' : 'text-emerald-600'">{{ status }}</p>
</div>
</div>
</div>
</template>