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
+1 -1
View File
@@ -2,7 +2,7 @@ import { randomUUID } from 'node:crypto';
export const EXECUTION_SCHEMA = 1;
export const ACTIVE_STATES = new Set(['running', 'awaiting_approval', 'stopping']);
export const CORE_KINDS = ['task', 'run', 'step', 'tool', 'artifact', 'check_plan', 'check_job', 'delivery_plan', 'delivery_job', 'change_set'];
export const CORE_KINDS = ['task', 'run', 'step', 'tool', 'artifact', 'check_plan', 'check_job', 'delivery_plan', 'delivery_job', 'change_set', 'context_plan'];
export const timestamp = () => new Date().toISOString();
export const isId = value => typeof value === 'string' && /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(value);
+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('模型请求正文与已保存计划不一致,未发送请求。');
}