import type { ChangeRequest, TelemetryContext } from '../types/change-request-types';
type SessionStatus = 'IDLE' | 'APPLYING' | 'READY';
export type DevServerOwnership = 'rivet_owned' | 'external' | 'none';
export type DevServerHealthReason = 'healthy' | 'upstream_unreachable' | 'rivet_unreachable' | 'unknown';
export type DevServerHealth = {
    ownership: DevServerOwnership;
    host: string | null;
    port: number | null;
    isReachable: boolean | null;
    reason: DevServerHealthReason;
    lastCheckedAt: number | null;
    startedByRivet: boolean;
};
type ActiveRunCorrelation = {
    traceId: string;
    agentRunId: string;
    startedAt: number;
    browserSessionId?: string;
};
type StartApplyingRunResult = {
    newRun: ActiveRunCorrelation;
    orphanedRun: ActiveRunCorrelation | null;
};
/**
 * Manages the lifecycle of an MCP visual editing session and queues
 * changes between the Rivet UI and the MCP server.
 *
 * Instantiated by the MCP server and shared in-memory with the Express
 * server so both MCP tool handlers and REST endpoints can access it.
 */
export declare class SessionBridgeService {
    private sessionId;
    private _setVariantTarget;
    private _variantLookup;
    private _isVariantPortAllowed;
    private statusAccessToken;
    private projectPath;
    private pendingChanges;
    private telemetryContext;
    private roundsCompleted;
    private feedback;
    private status;
    private waitResolve;
    private activeRunCorrelation;
    private devServerHealth;
    /**
     * Start a new MCP visual editing session
     * @returns The unique session ID
     */
    startSession(projectPath: string): string;
    /**
     * Add a feedback message to the session.
     * Feedback is shown in the Rivet UI to let the user know what the MCP client is doing.
     * Normalizes literal escape sequences (e.g. `\n`, `\t`) that MCP clients sometimes
     * emit instead of real whitespace characters.
     */
    reportFeedback(message: string): void;
    /** Get all feedback messages for the current session */
    getFeedback(): string[];
    /** Get the current session status */
    getStatus(): SessionStatus;
    /** Set the session status (used by MCP tools to indicate progress) */
    setStatus(status: SessionStatus): void;
    /** Check whether a session is currently active */
    isActive(): boolean;
    /** Get the current session ID, or null if no session is active */
    getSessionId(): string | null;
    /** Get the project path for the current session */
    getProjectPath(): string | null;
    /**
     * Rebind the active session to a new project root after a fresh-variant
     * handoff succeeds.
     */
    rebindProjectPath(projectPath: string): void;
    /**
     * Queue changes from the Rivet UI for retrieval by the MCP client.
     * Replaces any previously queued intent that hasn't been retrieved yet.
     */
    queueChangeRequest(intent: ChangeRequest): void;
    /**
     * Retrieve pending changes, or null if none is queued.
     * Does NOT clear the queue — call clearPending() after processing.
     */
    getPendingChanges(): ChangeRequest | null;
    /**
     * Block until changes are queued, or return immediately if already pending.
     * Used by watch_for_changes for clients without background monitoring (e.g. Cursor).
     * Rejects if the timeout is reached.
     */
    waitForChanges(timeoutMs?: number): Promise<ChangeRequest>;
    /**
     * Clear the pending changes queue and increment the round counter.
     * Call after the MCP client has retrieved and processed the intent.
     */
    clearPending(expectedIntent?: ChangeRequest): void;
    /**
     * Consume a single-item variant-request batch from the pending queue.
     *
     * Variant-request batches are not "applied" — they are routed into the MCP
     * variants lifecycle (propose_variants → approval → continue → commit). They
     * must NOT call startApplyingRun, must NOT fire trackChangesQueued /
     * trackAgentRunStarted, and must NOT increment the apply-run round counter.
     *
     * Returns the consumed intent so callers can derive the agent's
     * propose_variants target from it.
     */
    consumeVariantRequestBatch(expectedIntent?: ChangeRequest): ChangeRequest | null;
    /**
     * Consume a static-preview refinement batch from the pending queue.
     *
     * These batches refine an in-memory HTML variant through the variants MCP
     * lifecycle. They must not start a base project apply run or increment the
     * apply-round counter.
     */
    consumeStaticPreviewRefineBatch(expectedIntent?: ChangeRequest): ChangeRequest | null;
    /**
     * Remove variant-request comment items from a mixed pending batch while
     * preserving all non-variant items for a follow-up apply run.
     */
    rejectMixedVariantRequestBatch(expectedIntent?: ChangeRequest): ChangeRequest | null | undefined;
    /**
     * Mark the currently processing MCP apply run using identifiers from the queued request.
     */
    startApplyingRun(intent: ChangeRequest): StartApplyingRunResult;
    /**
     * Complete the active MCP run and clear it from bridge state.
     */
    completeActiveRunCorrelation(): ActiveRunCorrelation | null;
    /** Get the number of completed editing rounds in this session */
    getRoundsCompleted(): number;
    /** Get telemetry correlation data for the active session */
    getTelemetryContext(): TelemetryContext | null;
    /** Get dev-server health metadata for the active MCP session. */
    getDevServerHealth(): DevServerHealth;
    /** Set the base session dev-server context (ownership + endpoint). */
    setDevServerContext(context: {
        ownership: DevServerOwnership;
        host?: string | null;
        port?: number | null;
        startedByRivet: boolean;
    }): void;
    /** Update session dev-server health reason/reachability. */
    updateDevServerHealth(update: {
        isReachable?: boolean | null;
        reason?: DevServerHealthReason;
        lastCheckedAt?: number | null;
    }): void;
    /** Merge and store telemetry correlation data for the active session */
    private updateTelemetryContext;
    /** Inject the proxy's setVariantTarget fn (called from server.ts after proxy is created) */
    registerVariantTargetSetter(fn: (port: number | null) => void): void;
    /** Register a variant-key→port lookup function (called from mcp/server.ts after variant sessions are built) */
    registerVariantLookup(fn: (variantKey: string) => number | null): void;
    /** Register preview-port allowlist checker tied to the active variant session */
    registerVariantPortAllowlist(fn: (port: number) => boolean): void;
    /** Look up a variant's preview port by stable lookup key */
    lookupVariantPort(variantKey: string): number | null;
    /** Check whether a preview port is registered for the active variant session */
    isVariantPortAllowed(port: number): boolean;
    /** Register a status polling token used by Rivet UI. */
    setStatusAccessToken(token: string): void;
    /** Check whether a status polling token has already been registered. */
    hasStatusAccessToken(): boolean;
    /** Validate status polling token from API requests. */
    isStatusAccessTokenValid(token: string | null | undefined): boolean;
    /**
     * Advertise a Rivet-spawned committed dev server (vite_app or static
     * preview) on `devServerHealth` so `/api/mcp/status` and the iframe's
     * `usePreviewUpstreamHealth` probe see `ownership: 'rivet_owned'` + the
     * new port. Pass `null` to clear back to the no-server state. Distinct
     * from `switchPreviewPort` (which only retargets the proxy) and from
     * `setDevServerContext` (which the MCP server uses for the user's own
     * dev server during a regular session). Only the orchestrator's
     * commit-handoff path should call this — variant cycling and cancel
     * still go through `switchPreviewPort` and must NOT touch the user's
     * external dev-server health.
     */
    setCommittedDevServerHealth(port: number | null): void;
    /** Switch the proxy to a variant dev server (or back to user's dev server when port is null) */
    switchPreviewPort(port: number | null): void;
    /**
     * End the current session, clearing all state.
     * @returns The total number of completed rounds
     */
    endSession(): number;
}
export {};
//# sourceMappingURL=SessionBridgeService.d.ts.map