UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

72 lines (71 loc) • 4.66 kB
import { type PermissionResult, type ResolvedAsk } from "../tool-policy.js"; /** A deferred question: the identity its card carried and the digest of the bytes the deferring answer was bound to. */ export interface DeferredAsk { readonly checkpointId: string; readonly inputDigest: string; } /** The deferral a resolution records, read off the resolver's engine record for the call — none when the answer is not * `"unavailable"`, or when the record binds no bytes (arguments outside the bindable domain bind no row either). */ export declare function deferredAskOf(resolved: ResolvedAsk, call: { toolCallId: string; toolName: string; }, checkpointId: string): DeferredAsk | undefined; /** The approval row's identity: the deferred question's when the row binds the bytes its card showed, else the row's own mint. */ export declare function parkedAskIdentity(deferred: DeferredAsk | undefined, rowDigest: string): string; type Ask = Extract<PermissionResult, { action: "ask"; }>; /** One station's mark on a call: the question it routed to the park and the digest of the bytes it was bound to (`undefined` * for bytes outside the bindable domain: they bind nothing, so no later bytes are those); `windowExpired` when the station's approver * routed it with `window_expired` (its own window closed with no one answering), read by the refusal of a call no park took. */ export interface StationMark { readonly question: Ask; readonly inputDigest: string | undefined; readonly windowExpired?: true; } /** The mark's window fact, off the routing resolution's own record ({@link hostWindowUnanswered}). */ export declare const windowMarkOf: (resolved: ResolvedAsk, call: { toolCallId: string; toolName: string; }) => { windowExpired?: true; }; /** The marker channel: per call, per inherited station (its chain entry), the station's mark. A call is marked while one stands. */ export type MarkerChannel = Map<string, Map<object, StationMark>>; /** The marker channel as a reader that only asks "is this call marked?" reads it. */ export interface MarkedCalls { has(toolCallId: string): boolean; } type Call = { readonly toolName: string; readonly toolCallId: string; readonly args: unknown; readonly face?: object | undefined; }; /** A station's mark over the bytes it judged: the args as the station received them, under its ask's own rewrite when it carries * one (`boundArgs` overrides: the same-instance arbitration station is handed the bytes after that rewrite already cascaded). */ export declare function stationMarkOf(question: Ask, call: Call, boundArgs?: unknown): StationMark; /** Records a station's mark on a call: this look's question replaces the station's earlier one (another station's stays). */ export declare function markCall(channel: MarkerChannel, station: object, toolCallId: string, mark: StationMark): void; /** The station's own approver answered over the bytes in front of it: its mark is lifted; with none standing, the call is unmarked. */ export declare function liftMark(channel: MarkerChannel, station: object, toolCallId: string): void; /** Whether a station's mark is bound to the bytes `args` (the same digest; unbindable bytes are bound to nothing). */ export declare function markBinds(mark: StationMark, call: { toolName: string; }, args: unknown): boolean; /** * One look of an inherited station at a call (`look`, handed `call`). When the station marked the call on an EARLIER look: a deny * stands; a look whose own approver answered over these bytes stands (it lifted the mark, or moved it to them); a verdict that * rewrites these bytes stands too — every reader of a later look refuses a rewrite it is handed there (a rewrite is judged once, * never chased), and hiding it behind the question would park bytes the station wanted changed; any other verdict hands back the * deferred question ({@link standingOf}). */ export declare function stationLook(channel: MarkerChannel, station: object, call: Call, look: () => Promise<PermissionResult>): Promise<PermissionResult>; /** The question a station deferred on an earlier look at the call, as it stands over a later look: without its rewrite (a later * look never re-points the call). Undefined when the station marked nothing on the call. */ export declare function standingOf(channel: MarkerChannel, station: object, call: { readonly toolCallId: string; }): Ask | undefined; /** The clause a refusal or a card adds when the bytes in front of it are not the ones the deferred question was bound to. */ export declare function movedClause(toolName: string): string; export {};