import type { MessageBus } from '../infra/bus/index.js';
import { type Config } from '../config/schema.js';
import type { ChannelManager } from '../channels/manager.js';
import { SessionStore } from '../session/index.js';
import { OutboundCoordinator } from './messaging/index.js';
import { TurnDispatcher } from './inbound/turn-dispatcher.js';
import { SessionConfigService, SessionHydrator, SessionInspector } from './session/index.js';
import { type SkillCatalogEntry } from './agent-manager.js';
import type { SkillMarkdownPreviewPayload } from './skills/types.js';
import type { AgentServiceConfig, StreamHandle } from './service.types.js';
import { PersistentGoalService } from './goals/persistent-goal-service.js';
export type { AgentServiceConfig, AgentContext, StreamHandle } from './service.types.js';
export declare class AgentService {
    /**
     * Persistent transcript + session-metadata store. Public so the gateway/TUI
     * can read sessions, delete them, etc. without forcing every CRUD-style
     * operation through a delegation method on `AgentService`.
     */
    readonly sessionStore: SessionStore;
    private sessionConfigStore;
    private hookRunner?;
    private agentId;
    private workspaceDir;
    private channelManagerRef;
    private bus;
    private config;
    private sessionTracker;
    private modelManager;
    private progressManager;
    private hookHandler;
    private lifecycleManager;
    private errorTracker;
    private requestLimiter;
    private systemReminder;
    private toolUsageAnalyzer;
    private toolChainTracker;
    private errorPatternMatcher;
    private selfVerifyMiddleware;
    private contextMiddleware;
    private messageRouter;
    private commandHandler;
    private streamManager;
    /**
     * Outbound pipeline: typing controller, silence guard, final response publish,
     * extension `message_sending`/`message_sent` hooks, post-turn `webchat_turn_complete`
     * event. Public so the gateway / channels can drive it directly.
     */
    readonly outboundCoordinator: OutboundCoordinator;
    private inboundLoop;
    /**
     * Direct-turn entry points: `processDirect` (one-shot), `processDirectStreaming`
     * (SSE generator), webchat steering and SSE injection. Public so the gateway,
     * TUI, CLI, and cron jobs do not need to thread every call through `AgentService`.
     */
    readonly turnDispatcher: TurnDispatcher;
    /**
     * `/goal` runtime: continuation scheduling, persistent-goal API factory,
     * stream-outcome state, post-turn verdict. Public so the gateway can wire
     * the webchat continuation scheduler and read stream outcomes directly.
     */
    readonly persistentGoals: PersistentGoalService;
    /**
     * Per-session config writes (model / thinking / reasoning / working directory).
     * Public so REST endpoints and CLI flows can hit it without going through a
     * monolithic patch entrypoint on `AgentService`.
     */
    readonly sessionConfig: SessionConfigService;
    /**
     * Hydration — read persisted per-session config and apply it to the runtime
     * (AgentManager / ModelManager). The mirror image of `sessionConfig`: writes
     * go through `sessionConfig`, reads-into-runtime go through `sessionHydrator`.
     */
    readonly sessionHydrator: SessionHydrator;
    /**
     * Read-only introspection (compaction, /context report, /btw, contextUsage,
     * agentConfig view). Public so REST endpoints and CLI flows can query a
     * session's view without going through delegating methods on `AgentService`.
     */
    readonly sessionInspector: SessionInspector;
    private sessionContextManager;
    private sessionLifecycleManager;
    private agentOrchestrator;
    private agentEventHandler;
    private workflowProgressBrokerHandle;
    private feedbackCoordinator;
    private agentManager;
    /**
     * Unified per-session state container (replaces six ad-hoc Maps). Owns webchat
     * publishers, last assistant text, embedded stream buffer, persistent-goal stream
     * outcomes, concurrent-turn depth, and event-listener unsubscribers; runs a TTL
     * sweep for slots that have no explicit owner.
     */
    private sessionState;
    /** Gateway: notify UI after direct `SessionStore.updateMetadata` (no SessionManager emit). */
    private onSessionMetadataUpdated?;
    private onSessionTranscriptUpdated?;
    private effectiveAppConfig;
    constructor(bus: MessageBus, config: AgentServiceConfig);
    private attachmentRootsForSession;
    private createSessionStore;
    private createHookRunner;
    private createProgressManager;
    private initializeReliabilityModules;
    private initializeLifecycleHandlers;
    setChannelManager(channelManager: ChannelManager): void;
    /**
     * Apply config after save or hot reload so the default model updates without restarting the gateway.
     */
    applyAgentDefaultsFromConfig(config: Config): void;
    getSkillCatalog(lang?: string): SkillCatalogEntry[];
    getSkillMarkdownSource(skillName: string, lang?: string): SkillMarkdownPreviewPayload | null;
    refreshSkillsAfterDiskChange(): void;
    refreshSkillsAfterSkillConfigChange(): void;
    getModelForSession(sessionKey: string): string;
    switchModelForSession(sessionKey: string, modelId: string): Promise<boolean>;
    /**
     * Clears per-session model override so the next turn uses the configured agent default
     * (e.g. cron isolated job with no explicit model).
     */
    resetSessionModelToAgentDefault(sessionKey: string): Promise<void>;
    setStreamHandle(handle: StreamHandle): void;
    clearStreamHandle(): void;
    /** Last assistant visible plain text for a session (e.g. after a webchat stream). */
    getLastAssistantPlainText(sessionKey: string): string;
    beginInboundTurn(sessionKey: string): void;
    endInboundTurn(sessionKey: string): void;
    getInboundTurnDepth(sessionKey: string): number;
    start(): Promise<void>;
    stop(): Promise<void>;
    /**
     * Reconcile managed Dreaming cron job against the current effective config.
     * Safe to call after config saves to apply changes without restarting the process.
     */
    reconcileDreamingNow(): Promise<void>;
    private reconcileDreamingCronJob;
    /**
     * Persist agent messages with the same sanitizer + transcript hygiene as AgentOrchestrator.
     * Uses persistence hygiene so `thinking` blocks remain on disk for the web UI (LLM load path still drops them).
     */
    /**
     * Fire-and-forget: `maybeAutoTitleSessionStore` no-ops for cron/heartbeat keys.
     * Runs after persist so the store has the latest transcript; does not block SSE / callers.
     */
    private enqueueMaybeAutoTitleAfterPersist;
    private prepareLoadedSessionMessages;
    private parseSessionKey;
    private initSessionContext;
    /**
     * Persist inbound file attachments under agent home `inbound/` (non-images with data).
     * Idempotent if `workspaceRelativePath` is already set on an attachment.
     */
    prepareInboundAttachments(sessionKey: string, attachments?: Array<{
        type: string;
        mimeType?: string;
        data?: string;
        name?: string;
        size?: number;
        workspaceRelativePath?: string;
    }>): Promise<Array<{
        type: string;
        mimeType?: string;
        data?: string;
        name?: string;
        size?: number;
        workspaceRelativePath?: string;
    }> | undefined>;
    private endDirectRequestContext;
    /**
     * Reset a session's transcript and drop the in-memory agent so the next turn
     * reloads from disk. Combines two collaborators (sessionStore + agentManager)
     * so it stays on `AgentService`; pure sessionStore reads should use
     * `agentService.sessionStore.*` directly.
     */
    clearSessionMessages(key: string): Promise<void>;
    /**
     * Reset session transcript (archive + new session id) and evict in-memory agent state.
     * Preserves the session key and persisted per-session overrides.
     */
    resetSession(key: string): Promise<{
        sessionId: string;
        previousSessionId: string;
    } | null>;
    /**
     * Drop in-memory agent so the next turn reloads transcript from disk (e.g. after checkpoint restore).
     */
    evictSessionAgent(sessionKey: string): void;
    /**
     * Load session working directory override into AgentManager, ensure directory exists.
     * Call before AgentManager.getOrCreateAgent for this session.
     */
    /** Workspace root for UI file tree / editor (same as agent tools after hydration). */
    getEffectiveWorkspacePathForSession(sessionKey: string): Promise<string>;
    /**
     * Best-effort timezone resolution for webchat envelope timestamps.
     * Reads `USER.md` under the agent `profile/` directory and extracts a `Timezone:` line.
     */
    resolveUserTimezoneForSession(sessionKey: string): string | undefined;
    /**
     * Setup event handling for a specific session
     */
    private setupSessionEventHandling;
    /**
     * Handle events from a specific session's agent
     */
    private handleSessionEvent;
    private checkAndCompact;
    private getContextWindow;
    private dispose;
}
