/**
 * HTTP handlers for `/api/apps`, `/api/apps/:id`, `/api/apps/:id/dashboards/:did`,
 * `/api/persona`. Designed to be invoked from `local-runtime.ts`'s request
 * dispatcher — returns `true` if the request was handled, `false` otherwise.
 */
import type { IncomingMessage, ServerResponse } from 'node:http';
import { type AppDocument } from '@duckcodeailabs/dql-core';
import { type LocalAppInvestigationIntent } from '@duckcodeailabs/dql-project';
interface Ctx {
    req: IncomingMessage;
    res: ServerResponse;
    url: URL;
    path: string;
    projectRoot: string;
    executeSql?: (sql: string) => Promise<unknown>;
    generateInvestigationSql?: (input: AppInvestigationGenerationRequest) => Promise<AppInvestigationGenerationResult>;
    runNotebook?: (appId: string, notebookPath: string) => Promise<void>;
}
export declare function handleAppsApi(ctx: Ctx): Promise<boolean>;
type AppListEntry = {
    id: string;
    name: string;
    domain: string;
    subdomain?: string;
    groups: string[];
    description?: string;
    audience?: string;
    lifecycle: NonNullable<AppDocument['lifecycle']>;
    certification: 'certified' | 'uncertified';
    status?: 'ready' | 'empty' | 'review';
    storage: 'shared' | 'mine' | 'template';
    visibility: NonNullable<AppDocument['visibility']>;
    owners: string[];
    tags: string[];
    members: number;
    roles: number;
    policies: number;
    schedules: number;
    dashboards: Array<{
        id: string;
        title: string;
    }>;
    notebooks: Array<{
        path: string;
        title?: string;
        role: 'source' | 'analysis' | 'supporting';
        visibility: NonNullable<AppDocument['visibility']>;
    }>;
    drafts: Array<{
        path: string;
        name: string;
        reviewStatus?: string;
    }>;
    aiPins: number;
    investigations: number;
    homepage?: AppDocument['homepage'];
};
declare function collectAppsList(projectRoot: string): AppListEntry[];
interface AppRecommendationRequest {
    domain?: string;
    tags?: string[];
    purpose?: string;
    audience?: string;
    certifiedOnly?: boolean;
}
interface AppCreateRequest {
    name?: string;
    domain?: string;
    dashboardTitle?: string;
    subdomain?: string;
    groups?: string[];
    purpose?: string;
    audience?: string;
    visibility?: 'shared' | 'private' | 'template';
    lifecycle?: AppDocument['lifecycle'];
    tags?: string[];
    owners?: string[];
    selectedBlockIds?: string[];
}
interface AppGenerateRequest {
    prompt?: string;
    domain?: string;
    owner?: string;
    force?: boolean;
    selectedBlockIds?: string[];
}
interface AppInvestigationGenerationRequest {
    appId: string;
    dashboardId?: string;
    sourceTileId?: string;
    sourceBlockId?: string;
    title?: string;
    question: string;
    intent: LocalAppInvestigationIntent;
    context?: unknown;
}
interface AppInvestigationGenerationResult {
    sql?: string;
    answer?: string;
    result?: unknown;
    analysisPlan?: unknown;
    evidence?: unknown;
    citations?: unknown[];
    suggestedViz?: string;
    executionError?: string;
    providerUsed?: string;
}
interface BlockCandidate {
    id: string;
    name: string;
    domain: string;
    status: string;
    owner: string | null;
    tags: string[];
    path: string;
    lastModified: string;
    description: string;
    llmContext: string | null;
    chartType?: string;
    score: number;
    reasons: string[];
}
export declare function recommendBlocks(projectRoot: string, input: AppRecommendationRequest): BlockCandidate[];
export declare function generateAppPackage(projectRoot: string, input: AppGenerateRequest): Promise<{
    ok: true;
    plan: unknown;
    validation: unknown;
    generated: {
        paths: string[];
    };
    app: ReturnType<typeof collectAppsList>[number] | null;
    dashboardId: string | null;
} | {
    ok: false;
    error: string;
}>;
export declare function createAppPackage(projectRoot: string, input: AppCreateRequest): {
    ok: true;
    app: ReturnType<typeof collectAppsList>[number];
    paths: string[];
    dashboardId: string;
} | {
    ok: false;
    error: string;
};
declare function selectedBlockContext(context: unknown): Record<string, unknown> | null;
declare function buildPreviewMetricSnapshot(preview: Record<string, unknown>, fallbackTitle?: string): Record<string, unknown>;
declare function buildPreviewDriverCards(preview: Record<string, unknown>, intent: LocalAppInvestigationIntent): Array<Record<string, unknown>>;
declare function buildDeterministicInvestigationSql(projectRoot: string, input: {
    question: string;
    intent: LocalAppInvestigationIntent;
    selected: Record<string, unknown> | null;
    sourceBlockId?: string;
}): {
    sql: string;
    sourceBlockPath: string;
    sourceBlockName: string;
} | undefined;
declare function loadAppById(projectRoot: string, id: string): {
    app: AppDocument;
    dashboards: Array<{
        id: string;
        title: string;
        description?: string;
        itemCount: number;
    }>;
    notebooks: AppListEntry['notebooks'];
    drafts: AppListEntry['drafts'];
    aiPins: unknown[];
    investigations: unknown[];
} | null;
export declare function listNotebookCandidates(projectRoot: string, app: AppDocument, appDir: string): Array<{
    path: string;
    title: string;
    attached: boolean;
    role?: 'source' | 'analysis' | 'supporting';
    visibility?: NonNullable<AppDocument['visibility']>;
    lastModified?: string;
}>;
export declare function createNotebookForApp(projectRoot: string, appId: string, input: {
    name?: string;
    title?: string;
    role?: string;
    visibility?: string;
    template?: string;
}): {
    ok: true;
    path: string;
    app: ReturnType<typeof loadAppById>;
    preview: unknown;
} | {
    ok: false;
    error: string;
};
export declare function previewNotebookForApp(projectRoot: string, appId: string, notebookPath: string): {
    ok: true;
    preview: unknown;
} | {
    ok: false;
    status: number;
    error: string;
};
export declare const __test__: {
    buildPreviewDriverCards: typeof buildPreviewDriverCards;
    buildPreviewMetricSnapshot: typeof buildPreviewMetricSnapshot;
    buildDeterministicInvestigationSql: typeof buildDeterministicInvestigationSql;
    selectedBlockContext: typeof selectedBlockContext;
};
export {};
//# sourceMappingURL=apps-api.d.ts.map