@sema-agent/core
Version:
Stateless, task-oriented AI agent core
51 lines (50 loc) • 4.07 kB
TypeScript
/**
* The person's account of the media that left the model's view of a request (`context.media_removed`, user) — one code,
* the reason in `detail.reason`, the message minted once here for both:
* - `rejected_by_provider`: the harness's request view removes the images a provider refusal points at
* (`engine/llm/rejected-images.ts`) and hands {@link createProviderRefusalSeat} the removals the run itself met; every
* request re-reads the transcript — the live failure, then its record or a rebuilt copy — so that seat announces ONCE
* PER RUN PER REFUSAL, keyed by the identity all of those share (`refusalAt`);
* - `media_budget`: the request trim (`media-byte-cap.ts`) hands {@link createMediaBudgetSeat} what it did to a request
* view the context hook handed on (the lane's observation flush, KL-2988-a); that seat traces every such view (`context.media_removed`, the request's numbers) and announces
* each block ONCE PER SESSION, by the block's identity — the digest of its bytes, which a compaction, a resume or a
* rewind does not change. The digest rides the session's announced record (the advisory arm, bounded) and the write is
* parked for the leg's flush; best effort — a lost write, or a block whose digest the bound let go, is said again by a
* later run, never lost. Within a run a block is looked at once.
* Beside the provider's image refusal sits its other refused part, a tool's input schema ({@link createToolSchemaRemovedSeat},
* its own code).
*/
import { type EngineNotice } from "../engine-notice.js";
import type { RejectedImageRemoval } from "../../internal/llm.js";
import type { RequestMediaLimits } from "../image-admission.js";
import type { RequestMediaTrim } from "../media-byte-cap.js";
import { type TracerHook } from "../trace.js";
import type { Prepared } from "./contracts.js";
import type { NoticeSeatInput } from "./notice-seat-input.js";
/** The session's announced record and the leg's receipt ledger (the parked write). */
export type MediaBudgetRecord = Pick<Prepared, "announcedListingsRef" | "frameReceipts">;
/** The provider-refusal account: one notice per refusal, once per run. A refusal met for the first time is the request that
* re-sends the turn without those images — a rewrite of what the refused request carried: `onNewlyRemoved` is told (before
* that request leaves). */
export declare function createProviderRefusalSeat(ids: NoticeSeatInput, onNewlyRemoved?: () => void): (removals: readonly RejectedImageRemoval[]) => void;
/**
* The run's account of a tool whose input schema a provider refused (`context.tool_schema_removed`, user): the loop re-sent
* the turn with that tool's parameters taken out of what the model sees (`engine/llm/rejected-images.ts`), and every later
* request built from a transcript the refusal's record stands in sends it so. ONCE PER REFUSAL (`refusalAt`): the loop
* re-sends once per refusal, and a refusal recorded before the run began is never re-sent, so never announced again. The
* re-send's tool table is not the refused request's: `onNewlyRemoved` is told once per refusal, before the re-send leaves.
*/
export declare function createToolSchemaRemovedSeat(onNotice: ((notice: EngineNotice) => void) | undefined, ids: {
sessionId: string;
runId: string;
}, onNewlyRemoved?: () => void): (refusal: {
tool: string;
refusalAt: number;
}) => void;
/** The request budget's account of one request view the trim cut: its trace frame, then — of the blocks it left out, those
* the session was not yet told of — one notice. Those blocks are the newly cut ones (the trim takes the oldest first, so
* each sat in an earlier message the previous request carried whole): `onNewlyRemoved` is told, before the view leaves. */
export declare function createMediaBudgetSeat(ids: NoticeSeatInput, record: MediaBudgetRecord, trace: {
readonly tracer: TracerHook | undefined;
readonly taskId: string;
}, onNewlyRemoved?: () => void): (trim: RequestMediaTrim, limits: RequestMediaLimits) => void;