diff --git a/control-plane/src/catalog.ts b/control-plane/src/catalog.ts index 9946a54..06abf5d 100644 --- a/control-plane/src/catalog.ts +++ b/control-plane/src/catalog.ts @@ -5,14 +5,19 @@ export type ModelType = 'text' | 'code' | 'multimodal' | 'image' | 'audio' | 'vi export type CallMode = 'sync' | 'stream' | 'async' export type ProviderProtocol = 'openai-compatible' | 'http' | 'sdk' export type CatalogStatus = 'active' | 'disabled' +export type ProviderSourceType = 'official' | 'relay' | 'self-hosted' | 'custom' export interface ProviderRecord { id: string code: string name: string protocol: ProviderProtocol + sourceType: ProviderSourceType baseUrl?: string description?: string + credentialType?: 'none' | 'api-key' | 'bearer' | 'access-token' + credentialSecret?: string + credentialMasked?: string status: CatalogStatus createdAt: string updatedAt: string @@ -21,6 +26,8 @@ export interface ProviderRecord { export interface ModelRecord { id: string providerId: string + modelKey?: string + sourceLabel?: string publicName: string upstreamModel: string type: ModelType @@ -29,6 +36,9 @@ export interface ModelRecord { inputTypes: string[] outputTypes: string[] capabilities: Record + pricing?: { input?: number; output?: number; unit?: string } + priority?: number + maxConcurrency?: number status: CatalogStatus createdAt: string updatedAt: string @@ -104,6 +114,7 @@ export class MemoryCatalogRepository implements CatalogRepository { code: 'moyi-mock', name: 'MOYI Mock Provider', protocol: 'http', + sourceType: 'custom', baseUrl: 'http://mock.local', description: '用于控制台联调的 Mock 供应商,不代表真实上游能力。', status: 'active', @@ -115,6 +126,7 @@ export class MemoryCatalogRepository implements CatalogRepository { code: 'vast', name: 'VAST / Tripo', protocol: 'http', + sourceType: 'official', description: 'Tripo v3 文生 3D 供应商适配器;未配置服务端密钥时自动使用 Mock。', status: 'active', createdAt: now, @@ -125,6 +137,7 @@ export class MemoryCatalogRepository implements CatalogRepository { code: 'deepseek', name: 'DeepSeek', protocol: 'openai-compatible', + sourceType: 'official', baseUrl: 'https://api.deepseek.com', description: 'DeepSeek 官方 OpenAI 兼容接口;密钥通过 DEEPSEEK_API_KEY 注入。', status: 'active', @@ -136,6 +149,7 @@ export class MemoryCatalogRepository implements CatalogRepository { code: 'kimi', name: '月之暗面 Kimi', protocol: 'openai-compatible', + sourceType: 'official', baseUrl: 'https://api.moonshot.ai/v1', description: 'Kimi 官方 OpenAI 兼容接口;密钥通过 KIMI_API_KEY 注入。', status: 'active', @@ -147,6 +161,7 @@ export class MemoryCatalogRepository implements CatalogRepository { code: 'zhipu', name: '智谱 GLM', protocol: 'openai-compatible', + sourceType: 'official', baseUrl: 'https://open.bigmodel.cn/api/paas/v4', description: '智谱 AI 官方兼容接口;密钥通过 ZHIPU_API_KEY 注入。', status: 'active', @@ -158,6 +173,7 @@ export class MemoryCatalogRepository implements CatalogRepository { code: 'bytedance', name: '字节跳动 Seedance', protocol: 'http', + sourceType: 'official', baseUrl: 'https://ark.cn-beijing.volces.com/api/v3', description: '火山方舟 Seedance 异步视频生成接口;密钥通过 VOLCENGINE_API_KEY 注入。', status: 'active', @@ -319,10 +335,10 @@ export class CatalogService { } async listProviders(includeDisabled = false) { - return this.repository.listProviders(includeDisabled) + return (await this.repository.listProviders(includeDisabled)).map(toPublicProvider) } - async createProvider(input: { code: string; name: string; protocol: ProviderProtocol; baseUrl?: string; description?: string }) { + async createProvider(input: { code: string; name: string; protocol: ProviderProtocol; sourceType?: ProviderSourceType; baseUrl?: string; description?: string; credentialType?: ProviderRecord['credentialType']; credentialSecret?: string }) { const code = input.code.trim().toLowerCase() const name = input.name.trim() if (!/^[a-z0-9][a-z0-9._-]{1,63}$/.test(code) || !name) throw new CatalogError('INVALID_PROVIDER', '供应商 code 和名称不能为空且格式无效') @@ -332,18 +348,23 @@ export class CatalogService { code, name, protocol: input.protocol, + sourceType: input.sourceType || 'custom', ...(input.baseUrl?.trim() ? { baseUrl: input.baseUrl.trim() } : {}), ...(input.description?.trim() ? { description: input.description.trim() } : {}), + ...(input.credentialType && input.credentialType !== 'none' ? { credentialType: input.credentialType } : {}), + ...(input.credentialSecret?.trim() ? { credentialSecret: input.credentialSecret.trim(), credentialMasked: maskCredential(input.credentialSecret.trim()) } : {}), status: 'active', createdAt: now, updatedAt: now, } await this.repository.createProvider(provider) - return provider + return toPublicProvider(provider) } async createModel(input: { providerId: string + modelKey?: string + sourceLabel?: string publicName: string upstreamModel: string type: ModelType @@ -352,13 +373,21 @@ export class CatalogService { inputTypes?: string[] outputTypes?: string[] capabilities?: Record + pricing?: { input?: number; output?: number; unit?: string } + priority?: number + maxConcurrency?: number }) { if (!input.publicName.trim() || !input.upstreamModel.trim()) throw new CatalogError('INVALID_MODEL', '模型名称和上游模型标识不能为空') if (!await this.repository.findProviderById(input.providerId)) throw new CatalogError('PROVIDER_NOT_FOUND', '供应商不存在', 404) + if (input.priority !== undefined && (!Number.isInteger(input.priority) || input.priority < 0)) throw new CatalogError('INVALID_MODEL_PRIORITY', '模型路由优先级必须是大于等于 0 的整数') + if (input.maxConcurrency !== undefined && (!Number.isInteger(input.maxConcurrency) || input.maxConcurrency < 0)) throw new CatalogError('INVALID_MODEL_CONCURRENCY', '模型并发上限必须是大于等于 0 的整数') + if ([input.pricing?.input, input.pricing?.output].some((value) => value !== undefined && (!Number.isFinite(value) || value < 0))) throw new CatalogError('INVALID_MODEL_PRICING', '模型价格必须是大于等于 0 的数字') const now = new Date().toISOString() const model: ModelRecord = { id: randomUUID(), providerId: input.providerId, + ...(input.modelKey?.trim() ? { modelKey: input.modelKey.trim() } : {}), + ...(input.sourceLabel?.trim() ? { sourceLabel: input.sourceLabel.trim() } : {}), publicName: input.publicName.trim(), upstreamModel: input.upstreamModel.trim(), type: input.type, @@ -367,6 +396,9 @@ export class CatalogService { inputTypes: input.inputTypes || [], outputTypes: input.outputTypes || [], capabilities: input.capabilities || {}, + ...(input.pricing ? { pricing: input.pricing } : {}), + ...(input.priority !== undefined ? { priority: input.priority } : {}), + ...(input.maxConcurrency !== undefined ? { maxConcurrency: input.maxConcurrency } : {}), status: 'active', createdAt: now, updatedAt: now, @@ -476,3 +508,13 @@ export function toPublicApiKey(key: ApiKeyRecord): PublicApiKey { ...(key.revokedAt ? { revokedAt: key.revokedAt } : {}), } } + +export function toPublicProvider(provider: ProviderRecord) { + const { credentialSecret: _credentialSecret, ...publicProvider } = provider + return publicProvider +} + +function maskCredential(secret: string) { + if (secret.length <= 8) return '••••••••' + return `${secret.slice(0, 4)}••••••••${secret.slice(-4)}` +} diff --git a/control-plane/src/server.ts b/control-plane/src/server.ts index 5634fda..fa4f50f 100644 --- a/control-plane/src/server.ts +++ b/control-plane/src/server.ts @@ -2,7 +2,7 @@ import { randomBytes } from 'node:crypto' import { createServer, type IncomingMessage, type ServerResponse } from 'node:http' import { parse as parseUrl } from 'node:url' import { AuthError, AuthService, MemoryAuthRepository, type AuthRepository } from './auth.js' -import { CatalogService, MemoryCatalogRepository, type CallMode, type ModelType, type ProviderProtocol } from './catalog.js' +import { CatalogService, MemoryCatalogRepository, type CallMode, type ModelType, type ProviderProtocol, type ProviderSourceType } from './catalog.js' import { OpenAICompatibleProvider, OpenAICompatibleProviderError } from './providers/openai-compatible.js' import { SeedanceProvider, SeedanceProviderError } from './providers/seedance.js' import { TripoProvider, TripoProviderError } from './providers/tripo.js' @@ -469,8 +469,11 @@ async function route(request: IncomingMessage, response: ServerResponse) { code: stringValue(body.code), name: stringValue(body.name), protocol: providerProtocol(body.protocol), + sourceType: providerSourceType(body.sourceType), ...(body.baseUrl ? { baseUrl: stringValue(body.baseUrl) } : {}), ...(body.description ? { description: stringValue(body.description) } : {}), + ...(body.credentialType ? { credentialType: credentialType(body.credentialType) } : {}), + ...(body.credentialSecret ? { credentialSecret: stringValue(body.credentialSecret) } : {}), }) send(response, 201, { provider: result }) return @@ -487,6 +490,8 @@ async function route(request: IncomingMessage, response: ServerResponse) { const body = await readJson(request) const result = await catalog.createModel({ providerId: stringValue(body.providerId), + ...(body.modelKey ? { modelKey: stringValue(body.modelKey) } : {}), + ...(body.sourceLabel ? { sourceLabel: stringValue(body.sourceLabel) } : {}), publicName: stringValue(body.publicName), upstreamModel: stringValue(body.upstreamModel), type: modelType(body.type), @@ -494,6 +499,9 @@ async function route(request: IncomingMessage, response: ServerResponse) { ...(body.description ? { description: stringValue(body.description) } : {}), ...(body.inputTypes !== undefined ? { inputTypes: stringArrayValue(body.inputTypes) } : {}), ...(body.outputTypes !== undefined ? { outputTypes: stringArrayValue(body.outputTypes) } : {}), + ...(body.pricing && typeof body.pricing === 'object' && !Array.isArray(body.pricing) ? { pricing: (() => { const pricing = body.pricing as Record; return { ...(pricing.input !== undefined ? { input: numberValue(pricing.input, 'pricing.input') } : {}), ...(pricing.output !== undefined ? { output: numberValue(pricing.output, 'pricing.output') } : {}), ...(pricing.unit ? { unit: stringValue(pricing.unit) } : {}) } })() } : {}), + ...(body.priority !== undefined ? { priority: numberValue(body.priority, 'priority') } : {}), + ...(body.maxConcurrency !== undefined ? { maxConcurrency: numberValue(body.maxConcurrency, 'maxConcurrency') } : {}), ...(body.capabilities && typeof body.capabilities === 'object' && !Array.isArray(body.capabilities) ? { capabilities: body.capabilities as Record } : {}), @@ -647,6 +655,16 @@ function providerProtocol(value: unknown): ProviderProtocol { throw new AuthError('INVALID_PROVIDER_PROTOCOL', '供应商协议类型无效') } +function providerSourceType(value: unknown): ProviderSourceType { + if (value === 'official' || value === 'relay' || value === 'self-hosted' || value === 'custom') return value + return 'custom' +} + +function credentialType(value: unknown): 'none' | 'api-key' | 'bearer' | 'access-token' { + if (value === 'api-key' || value === 'bearer' || value === 'access-token') return value + return 'none' +} + function modelType(value: unknown): ModelType { const types: ModelType[] = ['text', 'code', 'multimodal', 'image', 'audio', 'video', 'embedding', '3d'] if (typeof value === 'string' && types.includes(value as ModelType)) return value as ModelType diff --git a/prototype/src/services/catalog.ts b/prototype/src/services/catalog.ts index 056d246..a9ef38d 100644 --- a/prototype/src/services/catalog.ts +++ b/prototype/src/services/catalog.ts @@ -6,12 +6,19 @@ export interface CatalogProvider { code: string name: string protocol: 'openai-compatible' | 'http' | 'sdk' + sourceType: 'official' | 'relay' | 'self-hosted' | 'custom' + baseUrl?: string + description?: string + credentialType?: 'none' | 'api-key' | 'bearer' | 'access-token' + credentialMasked?: string status: 'active' | 'disabled' } export interface CatalogModel { id: string providerId: string + modelKey?: string + sourceLabel?: string publicName: string upstreamModel: string type: CatalogModelType @@ -20,6 +27,9 @@ export interface CatalogModel { inputTypes: string[] outputTypes: string[] capabilities: Record + pricing?: { input?: number; output?: number; unit?: string } + priority?: number + maxConcurrency?: number status: 'active' | 'disabled' } @@ -214,11 +224,11 @@ class HttpCatalogClient { return this.request<{ providers: CatalogProvider[] }>('/api/admin/providers') } - async createAdminProvider(input: { code: string; name: string; protocol: CatalogProvider['protocol']; description?: string }) { + async createAdminProvider(input: { code: string; name: string; protocol: CatalogProvider['protocol']; sourceType?: CatalogProvider['sourceType']; baseUrl?: string; description?: string; credentialType?: CatalogProvider['credentialType']; credentialSecret?: string }) { return this.request<{ provider: CatalogProvider }>('/api/admin/providers', { method: 'POST', body: JSON.stringify(input) }) } - async createAdminModel(input: { providerId: string; publicName: string; upstreamModel: string; type: CatalogModelType; mode: CatalogCallMode; description?: string }) { + async createAdminModel(input: { providerId: string; publicName: string; upstreamModel: string; modelKey?: string; sourceLabel?: string; type: CatalogModelType; mode: CatalogCallMode; description?: string; inputTypes?: string[]; outputTypes?: string[]; pricing?: { input?: number; output?: number; unit?: string }; priority?: number; maxConcurrency?: number }) { return this.request<{ model: CatalogModel }>('/api/admin/models', { method: 'POST', body: JSON.stringify(input) }) } diff --git a/prototype/src/styles.css b/prototype/src/styles.css index fc1d8f9..b0cf75f 100644 --- a/prototype/src/styles.css +++ b/prototype/src/styles.css @@ -199,3 +199,6 @@ td strong{font-size:12px} @media(max-width:520px){.playground-connection>.button{width:100%;margin-left:0}.task-preview{height:190px}.live-task-head{align-items:flex-start;flex-direction:column}.live-task-actions{align-items:stretch;flex-wrap:wrap}.live-task-actions .button{flex:1}.request-panel,.response-panel{min-height:520px;padding:16px}} .model-permission-summary{display:inline-flex;align-items:center;gap:7px;padding:6px 9px;border:1px solid #dfe4ee;border-radius:7px;color:#5c4ade;background:#faf9ff;font-size:11px;cursor:pointer}.model-permission-summary:hover:not(:disabled){border-color:#b8acf9;background:#f3f0ff}.model-permission-summary:disabled{color:#98a2b3;background:#f7f8fa;cursor:not-allowed}.permission-hint{display:flex;align-items:flex-start;gap:8px;margin-top:18px;padding:11px 12px;border:1px solid #e4e0ff;border-radius:9px;color:#6252d7;background:#faf9ff;font-size:11px;line-height:1.5}.permission-hint svg{flex:0 0 auto;margin-top:1px}.permission-all-toggle,.permission-model-button{width:100%;display:flex;align-items:center;gap:10px;padding:12px 13px;border:1px solid #e4e7ef;border-radius:10px;background:#fff;color:var(--text);text-align:left;cursor:pointer}.permission-all-toggle{justify-content:space-between;margin-bottom:10px}.permission-all-toggle>span,.permission-model-button>span:nth-child(2){min-width:0;display:flex;flex:1;flex-direction:column;gap:3px}.permission-all-toggle strong,.permission-model-button strong{font-size:12px}.permission-all-toggle small,.permission-model-button small{overflow:hidden;color:var(--muted);font-size:10px;text-overflow:ellipsis;white-space:nowrap}.permission-all-toggle>span:first-child,.permission-model-button>span:first-child{display:flex;align-items:center;gap:8px}.permission-all-toggle i,.permission-model-button i{width:15px;height:15px;display:block;border:1.5px solid #cbd2df;border-radius:50%;background:#fff}.permission-all-toggle.active,.permission-model-button.active{border-color:#c7bcff;color:#5541d5;background:#faf9ff}.permission-all-toggle.active i,.permission-model-button.active i{border-color:#654de4;box-shadow:inset 0 0 0 4px #fff;background:#654de4}.permission-model-list{display:flex;max-height:290px;overflow:auto;flex-direction:column;gap:8px;padding-right:3px}.permission-model-button:hover{border-color:#b8acf9}.permission-model-button .model-icon{width:29px;height:29px;flex:0 0 29px}.modal-textarea{min-height:76px;resize:vertical}.modal-form-grid{display:grid;grid-template-columns:1fr 1fr;gap:13px}@media(max-width:600px){.modal-form-grid{grid-template-columns:1fr}.permission-model-list{max-height:240px}} +.model-filter-panel{display:flex;flex-direction:column;gap:13px;padding:16px;border:1px solid var(--border);border-radius:12px;background:#fff;box-shadow:var(--shadow)}.model-filter-head{display:flex;align-items:center;justify-content:space-between;gap:12px}.model-filter-head>div{display:flex;align-items:baseline;gap:10px}.model-filter-head strong{color:var(--text);font-size:13px}.model-filter-head span{color:var(--muted);font-size:11px}.model-filter-grid{display:grid;grid-template-columns:minmax(220px,1.7fr) repeat(4,minmax(125px,1fr));gap:9px}.model-filter-search{width:auto;height:42px}.select-filter{display:flex;min-width:0;flex-direction:column;gap:5px}.select-filter span{color:var(--muted);font-size:10px}.select-filter select{width:100%;height:42px;padding:0 11px;border:1px solid var(--border);border-radius:8px;color:var(--text-soft);font-size:11px;background:var(--soft)}.select-filter select:focus{outline:0;border-color:#bdb2f2;box-shadow:0 0 0 3px rgba(104,72,232,.07)}.filter-summary{display:flex;align-items:center;gap:12px;color:var(--muted);font-size:10px}.filter-summary span+span{padding-left:12px;border-left:1px solid var(--border);color:var(--primary)} +.provider-source-tag{display:inline-flex;align-items:center;gap:4px;padding:4px 7px;border-radius:5px;color:#5d54b8;font-size:10px;background:#f2efff}.provider-source-tag.relay{color:#176f91;background:#e9f9fd}.provider-source-tag.self-hosted{color:#317a5d;background:#ebf9f0}.provider-source-tag.custom{color:#6d7583;background:#f1f3f6}.provider-meta{display:flex;align-items:center;flex-wrap:wrap;gap:6px;margin-top:5px}.provider-endpoint{overflow:hidden;max-width:250px;color:var(--muted);font-family:"DM Mono",monospace;font-size:10px;text-overflow:ellipsis;white-space:nowrap}.provider-credential{color:#5f6b7c;font-size:10px}.admin-model-grid article{position:relative}.admin-model-grid article .model-source-line{display:flex;align-items:center;gap:7px;margin-top:8px;color:var(--muted);font-size:10px}.model-route-meta{display:flex;align-items:center;flex-wrap:wrap;gap:7px;margin-top:10px}.model-route-meta span{padding:4px 6px;border-radius:5px;color:#596579;font-size:10px;background:var(--soft)}.model-route-meta span strong{color:var(--text);font-weight:700}.admin-config-section{margin-top:16px}.admin-config-section .section-title{margin-bottom:11px} +@media(max-width:1150px){.model-filter-grid{grid-template-columns:1fr 1fr 1fr}.model-filter-search{grid-column:1/-1}}@media(max-width:720px){.model-filter-grid{grid-template-columns:1fr 1fr}.model-filter-search{grid-column:1/-1}.model-filter-head>div{align-items:flex-start;flex-direction:column;gap:4px}.filter-summary{align-items:flex-start;flex-direction:column;gap:5px}.filter-summary span+span{padding:0;border:0}}@media(max-width:480px){.model-filter-grid{grid-template-columns:1fr}.model-filter-search{grid-column:auto}} diff --git a/prototype/src/types.ts b/prototype/src/types.ts index 537c740..fb854c1 100644 --- a/prototype/src/types.ts +++ b/prototype/src/types.ts @@ -29,6 +29,11 @@ export interface ModelItem { availability: string accent: string icon: Component + modelKey?: string + sourceLabel?: string + pricing?: { input?: number; output?: number; unit?: string } + priority?: number + maxConcurrency?: number } export interface ApiKeyItem { @@ -82,6 +87,13 @@ export interface ProviderItem { successRate: string status: '健康' | '波动' | '维护中' enabled: boolean + code?: string + protocol?: 'openai-compatible' | 'http' | 'sdk' + sourceType?: 'official' | 'relay' | 'self-hosted' | 'custom' + baseUrl?: string + description?: string + credentialType?: 'none' | 'api-key' | 'bearer' | 'access-token' + credentialMasked?: string } export interface RouteItem { diff --git a/prototype/src/views/AdminConsole.vue b/prototype/src/views/AdminConsole.vue index ae91e46..03f76e5 100644 --- a/prototype/src/views/AdminConsole.vue +++ b/prototype/src/views/AdminConsole.vue @@ -51,14 +51,27 @@ const providerOpen = ref(false) const providerCode = ref('') const providerName = ref('') const providerProtocol = ref('http') +const providerSourceType = ref('official') +const providerBaseUrl = ref('') +const providerCredentialType = ref>('none') +const providerCredentialSecret = ref('') const providerDescription = ref('') const modelOpen = ref(false) const modelProviderId = ref('') const modelPublicName = ref('') const modelUpstreamModel = ref('') +const modelKey = ref('') +const modelSourceLabel = ref('') const modelType = ref('multimodal') const modelMode = ref('sync') const modelDescription = ref('') +const modelInputTypes = ref('text') +const modelOutputTypes = ref('text') +const modelInputPrice = ref('') +const modelOutputPrice = ref('') +const modelPriceUnit = ref('1K tokens') +const modelPriority = ref('100') +const modelMaxConcurrency = ref('') const auditQuery = ref('') const settings = reactive({ inviteOnly: false, emailSignup: false, phoneSignup: false, automaticCredit: false, maintenanceNotice: false, auditRetention: false }) @@ -123,6 +136,10 @@ async function addProvider() { providerCode.value = '' providerName.value = '' providerProtocol.value = 'http' + providerSourceType.value = 'official' + providerBaseUrl.value = '' + providerCredentialType.value = 'none' + providerCredentialSecret.value = '' providerDescription.value = '' providerOpen.value = true } @@ -133,7 +150,7 @@ async function createProvider() { if (!code || !name) return emit('notify', '请填写供应商 code 和名称') if (!catalogConnected.value) return emit('notify', 'Control Plane 未连接,无法保存供应商') try { - await catalogClient.createAdminProvider({ code, name, protocol: providerProtocol.value, description: providerDescription.value.trim() || undefined }) + await catalogClient.createAdminProvider({ code, name, protocol: providerProtocol.value, sourceType: providerSourceType.value, baseUrl: providerBaseUrl.value.trim() || undefined, credentialType: providerCredentialType.value, credentialSecret: providerCredentialSecret.value.trim() || undefined, description: providerDescription.value.trim() || undefined }) const result = await catalogClient.listAdminProviders() const modelsResult = await catalogClient.listAdminModels() providers.value = mapProviders(result.providers, modelsResult.models) @@ -151,9 +168,18 @@ async function addModel() { modelProviderId.value = provider.id modelPublicName.value = '' modelUpstreamModel.value = '' + modelKey.value = '' + modelSourceLabel.value = '' modelType.value = 'multimodal' modelMode.value = 'sync' modelDescription.value = '' + modelInputTypes.value = 'text' + modelOutputTypes.value = 'text' + modelInputPrice.value = '' + modelOutputPrice.value = '' + modelPriceUnit.value = '1K tokens' + modelPriority.value = '100' + modelMaxConcurrency.value = '' modelOpen.value = true } @@ -163,7 +189,12 @@ async function createModel() { if (!publicName || !upstreamModel) return emit('notify', '请填写统一模型名称和上游模型标识') if (!catalogConnected.value) return emit('notify', 'Control Plane 未连接,无法保存模型') try { - await catalogClient.createAdminModel({ providerId: modelProviderId.value, publicName, upstreamModel, type: modelType.value, mode: modelMode.value, description: modelDescription.value.trim() || undefined }) + const inputPrice = modelInputPrice.value.trim() ? Number(modelInputPrice.value) : undefined + const outputPrice = modelOutputPrice.value.trim() ? Number(modelOutputPrice.value) : undefined + const priority = Number(modelPriority.value) + const maxConcurrency = modelMaxConcurrency.value.trim() ? Number(modelMaxConcurrency.value) : undefined + if ([inputPrice, outputPrice, priority, maxConcurrency].some((value) => value !== undefined && !Number.isFinite(value))) return emit('notify', '价格、优先级和并发数必须是有效数字') + await catalogClient.createAdminModel({ providerId: modelProviderId.value, publicName, upstreamModel, modelKey: modelKey.value.trim() || undefined, sourceLabel: modelSourceLabel.value.trim() || undefined, type: modelType.value, mode: modelMode.value, inputTypes: modelInputTypes.value.split(',').map((value) => value.trim()).filter(Boolean), outputTypes: modelOutputTypes.value.split(',').map((value) => value.trim()).filter(Boolean), description: modelDescription.value.trim() || undefined, pricing: inputPrice !== undefined || outputPrice !== undefined ? { ...(inputPrice !== undefined ? { input: inputPrice } : {}), ...(outputPrice !== undefined ? { output: outputPrice } : {}), unit: modelPriceUnit.value } : undefined, priority, maxConcurrency }) const [providerResult, modelResult] = await Promise.all([catalogClient.listAdminProviders(), catalogClient.listAdminModels()]) providers.value = mapProviders(providerResult.providers, modelResult.models) models.value = mapModels(modelResult.models, providerResult.providers) @@ -184,6 +215,13 @@ function mapProviders(items: CatalogProvider[], modelItems: CatalogModel[]): Pro successRate: '—', status: provider.status === 'active' ? '健康' : '维护中', enabled: provider.status === 'active', + code: provider.code, + protocol: provider.protocol, + sourceType: provider.sourceType, + baseUrl: provider.baseUrl, + description: provider.description, + credentialType: provider.credentialType, + credentialMasked: provider.credentialMasked, })) } @@ -203,6 +241,11 @@ function mapModels(items: CatalogModel[], providersList: CatalogProvider[]): Mod availability: model.status === 'active' ? '在线' : '停用', accent: model.type === '3d' ? 'orange' : 'violet', icon: model.type === '3d' ? Box : Boxes, + modelKey: model.modelKey, + sourceLabel: model.sourceLabel, + pricing: model.pricing, + priority: model.priority, + maxConcurrency: model.maxConcurrency, })) } @@ -225,9 +268,9 @@ function mapModels(items: CatalogModel[], providersList: CatalogProvider[]): Mod diff --git a/prototype/src/views/UserConsole.vue b/prototype/src/views/UserConsole.vue index 81f3438..40303f1 100644 --- a/prototype/src/views/UserConsole.vue +++ b/prototype/src/views/UserConsole.vue @@ -47,6 +47,9 @@ const emit = defineEmits<{ navigate: [view: string]; notify: [message: string] } const modelQuery = ref('') const modelType = ref<'全部' | ModelType>('全部') +const modelProvider = ref('全部') +const modelMode = ref<'全部' | CallMode>('全部') +const modelAvailability = ref<'全部' | '在线' | '已停用'>('全部') const selectedModel = ref(null) const emptyModel: ModelItem = { id: '', name: '尚未选择模型', provider: '等待目录加载', type: '文本', mode: '同步', description: '', latency: '--', specification: '--', availability: '--', accent: 'violet', icon: MessageSquareText } const catalogModels = ref([]) @@ -113,8 +116,21 @@ onUnmounted(() => { const filteredModels = computed(() => { const query = modelQuery.value.trim().toLowerCase() - return catalogModels.value.filter((model) => (modelType.value === '全部' || model.type === modelType.value) && (!query || `${model.name} ${model.description} ${model.provider}`.toLowerCase().includes(query))) + return catalogModels.value.filter((model) => + (modelType.value === '全部' || model.type === modelType.value) + && (modelProvider.value === '全部' || model.provider === modelProvider.value) + && (modelMode.value === '全部' || model.mode === modelMode.value) + && (modelAvailability.value === '全部' || model.availability === modelAvailability.value) + && (!query || `${model.name} ${model.description} ${model.provider} ${model.sourceLabel || ''} ${model.modelKey || ''}`.toLowerCase().includes(query)), + ) }) +const modelProviders = computed(() => [...new Set(catalogModels.value.map((model) => model.provider))].sort((left, right) => left.localeCompare(right))) +const activeModelFilters = computed(() => [ + modelType.value !== '全部' ? modelType.value : '', + modelProvider.value !== '全部' ? modelProvider.value : '', + modelMode.value !== '全部' ? modelMode.value : '', + modelAvailability.value !== '全部' ? modelAvailability.value : '', +].filter(Boolean)) const filteredTasks = computed(() => taskFilter.value === '全部' ? tasks.value : tasks.value.filter((task) => task.status === taskFilter.value)) const activeTask = computed(() => tasks.value.find((task) => task.id === activeTaskId.value)) const runningTaskCount = computed(() => tasks.value.filter((task) => task.status === '执行中').length) @@ -130,6 +146,7 @@ const usageSeries = computed(() => { }) const recentTasks = computed(() => tasks.value.slice(0, 3)) const modelTypes: Array<'全部' | ModelType> = ['全部', '文本', '多模态', '图像', '3D', '视频', '音频'] +const callModes: Array<'全部' | CallMode> = ['全部', '同步', '流式', '异步'] const allModelsSelected = computed(() => catalogModels.value.length > 0 && catalogModels.value.every((model) => selectedModelIds.value.includes(model.id))) async function copy(value: string, label: string, target: string) { @@ -150,6 +167,14 @@ function copySucceeded(target: string) { return copyStates.value[target] === 'verified' || copyStates.value[target] === 'written' } +function resetModelFilters() { + modelQuery.value = '' + modelType.value = '全部' + modelProvider.value = '全部' + modelMode.value = '全部' + modelAvailability.value = '全部' +} + async function refreshOverview() { try { overview.value = await catalogClient.getOverview() @@ -305,6 +330,11 @@ function mapCatalogModels(items: CatalogModel[], providers: Array<{ id: string; availability: item.status === 'active' ? '在线' : '已停用', accent: item.type === '3d' ? 'orange' : 'violet', icon: item.type === '3d' ? Box : item.type === 'image' ? Sparkles : MessageSquareText, + modelKey: item.modelKey, + sourceLabel: item.sourceLabel, + pricing: item.pricing, + priority: item.priority, + maxConcurrency: item.maxConcurrency, })) } @@ -438,8 +468,8 @@ async function createProject() {