@sema-agent/core
Version:
Stateless, task-oriented AI agent core
15 lines (14 loc) • 776 B
JavaScript
export function rewindOutcomeOf(spec) {
if (spec.resumeAt === undefined && spec.rewindFilesTo === undefined && spec.restoreFiles === undefined)
return undefined;
return { moved: "none", branch: "untouched" };
}
export function rewindSettlementOf(outcome) {
return { moved: outcome.moved, ...(outcome.branch !== undefined ? { branch: outcome.branch } : {}) };
}
export function withRewindOutcome(result, outcome) {
if (outcome === undefined)
return result;
const terminal = result.terminal.kind === "failed" || result.terminal.kind === "blocked" ? { ...result.terminal, rewind: rewindSettlementOf(outcome) } : result.terminal;
return { ...result, terminal, ...(outcome.restore !== undefined ? { fileRestore: outcome.restore } : {}) };
}