import type { ProgressEvent } from '@histoire/cli/protocol/progress';
import type { ConfigurationRevision } from '@histoire/dev-proxy/config';
import type { ViteDevServer } from 'vite';
import type { StoryCollectionOutcome } from '../collect/outcome.js';
import type { ConfigurationObserver } from '../config/dependencies.js';
import type { Context } from '../context.js';
import type { CollectionEvent } from '../server/collect.js';
import type { CreateServerOptions } from '../server/index.js';
/** Observable lifecycle of one independently owned project. */
export type ProjectRuntimeStatus = 'starting' | 'ready' | 'restarting' | 'failed' | 'closed';
/** Exact configuration bytes captured before one generation loads its config. */
export type ProjectConfigurationRevision = ConfigurationRevision;
/** Resources returned by one dev-server startup. */
export interface RuntimeGeneration {
    /** Private project context, never a client DTO. */
    context: Context;
    /** Client-facing dev server. */
    server: ViteDevServer;
    /** Initial scan, Markdown association, collection and invalidation completion. */
    ready: Promise<void>;
    /** Optional resolved Vite config filename for restart watching. */
    viteConfigFile?: string;
    /** Config revision captured before this generation read its effective config. */
    configurationRevision?: ProjectConfigurationRevision;
    /** Releases all owned resources once. */
    close: () => Promise<void>;
    /** Runs or joins the owned collection loop. */
    collect: () => Promise<void>;
    /** Registers collection publication observations. */
    onCollection: (handler: (event: CollectionEvent) => void | Promise<void>) => () => void;
    /** Latest private collection outcomes keyed by registered file path. */
    collectionOutcomes?: ReadonlyMap<string, StoryCollectionOutcome>;
}
/** Generation identity captured by reads and asynchronous operations. */
export interface ProjectRuntimeHandle extends RuntimeGeneration {
    /** Random identity replaced on restart. */
    epoch: string;
    /** True only while this generation owns its controller. */
    isActive: () => boolean;
}
/** Inputs common to CLI dev and the stdio project worker. */
export interface ProjectRuntimeOptions extends CreateServerOptions {
    /** Incremental loader inputs keep proxy watches alive across configuration failures. */
    onConfigurationInputs?: ConfigurationObserver;
    /** Reports evaluated inputs before expensive Vite/story acquisition. */
    onConfiguration?: (context: Context, revision: ProjectConfigurationRevision) => void | Promise<void>;
    /** Explicit project root; CLI defaults to its launch cwd. */
    root?: string;
    /** Explicit Histoire configuration module. */
    config?: string;
    /** Reserved transport policy; false disables dev HTTP in a stdio worker. */
    devHttp?: boolean;
    /** Runs before readiness; useful for attaching generation-owned facades. */
    onGeneration?: (handle: ProjectRuntimeHandle) => void | Promise<void>;
    /** Confirms server work stopped after ownership invalidation, before project teardown. */
    onBeforeRelease?: (handle: ProjectRuntimeHandle) => void | Promise<void>;
    /** Internal observer of real startup work for this generation; never part of the public plugin API. */
    onProgress?: (event: ProgressEvent) => void;
    /** Reports observed restart or startup failures without escaping watcher callbacks. */
    onError?: (error: unknown) => void;
}
/** Injectable acquisition seams used by lifecycle tests. */
export interface ProjectRuntimeDependencies {
    /** Acquires one generation without changing process cwd. */
    start: (options: ProjectRuntimeOptions, signal: AbortSignal, isActive: () => boolean) => Promise<RuntimeGeneration>;
    /** Owns both Vite and Histoire configuration watchers. */
    watch: (runtime: RuntimeGeneration, options: ProjectRuntimeOptions, restart: (source: string) => void, revision?: ProjectConfigurationRevision) => Promise<() => Promise<void>>;
}
//# sourceMappingURL=types.d.ts.map