@sema-agent/core
Version:
Stateless, task-oriented AI agent core
52 lines (51 loc) • 4.66 kB
TypeScript
/**
* What a `resume_at.outside_window` refusal says in machine-readable form: which of its two arms refused, and the ways out the refusal's
* own sentence names. The code is one word for two different facts — the store the request landed on does not hold the branch the landing
* continues whole (`branch_not_held`), and the landing is a user message whose attachment frames the handle cannot read
* (`attachment_frames_unreadable`) — and only the second sentence names a way out. A reader that holds the code alone cannot tell them apart.
*
* It rides the refusal as the thrown error's `detail`, so a failed run carries it as `TaskResult.terminal.detail` (`kind: "coded"`,
* `detail: ResumeAtOutsideWindowDetail`, beside `terminal.code === "resume_at.outside_window"`). Both members are always present on this
* code: `remedies: []` is the refusal saying it names no way out (the store arm), never an absent member — a refusal with no `detail` at all
* (an engine from before this one) is "not known", and the two must not be read as the same answer. `remedies[].kind` is an OPEN set to a
* reader (a later engine may name another way out): a kind it does not know is shown as no sentence of its own, never guessed at.
*
* ONE SOURCE. The reason words, the remedy words and which reason names which remedies are written once, here; the refusal reads
* {@link resumeAtOutsideWindowDetail} and the sentence stays where it was minted (`runner/branch-window.ts`).
*/
import type { AssertAllKeysHandled } from "./ask-origin.js";
/** Which arm refused — the closed set of {@link ResumeAtOutsideWindowDetail.reason}. `branch_not_held`: the store's loaded part of the log
* does not hold the branch the landing continues whole (the entry it would continue from is not held, or the store's read of the branch
* stops at its floor with no compaction keeping from there) — or, for `Runner.rewindConversation`, its read of the session's current
* branch stops at its floor without the entry the request names. `attachment_frames_unreadable`: an `at` landing whose attachment frames
* cannot be read — the handle does not hold the entry it continues from and the store has no successor read — so where the frames end is
* not known. */
export declare const RESUME_AT_OUTSIDE_WINDOW_REASONS: readonly ["branch_not_held", "attachment_frames_unreadable"];
export type ResumeAtOutsideWindowReason = (typeof RESUME_AT_OUTSIDE_WINDOW_REASONS)[number];
/** The ways out a `resume_at.outside_window` sentence names — the closed set of {@link ResumeAtRemedy.kind} today. `retry_on_handle_holding_message`:
* retry on a handle that holds the entry the landing continues from (the whole log, or that entry's own branch). `resume_at_mode_before`: rewind
* with `resumeAtMode: "before"` to drop the message, then send it again with its attachments — named only when the target is a person's message
* (the one target that mode takes). */
export declare const RESUME_AT_REMEDY_KINDS: readonly ["retry_on_handle_holding_message", "resume_at_mode_before"];
export type ResumeAtRemedyKind = (typeof RESUME_AT_REMEDY_KINDS)[number];
/** One way out, discriminated by `kind` ({@link RESUME_AT_REMEDY_KINDS}). A reader treats the kind set as open. */
export interface ResumeAtRemedy {
readonly kind: ResumeAtRemedyKind;
}
/** The `detail` of a `resume_at.outside_window` refusal. */
export interface ResumeAtOutsideWindowDetail {
/** Which arm refused ({@link RESUME_AT_OUTSIDE_WINDOW_REASONS}). */
readonly reason: ResumeAtOutsideWindowReason;
/** The ways out the refusal's sentence names, in its order; EMPTY when it names none (always present — see the module note). */
readonly remedies: readonly ResumeAtRemedy[];
}
/** The ways out each reason's sentence names, in the sentence's order — the table is total over the reasons (a reason with no row is a red build). */
declare const REMEDY_KINDS_OF_REASON: {
readonly branch_not_held: readonly [];
readonly attachment_frames_unreadable: readonly ["retry_on_handle_holding_message", "resume_at_mode_before"];
};
export type ResumeAtRemedyTableCoversEveryReason = AssertAllKeysHandled<Exclude<ResumeAtOutsideWindowReason, keyof typeof REMEDY_KINDS_OF_REASON>>;
/** The `detail` for a refusal of `reason`: a fresh object, its remedies read off the one table — less `resume_at_mode_before` when the target
* is not one that mode takes (`takesBefore: false`), as the sentence then does not name it. */
export declare function resumeAtOutsideWindowDetail(reason: ResumeAtOutsideWindowReason, takesBefore?: boolean): ResumeAtOutsideWindowDetail;
export {};