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
@@ -0,0 +1,201 @@
{
"scope": "Exact official synchronous capacity declarations and independent product verification",
"checkedAt": "2026-11-06",
"officialPage": "https://platform.claude.com/docs/en/models/overview",
"extractionSource": {
"url": "https://platform.claude.com/llms-full.txt",
"finalUrl": "https://platform.claude.com/llms-full.txt",
"contentType": "text/plain; charset=utf-8",
"receivedBytes": 1769472,
"observedPlainBytes": 9034056,
"sha256": "76854bfc5b7d670bc96b8fe8074a7709bf7dc1ad04826cf083ada4e6137a427d",
"partial": true,
"modelsOverviewFound": true
},
"officialExcerpt": {
"file": "models-overview-excerpt.md",
"sha256": "af537b1ed95a9db9ee6614f11f6070227586d39f1ea915d28c120d944a3926ea"
},
"statements": {
"outputRow": "| Max output | 128K tokens | 128K tokens | 128K tokens | 128K tokens |",
"contextRow": "| [Context window](https://platform.claude.com/docs/en/build-with-claude/context-windows) | 1M tokens | 1M tokens | 1M tokens | 1M tokens |",
"numericalExample": "model: claude-opus-5-5\n max_tokens: 128000",
"limitScope": "Synchronous Messages; 300K Message Batches beta is separate"
},
"models": [
{
"model": "claude-fable-5-1",
"contextLimit": 1000000,
"maxOutputTokens": 128000,
"sourceUrl": "https://platform.claude.com/docs/en/models/overview",
"checkedAt": "2026-11-06",
"source": "official_model_spec"
},
{
"model": "claude-opus-5-5",
"contextLimit": 1000000,
"maxOutputTokens": 128000,
"sourceUrl": "https://platform.claude.com/docs/en/models/overview",
"checkedAt": "2026-11-06",
"source": "official_model_spec"
},
{
"model": "claude-sonnet-5-5",
"contextLimit": 1000000,
"maxOutputTokens": 128000,
"sourceUrl": "https://platform.claude.com/docs/en/models/overview",
"checkedAt": "2026-11-06",
"source": "official_model_spec"
},
{
"model": "claude-haiku-5-5",
"contextLimit": 1000000,
"maxOutputTokens": 128000,
"sourceUrl": "https://platform.claude.com/docs/en/models/overview",
"checkedAt": "2026-11-06",
"source": "official_model_spec"
}
],
"directPageCaptures": [
{
"name": "overview",
"url": "https://platform.claude.com/docs/en/models/overview.md",
"finalUrl": "https://claude.com/app-unavailable-in-region",
"status": 200,
"bytes": 306528,
"sha256": "77a6e0ca863148104852d7dcc974d50cac8d2afd86b2bd1d81ab149b2f8774e4",
"capturedAt": "2026-11-06T12:40:04.698587+00:00",
"documentContent": false,
"reason": "These captures redirected to app-unavailable-in-region; HTTP 200 is not documentation evidence."
},
{
"name": "opus-4-8",
"url": "https://platform.claude.com/docs/en/models/opus-4-8/overview.md",
"finalUrl": "https://claude.com/app-unavailable-in-region",
"status": 200,
"bytes": 308044,
"sha256": "5945edfad974f39df5610bc2b22686250bf3c732a14dfe385a8674a3c6657b5c",
"capturedAt": "2026-11-06T12:39:59.219661+00:00",
"documentContent": false,
"reason": "These captures redirected to app-unavailable-in-region; HTTP 200 is not documentation evidence."
},
{
"name": "sonnet-4-6",
"url": "https://platform.claude.com/docs/en/models/sonnet-4-6/overview.md",
"finalUrl": "https://claude.com/app-unavailable-in-region",
"status": 200,
"bytes": 306528,
"sha256": "5a1a735648cc0b271e8304b650b776fd5d217ac9df56ed9676f7b96155f26004",
"capturedAt": "2026-11-06T12:39:57.228635+00:00",
"documentContent": false,
"reason": "These captures redirected to app-unavailable-in-region; HTTP 200 is not documentation evidence."
},
{
"name": "haiku-5-5",
"url": "https://platform.claude.com/docs/en/models/haiku-5-5/overview.md",
"finalUrl": "https://claude.com/app-unavailable-in-region",
"status": 200,
"bytes": 307892,
"sha256": "3d852360aa31bb4f6928e8a1859a33e812e71de39d63671dfe7520505892d747",
"capturedAt": "2026-11-06T12:39:53.219614+00:00",
"documentContent": false,
"reason": "These captures redirected to app-unavailable-in-region; HTTP 200 is not documentation evidence."
}
],
"evidenceRoot": ".qa/claude-output-capacity-2026-11-06",
"runs": [
{
"file": "official-before.tap",
"bytes": 5179,
"sha256": "7a47c9212a9c558b8644a8399184137d611f07a71595a1c9c440ffa79f60f38d"
},
{
"file": "official-after.tap",
"bytes": 763,
"sha256": "9c980fec7eb9285078e4d3f9722b2ef0073c3932d859c17a40534138a815babf"
},
{
"file": "build-1.log",
"bytes": 1122,
"sha256": "0048e15cfb66e9316d1167d1a919e74d99c6498bf025160181d17f81c9b5e611"
},
{
"file": "build-2.log",
"bytes": 1122,
"sha256": "87fd8330d1a26c2cbbf20b178a309a89f0ad91d83df4de5921052f76eec9a740"
},
{
"file": "related-1.tap",
"bytes": 6988,
"sha256": "46b22ad34c867256d52595782495362caa6d3da89328896ef6e5810a958c50dd"
},
{
"file": "ui-1.log",
"bytes": 398,
"sha256": "e00cbe426df89ff6a9df74947434367c14f9661522c4f184e7f80a92dcfc88bf"
},
{
"file": "ui-result.json",
"bytes": 681,
"sha256": "db715c24c1ef8d9b011dc68d5d1f69f6b93ab8b4ea1c2ff44da7aa6cda56ece5"
},
{
"file": "model-center-1280.png",
"bytes": 116673,
"sha256": "d539c0f4e871a7070ed1b1a17992516c00da6321138738bc1998f35859b9572c"
},
{
"file": "model-center-390.png",
"bytes": 56585,
"sha256": "a5d6dba00d166ffbbd6e77ae366bb9f2ce79967396994b8a2d835736787de49a"
},
{
"file": "candidate-build.json",
"bytes": 5613,
"sha256": "8a5fa1fe43f1eb091c28951f0c5bf80e5c9a89cbd6192b80cbce9971f89b942b"
}
],
"buildInputs": [
{
"file": "src/shared/contracts/official-model-capacity.mjs",
"sha256": "8598a295b3674745d5bf1c10d172c583d45de2f8ced10c49830720280425480e"
},
{
"file": "src/shared/contracts/model-capacity.mjs",
"sha256": "9ea3e58e0d8d0140f6970f1ad5bb9132100c5a7c84de9cf761ccfcace5863a1f"
},
{
"file": "src/shared/contracts/model-capacity.d.mts",
"sha256": "731f8af8e114e6332bf57b0d3aa06d5484fa1eb3f3761740ac4b7943f2f3f9ee"
},
{
"file": "src/client/ModelCenter.tsx",
"sha256": "1b9a21774438727b56d1223d8b2e4af032690933c38c2cda6ec147b631a71d03"
},
{
"file": "src/client/NativeParameters.tsx",
"sha256": "3468ab04ef3764c9f1457a21841356896b454558bf9e850cbf724f002d4a9a16"
},
{
"file": "tests/official-model-capacity.test.mjs",
"sha256": "b8591872ac81dea479770b53734091d964de458aa4a87054fbbdb16071055c88"
},
{
"file": "scripts/verify-official-model-capacity-ui.mjs",
"sha256": "bd12e08239f589199b16d110ce8cf1c3b6d1821a684d643e67cf133dcdfb576a"
}
],
"tests": {
"related": 67,
"pass": 67,
"fail": 0,
"UI": 4,
"viewportWidths": [
1280,
390
]
},
"realModelRequests": 0,
"formalDeployment": false,
"claim": "Official specifications are known; actual gateway compatibility is not established here."
}
@@ -0,0 +1,72 @@
import fs from 'node:fs';
import path from 'node:path';
import assert from 'node:assert/strict';
import { chromium, expect } from 'playwright/test';
import { fixture, launchWorkbench } from '../tests/helpers.mjs';
import { Provider } from '../src/server/provider.mjs';
import { openWorkbenchTool } from './ui-navigation.mjs';
const evidence = path.resolve('.qa/claude-output-capacity-2026-11-06');
const disposers = [], t = { after: fn => disposers.push(fn) };
const f = fixture(t, { modernDefaults: true }), provider = new Provider(), hub = provider.modelHub(f.store);
const profile = { baseUrl: 'http://127.0.0.1:9/v1', protocol: 'anthropic-messages', requiresKey: false, maxOutputTokens: 2048 };
const official = hub.upsert({ ...profile, name: 'Owned official Claude', model: 'claude-opus-5-5' });
const gateway = hub.upsert({ ...profile, name: 'Owned gateway declaration', model: 'claude-opus-5-5' });
hub.connection(gateway.id).upstreamModel = { id: 'claude-opus-5-5', maxOutputTokens: 64000, contextLimit: 200000 };
const unknown = hub.upsert({ ...profile, name: 'Owned unknown model', model: 'owned-unknown' });
hub.save(); const before = structuredClone(hub.state); f.store.close();
let browser, host;
const errors = [], marks = [];
try {
host = await launchWorkbench(t, f.data); assert.notEqual(new URL(host.url).port, '4318');
browser = await chromium.launch({ channel: 'msedge', headless: true });
const page = await browser.newPage({ viewport: { width: 1280, height: 900 } });
page.on('pageerror', cause => errors.push(cause.message));
const open = async () => { await openWorkbenchTool(page, '打开模型中心'); await expect(page.getByRole('dialog', { name: '模型中心', exact: true })).toBeVisible(); };
const card = id => page.locator('.mc-connection[data-connection-id="' + id + '"]');
const mark = value => { marks.push(value); console.log('PASS ' + value); };
await page.goto(host.url); await open();
await expect(card(official.id)).toContainText('128,000 tokens · Anthropic 官方规格');
await expect(card(official.id)).toContainText('1,000,000 tokens · Anthropic 官方规格');
await expect(card(official.id)).toContainText('max_tokens = 128000 · Anthropic 官方同步输出规格');
await expect(card(gateway.id)).toContainText('64,000 tokens · 上游目录');
await expect(card(unknown.id)).toContainText('本地无限制 · 由上游决定');
mark('official model and gateway declarations are distinct; unknown model stays unknown');
await page.screenshot({ path: path.join(evidence, 'model-center-1280.png') });
await card(official.id).getByRole('button', { name: '编辑', exact: true }).click();
const editor = page.getByRole('form', { name: '编辑模型连接', exact: true });
await expect(editor.getByLabel('模型最大输出', { exact: true })).toContainText('128,000');
await expect(editor.getByLabel('模型最大上下文', { exact: true })).toContainText('1,000,000');
await expect(editor.getByLabel('连接容量策略')).toContainText('Messages 按协议带 max_tokens');
await editor.getByRole('button', { name: '取消', exact: true }).click();
await card(official.id).getByRole('button', { name: '推理与能力', exact: true }).click();
const native = page.getByRole('form', { name: '原生请求参数', exact: true });
await expect(native).toContainText('当前 128000(Anthropic 官方同步输出规格)');
await native.getByLabel('原生参数 JSON').fill('{"max_tokens":300000}');
await native.getByRole('button', { name: '保存原生参数', exact: true }).click();
await expect(native).not.toBeVisible();
await expect(card(official.id)).toContainText('max_tokens = 300000 · 显式原生参数');
await page.reload(); await open();
await expect(card(official.id)).toContainText('max_tokens = 300000 · 显式原生参数');
await expect(card(official.id)).toContainText('128,000 tokens · Anthropic 官方规格');
mark('capacity editor and native settings show the same source; explicit user output survives refresh without changing the official maximum');
await page.setViewportSize({ width: 390, height: 844 });
await card(official.id).scrollIntoViewIfNeeded();
await expect(card(official.id)).toContainText('128,000 tokens · Anthropic 官方规格');
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth + 1));
await page.screenshot({ path: path.join(evidence, 'model-center-390.png') });
mark('390px model source and output value remain readable without page overflow');
const after = await host.api('/model-center');
assert.equal(after.connections.find(value => value.id === official.id).maxOutputTokens, 2048);
assert.equal(after.connections.find(value => value.id === official.id).nativeParameters.max_tokens, 300000);
for (const id of [gateway.id, unknown.id]) assert.deepEqual(after.connections.find(value => value.id === id).upstreamModel, before.connections.find(value => value.id === id).upstreamModel);
assert.equal(after.attempts.length, 0); assert.deepEqual(errors, []);
mark('saved user declaration and other models are preserved; UI makes zero model requests');
fs.writeFileSync(path.join(evidence, 'ui-result.json'), JSON.stringify({ marks, errors, viewportWidths: [1280, 390], realModelRequests: 0,
appRoot: process.env.AGENT_WORKBENCH_TEST_APP_ROOT, officialDeclaredOutput: 128000, explicitOutput: 300000 }, null, 2) + '\n', { flag: 'wx' });
} catch (cause) {
fs.writeFileSync(path.join(evidence, 'ui-failure.txt'), cause.stack ?? String(cause), { flag: 'wx' }); throw cause;
} finally {
await browser?.close(); await host?.close();
for (const dispose of disposers.reverse()) await dispose();
}
+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;
}
+75
View File
@@ -0,0 +1,75 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { compatibleFixture } from './helpers.mjs';
import { Provider } from '../src/server/provider.mjs';
import * as capacity from '../src/shared/contracts/model-capacity.mjs';
import { completionBody, requestVariants } from '../src/shared/contracts/model-request.mjs';
const config = { mode: 'compatible', executionMode: 'unrestricted', capacityMode: 'passthrough',
protocol: 'anthropic-messages', model: 'claude-opus-5-5', contextLimit: 16000, maxOutputTokens: 2048 };
const input = [{ role: 'user', content: 'OWNED START ' + 'original '.repeat(12000) + ' ORIGINAL END' }];
test('published exact Claude model IDs use the official synchronous maximum without clipping original input or changing settings', () => {
for (const model of ['claude-fable-5-1', 'claude-opus-5-5', 'claude-sonnet-5-5', 'claude-haiku-5-5']) {
const value = { ...config, model }, before = structuredClone(value);
assert.equal(completionBody(value, input, []).max_tokens, 128000);
assert.equal(capacity.messagesOutputSetting(value).source, 'official_model_spec');
assert.equal(completionBody(value, input, []).messages[0].content[0].text, input[0].content);
assert.deepEqual(value, before);
}
});
test('official declarations fill only missing catalog fields and never override explicit native output or a matching gateway maximum', () => {
const value = { ...config, upstreamModel: { id: config.model, maxOutputTokens: 96000 } };
assert.equal(capacity.modelCapacityDeclaration(value, 'contextLimit').value, 1000000);
assert.equal(capacity.modelCapacityDeclaration(value, 'maxOutputTokens').source, 'upstream_catalog');
assert.equal(completionBody(value, input, []).max_tokens, 96000);
assert.equal(completionBody({ ...value, nativeParameters: { max_tokens: 300000 } }, input, []).max_tokens, 300000);
assert.equal(capacity.messagesOutputSetting({ ...value, nativeParameters: { max_tokens: 0 } }).value, 0);
assert.equal(capacity.modelCapacityDeclaration({ ...value, upstreamModel: { ...value.upstreamModel, id: 'different' } }, 'maxOutputTokens').value, 128000);
});
test('unpublished names are not matched by family, suffix, casing or branding; optional Chat and Responses output remains absent', () => {
for (const model of ['unknown-model', 'claude-opus-5-5-custom', 'claude-opus-99-1', 'CLAUDE-OPUS-5-5']) {
const value = { ...config, model, brand: 'Anthropic' };
assert.equal(capacity.modelCapacityDeclaration(value, 'maxOutputTokens'), null);
assert.equal(capacity.messagesOutputSetting(value).source, 'connection_declaration');
assert.equal(completionBody(value, input, []).max_tokens, 2048);
}
for (const protocol of ['chat-completions', 'responses']) {
const body = completionBody({ ...config, protocol }, input, []);
for (const field of ['max_tokens', 'max_completion_tokens', 'max_output_tokens']) assert.equal(Object.hasOwn(body, field), false);
}
});
test('each prepared route uses its own model capacity and explicit native choice', () => {
const members = [
{ id: 'official', model: config.model, protocol: 'anthropic-messages', maxOutputTokens: 2048 },
{ id: 'native', model: 'claude-sonnet-5-5', protocol: 'anthropic-messages', nativeParameters: { max_tokens: 320000 }, maxOutputTokens: 2048 },
{ id: 'unknown', model: 'owned-other', protocol: 'anthropic-messages', maxOutputTokens: 65536 },
{ id: 'chat', model: config.model, protocol: 'chat-completions', maxOutputTokens: 2048 },
];
const variants = requestVariants(completionBody({ ...config, modelRouting: { members } }, input, []));
assert.deepEqual(variants.map(body => body.max_tokens), [128000, 320000, 65536, undefined]);
});
test('actual owned Messages HTTP uses official max_tokens, retains upstream refusal and consumption, and never retries', async t => {
let failure = false;
const upstream = await compatibleFixture(t, () => failure
? { status: 400, body: { error: { type: 'upstream_error', message: 'owned gateway rejected this maximum' }, type: 'error' } }
: { body: { id: 'msg_owned', type: 'message', role: 'assistant', model: config.model, stop_reason: 'end_turn',
content: [{ type: 'text', text: 'Owned response' }], usage: { input_tokens: 10, output_tokens: 5 } } });
const provider = new Provider(), events = []; t.after(() => provider.abortRequests());
const actual = { ...config, baseUrl: upstream.baseUrl };
const result = await provider.complete(actual, input, null, undefined, event => events.push(event), null, []);
assert.equal(result.message.content, 'Owned response'); assert.equal(upstream.requests[0].input.max_tokens, 128000);
assert.equal(upstream.requests[0].input.messages[0].content[0].text, input[0].content);
assert.equal(events.find(event => event.consumption).consumption.usage.total_tokens, 15);
failure = true;
await assert.rejects(provider.complete(actual, input, null, undefined, undefined, null, []), cause => {
assert.equal(cause.diagnostic.httpStatus, 400); assert.equal(cause.diagnostic.origin, 'upstream');
assert.equal(cause.diagnostic.retryDecision, 'passthrough');
assert.match(cause.diagnostic.upstream.rawPreview, /owned gateway rejected this maximum/); return true;
});
assert.equal(upstream.requests.length, 2); assert.equal(actual.maxOutputTokens, 2048);
});