@sema-agent/core
Version:
Stateless, task-oriented AI agent core
59 lines (58 loc) • 5.28 kB
TypeScript
/**
* `Runner.rewindConversation`'s request and answer — the out-of-run conversation rewind (the reference's `rewind_conversation`, the twin
* of `Runner.rewindFiles`). The verb itself is `src/core/runner/rewind-conversation.ts`.
*/
import type { SessionRowExpectation } from "./session.js";
import type { TaskSpec } from "./task-spec.js";
/** `Runner.rewindConversation`'s request — a plain data object; the keys are a closed set. */
export interface RewindConversationRequest {
/** The session whose conversation is rewound. It must exist. */
sessionId: string;
/** The entry id of the person's words that opened the turn to take back — the id space `Runner.rewindFiles` `to` and `TaskSpec.resumeAt`
* address (a `message_committed` `entryId` with `origin: "human_input"`). The leaf lands on its parent: that turn and every later one
* leave the branch. The first turn's too (the session's pin); a message that is the log's root (an older or imported log) has nothing
* before it (`resume_at.before_root_unsupported`). An engine row (an interruption marker, a queued note) is no turn's opening
* (`resume_at.before_target_not_user`). It must be on the session's CURRENT branch — the turns go back along it, never sideways onto a
* branch taken back earlier (`rewind.target_off_branch`; a run's `resumeAt` is what continues from another branch). A session that
* already stands at the landing answers before this is read, so a retry of a rewind that landed is answered the same. */
to: string;
/** Preview only — `RewindFilesRequest.dryRun`'s member and meaning: every door and judgment of the rewind, in its order and with its
* refusal codes, then its answer (`dryRun: true`, the `leafId` it would land on, the `previousLeafId` the session stands on), and no
* write of its own — no `leaf` entry, no row; its reads are the rewind's, and so is what a store does on any acquire (a TTL store's
* sweep of sessions past their time — the previewed session itself included, then answered `resume.session_not_found` — and the file
* storage backend's repair of a torn log tail when it first takes the session). It reserves nothing: a rewind sent
* after it judges the session as it stands then (send the same `lastSeenInput` on both to refuse a person's turn that arrived in
* between; its `previousLeafId` says what it took back). Absent or `false` ⇒ the rewind. */
dryRun?: boolean;
/** The `entryId` of the newest person's message the caller has shown (`message_committed` with `origin: "human_input"`): it must be on
* the session's current branch, and no row after it may state that it is a person's input (`origin: "human_input"`), or nothing is
* rewound (`rewind.unseen_later_turn` — a turn the caller has not seen would be taken back unseen). A row written before rows stated
* their source (no `origin` member) counts as no later turn — on such a log an engine note after the row is no reason to refuse, and a
* person's later words written then are not caught either. Absent ⇒ not judged. A session that already stands at the landing answers
* before this is read. */
lastSeenInput?: string;
/** The occupant the caller read the session as: `{ row: { owner, incarnation } }` (a `SessionHead` serves as `row`) — the session under
* `sessionId` must still be that row, or nothing is rewound and the answer is `resume.session_not_found`. `row: null` and `log` are
* refused (`rewind.invalid_spec`). Absent ⇒ any session under the id. The same member, read the same way, as `RewindFilesRequest.expect`. */
expect?: SessionRowExpectation;
/** The checkpoint store the session's runs park in, when a run named its own (`TaskSpec.checkpointStore`): the same three-valued seat,
* read by the same one resolver — absent falls through to the deployment's `RunnerDeps.checkpointStore`, `"disabled"` says the session
* has no store. The parked-session check asks the store this names. */
checkpointStore?: TaskSpec["checkpointStore"];
/** The grant the host's verb acts under — the member `CompactSessionRequest.holder` states, met by the same door (refused here as
* `rewind.invalid_spec`, nothing rewound). The `leaf` entry the rewind writes carries it; a grant the store does not hold current
* refuses that write: `holder.superseded`, nothing written — do not retry. */
holder?: string;
}
/** `Runner.rewindConversation`'s answer. A refusal is a thrown `Error` carrying a `code` — a preview's the same code the rewind would
* throw, at the same door. */
export interface RewindConversationResult {
/** The request's `dryRun`, as `RewindFilesResult.dryRun` states it: `true` ⇔ nothing was written and the two leaves are what the
* rewind would answer now. */
dryRun: boolean;
/** The leaf the session stands on now — with `dryRun`, the leaf the rewind would land on: the parent of `to`. */
leafId: string;
/** The leaf the session stood on before — with `dryRun`, the leaf it stands on; equal to `leafId` when it already stood there
* (nothing was written, or would be). */
previousLeafId: string | null;
}