import { EventEmitter } from 'node:events';
import { type RuntimeAdapter, type StreamObserver, type UserInputHandler, type UserInputResponse } from '@inharness-ai/agent-adapters';
import type { ChatService } from '../services/chat.js';
import type { PagesService } from '../services/pages.js';
import type { TagsService } from '../services/tags.js';
import type { SectionsService } from '../services/sections.js';
import type { PlanService } from '../services/plan.js';
import type { BriefService } from '../services/brief.js';
import type { PatchService } from '../services/patch.js';
import type { PageVersionService } from '../services/page-version.js';
import type { SkillResolver, SkillRegistry } from '../services/skill-registry.js';
import type { Annotation, ChatThread } from '../../shared/entities.js';
import type { WsGateway } from '../ws/gateway.js';
import type { Db } from '../db/index.js';
/** Deps potrzebne do uruchomienia tury agenta. Wspolne dla `POST /api/chat`
 *  (SSE) i `POST /api/threads/:id/ask` (headless). */
export interface AgentTurnDeps {
    chatService: ChatService;
    pagesService: PagesService;
    tagsService: TagsService;
    sectionsService: SectionsService;
    planService: PlanService;
    briefService: BriefService;
    patchService: PatchService;
    pageVersions: PageVersionService;
    skillResolver: SkillResolver;
    skillRegistry: SkillRegistry;
    ws: WsGateway;
    cwd: string;
    pagesDir: string;
    mode: 'dev' | 'prod';
    db: Db;
}
export declare const ALLOWED_MODELS: readonly ["sonnet-4.6", "opus-4.8", "haiku-4.5"];
export type Model = (typeof ALLOWED_MODELS)[number];
interface PendingInput {
    resolve: (response: UserInputResponse) => void;
    reject: (reason: unknown) => void;
    requestIdsForRequest: string;
}
export interface ActiveAdapter {
    requestId: string;
    adapter: RuntimeAdapter;
    emitter: EventEmitter;
}
export declare const activeAdapters: Map<string, ActiveAdapter>;
export declare const pendingInputs: Map<string, PendingInput>;
export declare function cancelPendingForRequest(requestId: string): void;
/** Typed blad tury — pozwala konsumentom (headless `ask`) zmapowac powod
 *  zakonczenia na status HTTP. Te same kody co SSE `event: error`. */
export declare class AgentTurnError extends Error {
    code: 'ABORTED' | 'TIMEOUT' | 'AGENT_UNAVAILABLE' | 'AGENT_ERROR';
    constructor(code: 'ABORTED' | 'TIMEOUT' | 'AGENT_UNAVAILABLE' | 'AGENT_ERROR', message: string);
}
type TurnEvent = {
    type: string;
} & Record<string, unknown>;
export interface AgentTurnInput {
    /** Watek juz rozwiazany przez callera (+ planMode zaaplikowany). */
    thread: ChatThread;
    prompt: string;
    annotations?: Annotation[];
    model: Model;
    currentPage?: string | null;
    architectureConfig: Record<string, unknown>;
    requestId: string;
    consoleObserver: StreamObserver | null;
    /** Transport callera — SSE forwarder dla `POST /api/chat`, no-op dla `ask`. */
    onEvent: (event: TurnEvent) => void;
    /** Interaktywny kanal user-input. Brak = headless (np. `ask`). */
    onUserInput?: UserInputHandler;
}
export interface AgentTurnResult {
    threadId: string;
    answer: string;
}
/**
 * Uruchamia jedna ture agenta dla istniejacego watku: wstawia wiadomosc user,
 * buduje runtime przez rejestr `context_type`, wykonuje `adapter.execute(...)`,
 * persystuje eventy mapperem `UnifiedEvent → chat_message`. Caller wybiera
 * transport przez `onEvent` (SSE vs collapse). Zwraca `{ threadId, answer }`,
 * gdzie `answer` to skolapsowany tekst assistant tej tury.
 *
 * Pre-flight `activeAdapters.has` (→ 409) NALEZY do callera; ta funkcja
 * rejestruje adapter w `activeAdapters` i zwalnia go w `finally`.
 */
export declare function runAgentTurn(deps: AgentTurnDeps, input: AgentTurnInput): Promise<AgentTurnResult>;
export declare function countPages(tree: Array<{
    type: string;
    children?: unknown[];
}>): number;
export {};
