Files
Agent-Workbench/docs/messages-m-evidence/source-bytes/src/shared/contracts/engines.mjs
T

38 lines
2.5 KiB
JavaScript

import { createHash } from 'node:crypto';
export const ENGINE_ACTIVE = new Set(['queued', 'starting', 'initializing', 'checking', 'stopping']);
export const ENGINE_SCOPE = 'deepseek-sdk-connection-probe';
export const ENGINE_LIMITS = Object.freeze([
'当前接入核验启动、会话目录、协议错误和关闭;工程执行接入开发中。',
'SDK没有单会话cancel或close;停止以所属独立进程为单位。',
'SDK serverInfo.version与发行包版本分别核对,没有有效协议版本协商。',
'SDK事件覆盖运行时会话树,idle事件不能直接判项目交付完成。',
]);
export const engineError = (message, status = 409, code = 'ENGINE_CONTRACT') => Object.assign(new Error(message), { status, code });
export const engineDigest = value => createHash('sha256').update(typeof value === 'string' ? value : JSON.stringify(value), 'utf8').digest('hex');
const canonical = value => Array.isArray(value) ? value.map(canonical) : value && typeof value === 'object'
? Object.fromEntries(Object.keys(value).sort().map(key => [key, canonical(value[key])])) : value;
export const engineCanonicalDigest = value => engineDigest(canonical(value));
export function engineInput(job) {
return { schemaVersion: 1, jobId: job.id, sessionId: job.sessionId, projectId: job.projectId,
taskId: job.taskId, runId: job.runId, engineId: job.engineId, scope: job.scope,
installation: job.installation, sdkSessionId: job.sdkSessionId, directory: job.directory,
protocolMethods: ['initialize', 'session/working-directory/get', 'session/wait', 'session/resume', 'session/cancel', 'shutdown'],
modelRequestsAllowed: 0, externalProjectToolsAllowed: false };
}
export function engineReportContract(job) {
return { schemaVersion: 1, inputSha256: job.contractSha256, owner: { sessionId: job.sessionId,
projectId: job.projectId, taskId: job.taskId, runId: job.runId, jobId: job.id },
engineId: job.engineId, scope: job.scope, installationSha256: job.installation.identitySha256,
sdkSessionId: job.sdkSessionId, outcome: { status: job.status, error: job.error ?? null, verification: job.verification }, report: job.report };
}
export function publicEngineJob(job) {
const { report, ...value } = job;
return { ...value, reportSummary: report ? { status: report.status, modelRequests: report.modelRequests,
providerRequests: report.providerRequests, observedResponses: report.responses?.length ?? 0,
rootExited: report.cleanup?.rootExited ?? null } : null };
}