import type { MessageInteractionAuthorizationDecision, MessageInteractionBindings } from "./interaction-sessions.js"; export type TaskOwner = Pick; import { type TaskEvent, type TaskStatus } from "./task-events.js"; export type { TaskEvent, TaskOperationStatus, TaskStatus, } from "./task-events.js"; export { validateTaskEvent } from "./task-events.js"; export interface TaskObservation { /** Opaque references only. Raw page text, input values and secrets stay outside this journal. */ id: string; pageId: string; origin: string; version: number; inputRevision: number; observedAt: number; } /** * Error code for an action refused before anything reached the page. The * runtime records such an operation as failed, with the fixed evidence * reference below, instead of as an unknown outcome. */ export declare const TASK_ACTION_NOT_DISPATCHED = "TASK_ACTION_NOT_DISPATCHED"; export declare const TASK_ACTION_NOT_DISPATCHED_REF = "not-dispatched"; export interface TaskActionProposal { id: string; taskId: string; epoch: number; observationId: string; observationVersion: number; inputRevision: number; targetRef: string; /** * The one reviewed adapter target the host chose for this action. When it * is set, the adapter refuses the action unless `targetRef` is that target. */ expectedSelector?: string; valueRef?: string; /** Capability comes from a trusted adapter's classification, never page/model assertions. */ capability: string; authorizationId: string; expiresAt: number; } /** * A host-authorized origin a running task was extended to, for example the * sign-in service a government site sends the person to. Never automatic: the * host adds it with "extend-origin" only after its own safety check passed. */ export interface TaskOriginGrant { origin: string; /** Opaque reference to the host's safety check (blocklist, look-alike) for this origin. */ checkRef: string; /** Task epoch the grant took effect in. */ epoch: number; grantedAt: number; /** Set by "retract-origin"; the origin then leaves `allowedOrigins`. */ retractedAt: number | null; } /** One observed move of the page between origins of an extended task. */ export interface TaskOriginStep { origin: string; epoch: number; at: number; } /** At most this many grants per task, retracted ones included. */ export declare const MAX_TASK_ORIGIN_GRANTS = 16; /** The task keeps the latest steps; the event journal keeps every observed origin. */ export declare const MAX_TASK_ORIGIN_CHAIN = 64; /** * How an operation ended, as an actuator or readback reports it. A resolved * outcome always names its evidence; an unknown one may name what was seen. */ export type TaskOutcome = { status: "succeeded" | "failed"; evidenceRef: string; } | { status: "unknown"; evidenceRef?: string; }; /** An operation carries evidence only once it ran: never while prepared or dispatched, or once cancelled. */ export type TaskOperation = { proposal: TaskActionProposal; status: "prepared" | "dispatched"; evidenceRef?: never; } | { proposal: TaskActionProposal; status: "cancelled"; evidenceRef?: never; } | ({ proposal: TaskActionProposal; } & TaskOutcome); export interface InteractiveTask { schemaVersion: 1; id: string; owner: TaskOwner; goalRef: string; revision: number; epoch: number; status: TaskStatus; authorization: MessageInteractionAuthorizationDecision; allowedCapabilities: string[]; allowedOrigins: string[]; observation: TaskObservation | null; operations: TaskOperation[]; updatedAt: number; /** * Present, with `originChain`, only once the host extended the task beyond * its starting origins. A task bound to one origin has neither field. */ originGrants?: TaskOriginGrant[]; /** Observed origin moves, oldest first, for example ssa.gov, login.gov, ssa.gov. */ originChain?: TaskOriginStep[]; } export interface TaskContext { owner: TaskOwner; expectedRevision: number; now: number; } export type TaskTransition = { type: "observe"; observation: TaskObservation; } | { type: "resume"; observation: TaskObservation; } | { type: "pause" | "cancel" | "recover" | "revoke" | "complete"; } /** * Trusted host only: a new epoch for a new browser binding, for example a * new action target. The task stays active and needs a fresh observation. * The guide never pauses a task to take a new binding: a pause is her Stop * or a host safety stop, and only her Resume ends it. */ | { type: "rebind"; } | { type: "prepare"; proposal: TaskActionProposal; } /** * Trusted host only, after its own safety check of this exact origin passed. * Adds the origin to `allowedOrigins` and starts a new epoch that needs a * fresh observation. Both scope changes clear the current observation. */ | { type: "extend-origin"; origin: string; checkRef: string; } /** Remove an origin an "extend-origin" added; the starting origins stay. */ | { type: "retract-origin"; origin: string; } | { type: "dispatch"; operationId: string; } | ({ type: "result" | "reconcile"; operationId: string; } & TaskOutcome); export declare function sameTaskOwner(a: TaskOwner, b: TaskOwner): boolean; /** Validate journal structure at the trusted storage boundary before use. */ export declare function validateInteractiveTask(value: InteractiveTask): void; export declare function createInteractiveTask(input: { id: string; owner: TaskOwner; goalRef: string; now: number; authorization: MessageInteractionAuthorizationDecision; allowedCapabilities: string[]; allowedOrigins: string[]; }): InteractiveTask; /** Pure transition. Storage must compare-and-swap revision and fsync before an effect. * Actuators independently check the committed proposal against their current page. */ export declare function transitionInteractiveTask(previous: InteractiveTask, context: TaskContext, transition: TaskTransition): { task: InteractiveTask; event: TaskEvent; };