@sema-agent/core
Version:
Stateless, task-oriented AI agent core
199 lines (198 loc) • 19.1 kB
TypeScript
/**
* `delegation.ask_unresolvable` — the one mint of the notice the gate raises when an `ask` reached its
* final deny with NOBODY having judged it. Four ways that happens, one event class ("a call was denied
* fail-closed because its approval could not be resolved"), one closed cause set:
* · `approver_unavailable` — the approver consulted for the call (the run's own seat, or an ancestor's
* frozen seat on a delegated child) answered the ROUTING question `unavailable` and no durable park
* took the call afterwards (`tool_end.gate.settlement.kind:"approver_unavailable"`);
* · `no_approver_wired` — nobody in this run can be asked: no approver (or, for a question, no question face) is
* wired, the seat is the deny posture string, or the run declared that nobody on it can be asked
* (`approvalReach: "none"`): the headless auto-deny (`settlement.kind:"no_approver"`);
* · `mandate_unreconstructible` — an inherited durable-approval mandate binds the ask and THIS leg has no
* park facility to honor it, so the delegated child refuses in-fold rather than let a synchronous layer
* resolve what its ancestor bound to a park (an in-fold deny; no settlement rides the frame);
* · `approval_window_expired` — the approver consulted (the run's own seat, or an ancestor's frozen seat) answered the
* routing answer `window_expired` — its own approval window for the card closed with no one answering — and no durable
* park took the call afterwards (`settlement.kind:"approval_window_expired"`, `who.party:"host"`; a host's own
* `settledBy: "timeout"` shares that word and is no unresolved ask).
* The deny itself is older than this notice and stands unchanged (the model reads the sentence as its
* tool result); what was missing was any face a PERSON watching notices could see — an operator reading
* notices alone saw nothing, and the person whose work was refused learned it only from a transcript.
*
* ONE exit composes it: the gate's single deny exit (`exitGate`), which reads the settlement the deny
* carries or the cause an in-fold arm attested, after every park re-route has had its attempt. That exit is
* the only caller of this factory: one call, one notice, once per tool call.
*
* Audience `"user"`: the refused work is the user's own (their run, or a delegation their run made), so the
* sentence is a person's — what did not happen, why in their words, and what they can do themselves (be where they
* can be asked). The recovery that is the deployment's — an approver to wire, a checkpoint store with a durable
* approval opt-in so such asks can wait for a person, a live approver reachable for delegated agents — is a posture
* the operator reads off `detail` (`remedy`, `remedies`, `parkLaneExisted`, `notResumableSource`) and the
* integration guide, never off the sentence; the row adds the session-stream projection so the person whose call
* was refused sees WHY it did not run. `sessionId` is therefore REQUIRED at the mint (the routing
* half of a user row). On a delegated leg it is the delegation tree's root — the session a person
* watches; the child's own session has no reader — and `sourceSessionId` / `agentId` say which leg the
* refused call was (the gate station's notice address, `noticeAddressOf`). Dedup unit: per tool call —
* the gate's obligation (it owns the call); this module is pure.
*/
import type { EngineNotice } from "./engine-notice.js";
import { type ApprovalRemedy, type AssertAllKeysHandled, type HeadlessApproverSeat } from "./ask-origin.js";
import type { ApprovalParkNotResumable } from "./park-resumability.js";
import { type SuspendLaneReason } from "./suspend-lane-reasons.js";
/** WHY the ask could not be resolved — the closed set (see the module note for each word). */
export declare const ASK_UNRESOLVABLE_CAUSES: readonly ["approver_unavailable", "no_approver_wired", "mandate_unreconstructible", "approval_window_expired"];
export type AskUnresolvableCause = (typeof ASK_UNRESOLVABLE_CAUSES)[number];
/** Membership test for {@link AskUnresolvableCause} — the word rides a notice detail across process boundaries. */
export declare function isAskUnresolvableCause(v: unknown): v is AskUnresolvableCause;
/** What a workflow lacked to hand the host's durable-approval opt-in to its agents — the closed set, one word per store the Workflow
* tool's arming condition reads that an agent can still run without: `launch_records` (a journal store that keeps no launch records,
* which a continuation reads the run back from). A missing workflow run store has no word: such a workflow is refused at its entry
* (it holds a checkpoint seat no run store records parks for), before any agent runs to be refused. */
export declare const WORKFLOW_PARK_GAPS: readonly ["launch_records"];
export type WorkflowParkGap = (typeof WORKFLOW_PARK_GAPS)[number];
/** Membership test for {@link WorkflowParkGap} (the word rides a notice detail across process boundaries). */
export declare function isWorkflowParkGap(v: unknown): v is WorkflowParkGap;
/** What the gate knows at the deny exit — facts only, no words of the engine's vocabulary composed. */
export interface AskUnresolvableFacts {
/** The session the notice is addressed to — its routing key, required (see module note): the refused leg's own session on a
* top-level leg, the delegation tree's root on a delegated one (`noticeAddressOf`, leg-identity.ts). */
readonly sessionId: string;
/** Present exactly when the refused call was a delegated leg's: that leg's session (the call's own conversation). */
readonly sourceSessionId?: string;
/** The delegated leg's agent id, beside {@link sourceSessionId} (never without it): the id the spawner's card and the leg's
* events carry. */
readonly agentId?: string;
/** The tool the ask was for (the message quotes it verbatim). */
readonly toolName: string;
/** The refused call's id — the correlation key to the `tool_end` frame carrying the same deny. */
readonly toolCallId: string;
/** Why the ask could not be resolved — carried as a fact from the exit, not re-derived here. */
readonly cause: AskUnresolvableCause;
/** The refused call is the agent's own question to a person (the question tool: its ask's class set holds `content_question`), not
* a step that needed an approval — the sentence says a question went unanswered. Absent ⇒ an approval. A fact of the sentence
* only: no `detail` key carries it. */
readonly question?: boolean;
/** No approval can be bound to the refused call's arguments (the gate's `bindingRefusal`; {@link remedy} is then that finding's
* sentence): nobody, present or not, could have approved the call as it is, so the sentence says the call has to change, never to
* run the task again where someone can be asked. A fact of the sentence only: no `detail` key carries it. */
readonly unbindable?: boolean;
/** Whether this call had a durable approval park route (`true`: the park had its one attempt and did not take
* the call — it declined or failed; `false`: no route — no park lane at all, the usual shape, or a lane the call
* may not take: a declared-none workflow member's permission call). */
readonly parkLaneExisted: boolean;
/** Present for the causes that say nobody could be asked ({@link askUnresolvableRemedySeat}): the caller-side change that
* would have let the call run, as the gate minted it — the refusal's tool text carries it too where a person may answer on the leg,
* and names no person where nobody may (`headlessApprovalRemedy`, `NOBODY_CAN_APPROVE`, ask-origin.ts; that sentence rides the
* refused-ask record only, `RefusedAsk.modelRemedy`, never this notice;
* for arguments no approval can be bound to, the binding's own sentence, which is that text — the remedy's approver half would
* not let them run) — carried verbatim, never re-composed here. */
readonly remedy?: string;
/** The ways out of that same refusal as data ({@link ApprovalRemedy}) — the approver, and the permission mode where the refusal could be
* released by one — for a host that chooses which to offer. Rides exactly when {@link remedy} is the headless remedy's sentence
* (`headlessApprovalRemedy`); a binding's own sentence, which has no way out to offer, carries none. */
readonly remedies?: readonly ApprovalRemedy[];
/** The way out of a leg whose parks nobody resumes (`notResumableWayOut`, tool-policy.ts — the gate's leg seat, carried verbatim): the
* sentence's way on says it (a person present approves it live, or the step runs another way), in place of "run the task again where
* you can be asked"; the run's refused-ask record carries it where the refusal named no remedy of its own ({@link refusedAskOf}). */
readonly notResumableWayOut?: string;
/** The leg's sentence saying why it cannot hold a park (`GatePass.parkTargetGap`, the gate's deny exit hands it verbatim), present when that
* alone kept the call from parking. It is the deployment's sentence (it names the environment to use), so it rides `detail.parkTargetGap`
* as stated; the person's sentence says, in their words, that nothing was set aside to wait for a person. */
readonly parkTargetGap?: string;
/** A durable approval park was ATTEMPTED for the refused call and could not be minted: why, as the deny's note quotes it (the park's own
* sentence, contained at the exit). It is the deployment's fact — what to change so such an ask waits for a person — so it rides
* `detail.parkFailed` as stated; the person's sentence says, in their words, that the attempt to set it aside failed. Never beside
* {@link parkTargetGap} (no attempt is made where the leg cannot hold a park); always with `{ kind: "park" }` first of {@link remedies}
* — the one rule of that way out, which the mint holds both ways. */
readonly parkFailed?: string;
/** Beside {@link parkFailed}: the missing piece of durable-suspend infrastructure the failure is, when it is one — the manifest's own code
* for it ({@link SUSPEND_LANE_REASONS}; `volatile_tool_results`: the run's offloaded tool results sit in an in-memory store). Rides
* `detail.parkFailedReason`. */
readonly parkFailedReason?: SuspendLaneReason;
/** Who says that leg's parks cannot be resumed ({@link ApprovalParkNotResumable}: `lane` — an engine lane holds no resume seat for the leg; `host` —
* the host declared its decision parks cannot be resumed) — the word {@link notResumableWayOut} was chosen by, carried beside it so a consumer picks its
* own sentence for the way out without composing one. Present exactly when the leg's parks cannot be resumed (the facts the sentence's
* "cannot wait for a person" clause reads); absent otherwise. */
readonly notResumableSource?: ApprovalParkNotResumable;
/** A workflow agent's leg the host's durable-approval opt-in was withheld from, because the workflow lacked these stores
* ({@link WORKFLOW_PARK_GAPS}, in the set's order) — present only where that is why no park could take the call (no park lane was
* armed on the leg). The deployment's fact: it rides `detail.workflowParkGap`, never the person's sentence. */
readonly workflowParkGap?: readonly WorkflowParkGap[];
}
/**
* Why nobody answered, in a person's words — the ONE table every sentence a person or a model reads takes the cause from: this
* notice's sentence and a parent's report of a leg's refused asks (`refusedAsksText`, member-outcome.ts). Total over the closed set
* (a missing row is a red build). The cause WORD stays the machine's (`detail.cause`, `RefusedAsk.cause`); no sentence spells it.
*/
export declare const ASK_UNRESOLVABLE_CAUSE_WORDS: Readonly<{
readonly approver_unavailable: "nobody was available to answer it";
readonly no_approver_wired: "nobody could be asked in this run";
readonly mandate_unreconstructible: "its approval had to wait for a person, and this part of the run cannot wait";
readonly approval_window_expired: "its approval window closed with no one answering it";
}>;
export type CauseWordsCoverEveryCause = AssertAllKeysHandled<Exclude<AskUnresolvableCause, keyof typeof ASK_UNRESOLVABLE_CAUSE_WORDS>>;
/**
* Which causes take the caller-side remedy (`headlessApprovalRemedy`, ask-origin.ts), and in which seat's clause — the table IS
* the rule, and it is total over the closed set (a cause with no row is a red build: {@link CauseRemedySeatCoversEveryCause}).
* The two causes that say NOBODY COULD BE ASKED take it — no approver is wired (`absent`: the clause says to wire one), or the
* wired approver reported nobody reachable (`unavailable`: the clause says to make a person reachable through it, never to
* wire what is wired — and the deny exit reads it as the `policy` clause when the wired approver is the deployment's approval
* policy, which is no person to make reachable): one fact, one sentence about the way out, whichever way nobody was there. The
* wired approver's own window closing with no one answering (`window_expired`) takes it in its own clause: be answered within
* that window, or let the ask wait at a park — a person WAS reachable, so neither "wire one" nor "make one reachable" is true of it. The inherited-mandate cause
* takes none (`undefined`): its recovery is a park facility on this leg, which neither a permission mode nor an `onAsk` here
* supplies, so the remedy's arms would name a change that does not release the call. (The settlement-axis table
* `SETTLEMENT_NOBODY_JUDGED` keeps `approver_unavailable` false because there a park route may still take the ask; this table is
* read at the deny exit, where every park route has had its attempt.)
*/
declare const CAUSE_REMEDY_SEAT: {
readonly approver_unavailable: "unavailable";
readonly no_approver_wired: "absent";
readonly mandate_unreconstructible: undefined;
readonly approval_window_expired: "window_expired";
};
export type CauseRemedySeatCoversEveryCause = AssertAllKeysHandled<Exclude<AskUnresolvableCause, keyof typeof CAUSE_REMEDY_SEAT>>;
/** The seat whose clause the refusal for `cause` carries its remedy in, or `undefined` when the cause takes no remedy
* ({@link CAUSE_REMEDY_SEAT}); read once at the deny exit, which hands the sentence to the tool text and the notice alike. */
export declare function askUnresolvableRemedySeat(cause: AskUnresolvableCause): HeadlessApproverSeat | undefined;
/** The run's record of one refused ask (`TaskResult.refusedAsks`), off the same facts its notice is composed from: the call, the cause,
* and the way out the refusal named — the headless remedy's sentence or a binding's own, else the way out of a leg whose parks cannot
* be resumed — and, where nobody on the leg could answer it, the way out its model read instead (`modelRemedy`, the deny exit's
* mint, carried verbatim: the notice never reads it). */
export declare function refusedAskOf(facts: Pick<AskUnresolvableFacts, "toolName" | "toolCallId" | "cause" | "remedy" | "notResumableWayOut" | "parkFailed" | "parkFailedReason"> & {
readonly modelRemedy?: string;
}): import("./task-result.js").RefusedAsk;
/**
* A leg's memory of the `delegation.ask_unresolvable` notices it told — a refusal's notice is said ONCE per leg: a call the model issues
* again after it was refused (the same tool, nobody to ask for the same reason, the same way out) is refused again, word for word, and a
* person who heard it once is not told again. Made once per leg over the leg's notice address; the answer is whether the notice of the
* address and these facts ({@link askUnresolvableNotice}, so a fact it refuses throws on every call) is new to the leg, read whole but for
* the one member every call has its own (`toolCallId`) — so two refusals whose sentence is the same but whose `detail` differs (another
* remedy, another park state) are each told. `false` for a repeat. The run's record (`TaskResult.refusedAsks`) and each call's `tool_end`
* frame keep every refusal: only the notice is said once.
*/
export declare function askUnresolvableTeller(address: Pick<AskUnresolvableFacts, "sessionId" | "sourceSessionId" | "agentId">): (facts: Omit<AskUnresolvableFacts, "sessionId" | "sourceSessionId" | "agentId">) => boolean;
/**
* Compose the `delegation.ask_unresolvable` notice from the gate's deny-exit facts.
*
* @contract delegation.ask_unresolvable.single_mint — the `delegation.ask_unresolvable` notice is composed
* by CORE from the gate's deny-exit FACTS (session, tool, call id, the cause, whether a park lane existed)
* at the ONE deny exit every unresolvable arm reaches; no other site spells the code or the sentence, and
* an empty session or tool name, or a cause outside the closed set, is refused at the mint with a
* `TypeError` rather than shaped into a notice that would route nowhere or say nothing.
*
* `detail: { sessionId, sourceSessionId?, agentId?, toolName, toolCallId, cause, parkLaneExisted, remedy?, remedies?, notResumableSource?, parkTargetGap?, parkFailed?, parkFailedReason?, workflowParkGap? }` — `parkTargetGap`
* rides exactly when the leg's "cannot hold a park" sentence alone kept the call from parking (that sentence, as the leg stated it); `parkFailed`
* exactly when a durable park was attempted for the call and could not be minted (its sentence, as the deny's note quotes it — the thing to
* change on a deployment whose asks are meant to wait for a person: `cause` still says who could answer live), and `parkFailedReason` beside it
* when that failure is one missing piece of durable-suspend infrastructure ({@link SUSPEND_LANE_REASONS}); `workflowParkGap`
* rides exactly on a workflow agent's leg the host's durable-approval opt-in was withheld from for missing stores, with no park lane armed
* ({@link WORKFLOW_PARK_GAPS}); `sourceSessionId`
* and `agentId` ride a delegated leg's refusal only (the leg the call was, the notice being addressed to the tree's root); `remedy` rides the causes that say nobody
* could be asked ({@link askUnresolvableRemedySeat}: the sentence the refusal's tool text carries) and `remedies` beside it, the same
* way out as data ({@link ApprovalRemedy}); `notResumableSource` rides exactly when the leg's parks cannot be resumed (whichever `cause` the refusal read as): who says
* so ({@link ApprovalParkNotResumable}), the word the leg's way out is chosen by — ABSENT on every other leg, and on an engine from before it, so a reader takes absent as "the
* source is not known" and picks no sentence by it; `sessionId` is lifted onto the typed key by {@link import("./engine-notice.js").deliverEngineNotice}, the one throat.
*/
export declare function askUnresolvableNotice(facts: AskUnresolvableFacts): EngineNotice;
export {};