diff --git a/docs/M2-OFFICIAL-REGISTRY-PLAN.md b/docs/M2-OFFICIAL-REGISTRY-PLAN.md index c2366d94..4c761b73 100644 --- a/docs/M2-OFFICIAL-REGISTRY-PLAN.md +++ b/docs/M2-OFFICIAL-REGISTRY-PLAN.md @@ -4,9 +4,9 @@ 1. [complete] 17份官方来源/813289字节及双方SHA固定于[来源清单](../tests/fixtures/official-model-registry/SOURCE.json),完整捕获留自有QA根。6旧源码/4配置和目录基线显示nextPageToken与原字段遗漏;精确协议/型号/版本/条件已核对。首次夹具脚本把M1清单路径误当basename,原失败保持,第二独立脚本按实际路径验封通过。官方Anthropic示例使用2026-10-21,与当前固定2023-06-01的有效性不能混称已验证,I14另核对实际请求版本。 2. [complete] 纯注册表26协议记录/13精确ID及17逐字段来源,校验供应商来源/合法JSON/能力范围/重复,记录容量/推理/工具/媒体/缓存/结构化/弃用和条件;兼容覆盖与旧声明来源不猜,手选透传不变。首source-1为67/68,路由来源误映射已修;source-2为71/71、最后用户声明来源补强source-3为31/31,types-1/2/3与来源字节CLI通过。截断诊断只说明实际发送字段,DeepSeek可选/显式输出与注册表source-4为34/34;核心阶段限定提交。 -3. [in_progress] 目录完整脱敏item及原表示SHA、pageToken/after_id分页、空中间页和冲突已接入;新规格快照冻结、刷新保留用户字段。推理/覆盖编辑不改变既有凭据身份时保留原密文绑定,不解密重存;更换地址/型号/鉴权/Key仍失效。现有Orven规格来源/冲突/兼容编辑已实现、静态类型通过,实际两端验收待下一阶段。 -4. [pending] 固定官方来源/条件矩阵、多页/未知/退役/冲突/旧配置/参数/真实本机 wire 和恢复;独立冻结构建与网页/实际 Electron 宽窄屏核心路径,检查源码/编译/原件身份。首失败完整保留,不为通过降低检查。 -5. [pending] 回顾、限定本地提交与既有 GitAtlas 普通增量推送,更新准确接续。下一缓存块/状态/指纹/请求版本与 CI,再 M3 统一发行。 +3. [complete] 核心ba4b4491完成目录完整脱敏item/原表示SHA、pageToken/after_id分页、空中间页和冲突;新规格快照冻结、刷新保留用户字段。推理/覆盖编辑不改变既有凭据身份时保留原密文绑定,不解密重存;更换地址/型号/鉴权/Key仍失效。现有Orven规格来源/冲突/兼容编辑及DeepSeek显式输出仍可选的显示补强已完成,最终两端实际通过。 +4. [complete] 首候选独立62/62;最后仅UI及验证器补强,其余856输入和全部core/server/shared源码相同。build-6/candidate-app-6最终858输入/291产品源码/29编译及74runtime逐SHA通过;最终web-6与electron-3各6组/7图/三配色/1280及390、各2目录GET和3本机模型POST、重启原metadata/cipher/存储JSON快照exact。前三网页验收器与第四JSON表示失败、首隐藏窗口截图超时原件保留,产品锁/新账本不绕过。 +5. [in_progress] 回顾、限定本地提交与既有 GitAtlas 普通增量推送,封存准确原件清单、更新接续。下一缓存块/状态/指纹/请求版本与 CI,再 M3 统一发行。 官方已确认的差异包括 GPT-6.1 Sol/Terra 工具要求 Responses、GPT-6 Sol/Luna 在 Chat 中要求 reasoning_effort=none。它们属于有来源的型号/协议条件,不代表代理拒发、真实模型通过或本地额度。兼容线路可显式声明差异,保留双方来源和实际错误。 diff --git a/progress.md b/progress.md index 128325fe..bfb9cd0f 100644 --- a/progress.md +++ b/progress.md @@ -1,5 +1,17 @@ # 统一执行进度 +M2 I15最终build-6与candidate-app-6完成:858输入/291产品源码/29编译/74runtime逐SHA一致,较首冻结856原件相同,仅NativeParameters显示和验证器补强;所有core/server/shared输入保持。最终网页web-6和实际Electron electron-3各6组/7图/各3本机POST与2目录GET通过,三配色文字对比度12.29以上、1280/390实际画面已看,原metadata/密文/存储JSON快照exact。首候选62/62适用未变后端,未重复无关测试。历史失败不改;正在UI限定提交/QA封存与既有GitAtlas普通增量推送,正式/真实模型/Key/历史unknown和M3待办不变。 + +M2 I15网页第五轮与实际Electron第二轮各6组/7图完整通过(含原metadata/cipher/存储JSON快照exact),原失败保持。后续复核发现DeepSeek显式max_tokens时编辑器仍沿source标签误称必填;已按精确规格request.maxTokensRequired显示可选,不改发送体,并纠正兼容覆盖的必填字段用途说明。新增实际表单显式值预览核对;该UI补强需新候选编译和两端相关复验,原candidate-app-1不覆盖。62/62后端证据继续适用,不重复无改动检查。 + +M2 I15网页第四轮恢复核对原cipher和原metadata通过,最后snapshot对比因内存undefined字段与实际JSON序列化表示混用失败;原web-75b5cbfe保持。验收器现从真实写入的JSON固定原快照,同时逐字核对snapshot原metadata,并保存自有retention-before/after原件;不会删除字段以改变产品运行快照。其余产品输入无修改,下一最终网页与Electron,62/62独立相关不重复运行。 + +M2 I15网页第三轮五组通过后原恢复断言又失败:meta(modelAttempts)按I13合同返回原1+新3的完整投影,不能冒称只返回原metadata。复核改为SQL原value逐字核对,同时验证完整4条与原unknown逐字段相同;保留web-9acc3904失败,不删除新账本。Electron首轮因隐藏窗口的Playwright截图超时,原electron-f89ba83f保持,已按随包Electron类型说明改为native capturePage/stayHidden并检查非空及窗口仍隐藏;不改产品或增加截图超时。第四份验证输入另冻,产品输入/编译继续原样。 + +M2 I15独立frozen-1为62/62、固定来源CLI再次通过。网页第二轮前五组仍通过,但验收器在新宿主持有数据锁时又new Store,被正确拒绝;原web-a924f68a保持。已将原metadata/cipher/snapshot核对顺序改为完成恢复API后正常关闭自有宿主,再只读存储;不绕过产品锁。实际Electron首轮用原冻结验收器,结果另记,下一冻结第三份验证输入。产品/29编译仍原candidate-app-1,0真实模型/Key/正式操作。 + +M2 I15核心ba4b4491已提交,build-1独立858输入/29编译及74真实runtime副本构建通过。网页首轮已通过五组操作、七截图及三配色实测对比度,最后恢复核对因验收器漏import Store失败;原web-dd0b94a4结果/DOM/截图/本机请求保持。只补验收器import,产品输入不变;另冻build-2的验证输入,复用原candidate-app-1编译,独立复验恢复与实际Electron。不是网页整轮通过,不为错误改产品或伪造原结果。 + M2 I15核心最后专项source-4为34/34:精确注册表、目录/密文恢复、DeepSeek可选及显式输出截断诊断、原响应和reported用量/单物理尝试通过。此前source-1原67/68保留。进入核心限定提交与build-1独立冻结;网页/Electron实际路径仍待,I14实际版本及M3迁移回退未因此完成。 M2 I15后端复核:source-2为71/71,最后用户声明来源补强source-3为31/31,types-1/2/3和17来源813289字节CLI已通过。接续修正DeepSeek HTTP Messages可选max_tokens仍被截断诊断泛称必填的文案,保留原上游响应/用量和单次尝试;专项复验后先提交核心。UI未运行,不称I15完成。本轮一处猜错测试文件路径和过量输出记录为调查失误,原产品失败不改。正式/真实模型/Key均未操作,继续独立冻结和实际两端验收。 diff --git a/scripts/verify-official-model-registry-ui.mjs b/scripts/verify-official-model-registry-ui.mjs new file mode 100644 index 00000000..e6e97491 --- /dev/null +++ b/scripts/verify-official-model-registry-ui.mjs @@ -0,0 +1,244 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import http from 'node:http'; +import net from 'node:net'; +import assert from 'node:assert/strict'; +import { randomUUID, createHash } from 'node:crypto'; +import { chromium, _electron } from 'playwright'; +import { expect } from 'playwright/test'; +import { fixture, launchWorkbench, until } from '../tests/helpers.mjs'; +import { Provider } from '../src/server/provider.mjs'; +import { Store } from '../src/server/store.mjs'; +import { HostController } from '../src/core/desktop/host-controller.mjs'; +import { desktopExecutableIdentity } from '../src/core/desktop/app-installation.mjs'; +import { projectEnvironment } from '../src/core/process-environment.mjs'; +import { catalogModel } from '../src/shared/contracts/model-catalog.mjs'; +import { modelSnapshot } from '../src/shared/contracts/execution.mjs'; +import { openWorkbenchTool } from './ui-navigation.mjs'; + +const desktop = process.argv.includes('--desktop'); +assert.ok(process.argv.slice(2).every(value => value === '--desktop')); +assert.ok(process.env.AGENT_WORKBENCH_QA_APP_ROOT, 'Use an independent candidate build'); +const appRoot = fs.realpathSync.native(process.env.AGENT_WORKBENCH_QA_APP_ROOT); +const directory = path.resolve(process.env.AGENT_WORKBENCH_QA_EVIDENCE_ROOT ?? '.qa/m2-official-registry-2026-11-07', (desktop ? 'electron-' : 'web-') + randomUUID()); +fs.mkdirSync(directory, { recursive: true }); console.log('EVIDENCE ' + directory); +const disposers = [], t = { after: fn => disposers.push(fn) }, f = fixture(t, { modernDefaults: true }); +const sha = bytes => createHash('sha256').update(bytes).digest('hex'); +const requests = [], checks = [], screenshots = [], errors = [], externalBlocked = [], contrast = []; +let listedOutput = 96000; +const raw = model => ({ id: model, context_window: 1000000, max_output_tokens: listedOutput, capabilities: { text: true, tools: true }, + vendor_extension: { preserve: ['original', { detail: 'complete upstream declaration' }], api_key: 'owned-not-exported-secret' } }); +const model = http.createServer(async (req, res) => { + const chunks = []; for await (const chunk of req) chunks.push(chunk); + const body = chunks.length ? JSON.parse(Buffer.concat(chunks)) : null; + requests.push({ method: req.method, route: req.url, body, hadCredential: !!req.headers['x-api-key'] || !!req.headers.authorization }); + res.writeHead(200, { 'Content-Type': 'application/json' }); + if (req.method === 'GET') { + res.end(JSON.stringify(req.url.includes('pageToken=') ? { data: [raw('claude-sonnet-5-5')] } : { data: [raw('claude-opus-5-5')], nextPageToken: 'owned-page-two' })); + } else if (req.url.endsWith('/messages')) { + res.end(JSON.stringify({ type: 'message', id: 'owned-msg', role: 'assistant', model: body.model, content: [{ type: 'text', text: 'OK' }], stop_reason: 'end_turn', usage: { input_tokens: 11, output_tokens: 1 } })); + } else if (req.url.endsWith('/responses')) { + res.end(JSON.stringify({ id: 'owned-resp', model: body.model, status: 'completed', output: [{ type: 'message', role: 'assistant', content: [{ type: 'output_text', text: 'OK' }] }], usage: { input_tokens: 11, output_tokens: 1 } })); + } else { + res.end(JSON.stringify({ id: 'owned-chat', model: body.model, choices: [{ message: { role: 'assistant', content: 'OK' }, finish_reason: 'stop' }], usage: { prompt_tokens: 11, completion_tokens: 1, total_tokens: 12 } })); + } +}); +await new Promise(resolve => model.listen(0, '127.0.0.1', resolve)); +const baseUrl = 'http://127.0.0.1:' + model.address().port + '/v1'; +const legacyAttempt = { id: 'owned-old-request', status: 'unknown', model: 'owned-old', usage: null, legacy_extension: { preserve: ['failed network', 'repeated reads', 'unknown usage'] } }; +f.store.storage.setMeta('modelAttempts', [legacyAttempt]); +const originalMetadata = f.store.storage.database.prepare("SELECT value FROM metadata WHERE key='modelAttempts'").get().value; +const provider = Object.assign(Object.create(Provider.prototype), { apiKey: '' }), hub = provider.modelHub(f.store); +const format = { type: 'json_schema', schema: { type: 'object', properties: { result: { type: 'string' } } } }; +const claude = hub.upsert({ name: '自有验证 · Claude 规格', model: 'claude-opus-5-5', protocol: 'anthropic-messages', baseUrl, apiKey: 'owned-ui-key-only', persistKey: true, + nativeParameters: { thinking: { type: 'adaptive', display: 'summarized' }, output_config: { effort: 'high', format }, metadata: { preserve: ['owned'] } }, parameterProfile: 'auto' }); +const declaration = catalogModel(raw(claude.model)); declaration.rawSha256 = sha(JSON.stringify(declaration.rawItem)); declaration.rawBytes = Buffer.byteLength(JSON.stringify(declaration.rawItem)); +hub.connection(claude.id).upstreamModel = { ...declaration, endpoint: baseUrl, fetchedAt: '2026-11-07T00:00:00.000Z' }; +const deepseek = hub.upsert({ name: '自有验证 · DeepSeek', model: 'deepseek-flash', protocol: 'anthropic-messages', baseUrl, requiresKey: false, + nativeParameters: { thinking: { type: 'enabled' }, output_config: { effort: 'max', opaque: { keep: true } } }, parameterProfile: 'auto' }); +const responses = hub.upsert({ name: '自有验证 · Responses', model: 'gpt-6.1-sol', protocol: 'responses', baseUrl, requiresKey: false, + nativeParameters: { reasoning: { effort: 'high', summary: 'auto' }, metadata: { stable: 'owned' } }, parameterProfile: 'auto' }); +const chat = hub.upsert({ name: '自有验证 · Chat', model: 'gpt-6-sol', protocol: 'chat-completions', baseUrl, requiresKey: false, + nativeParameters: { reasoning_effort: 'none', thinking: { type: 'enabled', opaque: ['unchanged'] } }, parameterProfile: 'auto' }); +const unknown = hub.upsert({ name: '自有验证 · 未公布型号', model: 'claude-opus-5-5-custom', protocol: 'anthropic-messages', baseUrl, requiresKey: false, + nativeParameters: { thinking: { type: 'owned-custom-mode', display: 'summarized' }, output_config: { effort: 'owned-custom-effort' } }, parameterProfile: 'auto' }); +hub.select({ type: 'connection', id: claude.id }); +const originalCipher = structuredClone(hub.vault().state), originalNative = structuredClone(claude.nativeParameters), originalSnapshot = JSON.parse(JSON.stringify(modelSnapshot(hub.prepare(f.store.config)))); +f.store.storage.setMeta('ownedModelSnapshot', originalSnapshot); +const originalSnapshotMetadata = f.store.storage.database.prepare("SELECT value FROM metadata WHERE key='ownedModelSnapshot'").get().value; +fs.writeFileSync(path.join(directory, 'retention-before.json'), JSON.stringify({ modelAttempts: originalMetadata, modelCredentials: originalCipher, modelSnapshot: originalSnapshotMetadata }, null, 2)); +hub.save(); f.store.close(); +let host, browser, application, controller, page, window, result, desktopStdout = '', desktopStderr = ''; +const form = () => page.getByRole('form', { name: '原生请求参数', exact: true }); +const center = () => page.getByRole('dialog', { name: '模型中心', exact: true }); +const card = id => page.locator('.mc-connection[data-connection-id="' + id + '"]'); +const field = label => form().getByLabel(label, { exact: true }); +const parameters = async () => JSON.parse(await field('原生参数 JSON').inputValue()); +const current = async id => (await host.api('/model-center')).connections.find(value => value.id === id); +const mark = name => { checks.push(name); console.log('PASS ' + name); }; +async function resize(width, height = 960) { + if (window) { await window.evaluate((win, size) => win.setContentSize(size.width, size.height), { width, height }); await until(() => page.evaluate(w => innerWidth === w, width)); } + else await page.setViewportSize({ width, height }); +} +async function open() { await openWorkbenchTool(page, '打开模型中心'); await expect(center()).toBeVisible(); } +async function edit(id) { if (!await center().count()) await open(); await card(id).getByRole('button', { name: '推理与能力', exact: true }).click(); await expect(form()).toBeVisible(); } +async function save(id, expected) { await form().getByRole('button', { name: '保存原生参数', exact: true }).click(); await expect(form()).toHaveCount(0); assert.deepEqual((await current(id)).nativeParameters, expected); } +async function capture(file) { + if (!window) { await page.screenshot({ path: file, scale: 'css' }); return { method: 'playwright-page' }; } + const captured = await window.evaluate(async win => { + const [width, height] = win.getContentSize(), picture = await win.capturePage({ x: 0, y: 0, width, height }, { stayHidden: true, stayAwake: true }); + return { png: picture.toPNG().toString('base64'), empty: picture.isEmpty(), size: picture.getSize(), hidden: !win.isVisible() }; + }); + assert.equal(captured.empty, false); assert.equal(captured.hidden, true); + fs.writeFileSync(file, Buffer.from(captured.png, 'base64')); + return { method: 'electron-native-stay-hidden', size: captured.size }; +} +async function shot(name, anchor) { + if (anchor) await anchor.scrollIntoViewIfNeeded(); + assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth + 1), 'No page overflow'); + const file = path.join(directory, name + '.png'), captured = await capture(file); + screenshots.push({ file: path.basename(file), sha256: sha(fs.readFileSync(file)), ...captured }); + fs.writeFileSync(path.join(directory, name + '.txt'), await center().innerText(), { flag: 'wx' }); +} +async function sampleContrast(locator, label) { + const sampled = await locator.evaluate(element => { + const style = getComputedStyle(element); let ancestor = element, background; + while (ancestor) { const color = getComputedStyle(ancestor).backgroundColor; if (color !== 'rgba(0, 0, 0, 0)' && color !== 'transparent') { background = color; break; } ancestor = ancestor.parentElement; } + return { color: style.color, background, fontSize: style.fontSize }; + }); + const luminance = value => value.match(/[\d.]+/g).slice(0, 3).map(Number).map(c => c / 255).map(c => c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4).reduce((sum, c, i) => sum + c * [0.2126, 0.7152, 0.0722][i], 0); + const a = luminance(sampled.color), b = luminance(sampled.background), ratio = (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05); + contrast.push({ label, ...sampled, ratio }); assert.ok(ratio >= 4.5, label + ' contrast ' + ratio); +} +try { + if (desktop) { + const socket = net.createServer(); await new Promise(resolve => socket.listen(0, '127.0.0.1', resolve)); const port = socket.address().port; await new Promise(resolve => socket.close(resolve)); + assert.notEqual(port, 4318); controller = new HostController({ appRoot, dataRoot: f.data, port, nodePath: process.execPath, timeoutMs: 60000 }); await controller.start(); + host = { url: controller.url, api: (route, input) => controller.api(route, input === undefined ? {} : { method: 'POST', input }) }; + application = await _electron.launch({ executablePath: desktopExecutableIdentity(appRoot).path, + args: [path.join(appRoot, 'dist-desktop/main.cjs'), '--app-root', appRoot, '--data-root', f.data, '--node', process.execPath, '--port', String(port), '--hidden-window'], cwd: appRoot, env: projectEnvironment(), timeout: 60000 }); + application.process().stdout?.on('data', bytes => { desktopStdout += bytes.toString('utf8'); }); application.process().stderr?.on('data', bytes => { desktopStderr += bytes.toString('utf8'); }); + page = await application.firstWindow(); window = await application.browserWindow(page); + } else { + host = await launchWorkbench(t, f.data, {}, { appRoot }); assert.notEqual(new URL(host.url).port, '4318'); + browser = await chromium.launch({ channel: 'msedge', headless: true }); page = await browser.newPage(); + } + page.on('pageerror', cause => errors.push(cause.message)); + await page.route('**/*', route => { + const url = new URL(route.request().url()); + if (url.origin === new URL(host.url).origin || ['data:', 'blob:'].includes(url.protocol)) return route.continue(); + externalBlocked.push(url.origin); return route.abort(); + }); + await resize(1280); await page.goto(host.url); await page.waitForLoadState('networkidle'); await open(); + await expect(card(claude.id)).toContainText('96,000 tokens · 上游目录'); await expect(card(responses.id)).toContainText('1,050,000 tokens · OpenAI 官方规格'); + await expect(card(deepseek.id)).toContainText('393,216 tokens · DeepSeek 官方规格'); await expect(card(deepseek.id)).toContainText('默认省略 max_tokens'); + await expect(card(unknown.id)).toContainText('本地无限制 · 由上游决定'); + await edit(claude.id); await form().locator('.model-specification-details > summary').click(); + const specification = form().locator('.model-specification-details'), row = key => specification.locator('[data-spec-field="' + key + '"]'); + await expect(row('maxOutputTokens')).toContainText('96,000'); await expect(row('maxOutputTokens')).toContainText('上游目录声明'); + await row('maxOutputTokens').locator('.model-spec-alternatives > summary').click(); await expect(row('maxOutputTokens')).toContainText('128,000'); + await expect(specification).toContainText('规格 API 版本 2026-10-21'); await expect(specification).toContainText('实际发送版本以请求账本为准'); + await specification.locator('.model-spec-raw > summary').click(); await expect(specification.locator('.model-spec-raw pre')).toContainText('complete upstream declaration'); + await expect(specification.locator('.model-spec-raw pre')).toContainText('[redacted]'); assert.equal((await specification.innerText()).includes('owned-not-exported-secret'), false); + await shot('sources-1280', row('maxOutputTokens')); + mark('Known capacities, exact official versions, conflicts and full redacted catalog origin are visible; unknown model stays unknown'); + + await form().locator('.mc-model-overrides > summary').click(); await field('兼容规格 JSON').fill('{"maxOutputTokens":0}'); + await form().getByRole('button', { name: '保存原生参数', exact: true }).click(); await expect(form().getByRole('alert')).toContainText('正安全整数'); + assert.equal((await current(claude.id)).revision, claude.revision); assert.equal(await field('兼容规格 JSON').inputValue(), '{"maxOutputTokens":0}'); + const overrides = { maxOutputTokens: 70000, efforts: ['low', 'custom'], modes: ['adaptive'], note: '自有代理显式兼容声明' }; + await field('兼容规格 JSON').fill(JSON.stringify(overrides, null, 2)); await field('推理强度').selectOption('custom'); + const expectedClaude = { ...originalNative, output_config: { ...originalNative.output_config, effort: 'custom' } }; + assert.deepEqual(await parameters(), expectedClaude); await expect(row('maxOutputTokens')).toContainText('70,000'); + await shot('override-1280', field('兼容规格 JSON')); await save(claude.id, expectedClaude); + await page.reload(); await open(); await edit(claude.id); assert.deepEqual(JSON.parse(await field('兼容规格 JSON').inputValue()), overrides); assert.deepEqual(await parameters(), expectedClaude); + await form().getByRole('button', { name: '取消', exact: true }).click(); + mark('Invalid override saves nothing; valid explicit values persist with nested native siblings and current source conflicts'); + + listedOutput = 64000; await card(claude.id).getByRole('button', { name: '获取同源模型', exact: true }).click(); + const catalogSection = center().locator('section[aria-label="上游模型目录"]'); + await catalogSection.getByRole('button', { name: '获取上游模型', exact: true }).click(); await expect(catalogSection.getByLabel('选择模型 claude-sonnet-5-5', { exact: true })).toBeVisible(); + await catalogSection.getByLabel('选择模型 claude-opus-5-5', { exact: true }).check(); await catalogSection.getByLabel('选择模型 claude-sonnet-5-5', { exact: true }).check(); + await catalogSection.getByRole('button', { name: '保存所选 2 个模型', exact: true }).click(); await expect(catalogSection).toContainText('已新增 1 个模型,沿用 1 个已有模型'); + const refreshed = await current(claude.id); assert.equal(refreshed.upstreamModel.maxOutputTokens, 64000); assert.deepEqual(refreshed.modelOverrides, overrides); assert.deepEqual(refreshed.nativeParameters, expectedClaude); + assert.equal(refreshed.revision, claude.revision + 1); assert.equal(requests.filter(value => value.method === 'GET').length, 2); + assert.equal(requests.filter(value => value.method === 'POST').length, 0); + await edit(claude.id); await form().locator('.model-specification-details > summary').click(); + await shot('refreshed-source-1280', form().locator('[data-spec-field="maxOutputTokens"]')); + await form().getByRole('button', { name: '取消', exact: true }).click(); + mark('Real UI catalog pageToken fetch and selection refresh metadata, retain explicit settings, share one credential and make zero model requests'); + + await edit(deepseek.id); await expect(field('推理模式')).toHaveValue('enabled'); await expect(form().getByLabel('推理预算 tokens')).toHaveCount(0); + await expect(form()).toContainText('允许省略 max_tokens'); + const originalDeepSeekParameters = await parameters(); + await field('原生参数 JSON').fill(JSON.stringify({ ...originalDeepSeekParameters, max_tokens: 65536 })); + await expect(form()).toContainText('允许省略 max_tokens'); await expect(form()).toContainText('当前 max_tokens=65536'); + assert.equal((await form().innerText()).includes('Messages 协议需带 max_tokens'), false); + await field('原生参数 JSON').fill(JSON.stringify(originalDeepSeekParameters)); + await field('推理模式').selectOption('adaptive'); + const expectedDeepSeek = { ...deepseek.nativeParameters, thinking: { type: 'adaptive' } }; + assert.deepEqual(await parameters(), expectedDeepSeek); await save(deepseek.id, expectedDeepSeek); + await host.api('/model-center/probe', { id: deepseek.id, scope: 'text' }); + let sent = requests.filter(value => value.method === 'POST').at(-1).body; + assert.equal(Object.hasOwn(sent, 'max_tokens'), false); assert.deepEqual(sent.output_config, expectedDeepSeek.output_config); assert.deepEqual(sent.thinking, expectedDeepSeek.thinking); + await edit(responses.id); assert.equal(await field('推理模式').locator('option[value="disabled"]').count(), 0); + await field('推理强度').selectOption('max'); let expected = { ...responses.nativeParameters, reasoning: { effort: 'max', summary: 'auto' } }; + assert.deepEqual(await parameters(), expected); await save(responses.id, expected); await host.api('/model-center/probe', { id: responses.id, scope: 'text' }); + sent = requests.filter(value => value.method === 'POST').at(-1).body; assert.deepEqual(sent.reasoning, expected.reasoning); assert.equal(Object.hasOwn(sent, 'max_output_tokens'), false); + await edit(chat.id); await expect(field('推理模式')).toHaveValue('disabled'); await field('推理模式').selectOption('enabled'); await field('推理强度').selectOption('high'); + expected = { ...chat.nativeParameters, reasoning_effort: 'high' }; assert.deepEqual(await parameters(), expected); await save(chat.id, expected); + await host.api('/model-center/probe', { id: chat.id, scope: 'text' }); sent = requests.filter(value => value.method === 'POST').at(-1).body; + assert.equal(sent.reasoning_effort, 'high'); assert.deepEqual(sent.thinking, chat.nativeParameters.thinking); assert.equal(Object.hasOwn(sent, 'max_tokens'), false); + mark('Exact provider reasoning switches preserve native objects on three actual loopback wires; optional limits and DeepSeek budgets are omitted'); + + await edit(unknown.id); await expect(form()).toContainText('未取得精确型号能力'); await expect(field('推理模式')).toHaveValue('owned-custom-mode'); + await expect(field('推理强度')).toHaveValue('owned-custom-effort'); await resize(390, 844); await shot('unknown-390', field('推理模式')); + assert.deepEqual(await parameters(), unknown.nativeParameters); await form().getByRole('button', { name: '取消', exact: true }).click(); + for (const [palette, name] of [['green', '深青绿'], ['blue', '雾蓝'], ['purple', '鸢尾紫']]) { + await page.keyboard.press('Escape'); await page.getByRole('button', { name: '外观', exact: true }).click(); + await page.getByRole('dialog', { name: '外观', exact: true }).getByRole('radio', { name, exact: true }).check(); await page.keyboard.press('Escape'); + await open(); await edit(claude.id); await form().locator('.model-specification-details > summary').click(); + const heading = form().locator('.model-specification-details > summary'); + await sampleContrast(heading, palette + ' specification summary'); await sampleContrast(form().locator('[data-spec-field="maxOutputTokens"] > th'), palette + ' specification field'); + await sampleContrast(form().locator('.model-specification-details a').first(), palette + ' specification source link'); + await shot('source-' + palette + '-390', form().locator('[data-spec-field="maxOutputTokens"]')); await form().getByRole('button', { name: '取消', exact: true }).click(); + } + mark('390px custom values and source rows remain readable across three actual appearance selections with measured text contrast'); + + const finalCenter = await host.api('/model-center'); assert.equal(finalCenter.attemptCount, 4); assert.equal(requests.filter(value => value.method === 'POST').length, 3); + assert.deepEqual(finalCenter.attempts.find(value => value.id === legacyAttempt.id), legacyAttempt); + assert.deepEqual(errors, []); assert.deepEqual(externalBlocked, []); + fs.writeFileSync(path.join(directory, 'center-final.json'), JSON.stringify(finalCenter, null, 2)); + if (application) { await application.close(); application = null; } if (browser) { await browser.close(); browser = null; } + if (controller) { await controller.stop(); controller = null; } await host.close?.(); host = null; + host = await launchWorkbench(t, f.data, {}, { appRoot }); + const restored = await host.api('/model-center'), restoredClaude = restored.connections.find(value => value.id === claude.id); + assert.equal(restoredClaude.hasKey, true); assert.equal(restoredClaude.savedCredential.status, 'saved'); assert.deepEqual(restoredClaude.nativeParameters, expectedClaude); assert.deepEqual(restoredClaude.modelOverrides, overrides); + assert.equal(requests.filter(value => value.method === 'POST').length, 3); assert.equal(restored.attemptCount, 4); + const restoredHostUrl = host.url; + await host.close(); host = null; + const storage = new Store(f.data); try { + const retainedCipher = storage.storage.meta('modelCredentials'), retainedMetadata = storage.storage.database.prepare("SELECT value FROM metadata WHERE key='modelAttempts'").get().value; + const retainedSnapshotMetadata = storage.storage.database.prepare("SELECT value FROM metadata WHERE key='ownedModelSnapshot'").get().value; + fs.writeFileSync(path.join(directory, 'retention-after.json'), JSON.stringify({ modelAttempts: retainedMetadata, modelCredentials: retainedCipher, modelSnapshot: retainedSnapshotMetadata }, null, 2)); + assert.deepEqual(retainedCipher, originalCipher); assert.equal(retainedMetadata, originalMetadata); assert.equal(retainedSnapshotMetadata, originalSnapshotMetadata); + const retained = storage.storage.meta('modelAttempts'); assert.equal(retained.length, 4); assert.deepEqual(retained.find(value => value.id === legacyAttempt.id), legacyAttempt); + assert.deepEqual(storage.storage.meta('ownedModelSnapshot'), originalSnapshot); + } finally { storage.close(); } + mark('Independent packaged host restart restores existing synthetic cipher and new options; original unknown ledger and frozen snapshot remain exact with no replay'); + result = { success: true, appRoot, actualElectron: desktop, checks, screenshots, contrast, errors, externalBlocked, hostUrl: restoredHostUrl, + syntheticRequests: 3, catalogRequests: 2, originalUnknownAttempts: 1, originalMetadataExact: true, originalMetadataSha256: sha(originalMetadata), originalCipherExact: true, originalSnapshotExact: true, originalSnapshotSha256: sha(originalSnapshotMetadata), + realModelRequests: 0, realCredentialsRead: 0, productionWrites: 0, viewportWidths: [1280, 390] }; +} catch (cause) { + if (page) { await capture(path.join(directory, 'failure.png')).catch(() => {}); fs.writeFileSync(path.join(directory, 'failure.txt'), await page.locator('body').innerText().catch(() => '')); } + result = { success: false, appRoot, actualElectron: desktop, checks, screenshots, contrast, errors, externalBlocked, error: cause.stack, syntheticRequests: requests.filter(value => value.method === 'POST').length, catalogRequests: requests.filter(value => value.method === 'GET').length, realModelRequests: 0 }; +} finally { + fs.writeFileSync(path.join(directory, 'requests.json'), JSON.stringify(requests, null, 2)); + if (application) await application.close(); if (browser) await browser.close(); + if (controller && await controller.health()) await controller.stop(); await host?.close?.(); + await new Promise(resolve => { model.closeAllConnections(); model.close(resolve); }); + for (const dispose of disposers.reverse()) await dispose(); + if (desktop) { fs.writeFileSync(path.join(directory, 'desktop-stdout.txt'), desktopStdout); fs.writeFileSync(path.join(directory, 'desktop-stderr.txt'), desktopStderr); } + fs.writeFileSync(path.join(directory, 'result.json'), JSON.stringify(result, null, 2)); +} +console.log(JSON.stringify({ directory, ...result })); if (!result.success) process.exitCode = 1; diff --git a/src/client/ModelCatalog.tsx b/src/client/ModelCatalog.tsx index 303c5810..f3e1808d 100644 --- a/src/client/ModelCatalog.tsx +++ b/src/client/ModelCatalog.tsx @@ -3,6 +3,7 @@ import { api } from './api'; import type { CatalogPreview } from '../shared/contracts/model-catalog.mjs'; import { ModelErrorDetails } from './ModelErrorDetails'; import type { RuntimeFailure } from './types'; +import { resolveModelSpecification } from '../shared/contracts/official-model-registry.mjs'; type Source = { id: string; revision: number; name: string; protocol: string; baseUrl: string; brand: string; enabled: boolean; credentialSource?: { connectionId: string } }; const initial = { name: '', brand: '自定义', protocol: 'chat-completions', baseUrl: 'https://api.openai.com/v1', messagesAuth: 'api-key', requiresKey: true }; @@ -91,16 +92,21 @@ export function ModelCatalog({ sources, sourceId = '', busy, onSaved, onClose }:

以下为上游目录声明,尚未经过模型调用验证。{open ? '可选择上游返回的型号,目录、连接和自动池不设本地数量上限。' : `目录最多${preview.limits.catalog}项,本机最多${selectionLimit}个模型连接;单个自动池最多${poolLimit}个成员。`}

- {visible.map(value => ; })}{!visible.length &&

{preview.entries.length ? '没有匹配的型号。可更改搜索条件。' : '上游返回了空目录。可核对连接或使用手动兼容入口。'}

}
{routing === 'manual' && }
- {routing === 'auto' &&

自动适配复用模型池,按任务所需能力、连接健康和可用并发筛选,再按轮询分配;同一运行优先保持型号。未确认能力的型号不会用于需要该能力的任务。

} + {routing === 'auto' &&

自动适配复用模型池,优先选择声明适配的型号;默认开放模式在没有已知适配型号时保留未知能力后备,并记录实际选择依据。同一运行优先保持型号,上游错误按原结果保留。

}
} ; diff --git a/src/client/ModelCenter.tsx b/src/client/ModelCenter.tsx index 22b5fee3..d9de23bb 100644 --- a/src/client/ModelCenter.tsx +++ b/src/client/ModelCenter.tsx @@ -5,7 +5,7 @@ import type { Config, ModelSelection, ModelSnapshot, RuntimeFailure } from './ty import './ModelCenter.css'; import { ModelRequestLedger, type ModelAttempt } from './ModelRequestLedger'; import { ModelWaitSettings, type WaitSettings } from './ModelWaitSettings'; -import { NativeParameters } from './NativeParameters'; +import { NativeParameters, type NativeConnection } from './NativeParameters'; import { ModelErrorDetails } from './ModelErrorDetails'; import { ModelBudgetSettings } from './ModelBudgetSettings'; import { DEFAULT_MODEL_CAPACITY, messagesOutputSetting, modelCapacityDeclaration } from '../shared/contracts/model-capacity.mjs'; @@ -13,14 +13,22 @@ import { modelRequestUrl, protocolLabel } from '../shared/contracts/model-endpoi import { ModelNetworkDiagnostics } from './ModelNetworkDiagnostics'; import { ModelCatalog } from './ModelCatalog'; import type { CatalogModel } from '../shared/contracts/model-catalog.mjs'; +import type { ModelSpecConnection } from '../shared/contracts/official-model-registry.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 upstreamCapacity = (value: ModelSpecConnection, field: 'contextLimit' | 'maxOutputTokens') => { const declaration = modelCapacityDeclaration(value, field); - return declaration ? declaration.value.toLocaleString() + ' tokens · ' + (declaration.source === 'official_model_spec' ? 'Anthropic 官方规格' : '上游目录') : '本地无限制 · 由上游决定'; + return declaration ? declaration.value.toLocaleString() + ' tokens · ' + (declaration.source === 'official_model_spec' ? ({ anthropic: 'Anthropic', openai: 'OpenAI', deepseek: 'DeepSeek' }[declaration.provider ?? ''] ?? '供应商') + ' 官方规格' + : declaration.source === 'explicit_compatibility' ? '用户兼容覆盖' : '上游目录') : '本地无限制 · 由上游决定'; }; -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; +const protocolOutput = (value: ModelSpecConnection & { maxOutputTokens?: number }) => { + const output = messagesOutputSetting(value); + return output.source === 'upstream_optional' ? '默认省略 max_tokens · 官方 HTTP 可选字段' + : 'max_tokens = ' + String(output.value) + ' · ' + ({ upstream_catalog: '上游目录最大值', official_model_spec: '官方同步输出规格', explicit_native: '显式原生参数', explicit_compatibility: '用户兼容覆盖' }[output.source] ?? '连接声明,最大值未验证'); +}; + +type Connection = NativeConnection & { 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; outputTokenField?: string; streaming?: boolean; capabilityDeclarations?: Record; capabilities?: Record; 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 ImportRecord = { id: string; source: string; path: string; enabled: boolean; lastCheckedAt?: string; lastSyncedAt?: string; lastError?: string; lastResult?: { imported?: number; conflicts?: string[] } }; @@ -39,7 +47,7 @@ export function ModelCenter({ onConfig, busy, runModel }: { onConfig: (value: Co const [view, setView] = useState
(null); const [runtimeConfig, setRuntimeConfig] = useState(null); const [tab, setTab] = useState('connections'); - const [draft, setDraft] = useState; outputTokenField?: string }>(initial); + const [draft, setDraft] = useState; outputTokenField?: string }>(initial); const [editing, setEditing] = useState(false), [key, setKey] = useState(''); const [nativeTarget, setNativeTarget] = useState(null); const [catalogSource, setCatalogSource] = useState(null); @@ -123,8 +131,9 @@ export function ModelCenter({ onConfig, busy, runModel }: { onConfig: (value: Co {!connections.length && catalogSource === null && !editing &&
还没有模型连接

从上游获取可用型号,选择后即可开始开发。

}
{connections.map(value =>

{value.name}

{value.brand} · {protocolLabel(value.protocol)}{value.streaming ? ' · 流式开启' : ''}
{states[value.status]}
-
模型
{value.model || '尚未填写'}
请求地址
{previewUrl(value)}
{value.protocol === 'anthropic-messages' && <>
协议必填输出
max_tokens = {String(messagesOutputSetting(value).value)} · {messagesOutputSetting(value).source === 'upstream_catalog' ? '上游目录最大值' : messagesOutputSetting(value).source === 'official_model_spec' ? 'Anthropic 官方同步输出规格' : messagesOutputSetting(value).source === 'explicit_native' ? '显式原生参数' : '连接声明,最大值未验证'}
鉴权
{value.messagesAuth === 'bearer' ? 'Bearer' : 'x-api-key'} · anthropic-version 2023-06-01
}
凭据
{value.credentialSource ? '共用 ' + (connections.find(source => source.id === value.credentialSource!.connectionId)?.name ?? '源连接') + (value.hasKey ? ' 的上游凭据' : ';请核对源连接是否启用及凭据') : value.hasKey ? value.savedCredential?.status === 'saved' ? '已设置,可从本机加密保存加载' : '已设置,重启需重新填写' : value.requiresKey ? '尚未填写' : '此服务可不填'}
当前请求
{value.activeRequests} 在途 · 并发 {value.concurrency === 0 ? '不限' : value.concurrency}
{passthrough ? <>
模型最大上下文
{upstreamCapacity(value, 'contextLimit')}
模型最大输出
{upstreamCapacity(value, 'maxOutputTokens')}
: <>
连接容量声明
上下文 {value.contextLimit.toLocaleString()} · 输出 {value.maxOutputTokens.toLocaleString()}
}
+
模型
{value.model || '尚未填写'}
请求地址
{previewUrl(value)}
{value.protocol === 'anthropic-messages' && <>
协议输出参数
{protocolOutput(value)}
鉴权
{value.messagesAuth === 'bearer' ? 'Bearer' : 'x-api-key'} · anthropic-version 2023-06-01
}
凭据
{value.credentialSource ? '共用 ' + (connections.find(source => source.id === value.credentialSource!.connectionId)?.name ?? '源连接') + (value.hasKey ? ' 的上游凭据' : ';请核对源连接是否启用及凭据') : value.hasKey ? value.savedCredential?.status === 'saved' ? '已设置,可从本机加密保存加载' : '已设置,重启需重新填写' : value.requiresKey ? '尚未填写' : '此服务可不填'}
当前请求
{value.activeRequests} 在途 · 并发 {value.concurrency === 0 ? '不限' : value.concurrency}
{passthrough ? <>
模型最大上下文
{upstreamCapacity(value, 'contextLimit')}
模型最大输出
{upstreamCapacity(value, 'maxOutputTokens')}
: <>
连接容量声明
上下文 {value.contextLimit.toLocaleString()} · 输出 {value.maxOutputTokens.toLocaleString()}
}
{value.upstreamModel &&

型号来自上游目录,能力按目录声明与显式设置保存;可在“推理与能力”查看已接入范围。

} + {!!value.modelSpecification?.conflicts.length &&

有 {value.modelSpecification.conflicts.length} 项规格声明差异,可在“推理与能力”的“模型规格与来源”查看。原目录与显式设置分别保留。

}
{Object.entries(capabilityLabels).map(([key, title]) => {title}:{capabilityStates[value.capabilities?.[key] ?? 'unknown']})}
{value.health.reason &&

{value.health.reason}{!!value.health.cooldownUntil && value.health.cooldownUntil > Date.now() && ' · 冷却至 ' + new Date(value.health.cooldownUntil).toLocaleTimeString()}

}