import type { ActorPersonaRef, ActorTokenUsage, ActorTraceItem } from "./actor-contract.js"; import { type CuaExecutor, type CuaLoopResult, type CuaProvider, type CuaSafetyCheck } from "./computer-use.js"; import { type E2BDesktopExecutorOptions, type E2BDesktopLike } from "./e2b-desktop-executor.js"; import { type OpenAiResponsesProviderOptions } from "./openai-responses-cu.js"; import { type RedactionHooks } from "./redaction.js"; import type { DwellWindow, StopWhen } from "./stop-conditions.js"; import type { LabTask } from "./tasks.js"; export interface CuaActorSessionOptions { /** The composed mission (persona + scenario/lane instruction) handed to the model. */ instructions: string; /** Provenance of the persona this actor embodies (id + applied traits + prompt digest). */ persona: ActorPersonaRef; /** Hard wall-clock runaway guard — the only count-free hard stop the loop honors. */ timeoutMs: number; signal?: AbortSignal; /** Live provider construction (used when `provider` is not injected). */ openai?: OpenAiResponsesProviderOptions; /** Live executor construction (used when `executor` is not injected). */ desktop?: E2BDesktopLike; executorOptions?: E2BDesktopExecutorOptions; /** * DI seams — inject to bypass live construction (CI uses these for zero-spend tests; library * callers use them to drive a state-driven, non-vision flow). NOTE: a STATE executor (one * whose observe() returns no screenshot — see CuaObservation.screenshot optional) MUST be * paired with a NON-vision provider (requiresFrame falsey). The default OpenAI provider is * vision-based and would fail closed against a screenshot-less observation. See * docs/architecture/state-driven-executor.md. */ provider?: CuaProvider; executor?: CuaExecutor; redaction?: RedactionHooks; now?: () => number; /** * Decide which model-flagged safety checks to acknowledge; returned checks are echoed back * (verbatim wire triples) on the next turn's request so the model proceeds. Omitted here means * the loop's own fail-closed default applies (pause on any check). No auto-ack policy ships yet. */ acknowledgeSafetyChecks?: (checks: CuaSafetyCheck[]) => CuaSafetyCheck[] | null; idleSteps?: number; noProgressSteps?: number; /** * Redact persisted screenshots (blur+downscale). Default FALSE — full fidelity for local use. * Set true for unowned subjects or share-as-is bundles. The provider always sees raw frames. */ redactScreenshots?: boolean; /** Literal scrub for known provisioned values, composed before redactText on model narration. */ scrubText?: (text: string) => string; /** Persist a screenshot (raw or redacted per redactScreenshots), returning the trace ref path. */ writeScreenshot?: (name: string, bytes: Buffer) => Promise; /** Deterministic harness-owned stop guards evaluated between model turns. */ stopWhen?: StopWhen; /** A declared observation window (#510), forwarded to the loop. */ dwell?: DwellWindow; /** The lab's declared protocol; the loop records a corroborated task funnel on the trace (#414). * Only the `success` criteria are read here — the participant-facing goals are already composed * into `instructions` upstream, and the criteria never reach the prompt. */ tasks?: readonly LabTask[]; /** FAIL-CLOSED spend cap (USD) threaded to the loop; absent = uncapped. See CuaLoopOptions.maxUsd. */ maxUsd?: number; /** Injected pure per-turn cost estimator paired with `maxUsd`. See CuaLoopOptions.estimateTurnCostUsd. */ estimateTurnCostUsd?: (usage: ActorTokenUsage) => number | null; /** RUN-LEVEL spend guard threaded to the loop (#299). See CuaLoopOptions.overRunBudget. */ overRunBudget?: (usage: ActorTokenUsage) => string | null; /** Sequential capped studies stop if a request's usage is unavailable; library-only policy. */ requireReportedUsageForSpendCap?: boolean; /** RUNTIME-ONLY observed-URL callback threaded to the loop; see CuaLoopOptions.onObservedUrl. Used by * the concurrent shared-world handoff barrier to latch a host seat's live /lobby/CODE URL. */ onObservedUrl?: (url: string | undefined) => void; /** RUNTIME-ONLY per-turn narration callback threaded to the loop; see CuaLoopOptions.onMessage. */ onMessage?: (text: string) => void; /** RUNTIME-ONLY per-turn raw-frame callback threaded to the loop; see CuaLoopOptions.onScreenshot. */ onScreenshot?: (frame: Buffer) => void; /** Per-turn trace snapshot callback threaded to the loop (#441); see CuaLoopOptions.onTrace. */ onTrace?: (items: readonly ActorTraceItem[], usage: ActorTokenUsage) => void; } export declare function runCuaActorSession(options: CuaActorSessionOptions): Promise;