22 lines
1.7 KiB
JavaScript
22 lines
1.7 KiB
JavaScript
import { randomUUID } from 'node:crypto';
|
|
import { call } from '../helpers.mjs';
|
|
import { readText } from '../../src/server/files.mjs';
|
|
|
|
export const readingStep = (key = 'read', depends_on = []) => ({ key, title: '读取实际工程', criterion: '实际读取本工程文件并保留原结果', kind: 'analysis', tools: ['read_file'], depends_on });
|
|
export const checksStep = (key = 'check', depends_on = []) => ({ key, title: '检查工程', criterion: '所选测试与构建实际通过', kind: 'checks', checks: ['test', 'build'], depends_on });
|
|
export function beginPlanTask(f, goal = '检查工程并按真实证据交付') {
|
|
const run = f.store.beginRun(f.session, goal, false, f.store.config);
|
|
f.session.status = 'paused'; f.store.finishRun(f.session, run, 'plan_ready'); return run;
|
|
}
|
|
export function completeRead(f, relative = 'README.md') {
|
|
const run = f.store.core.run.get(f.session.runId), invocation = call('plan-read-' + randomUUID(), 'read_file', { path: relative });
|
|
f.session.providerMessages.push({ role: 'assistant', content: '', tool_calls: [invocation] });
|
|
const event = f.store.event(f.session, { kind: 'tool', toolCallId: invocation.id, tool: 'read_file', phase: 'queued', label: '实际文件读取' });
|
|
const record = f.store.beginInvocation(f.session, invocation, run, event);
|
|
f.store.invocationState(f.session, event, 'running');
|
|
const result = { ...readText(f.project, relative), tool_invocation_id: record.id };
|
|
event.phase = 'completed'; f.store.finishInvocation(f.session, event, result);
|
|
f.session.providerMessages.push({ role: 'tool', tool_call_id: invocation.id, content: JSON.stringify(result) }); f.store.save(f.session);
|
|
return record;
|
|
}
|