feat: add model catalog filters and channel configuration

This commit is contained in:
wlx committed 2026-08-31 13:41:40 +08:00
1 parent 547f7c0977
commit 2897354dd8
7 files changed
+173 -15

No files matched your search

+19 -1
View File
@@ -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<string, unknown>; 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<string, unknown> }
: {}),
@@ -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