import type { Agent, CheckpointedIRWithTrajectories, LoweredIR } from "./llm-ir.ts"; export function lower>( messages: Array>, ): Array> { const output: Array> = []; for (const ir of sliceFromMostRecentCheckpoint(messages)) { if (ir.role === "checkpoint") { output.push({ role: "lowered-checkpoint", content: ir.content, }); continue; } if (ir.role === "trajectory") { throw new Error("Subagent trajectory lowering is not implemented yet"); } output.push(ir); } return output; } function sliceFromMostRecentCheckpoint(messages: T[]): T[] { return messages.slice(findMostRecentCheckpointIndex(messages)); } function findMostRecentCheckpointIndex(messages: Array<{ role: string }>): number { for (let i = messages.length - 1; i >= 0; i--) { if (messages[i].role === "checkpoint") return i; } return 0; }