2025-12-10 20:52:44 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<Dialog
|
|
|
|
|
|
:model-value="open"
|
|
|
|
|
|
:title="isEditMode ? '编辑模型' : '创建统一模型'"
|
2025-12-16 12:21:21 +08:00
|
|
|
|
:description="isEditMode ? '修改模型配置和价格信息' : ''"
|
2025-12-10 20:52:44 +08:00
|
|
|
|
:icon="isEditMode ? SquarePen : Layers"
|
2026-01-29 17:41:12 +08:00
|
|
|
|
size="4xl"
|
2025-12-10 20:52:44 +08:00
|
|
|
|
@update:model-value="handleDialogUpdate"
|
|
|
|
|
|
>
|
2025-12-16 12:21:21 +08:00
|
|
|
|
<div
|
|
|
|
|
|
class="flex gap-4"
|
2026-01-29 17:41:12 +08:00
|
|
|
|
:class="isEditMode ? '' : 'h-[600px]'"
|
2025-12-12 16:15:36 +08:00
|
|
|
|
>
|
2025-12-16 12:21:21 +08:00
|
|
|
|
<!-- 左侧:模型选择(仅创建模式) -->
|
|
|
|
|
|
<div
|
|
|
|
|
|
v-if="!isEditMode"
|
2025-12-16 17:28:40 +08:00
|
|
|
|
class="w-[260px] shrink-0 flex flex-col h-full"
|
2025-12-12 16:15:36 +08:00
|
|
|
|
>
|
2025-12-16 12:21:21 +08:00
|
|
|
|
<!-- 搜索框 -->
|
|
|
|
|
|
<div class="relative mb-3">
|
|
|
|
|
|
<Search class="absolute left-2.5 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
2025-12-10 20:52:44 +08:00
|
|
|
|
<Input
|
2025-12-16 12:21:21 +08:00
|
|
|
|
v-model="searchQuery"
|
|
|
|
|
|
type="text"
|
2025-12-16 17:28:40 +08:00
|
|
|
|
placeholder="搜索模型、提供商..."
|
2025-12-16 12:21:21 +08:00
|
|
|
|
class="pl-8 h-8 text-sm"
|
2025-12-10 20:52:44 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
2025-12-16 12:21:21 +08:00
|
|
|
|
|
|
|
|
|
|
<!-- 模型列表(两级结构) -->
|
2025-12-16 17:28:40 +08:00
|
|
|
|
<div class="flex-1 overflow-y-auto border rounded-lg min-h-0 scrollbar-thin">
|
2025-12-16 12:21:21 +08:00
|
|
|
|
<div
|
|
|
|
|
|
v-if="loading"
|
|
|
|
|
|
class="flex items-center justify-center h-32"
|
|
|
|
|
|
>
|
|
|
|
|
|
<Loader2 class="w-5 h-5 animate-spin text-muted-foreground" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<template v-else>
|
|
|
|
|
|
<!-- 提供商分组 -->
|
|
|
|
|
|
<div
|
|
|
|
|
|
v-for="group in groupedModels"
|
|
|
|
|
|
:key="group.providerId"
|
|
|
|
|
|
class="border-b last:border-b-0"
|
|
|
|
|
|
>
|
|
|
|
|
|
<!-- 提供商标题行 -->
|
|
|
|
|
|
<div
|
|
|
|
|
|
class="flex items-center gap-2 px-2.5 py-2 cursor-pointer hover:bg-muted text-sm"
|
|
|
|
|
|
@click="toggleProvider(group.providerId)"
|
|
|
|
|
|
>
|
|
|
|
|
|
<ChevronRight
|
|
|
|
|
|
class="w-3.5 h-3.5 text-muted-foreground transition-transform shrink-0"
|
|
|
|
|
|
:class="expandedProvider === group.providerId ? 'rotate-90' : ''"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<img
|
|
|
|
|
|
:src="getProviderLogoUrl(group.providerId)"
|
|
|
|
|
|
:alt="group.providerName"
|
2025-12-16 17:28:40 +08:00
|
|
|
|
class="w-4 h-4 rounded shrink-0 dark:invert dark:brightness-90"
|
2025-12-16 12:21:21 +08:00
|
|
|
|
@error="handleLogoError"
|
|
|
|
|
|
>
|
|
|
|
|
|
<span class="truncate font-medium text-xs flex-1">{{ group.providerName }}</span>
|
|
|
|
|
|
<span class="text-[10px] text-muted-foreground shrink-0">{{ group.models.length }}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<!-- 模型列表 -->
|
|
|
|
|
|
<div
|
|
|
|
|
|
v-if="expandedProvider === group.providerId"
|
|
|
|
|
|
class="bg-muted/30"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div
|
2026-02-22 00:43:41 +08:00
|
|
|
|
v-for="item in group.models"
|
|
|
|
|
|
:key="item.modelId"
|
2025-12-16 18:36:23 +08:00
|
|
|
|
class="flex flex-col gap-0.5 pl-7 pr-2.5 py-1.5 cursor-pointer text-xs border-t"
|
2026-02-22 00:43:41 +08:00
|
|
|
|
:class="selectedModel?.modelId === item.modelId && selectedModel?.providerId === item.providerId
|
2025-12-16 12:21:21 +08:00
|
|
|
|
? 'bg-primary text-primary-foreground'
|
|
|
|
|
|
: 'hover:bg-muted'"
|
2026-02-22 00:43:41 +08:00
|
|
|
|
@click="selectModel(item)"
|
2025-12-16 12:21:21 +08:00
|
|
|
|
>
|
2026-02-22 00:43:41 +08:00
|
|
|
|
<span class="truncate font-medium">{{ item.modelName }}</span>
|
2025-12-16 18:36:23 +08:00
|
|
|
|
<span
|
|
|
|
|
|
class="truncate text-[10px]"
|
2026-02-22 00:43:41 +08:00
|
|
|
|
:class="selectedModel?.modelId === item.modelId && selectedModel?.providerId === item.providerId
|
2025-12-16 18:36:23 +08:00
|
|
|
|
? 'text-primary-foreground/70'
|
|
|
|
|
|
: 'text-muted-foreground'"
|
2026-02-22 00:43:41 +08:00
|
|
|
|
>{{ item.modelId }}</span>
|
2025-12-16 12:21:21 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div
|
|
|
|
|
|
v-if="groupedModels.length === 0"
|
|
|
|
|
|
class="text-center py-8 text-sm text-muted-foreground"
|
|
|
|
|
|
>
|
|
|
|
|
|
{{ searchQuery ? '未找到模型' : '加载中...' }}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 右侧:表单 -->
|
|
|
|
|
|
<div
|
2025-12-16 17:28:40 +08:00
|
|
|
|
class="flex-1 overflow-y-auto h-full scrollbar-thin"
|
2025-12-16 12:21:21 +08:00
|
|
|
|
:class="isEditMode ? 'max-h-[70vh]' : ''"
|
|
|
|
|
|
>
|
|
|
|
|
|
<form
|
|
|
|
|
|
class="space-y-5"
|
|
|
|
|
|
@submit.prevent="handleSubmit"
|
|
|
|
|
|
>
|
|
|
|
|
|
<!-- 基本信息 -->
|
|
|
|
|
|
<section class="space-y-3">
|
|
|
|
|
|
<h4 class="font-medium text-sm">
|
|
|
|
|
|
基本信息
|
|
|
|
|
|
</h4>
|
|
|
|
|
|
<div class="grid grid-cols-2 gap-3">
|
|
|
|
|
|
<div class="space-y-1.5">
|
|
|
|
|
|
<Label
|
2026-02-03 18:48:39 +08:00
|
|
|
|
for="model-display-name"
|
2025-12-16 12:21:21 +08:00
|
|
|
|
class="text-xs"
|
2026-02-03 18:48:39 +08:00
|
|
|
|
>名称 *</Label>
|
2025-12-16 12:21:21 +08:00
|
|
|
|
<Input
|
2026-02-03 18:48:39 +08:00
|
|
|
|
id="model-display-name"
|
|
|
|
|
|
v-model="form.display_name"
|
|
|
|
|
|
placeholder="Claude 3.5 Sonnet"
|
2025-12-16 12:21:21 +08:00
|
|
|
|
required
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="space-y-1.5">
|
|
|
|
|
|
<Label
|
2026-02-03 18:48:39 +08:00
|
|
|
|
for="model-name"
|
2025-12-16 12:21:21 +08:00
|
|
|
|
class="text-xs"
|
2026-02-03 18:48:39 +08:00
|
|
|
|
>模型ID *</Label>
|
2025-12-16 12:21:21 +08:00
|
|
|
|
<Input
|
2026-02-03 18:48:39 +08:00
|
|
|
|
id="model-name"
|
|
|
|
|
|
v-model="form.name"
|
|
|
|
|
|
placeholder="claude-3-5-sonnet-20241022"
|
|
|
|
|
|
:disabled="isEditMode"
|
2025-12-16 12:21:21 +08:00
|
|
|
|
required
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="space-y-1.5">
|
|
|
|
|
|
<Label
|
|
|
|
|
|
for="model-description"
|
|
|
|
|
|
class="text-xs"
|
|
|
|
|
|
>描述</Label>
|
|
|
|
|
|
<Input
|
|
|
|
|
|
id="model-description"
|
|
|
|
|
|
:model-value="form.config?.description || ''"
|
|
|
|
|
|
placeholder="简短描述此模型的特点"
|
|
|
|
|
|
@update:model-value="(v) => setConfigField('description', v || undefined)"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
2026-02-19 10:40:49 +08:00
|
|
|
|
<div class="grid grid-cols-2 gap-3">
|
|
|
|
|
|
<div class="space-y-1.5">
|
|
|
|
|
|
<Label
|
|
|
|
|
|
for="model-output-limit"
|
|
|
|
|
|
class="text-xs"
|
|
|
|
|
|
>最大输出 Token</Label>
|
|
|
|
|
|
<Input
|
|
|
|
|
|
id="model-output-limit"
|
|
|
|
|
|
:model-value="form.config?.output_limit ?? ''"
|
|
|
|
|
|
type="number"
|
|
|
|
|
|
min="1"
|
|
|
|
|
|
placeholder="如 8192"
|
|
|
|
|
|
@update:model-value="(v) => setConfigField('output_limit', parseNumberInput(v, { allowFloat: false }))"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="space-y-1.5">
|
|
|
|
|
|
<Label
|
|
|
|
|
|
for="model-context-limit"
|
|
|
|
|
|
class="text-xs"
|
|
|
|
|
|
>上下文窗口</Label>
|
|
|
|
|
|
<Input
|
|
|
|
|
|
id="model-context-limit"
|
|
|
|
|
|
:model-value="form.config?.context_limit ?? ''"
|
|
|
|
|
|
type="number"
|
|
|
|
|
|
min="1"
|
|
|
|
|
|
placeholder="如 200000"
|
|
|
|
|
|
@update:model-value="(v) => setConfigField('context_limit', parseNumberInput(v, { allowFloat: false }))"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-12-16 12:21:21 +08:00
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 价格配置 -->
|
|
|
|
|
|
<section class="space-y-3">
|
|
|
|
|
|
<h4 class="font-medium text-sm">
|
|
|
|
|
|
价格配置
|
|
|
|
|
|
</h4>
|
|
|
|
|
|
<TieredPricingEditor
|
|
|
|
|
|
ref="tieredPricingEditorRef"
|
|
|
|
|
|
v-model="tieredPricing"
|
2026-02-28 13:52:32 +08:00
|
|
|
|
:show-cache1h="true"
|
2025-12-16 12:21:21 +08:00
|
|
|
|
/>
|
|
|
|
|
|
<div class="flex items-center gap-3 pt-2 border-t">
|
|
|
|
|
|
<Label class="text-xs whitespace-nowrap">按次计费</Label>
|
|
|
|
|
|
<Input
|
|
|
|
|
|
:model-value="form.default_price_per_request ?? ''"
|
|
|
|
|
|
type="number"
|
|
|
|
|
|
step="0.001"
|
|
|
|
|
|
min="0"
|
|
|
|
|
|
class="w-24"
|
|
|
|
|
|
placeholder="$/次"
|
|
|
|
|
|
@update:model-value="(v) => form.default_price_per_request = parseNumberInput(v, { allowFloat: true })"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<span class="text-xs text-muted-foreground">可与 Token 计费叠加</span>
|
|
|
|
|
|
</div>
|
2026-02-03 18:48:39 +08:00
|
|
|
|
|
|
|
|
|
|
<!-- 视频计费(分辨率 × 时长) -->
|
|
|
|
|
|
<div class="pt-3 border-t space-y-2">
|
2026-02-04 23:59:45 +08:00
|
|
|
|
<div class="text-sm font-medium">
|
|
|
|
|
|
视频计费(分辨率 × 时长)
|
|
|
|
|
|
</div>
|
2026-02-03 18:48:39 +08:00
|
|
|
|
|
|
|
|
|
|
<div class="flex items-center gap-1.5 flex-wrap">
|
|
|
|
|
|
<Button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
variant="outline"
|
|
|
|
|
|
size="sm"
|
|
|
|
|
|
class="h-7 text-xs"
|
|
|
|
|
|
@click="fillVideoResolutionPricePreset('common')"
|
|
|
|
|
|
>
|
|
|
|
|
|
通用
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
variant="outline"
|
|
|
|
|
|
size="sm"
|
|
|
|
|
|
class="h-7 text-xs"
|
|
|
|
|
|
@click="fillVideoResolutionPricePreset('sora')"
|
|
|
|
|
|
>
|
|
|
|
|
|
Sora
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
variant="outline"
|
|
|
|
|
|
size="sm"
|
|
|
|
|
|
class="h-7 text-xs"
|
|
|
|
|
|
@click="fillVideoResolutionPricePreset('veo')"
|
|
|
|
|
|
>
|
|
|
|
|
|
Veo
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
variant="outline"
|
|
|
|
|
|
size="sm"
|
|
|
|
|
|
class="h-7 text-xs"
|
|
|
|
|
|
@click="addVideoResolutionPriceRow"
|
|
|
|
|
|
>
|
|
|
|
|
|
<Plus class="w-3.5 h-3.5 mr-0.5" />
|
|
|
|
|
|
自定义
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div
|
|
|
|
|
|
v-if="videoResolutionPrices.length > 0"
|
|
|
|
|
|
class="rounded-lg border border-border overflow-hidden"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div class="grid grid-cols-[1fr_1fr_32px] gap-0 text-xs text-muted-foreground bg-muted/50 px-3 py-1.5 border-b border-border">
|
|
|
|
|
|
<span>分辨率</span>
|
|
|
|
|
|
<span>单价($/秒)</span>
|
2026-02-04 23:59:45 +08:00
|
|
|
|
<span />
|
2026-02-03 18:48:39 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="divide-y divide-border">
|
|
|
|
|
|
<div
|
|
|
|
|
|
v-for="(row, idx) in videoResolutionPrices"
|
|
|
|
|
|
:key="idx"
|
|
|
|
|
|
class="grid grid-cols-[1fr_1fr_32px] gap-2 items-center px-3 py-1.5"
|
|
|
|
|
|
>
|
|
|
|
|
|
<Input
|
|
|
|
|
|
v-model="row.resolution"
|
|
|
|
|
|
class="h-7 text-sm"
|
|
|
|
|
|
placeholder="如 720p"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<Input
|
|
|
|
|
|
:model-value="row.price_per_second ?? ''"
|
|
|
|
|
|
type="number"
|
|
|
|
|
|
step="0.0001"
|
|
|
|
|
|
min="0"
|
|
|
|
|
|
class="h-7 text-sm"
|
|
|
|
|
|
placeholder="0"
|
|
|
|
|
|
@update:model-value="(v) => row.price_per_second = parseNumberInput(v, { allowFloat: true })"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
variant="ghost"
|
|
|
|
|
|
size="icon"
|
|
|
|
|
|
class="h-7 w-7"
|
|
|
|
|
|
title="删除"
|
|
|
|
|
|
@click="removeVideoResolutionPriceRow(idx)"
|
|
|
|
|
|
>
|
|
|
|
|
|
<Trash2 class="w-3.5 h-3.5" />
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-12-16 12:21:21 +08:00
|
|
|
|
</section>
|
|
|
|
|
|
</form>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-12-10 20:52:44 +08:00
|
|
|
|
|
|
|
|
|
|
<template #footer>
|
2025-12-12 16:15:36 +08:00
|
|
|
|
<Button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
variant="outline"
|
|
|
|
|
|
@click="handleCancel"
|
|
|
|
|
|
>
|
2025-12-10 20:52:44 +08:00
|
|
|
|
取消
|
|
|
|
|
|
</Button>
|
2025-12-12 16:15:36 +08:00
|
|
|
|
<Button
|
2025-12-16 12:21:21 +08:00
|
|
|
|
:disabled="submitting || !form.name || !form.display_name"
|
2025-12-12 16:15:36 +08:00
|
|
|
|
@click="handleSubmit"
|
|
|
|
|
|
>
|
|
|
|
|
|
<Loader2
|
|
|
|
|
|
v-if="submitting"
|
|
|
|
|
|
class="w-4 h-4 mr-2 animate-spin"
|
|
|
|
|
|
/>
|
2026-02-25 23:33:16 +08:00
|
|
|
|
{{ isEditMode ? '保存' : '添加' }}
|
2025-12-10 20:52:44 +08:00
|
|
|
|
</Button>
|
2025-12-16 12:21:21 +08:00
|
|
|
|
<Button
|
|
|
|
|
|
v-if="selectedModel && !isEditMode"
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
variant="ghost"
|
|
|
|
|
|
@click="clearSelection"
|
|
|
|
|
|
>
|
|
|
|
|
|
清空
|
|
|
|
|
|
</Button>
|
2025-12-10 20:52:44 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</Dialog>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2026-02-28 13:52:32 +08:00
|
|
|
|
import { ref, computed, watch } from 'vue'
|
2025-12-16 12:21:21 +08:00
|
|
|
|
import {
|
2026-02-03 18:48:39 +08:00
|
|
|
|
Loader2, Layers, SquarePen,
|
|
|
|
|
|
Search, ChevronRight, Plus, Trash2
|
2025-12-16 12:21:21 +08:00
|
|
|
|
} from 'lucide-vue-next'
|
2025-12-10 20:52:44 +08:00
|
|
|
|
import { Dialog, Button, Input, Label } from '@/components/ui'
|
|
|
|
|
|
import { useToast } from '@/composables/useToast'
|
|
|
|
|
|
import { useFormDialog } from '@/composables/useFormDialog'
|
2026-02-03 18:48:39 +08:00
|
|
|
|
import { parseNumberInput, sortResolutionEntries } from '@/utils/form'
|
2025-12-12 16:15:36 +08:00
|
|
|
|
import { log } from '@/utils/logger'
|
2026-02-22 00:43:41 +08:00
|
|
|
|
import { parseApiError } from '@/utils/errorParser'
|
2025-12-10 20:52:44 +08:00
|
|
|
|
import TieredPricingEditor from './TieredPricingEditor.vue'
|
2025-12-16 12:21:21 +08:00
|
|
|
|
import {
|
|
|
|
|
|
getModelsDevList,
|
|
|
|
|
|
getProviderLogoUrl,
|
|
|
|
|
|
type ModelsDevModelItem,
|
|
|
|
|
|
} from '@/api/models-dev'
|
2025-12-10 20:52:44 +08:00
|
|
|
|
import {
|
|
|
|
|
|
createGlobalModel,
|
|
|
|
|
|
updateGlobalModel,
|
|
|
|
|
|
type GlobalModelResponse,
|
|
|
|
|
|
type GlobalModelCreate,
|
|
|
|
|
|
type GlobalModelUpdate,
|
|
|
|
|
|
} from '@/api/global-models'
|
|
|
|
|
|
import type { TieredPricingConfig } from '@/api/endpoints/types'
|
|
|
|
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
|
|
open: boolean
|
|
|
|
|
|
model?: GlobalModelResponse | null
|
|
|
|
|
|
}>()
|
|
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
|
|
'update:open': [value: boolean]
|
|
|
|
|
|
'success': []
|
|
|
|
|
|
}>()
|
|
|
|
|
|
|
|
|
|
|
|
const { success, error: showError } = useToast()
|
|
|
|
|
|
const submitting = ref(false)
|
2025-12-12 15:43:00 +08:00
|
|
|
|
const tieredPricingEditorRef = ref<InstanceType<typeof TieredPricingEditor> | null>(null)
|
2025-12-10 20:52:44 +08:00
|
|
|
|
|
2025-12-16 12:21:21 +08:00
|
|
|
|
// 模型列表相关
|
|
|
|
|
|
const loading = ref(false)
|
|
|
|
|
|
const searchQuery = ref('')
|
2025-12-16 17:28:40 +08:00
|
|
|
|
const allModelsCache = ref<ModelsDevModelItem[]>([]) // 全部模型(缓存)
|
2025-12-16 12:21:21 +08:00
|
|
|
|
const selectedModel = ref<ModelsDevModelItem | null>(null)
|
|
|
|
|
|
const expandedProvider = ref<string | null>(null)
|
|
|
|
|
|
|
2025-12-16 17:28:40 +08:00
|
|
|
|
// 当前显示的模型列表:有搜索词时用全部,否则只用官方
|
|
|
|
|
|
const allModels = computed(() => {
|
|
|
|
|
|
if (searchQuery.value) {
|
|
|
|
|
|
return allModelsCache.value
|
|
|
|
|
|
}
|
|
|
|
|
|
return allModelsCache.value.filter(m => m.official)
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2025-12-16 12:21:21 +08:00
|
|
|
|
// 按提供商分组的模型
|
|
|
|
|
|
interface ProviderGroup {
|
|
|
|
|
|
providerId: string
|
|
|
|
|
|
providerName: string
|
|
|
|
|
|
models: ModelsDevModelItem[]
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const groupedModels = computed(() => {
|
|
|
|
|
|
let models = allModels.value.filter(m => !m.deprecated)
|
2025-12-17 16:41:10 +08:00
|
|
|
|
// 搜索(支持空格分隔的多关键词 AND 搜索)
|
2025-12-16 12:21:21 +08:00
|
|
|
|
if (searchQuery.value) {
|
2025-12-17 16:41:10 +08:00
|
|
|
|
const keywords = searchQuery.value.toLowerCase().split(/\s+/).filter(k => k.length > 0)
|
|
|
|
|
|
models = models.filter(model => {
|
|
|
|
|
|
const searchableText = `${model.providerId} ${model.providerName} ${model.modelId} ${model.modelName} ${model.family || ''}`.toLowerCase()
|
|
|
|
|
|
return keywords.every(keyword => searchableText.includes(keyword))
|
|
|
|
|
|
})
|
2025-12-16 12:21:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 按提供商分组
|
|
|
|
|
|
const groups = new Map<string, ProviderGroup>()
|
|
|
|
|
|
for (const model of models) {
|
|
|
|
|
|
if (!groups.has(model.providerId)) {
|
|
|
|
|
|
groups.set(model.providerId, {
|
|
|
|
|
|
providerId: model.providerId,
|
|
|
|
|
|
providerName: model.providerName,
|
|
|
|
|
|
models: []
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2026-02-22 00:43:41 +08:00
|
|
|
|
groups.get(model.providerId)?.models.push(model)
|
2025-12-16 12:21:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 转换为数组并排序
|
2025-12-16 18:33:14 +08:00
|
|
|
|
const result = Array.from(groups.values())
|
2025-12-16 12:21:21 +08:00
|
|
|
|
|
|
|
|
|
|
// 如果有搜索词,把提供商名称/ID匹配的排在前面
|
|
|
|
|
|
if (searchQuery.value) {
|
2025-12-17 16:41:10 +08:00
|
|
|
|
const keywords = searchQuery.value.toLowerCase().split(/\s+/).filter(k => k.length > 0)
|
2025-12-16 12:21:21 +08:00
|
|
|
|
result.sort((a, b) => {
|
2025-12-17 16:41:10 +08:00
|
|
|
|
const aText = `${a.providerId} ${a.providerName}`.toLowerCase()
|
|
|
|
|
|
const bText = `${b.providerId} ${b.providerName}`.toLowerCase()
|
|
|
|
|
|
const aProviderMatch = keywords.some(k => aText.includes(k))
|
|
|
|
|
|
const bProviderMatch = keywords.some(k => bText.includes(k))
|
2025-12-16 12:21:21 +08:00
|
|
|
|
if (aProviderMatch && !bProviderMatch) return -1
|
|
|
|
|
|
if (!aProviderMatch && bProviderMatch) return 1
|
|
|
|
|
|
return a.providerName.localeCompare(b.providerName)
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
result.sort((a, b) => a.providerName.localeCompare(b.providerName))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// 搜索时如果只有一个提供商,自动展开
|
|
|
|
|
|
watch(groupedModels, (groups) => {
|
|
|
|
|
|
if (searchQuery.value && groups.length === 1) {
|
|
|
|
|
|
expandedProvider.value = groups[0].providerId
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// 切换提供商展开状态
|
|
|
|
|
|
function toggleProvider(providerId: string) {
|
|
|
|
|
|
expandedProvider.value = expandedProvider.value === providerId ? null : providerId
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 阶梯计费配置
|
2025-12-10 20:52:44 +08:00
|
|
|
|
const tieredPricing = ref<TieredPricingConfig | null>(null)
|
|
|
|
|
|
|
2026-02-03 18:48:39 +08:00
|
|
|
|
type VideoResolutionPriceRow = { resolution: string; price_per_second: number | undefined }
|
|
|
|
|
|
|
|
|
|
|
|
const videoResolutionPrices = ref<VideoResolutionPriceRow[]>([])
|
|
|
|
|
|
|
|
|
|
|
|
const VIDEO_RESOLUTION_PRICE_PRESETS: Record<
|
|
|
|
|
|
'common' | 'sora' | 'veo',
|
|
|
|
|
|
VideoResolutionPriceRow[]
|
|
|
|
|
|
> = {
|
|
|
|
|
|
common: [
|
|
|
|
|
|
{ resolution: '480p', price_per_second: 0 },
|
|
|
|
|
|
{ resolution: '720p', price_per_second: 0 },
|
|
|
|
|
|
{ resolution: '1080p', price_per_second: 0 },
|
|
|
|
|
|
{ resolution: '4k', price_per_second: 0 },
|
|
|
|
|
|
],
|
|
|
|
|
|
sora: [
|
|
|
|
|
|
{ resolution: '720x1080', price_per_second: 0 },
|
|
|
|
|
|
{ resolution: '1024x1792', price_per_second: 0 },
|
|
|
|
|
|
],
|
|
|
|
|
|
veo: [
|
|
|
|
|
|
{ resolution: '720p', price_per_second: 0 },
|
|
|
|
|
|
{ resolution: '1080p', price_per_second: 0 },
|
|
|
|
|
|
{ resolution: '4k', price_per_second: 0 },
|
|
|
|
|
|
],
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-10 20:52:44 +08:00
|
|
|
|
interface FormData {
|
|
|
|
|
|
name: string
|
|
|
|
|
|
display_name: string
|
|
|
|
|
|
default_price_per_request?: number
|
|
|
|
|
|
supported_capabilities?: string[]
|
2026-02-22 00:43:41 +08:00
|
|
|
|
config?: Record<string, unknown>
|
2025-12-10 20:52:44 +08:00
|
|
|
|
is_active?: boolean
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const defaultForm = (): FormData => ({
|
|
|
|
|
|
name: '',
|
|
|
|
|
|
display_name: '',
|
|
|
|
|
|
default_price_per_request: undefined,
|
|
|
|
|
|
supported_capabilities: [],
|
2025-12-16 12:21:21 +08:00
|
|
|
|
config: { streaming: true },
|
2025-12-10 20:52:44 +08:00
|
|
|
|
is_active: true,
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const form = ref<FormData>(defaultForm())
|
|
|
|
|
|
|
2025-12-16 12:21:21 +08:00
|
|
|
|
const KEEP_FALSE_CONFIG_KEYS = new Set(['streaming'])
|
|
|
|
|
|
|
|
|
|
|
|
// 设置 config 字段
|
2026-02-22 00:43:41 +08:00
|
|
|
|
function setConfigField(key: string, value: unknown) {
|
2025-12-16 12:21:21 +08:00
|
|
|
|
if (!form.value.config) {
|
|
|
|
|
|
form.value.config = {}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (value === undefined || value === '' || (value === false && !KEEP_FALSE_CONFIG_KEYS.has(key))) {
|
|
|
|
|
|
delete form.value.config[key]
|
|
|
|
|
|
} else {
|
|
|
|
|
|
form.value.config[key] = value
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-22 00:43:41 +08:00
|
|
|
|
function getNested(obj: unknown, path: string): unknown {
|
2026-02-03 18:48:39 +08:00
|
|
|
|
if (!obj || typeof obj !== 'object') return undefined
|
|
|
|
|
|
const parts = path.split('.').filter(Boolean)
|
2026-02-22 00:43:41 +08:00
|
|
|
|
let cur = obj as Record<string, unknown>
|
2026-02-03 18:48:39 +08:00
|
|
|
|
for (const p of parts) {
|
|
|
|
|
|
if (!cur || typeof cur !== 'object') return undefined
|
2026-02-22 00:43:41 +08:00
|
|
|
|
cur = cur[p] as Record<string, unknown>
|
2026-02-03 18:48:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
return cur
|
|
|
|
|
|
}
|
2025-12-10 20:52:44 +08:00
|
|
|
|
|
2026-02-22 00:43:41 +08:00
|
|
|
|
function setNested(obj: unknown, path: string, value: unknown) {
|
2026-02-03 18:48:39 +08:00
|
|
|
|
if (!obj || typeof obj !== 'object') return
|
|
|
|
|
|
const parts = path.split('.').filter(Boolean)
|
|
|
|
|
|
if (parts.length === 0) return
|
2026-02-22 00:43:41 +08:00
|
|
|
|
let cur = obj as Record<string, unknown>
|
2026-02-03 18:48:39 +08:00
|
|
|
|
for (let i = 0; i < parts.length - 1; i++) {
|
|
|
|
|
|
const p = parts[i]
|
|
|
|
|
|
if (!cur[p] || typeof cur[p] !== 'object') {
|
|
|
|
|
|
cur[p] = {}
|
|
|
|
|
|
}
|
2026-02-22 00:43:41 +08:00
|
|
|
|
cur = cur[p] as Record<string, unknown>
|
2026-02-03 18:48:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
cur[parts[parts.length - 1]] = value
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-22 00:43:41 +08:00
|
|
|
|
function deleteNested(obj: unknown, path: string) {
|
2026-02-03 18:48:39 +08:00
|
|
|
|
if (!obj || typeof obj !== 'object') return
|
|
|
|
|
|
const parts = path.split('.').filter(Boolean)
|
|
|
|
|
|
if (parts.length === 0) return
|
2026-02-22 00:43:41 +08:00
|
|
|
|
let cur = obj as Record<string, unknown>
|
2026-02-03 18:48:39 +08:00
|
|
|
|
for (let i = 0; i < parts.length - 1; i++) {
|
|
|
|
|
|
const p = parts[i]
|
|
|
|
|
|
if (!cur[p] || typeof cur[p] !== 'object') return
|
2026-02-22 00:43:41 +08:00
|
|
|
|
cur = cur[p] as Record<string, unknown>
|
2026-02-03 18:48:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
delete cur[parts[parts.length - 1]]
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function pruneEmptyBillingConfig() {
|
|
|
|
|
|
const cfg = form.value.config
|
|
|
|
|
|
if (!cfg || typeof cfg !== 'object') return
|
2026-02-22 00:43:41 +08:00
|
|
|
|
const billing = cfg.billing as Record<string, unknown> | undefined
|
2026-02-03 18:48:39 +08:00
|
|
|
|
if (!billing || typeof billing !== 'object') return
|
2026-02-22 00:43:41 +08:00
|
|
|
|
const video = billing.video as Record<string, unknown> | undefined
|
2026-02-03 18:48:39 +08:00
|
|
|
|
if (video && typeof video === 'object' && Object.keys(video).length === 0) {
|
|
|
|
|
|
delete billing.video
|
|
|
|
|
|
}
|
|
|
|
|
|
if (Object.keys(billing).length === 0) {
|
|
|
|
|
|
delete cfg.billing
|
2025-12-16 12:21:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-03 18:48:39 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* Normalize resolution key:
|
|
|
|
|
|
* - lowercase, remove spaces, × → x
|
|
|
|
|
|
* - For WxH format, sort dimensions so smaller comes first (720x1080 = 1080x720)
|
|
|
|
|
|
*/
|
|
|
|
|
|
function normalizeResolutionKey(raw: string): string {
|
|
|
|
|
|
let k = (raw || '').trim().toLowerCase().replace(/\s+/g, '').replace(/×/g, 'x')
|
|
|
|
|
|
// Check if it's WxH format (e.g., 1080x720)
|
|
|
|
|
|
const match = k.match(/^(\d+)x(\d+)$/)
|
|
|
|
|
|
if (match) {
|
|
|
|
|
|
const a = parseInt(match[1], 10)
|
|
|
|
|
|
const b = parseInt(match[2], 10)
|
|
|
|
|
|
// Sort: smaller dimension first
|
|
|
|
|
|
k = a <= b ? `${a}x${b}` : `${b}x${a}`
|
2025-12-16 12:21:21 +08:00
|
|
|
|
}
|
2026-02-03 18:48:39 +08:00
|
|
|
|
return k
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function loadVideoPricingFromConfig() {
|
|
|
|
|
|
const cfg = form.value.config || {}
|
|
|
|
|
|
const raw = getNested(cfg, 'billing.video.price_per_second_by_resolution')
|
|
|
|
|
|
if (raw && typeof raw === 'object' && !Array.isArray(raw)) {
|
|
|
|
|
|
// 按分辨率从低到高排序
|
2026-02-22 00:43:41 +08:00
|
|
|
|
const sortedEntries = sortResolutionEntries(Object.entries(raw as Record<string, unknown>))
|
2026-02-03 18:48:39 +08:00
|
|
|
|
videoResolutionPrices.value = sortedEntries.map(([k, v]) => ({
|
|
|
|
|
|
resolution: String(k),
|
|
|
|
|
|
price_per_second: typeof v === 'number' ? v : undefined,
|
|
|
|
|
|
}))
|
|
|
|
|
|
} else {
|
|
|
|
|
|
videoResolutionPrices.value = []
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function applyVideoPricingToConfig() {
|
|
|
|
|
|
if (!form.value.config) {
|
|
|
|
|
|
form.value.config = {}
|
|
|
|
|
|
}
|
|
|
|
|
|
const cfg = form.value.config
|
|
|
|
|
|
|
|
|
|
|
|
// Clean legacy keys
|
|
|
|
|
|
deleteNested(cfg, 'billing.video.price_per_second')
|
|
|
|
|
|
deleteNested(cfg, 'billing.video.resolution_multipliers')
|
|
|
|
|
|
|
|
|
|
|
|
// resolution/size prices (normalized: 1080x720 → 720x1080)
|
|
|
|
|
|
const map: Record<string, number> = {}
|
|
|
|
|
|
for (const row of videoResolutionPrices.value) {
|
|
|
|
|
|
const k = normalizeResolutionKey(row.resolution || '')
|
|
|
|
|
|
const v = row.price_per_second
|
|
|
|
|
|
if (!k) continue
|
|
|
|
|
|
if (typeof v !== 'number' || Number.isNaN(v)) continue
|
|
|
|
|
|
map[k] = v
|
|
|
|
|
|
}
|
|
|
|
|
|
if (Object.keys(map).length > 0) {
|
|
|
|
|
|
setNested(cfg, 'billing.video.price_per_second_by_resolution', map)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
deleteNested(cfg, 'billing.video.price_per_second_by_resolution')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pruneEmptyBillingConfig()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function addVideoResolutionPriceRow() {
|
|
|
|
|
|
videoResolutionPrices.value.push({ resolution: '', price_per_second: undefined })
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function removeVideoResolutionPriceRow(idx: number) {
|
|
|
|
|
|
videoResolutionPrices.value.splice(idx, 1)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function fillVideoResolutionPricePreset(preset: 'common' | 'sora' | 'veo') {
|
|
|
|
|
|
videoResolutionPrices.value = VIDEO_RESOLUTION_PRICE_PRESETS[preset].map(r => ({
|
|
|
|
|
|
resolution: r.resolution,
|
|
|
|
|
|
price_per_second: r.price_per_second,
|
|
|
|
|
|
}))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-10 20:52:44 +08:00
|
|
|
|
|
2026-02-03 18:48:39 +08:00
|
|
|
|
// 加载模型列表
|
|
|
|
|
|
async function loadModels() {
|
|
|
|
|
|
if (allModelsCache.value.length > 0) return
|
|
|
|
|
|
loading.value = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 只加载一次全部模型,过滤在 computed 中完成
|
|
|
|
|
|
allModelsCache.value = await getModelsDevList(false)
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
log.error('Failed to load models:', err)
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
loading.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 打开对话框时加载数据
|
|
|
|
|
|
watch(() => props.open, (isOpen) => {
|
|
|
|
|
|
if (isOpen && !props.model) {
|
|
|
|
|
|
loadModels()
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2025-12-16 12:21:21 +08:00
|
|
|
|
// 选择模型并填充表单
|
|
|
|
|
|
function selectModel(model: ModelsDevModelItem) {
|
|
|
|
|
|
selectedModel.value = model
|
|
|
|
|
|
expandedProvider.value = model.providerId
|
|
|
|
|
|
form.value.name = model.modelId
|
|
|
|
|
|
form.value.display_name = model.modelName
|
|
|
|
|
|
|
|
|
|
|
|
// 构建 config
|
2026-02-22 00:43:41 +08:00
|
|
|
|
const config: Record<string, unknown> = {
|
2025-12-16 12:21:21 +08:00
|
|
|
|
streaming: true,
|
|
|
|
|
|
}
|
|
|
|
|
|
if (model.supportsVision) config.vision = true
|
|
|
|
|
|
if (model.supportsToolCall) config.function_calling = true
|
|
|
|
|
|
if (model.supportsReasoning) config.extended_thinking = true
|
2025-12-16 17:28:40 +08:00
|
|
|
|
if (model.supportsStructuredOutput) config.structured_output = true
|
|
|
|
|
|
if (model.supportsTemperature !== false) config.temperature = model.supportsTemperature
|
|
|
|
|
|
if (model.supportsAttachment) config.attachment = true
|
|
|
|
|
|
if (model.openWeights) config.open_weights = true
|
2025-12-16 12:21:21 +08:00
|
|
|
|
if (model.contextLimit) config.context_limit = model.contextLimit
|
|
|
|
|
|
if (model.outputLimit) config.output_limit = model.outputLimit
|
|
|
|
|
|
if (model.knowledgeCutoff) config.knowledge_cutoff = model.knowledgeCutoff
|
|
|
|
|
|
if (model.family) config.family = model.family
|
|
|
|
|
|
if (model.releaseDate) config.release_date = model.releaseDate
|
|
|
|
|
|
if (model.inputModalities?.length) config.input_modalities = model.inputModalities
|
|
|
|
|
|
if (model.outputModalities?.length) config.output_modalities = model.outputModalities
|
|
|
|
|
|
form.value.config = config
|
2026-02-03 18:48:39 +08:00
|
|
|
|
loadVideoPricingFromConfig()
|
2025-12-16 12:21:21 +08:00
|
|
|
|
|
|
|
|
|
|
if (model.inputPrice !== undefined || model.outputPrice !== undefined) {
|
|
|
|
|
|
tieredPricing.value = {
|
|
|
|
|
|
tiers: [{
|
|
|
|
|
|
up_to: null,
|
|
|
|
|
|
input_price_per_1m: model.inputPrice || 0,
|
|
|
|
|
|
output_price_per_1m: model.outputPrice || 0,
|
|
|
|
|
|
}]
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
tieredPricing.value = null
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 清除选择(手动填写)
|
|
|
|
|
|
function clearSelection() {
|
|
|
|
|
|
selectedModel.value = null
|
|
|
|
|
|
form.value = defaultForm()
|
|
|
|
|
|
tieredPricing.value = null
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Logo 加载失败处理
|
|
|
|
|
|
function handleLogoError(event: Event) {
|
|
|
|
|
|
const img = event.target as HTMLImageElement
|
|
|
|
|
|
img.style.display = 'none'
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-10 20:52:44 +08:00
|
|
|
|
// 重置表单
|
|
|
|
|
|
function resetForm() {
|
|
|
|
|
|
form.value = defaultForm()
|
|
|
|
|
|
tieredPricing.value = null
|
2026-02-03 18:48:39 +08:00
|
|
|
|
videoResolutionPrices.value = []
|
2025-12-16 12:21:21 +08:00
|
|
|
|
searchQuery.value = ''
|
|
|
|
|
|
selectedModel.value = null
|
|
|
|
|
|
expandedProvider.value = null
|
2025-12-10 20:52:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 加载模型数据(编辑模式)
|
|
|
|
|
|
function loadModelData() {
|
|
|
|
|
|
if (!props.model) return
|
2025-12-16 18:42:58 +08:00
|
|
|
|
// 先重置创建模式的残留状态
|
|
|
|
|
|
selectedModel.value = null
|
|
|
|
|
|
searchQuery.value = ''
|
|
|
|
|
|
expandedProvider.value = null
|
|
|
|
|
|
|
2025-12-10 20:52:44 +08:00
|
|
|
|
form.value = {
|
|
|
|
|
|
name: props.model.name,
|
|
|
|
|
|
display_name: props.model.display_name,
|
|
|
|
|
|
default_price_per_request: props.model.default_price_per_request,
|
|
|
|
|
|
supported_capabilities: [...(props.model.supported_capabilities || [])],
|
2025-12-16 12:21:21 +08:00
|
|
|
|
config: props.model.config ? { ...props.model.config } : { streaming: true },
|
2025-12-10 20:52:44 +08:00
|
|
|
|
is_active: props.model.is_active,
|
|
|
|
|
|
}
|
2025-12-16 18:42:58 +08:00
|
|
|
|
// 确保 tieredPricing 也被正确设置或重置
|
|
|
|
|
|
tieredPricing.value = props.model.default_tiered_pricing
|
|
|
|
|
|
? JSON.parse(JSON.stringify(props.model.default_tiered_pricing))
|
|
|
|
|
|
: null
|
2026-02-03 18:48:39 +08:00
|
|
|
|
loadVideoPricingFromConfig()
|
2025-12-10 20:52:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 使用 useFormDialog 统一处理对话框逻辑
|
|
|
|
|
|
const { isEditMode, handleDialogUpdate, handleCancel } = useFormDialog({
|
|
|
|
|
|
isOpen: () => props.open,
|
|
|
|
|
|
entity: () => props.model,
|
|
|
|
|
|
isLoading: submitting,
|
|
|
|
|
|
onClose: () => emit('update:open', false),
|
|
|
|
|
|
loadData: loadModelData,
|
|
|
|
|
|
resetForm,
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
async function handleSubmit() {
|
|
|
|
|
|
if (!form.value.name || !form.value.display_name) {
|
2026-02-03 18:48:39 +08:00
|
|
|
|
showError('请填写模型ID和名称')
|
2025-12-10 20:52:44 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!tieredPricing.value?.tiers?.length) {
|
|
|
|
|
|
showError('请配置至少一个价格阶梯')
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-12 15:43:00 +08:00
|
|
|
|
const finalTiers = tieredPricingEditorRef.value?.getFinalTiers()
|
|
|
|
|
|
const finalTieredPricing = finalTiers ? { tiers: finalTiers } : tieredPricing.value
|
|
|
|
|
|
|
2026-02-03 18:48:39 +08:00
|
|
|
|
// Apply billing (video) pricing into config before cleaning/submitting.
|
|
|
|
|
|
applyVideoPricingToConfig()
|
|
|
|
|
|
|
2026-02-28 13:52:32 +08:00
|
|
|
|
// Auto-infer supported_capabilities from tiered pricing config
|
|
|
|
|
|
const caps = new Set(form.value.supported_capabilities || [])
|
|
|
|
|
|
const has1hPricing = finalTieredPricing?.tiers?.some(
|
|
|
|
|
|
(t: Record<string, unknown>) => Array.isArray(t.cache_ttl_pricing)
|
|
|
|
|
|
&& (t.cache_ttl_pricing as Array<Record<string, unknown>>).some(c => c.ttl_minutes === 60)
|
|
|
|
|
|
)
|
|
|
|
|
|
if (has1hPricing) {
|
|
|
|
|
|
caps.add('cache_1h')
|
|
|
|
|
|
} else {
|
|
|
|
|
|
caps.delete('cache_1h')
|
|
|
|
|
|
}
|
|
|
|
|
|
form.value.supported_capabilities = caps.size > 0 ? [...caps] : []
|
|
|
|
|
|
|
2025-12-16 12:21:21 +08:00
|
|
|
|
// 清理空的 config
|
|
|
|
|
|
const cleanConfig = form.value.config && Object.keys(form.value.config).length > 0
|
|
|
|
|
|
? form.value.config
|
|
|
|
|
|
: undefined
|
|
|
|
|
|
|
2025-12-10 20:52:44 +08:00
|
|
|
|
submitting.value = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
if (isEditMode.value && props.model) {
|
|
|
|
|
|
const updateData: GlobalModelUpdate = {
|
|
|
|
|
|
display_name: form.value.display_name,
|
2025-12-16 12:21:21 +08:00
|
|
|
|
config: cleanConfig || null,
|
2025-12-10 20:52:44 +08:00
|
|
|
|
default_price_per_request: form.value.default_price_per_request ?? null,
|
2025-12-12 15:43:00 +08:00
|
|
|
|
default_tiered_pricing: finalTieredPricing,
|
2025-12-10 20:52:44 +08:00
|
|
|
|
supported_capabilities: form.value.supported_capabilities?.length ? form.value.supported_capabilities : null,
|
|
|
|
|
|
is_active: form.value.is_active,
|
|
|
|
|
|
}
|
|
|
|
|
|
await updateGlobalModel(props.model.id, updateData)
|
|
|
|
|
|
success('模型更新成功')
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const createData: GlobalModelCreate = {
|
2026-02-22 00:43:41 +08:00
|
|
|
|
name: form.value.name ?? '',
|
|
|
|
|
|
display_name: form.value.display_name ?? '',
|
2025-12-16 12:21:21 +08:00
|
|
|
|
config: cleanConfig,
|
|
|
|
|
|
default_price_per_request: form.value.default_price_per_request ?? undefined,
|
2025-12-12 15:43:00 +08:00
|
|
|
|
default_tiered_pricing: finalTieredPricing,
|
2025-12-10 20:52:44 +08:00
|
|
|
|
supported_capabilities: form.value.supported_capabilities?.length ? form.value.supported_capabilities : undefined,
|
|
|
|
|
|
is_active: form.value.is_active,
|
|
|
|
|
|
}
|
|
|
|
|
|
await createGlobalModel(createData)
|
|
|
|
|
|
success('模型创建成功')
|
2026-02-25 23:33:16 +08:00
|
|
|
|
clearSelection()
|
|
|
|
|
|
emit('success')
|
|
|
|
|
|
return
|
2025-12-10 20:52:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
emit('update:open', false)
|
|
|
|
|
|
emit('success')
|
2026-02-22 00:43:41 +08:00
|
|
|
|
} catch (err: unknown) {
|
|
|
|
|
|
showError(parseApiError(err, isEditMode.value ? '更新失败' : '创建失败'), isEditMode.value ? '更新失败' : '创建失败')
|
2025-12-10 20:52:44 +08:00
|
|
|
|
} finally {
|
|
|
|
|
|
submitting.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|