UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

56 lines (55 loc) • 4.53 kB
/** * The notice a stop that landed on the run's TAIL leaves (`task.interrupt_unconsumed`): the run had given its answer, so the stop * cut no turn and the answer stands — but a one-shot ending may have been waiting for background tasks it started, and the stop * ended that wait. The notice says which and what the run's end does to each, read when the notice is built * ({@link stopTailWaitedFor}); "nothing was cut or stopped" is said only when nothing was still waited for. */ import type { EngineNotice } from "../types.js"; import { type TaskAccess, type TaskListRow, type TaskRegistry } from "../task-registry.js"; import type { DeliveryObligations } from "../task-notification.js"; /** A waited task's description, as the notice carries it (in its sentence and in `detail.waitedFor`): credentials redacted FIRST, * then one line with control characters folded, capped at this many code points by a marker-safe cut — the length the reference * names a background task by in its own stop line. */ export declare const STOP_TAIL_DESCRIPTION_MAX_CHARS = 60; /** One task the one-shot ending was still waiting for when the notice was built. */ export interface StopTailWaitedTask { readonly taskId: string; /** The row's type — absent when no row this leg reaches could be read for the id. */ readonly taskType?: TaskListRow["type"]; /** The row's status when the notice was built (absent as `taskType` is). */ readonly status?: TaskListRow["status"]; /** The row's description in the notice's one shape: credentials redacted, one line, control characters folded, capped at * {@link STOP_TAIL_DESCRIPTION_MAX_CHARS} code points (and the truncation mark when cut). */ readonly description?: string; /** The run's end stops it: the sweep of this leg's background agents takes it (a task-scoped agent this leg owns, still running). * False for one that keeps its own lifetime — session-scoped, another leg's (a revived row keeps its owner), a workflow run, parked, * or one that already finished. ABSENT when the row could not be read: what became of it is not known here. */ readonly stopped?: boolean; } /** * What the one-shot ending's book (`owed`; its lane keys are task ids; undefined for a run that does not wait) is still owed NOW, and * for each the row `access.read` reaches and whether the run-end sweep of `access.owner`'s background agents takes it * ({@link TaskRegistry.runEndReading}). Read when the notice is built: that sweep runs after the notice, so a task named as stopped is * one the end will stop, and a task that finished on its own after the stop (its debt discharged) is not named at all. */ export declare function stopTailWaitedFor(owed: Pick<DeliveryObligations, "pending"> | undefined, access: { read: TaskAccess; owner: TaskAccess; }, registry?: Pick<TaskRegistry, "runEndReading">): readonly StopTailWaitedTask[]; /** `task.interrupt_unconsumed`, for a stop that landed after the answer settled. `origin` names the axis that stopped the run; * `crossedAxis` the axis the result's `limitCrossed` records when it records one (a budget, walltime or turn stop at the tail is a * ceiling the run ended past) — the sentence then names that record instead of saying none exists. */ export declare function interruptUnconsumedNotice(waitedFor: readonly StopTailWaitedTask[], origin: string, ids: Record<string, string>, crossedAxis?: string): EngineNotice; /** * The engine note a run with a member ledger reads when its one-shot wait reached its ceiling (`TaskSpec.runLedger`): one more turn, * told which tasks it is leaving behind and what the run's end does to each, so the gap goes into its report to the person. Same * reading as {@link waitCeilingReachedNotice} (read before the run-end sweep). */ export declare function ceilingTurnNote(waitedFor: readonly StopTailWaitedTask[], ceilingMs: number): string; /** * `task.wait_ceiling_reached`, for a one-shot ending whose wait reached its ceiling (`limits.oneShotWaitCeilingMs`, `ceilingMs` the * value it waited under) with background tasks it started still owed: no stop arrived — the wait gave up. `waitedFor` is the same * reading the stop's notice carries ({@link stopTailWaitedFor}), taken before the run-end sweep; never empty (the ceiling only stops a * wait with something still owed). */ export declare function waitCeilingReachedNotice(waitedFor: readonly StopTailWaitedTask[], ceilingMs: number, ids: Record<string, string>): EngineNotice;