feat(models): register protocols and evidence-bound capabilities

This commit is contained in:
Agent Workbench Dev
2026-10-31 21:56:41 +08:00
parent 299fb14234
commit 578cf88eca
9 changed files with 154 additions and 4 deletions
+1
View File
@@ -4,6 +4,7 @@
*.png binary
*.jpg binary
*.ico binary
docs/model-protocols-*.txt -text
docs/companion-a-b-evidence/*.tap binary
docs/companion-c-e-evidence/**/*.tap binary
docs/companion-c-e-evidence/*.tap binary
+9
View File
@@ -0,0 +1,9 @@
# 1.17 模型协议、流式执行与能力路由验收
基线299fb14/正式1.16.0,在feat/model-protocols-1.17开发。开发使用自有项目/loopback服务/数据与凭据;正式Provider与数据保持,真实模型工程与Purge收益单独待验。阶段未完整验收前不部署或宣称1.17已交付。
## A:协议与能力登记
新增Chat Completions/Responses协议登记和版本化能力声明。文本、工具、流式、视觉与语音分别显示声明、未知、不支持、已验证;后者绑定连接修订及凭据修订,客户端提交不能伪造。旧schema:1记录只读兼容,读取不迁移原记录,原DPAPI绑定仍使用原协议/接口/模型身份。流式开关默认关闭,必须先明确声明支持。
18/18相关检查通过,包含旧模型池/请求身份/导入事务/热升级以及新能力声明、失效、未知筛选和失败回滚。原TAP见[专项结果](model-protocols-a-specialists.txt)。本切片尚不代表Responses请求或流式已实现;它们在B/C独立验收。全阶段发行、UI与工程门槛仍待执行。
+5
View File
@@ -0,0 +1,5 @@
# 1.17 切片回顾
## A:能力来源与旧连接
保留原schema:1和默认Chat连接,新增的能力信息放在每个连接上。声明不能当成实测,实测必须跟随实际连接和凭据修订;未知视觉/音频保持未知,不从模型名猜测。原模型池/导入/热升级和能力专项18项通过,未访问正式Key或发送真实模型请求。B/C继续实现实际协议和流式,A通过不能代表它们已交付。
+26
View File
@@ -0,0 +1,26 @@
✔ schema1 connections remain readable without inventing observed capabilities or migrating original state (993.7387ms)
✔ protocol, unsupported capabilities and stream choice persist; client claims cannot forge verified evidence (1262.8972ms)
✔ ability evidence belongs to exact connection and credential revision; unknown and unsupported reject required routing (0.2789ms)
✔ invalid declarations and inconsistent stream settings reject before registry, revision and credentials mutate (1249.8472ms)
✔ model registry keeps original credentials/endpoint intact, rejects stale edits, and forgets only volatile keys on restart (1447.1195ms)
✔ config import previews exact revisions, keeps secrets volatile, syncs only when enabled and preserves manual edits on conflicts (1141.502ms)
✔ real HTTP pool fails over 429 to another model and never repeats completed tools; attempts seal actual request bytes and Run identity (3887.3408ms)
✔ pool rotation and weights select members on new Runs; disabled and missing credentials are excluded without requests (3709.6143ms)
✔ 401 blocks the credential revision; updating the key restores availability without leaking error echoes (1282.2837ms)
✔ queued request cancellation and in-flight disable release only owned leases and do not dispatch another HTTP request (807.0351ms)
✔ compiled model-center HTTP API persists public profiles, blocks forged origins, and local operations never invoke a model (1915.174ms)
✔ model registry disk failures restore routing, pool profiles and credential references without partial updates (633.2153ms)
✔ model selection and saved configuration commit together and failures preserve the original mode and endpoint (651.1629ms)
✔ configuration imports roll back the entire batch and retain one usable preview after validation or commit failure (615.3665ms)
✔ hot upgrade adopts a retained virtual data root without reopening SQLite or changing rows, Provider or routing (1435.7982ms)
✔ failed adoption restores the original virtual data-root name and original open database (857.4231ms)
✔ hot upgrade refreshes retained model and importer methods while preserving credential and routing objects (940.5107ms)
✔ hot upgrade refuses active probes and restores retained model methods if installation fails (841.6437ms)
ℹ tests 18
ℹ suites 0
ℹ pass 18
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 16212.7253
+5
View File
@@ -815,3 +815,8 @@ formal-stage已成功,12:28:12Z→12:38:20Z约10分9秒;真实产品setup/
收尾复核:正式原生窗口截图已目视核对,1.16.0、服务连接和手机入口可见,窗口保持开启。封存274份原件共74928077字节,79份JSON、34份mjs/cjs语法及16份文档的324个本地链接通过;378输入/22构建/40基准保持。补正AGENTS当前服务身份和1.17方案的连接状态表述,避免沿用1.15的旧Key记录。最终仅提交本轮文档/证据,原包体不回写,之后生成带最终commit的独立ACCEPTANCE说明。
最终不可变20261031114604110、来源52f0d20;独立源码519/519、24类186组历史UI、实际Electron窗口7项、原生流程9组、三工程16节点及父Node8/8、React9/9、Python10/10通过;源码与便携各7组手机流程、同载荷隔离安装/重启/卸载7组、正式桌面/390px共20页通过。正式PID36552/Provider保持,17项目/30全部会话/2590记录/4653事件、全部表每行/会话导出/工件原字节保持;1455条工件及1366个去重文件核对通过,9229关闭。iPhone 14 Pro Max/iOS 27.2为用户提供;用户确认信任、配对、原审批、差异/报告SHA、主屏幕、锁屏、切网恢复、停止及撤销,原宿主审计/进程/文件另行核对,无手机截图。正式手机网关默认关闭、无设备/证书;QA证书与设备身份没有迁入。验收手机监听已关闭并释放4321,4320管理及原数据保留。真实模型工程和Purge推理收益继续按用户选择单独待验,本轮真实模型请求为0。最终274份原字节证据封存,发行身份/QA/回顾/能力矩阵/执行计划和下一阶段方案已同步。原响应式QA失败和提前启动失败独立保留,成功来自source-retry完整独立整轮。所有378输入/22构建/40基准保持冻结,后续说明修改不重跑已通过的产品检查。下一1.17仍仅方案,未开始产品变更。
## 2026-10-31 1.17 启动
基线299fb14与干净工作区已核对,新分支feat/model-protocols-1.17。按A–F实现协议/能力、Responses适配、Chat与Responses流式、能力选池及界面/工程发行。复用原轮询/租约/粘连/冷却、DPAPI与Task/Run,不触碰正式配置。官方OpenAI迁移文档已实际读取;工具调用身份/结果配对、store:false、手工Items与typed SSE终结作为协议约束,真实模型收益单独待验。一次规划补丁因猜测progress标题整批拒绝,未发生部分写入;改为已知task_plan锚点和追加日志。只读检索误猜src/core/runtime目录已确认不存在,实际运行器为src/server/runtime.mjs。
1.17 A能力登记18/18通过(新4项+原模型中心/升级14项),旧schema1无写入迁移、能力声明不能伪造已验证,流式选择先声明;正式未动。误猜upgrade.mjs/build.mjs只读失败后通过rg定位hot-upgrade.mjs/build-server.mjs,后续不再猜路径。A回顾与原TAP保存;B/C将新增Responses实际请求、保留reasoning Items和有界终结SSE,混合协议池按各实际请求封存并保守预算。
+10 -3
View File
@@ -2,6 +2,7 @@ import { randomUUID, createHash } from 'node:crypto';
import { setTimeout as delay } from 'node:timers/promises';
import { ModelRequestError } from '../../server/diagnostics.mjs';
import { CredentialVault } from './credential-vault.mjs';
import { modelProtocol, capabilityDeclarations, capabilityView } from '../../shared/contracts/model-capabilities.mjs';
const legacyId = 'legacy-default';
const stamp = () => new Date().toISOString();
@@ -107,7 +108,8 @@ export class ModelHub {
...(this.credentialVault ? { savedCredential: this.credentialVault.status(connection) } : {}),
status: !connection.enabled ? 'disabled' : !ready ? 'needs_key' : health?.blocked ? 'needs_attention' : health?.cooldownUntil > Date.now() ? 'cooling' : 'configured',
activeRequests: this.leases.get(connection.id) ?? 0, health: health ?? { state: 'unverified' },
capabilities: { tools: 'protocol_declared', vision: 'unknown', audio: 'unknown' } };
streaming: connection.streaming === true, capabilitySchema: 1, capabilityDeclarations: capabilityDeclarations(undefined, connection.capabilityDeclarations),
capabilities: capabilityView(connection, credential?.revision ?? 0) };
}
view() { return { revision: this.state.revision, selected: this.state.selected, connections: this.connections().map(value => this.status(value)), pools: this.state.pools,
imports: Object.entries(this.state.imports).map(([id, value]) => ({ id, ...value })), attempts: this.attempts.slice(-100).reverse(), waiting: this.waiting,
@@ -119,10 +121,15 @@ export class ModelHub {
const previous = input.id ? this.connection(input.id) : null;
if (this.state.connections.length >= 100 && !previous) throw error('最多保存100个模型连接。');
if (previous && input.revision !== previous.revision) throw error('模型连接已修改,请刷新后重试。', 409);
if (input.protocol && input.protocol !== 'chat-completions') throw error('当前接入仅支持经过验证的 Chat Completions 协议。');
const protocol = modelProtocol(input.protocol ?? previous?.protocol ?? 'chat-completions');
const declarations = capabilityDeclarations(input.capabilityDeclarations, previous?.capabilityDeclarations);
if (input.streaming !== undefined && typeof input.streaming !== 'boolean') throw error('流式选项必须为开启或关闭。');
const streaming = input.streaming ?? previous?.streaming ?? false;
if (streaming && declarations.streaming !== 'supported') throw error('请先声明服务支持流式输出,再开启流式请求。');
const name = label(input.name), model = label(input.model, 200);
if (!name || !model) throw error('请填写连接名称和实际模型名称。');
const connection = { id: previous?.id ?? randomUUID(), name, brand: label(input.brand || '自定义', 40), protocol: 'chat-completions', model,
const connection = { id: previous?.id ?? randomUUID(), name, brand: label(input.brand || '自定义', 40), protocol, model,
capabilitySchema: 1, capabilityDeclarations: declarations, streaming,
baseUrl: modelEndpoint(input.baseUrl), enabled: input.enabled !== false, requiresKey: input.requiresKey !== false,
contextLimit: bounded(input.contextLimit, 16000, 1000, 200000), maxOutputTokens: bounded(input.maxOutputTokens, 2048, 256, 16000),
concurrency: bounded(input.concurrency, 1, 1, 8), revision: (previous?.revision ?? 0) + 1,
@@ -0,0 +1,36 @@
export const MODEL_PROTOCOLS = ['chat-completions', 'responses'];
export const MODEL_CAPABILITIES = ['text', 'tools', 'streaming', 'vision', 'audio'];
const failure = message => Object.assign(new Error(message), { status: 400 });
export function modelProtocol(value = 'chat-completions') {
if (!MODEL_PROTOCOLS.includes(value)) throw failure('请选择已接入的 Chat Completions 或 Responses 协议。');
return value;
}
export function capabilityDeclarations(input, previous = null) {
const result = { text: 'supported', tools: 'supported', streaming: 'unknown', vision: 'unknown', audio: 'unknown', ...previous };
if (input === undefined) return result;
if (!input || typeof input !== 'object' || Array.isArray(input)) throw failure('模型能力声明格式无效。');
for (const [key, value] of Object.entries(input)) {
if (!MODEL_CAPABILITIES.includes(key) || !['supported', 'unsupported', 'unknown'].includes(value)) throw failure('能力只能声明支持、不支持或未知,不能自行标为已验证。');
result[key] = value;
}
return result;
}
export function capabilityView(connection, credentialRevision = 0) {
const declarations = capabilityDeclarations(undefined, connection.capabilityDeclarations);
const evidence = connection.capabilityEvidence;
const current = evidence?.connectionRevision === connection.revision && evidence?.credentialRevision === credentialRevision;
return Object.fromEntries(MODEL_CAPABILITIES.map(key => [key,
declarations[key] === 'unsupported' ? 'unsupported' : current && evidence.results?.[key] === 'verified' ? 'verified'
: declarations[key] === 'supported' ? 'protocol_declared' : 'unknown']));
}
export function capabilityRejections(connection, requirements, credentialRevision = 0) {
const view = capabilityView(connection, credentialRevision);
return requirements.filter(key => !['verified', 'protocol_declared'].includes(view[key])).map(capability => ({
connectionId: connection.id, connectionName: connection.name, capability, state: view[capability] ?? 'unknown',
reason: view[capability] === 'unsupported' ? '连接明确声明不支持所需能力' : '连接尚未声明或验证所需能力',
}));
}
+12 -1
View File
@@ -1,6 +1,17 @@
# Agent Workbench:核心代理能力研究与产品计划
## 2026-10-31 当前任务:1.16 手机伴随端
## 2026-10-31 当前任务:1.17 模型协议、流式执行与能力路由
用户授权下一阶段全量开发并及时回顾。基线299fb14/正式1.16.0,在feat/model-protocols-1.17按PLAN-1.17推进。正式PID36552/Provider和数据保持,开发使用自有loopback服务/独立数据/端口,不读取真实Key、不发真实模型请求;真实收益验收继续单列。不新建代理/goal/automation/chat。
1. [complete] A:协议/能力声明与修订绑定已实现,旧模型中心/导入/热升级及新增能力18/18专项通过,见QA-1.17;不将声明当实际协议执行。
2. [in_progress] B:Chat Completions与新增Responses的实际请求、消息/工具结果/原用量适配;请求封存绑定实际协议字节,保留旧证据。
3. [pending] C:两协议增量文本与工具片段、有界SSE、终结校验/停止/断开/迟到保护;完整参数与终结前不执行工具,不自动重放。
4. [pending] D:复用租约/轮询/粘连/冷却,按任务所需能力筛选及明确拒绝;401/429/超时/中断分类和有界切换。
5. [pending] E:协议/能力/检测范围、选池与当前流状态的桌面/390px/手机对应流程;保留品牌与真实任务布局,实际渲染与操作验收。
6. [pending] F:三工程/故障验证、完整历史回归、独立源码/便携/安装、保留状态部署、证据/文档封存及本地Git;逐切片回顾。
## 2026-10-31 已交付:1.16 手机伴随端
用户授权全阶段开发并及时回顾。以06c9fac/正式1.15.0为基线,在feat/mobile-companion-1.16实施PLAN-1.16六个切片。用户选择iPhone,可配合手机证书信任;Windows提供HTTPS服务,同Wi-Fi的iPhone Safari/PWA实际联调。开发使用自有数据/端口/凭据,保留正式宿主与Provider;不读取真实Key、不发送真实模型请求,不新建代理/goal/automation/chat。
+50
View File
@@ -0,0 +1,50 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { fixture } from './helpers.mjs';
import { Provider } from '../src/server/provider.mjs';
import { Store } from '../src/server/store.mjs';
import { capabilityView, capabilityRejections } from '../src/shared/contracts/model-capabilities.mjs';
const input = { name: 'Owned Responses', model: 'owned-model', protocol: 'responses', baseUrl: 'http://127.0.0.1:12345/v1', requiresKey: false };
test('schema1 connections remain readable without inventing observed capabilities or migrating original state', t => {
const f = fixture(t), provider = new Provider();
const original = { schema: 1, revision: 4, selected: { type: 'connection', id: 'owned-old' }, pools: [], imports: {},
connections: [{ ...input, protocol: 'chat-completions', id: 'owned-old', revision: 1, enabled: true }] };
f.store.storage.setMeta('modelRegistry', original);
const hub = provider.modelHub(f.store), old = hub.view().connections.find(item => item.id === 'owned-old');
assert.equal(old.capabilities.tools, 'protocol_declared'); assert.equal(old.capabilities.streaming, 'unknown');
assert.equal(old.capabilities.vision, 'unknown'); assert.equal(old.capabilities.audio, 'unknown');
assert.deepEqual(f.store.storage.meta('modelRegistry'), original);
});
test('protocol, unsupported capabilities and stream choice persist; client claims cannot forge verified evidence', t => {
const f = fixture(t), provider = new Provider(), hub = provider.modelHub(f.store);
const connection = hub.upsert({ ...input, streaming: true, apiKey: 'owned-volatile', capabilityDeclarations: { tools: 'unsupported', streaming: 'supported' },
capabilityEvidence: { results: { tools: 'verified' } } });
assert.equal(connection.protocol, 'responses'); assert.equal(connection.capabilities.tools, 'unsupported');
assert.equal(connection.capabilityEvidence, undefined); assert.equal(connection.capabilities.streaming, 'protocol_declared');
assert.equal(JSON.stringify(f.store.storage.meta('modelRegistry')).includes('owned-volatile'), false);
assert.throws(() => hub.upsert({ ...input, protocol: 'unknown' }), /协议/);
f.store.close(); const reopened = new Store(f.data); f.onCleanup(() => reopened.close());
const restored = new Provider().modelHub(reopened).connection(connection.id);
assert.equal(restored.streaming, true); assert.equal(restored.capabilityDeclarations.tools, 'unsupported');
assert.equal(restored.protocol, 'responses');
});
test('ability evidence belongs to exact connection and credential revision; unknown and unsupported reject required routing', () => {
const connection = { ...input, id: 'owned', revision: 3, capabilityDeclarations: { text: 'supported', tools: 'unknown', streaming: 'unsupported' },
capabilityEvidence: { connectionRevision: 3, credentialRevision: 7, results: { tools: 'verified', text: 'verified' } } };
assert.equal(capabilityView(connection, 7).tools, 'verified');
assert.equal(capabilityView(connection, 8).tools, 'unknown');
assert.deepEqual(capabilityRejections(connection, ['text', 'tools', 'streaming'], 7).map(item => item.capability), ['streaming']);
assert.deepEqual(capabilityRejections({ ...connection, revision: 4 }, ['text', 'tools'], 7).map(item => item.capability), ['tools']);
});
test('invalid declarations and inconsistent stream settings reject before registry, revision and credentials mutate', t => {
const f = fixture(t), provider = new Provider(), hub = provider.modelHub(f.store), connection = hub.upsert(input);
const before = structuredClone(hub.state);
for (const change of [{ capabilityDeclarations: { tools: 'verified' } }, { capabilityDeclarations: { invented: 'supported' } }, { streaming: true }, { streaming: 'yes' }]) {
assert.throws(() => hub.upsert({ ...connection, ...change, apiKey: 'owned-should-not-save' }));
assert.deepEqual(hub.state, before); assert.equal(provider.credentials.has(connection.id), false);
}
});