Files
Agent-Workbench/src/client/ModelSpecificationDetails.tsx
T

40 lines
5.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { resolveModelSpecification } from '../shared/contracts/official-model-registry.mjs';
import type { ModelSpecConnection, ModelSpecField, ModelSpecification } from '../shared/contracts/official-model-registry.mjs';
import './ModelSpecificationDetails.css';
const fields: Record<string, string> = { contextLimit: '最大上下文', maxInputTokens: '最大输入', maxOutputTokens: '最大输出', efforts: '推理强度', modes: '推理模式', defaultEffort: '默认强度', defaultMode: '默认模式', modeEfforts: '模式与强度组合', inputModalities: '输入类型', outputModalities: '输出类型', nativeTools: '供应商原生工具', lifecycle: '型号状态', aliasOf: '供应商型号映射', toolsCondition: '工具调用条件',
'capabilities.text': '文本', 'capabilities.tools': '工具调用', 'capabilities.streaming': '流式', 'capabilities.vision': '图像输入', 'capabilities.audio': '语音',
'features.thinking': '推理', 'features.effort': '强度选择', 'features.prompt_caching': '提示缓存', 'features.structured_outputs': '结构化输出', 'features.json_output': 'JSON 输出',
'request.systemPromptUpdate': '系统提示更新位置', 'request.maxTokensRequired': 'HTTP 必须带 max_tokens', 'request.versionHandling': 'API 版本处理', 'request.thinkingBudget': '推理预算处理', 'request.aliasAccepted': '上游接受旧型号名', 'request.originalModelRetired': '旧型号底层已退役' };
const kinds: Record<string, string> = { official_model_spec: '官方规格', upstream_catalog: '上游目录声明', explicit_compatibility: '用户兼容覆盖', connection_declaration: '用户连接声明', legacy_connection_declaration: '原连接声明(编辑来源未记录)', revision_bound_observation: '对应修订的实际观测', protocol_declaration: '协议声明' };
const states: Record<string, string> = { supported: '声明支持', unsupported: '声明不支持', unknown: '待确认', active: '可用', deprecated: '已弃用的旧名称', retired: '已退役', ignored: '上游忽略', 'reasoning-none': 'Chat 工具调用需 reasoning_effort=none', 'responses-only': '工具调用需 Responses', 'in-history': '可在历史中更新', 'leading-only': '仅允许开头的系统提示' };
const display = (value: unknown): string => value === null || value === undefined ? '未公布 / 未知' : Array.isArray(value) ? value.length ? value.map(display).join(' / ') : '无已声明选项'
: typeof value === 'number' ? value.toLocaleString() : typeof value === 'boolean' ? value ? '是' : '否' : typeof value === 'object' ? JSON.stringify(value) : states[String(value)] ?? String(value);
function Source({ fact }: { fact: Omit<ModelSpecField, 'alternatives' | 'conflict'> }) {
return <span className="model-spec-source"><span>{kinds[fact.kind] ?? fact.kind}{fact.checkedAt ? ' · ' + fact.checkedAt : ''}</span>
{fact.url && <a href={fact.url} target="_blank" rel="noreferrer">{fact.sourceId ?? '查看声明来源'}</a>}
{fact.apiVersion && <span>规格 API 版本 {fact.apiVersion}</span>}{fact.sha256 && <code>SHA256 {fact.sha256}</code>}{fact.note && <span>{fact.note}</span>}</span>;
}
export function ModelSpecificationDetails({ connection, specification }: { connection: ModelSpecConnection; specification?: ModelSpecification }) {
const value = specification ?? resolveModelSpecification(connection), catalog = connection.upstreamModel;
return <details className="model-specification-details">
<summary>模型规格与来源{value.conflicts.length > 0 ? ` · ${value.conflicts.length} 项声明差异` : ''}</summary>
<p>型号 {value.model || '尚未选择'} · {value.protocol} · 资料版本 {value.registryVersion}。官方规格、目录声明与本次线路观测分别保留。</p>
{value.officialRecord && <p>匹配到官方精确型号,规格 API 版本 {value.officialRecord.apiVersion};实际发送版本以请求账本为准。官方资料不代表这条代理线路已通过验证。</p>}
{connection.modelSpecificationFrozen && <p>这是该次运行封存的规格;后续目录刷新和设置不会改写它。</p>}
<table aria-label="模型规格来源表"><thead><tr><th>规格</th><th>当前参考值</th><th>来源</th></tr></thead><tbody>
{Object.entries(value.fields).map(([key, fact]) => <tr key={key} data-spec-field={key}>
<th scope="row">{fields[key] ?? key}</th><td>{display(fact.value)}{fact.conflict && <strong className="model-spec-conflict">存在声明差异</strong>}</td>
<td><Source fact={fact} />{fact.alternatives.length > 0 && <details className="model-spec-alternatives"><summary>查看其他 {fact.alternatives.length} 项来源</summary>
{fact.alternatives.map((other, index) => <div key={index}><strong>{display(other.value)}</strong><Source fact={other} /></div>)}</details>}</td>
</tr>)}
{!Object.keys(value.fields).length && <tr><td colSpan={3}>尚未取得型号规格。默认透传,由上游处理。</td></tr>}
</tbody></table>
{catalog?.rawItem && <details className="model-spec-raw"><summary>上游完整声明</summary>
<p>保存的是已解析、脱敏的 JSON 条目;不会把这些额外字段自动加入请求。{catalog.rawBytes !== undefined ? ` ${catalog.rawBytes.toLocaleString()} 字节。` : ''}</p>
<code>表示 {catalog.rawRepresentation ?? '旧目录未记录表示格式'}{catalog.rawSha256 ? ' · SHA256 ' + catalog.rawSha256 : ''}</code>
<pre tabIndex={0}>{JSON.stringify(catalog.rawItem, null, 2)}</pre>
</details>}
</details>;
}