UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

53 lines (52 loc) • 4.22 kB
/** * `TaskResult.intake` — whether a call's own input was taken into its conversation — and the composition's own accounts of * the legs it dispatched. * * One mint: the commit of the leg's prompt message (its prompt receipt, fired at the same append that publishes the * row's `message_committed { role: "user" }` frame). {@link intakeOfCommit} is the reading of that commit; the run body * publishes it on its backstop carrier, so the settled result and the failure backstop answer from the same record. * {@link foldIntake} is the one projection a composition (verification gate, cascade, repair loop) applies to the legs * it dispatched — never a second read of the store, never `stats.turns`. {@link foldContinuesFrom} is its twin for where * the composition leaves the session it hands back (`TaskResult.continuesFrom`), and {@link closeComposition} is the one closing * every composition's returned result passes: both accounts, and the byte floor's record (`TaskResult.readDenyFloor`), are the * composition's own fold over its legs, never the last leg's by spread. {@link closeFloorOverSideLegs} adds the legs a * composition dispatched whose accounts are not its own (the verify gate's verifier legs) to the byte floor's record only. */ import type { TaskResult } from "./task-result.js"; export type TaskIntake = NonNullable<TaskResult["intake"]>; type ContinuesFrom = NonNullable<TaskResult["continuesFrom"]>; /** * The intake fact of one committed prompt message. The entry id is the session store's answer for the append: only a * non-empty string is an address (the same reading of a usable key a stored record hands over); anything else leaves the * fact unknown rather than naming an entry nobody can find. */ export declare function intakeOfCommit(sessionId: string, entryId: unknown): TaskIntake | undefined; /** * The intake of a composition, over the legs it dispatched in dispatch order: the first leg that took the input in; * when none did, `{ committed: false }` if every leg said so and `undefined` (unknown) if any leg's account was unknown. * A composition that dispatched no leg took nothing in. */ export declare function foldIntake(legs: ReadonlyArray<unknown>): TaskIntake | undefined; /** * Where a composition leaves the session it hands back (`hostSessionId`: the session of the leg whose result it returns), over the * legs it dispatched in dispatch order: the landing of the LAST leg that ran in that session and landed a write there — a later leg * that wrote nothing (`nothing_taken_in`) does not unsay an earlier leg's landing, and a leg in another session (an earlier rung, a * verifier, an attempt before a clean restart) never answers for it. None did, or there is no such session ⇒ `nothing_taken_in`. * A leg in it whose account is not a well-formed landing makes the fold unknown (`undefined`), unless a later one landed. */ export declare function foldContinuesFrom(legs: ReadonlyArray<unknown>, hostSessionId: string | undefined): ContinuesFrom | undefined; /** * A composition's returned result: `result` (the leg it hands back) with the composition's own accounts of the legs it * dispatched in place of that leg's — its intake ({@link foldIntake}), where it leaves the session that leg ran in, * `result.sessionId` ({@link foldContinuesFrom}), and whether any of them ran with an unkept byte floor ({@link foldFloorUnkept}, * over the legs and the returned leg itself); an unknown fold drops the member. The one closing every composition's return passes. */ export declare function closeComposition<R extends TaskResult>(result: R, legs: ReadonlyArray<TaskResult>): R; /** * A composition's result with the byte floor's record of the legs it dispatched whose accounts are not its own (the verify gate's * verifier legs: their spend, intake and landing are not the composition's) folded in by the same reader ({@link foldFloorUnkept}): * `result`'s own record first, then those legs in dispatch order. Those legs only add: none of them says `kept: false` ⇒ `result` * unchanged. */ export declare function closeFloorOverSideLegs<R extends TaskResult>(result: R, sideLegs: ReadonlyArray<TaskResult>): R; export {};