feat: preserve bounded model requests and complete task history

This commit is contained in:
Agent Workbench Dev
2026-10-29 21:09:50 +08:00
parent 19b738b468
commit 8f32dec6cc
58 changed files with 1269 additions and 108 deletions
+19
View File
@@ -0,0 +1,19 @@
import { createHash } from 'node:crypto';
export function completionBody(config, messages, tools) {
return { model: config.model, messages, tools, tool_choice: 'auto', max_tokens: config.maxOutputTokens, stream: false };
}
export function requestMetrics(body) {
const serialized = JSON.stringify(body);
const bytes = Buffer.byteLength(serialized, 'utf8');
return { bytes, sha256: createHash('sha256').update(serialized, 'utf8').digest('hex'),
estimatedInputTokens: Math.ceil(bytes / 3) + body.messages.length * 8 + (body.tools?.length ?? 0) * 16,
estimateMethod: 'utf8-third-plus-framing-v1' };
}
export function assertPlannedRequest(body, plan) {
if (!plan) return;
const metrics = requestMetrics(body);
if (metrics.sha256 !== plan.requestSha256 || metrics.bytes !== plan.requestBytes) throw new Error('模型请求正文与已保存计划不一致,未发送请求。');
}