@@ -3,6 +3,8 @@ import { Activity, Check, CircleHelp, KeyRound, Layers3, Plus, Power, RefreshCw,
import { api , downloadArtifact } from './api' ;
import type { Config , ModelSelection , ModelSnapshot , RuntimeFailure } from './types' ;
import './ModelCenter.css' ;
import { ModelUsageDetails } from './ModelUsageDetails' ;
import type { TokenUsage } from '../shared/contracts/model-usage.mjs' ;
import { ModelIdentityDetails } from './ModelIdentityDetails' ;
import { ModelRoutingDetails , type RoutingDecision } from './ModelRoutingDetails' ;
import type { ModelIdentity } from '../shared/contracts/model-identity.mjs' ;
@@ -25,7 +27,7 @@ const upstreamCapacity = (value: { model: string; upstreamModel?: CatalogModel }
type Connection = { id : string ; name : string ; brand : string ; protocol : string ; parameterProfile? : string ; messagesAuth? : string ; baseUrl : string ; model : string ; enabled : boolean ; revision : number ; hasKey : boolean ; credentialSource ? : { connectionId : string } ; upstreamModel? : CatalogModel ;
requiresKey : boolean ; modelIdentityPolicy? : string ; modelIdentityAliases? : string [ ] ; modelIdentityAliasSource? : string ; nativeParameters? : Record < string , unknown > ; outputTokenField? : string ; streaming? : boolean ; capabilityDeclarations? : Record < string , string > ; capabilities? : Record < string , string > ; capabilityEvidence ? : { checkedAt : string } ; contextLimit : number ; maxOutputTokens : number ; concurrency : number ; status : string ; activeRequests : number ; savedCredential ? : { status : string } ; health : { state : string ; reason? : string ; cooldownUntil? : number } } ;
type Pool = { id? : string ; name : string ; members : { connectionId : string ; weight : number } [ ] ; strategy : string ; sticky : boolean ; maxAttempts : number ; revision? : number ; queueTimeoutMs : number } ;
type Attempt = { routingDecision? : RoutingDecision ; modelIdentity? : ModelIdentity ; diagnostic? : RuntimeFailure ; requestUrl? : string ; upstreamResponse ? : { requestId? : string | null ; requestUrl? : string ; responseUrl? : string | null ; redirectMode? : string } ; id : string ; connectionId : string ; poolId : string | null ; model : string ; protocol? : string ; streaming? : boolean ; rejections ? : { connectionName : string ; capability : string ; reason : string } [ ] ; status : string ; startedAt : string ; ordinal : number ; usageStatus : string ; reason? : string ; taskId? : string ; sessionId? : string ; runId : string ; requestArtifactId? : string ; responseArtifactId? : string ; responseSha256? : string ; responseRedacted? : boolean ; stream ? : { bytes : number ; capturedBytes? : number ; frames : number ; sha256 : string ; terminal : boolean } ; usage ? : { prompt_tokens? : number ; completion_tokens? : number } } ;
type Attempt = { routingDecision? : RoutingDecision ; modelIdentity? : ModelIdentity ; diagnostic? : RuntimeFailure ; requestUrl? : string ; upstreamResponse ? : { requestId? : string | null ; requestUrl? : string ; responseUrl? : string | null ; redirectMode? : string } ; id : string ; connectionId : string ; poolId : string | null ; model : string ; protocol? : string ; streaming? : boolean ; rejections ? : { connectionName : string ; capability : string ; reason : string } [ ] ; status : string ; startedAt : string ; ordinal : number ; usageStatus : string ; reason? : string ; taskId? : string ; sessionId? : string ; runId : string ; requestArtifactId? : string ; responseArtifactId? : string ; responseSha256? : string ; responseRedacted? : boolean ; stream ? : { bytes : number ; capturedBytes? : number ; frames : number ; sha256 : string ; terminal : boolean } ; usage? : TokenUsage | null } ;
type ImportRecord = { id : string ; source : string ; path : string ; enabled : boolean ; lastCheckedAt? : string ; lastSyncedAt? : string ; lastError? : string ; lastResult ? : { imported? : number ; conflicts? : string [ ] } } ;
type Center = { revision : number ; selected : { type : string ; id : string } ; waitSettings : WaitSettings ; connections : Connection [ ] ; pools : Pool [ ] ; imports : ImportRecord [ ] ; attempts : Attempt [ ] ; waiting : number } ;
type Operations = { checkedAt : string ; version : string ; scope : string ; activeTasks : number ; queue : number ; checks : { id : string ; title : string ; status : string ; detail : string } [ ] ;
@@ -205,7 +207,7 @@ export function ModelCenter({ onConfig, busy, runModel }: { onConfig: (value: Co
< fieldset > < legend > 模 型 池 成 员 与 权 重 < / legend > { connections . map ( connection = > { const member = pool . members . find ( value = > value . connectionId === connection . id ) ; return < label key = { connection . id } className = "mc-member-choice" > < input type = "checkbox" checked = { ! ! member } onChange = { event = > setPool ( { . . . pool , members : event.target.checked ? [ . . . pool . members , { connectionId : connection.id , weight : 1 } ] : pool . members . filter ( value = > value . connectionId !== connection . id ) } ) } / > < span > { connection . name } < small > { connection . model || '尚未选择模型' } · { states [ connection . status ] } < / small > < / span > < input type = "number" aria-label = { connection . name + '权重' } disabled = { ! member } min = "1" max = "10" value = { member ? . weight ? ? 1 } onChange = { event = > setPool ( { . . . pool , members : pool.members.map ( value = > value . connectionId === connection . id ? { . . . value , weight : Number ( event . target . value ) } : value ) } ) } / > < / label > ; } ) } < / fieldset >
< div className = "mc-actions" > < button className = "button secondary" type = "button" onClick = { ( ) = > setPoolEditing ( false ) } > 取 消 < / button > < button className = "button primary" disabled = { locked || ! pool . members . length } > 保 存 模 型 池 < / button > < / div > < / form > }
< / > }
{ tab === 'attempts' && < > < div className = "mc-section-title" > < div > < h3 > 请 求 账 本 < / h3 > < p > 最 近 100 次 物 理 请 求 ; 最 多 保 存 1000 次 。 未 知 用 量 保 持 未 知 。 < / p > < / div > < span > { view . attempts . length } 条 记 录 < / span > < / div > { ! view . attempts . length && < p className = "mc-empty" > 当 前 没 有 模 型 中 心 请 求 。 选 择 连 接 或 模 型 池 执 行 任 务 后 , 实 际 尝 试 会 保 存 在 这 里 。 < / p > } < div className = "mc-attempts" > { view . attempts . map ( value = > < article key = { value . id } > < div > < span className = { 'mc-state mc-state-' + value . status } > { states [ value . status ] } < / span > < strong > { value . model } < / strong > < time > { new Date ( value . startedAt ) . toLocaleString ( ) } < / time > < / div > < p > { connections . find ( connection = > connection . id === value . connectionId ) ? . name || '未派发' } · { value . protocol ? protocolLabel ( value . protocol ) : '能力筛选' } { value . streaming ? ' · 流式' : '' } · { value . ordinal ? '尝试 ' + value . ordinal : '未发送' } · { value . usageStatus === 'reported' ? ` ${ value . usage ? . prompt_tokens ? ? '?' } 输入 / ${ value . usage ? . completion_tokens ? ? '?' } 输出 tokens ` : value . usageStatus === 'not_dispatched' ? '未产生请求用量' : '用量未知' } < / p > < code > Run { value . runId } < / code > { value . stream && < div className = "mc-stream-receipt" > < p > { value . stream . terminal ? "响应完整终结" : "响应未完整,片段保留待核对" } · 已 接 收 { value . stream . bytes . toLocaleString ( ) } bytes · { value . stream . frames } 个 事 件 { value . stream . capturedBytes !== undefined && value . stream . capturedBytes < value . stream . bytes ? " · 仅保存上限内片段" : "" } < / p > < code > 原 流 SHA256 { value . stream . sha256 } < / code > { value . responseSha256 && < code > 工 件 SHA256 { value . responseSha256 } { value . responseRedacted ? "(已脱敏)" : "" } < / code > } { value . sessionId && value . responseArtifactId && < button className = "button secondary" disabled = { working } onClick = { ( ) = > void act ( async ( ) = > { await downloadArtifact ( value . sessionId ! , value . responseArtifactId ! , "model-stream-" + value . id + ".sse" ) ; } ) } > 下 载 已 保 存 的 响 应 < / button > } < / div > } { value . requestUrl && < p className = "mc-request-url" > 请 求 地 址 : { value . requestUrl } { value . upstreamResponse ? . responseUrl && < > < br / > 响 应 地 址 : { value . upstreamResponse . responseUrl } < / > } < / p > } { value . reason && < p className = "mc-card-warning" > { value . reason } < / p > } < ModelRoutingDetails decision = { value . routingDecision } / > < ModelIdentityDetails identity = { value . modelIdentity } requestedModel = { value . model } / > { value . diagnostic && < ModelErrorDetails failure = { value . diagnostic } / > } { ! value . diagnostic && value . upstreamResponse ? . requestId && < p className = "mc-help" > 上 游 请 求 ID : { value . upstreamResponse . requestId } < / p > } { value . requestArtifactId && value . sessionId && < button className = "button secondary" disabled = { working } onClick = { ( ) = > void act ( async ( ) = > { await downloadArtifact ( value . sessionId ! , value . requestArtifactId ! , "model-request-" + value . id + ".json" ) ; } ) } > 下 载 实 际 请 求 < / button > } { ! ! value . rejections ? . length && < p className = "mc-route-rejections" > { value . rejections . map ( item = > item . connectionName + ': ' + ( capabilityLabels [ item . capability ] ? ? item . capability ) + ' · ' + item . reason ) . join ( '; ' ) } < / p > } < / article > ) } < / div > < / > }
{ tab === 'attempts' && < > < div className = "mc-section-title" > < div > < h3 > 请 求 账 本 < / h3 > < p > 最 近 100 次 物 理 请 求 ; 最 多 保 存 1000 次 。 未 知 用 量 保 持 未 知 。 < / p > < / div > < span > { view . attempts . length } 条 记 录 < / span > < / div > { ! view . attempts . length && < p className = "mc-empty" > 当 前 没 有 模 型 中 心 请 求 。 选 择 连 接 或 模 型 池 执 行 任 务 后 , 实 际 尝 试 会 保 存 在 这 里 。 < / p > } < div className = "mc-attempts" > { view . attempts . map ( value = > < article key = { value . id } > < div > < span className = { 'mc-state mc-state-' + value . status } > { states [ value . status ] } < / span > < strong > { value . model } < / strong > < time > { new Date ( value . startedAt ) . toLocaleString ( ) } < / time > < / div > < p > { connections . find ( connection = > connection . id === value . connectionId ) ? . name || '未派发' } · { value . protocol ? protocolLabel ( value . protocol ) : '能力筛选' } { value . streaming ? ' · 流式' : '' } · { value . ordinal ? '尝试 ' + value . ordinal : '未发送' } · { value . usageStatus === 'reported' ? ` ${ value . usage ? . prompt_tokens ? ? '?' } 输入 / ${ value . usage ? . completion_tokens ? ? '?' } 输出 tokens ` : value . usageStatus === 'not_dispatched' ? '未产生请求用量' : '用量未知' } < / p > < ModelUsageDetails usage = { value . usage } / > < code > Run { value . runId } < / code > { value . stream && < div className = "mc-stream-receipt" > < p > { value . stream . terminal ? "响应完整终结" : "响应未完整,片段保留待核对" } · 已 接 收 { value . stream . bytes . toLocaleString ( ) } bytes · { value . stream . frames } 个 事 件 { value . stream . capturedBytes !== undefined && value . stream . capturedBytes < value . stream . bytes ? " · 仅保存上限内片段" : "" } < / p > < code > 原 流 SHA256 { value . stream . sha256 } < / code > { value . responseSha256 && < code > 工 件 SHA256 { value . responseSha256 } { value . responseRedacted ? "(已脱敏)" : "" } < / code > } { value . sessionId && value . responseArtifactId && < button className = "button secondary" disabled = { working } onClick = { ( ) = > void act ( async ( ) = > { await downloadArtifact ( value . sessionId ! , value . responseArtifactId ! , "model-stream-" + value . id + ".sse" ) ; } ) } > 下 载 已 保 存 的 响 应 < / button > } < / div > } { value . requestUrl && < p className = "mc-request-url" > 请 求 地 址 : { value . requestUrl } { value . upstreamResponse ? . responseUrl && < > < br / > 响 应 地 址 : { value . upstreamResponse . responseUrl } < / > } < / p > } { value . reason && < p className = "mc-card-warning" > { value . reason } < / p > } < ModelRoutingDetails decision = { value . routingDecision } / > < ModelIdentityDetails identity = { value . modelIdentity } requestedModel = { value . model } / > { value . diagnostic && < ModelErrorDetails failure = { value . diagnostic } / > } { ! value . diagnostic && value . upstreamResponse ? . requestId && < p className = "mc-help" > 上 游 请 求 ID : { value . upstreamResponse . requestId } < / p > } { value . requestArtifactId && value . sessionId && < button className = "button secondary" disabled = { working } onClick = { ( ) = > void act ( async ( ) = > { await downloadArtifact ( value . sessionId ! , value . requestArtifactId ! , "model-request-" + value . id + ".json" ) ; } ) } > 下 载 实 际 请 求 < / button > } { ! ! value . rejections ? . length && < p className = "mc-route-rejections" > { value . rejections . map ( item = > item . connectionName + ': ' + ( capabilityLabels [ item . capability ] ? ? item . capability ) + ' · ' + item . reason ) . join ( '; ' ) } < / p > } < / article > ) } < / div > < / > }
{ tab === 'imports' && < > < div className = "mc-section-title" > < div > < h3 > 已 有 配 置 导 入 < / h3 > < p > 先 预 览 来 源 和 模 型 , 再 导 入 。 原 客 户 端 配 置 保 持 原 样 。 < / p > < / div > < button className = "button secondary" disabled = { working } onClick = { ( ) = > void act ( async ( ) = > { const value = await api < { sources : typeof discovery } > ( '/model-center/imports' ) ; if ( alive . current ) setDiscovery ( value . sources ) ; } ) } > 识 别 本 机 来 源 < / button > < / div >
{ view . imports . length > 0 && < > < h4 > 已 登 记 来 源 < / h4 > { view . imports . map ( value = > < article className = "mc-import-source" key = { value . id } > < strong > { value . source } < / strong > < code > { value . path } < / code > < span > { value . enabled ? '每分钟检查' : '自动同步已关闭' } < / span > { value . lastCheckedAt && < p > 最 近 检 查 { new Date ( value . lastCheckedAt ) . toLocaleString ( ) } < / p > } { value . lastError && < p className = "mc-card-warning" > { value . lastError } < / p > } { ! ! value . lastResult ? . conflicts ? . length && < p className = "mc-card-warning" > 有 { value . lastResult . conflicts . length } 项 与 手 动 修 改 冲 突 , 已 保 留 工 作 台 中 的 修 改 。 < / p > } < button className = "button secondary" disabled = { locked } onClick = { ( ) = > void act ( async ( ) = > { await api ( '/model-center/import-toggle' , { id : value.id , enabled : ! value . enabled } ) ; } ) } > { value . enabled ? '关闭自动同步' : '启用自动同步' } < / button > < / article > ) } < button className = "button secondary" disabled = { locked || ! view . imports . some ( value = > value . enabled ) } onClick = { ( ) = > void act ( async ( ) = > { const result = await api < { results : { imported? : string [ ] ; conflicts? : string [ ] ; error? : string } [ ] } > ( '/model-center/import-sync' , { } ) ; const imported = result . results . reduce ( ( sum , value ) = > sum + ( value . imported ? . length ? ? 0 ) , 0 ) ; const conflicts = result . results . reduce ( ( sum , value ) = > sum + ( value . conflicts ? . length ? ? 0 ) , 0 ) ; if ( alive . current ) setNotice ( ` 已检查启用来源:更新 ${ imported } 项,冲突 ${ conflicts } 项。 ` ) ; } ) } > 立 即 同 步 已 启 用 来 源 < / button > < / > }
{ discovery . map ( value = > < article className = "mc-import-source" key = { value . source } > < strong > { value . source } < / strong > < code > { value . path || '当前版本尚无可发现的配置路径' } < / code > < span > { value . available ? value . supported ? '可预览' : '当前不支持' : '未发现' } < / span > { value . detail && < p > { value . detail } < / p > } < button className = "button secondary" disabled = { ! value . available || ! value . supported || locked } onClick = { ( ) = > { setImportSource ( value . source ) ; setImportPath ( value . path ) ; } } > 选 择 来 源 < / button > < / article > ) }