UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

46 lines • 2.12 kB
import { stopResumeDirective } from "./stop-resume-directive.js"; function partsOf(content) { return typeof content === "string" ? [{ type: "text", text: content }] : [...content]; } /** * The turn after a Stop or a parent's run Resume (senpi#3811), as ONE message so it is one turn: held human input * first, then the wakes held while paused, then the directive naming the interrupted turn. Answers once that turn * started, or once the send settled without starting one (a newer Stop during admission), so a resume never waits on * a turn that will not come. `delivered` is the one settlement rule both resume paths share: it hands the held input * and wakes to `consume` only if the turn started, its send succeeded, and no newer Stop aborted it. */ export async function startRunResumeTurn(ports) { const inputs = ports.heldInputs(); const continues = ports.continueInputs(); const wakes = ports.heldWakes(); const directive = stopResumeDirective(ports.resumeCause); const content = [ ...inputs.flatMap((input) => [ { type: "text", text: `The user wrote while the run was paused:\n${input.text}` }, ...(input.images ?? []), ]), ...wakes.flatMap((wake) => partsOf(wake.message.content)), ...partsOf(directive.content), ]; const sendSettled = Promise.withResolvers(); const started = ports.turnStarted(sendSettled.promise); const sending = ports.send({ ...directive, content, display: inputs.length > 0 }); sending.then(sendSettled.resolve, sendSettled.resolve); const turnId = await started; const delivered = (async () => { await ports.idle(); try { await sending; } catch (error) { ports.sendFailed(error); return false; } if (turnId === undefined || !ports.current()) return false; ports.consume([...inputs.map((input) => input.inputId), ...continues], wakes.map((wake) => wake.source)); return true; })(); return { turnId, delivered }; } //# sourceMappingURL=run-resume-turn.js.map