From f1242ee80041070d19670bce54398e89bd7af21f Mon Sep 17 00:00:00 2001 From: Agent Workbench Dev Date: Thu, 5 Nov 2026 00:13:53 +0800 Subject: [PATCH] feat(models): pair reasoning controls with provider profiles and tool history --- docs/QA-REASONING-CONTROLS.md | 29 ++++ docs/REASONING-CONTROLS-PLAN.md | 2 + progress.md | 2 + scripts/verify-anthropic-messages-ui.mjs | 2 +- scripts/verify-model-fidelity-ui.mjs | 4 +- scripts/verify-reasoning-settings-ui.mjs | 146 ++++++++++++++++ src/client/ModelCenter.css | 1 + src/client/ModelCenter.tsx | 8 +- src/client/NativeParameters.tsx | 25 ++- src/client/ReasoningSettings.tsx | 40 +++++ src/core/models/config-import.mjs | 8 +- src/core/models/model-hub.mjs | 19 ++- src/core/models/model-stream.mjs | 9 +- src/core/models/protocols.mjs | 11 +- src/core/storage/legacy-import.mjs | 2 +- src/shared/contracts/execution.mjs | 2 + .../contracts/model-parameter-profiles.d.mts | 12 ++ .../contracts/model-parameter-profiles.mjs | 69 ++++++++ src/shared/contracts/model-request.mjs | 12 +- src/shared/contracts/native-parameters.d.mts | 3 +- src/shared/contracts/native-parameters.mjs | 17 +- tests/reasoning-settings.test.mjs | 157 ++++++++++++++++++ 22 files changed, 546 insertions(+), 34 deletions(-) create mode 100644 docs/QA-REASONING-CONTROLS.md create mode 100644 scripts/verify-reasoning-settings-ui.mjs create mode 100644 src/client/ReasoningSettings.tsx create mode 100644 src/shared/contracts/model-parameter-profiles.d.mts create mode 100644 src/shared/contracts/model-parameter-profiles.mjs create mode 100644 tests/reasoning-settings.test.mjs diff --git a/docs/QA-REASONING-CONTROLS.md b/docs/QA-REASONING-CONTROLS.md new file mode 100644 index 00000000..cc014e79 --- /dev/null +++ b/docs/QA-REASONING-CONTROLS.md @@ -0,0 +1,29 @@ +# 推理与能力配套:开发阶段验收 + +状态:源码已实现并验证,正式仍1.25.2;独立发行验收另记。本阶段真实模型请求0,未改正式连接、Provider或真实Key。来源为b74e5edc后的本地开发切片,先提交空响应修复3ab3a6e4。 + +用户要求推理可开启、选择强度,并与品牌或自定义兼容连接配套。模型中心现有入口改为“推理与能力”,新增一份共享配置档贯通自动匹配、手动覆盖、保存、导入、Run快照及实际请求。原JSON仍是同一份参数,可与控件双向编辑;其它参数、凭据引用、旧记录和池保持。导入保留推理字段、输出字段和能力声明,来源变更需重新预览,本地编辑冲突保留。 + +| 兼容格式 | 推理开关 | 强度 | 工具历史 | +| --- | --- | --- | --- | +| OpenAI Chat | reasoning_effort=none(需型号支持) | minimal/low/medium/high/xhigh/max | 既有工具调用 | +| OpenAI Responses | reasoning.effort=none(需型号支持) | minimal/low/medium/high/xhigh/max | 既有原生reasoning/encrypted items | +| Claude Messages | disabled / enabled+budget_tokens / adaptive | output_config.effort=low/medium/high/xhigh/max | 保留原thinking/signature块 | +| DeepSeek Chat | thinking.type=enabled/disabled | reasoning_effort=low/high/max | JSON/SSE的reasoning_content只回传原endpoint/model/连接/凭据修订 | +| 自定义代理 | 用户选择上述兼容格式 | 按所选格式 | 与对应协议一致 | + +格式接入不能证明具体型号或代理接受全部值。界面保留声明支持/已验证/待确认区别,并列出未接入的音视频、服务端工具和结构化输出约束。/models通常只提供型号,不会被当完整能力目录。后续能力接入继续走同一份契约与验收,不把“品牌配套”写成所有模型功能均已验证。 + +推理和答复共用原输出预算。Messages指定预算至少1024且小于实际输出上限,普通256检测不够时使用已有任务/连接输出上限的较小值,并在界面说明消费;不自动增加预算。Chat opaque历史的实际字节进入请求预算,不作为可见答复或进展评分。 + +完整但无文字/工具的Messages JSON/SSE明确protocol错误,空数组/空白/仅thinking均不当完成;忠实复现6692输入/0输出,原文SHA、用量与身份保持,0工具/重试,避免误报“检查未完成”。这项修复不能使供应商空响应变为成功。 + +## 实际验证 + +- Messages专项28/28,新增空响应JSON/SSE原文和6692/0用量核对。 +- 模型中心/参数/流式/Messages/推理相关85/85;补旧Run冻结、原连接重开及凭据引用保持后推理专项8/8。首联合夹具清理挂起和单项超时保持,修fixture清理次序后通过。 +- TypeScript/Vite/mobile/server构建通过;首缺契约声明失败保留。 +- 新推理网页6组、实际Electron6组(各9自有HTTP请求、0真实模型),1440/390px保存/刷新/默认/关闭/开启/强度/手动预算/JSON错误/保护字段/空响应反馈通过,原图实际回看。 +- 旧原生参数/上游错误网页6组、Messages网页7组通过;来源日志在.qa/reasoning-controls/,旧证据目录未写入。 + +阶段回顾:已修本地参数、状态回传与诊断缺口,尚未证明真实供应商稳定、自主Node交付、网络间歇唯一根因、重复读取收益或Purge AB/BA。Z3原空响应、DeepSeek原length、全部旧失败及预算保持,不续跑旧实验、不推送、不委派。下一独立版本冻结、归档重建/实际安装及保留状态升级。 diff --git a/docs/REASONING-CONTROLS-PLAN.md b/docs/REASONING-CONTROLS-PLAN.md index db9ef141..fc65b849 100644 --- a/docs/REASONING-CONTROLS-PLAN.md +++ b/docs/REASONING-CONTROLS-PLAN.md @@ -15,3 +15,5 @@ - 起步:读取AGENTS与两份采用计划,确认现有表单只有JSON;Chat尚不接受thinking,Messages已有thinking历史但没有output_config.effort;Chat流式/历史路径待核对。一次猜测不存在的chat-stream.mjs读取失败,无文件变化,后续用rg定位。 - 阶段一通过:Messages JSON/SSE真实本机HTTP复现空响应,原6692输入/0输出完整保留,单次protocol错误、0工具/重发。空数组、空白与仅opaque thinking拒绝,合法文字/工具保留;Messages相关28/28通过,日志.qa/reasoning-controls/messages-tests.txt。修复尚未部署。 - 官方来源:DeepSeek既有Thinking Mode原HTML保持;OpenAI Docs查阅Chat与reasoning-effort;Claude文档重定向地区不可用页,已保存原失败,随后官方SDK原始类型取得HTTP200,确认output_config.effort支持low/medium/high/xhigh/max。一次node_repl网络等待超时、几次不存在的可选路径读取错误均无产品影响,后续改curl有界及已有实际文件定位。 +- 阶段二:参数配置档、可视推理设置、导入同步、所属Chat opaque状态回传/流式聚合及原预算约束已实现。相关85/85,补充冻结/旧连接恢复后专项8/8;完整构建通过。网页与真实Electron各6组、原参数错误UI6组/Messages UI7组通过;1440/390原图已回看。新控件未读取Key,保存本身不发请求,HTTP夹具均自有。 +- 首失败保留:首构建缺新共享契约声明,补d.mts后通过;首联合测试在新增重开SQLite夹具清理时挂起(reopened用t.after,夹具先删目录),有界单项诊断超时与所属测试进程终止保留。改用fixture.onCleanup先关数据库,不改产品断言/期限;随后专项/相关全部通过。一次对整个.qa的递归定位过慢,停止所属rg,改为已有发行目录的有界定位。 diff --git a/progress.md b/progress.md index ea1cb384..73cd407a 100644 --- a/progress.md +++ b/progress.md @@ -2,6 +2,8 @@ ## 推理控制与空响应修复 +- 配置档/可视推理/导入和Run冻结/Chat原生状态回传实现;85/85相关+最终8/8专项,构建通过。网页/实际Electron各6组及旧参数6组/Messages7组通过,1440/390原图回看。首构建声明缺失、重开DB夹具清理超时和所属进程终止保留,修清理顺序后通过。正式仍1.25.2,待独立发行。见docs/QA-REASONING-CONTROLS.md。 + - 阶段一:Messages空响应诊断与JSON/SSE原6692/0用量回归28/28通过;用户补充品牌/自定义兼容的整套能力同步,纳入版本化参数配置档/导入/请求/界面与能力状态说明。正式尚未变更,真实请求0。 - b74e5edc干净接续。用户明确补充推理可开启/选择强度,扩展原disabled单项范围;沿用product-ui-ux/frontend-design/planning-with-files,查官方参数和工具历史。一次不存在的chat-stream.mjs读取失败已记计划,后续rg定位。正式仍1.25.2,本阶段不发真实模型请求。 diff --git a/scripts/verify-anthropic-messages-ui.mjs b/scripts/verify-anthropic-messages-ui.mjs index 547ba25c..2067acef 100644 --- a/scripts/verify-anthropic-messages-ui.mjs +++ b/scripts/verify-anthropic-messages-ui.mjs @@ -75,7 +75,7 @@ try { await card.getByRole('button', { name: '用于新任务', exact: true }).click(); assert.equal(requests.length, 0); await page.reload(); await open(); await expect(dialog().getByLabel('新任务默认模型', { exact: true })).toHaveValue('connection:' + connection.id); await shot('narrow-saved'); mark('saved protocol, auth and selected connection survive reload and remain operable at 390px'); - await page.setViewportSize({ width: 1440, height: 1000 }); await card.getByRole('button', { name: '原生参数', exact: true }).click(); + await page.setViewportSize({ width: 1440, height: 1000 }); await card.getByRole('button', { name: '推理与能力', exact: true }).click(); const native = dialog().getByRole('form', { name: '原生请求参数', exact: true }); await expect(native.getByLabel('输出上限字段')).toHaveValue('max_tokens'); await expect(native.getByLabel('输出上限字段').locator('option')).toHaveCount(1); await native.getByLabel('原生参数 JSON').fill('{"reasoning_effort":"high"}'); await native.getByRole('button', { name: '保存原生参数', exact: true }).click(); await expect(native.getByRole('alert')).toContainText('尚未接入'); diff --git a/scripts/verify-model-fidelity-ui.mjs b/scripts/verify-model-fidelity-ui.mjs index 7488bbe0..d3babe6f 100644 --- a/scripts/verify-model-fidelity-ui.mjs +++ b/scripts/verify-model-fidelity-ui.mjs @@ -47,12 +47,12 @@ try { browser = await chromium.launch({ channel: 'msedge', headless: true }); page = await browser.newPage({ viewport: { width: 1440, height: 1000 } }); page.on('pageerror', error => errors.push(error.message)); await page.goto(host.url); await page.getByLabel('当前项目').selectOption(f.project.id); let dialog = await openCenter(); const card = dialog.locator('.mc-connection').filter({ has: page.getByRole('heading', { name: 'Owned UI 模型', exact: true }) }); - await card.getByRole('button', { name: '原生参数', exact: true }).click(); + await card.getByRole('button', { name: '推理与能力', exact: true }).click(); await page.getByLabel('原生参数 JSON', { exact: true }).fill('{"reasoning_effort":"high","temperature":0.4,"parallel_tool_calls":false}'); await page.getByLabel('输出上限字段', { exact: true }).selectOption('max_completion_tokens'); await page.getByRole('button', { name: '保存原生参数', exact: true }).click(); await expect(dialog.getByRole('status')).toContainText('原生参数已保存'); assert.equal(requests.length, 0); await page.reload(); dialog = await openCenter(); - await dialog.locator('.mc-connection').filter({ has: page.getByRole('heading', { name: 'Owned UI 模型', exact: true }) }).getByRole('button', { name: '原生参数', exact: true }).click(); + await dialog.locator('.mc-connection').filter({ has: page.getByRole('heading', { name: 'Owned UI 模型', exact: true }) }).getByRole('button', { name: '推理与能力', exact: true }).click(); await expect(page.getByLabel('原生参数 JSON', { exact: true })).toContainText('reasoning_effort'); await capture('native-desktop'); await page.setViewportSize({ width: 390, height: 844 }); await page.getByRole('button', { name: '保存原生参数', exact: true }).scrollIntoViewIfNeeded(); diff --git a/scripts/verify-reasoning-settings-ui.mjs b/scripts/verify-reasoning-settings-ui.mjs new file mode 100644 index 00000000..215b6bf3 --- /dev/null +++ b/scripts/verify-reasoning-settings-ui.mjs @@ -0,0 +1,146 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import net from 'node:net'; +import http from 'node:http'; +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 { 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'; + +const desktop = process.argv.includes('--desktop'), appRoot = path.resolve(process.env.AGENT_WORKBENCH_QA_APP_ROOT || '.'); +assert.ok(process.argv.slice(2).every(value => value === '--desktop')); +const directory = path.resolve('.qa/reasoning-controls', (desktop ? 'electron-' : 'web-') + randomUUID()); fs.mkdirSync(directory, { recursive: true }); +console.log('EVIDENCE ' + directory); +const disposers = [], t = { after: fn => disposers.push(fn) }, f = fixture(t); f.store.close(); +const requests = [], checks = [], screenshots = [], errors = []; let empty = false; +const server = http.createServer(async (req, res) => { + const parts = []; for await (const part of req) parts.push(part); const body = JSON.parse(Buffer.concat(parts)); requests.push({ route: req.url, body }); + const usage = { input_tokens: 338, cache_creation_input_tokens: 331, cache_read_input_tokens: 6023, output_tokens: 0 }; + if (req.url.endsWith('/messages')) { + const value = { id: 'msg_owned', type: 'message', role: 'assistant', model: body.model, content: empty ? [] : [{ type: 'text', text: 'OK' }], stop_reason: 'end_turn', usage: empty ? usage : { input_tokens: 20, output_tokens: 1 } }; + if (body.stream) { + res.writeHead(200, { 'Content-Type': 'text/event-stream' }); + const event = (type, fields = {}) => 'event: ' + type + '\ndata: ' + JSON.stringify({ type, ...fields }) + '\n\n'; + res.end(event('message_start', { message: { ...value, content: [], stop_reason: null } }) + event('message_delta', { delta: { stop_reason: 'end_turn' }, usage }) + event('message_stop')); + } else { res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify(value)); } + } else if (req.url.endsWith('/responses')) { + res.writeHead(200, { 'Content-Type': 'application/json' }); + res.end(JSON.stringify({ id: 'resp_owned', model: body.model, status: 'completed', output: [{ type: 'message', role: 'assistant', content: [{ type: 'output_text', text: 'OK' }] }], usage: { input_tokens: 20, output_tokens: 1 } })); + } else { + res.writeHead(200, { 'Content-Type': 'application/json' }); + res.end(JSON.stringify({ model: body.model, choices: [{ message: { role: 'assistant', content: 'OK' }, finish_reason: 'stop' }], usage: { prompt_tokens: 20, completion_tokens: 1 } })); + } +}); +await new Promise(resolve => server.listen(0, '127.0.0.1', resolve)); +let browser, application, controller, host, page, window, result; +const mark = name => { checks.push(name); console.log('PASS ' + name); }; +const dialog = () => page.getByRole('dialog', { name: '模型中心', exact: true }); +const form = () => page.getByRole('form', { name: '原生请求参数', exact: true }); +async function resize(width, height) { + 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 shot(name) { + const file = path.join(directory, name + '.png'); await page.screenshot({ path: file, scale: 'css' }); + screenshots.push({ path: file, sha256: createHash('sha256').update(fs.readFileSync(file)).digest('hex') }); + fs.writeFileSync(path.join(directory, name + '.txt'), await page.locator('body').innerText()); +} +async function edit(name) { + if (!await dialog().count()) await page.getByRole('button', { name: '打开模型中心', exact: true }).click(); + await dialog().locator('.mc-connection').filter({ has: page.getByRole('heading', { name, exact: true }) }).getByRole('button', { name: '推理与能力', exact: true }).click(); + await form().waitFor(); +} +async function save() { + await form().getByRole('button', { name: '保存原生参数', exact: true }).click(); + await expect(form()).toHaveCount(0); await expect(dialog().getByRole('status')).toContainText('原生参数已保存'); +} +async function current(id) { return (await host.api('/model-center')).connections.find(c => c.id === id); } +async function probe(member) { await host.api('/model-center/probe', { id: member.id, scope: 'text' }); return requests.at(-1).body; } +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 = { api: (route, input) => controller.api(route, input ? { method: 'POST', input } : {}), bootstrap: await controller.api('/bootstrap') }; + const executable = desktopExecutableIdentity(appRoot).path; + application = await _electron.launch({ executablePath: executable, args: [...(executable.toLowerCase().endsWith('agentworkbench.exe') ? [] : [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 }); + page = await application.firstWindow(); window = await application.browserWindow(page); await window.evaluate(win => win.showInactive()); await resize(1440, 1080); + } 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({ viewport: { width: 1440, height: 1080 } }); await page.goto(host.url); + } + page.on('pageerror', error => errors.push(error.message)); + const baseUrl = 'http://127.0.0.1:' + server.address().port + '/v1'; + const members = []; + for (const [name, protocol, model] of [['自定义兼容线路', 'chat-completions', 'owned-custom'], ['Responses 线路', 'responses', 'owned-responses'], ['Claude 线路', 'anthropic-messages', 'owned-claude']]) { + members.push(await host.api('/model-center/connections', { name, protocol, model, baseUrl, brand: '自定义', requiresKey: false })); + } + await page.reload(); await page.locator('.connection.connected').waitFor(); + await edit(members[0].name); await expect(form().getByLabel('推理模式', { exact: true })).toHaveValue('default'); + await form().getByLabel('原生参数 JSON', { exact: true }).fill('{"temperature":0.4,"seed":3}'); + await form().getByLabel('参数配置档', { exact: true }).selectOption('deepseek'); await form().getByLabel('推理模式', { exact: true }).selectOption('enabled'); + await form().getByLabel('推理强度', { exact: true }).selectOption('low'); await save(); + assert.equal(requests.length, 0); await page.reload(); await edit(members[0].name); + await expect(form().getByLabel('参数配置档', { exact: true })).toHaveValue('deepseek'); await expect(form().getByLabel('推理模式', { exact: true })).toHaveValue('enabled'); + await expect(form().getByLabel('推理强度', { exact: true })).toHaveValue('low'); + await form().getByText('推理设置', { exact: true }).scrollIntoViewIfNeeded(); await shot('deepseek-desktop'); + assert.deepEqual((await current(members[0].id)).nativeParameters, { temperature: 0.4, seed: 3, thinking: { type: 'enabled' }, reasoning_effort: 'low' }); + mark('custom-compatible profile and enabled/low controls save and reload without requests or losing unrelated parameters'); + await form().getByLabel('推理模式', { exact: true }).selectOption('disabled'); await expect(form().getByLabel('推理强度', { exact: true })).toBeDisabled(); await save(); + let wire = await probe(members[0]); assert.deepEqual(wire.thinking, { type: 'disabled' }); assert.equal(wire.reasoning_effort, undefined); + await edit(members[0].name); await form().getByLabel('推理模式', { exact: true }).selectOption('enabled'); await form().getByLabel('推理强度', { exact: true }).selectOption('max'); await save(); + wire = await probe(members[0]); assert.deepEqual(wire.thinking, { type: 'enabled' }); assert.equal(wire.reasoning_effort, 'max'); + await edit(members[0].name); await form().getByLabel('推理模式', { exact: true }).selectOption('default'); await save(); + wire = await probe(members[0]); assert.equal(wire.thinking, undefined); assert.equal(wire.reasoning_effort, undefined); assert.equal(wire.seed, 3); + mark('DeepSeek off/on/max/default reach actual HTTP with no stale fields and preserve the original output reservation'); + await edit(members[0].name); await form().getByLabel('原生参数 JSON', { exact: true }).fill('{"reasoning_effort":"high","seed":3}'); + await expect(form().getByLabel('推理强度', { exact: true })).toHaveValue('high'); + await form().getByLabel('原生参数 JSON', { exact: true }).fill('{'); await expect(form().getByLabel('推理模式', { exact: true })).toBeDisabled(); + await form().getByLabel('原生参数 JSON', { exact: true }).fill('{"tools":[]}'); await form().getByRole('button', { name: '保存原生参数', exact: true }).click(); + await expect(form().getByRole('alert')).toContainText('尚未接入原生参数:tools'); assert.equal(requests.length, 3); await shot('invalid-json'); + await form().getByLabel('原生参数 JSON', { exact: true }).fill('{"seed":3}'); await form().getByLabel('参数配置档', { exact: true }).selectOption('openai'); + await form().getByLabel('推理模式', { exact: true }).selectOption('enabled'); await form().getByLabel('推理强度', { exact: true }).selectOption('medium'); await save(); + wire = await probe(members[0]); assert.equal(wire.reasoning_effort, 'medium'); assert.equal(wire.thinking, undefined); + mark('JSON and controls edit one value; malformed JSON and protected fields fail visibly; changing custom dialect uses the matching wire format'); + await edit(members[1].name); await form().getByLabel('推理强度', { exact: true }).selectOption('max'); await save(); wire = await probe(members[1]); + assert.deepEqual(wire.reasoning, { effort: 'max' }); assert.equal(wire.reasoning_effort, undefined); + await edit(members[1].name); await form().getByLabel('推理模式', { exact: true }).selectOption('disabled'); await save(); wire = await probe(members[1]); assert.deepEqual(wire.reasoning, { effort: 'none' }); + mark('Responses strength and disable controls send reasoning.effort using their own protocol'); + await edit(members[2].name); await form().getByLabel('推理模式', { exact: true }).selectOption('adaptive'); await form().getByLabel('推理强度', { exact: true }).selectOption('high'); await save(); + wire = await probe(members[2]); assert.deepEqual(wire.thinking, { type: 'adaptive' }); assert.deepEqual(wire.output_config, { effort: 'high' }); + await edit(members[2].name); await form().getByLabel('推理模式', { exact: true }).selectOption('enabled'); await form().getByLabel('推理预算 tokens', { exact: true }).fill('1024'); await save(); + const manual = await current(members[2].id); assert.deepEqual(manual.nativeParameters.thinking, { type: 'enabled', budget_tokens: 1024 }); + wire = await probe(members[2]); assert.deepEqual(wire.thinking, { type: 'enabled', budget_tokens: 1024 }); assert.equal(wire.max_tokens, 2048); + await page.reload(); await edit(members[2].name); await expect(form().getByLabel('推理预算 tokens', { exact: true })).toHaveValue('1024'); + await resize(390, 844); await form().getByLabel('推理强度', { exact: true }).scrollIntoViewIfNeeded(); await shot('messages-390'); + assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth + 1), true); + await form().getByText('查看接口能力与接入范围', { exact: true }).click(); await form().locator('table').scrollIntoViewIfNeeded(); await shot('features-390'); + await expect(form().locator('table')).toContainText('尚未接入'); await expect(form().locator('table')).toContainText('待确认'); + assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth + 1), true); + await form().getByRole('button', { name: '保存原生参数', exact: true }).scrollIntoViewIfNeeded(); const bounds = await form().getByRole('button', { name: '保存原生参数', exact: true }).boundingBox(); + assert.ok(bounds && bounds.x >= 0 && bounds.x + bounds.width <= 391); await save(); + mark('Messages adaptive/effort and manual budget persist; 390px controls, capability scope and save action remain readable and usable'); + await resize(1440, 1080); await page.keyboard.press('Escape'); + await host.api('/model-center/native-parameters', { id: manual.id, revision: (await current(manual.id)).revision, parameterProfile: 'anthropic', nativeParameters: { thinking: { type: 'disabled' } } }); + const selected = await current(manual.id); await host.api('/model-center/connections', { ...selected, streaming: true, capabilityDeclarations: { ...selected.capabilityDeclarations, streaming: 'supported' } }); + await host.api('/model-center/select', { type: 'connection', id: selected.id }); empty = true; await page.reload(); + await page.getByLabel('当前项目').selectOption(f.project.id); await page.getByLabel('任务内容').fill('检查当前工程,保留实际失败。'); await page.getByRole('button', { name: '发送任务', exact: true }).click(); + let failed; await until(async () => { const rows = await host.api('/sessions'); const row = rows.find(s => s.title === '检查当前工程,保留实际失败。'); failed = row && await host.api('/sessions/' + row.id); return failed?.status === 'failed'; }, 15000); + assert.equal(failed.failure.kind, 'protocol'); assert.match(failed.failure.message, /返回为空/); assert.equal(failed.execution.run.usage.totalTokens, 6692); + await expect(page.locator('.failure-card').last()).toContainText('返回为空'); await shot('empty-response-desktop'); await resize(390, 844); await page.locator('.failure-card').last().scrollIntoViewIfNeeded(); await shot('empty-response-390'); + assert.equal(failed.execution.run.usage.requests, 1); assert.equal(failed.changes.length, 0); assert.equal(requests.length, 9); + mark('actual Messages empty SSE is diagnosed explicitly in the task at both widths with 6692/0 use, zero tools and one request'); + assert.deepEqual(errors, []); fs.writeFileSync(path.join(directory, 'requests.json'), JSON.stringify(requests, null, 2)); + result = { success: true, version: host.bootstrap.version, appRoot, actualElectron: desktop, checks, screenshots, errors, syntheticRequests: requests.length, realModelRequests: 0, officialServiceTouched: false }; +} catch (error) { + if (page) await shot('failure').catch(() => {}); result = { success: false, appRoot, actualElectron: desktop, checks, screenshots, errors, error: error.stack, realModelRequests: 0 }; +} finally { + if (application) await application.close(); if (browser) await browser.close(); if (controller && await controller.health()) await controller.stop(); + await new Promise(resolve => { server.closeAllConnections(); server.close(resolve); }); for (const dispose of disposers.reverse()) await dispose(); + 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/ModelCenter.css b/src/client/ModelCenter.css index 7eecac0f..5c119b33 100644 --- a/src/client/ModelCenter.css +++ b/src/client/ModelCenter.css @@ -25,3 +25,4 @@ .mc-route-control{margin-bottom:24px;padding:18px 20px;background:#fff;border:1px solid #b8cadb;border-left:3px solid #2560a3;border-radius:6px;min-width:0}.mc-route-heading{display:flex;align-items:center;justify-content:space-between;gap:16px;margin-bottom:14px}.mc-route-heading h3{font-size:15px;margin-bottom:5px}.mc-route-heading p,.mc-route-detail{font-size:12px;color:#4b6078;line-height:1.7;overflow-wrap:anywhere}.mc-route-heading>.button{flex-shrink:0}.mc-route-select{display:flex;gap:12px;align-items:center;font-size:12px;color:#425974}.mc-route-select select{min-width:0;flex:1;width:100%;min-height:42px;border:1px solid #a7bbcf;border-radius:5px;background:#fff;padding:10px;color:#15283f;font-size:13px}.mc-route-detail{margin-top:9px}.mc-run-model{display:flex;flex-wrap:wrap;gap:6px 12px;border-top:1px solid #dce4eb;margin-top:13px;padding-top:12px;font-size:12px;line-height:1.7;overflow-wrap:anywhere}.mc-run-model strong{color:#344c67}.mc-run-model span{color:#405670}.mc-run-model small{width:100%;color:#566b81;font-size:11px}.mc-route-select select:focus-visible{outline:2px solid #2560a3;outline-offset:2px} @media(max-width:620px){.mc-route-control{padding:14px}.mc-route-heading{align-items:flex-start;gap:10px}.mc-route-heading p{font-size:11px}.mc-route-heading>.button{padding:8px;font-size:11px}.mc-route-select{align-items:stretch;flex-direction:column;gap:7px}.mc-route-select select{font-size:12px}.mc-run-model{display:block}.mc-run-model strong,.mc-run-model span,.mc-run-model small{display:block}.mc-run-model span{margin-top:4px}} .mc-request-url { overflow-wrap: anywhere; font-family: var(--font-mono, monospace); font-size: 12px; line-height: 1.6; } +.mc-reasoning .mc-form-grid{margin-top:12px}.mc-reasoning .mc-help{color:#40566e;font-size:12px}.mc-feature-scope{font-size:12px;line-height:1.7;margin:12px 0;overflow-wrap:anywhere}.mc-feature-scope summary{cursor:pointer;color:#245b92;padding:8px 0;min-height:40px}.mc-feature-scope table{width:100%;table-layout:fixed;border-collapse:collapse;margin-top:10px}.mc-feature-scope th,.mc-feature-scope td{text-align:left;vertical-align:top;border-bottom:1px solid #d3dde7;padding:9px 7px;font-size:12px;color:#40566e}.mc-feature-scope th{font-weight:600}.mc-reasoning input:focus-visible{outline:2px solid #2560a3;outline-offset:2px} diff --git a/src/client/ModelCenter.tsx b/src/client/ModelCenter.tsx index e465c22d..5870825e 100644 --- a/src/client/ModelCenter.tsx +++ b/src/client/ModelCenter.tsx @@ -14,7 +14,7 @@ import { ModelNetworkDiagnostics } from './ModelNetworkDiagnostics'; const previewUrl = (value: { protocol: string; baseUrl: string }) => { try { return modelRequestUrl(value); } catch { return '请填写有效的接口根地址'; } }; -type Connection = { id: string; name: string; brand: string; protocol: string; messagesAuth?: string; baseUrl: string; model: string; enabled: boolean; revision: number; hasKey: boolean; +type Connection = { id: string; name: string; brand: string; protocol: string; parameterProfile?: string; messagesAuth?: string; baseUrl: string; model: string; enabled: boolean; revision: number; hasKey: boolean; 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 Attempt = { 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 } }; @@ -34,7 +34,7 @@ export function ModelCenter({ onConfig, onLegacy, busy, runModel }: { onConfig: 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 [persistKey, setPersistKey] = useState(false), [persistImports, setPersistImports] = useState(false); @@ -122,13 +122,13 @@ export function ModelCenter({ onConfig, onLegacy, busy, runModel }: { onConfig: {value.id !== 'legacy-default' && } - + )} {nativeTarget && setNativeTarget(null)} onSave={async input => { await act(async () => { const result = await api<{ config: Config }>("/model-center/native-parameters", input); if (alive.current) { onConfig(result.config); setNativeTarget(null); setNotice("原生参数已保存;新任务按所选协议发送,旧请求保持原记录。"); } }); }} />}{editing &&
{ event.preventDefault(); void act(async () => { await api('/model-center/connections', { ...draft, modelIdentityAliases: draft.modelIdentityAliasesText.split(',').map(v=>v.trim()).filter(Boolean), ...(key ? { apiKey: key } : {}), ...(persistKey ? { persistKey: true } : {}) }); if (alive.current) { setKey(''); setEditing(false); setNotice(persistKey ? '连接与本机加密凭据已一起保存。' : '连接已保存。'); } }); }}>

{draft.id ? '编辑模型连接' : '添加模型连接'}

- + diff --git a/src/client/NativeParameters.tsx b/src/client/NativeParameters.tsx index a9254ef0..d5583551 100644 --- a/src/client/NativeParameters.tsx +++ b/src/client/NativeParameters.tsx @@ -1,25 +1,40 @@ import { useEffect, useRef, useState } from 'react'; import { nativeParameterSettings } from '../shared/contracts/native-parameters.mjs'; +import { changeReasoningSetting, modelParameterProfile, reasoningSetting } from '../shared/contracts/model-parameter-profiles.mjs'; +import { ReasoningSettings } from './ReasoningSettings'; -export type NativeConnection = { id: string; revision: number; name: string; protocol: string; nativeParameters?: Record; outputTokenField?: string }; +export type NativeConnection = { id: string; revision: number; name: string; protocol: string; model?: string; brand?: string; baseUrl?: string; parameterProfile?: string; capabilityDeclarations?: Record; capabilities?: Record; nativeParameters?: Record; outputTokenField?: string }; export function NativeParameters({ connection, busy, onCancel, onSave }: { connection: NativeConnection; busy: boolean; onCancel: () => void; - onSave: (input: { id: string; revision: number; nativeParameters: Record; outputTokenField: string }) => Promise }) { + onSave: (input: { id: string; revision: number; nativeParameters: Record; outputTokenField: string; parameterProfile?: string }) => Promise }) { const [text, setText] = useState(JSON.stringify(connection.nativeParameters ?? {}, null, 2)); const [field, setField] = useState(connection.outputTokenField ?? (connection.protocol === 'responses' ? 'max_output_tokens' : 'max_tokens')); const [error, setError] = useState(''); + const [profile, setProfile] = useState(connection.parameterProfile ?? 'auto'); + let parameters: Record | null = null; + try { const parsed = JSON.parse(text); if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) parameters = parsed; } catch { /* The original editor content remains editable. */ } + const updateParameters = (value: Record) => { setText(JSON.stringify(value, null, 2)); setError(''); }; const form = useRef(null); useEffect(() => { form.current?.scrollIntoView({ block: 'nearest' }); }, []); return { event.preventDefault(); setError(''); - try { const settings = nativeParameterSettings(connection.protocol, JSON.parse(text), field); await onSave({ id: connection.id, revision: connection.revision, ...settings }); } + try { const settings = nativeParameterSettings(connection.protocol, JSON.parse(text), field, profile); await onSave({ id: connection.id, revision: connection.revision, ...settings }); } catch (cause) { setError(cause instanceof Error ? cause.message : '参数格式无效。'); } }}> -

{connection.name} · 原生请求参数

+

{connection.name} · 推理与原生参数

参数按所选协议原字段发送,并封存在实际请求中。具体模型是否接受这些选项,以服务响应为准;未填写的选项采用上游默认值。

+ { + if (parameters) { + const before = { ...connection, parameterProfile: profile }, after = { ...connection, parameterProfile: value }; + if (modelParameterProfile(before).thinking !== modelParameterProfile(after).thinking) { + updateParameters(changeReasoningSetting(after, parameters, 'mode', reasoningSetting(before, parameters).mode)); + } + } + setProfile(value); + }} />

数值沿用当前任务和连接的输出预算,不允许原生参数覆盖预算、消息、工具或接口。