fix: use published Claude capacity when upstream metadata is missing

This commit is contained in:
Agent Workbench Dev
2026-11-06 20:52:39 +08:00
parent 2eac1bcb12
commit 2bd7b24aa2
8 changed files with 380 additions and 9 deletions
+6 -6
View File
@@ -9,7 +9,7 @@ import { ModelWaitSettings, type WaitSettings } from './ModelWaitSettings';
import { NativeParameters } from './NativeParameters';
import { ModelErrorDetails } from './ModelErrorDetails';
import { ModelBudgetSettings } from './ModelBudgetSettings';
import { DEFAULT_MODEL_CAPACITY, messagesOutputSetting } from '../shared/contracts/model-capacity.mjs';
import { DEFAULT_MODEL_CAPACITY, messagesOutputSetting, modelCapacityDeclaration } from '../shared/contracts/model-capacity.mjs';
import { modelRequestUrl, protocolLabel } from '../shared/contracts/model-endpoint.mjs';
import { ModelNetworkDiagnostics } from './ModelNetworkDiagnostics';
import { ModelCatalog } from './ModelCatalog';
@@ -17,8 +17,8 @@ import type { CatalogModel } from '../shared/contracts/model-catalog.mjs';
const previewUrl = (value: { protocol: string; baseUrl: string }) => { try { return modelRequestUrl(value); } catch { return '请填写有效的接口根地址'; } };
const upstreamCapacity = (value: { model: string; upstreamModel?: CatalogModel }, field: 'contextLimit' | 'maxOutputTokens') => {
const tokens = value.upstreamModel?.id === value.model ? value.upstreamModel[field] : undefined;
return typeof tokens === 'number' && tokens > 0 ? tokens.toLocaleString() + ' tokens' : '本地无限制 · 由上游决定';
const declaration = modelCapacityDeclaration(value, field);
return declaration ? declaration.value.toLocaleString() + ' tokens · ' + (declaration.source === 'official_model_spec' ? 'Anthropic 官方规格' : '上游目录') : '本地无限制 · 由上游决定';
};
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;
@@ -125,7 +125,7 @@ export function ModelCenter({ onConfig, busy, runModel }: { onConfig: (value: Co
{!connections.length && catalogSource === null && !editing && <div className="mc-empty"><strong>还没有模型连接</strong><p>从上游获取可用型号,选择后即可开始开发。</p></div>}
<div className="mc-connections">{connections.map(value => <article className={'mc-connection ' + (!value.enabled ? 'mc-disabled' : '')} key={value.id} data-connection-id={value.id}>
<div className="mc-card-heading"><span className="mc-service-icon"><Server size={20} /></span><div><h4>{value.name}</h4><span>{value.brand} · {protocolLabel(value.protocol)}{value.streaming ? ' · 流式开启' : ''}</span></div><span className={'mc-state mc-state-' + value.status}>{states[value.status]}</span></div>
<dl><dt>模型</dt><dd>{value.model || '尚未填写'}</dd><dt>请求地址</dt><dd>{previewUrl(value)}</dd>{value.protocol === 'anthropic-messages' && <><dt>协议必填输出</dt><dd>max_tokens = {String(messagesOutputSetting(value).value)} · {messagesOutputSetting(value).source === 'upstream_catalog' ? '上游目录最大值' : messagesOutputSetting(value).source === 'explicit_native' ? '显式原生参数' : '连接声明,最大值未验证'}</dd><dt>鉴权</dt><dd>{value.messagesAuth === 'bearer' ? 'Bearer' : 'x-api-key'} · anthropic-version 2023-06-01</dd></>}<dt>凭据</dt><dd>{value.credentialSource ? '共用 ' + (connections.find(source => source.id === value.credentialSource!.connectionId)?.name ?? '源连接') + (value.hasKey ? ' 的上游凭据' : ';请核对源连接是否启用及凭据') : value.hasKey ? value.savedCredential?.status === 'saved' ? '已设置,可从本机加密保存加载' : '已设置,重启需重新填写' : value.requiresKey ? '尚未填写' : '此服务可不填'}</dd><dt>当前请求</dt><dd>{value.activeRequests} 在途 · 并发 {value.concurrency === 0 ? '不限' : value.concurrency}</dd>{passthrough ? <><dt>模型最大上下文</dt><dd>{upstreamCapacity(value, 'contextLimit')}</dd><dt>模型最大输出</dt><dd>{upstreamCapacity(value, 'maxOutputTokens')}</dd></> : <><dt>连接容量声明</dt><dd>上下文 {value.contextLimit.toLocaleString()} · 输出 {value.maxOutputTokens.toLocaleString()}</dd></>}</dl>
<dl><dt>模型</dt><dd>{value.model || '尚未填写'}</dd><dt>请求地址</dt><dd>{previewUrl(value)}</dd>{value.protocol === 'anthropic-messages' && <><dt>协议必填输出</dt><dd>max_tokens = {String(messagesOutputSetting(value).value)} · {messagesOutputSetting(value).source === 'upstream_catalog' ? '上游目录最大值' : messagesOutputSetting(value).source === 'official_model_spec' ? 'Anthropic 官方同步输出规格' : messagesOutputSetting(value).source === 'explicit_native' ? '显式原生参数' : '连接声明,最大值未验证'}</dd><dt>鉴权</dt><dd>{value.messagesAuth === 'bearer' ? 'Bearer' : 'x-api-key'} · anthropic-version 2023-06-01</dd></>}<dt>凭据</dt><dd>{value.credentialSource ? '共用 ' + (connections.find(source => source.id === value.credentialSource!.connectionId)?.name ?? '源连接') + (value.hasKey ? ' 的上游凭据' : ';请核对源连接是否启用及凭据') : value.hasKey ? value.savedCredential?.status === 'saved' ? '已设置,可从本机加密保存加载' : '已设置,重启需重新填写' : value.requiresKey ? '尚未填写' : '此服务可不填'}</dd><dt>当前请求</dt><dd>{value.activeRequests} 在途 · 并发 {value.concurrency === 0 ? '不限' : value.concurrency}</dd>{passthrough ? <><dt>模型最大上下文</dt><dd>{upstreamCapacity(value, 'contextLimit')}</dd><dt>模型最大输出</dt><dd>{upstreamCapacity(value, 'maxOutputTokens')}</dd></> : <><dt>连接容量声明</dt><dd>上下文 {value.contextLimit.toLocaleString()} · 输出 {value.maxOutputTokens.toLocaleString()}</dd></>}</dl>
{value.upstreamModel && <p className="mc-help">型号来自上游目录,能力按目录声明与显式设置保存;可在“推理与能力”查看已接入范围。</p>}
<div className="mc-capabilities">{Object.entries(capabilityLabels).map(([key, title]) => <span key={key} data-capability={value.capabilities?.[key] ?? 'unknown'}>{title}:{capabilityStates[value.capabilities?.[key] ?? 'unknown']}</span>)}</div>
{value.health.reason && <p className="mc-card-warning">{value.health.reason}{!!value.health.cooldownUntil && value.health.cooldownUntil > Date.now() && ' · 冷却至 ' + new Date(value.health.cooldownUntil).toLocaleTimeString()}</p>}
@@ -154,10 +154,10 @@ export function ModelCenter({ onConfig, busy, runModel }: { onConfig: (value: Co
<label className="mc-full">允许的返回型号(可选,逗号分隔)<input value={draft.modelIdentityAliasesText} onChange={event => setDraft({ ...draft, modelIdentityAliasesText: event.target.value })} /></label>
<label className="mc-full">型号映射依据<input required={draft.modelIdentityAliasesText.trim().length > 0} value={draft.modelIdentityAliasSource} placeholder="填写供应商映射说明或可核对的出处" onChange={event => setDraft({ ...draft, modelIdentityAliasSource: event.target.value })} /></label>
<label>临时 API Key<input type="password" autoComplete="off" value={key} placeholder={draft.id ? '留空保留本次凭据' : '按服务要求填写'} onChange={event => setKey(event.target.value)} /></label>
{passthrough ? <div className="mc-full" aria-label="连接容量策略"><strong>默认透传 · 不设本地上限</strong><dl className="mc-capacity-facts"><div><dt>模型最大上下文</dt><dd aria-label="模型最大上下文">{upstreamCapacity(draft, 'contextLimit')}</dd></div><div><dt>模型最大输出</dt><dd aria-label="模型最大输出">{upstreamCapacity(draft, 'maxOutputTokens')}</dd></div></dl><p className="mc-help">容量数值来自当前型号的上游目录,仅供查看;上游未提供时显示本地无限制。完整发送上下文,不附加输出 token 上限,上游错误原文保留。</p></div> : <>
{passthrough ? <div className="mc-full" aria-label="连接容量策略"><strong>默认透传 · 不设本地上限</strong><dl className="mc-capacity-facts"><div><dt>模型最大上下文</dt><dd aria-label="模型最大上下文">{upstreamCapacity(draft, 'contextLimit')}</dd></div><div><dt>模型最大输出</dt><dd aria-label="模型最大输出">{upstreamCapacity(draft, 'maxOutputTokens')}</dd></div></dl><p className="mc-help">容量来自当前型号的上游目录或官方规格,仅供查看;未公开时本地无限制。完整发送上下文;Messages 按协议带 max_tokens,其它协议默认不附加输出上限,上游错误原文保留。</p></div> : <>
<label>上下文上限<input type="number" required step="1" min="1000" value={draft.contextLimit} onChange={event => setDraft({ ...draft, contextLimit: Number(event.target.value) })} /></label>
<label>输出上限<input type="number" required step="1" min="256" value={draft.maxOutputTokens} onChange={event => setDraft({ ...draft, maxOutputTokens: Number(event.target.value) })} /></label>
<div className="mc-full"><p className="mc-help">容量优先使用上游目录声明;未提供时需要按供应商核对。推理可能共享输出额度。</p><button type="button" className="button secondary" onClick={() => setDraft({ ...draft, contextLimit: draft.upstreamModel?.contextLimit ?? DEFAULT_MODEL_CAPACITY.contextLimit, maxOutputTokens: draft.upstreamModel?.maxOutputTokens ?? DEFAULT_MODEL_CAPACITY.maxOutputTokens })}>{draft.upstreamModel?.contextLimit || draft.upstreamModel?.maxOutputTokens ? '采用上游容量' : '填入开发初始值'}</button></div>
<div className="mc-full"><p className="mc-help">容量优先使用上游目录,缺项时采用已知型号的官方规格;未知型号由上游决定。推理可能共享输出额度。</p><button type="button" className="button secondary" onClick={() => setDraft({ ...draft, contextLimit: modelCapacityDeclaration(draft, 'contextLimit')?.value ?? DEFAULT_MODEL_CAPACITY.contextLimit, maxOutputTokens: modelCapacityDeclaration(draft, 'maxOutputTokens')?.value ?? DEFAULT_MODEL_CAPACITY.maxOutputTokens })}>{modelCapacityDeclaration(draft, 'contextLimit') || modelCapacityDeclaration(draft, 'maxOutputTokens') ? '采用已知模型容量' : '填入开发初始值'}</button></div>
</>}
<label>{runtimeConfig?.executionMode === 'unrestricted' ? '并发请求数(0 为不限)' : '并发请求上限'}<input type="number" min={runtimeConfig?.executionMode === 'unrestricted' ? 0 : 1} max={runtimeConfig?.executionMode === 'unrestricted' ? undefined : 8} value={draft.concurrency} onChange={event => setDraft({ ...draft, concurrency: Number(event.target.value) })} /></label>
<label className="mc-checkbox"><input type="checkbox" checked={draft.requiresKey} onChange={event => setDraft({ ...draft, requiresKey: event.target.checked })} />服务需要 API Key</label></div>
+1 -1
View File
@@ -34,7 +34,7 @@ export function NativeParameters({ connection, busy, onCancel, onSave, execution
setProfile(value);
}} />
<label>输出上限字段<select aria-label="输出上限字段" value={field} disabled={busy} onChange={event => setField(event.target.value)}>{(connection.protocol === 'responses' ? ['max_output_tokens'] : connection.protocol === 'anthropic-messages' ? ['max_tokens'] : ['max_tokens', 'max_completion_tokens']).map(value => <option key={value}>{value}</option>)}</select></label>
<p className="mc-help">{connection.protocol === 'anthropic-messages' ? 'Messages 协议必须带 max_tokens;当前 ' + String(messagesOutputSetting(connection).value) + '(' + ({ explicit_native: '显式原生参数', upstream_catalog: '上游目录最大输出', connection_declaration: '连接声明,非已验证最大值' }[messagesOutputSetting(connection).source] ?? '') + ')。可在 JSON 中显式设置;本地不裁剪输出。' : executionMode === 'unrestricted' ? '默认不附加输出上限;可在 JSON 中显式填写上游参数,服务是否接受以原始响应为准。' : '数值沿用当前任务和连接的输出预算。'}消息、工具、接口和凭据由各自设置管理。</p>
<p className="mc-help">{connection.protocol === 'anthropic-messages' ? 'Messages 协议必须带 max_tokens;当前 ' + String(messagesOutputSetting(connection).value) + '(' + ({ explicit_native: '显式原生参数', upstream_catalog: '上游目录最大输出', official_model_spec: 'Anthropic 官方同步输出规格', connection_declaration: '连接声明,非已验证最大值' }[messagesOutputSetting(connection).source] ?? '') + ')。可在 JSON 中显式设置;本地不裁剪输出。' : executionMode === 'unrestricted' ? '默认不附加输出上限;可在 JSON 中显式填写上游参数,服务是否接受以原始响应为准。' : '数值沿用当前任务和连接的输出预算。'}消息、工具、接口和凭据由各自设置管理。</p>
<label>原生参数 JSON<textarea aria-label="原生参数 JSON" rows={7} maxLength={executionMode === 'unrestricted' ? undefined : 8192} spellCheck={false} value={text} disabled={busy} onChange={event => setText(event.target.value)} /></label>
<p className="mc-help">{connection.protocol === 'anthropic-messages' ? '已接入 temperature(0–1)、top_p、top_k、stop_sequences、thinking、output_config.effort。' : connection.protocol === 'responses' ? '已接入 temperature、top_p、parallel_tool_calls、reasoning.effort、text.verbosity。' : '已接入 temperature、top_p、seed、parallel_tool_calls、reasoning_effort、verbosity、DeepSeek thinking。'}推理控件与 JSON 编辑同一份参数,其他字段保存时会给出具体提示。</p>
{error && <p className="mc-card-warning" role="alert">{error}</p>}
@@ -3,3 +3,4 @@ export const CAPACITY_RANGES: Readonly<Record<'contextLimit' | 'maxOutputTokens'
export function capacitySettings(input?: { contextLimit?: number; maxOutputTokens?: number }, previous?: { contextLimit?: number; maxOutputTokens?: number }): { contextLimit: number; maxOutputTokens: number };
export function capacityMode(value?: string): 'model' | 'manual';
export function messagesOutputSetting(config: { model?: string; nativeParameters?: Record<string, unknown>; maxOutputTokens?: number; upstreamModel?: { id: string; maxOutputTokens?: number | null } }): { value: unknown; source: string };
export function modelCapacityDeclaration(config: { model?: string; upstreamModel?: { id: string; contextLimit?: number | null; maxOutputTokens?: number | null } }, field: 'contextLimit' | 'maxOutputTokens'): { value: number; source: 'upstream_catalog' | 'official_model_spec'; sourceUrl?: string; checkedAt?: string } | null;
+12 -2
View File
@@ -1,4 +1,5 @@
import { unrestricted } from './execution-policy.mjs';
import { officialModelCapacity } from './official-model-capacity.mjs';
// Editable fallbacks for upstreams that do not publish capacity. These values
// are not verified model capabilities or ceilings on larger models.
@@ -16,12 +17,21 @@ export function capacitySettings(input = {}, previous = DEFAULT_MODEL_CAPACITY,
export const isPassthrough = config => config.capacityMode === 'passthrough';
export function modelCapacityDeclaration(config, field) {
if (!['contextLimit', 'maxOutputTokens'].includes(field)) return null;
const member = config.modelRouting?.members?.find(value => value.id === config.modelConnectionId) ?? config;
const upstream = member.upstreamModel;
if (upstream?.id === member.model && Number.isSafeInteger(upstream[field]) && upstream[field] > 0) return { value: upstream[field], source: 'upstream_catalog' };
const official = officialModelCapacity(member.model);
return official ? { value: official[field], source: official.source, sourceUrl: official.sourceUrl, checkedAt: official.checkedAt } : null;
}
export function messagesOutputSetting(config) {
const member = config.modelRouting?.members?.find(value => value.id === config.modelConnectionId) ?? config;
const native = config.nativeParameters ?? member.nativeParameters ?? {};
if (Object.hasOwn(native, 'max_tokens')) return { value: native.max_tokens, source: 'explicit_native' };
const upstream = member.upstreamModel;
if (upstream?.id === member.model && upstream.maxOutputTokens) return { value: upstream.maxOutputTokens, source: 'upstream_catalog' };
const declaration = modelCapacityDeclaration(config, 'maxOutputTokens');
if (declaration) return declaration;
return { value: member.maxOutputTokens ?? config.maxOutputTokens ?? DEFAULT_MODEL_CAPACITY.maxOutputTokens, source: 'connection_declaration' };
}
@@ -0,0 +1,12 @@
// Exact pinned IDs from Anthropic's Models overview, checked 2026-11-06.
// These are synchronous Messages declarations, not measured gateway limits.
// The separate 300K Message Batches beta is not used for ordinary requests.
const sourceUrl = 'https://platform.claude.com/docs/en/models/overview';
const claude = Object.freeze(Object.fromEntries([
'claude-fable-5-1', 'claude-opus-5-5', 'claude-sonnet-5-5', 'claude-haiku-5-5',
].map(model => [model, Object.freeze({ model, contextLimit: 1000000, maxOutputTokens: 128000,
sourceUrl, checkedAt: '2026-11-06', source: 'official_model_spec' })])));
export function officialModelCapacity(model) {
return typeof model === 'string' && Object.hasOwn(claude, model) ? claude[model] : null;
}