@sema-agent/core
Version:
Stateless, task-oriented AI agent core
66 lines (65 loc) • 4.66 kB
TypeScript
import type { TaskSpec } from "../types.js";
import type { AnnounceOnceSink, DateAnchorRead, Prepared, PrepareResume, ToolFaceSnapshot } from "./contracts.js";
import type { AnnouncedListingSnapshot } from "../../internal/harness.js";
import type { ResolvedSkillListingBudget } from "../skill-listing-budget.js";
export interface PrepareListingsInput {
/** borrowed-readonly — the REBOUND spec (`spec′`). Read: `tools` (the roster-bearing delegation tool, by its `agentListing`
* marker), `sessionId` (continuation ⇒ seeded/removal projections), `attachments` (the two opt-outs). Never mutated. */
spec: Pick<TaskSpec, "agents" | "tools" | "sessionId" | "attachments" | "excludeAllTools">;
/** borrowed-readonly — the once-per-session ledger: its deduplicated operator sink (`onError`) and
* the whole announced snapshot (`arms()`) the mirror is seeded from. */
onceLedger: AnnounceOnceSink & {
arms(): AnnouncedListingSnapshot;
};
/** borrowed-readonly — the acquired session's id (operator-line context). */
sessionId: string;
/** borrowed-readonly — the frozen tool face: the selector and `defer` decide the roster face's arm. */
toolFaceSnapshot: Pick<ToolFaceSnapshot, "selector" | "defer">;
/** borrowed-readonly — the activated deferred names as of prepare (transcript replay / checkpoint
* seed); only `has()` is read: an already-ACTIVE roster tool un-defers its listing face. The set
* keeps mutating mid-run (ToolSearch activations) — this phase reads it once, here. */
activeTools: ReadonlySet<string>;
/** borrowed-readonly — the leg's EFFECTIVE deferred set (the defer classification's answer): a name the caller listed in `deferTools`
* is deferred only if it is in here — a leg whose selector leaves ToolSearch out defers nothing, so its roster tool ships inline with its listing. */
deferred: ReadonlySet<string>;
/** borrowed-readonly — the durable-resume carrier: presence (seedAnnounced) and
* `seed.announcedListings.agents` (the removal-to-zero projection's gate). */
resume: Pick<PrepareResume, "seed"> | undefined;
/** borrowed-readonly — the project-context phase's skills-listing projection; read only for the
* skills opt-out advisory (entries.length). */
skillsListing: Prepared["skillsListing"];
/** borrowed-readonly — the listing family's resolved budget; the agent roster frames fold into it. */
listingBudget: ResolvedSkillListingBudget;
/** borrowed-mutable — the deferred roster's ToolSearch RIDE seat (declared by the disclosure
* mount, read at activation time through `listingRideRef.current?.(newly)`). Written here, once,
* on a deferred roster face; no later writer. Identity is the contract (the mount's closures read
* this exact cell). */
listingRideRef: {
current?: (newly: readonly string[]) => string | undefined;
};
/** borrowed-readonly — the prompt assembly's date re-renderer; presence alone decides whether the
* date_change seam exists (a provider that owns the whole prompt has none). */
renderWithDate: ((date: string) => string) | undefined;
/** borrowed-readonly — the environment facts; only `date` is read (the leg's frozen date). */
envFacts: {
readonly date?: string;
};
/** borrowed-readonly — whether the client zone validated (the seam re-judges "today" in it). */
tzValid: boolean;
/** borrowed-readonly — the client's declared zone (used only when `tzValid`). */
userTz: string | undefined;
/** borrowed-readonly — the session's date anchor as the prompt-inputs phase read it (rides the seam). */
dateAnchor: DateAnchorRead | undefined;
}
export interface PrepareListingsResult {
/** owned — the agent-listing announce projection (`Prepared.agentListing`): the roster off the
* delegation tool's effective face, the removal-to-zero projection, or undefined (silent). */
agentListing: Prepared["agentListing"];
/** owned — the announced-listings mirror seeded from the ledger's whole snapshot
* (`Prepared.announcedListingsRef`); the run loop and the checkpoint serializer write it from here on. */
announcedListingsRef: Prepared["announcedListingsRef"];
/** owned — the date_change seam (`Prepared.dateChange`), or undefined when the prompt has no date re-renderer. */
dateChange: Prepared["dateChange"];
}
/** The M15 phase body — prepareTask's listings stretch, verbatim (see the module header). */
export declare function prepareListings(input: PrepareListingsInput): PrepareListingsResult;