UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

75 lines (74 loc) • 6.83 kB
/** * The NORMALIZATION a leg's mount facts pass through before the mount table reads them (tool-mount-plan.ts): the task's * own word, the deployment's seats and the execution environment, each read ONCE into the closed fact set. Both halves * read the table through these functions — prepare states their answers when its roster opens, and * `describeStaticWiring` states the ones a deployment can read before any task — so a fact means the same thing to the * leg that mounts and to the reader that predicts. * * Facts only known where a phase computes them (a listing, a verdict a phase reaches live, the name domain at a * phase's point) are not here: the phase that computes one states it beside the judgment that reads it. */ import type { ExecutionEnv } from "../internal/harness-types.js"; import { type ModelShellReading } from "./model-shell.js"; import { type SchedulerReading } from "./scheduler.js"; import type { ApprovalParkNotResumable } from "./park-resumability.js"; import type { ToolMountFact, ToolMountIdentity } from "./tool-mount-plan.js"; import type { RunnerDeps, TaskSpec } from "./types.js"; /** Facts a reader of the mount table states; a fact absent from the record is one it cannot read. */ export type ToolMountFacts = Partial<Record<ToolMountFact, boolean>>; /** The spec members the task's own word is read from. */ export type MountFactSpec = Pick<TaskSpec, "enableBlockedReport" | "enablePlanMode" | "interactiveTools" | "selfOrchestration" | "outputSchema" | "handsReadOnly" | "runLedger" | "advisorModel" | "lspManager">; /** The task's own word. */ export declare function specMountFacts(spec: MountFactSpec): ToolMountFacts; /** The deps members the deployment's seats are read from. */ export type MountFactDeps = Pick<RunnerDeps, "workflowScriptRunner" | "workflowGovernanceBaseline" | "lspManager" | "artifactHost" | "sharedMemoryStores" | "runtimeCapsResolver" | "a2a">; /** The deployment's seats a task cannot move (a task's own LSP manager counts with the deployment's; so do a task's own A2A peers with * the deployment's word that its readers read `peer_task` frames — together, a call can start a peer task). A principal's runtime * entitlement is read per principal, so a deployment with a resolver leaves it to the leg; one with none has the default. */ export declare function seatMountFacts(deps: MountFactDeps, spec: Pick<TaskSpec, "lspManager" | "a2a">): ToolMountFacts; /** The run's global offload thresholds: the explicit one (the task's, else the deployment's — the coarse knob that outranks * the per-tool defaults) and the effective one (the explicit one, else the engine default). */ export declare function offloadThresholdsOf(spec: Pick<TaskSpec, "toolResultThresholdChars">, deps: Pick<RunnerDeps, "toolResultThresholdChars">): { readonly explicit: number | undefined; readonly effective: number; }; /** `seat.offload`: a finite, positive effective threshold opens the offload seat (a store is always at hand once it is open — * the deployment's, else a fresh in-memory one). */ export declare function offloadSeatFact(effectiveThreshold: number): boolean; /** The question seat's inputs: a live question face; a park store the question can wait in; the per-principal durable * entitlement (`undefined` where it cannot be read before a principal resolves); the task's own durable opt-in. */ export interface QuestionSeatInputs<F extends boolean | undefined = boolean | undefined> { readonly face: boolean; readonly parkStore: boolean; readonly forceDurableGate: F; readonly durableApprovalDeclared: boolean; /** The leg's one fact `approvalParkNotResumable` (`approvalParkNotResumableOf`; a static reader reads a top-level leg: the host's word only). */ readonly approvalParkNotResumable: ApprovalParkNotResumable | undefined; } /** `seat.question`: a seat that answers — a live face, or the durable park (a store to wait in AND a declared opt-in). */ export declare function questionSeatFact(input: QuestionSeatInputs<boolean>): boolean; export declare function questionSeatFact(input: QuestionSeatInputs): boolean | undefined; /** The seats a leg reads before its environment off its own two facts (the park store it resolved, whether anyone resumes its * park) and the deployment's: the question seat (a principal's durable entitlement left open where a resolver reads it) and * an engine-memory seat that never opens. The static half states them for a new top-level leg and the leg before its * environment, so both place the question face and the memory trio — and read whether a call can happen — alike. */ export declare function legSeatMountFacts(deps: Pick<RunnerDeps, "onQuestion" | "runtimeCapsResolver" | "memoryBackend">, spec: Pick<TaskSpec, "onQuestion" | "durableApproval" | "memory">, leg: { readonly parkStore: boolean; readonly approvalParkNotResumable: ApprovalParkNotResumable | undefined; }): ToolMountFacts; /** `leg.backgroundAgents`: a caller tool the valve leaves launches background agents — a delegation tool the factory made whose mount has * a background lane, both read from its `execute` where the factory bound them ({@link delegationHasBackgroundLane}): a copy whose face * dropped `run_in_background` still launches in the background by default, and a synchronous one whose face gained it does not. */ export declare function backgroundAgentsFact(callerTools: readonly unknown[], leaves: (identity: ToolMountIdentity) => boolean): boolean; /** `leg.startersWithheld`: the leg is a worker handed no tool that starts agents (`RunInternals.agentStartersWithheld`, set by the * spawn or revival that made it) — read here once for both of the leg's readings, its environment's and its roster's. */ export declare function startersWithheldFact(internals: { readonly agentStartersWithheld?: true; } | undefined): ToolMountFacts; /** The execution environment's reach: hands at all, a target its shell faces reach, its start for model text, the two daemon * capabilities (a background shell counts only beside a start with a background face — its commands are the model's text). A leg * hands in the scheduler reading and the start's reading it took ({@link readSchedulerDeclaration}, `readModelShell`: both facts of * the start are the reading's — `mounted`, and its `background.launch`), so each declaration is read once per leg; a static reader * takes its own — for the start, the same declaration before anything is asked ({@link declaredModelShell}): a start whose `ready` * the leg still asks is not stated, so the rows that read it stay conditional on it. */ export declare function envMountFacts(handsEnabled: boolean, env: ExecutionEnv, scheduler?: SchedulerReading, modelShell?: ModelShellReading): ToolMountFacts;