import { type Brief, type ActiveVariantSnapshot, type LeasedWorkItemDescriptor, type ProjectContext, type SourcePlanArtifact, type Stage, type Target, type TerminalSummary, type VariantPickEnvelope, type WorkItem, type WorkItemStatus } from './contracts';
/** TTL for a lease on a code_gen work item. Bumped to 10min after observing
 *  agents legitimately take longer than 3min when running 4+ Task sub-agents
 *  in parallel — the recovery path (re-lease + re-report) worked, but the UX
 *  delay before the chip's pills lit up was noticeable. */
export declare const DEFAULT_LEASE_TTL_MS: number;
/** TTL for a lease on a scaffold_base work item. Slightly longer than
 *  code_gen because npm/yarn create can be slow on a cold cache. */
export declare const SCAFFOLD_LEASE_TTL_MS: number;
export interface SessionStoreClock {
    now(): number;
}
export interface ProposeArgs {
    sessionId?: string;
    prompt: string;
    count?: number;
    target?: Target;
    projectContext?: ProjectContext;
    /** Agent-provided 1–2 word label for the run's intent (e.g. "Brighter").
     *  Falls back to a heuristic derived from the prompt when absent. */
    runLabel?: string;
}
export interface ProposeResult {
    sessionId: string;
    stage: 'awaiting_source_plan' | 'awaiting_briefs';
    briefWorkItem?: WorkItem;
    sourcePlanWorkItem?: WorkItem;
}
export interface ApprovedBriefSelection {
    briefId: string;
    bodyOverride?: string;
}
export interface ApproveResult {
    approvedCount: number;
    totalCount: number;
    codeGenWorkItemIds: string[];
    scaffoldBaseWorkItemId?: string;
}
export interface RequestWorkResult {
    leaseId: string;
    leaseTtlMs: number;
    leasedWorkItems: LeasedWorkItemDescriptor[];
}
export type ReportSourcePlanArgs = {
    sessionId: string;
    workItemId: string;
    attempt: number;
    leaseId: string;
    sourcePlan: SourcePlanArtifact;
};
export interface ReportCompleteResult {
    stage: Stage;
    progress: {
        ready: number;
        total: number;
    };
    summary?: TerminalSummary;
    /** Cooperative abort signal. Set when the reported work item was removed or
     *  cancelled out from under the agent (delete-while-loading, cancel_variant,
     *  or session cancel). The agent should drop this work item immediately — no
     *  retry, no finishing wasted work — instead of treating the cleared lease as
     *  an error. */
    aborted?: boolean;
}
export declare const SOURCE_PLAN_OUTPUT_SCHEMA: {
    readonly sourceIntent: "sources: Array<{ url? | imageRef?, role: design_source|interaction_reference|asset_source|content_reference|other, confidence: low|medium|high, reason }> — classify every input source. Each entry keys by EXACTLY ONE of `url` (an inspiration URL the user provided) OR `imageRef` (a stable `image:<index>` reference for an attached-image artifact; the index matches the order of image-kind entries in the session's `sourceArtifacts`, i.e. visualBrief/screenshotNotes). Classify by prompt intent only, no deterministic URL heuristics.";
    readonly sourceContext: "sourceFindings, sectionInventory, visualObservations, sourceRoles, qualityBar, screenshotReferences?, risks?";
    readonly designContexts: "Array<{ url? | imageRef?, label, markdown }> REQUIRED for every design_source from sourceIntent. Use `url` for browser-extracted DESIGN.md from inspiration URLs; use `imageRef` (the matching `image:<index>` ref) for DESIGN.md you derived from an attached image. For image-derived DESIGN.md, write `Not observed` for sections you cannot determine from the image (commonly Responsive Behavior, full interaction states) rather than inventing values.";
    readonly executionPlan: "{ mode: 'static_preview' | 'vite_app', confidence: low|medium|high, reason, assetPlan?: Array<{source, destination, referenceAs}>, runtimeRequirements?, userQuestion? } — choose vite_app for large local assets, model-viewer, Three.js, route structure, package deps, or files under public/; assetPlan.source must live under the approved asset root; static_preview for self-contained HTML/CSS/JS prototypes.";
};
/**
 * Stable per-session ref for image-derived design sources. Indexed over the
 * filtered list of image-kind artifacts so the ref survives reordering of
 * text-only artifacts in the same `sourceArtifacts` array.
 */
export declare const buildImageRefs: (artifacts: ReadonlyArray<{
    kind: string;
}> | undefined) => string[];
export declare class SessionStore {
    private readonly sessions;
    private readonly clock;
    constructor(clock?: SessionStoreClock);
    propose(args: ProposeArgs): ProposeResult;
    reportBriefs(args: {
        sessionId: string;
        workItemId: string;
        attempt: number;
        leaseId?: string;
        briefs: Brief[];
    }): {
        briefs: Brief[];
    };
    reportSourcePlan(args: ReportSourcePlanArgs): {
        briefWorkItem: WorkItem;
    };
    approve(args: {
        sessionId: string;
        selections: ApprovedBriefSelection[];
    }): ApproveResult;
    requestWork(args: {
        sessionId: string;
        leaseOwner: string;
        requestedLeaseCount?: number;
        workItemId?: string;
    }): RequestWorkResult;
    reportComplete(args: {
        sessionId: string;
        workItemId: string;
        leaseId: string;
        attempt: number;
        status: WorkItemStatus;
        output?: unknown;
        error?: {
            code: string;
            message: string;
        };
    }): ReportCompleteResult;
    /**
     * Creates a refinable HTML work item for a completed static preview variant.
     * The target variant remains the user-facing snapshot; this work item only
     * tracks the in-flight refinement and is surfaced through its `refinement`.
     */
    createRefineVariantWorkItem(args: {
        sessionId: string;
        variantId: string;
        instruction: string;
        currentHtml?: string;
    }): WorkItem;
    /**
     * Fold a newer instruction into a variant's still-pending refinement. Used
     * when a second refinement is requested for a variant that already has a
     * queued (not yet leased) refinement: the new instruction is appended so the
     * agent applies both rather than dropping the later request. Returns false
     * when no pending refinement exists.
     */
    appendPendingRefineVariantInstruction(args: {
        sessionId: string;
        variantId: string;
        instruction: string;
    }): boolean;
    /**
     * Lease the pending refinement already associated with a specific static
     * preview variant. Keeps multi-target refinement batches independent of
     * work-item order.
     */
    leaseRefineItemForVariant(args: {
        sessionId: string;
        variantId: string;
        leaseOwner: string;
    }): RequestWorkResult;
    /**
     * Mark a server-owned work item as succeeded without going through the
     * lease + agent-report path. Used for `scaffold_base` items where the
     * orchestrator runs the scaffold + npm install in the background and needs
     * to unblock dependent code_gen items when it's done.
     *
     * Bypasses lease validation because no lease was ever issued for internal
     * items. Idempotent: completing an already-succeeded item is a no-op.
     */
    completeInternal(args: {
        sessionId: string;
        workItemId: string;
        output?: unknown;
    }): ReportCompleteResult;
    /**
     * Mark a server-owned work item as failed, cascading DEPENDENCY_FAILED to
     * its dependents. Used when the orchestrator's background scaffold work
     * (npm install, file writes) fails and we need the session to degrade.
     */
    failInternal(args: {
        sessionId: string;
        workItemId: string;
        error: {
            code: string;
            message: string;
        };
    }): ReportCompleteResult;
    cancel(args: {
        sessionId: string;
        reason?: string;
    }): {
        stage: 'cancelled';
        cleanupStatus: 'pending' | 'complete' | 'partial';
    };
    /**
     * Cancel a single work item without tearing down its sibling variants or
     * the session itself. Idempotent on terminal states — already-cancelled,
     * succeeded, or failed items return their current status with
     * `alreadyTerminal: true` and no state change. Triggers
     * `evaluateTerminal` so the session can reach a terminal stage if this
     * was the last in-flight item.
     */
    cancelWorkItem(args: {
        sessionId: string;
        workItemId: string;
        reason?: string;
    }): {
        workItemId: string;
        finalStatus: WorkItemStatus;
        sessionStage: Stage;
        alreadyTerminal: boolean;
    };
    /**
     * Remove a variant from the UI. The work item is retained in the session
     * (and the caller persists it to `.rivet/variants/` as `removed`) but its
     * `removed` flag excludes it from the active snapshot, progress/summary, and
     * terminal evaluation — so it is never rendered again. Any in-flight work is
     * cancelled first so the hidden variant doesn't keep a lease or resurface via
     * `request_work`; terminal variants keep their final status. Idempotent.
     */
    removeWorkItem(args: {
        sessionId: string;
        workItemId: string;
    }): {
        workItemId: string;
        finalStatus: WorkItemStatus;
        sessionStage: Stage;
        alreadyRemoved: boolean;
    };
    /**
     * Rename a variant: patches the brief label held in the work item's `input`
     * blob (the same field `variantsOf` reads for the snapshot `label`), so the
     * next `emitChange` pushes the new title to the UI. Pure metadata edit — it
     * never touches status, lease, or refinement state. Idempotent.
     */
    renameWorkItem(args: {
        sessionId: string;
        workItemId: string;
        label: string;
    }): {
        workItemId: string;
        label: string;
        sessionStage: Stage;
    };
    recordVariantPick(args: {
        sessionId: string;
        envelope: VariantPickEnvelope;
    }): {
        duplicate: boolean;
    };
    getStage(sessionId: string): Stage;
    getPrompt(sessionId: string): string;
    /** The run's label — the agent-provided one if present, else a heuristic
     *  derived from the prompt. */
    getRunLabel(sessionId: string): string;
    getBriefs(sessionId: string): Brief[];
    getProgress(sessionId: string): {
        ready: number;
        total: number;
    };
    getSummary(sessionId: string): TerminalSummary;
    getVariants(sessionId: string): ActiveVariantSnapshot[];
    getVariantPick(sessionId: string): VariantPickEnvelope | undefined;
    /** Validates a report lease without mutating the work item. */
    validateReportLease(args: {
        sessionId: string;
        workItemId: string;
        leaseId: string;
        attempt: number;
    }): void;
    hasSession(sessionId: string): boolean;
    /** Read a work item's input blob — used by the orchestrator to recover
     *  briefLabel / target / projectContext when auto-enqueueing the diff. */
    getWorkItemInput(sessionId: string, workItemId: string): unknown;
    getWorkItemOutput(sessionId: string, workItemId: string): unknown;
    /** Replaces a completed work item's output after server-side post-processing. */
    replaceWorkItemOutput(sessionId: string, workItemId: string, output: unknown): void;
    /** Read a work item's `kind` discriminator (brief | source_plan |
     *  static_preview | code_gen | scaffold_base). Used by callers that need to
     *  branch their validation on the work-item shape — e.g. enforcing the
     *  inline-HTML contract on static_preview `succeeded` reports. */
    getWorkItemKind(sessionId: string, workItemId: string): WorkItem['kind'];
    /** True when the work item was removed or cancelled out from under the agent.
     *  The orchestrator checks this to short-circuit the schema/QA gates before a
     *  `report_variant_complete` it's about to abort. Non-throwing: unknown
     *  session or work item reads as not-aborted. */
    isWorkItemAborted(sessionId: string, workItemId: string): boolean;
    /** Read the projectContext for a session (existing | fresh). */
    getProjectContext(sessionId: string): ProjectContext;
    private requireSession;
    private requireWorkItem;
    private assertStage;
    private validateLease;
    private expireStaleLeases;
    private leasableItems;
    private hasLeasableCodeGenForStaticPreview;
    private dependenciesMet;
    private cascadeDependencyFailure;
    private terminalItems;
    /**
     * The work-item kind that represents a user-facing variant for this
     * session. Drives both progress accounting and the active variants
     * snapshot. Fresh+vite_app sessions use `code_gen` like existing
     * projects; fresh+static_preview (the default for source-less 0→1)
     * keeps `static_preview` as the deliverable.
     */
    private variantWorkItemKind;
    private evaluateTerminal;
    private progressOf;
    private summaryOf;
    private variantsOf;
}
//# sourceMappingURL=SessionStore.d.ts.map