diff --git a/docs/MODEL-CATALOG.md b/docs/MODEL-CATALOG.md new file mode 100644 index 00000000..beea4c49 --- /dev/null +++ b/docs/MODEL-CATALOG.md @@ -0,0 +1,27 @@ +# 上游模型目录与多模型使用 + +用户补充:模型应正常从上游获取,不要求手填;可选择多个型号,使用时手动指定或自动适配。本切片并入1.25.3,沿用模型中心、ModelHub和现有模型池,不另建路由体系。正式交付状态以独立发行记录为准。 + +## 实现 + +模型中心主要入口为“从上游添加模型”:新上游填写名称、品牌、协议、根地址与凭据即可获取,无需先填型号。也可从已有连接“获取同源模型”,使用原凭据。目录支持搜索、多选与筛选批量选中;保存时可保留当前选择、手动指定默认型号,或建立自动适配池。手动填写保留为未提供目录的兼容入口。 + +Chat/Responses和DeepSeek兼容服务使用根地址下的GET /models;Messages按根地址或/v1地址补齐/v1/models,并保留x-api-key/Bearer选择和anthropic-version。has_more/last_id分页有60秒、20页、1000项、4MB界限,达到范围明确显示部分目录;本机100连接、单池32成员的原上限不静默截断。错误保留原上游原因与请求ID,单次目录GET不自动重试,不生成模型推理尝试。取消覆盖请求先后乱序与迟到响应;关闭宿主清除临时预览。 + +同上游的多个型号通过credentialSource引用源连接,原内存Key对象和DPAPI块保持;只为新填写且用户明确选择保存的Key创建一个块。不同账号即使端点/型号相同仍独立。源停用或地址/鉴权不符则引用不可用;原Key替换、源代次和连接修订参与旧Run拒绝。子型号显式填写独立Key会脱离引用并增加凭据修订,避免旧opaque历史误回传。新增模型、池、选线和模式在同一SQLite事务中保存,失败整批回退且预览仍可修正。重启只恢复原保存块;临时Key仍不持久化。 + +目录同步上游明确提供的型号、显示名称、提供方、容量、生命周期、文本/工具/流式/图像/语音声明、推理模式/强度、支持参数及PDF/服务端工具等功能声明。元数据缺失保持未知,允许用户明确补充未知文本/工具项;负面声明不会被补充覆盖。推理界面与服务端按已提供的档位/模式限制选择。实际配置容量仍取原本机预算与上游上限的较小值,不自动扩预算。目录声明不变成已验证,本地未接入功能仍标未接入。重新选择已有模型保留其本地参数、能力覆盖和命名,结果明确为沿用已有模型;不暗中覆盖用户编辑。 + +自动适配按照本次任务能力、健康、并发和原池策略筛选,运行内优先保持型号;这不是已验证的语义任务路由。手动与自动都保留每次实际请求身份、用量和原失败,旧Run保存原目录/连接/凭据/池快照。 + +## 验证与回顾 + +首批11/11目录核心验证与构建通过;补足编译HTTP、容量、不同账号、停用中的子型号检测和宿主停止后,目录/模型中心/能力路由/推理/凭据/发行与升级相关68/68通过,热升级保留目录对象与方法回退另补4/4通过,完整构建通过。网页/实际Electron最终各8组、各13目录GET、0推理通过,1440/390px原图实际回看。新增目录没有减掉原推理验收,推理网页/桌面各6组再次通过;原模型中心、协议、Messages入口随后复验。独立载荷/安装/正式升级另写发行报告。 + +目录品牌补强首轮有一项验收器断言失败:DOM已包含disabled的option,Playwright的toBeDisabled仍返回enabled。原截图和失败保留,改为核对真实HTMLSelectElement选项的disabled布尔属性,原期望/期限不变,最终网页/桌面通过。阶段复核另发现同地址/型号的新账号可能误中旧源匹配,已将去重严格限制到明确源连接,增加真实HTTP两账号隔离;不是将端点或型号当凭据身份。 + +证据位于`.qa/reasoning-controls/`的新文件。原109e5124范围的完整源码测试因本次需求扩大,在264个完成项、未观察到失败时主动停止所属进程;未完整通过,不作为新范围验收。原日志与取消回执位于`.qa/reasoning-1.25.3/full-source*`。新范围将重新冻结,旧freeze不覆盖。 + +公开契约参考:OpenAI官方GET https://api.openai.com/v1/models的OpenAPI说明;Anthropic官方SDK `https://raw.githubusercontent.com/anthropics/anthropic-sdk-typescript/main/src/resources/models.ts`(原文件已保存于`.qa/reasoning-controls/public-docs/claude-sdk-models.ts`),包括capabilities、effort、thinking.types与分页。兼容代理实际是否提供这些元数据尚未用真实账号核验,本阶段真实模型请求0。 + +本地核心/HTTP夹具与真实供应商交付分别判断。Z3空响应、DeepSeek length、全部旧网络异常/重复读取、自主工程交付与Purge AB/BA未验证保持,不续跑旧实验、不推送、不委派、不操作真实Key。 diff --git a/docs/REASONING-CONTROLS-PLAN.md b/docs/REASONING-CONTROLS-PLAN.md index fa76324b..9f6967b0 100644 --- a/docs/REASONING-CONTROLS-PLAN.md +++ b/docs/REASONING-CONTROLS-PLAN.md @@ -12,6 +12,12 @@ ## 阶段记录 +- 用户新增模型目录要求:1.25.3扩大为上游目录→搜索多选→保存同源型号→手动/自动使用;旧109e5124冻结及其完整源码轮次保持原范围历史证据,不据此打包或升级。新范围完成后重新冻结。 +- 原范围源码轮次在264个完成项、未观察到失败时因需求扩大停止所属PID56056及其子测试树;原日志/取消回执保持,不报整轮通过。目录实现与阶段回顾见MODEL-CATALOG.md。 +- 目录设计:复用现有ModelHub与池,保留手动兼容入口;新型号引用单一源连接凭据,源停用、端点/鉴权变化、换Key与重启恢复必须隔离,不能复制或重新保存已有Key。目录从品牌所用协议获取,Messages分页;60秒/20页/1000项/4MB有界、不跟随重定向、不自动重试。目录仅为上游声明,无元数据时保留未知,用户显式补充;不把型号名当已验证能力。 +- 交互选择:比较另建供应商中心(重复配置体系)、在旧手填表单插入目录(仍强迫先填型号)、现有模型中心独立目录编辑区;采用第三种。新上游不需型号,已有连接可一键获取同源目录,搜索/批量选择/结果/错误/取消都在同区;手动与自动复用现有默认选线和模型池。 +- 新验收:OpenAI/Responses/DeepSeek兼容GET与Messages两种鉴权/分页;空目录、重复游标、冲突型号、超限、错误/取消/迟到响应;原凭据引用对象/DPAPI块不重存、源变化及重启;未知能力/参数元数据/手动编辑冲突;原Run冻结及手动/自动实际HTTP;网页/实际Electron及390px,然后独立发行、保留状态升级。 + - 起步:读取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有界及已有实际文件定位。 diff --git a/findings.md b/findings.md index 03ca6b5e..87be76b9 100644 --- a/findings.md +++ b/findings.md @@ -1,5 +1,7 @@ # 汇总发现 +上游模型目录:原Provider.models仅字符串/100条,模型中心手填;新目录入口复用原Hub/池,Chat/Responses/DeepSeek GET及Messages根/v1分页/鉴权。新型号通过源连接凭据引用,原对象与DPAPI块不重存;不同账号即使同地址型号也不去重。目录元数据为声明、未知不伪造、推理档位限制可选项,未接入执行功能仍显明。自动适配是能力/健康/并发加池策略;原Run冻结目录/凭据源代次。68相关+4升级、网页/原生各8组通过,真实推理0。细节docs/MODEL-CATALOG.md;正式和独立发行仍待完成。 + 推理设置补充:用户要求可开启并选择强度,不能仅支持thinking.disabled。DeepSeek官方Chat思考开关为thinking.type,强度low/high/max;携带tools的后续请求必须完整回传所有已有reasoning_content。OpenAI官方Chat/Responses强度受型号限制(none/minimal/low/medium/high/xhigh/max),不能在UI宣称所有模型都支持关闭。新增工作见docs/REASONING-CONTROLS-PLAN.md,真实请求暂0。 Z:Claude请求5.5/返回5-5的型号手误,用户已确认并保存新连接/凭据修订2,首样本1请求176tokens保留。DeepSeek默认high推理;预检146tokens通过,Node5请求47740tokens末轮finish_reason=length,2048输出全部reasoning_tokens,完整SSE也不能当完整答复;identity incomplete、0提案/修改/交付,原九基线失败/build通过。两轮151份82988849字节证据离线通过,原状态/预算/选线/凭据恢复,不续跑旧Task。官方Thinking Mode原HTML117778字节和SHA保存,当前Chat白名单不支持thinking是明确兼容缺口,不能假装已发送该参数或归因网络。 diff --git a/progress.md b/progress.md index 73cd407a..d0300078 100644 --- a/progress.md +++ b/progress.md @@ -1,5 +1,10 @@ # 统一执行进度 +## 上游模型目录与多模型使用 + +- 用户补充无需手填型号、从上游多选并手动/自动使用;已接到原模型中心/池,来源与边界见docs/MODEL-CATALOG.md。相关68/68、目录热升级补4/4及完整构建通过;网页/真实Electron各8组、13目录GET、0推理,1440/390原图回看,原推理两端各6组再次通过。 +- 旧109e冻结完整源码轮次因新增范围在264完成项、未观察到失败时主动停止所属树,日志/取消回执保持;不报通过,最终另冻。目录品牌首次UI的option matcher失败及原图保持,按真实disabled属性复验通过。正式仍1.25.2/PID36552,未操作真实Key或续跑旧样本。 + ## 推理控制与空响应修复 - 配置档/可视推理/导入和Run冻结/Chat原生状态回传实现;85/85相关+最终8/8专项,构建通过。网页/实际Electron各6组及旧参数6组/Messages7组通过,1440/390原图回看。首构建声明缺失、重开DB夹具清理超时和所属进程终止保留,修清理顺序后通过。正式仍1.25.2,待独立发行。见docs/QA-REASONING-CONTROLS.md。 diff --git a/scripts/verify-anthropic-messages-ui.mjs b/scripts/verify-anthropic-messages-ui.mjs index 2067acef..a3410c8a 100644 --- a/scripts/verify-anthropic-messages-ui.mjs +++ b/scripts/verify-anthropic-messages-ui.mjs @@ -58,7 +58,7 @@ let result; try { await page.addInitScript(({ projectId, sessionId }) => { localStorage.setItem('awb-project', projectId); localStorage.setItem('awb-session', sessionId); }, { projectId: f.project.id, sessionId: f.session.id }); await page.goto(host.url); await page.waitForLoadState('networkidle'); await open(); - await dialog().getByRole('button', { name: '添加连接', exact: true }).click(); const form = dialog().getByRole('form', { name: '编辑模型连接', exact: true }); + await dialog().getByRole('button', { name: '手动填写(兼容)', exact: true }).click(); const form = dialog().getByRole('form', { name: '编辑模型连接', exact: true }); await form.getByLabel('连接名称', { exact: true }).fill('本机 Messages 验收'); await form.getByLabel('接口协议', { exact: true }).selectOption('anthropic-messages'); await form.getByLabel('接口根地址', { exact: true }).fill(baseUrl); await form.getByLabel('请求模型名称', { exact: true }).fill('claude-owned-ui'); await form.getByLabel('临时 API Key', { exact: true }).fill('owned-ui-key'); await form.getByLabel('Messages 鉴权', { exact: true }).selectOption('bearer'); diff --git a/scripts/verify-desktop-credentials.py b/scripts/verify-desktop-credentials.py index bf2fd8e5..2951ce1d 100644 --- a/scripts/verify-desktop-credentials.py +++ b/scripts/verify-desktop-credentials.py @@ -105,7 +105,7 @@ try: dialog = page.get_by_role('dialog', name='模型中心', exact=True) expect(dialog).to_be_visible() stage = 'real connection form and explicit encrypted save' - dialog.get_by_role('button', name='添加连接', exact=True).click() + dialog.get_by_role('button', name='手动填写(兼容)', exact=True).click() editor = dialog.get_by_role('form', name='编辑模型连接', exact=True) editor.get_by_label('连接名称', exact=True).fill('Owned Saved Primary') editor.get_by_label('接口根地址', exact=True).fill(endpoint) diff --git a/scripts/verify-model-catalog-ui.mjs b/scripts/verify-model-catalog-ui.mjs new file mode 100644 index 00000000..80527753 --- /dev/null +++ b/scripts/verify-model-catalog-ui.mjs @@ -0,0 +1,151 @@ +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 ? 'catalog-electron-' : 'catalog-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 scenario = 'normal', release; +const models = Array.from({ length: 132 }, (_, i) => ({ id: 'owned-model-' + String(i).padStart(3, '0'), owned_by: '自有目录夹具', + context_length: 64000, max_output_tokens: 8192, capabilities: { text: true, tools: i !== 1, streaming: true, image_input: { supported: i === 2 }, + effort: { supported: true, low: { supported: true }, high: { supported: true } }, thinking: { supported: true, types: { adaptive: { supported: true }, disabled: { supported: true }, enabled: { supported: false } } } } })); +const server = http.createServer(async (req, res) => { + const parts = []; for await (const part of req) parts.push(part); + const body = parts.length ? JSON.parse(Buffer.concat(parts)) : null; + requests.push({ method: req.method, route: req.url, body, authorizationPresent: !!req.headers.authorization, apiKeyHeaderPresent: !!req.headers['x-api-key'], anthropicVersion: req.headers['anthropic-version'] }); + if (scenario === 'wait') await new Promise(resolve => { release = resolve; }); + if (scenario === 'error') { res.writeHead(503, { 'Content-Type': 'application/json', 'x-request-id': 'owned-catalog-503' }); res.end(JSON.stringify({ error: { message: '自有目录暂不可用', code: 'owned_unavailable' } })); return; } + const input = new URL(req.url, 'http://owned.test'); + const value = scenario === 'empty' ? { data: [] } : input.searchParams.has('after_id') ? { data: models.slice(100), has_more: false } + : { data: models.slice(0, 100), has_more: true, last_id: models[99].id }; + res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify(value)); +}); +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 catalog = () => dialog().getByRole('region', { 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 open() { if (!await dialog().count()) await page.getByRole('button', { name: '打开模型中心', exact: true }).click(); } +async function add() { await open(); await dialog().getByRole('button', { name: '从上游添加模型', exact: true }).click(); await catalog().waitFor(); } +async function fetchModels() { await catalog().getByRole('button', { name: /获取上游模型|重新获取模型目录/ }).click(); await expect(catalog().getByLabel('上游模型列表', { exact: true })).toBeVisible(); } +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)], env: projectEnvironment({ AGENT_WORKBENCH_QA: '1', AGENT_WORKBENCH_NODE: process.execPath }) }); + page = await application.firstWindow(); window = await application.browserWindow(page); await page.waitForLoadState(); await resize(1440, 1080); + } else { + host = await launchWorkbench(t, f.data, {}, { appRoot }); 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)); await page.locator('.connection.connected').waitFor(); + await add(); await expect(catalog().getByRole('textbox', { name: '请求模型名称', exact: true })).toHaveCount(0); + await catalog().getByLabel('上游名称', { exact: true }).fill('自有多模型上游'); + await catalog().getByLabel('目录接口根地址', { exact: true }).fill('http://127.0.0.1:' + server.address().port + '/v1'); + await catalog().getByLabel('目录 API Key', { exact: true }).fill('owned-catalog-ui-key'); await fetchModels(); + assert.equal(requests.length, 2); assert.ok(requests.every(value => value.method === 'GET' && value.body === null)); + await expect(catalog().getByLabel('上游模型列表', { exact: true }).getByRole('checkbox')).toHaveCount(132); + await catalog().getByLabel('搜索上游模型', { exact: true }).fill('owned-model-00'); + await catalog().getByLabel('选择模型 owned-model-000', { exact: true }).check(); await catalog().getByLabel('选择模型 owned-model-001', { exact: true }).check(); await catalog().getByLabel('选择模型 owned-model-002', { exact: true }).check(); + await catalog().getByLabel('模型使用方式', { exact: true }).selectOption('auto'); await shot('catalog-multiselect-1440'); + await catalog().getByRole('button', { name: '保存所选 3 个模型', exact: true }).click(); await expect(catalog().getByRole('status')).toContainText('已新增 3 个模型'); + let center = await host.api('/model-center'); const members = center.connections.filter(value => value.upstreamModel); + assert.equal(members.length, 3); assert.equal(members.filter(value => value.credentialSource).length, 2); assert.equal(center.selected.type, 'pool'); + assert.equal(center.pools.find(value => value.id === center.selected.id).members.length, 3); assert.equal(requests.length, 2); + mark('new upstream needs no manual model; 132 paginated IDs are searchable and selectable; saving creates shared-source members and the existing automatic pool without inference'); + await page.reload(); await open(); await expect(dialog().getByLabel('新任务默认模型', { exact: true })).toHaveValue('pool:' + center.selected.id); + const child = members.find(value => value.model === 'owned-model-002'); await dialog().getByLabel('新任务默认模型', { exact: true }).selectOption('connection:' + child.id); + assert.equal((await host.api('/model-center')).selected.id, child.id); + const card = () => dialog().locator('.mc-connection').filter({ has: page.getByRole('heading', { name: child.name, exact: true }) }); + await expect(card()).toContainText('共用'); await card().getByRole('button', { name: '推理与能力', exact: true }).click(); + const params = () => dialog().getByRole('form', { name: '原生请求参数', exact: true }); + await expect(params().getByLabel('推理强度', { exact: true }).locator('option')).toHaveCount(3); + await params().getByRole('button', { name: '取消', exact: true }).click(); + mark('reload retains the automatic pool; users can manually choose a member, see its credential source and receive only upstream-declared reasoning strengths'); + await card().getByRole('button', { name: '获取同源模型', exact: true }).click(); await expect(catalog().getByLabel('目录 API Key', { exact: true })).toHaveCount(0); await fetchModels(); + await catalog().getByLabel('搜索上游模型', { exact: true }).fill('owned-model-003'); await catalog().getByLabel('选择模型 owned-model-003', { exact: true }).check(); + await catalog().getByLabel('模型使用方式', { exact: true }).selectOption('manual'); await catalog().getByLabel('目录默认模型', { exact: true }).selectOption('owned-model-003'); + await catalog().getByRole('button', { name: '保存所选 1 个模型', exact: true }).click(); await expect(catalog().getByRole('status')).toContainText('已新增 1 个模型'); + center = await host.api('/model-center'); assert.equal(center.connections.find(value => value.id === center.selected.id).model, 'owned-model-003'); + assert.equal(center.connections.filter(value => value.upstreamModel).length, 4); assert.equal(requests.length, 4); + mark('an existing member opens its original upstream without exposing or re-entering a key and adds another model with an explicit manual default'); + await catalog().getByRole('button', { name: '关闭目录', exact: true }).click(); await card().getByRole('button', { name: '获取同源模型', exact: true }).click(); + scenario = 'error'; await catalog().getByRole('button', { name: '获取上游模型', exact: true }).click(); await expect(catalog().getByRole('alert')).toContainText('自有目录暂不可用'); + await catalog().getByText('查看上游原文与请求信息', { exact: true }).click(); await expect(catalog()).toContainText('owned-catalog-503'); await shot('catalog-upstream-error'); + assert.equal(requests.length, 5); scenario = 'empty'; await fetchModels(); await expect(catalog()).toContainText('上游返回了空目录'); + assert.equal((await host.api('/model-center')).connections.length, 5); + scenario = 'wait'; await catalog().getByRole('button', { name: '重新获取模型目录', exact: true }).click(); await until(() => !!release); + await catalog().getByRole('button', { name: '取消获取', exact: true }).click(); release(); await expect(catalog().getByRole('status')).toContainText('已取消获取'); + await expect(catalog().getByLabel('上游模型列表', { exact: true })).toHaveCount(0); scenario = 'normal'; await fetchModels(); + await expect(catalog().getByLabel('上游模型列表', { exact: true }).getByRole('checkbox')).toHaveCount(132); + mark('upstream error retains request ID and original reason with one GET; empty directory and cancellation preserve members, and a later explicit refresh recovers'); + await resize(390, 844); await catalog().getByLabel('搜索上游模型', { exact: true }).fill('owned-model-13'); + await catalog().getByRole('button', { name: '选中当前筛选', exact: true }).click(); await catalog().getByLabel('模型使用方式', { exact: true }).selectOption('keep'); + await catalog().getByLabel('上游模型列表', { exact: true }).scrollIntoViewIfNeeded(); await shot('catalog-list-390'); + assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth + 1), true); + const save = catalog().getByRole('button', { name: '保存所选 2 个模型', exact: true }); await save.scrollIntoViewIfNeeded(); const bounds = await save.boundingBox(); assert.ok(bounds && bounds.x >= 0 && bounds.x + bounds.width <= 391); + await save.click(); await expect(catalog().getByRole('status')).toContainText('已新增 2 个模型'); await shot('catalog-saved-390'); + assert.equal((await host.api('/model-center')).connections.filter(value => value.upstreamModel).length, 6); + mark('390px search, filtered bulk selection, source feedback and save action fit and complete the same real API flow'); + await resize(1440, 1080); await catalog().getByRole('button', { name: '关闭目录', exact: true }).click(); await add(); + await catalog().getByLabel('目录服务品牌', { exact: true }).selectOption('Anthropic'); + await expect(catalog().getByLabel('目录接口协议', { exact: true })).toHaveValue('anthropic-messages'); + await expect(catalog().getByLabel('目录接口根地址', { exact: true })).toHaveValue('https://api.anthropic.com'); + await catalog().getByLabel('上游名称', { exact: true }).fill('自有 Claude 上游'); + await catalog().getByLabel('目录接口根地址', { exact: true }).fill('http://127.0.0.1:' + server.address().port); + await catalog().getByLabel('目录 API Key', { exact: true }).fill('owned-messages-catalog'); await fetchModels(); + assert.equal(requests.at(-1).route, '/v1/models?after_id=owned-model-099&limit=100'); assert.equal(requests.at(-1).apiKeyHeaderPresent, true); assert.equal(requests.at(-1).authorizationPresent, false); + await catalog().getByLabel('搜索上游模型', { exact: true }).fill('owned-model-003'); await catalog().getByLabel('选择模型 owned-model-003', { exact: true }).check(); + await catalog().getByRole('button', { name: '保存所选 1 个模型', exact: true }).click(); await expect(catalog().getByRole('status')).toContainText('已新增 1 个模型'); + const claude = (await host.api('/model-center')).connections.find(value => value.name === '自有 Claude 上游 · owned-model-003'); + await catalog().getByRole('button', { name: '关闭目录', exact: true }).click(); await dialog().locator('.mc-connection').filter({ has: page.getByRole('heading', { name: claude.name, exact: true }) }).getByRole('button', { name: '推理与能力', exact: true }).click(); + await expect(params().getByLabel('推理模式', { exact: true }).locator('option[value="enabled"]')).toHaveJSProperty('disabled', true); + await expect(params().getByLabel('推理模式', { exact: true }).locator('option[value="adaptive"]')).toHaveJSProperty('disabled', false); + await params().getByRole('button', { name: '取消', exact: true }).click(); + mark('Anthropic brand pairs its endpoint, protocol and x-api-key pagination; upstream thinking modes restrict the actual controls'); + await add(); await catalog().getByLabel('目录服务品牌', { exact: true }).selectOption('DeepSeek'); + await expect(catalog().getByLabel('目录接口协议', { exact: true })).toHaveValue('chat-completions'); + await expect(catalog().getByLabel('目录接口根地址', { exact: true })).toHaveValue('https://api.deepseek.com'); + await catalog().getByLabel('上游名称', { exact: true }).fill('自有 DeepSeek 上游'); + await catalog().getByLabel('目录接口根地址', { exact: true }).fill('http://127.0.0.1:' + server.address().port + '/v1'); + await catalog().getByLabel('目录 API Key', { exact: true }).fill('owned-deepseek-catalog'); await fetchModels(); + assert.equal(requests.at(-1).authorizationPresent, true); assert.equal(requests.at(-1).apiKeyHeaderPresent, false); + await catalog().getByLabel('搜索上游模型', { exact: true }).fill('owned-model-005'); await catalog().getByLabel('选择模型 owned-model-005', { exact: true }).check(); + await catalog().getByRole('button', { name: '保存所选 1 个模型', exact: true }).click(); await expect(catalog().getByRole('status')).toContainText('已新增 1 个模型'); + mark('DeepSeek brand pairs Chat and bearer discovery with a separate explicitly entered source key and no inference'); + await catalog().getByRole('button', { name: '关闭目录', exact: true }).click(); await dialog().getByRole('button', { name: '手动填写(兼容)', exact: true }).click(); + await expect(dialog().getByRole('form', { name: '编辑模型连接', exact: true }).getByLabel('请求模型名称', { exact: true })).toBeVisible(); + assert.deepEqual(errors, []); assert.ok(requests.every(value => value.method === 'GET')); assert.equal((await host.api('/model-center')).attempts.length, 0); + mark('manual compatibility entry remains usable; every upstream call was a directory GET with zero model attempts'); + result = { success: true, version: host.bootstrap.version, appRoot, actualElectron: desktop, checks, screenshots, errors, directoryGets: 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 { + release?.(); 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, 'requests.json'), JSON.stringify(requests, null, 2)); 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/scripts/verify-model-center-ui.mjs b/scripts/verify-model-center-ui.mjs index 80ce2af8..5d488891 100644 --- a/scripts/verify-model-center-ui.mjs +++ b/scripts/verify-model-center-ui.mjs @@ -26,7 +26,7 @@ try { await page.goto(host.url); await page.waitForLoadState('networkidle'); await page.getByRole('button', { name: '打开模型中心', exact: true }).click(); const dialog = page.getByRole('dialog', { name: '模型中心', exact: true }); await expect(dialog).toBeVisible(); - await dialog.getByRole('button', { name: '添加连接', exact: true }).click(); + await dialog.getByRole('button', { name: '手动填写(兼容)', exact: true }).click(); const editor = dialog.getByRole('form', { name: '编辑模型连接', exact: true }); await editor.getByLabel('连接名称', { exact: true }).fill('Fixture Primary'); await editor.getByLabel('接口根地址', { exact: true }).fill('http://127.0.0.1:9/v1'); @@ -38,7 +38,7 @@ try { assert.equal((await host.api('/model-center')).connections.find(value => value.name === 'Fixture Primary').hasKey, true); mark('connection form stores only the volatile credential and renders configured status without exposing it'); - await dialog.getByRole('button', { name: '添加连接', exact: true }).click(); + await dialog.getByRole('button', { name: '手动填写(兼容)', exact: true }).click(); const second = dialog.getByRole('form', { name: '编辑模型连接', exact: true }); await second.getByLabel('连接名称', { exact: true }).fill('Fixture Reserve'); await second.getByLabel('接口根地址', { exact: true }).fill('http://127.0.0.1:9/v1'); diff --git a/scripts/verify-model-protocols-ui.mjs b/scripts/verify-model-protocols-ui.mjs index 96e9b5da..0aa49ded 100644 --- a/scripts/verify-model-protocols-ui.mjs +++ b/scripts/verify-model-protocols-ui.mjs @@ -59,7 +59,7 @@ try { await page.goto(host.url); await page.waitForLoadState('networkidle'); await page.getByRole('button', { name: '打开模型中心', exact: true }).click(); const dialog = page.getByRole('dialog', { name: '模型中心', exact: true }); - await dialog.getByRole('button', { name: '添加连接', exact: true }).click(); + await dialog.getByRole('button', { name: '手动填写(兼容)', exact: true }).click(); const form = dialog.getByRole('form', { name: '编辑模型连接', exact: true }); await form.getByLabel('连接名称', { exact: true }).fill('验收 Responses'); await form.getByLabel('接口协议', { exact: true }).selectOption('responses'); diff --git a/src/client/ModelCatalog.tsx b/src/client/ModelCatalog.tsx new file mode 100644 index 00000000..60ec7030 --- /dev/null +++ b/src/client/ModelCatalog.tsx @@ -0,0 +1,105 @@ +import { useEffect, useRef, useState } from 'react'; +import { api } from './api'; +import type { CatalogPreview } from '../shared/contracts/model-catalog.mjs'; +import { ModelErrorDetails } from './ModelErrorDetails'; +import type { RuntimeFailure } from './types'; + +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 }; +const capabilityNames: Record = { text: '文本', tools: '工具调用', streaming: '流式输出', vision: '图像输入', audio: '语音' }; +export function ModelCatalog({ sources, sourceId = '', busy, onSaved, onClose }: { + sources: Source[]; sourceId?: string; busy: boolean; onSaved: () => Promise; onClose: () => void; +}) { + const [source, setSource] = useState(sourceId), [draft, setDraft] = useState(initial); + const [key, setKey] = useState(''), [persistKey, setPersistKey] = useState(false); + const [preview, setPreview] = useState(null), [chosen, setChosen] = useState([]), [query, setQuery] = useState(''); + const [routing, setRouting] = useState('keep'), [defaultModel, setDefaultModel] = useState(''); + const [declare, setDeclare] = useState(false), [working, setWorking] = useState(false), [saving, setSaving] = useState(false); + const [error, setError] = useState(''), [diagnostic, setDiagnostic] = useState(null), [notice, setNotice] = useState(''); + const live = useRef(true), generation = useRef(0), request = useRef(''), region = useRef(null); + const current = sources.find(value => value.id === source), locked = busy || saving; + function invalidate() { + generation.current++; const id = request.current; request.current = ''; + if (id) void api('/model-center/catalog/cancel', { id }).catch(() => {}); + setPreview(null); setChosen([]); setWorking(false); setError(''); setDiagnostic(null); setNotice(''); + } + useEffect(() => { + live.current = true; region.current?.scrollIntoView({ block: 'start' }); + return () => { live.current = false; generation.current++; const id = request.current; if (id) void api('/model-center/catalog/cancel', { id }).catch(() => {}); }; + }, []); + function failed(cause: unknown) { + setError(cause instanceof Error ? cause.message : '操作未完成,请重新获取。'); + if (cause && typeof cause === 'object' && 'diagnostic' in cause) setDiagnostic(cause.diagnostic as RuntimeFailure | null); + } + async function fetchModels() { + invalidate(); const marker = ++generation.current, requestId = crypto.randomUUID(); request.current = requestId; + setWorking(true); + try { + const result = await api('/model-center/catalog', { requestId, + ...(current ? { id: current.id, revision: current.revision } : { draft, ...(key ? { apiKey: key } : {}) }) }); + if (live.current && generation.current === marker) { setPreview(result); setNotice(`已获取 ${result.entries.length} 个模型。勾选后保存。`); } + } catch (cause) { if (live.current && generation.current === marker) failed(cause); } + finally { if (live.current && generation.current === marker) setWorking(false); } + } + async function save() { + if (!preview) return; setSaving(true); setError(''); setDiagnostic(null); + try { + const result = await api<{ added: string[]; existing: string[] }>('/model-center/catalog/apply', { + previewId: preview.id, models: chosen, routing, defaultModel, persistKey: !source && persistKey, + ...(declare ? { declarations: { text: 'supported', tools: 'supported' } } : {}), + }); + if (live.current) { + request.current = ''; setKey(''); setPreview(null); setChosen([]); + setNotice(`已新增 ${result.added.length} 个模型,沿用 ${result.existing.length} 个已有模型。${routing === 'auto' ? '已设为自动适配。' : routing === 'manual' ? '默认模型已更新。' : '可在上方选择使用。'}已有模型的手动设置保持。`); + await onSaved(); + } + } catch (cause) { if (live.current) failed(cause); } + finally { if (live.current) setSaving(false); } + } + const visible = preview?.entries.filter(value => (value.id + ' ' + value.name + ' ' + value.owner).toLowerCase().includes(query.trim().toLowerCase())) ?? []; + const selectable = visible.filter(value => value.lifecycle !== 'retired'); + return
+

从上游选择模型

获取目录,勾选要用的型号,再决定手动指定或自动适配。

+
+ + {!source ? <> + + + + {draft.protocol === 'anthropic-messages' && } + + + + + :

使用该连接当前的凭据获取目录;新增型号引用同一凭据来源。

} +
+
+ {working && }
+

只访问模型目录,不发起推理请求。兼容服务未开放目录时,可返回“手动填写(兼容)”。

+ {error &&

{error}

}{diagnostic && } + {notice &&

{notice}

} + {preview && <> +
显示 {visible.length} / {preview.entries.length} · 已选 {chosen.length}
+ {preview.warning &&

{preview.warning}

} +

以下为上游目录声明,尚未经过模型调用验证。目录最多1000项,本机最多100个模型连接;单个自动池最多32个成员。

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

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

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

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

} +
+ } +
; +} diff --git a/src/client/ModelCenter.css b/src/client/ModelCenter.css index 5c119b33..2383dfd3 100644 --- a/src/client/ModelCenter.css +++ b/src/client/ModelCenter.css @@ -25,4 +25,6 @@ .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-section-title .mc-row-actions,.mc-catalog .mc-row-actions{display:flex;flex-wrap:wrap;gap:8px}.mc-catalog{margin-bottom:24px;border-top:3px solid #2560a3;min-width:0}.mc-catalog-heading{display:flex;align-items:end;flex-wrap:wrap;gap:12px;margin:18px 0 12px}.mc-catalog-heading label{display:grid;gap:7px;flex:1;min-width:180px}.mc-catalog-heading input{padding:10px;border:1px solid #a9bdcf;border-radius:5px;width:100%;min-width:0;background:#fff}.mc-catalog-heading>span{font-size:12px;color:#40566e;padding:10px 0}.mc-catalog-list{margin:12px 0;max-height:440px;overflow:auto;border:1px solid #b8cadb;border-radius:5px;background:#fff;overscroll-behavior:contain}.mc-catalog-model{display:flex;gap:12px;align-items:start;padding:13px 14px;border-bottom:1px solid #d3dde7;cursor:pointer;min-width:0}.mc-catalog-model:last-child{border-bottom:0}.mc-catalog-model.is-selected{background:#eaf2fa}.mc-catalog-model>input{margin-top:4px;flex:0 0 auto;width:18px;height:18px;accent-color:#2560a3}.mc-catalog-model>span{display:grid;gap:5px;min-width:0;overflow-wrap:anywhere;line-height:1.6}.mc-catalog-model strong{font-family:Consolas,"Microsoft YaHei",monospace;font-size:13px}.mc-catalog-model small{font-size:12px;color:#40566e}.mc-catalog input:focus-visible{outline:2px solid #2560a3;outline-offset:2px}.mc-catalog>.mc-checkbox{display:flex;align-items:start;gap:9px;line-height:1.8;margin:16px 0;color:#40566e;font-size:12px}.mc-catalog>.mc-checkbox>input{flex:0 0 auto;margin-top:4px} +@media(max-width:620px){.mc-catalog-heading{align-items:stretch}.mc-catalog-heading>span{padding:0}.mc-catalog-model{padding:12px 10px;gap:10px}.mc-catalog-model>input{width:22px;height:22px}.mc-catalog-list{max-height:380px}.mc-catalog .mc-section-title>.button{align-self:flex-end}} .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 5870825e..45c93d4d 100644 --- a/src/client/ModelCenter.tsx +++ b/src/client/ModelCenter.tsx @@ -11,10 +11,12 @@ import { ModelErrorDetails } from './ModelErrorDetails'; import { ModelBudgetSettings } from './ModelBudgetSettings'; import { modelRequestUrl, protocolLabel } from '../shared/contracts/model-endpoint.mjs'; import { ModelNetworkDiagnostics } from './ModelNetworkDiagnostics'; +import { ModelCatalog } from './ModelCatalog'; +import type { CatalogModel } from '../shared/contracts/model-catalog.mjs'; const previewUrl = (value: { protocol: string; baseUrl: string }) => { try { return modelRequestUrl(value); } catch { return '请填写有效的接口根地址'; } }; -type Connection = { id: string; name: string; brand: string; protocol: string; parameterProfile?: 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; 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 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 } }; @@ -24,7 +26,7 @@ type Operations = { checkedAt: string; version: string; scope: string; activeTas artifacts?: { offset: number; checked: number; total: number; remaining: number; olderOffset: number | null; newerOffset: number | null; results: { id: string; passed: boolean; error?: string }[] } }; type SavedCredential = { id: string; name: string; revision: number; status: string; enabled?: boolean; savedAt?: string; message: string }; type CredentialView = { supported: boolean; unavailable: boolean; connections: SavedCredential[]; scope: string }; -const savedStates: Record = { not_saved: '仅本次内存', saved: '本机加密保存', disabled: '关闭自动加载', source_changed: '配置已变化', decrypt_failed: '无法解密', user_mismatch: '用户不匹配', directory_mismatch: '目录不匹配', unavailable: '保存登记不可用' }; +const savedStates: Record = { reference: '共用上游凭据', not_saved: '仅本次内存', saved: '本机加密保存', disabled: '关闭自动加载', source_changed: '配置已变化', decrypt_failed: '无法解密', user_mismatch: '用户不匹配', directory_mismatch: '目录不匹配', unavailable: '保存登记不可用' }; const states: Record = { configured: '已配置', needs_key: '待填凭据', disabled: '已停用', needs_attention: '需要处理', cooling: '冷却中', completed: '收到响应', failed: '失败', running: '请求中', unknown: '结果待核对', interrupted: '已中断', rejected: '能力不匹配', passed: '通过', attention: '待配置' }; const initial = { modelIdentityAliasesText: '', modelIdentityPolicy: 'record', modelIdentityAliases: [] as string[], modelIdentityAliasSource: '', name: '', brand: '自定义', protocol: 'chat-completions', streaming: false, capabilityDeclarations: { text: 'supported', tools: 'supported', streaming: 'unknown', vision: 'unknown', audio: 'unknown' } as Record, model: '', baseUrl: 'https://api.openai.com/v1', requiresKey: true, enabled: true, contextLimit: 16000, maxOutputTokens: 2048, concurrency: 1 }; const capabilityLabels: Record = { text: '文本', tools: '工具', streaming: '流式', vision: '视觉', audio: '语音' }; @@ -37,6 +39,7 @@ export function ModelCenter({ onConfig, onLegacy, busy, runModel }: { onConfig: 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); const [persistKey, setPersistKey] = useState(false), [persistImports, setPersistImports] = useState(false); const [credentialView, setCredentialView] = useState(null), [credentialKey, setCredentialKey] = useState(''), [credentialTarget, setCredentialTarget] = useState(''); const [pool, setPool] = useState(emptyPool), [poolEditing, setPoolEditing] = useState(false); @@ -111,14 +114,17 @@ export function ModelCenter({ onConfig, onLegacy, busy, runModel }: { onConfig: if (alive.current) { onConfig(result.config); setNotice('等待时限已保存,从下一次运行生效。当前模型路由保持。'); } })} />} {tab === 'connections' && <> -

模型连接

保存多条连接后可在上方切换;添加连接不会替换当前模型。凭据可选择本机加密保存。

+

模型连接

从上游获取目录并选择多个型号,可手动使用或加入自动适配模型池。

+ {catalogSource !== null && setCatalogSource(null)} />}
{view.connections.map(value =>

{value.name}

{value.brand} · {protocolLabel(value.protocol)}{value.streaming ? ' · 流式开启' : ''}
{states[value.status]}
-
模型
{value.model || '尚未填写'}
请求地址
{previewUrl(value)}
{value.protocol === 'anthropic-messages' && <>
鉴权
{value.messagesAuth === 'bearer' ? 'Bearer' : 'x-api-key'} · anthropic-version 2023-06-01
}
凭据
{value.hasKey ? value.savedCredential?.status === 'saved' ? '已设置,可从本机加密保存加载' : '已设置,重启需重新填写' : value.requiresKey ? '尚未填写' : '此服务可不填'}
请求 / 容量
{value.activeRequests} 在途 · 并发 {value.concurrency} · 上下文 {value.contextLimit.toLocaleString()}
+
模型
{value.model || '尚未填写'}
请求地址
{previewUrl(value)}
{value.protocol === 'anthropic-messages' && <>
鉴权
{value.messagesAuth === 'bearer' ? 'Bearer' : 'x-api-key'} · anthropic-version 2023-06-01
}
凭据
{value.credentialSource ? '共用 ' + (view.connections.find(source => source.id === value.credentialSource!.connectionId)?.name ?? '源连接') + (value.hasKey ? ' 的上游凭据' : ';请核对源连接是否启用及凭据') : value.hasKey ? value.savedCredential?.status === 'saved' ? '已设置,可从本机加密保存加载' : '已设置,重启需重新填写' : value.requiresKey ? '尚未填写' : '此服务可不填'}
请求 / 容量
{value.activeRequests} 在途 · 并发 {value.concurrency} · 上下文 {value.contextLimit.toLocaleString()}
+ {value.upstreamModel &&

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

}
{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()}

}