import { type AiAppFact } from "@superblocksteam/library-shared/types";
import { TracedEventEmitter } from "@superblocksteam/shared";
import { ChatSessionStore } from "./chat/chat-session-store.js";
import { AppContextStore } from "./context/app-context.js";
import { RecordingManager } from "./recording/index.js";
import type { FileSystemManager } from "../file-system-manager.js";
import type { SourceTracker } from "../source-tracker.js";
import type { JudgeEvaluationOptions, JudgeEvaluationResult } from "./judge/judge-service.js";
import type { AiServiceConfig, AiServiceEvents, EditorClient, UserChange, ApiUpdate } from "./types.ts";
import type { ContextId } from "./llm/context-v2/types.js";
import type { AiGenerateRequest, AiExplainCodeRequest, AiLabelAttachmentRequest, AiLabelAttachmentResponse, AiToolPermission, LLMProviderConfig, PromptContext, RuntimeErrorData, ConsoleLogEntry, ApiRunRecord } from "@superblocksteam/library-shared/types";
import type { ViteDevServer } from "vite";
export { AiServiceFeatureFlags } from "./features.js";
export { SnapshotManager } from "./recording/index.js";
export { isSdkApiTemplate } from "./sdk-api-templates.js";
export declare function pruneByTTL<T extends {
    timestamp?: number;
    generationTimestamp?: string;
}>(items: T[], ttlMs: number): T[];
export declare function estimateSize(obj: unknown): number;
export declare function truncateString(str: string, maxBytes: number): string;
export declare function pruneBySize<T extends {
    _size?: number;
}>(items: T[], maxBytes: number): T[];
export declare class AiService extends TracedEventEmitter<AiServiceEvents> {
    private readonly config;
    private artifactProcessor;
    private templateRenderer;
    private appShell;
    private fileSystemInterface;
    private integrationStore;
    private knowledgeManager;
    private _appContext;
    private llmProviderSettings;
    private _logger;
    private readonly clark;
    private clarkProfiler;
    readonly chatSessionStore: ChatSessionStore;
    private readonly contextManagerV2;
    private readonly llmClient;
    private readonly toolRegistry;
    private readonly entityPermissionStore;
    private _onGenerationCompleteCallback;
    private tokenManagerJwt?;
    private viteServer?;
    private readonly mcpServerManager;
    private readonly recordingManager;
    private readonly sessionId;
    get appContext(): AppContextStore;
    get clarkState(): string;
    get appRootDirPath(): string;
    get organizationId(): string;
    get superblocksBaseUrl(): string;
    /**
     * Gets the contextId for the current conversation context.
     * Returns null if JWT is missing or has no userId.
     */
    getContextId(): ContextId | null;
    /**
     * Gets the JWT from Clark context
     */
    getClarkJwt(): string | undefined;
    /**
     * Updates the JWT in Clark context
     */
    updateClarkJwt(jwt: string): void;
    /**
     * Check if recording is currently enabled.
     */
    isRecording(): boolean;
    /**
     * Get the current recording session ID.
     */
    getRecordingSessionId(): string | null;
    /**
     * Clear all recordings.
     *
     * @param sessionId - Optional session ID to clear only that session
     */
    clearRecordings(sessionId?: string): Promise<void>;
    /**
     * Get the RecordingManager instance for advanced usage.
     * This allows external code to add custom recording middleware.
     */
    getRecordingManager(): RecordingManager;
    /**
     * Returns the set of integration IDs available in the current environment.
     */
    getAvailableIntegrationIds(): Promise<Set<string>>;
    get isSessionManagementEnabled(): boolean;
    /**
     * Checks if there is a connected peer (user is connected via socket)
     */
    hasConnectedPeer(): boolean;
    constructor(config: AiServiceConfig);
    /**
     * Initialize the AI service. Must be called after construction.
     * Sets up storage, cleanup tasks, and starts recording.
     */
    initialize(): Promise<void>;
    /**
     * Remove the integration metadata cache for this session.
     * Cleans up the session cache directory.
     */
    removeIntegrationCache(): Promise<void>;
    private getLogger;
    private createClarkTransitionHandler;
    private getJwt;
    private createClarkTagProviderFactory;
    handleAiGenerate(request: AiGenerateRequest, peer: EditorClient, peerId: string): Promise<void>;
    handleAiExplainCode(request: AiExplainCodeRequest, peer: EditorClient): Promise<void>;
    handleAiLabelAttachment(request: AiLabelAttachmentRequest): Promise<AiLabelAttachmentResponse>;
    /**
     * Converts an attachment to the appropriate LLM content part.
     */
    private attachmentToContentPart;
    private submitAcceptanceEvaluation;
    handleUserAcceptedDraft(peer: EditorClient, silently?: boolean): Promise<void>;
    handleUserRejectedDraft(peer: EditorClient, silently?: boolean): Promise<void>;
    handleUserCanceled(): Promise<void>;
    /**
     * Submit a prompt with interrupt behavior.
     * If not busy, starts immediately. Otherwise interrupts and continues.
     */
    handleAiGenerateWithQueue(request: AiGenerateRequest, peer: EditorClient, peerId: string, mode: "queue" | "interrupt"): Promise<{
        status: "started" | "interrupted";
    }>;
    /**
     * Interrupt current generation and continue with new prompt.
     * The partial response is preserved in chat history for context.
     */
    private interruptAndContinue;
    /**
     * Wait for the FSM to transition out of busy state after abort.
     *
     * Resolves when idle, rejects after 20s. The caller must NOT replace
     * the AbortController before this settles — the running generation
     * re-reads the signal on each streamText / tool call and would
     * "un-abort" itself if given a fresh controller.
     */
    private waitForAbortComplete;
    handleSkipTestCase(testRunId: string, testCaseId: string): Promise<void>;
    /**
     * Handles the user's response to a tool permission request.
     *
     * If approved, immediately executes the tool with the original input,
     * injects the tool call and result into the conversation context,
     * and restarts the LLM with the updated context.
     *
     * If denied, injects a tool error into the context and restarts the LLM.
     */
    handleAiRespondToToolPermission(request: {
        messageId: string;
        approved: boolean;
        alwaysAllowPermissions?: AiToolPermission[];
        denyMessage?: string;
    }, peer: EditorClient, peerId: string): Promise<void>;
    handleUserConnected(peer: EditorClient, peerId: string): void;
    handleUserDisconnected(peerId: string): void;
    private clearPeerConnection;
    handleBuildSystemError(error: Error): void;
    handleRuntimeError(errorData: RuntimeErrorData): void;
    handleClearRuntimeError(id: string): void;
    handleConsoleLog(logEntry: ConsoleLogEntry): void;
    handleApiRunRecord(apiId: string, runRecord: ApiRunRecord): void;
    handleClearRuntimeErrors(before?: number): void;
    handleClearBuildSystemErrors(): void;
    handlePromptInterpretation(request: {
        prompt: string;
        jwt: string;
        promptContext?: PromptContext;
    }, peer: EditorClient): Promise<void>;
    /**
     * Handles judge evaluation requests.
     *
     * Evaluates an application against a prompt using the judge system.
     * The evaluation is automatically stored to CSV for later analysis.
     *
     * @param request - Judge evaluation request
     * @returns Evaluation result with scores and feedback
     */
    handleJudgeEvaluation(request: {
        promptId: string;
        prompt: string;
        appId: string;
        appUrl: string;
        jwt: string;
        llmConfig?: LLMProviderConfig;
        options?: Partial<JudgeEvaluationOptions>;
        storageStateData?: any;
    }): Promise<JudgeEvaluationResult>;
    handleUserChange(change: UserChange): void;
    handleNewChat(): Promise<void>;
    /**
     * Returns all saved app skill facts for the current application.
     */
    getAppFacts(): Promise<AiAppFact[]>;
    /**
     * Deletes an app skill fact by its virtual path.
     */
    deleteAppFact(virtualPath: string): Promise<void>;
    /**
     * Toggles the isEnabled field of an app skill fact and returns the updated fact.
     */
    toggleAppFact(virtualPath: string, isEnabled: boolean): Promise<AiAppFact>;
    handleRestoreToCommit(sinceTimestamp: number, commitId: string, applicationId: string, branchName: string): Promise<void>;
    handleApiUpdate(update: ApiUpdate): Promise<void>;
    isBusy(): boolean;
    isAwaitingUser(): boolean;
    /**
     * Check if Clark is currently generating code.
     * Used by lock-service to determine if lock should be held during generation.
     * @returns true if Clark is in a generating state (AgentPlanning, LLMGenerating, PostProcessing, RuntimeReviewing)
     */
    isGenerating(): boolean;
    /**
     * Wait for Clark generation to complete.
     * Generation means that Clark is either in Plan Mode or Build Mode
     * If Clark is not currently generating, resolves immediately.
     * Used by lock-service to wait for generation before releasing lock.
     * @returns Promise that resolves when generation completes (or immediately if not generating)
     */
    waitUntilGenerationComplete(): Promise<void>;
    /**
     * Manually trigger the generation complete callback.
     * Should be called when Clark transitions to Idle or AwaitingUser state.
     */
    private triggerGenerationComplete;
    isGeneratingFullAppOrBroadUpdate(): Promise<boolean>;
    setSourceTracker(sourceTracker: SourceTracker | undefined): void;
    setFileSystemManager(fileSystemManager: FileSystemManager): void;
    setViteServer(server: ViteDevServer): void;
    getViteServer(): ViteDevServer | undefined;
    private getLLMProviderSettings;
}
//# sourceMappingURL=index.d.ts.map