/**
 * Types for Page Converter
 *
 * Defines input/output types for converting full page HTML/JSX
 * into CMS page structures with block mappings.
 *
 * Architecture (2 passes):
 * - Pass 1: HTML + block catalog → sections with HTML + match decisions
 * - Pass 2: sections + matches → populated blocks
 */
import type { Theme, CustomCssRuleInput, CustomCssAtRuleInput } from '../contracts';
import type { SdkCustomBlock, BlockCategory } from '../config/types';
export type FieldSummary = {
    id: string;
    type: string;
    label?: string;
    description?: string;
    required?: boolean;
    options?: Array<{
        value: string;
        label: string;
    }>;
    /**
     * Repeater item field summaries (for `type: 'repeater'`).
     * Mirrors the schema used elsewhere in the repo for LLM-facing summaries.
     */
    itemFields?: FieldSummary[];
    /**
     * Nested field summaries (for object/group-like fields).
     * Note: repeaters should prefer `itemFields`.
     */
    fields?: FieldSummary[];
};
export type ContentPattern = {
    type: string;
    signals?: string[];
};
export type BlockSummaryForLLM = {
    name: string;
    title: string;
    description?: string;
    category: BlockCategory;
    tags?: string[];
    contentTypes?: string[];
    fieldSummary: FieldSummary[];
    matchPatterns?: ContentPattern[];
};
/**
 * Summary of a content type available for the LLM to use.
 * Provides enough context for the LLM to decide when to use
 * content entries vs repeater fields vs plain fields.
 */
export interface ContentTypeSummary {
    /** Content type key (e.g., 'event', 'testimonial', 'post') */
    key: string;
    /** Human-readable name */
    name: string;
    /** Description for LLM context */
    description?: string;
    /** Schema fields for this content type */
    fields: FieldSummary[];
    /** Whether this content type has its own routable pages */
    isRouted: boolean;
}
/**
 * Configuration for a content entry to create.
 * Extracted from HTML when the LLM decides to use content types.
 */
export interface EntryConfig {
    /** Unique identifier within site+contentType (slug-safe) */
    identifier: string;
    /** Content type key (e.g., 'event', 'testimonial') */
    contentType: string;
    /** Entry title */
    title: string;
    /** Entry data matching the content type schema */
    data: Record<string, unknown>;
    /** Entry status */
    status?: 'draft' | 'published';
}
/**
 * Configuration for a new content type to create.
 * Used when no existing content type fits the data.
 */
export interface ContentTypeConfig {
    /** Content type key (slug-safe) */
    key: string;
    /** Human-readable name */
    name: string;
    /** Description */
    description?: string;
    /** Schema fields */
    fields: Array<{
        id: string;
        type: string;
        label: string;
        required?: boolean;
        description?: string;
    }>;
    /** Whether this content type should be routable */
    isRouted: boolean;
}
/**
 * Input for page-to-blocks conversion.
 */
export interface PageConverterInput {
    /** Full page HTML/JSX content */
    html: string;
    /** Optional separate CSS file content */
    css?: string;
    /** Theme JSON - required for mapping styles to tokens */
    theme: Theme;
    /** Available built-in blocks for matching */
    availableBlocks: BlockSummaryForLLM[];
    /**
     * Available content types for the LLM to consider.
     * When provided, the LLM may decide to create content entries
     * instead of using repeater fields for list-like content.
     */
    availableContentTypes?: ContentTypeSummary[];
    /**
     * Minimum match score (0-100) for using a built-in block.
     * Sections scoring below this threshold get custom blocks.
     * @default 80
     */
    matchThreshold?: number;
}
/** Section type classification */
export type SectionType = 'header' | 'content' | 'footer';
/**
 * Base fields shared by all section matches.
 */
interface BaseSectionMatch {
    /** The actual HTML/JSX content for this section */
    html: string;
    /** Brief description of section purpose (e.g., "hero banner", "testimonials") */
    purpose: string;
    /** Section type classification */
    sectionType: SectionType;
}
/**
 * Section matched to a built-in block.
 */
export interface BuiltinSectionMatch extends BaseSectionMatch {
    decision: 'builtin';
    /** Name of the matched built-in block (must match a key from available blocks) */
    matchedBlock: string;
    /** Match confidence score 0-100 */
    matchScore: number;
    /** Explanation of why this block was chosen */
    matchRationale: string;
}
/**
 * Section requiring a custom block.
 */
export interface CustomSectionMatch extends BaseSectionMatch {
    decision: 'custom';
    /** Suggested custom block metadata */
    customBlockSuggestion: {
        /** Human-readable title */
        title: string;
        /** Block category */
        category: BlockCategory;
    };
}
/**
 * A section match from Pass 1 (discriminated union).
 */
export type SectionMatch = BuiltinSectionMatch | CustomSectionMatch;
/**
 * Content that was intentionally skipped (imports, types, data constants).
 */
export interface SkippedContent {
    /** Description of what was skipped (e.g., "TypeScript imports") */
    description: string;
    /** Reason for skipping (e.g., "non-UI code") */
    reason: string;
}
/**
 * Output from Pass 1 (combined segmentation + matching).
 */
export interface Pass1Output {
    /** Matched sections (UI content only) */
    sections: SectionMatch[];
    /** Content that was skipped (imports, types, data) */
    skippedContent: SkippedContent[] | null;
    /** Explanation of segmentation and matching decisions */
    rationale: string;
}
/**
 * Content extracted for a block.
 */
export interface BlockContent {
    /** Block kind (e.g., "block.hero" or "custom.pricing-table") */
    kind: string;
    /** Order index on the page */
    orderIndex: number;
    /** Section purpose for organization */
    purpose: 'header' | 'content' | 'footer';
    /** Content values mapped to block fields */
    content: Record<string, unknown>;
}
/**
 * A block in the page output.
 */
export interface PageBlock {
    /** Block kind identifier */
    kind: string;
    /** Order index on the page */
    orderIndex: number;
    /** Section purpose */
    purpose: 'header' | 'content' | 'footer';
    /** Content values for block fields */
    content: Record<string, unknown>;
}
/**
 * Output from page-to-blocks conversion.
 */
export interface PageConverterOutput {
    /** Page structure */
    page: {
        /** Page name */
        name: string;
        /** Page path */
        path: string;
        /** Ordered blocks for the page */
        blocks: PageBlock[];
    };
    /** Custom block definitions (when built-in blocks don't match) */
    customBlocks?: Array<SdkCustomBlock & {
        /** Custom CSS rules for this block */
        customCssRules?: CustomCssRuleInput[];
        /** Custom CSS at-rules for this block */
        customCssAtRules?: CustomCssAtRuleInput[];
    }>;
    /**
     * Content entries to create.
     * Generated when the LLM decides to use content types
     * instead of repeater fields for list-like content.
     */
    entries?: EntryConfig[];
    /**
     * Custom content types to create.
     * Generated when no existing content type fits the data.
     */
    contentTypes?: ContentTypeConfig[];
}
/**
 * Details of a single conversion attempt for debugging.
 */
export interface PageConversionAttempt {
    /** Attempt number (1-based) */
    attempt: number;
    /** Pass that failed */
    pass: 'segmentation-matching' | 'population' | 'custom-block';
    /** Errors encountered */
    errors: string[];
    /** Raw output for debugging */
    rawOutput?: unknown;
}
/**
 * Successful conversion result.
 */
export interface PageConversionSuccess {
    success: true;
    output: PageConverterOutput;
    /** Number of sections processed */
    sectionCount: number;
    /** Number of built-in blocks used */
    builtinBlockCount: number;
    /** Number of custom blocks created */
    customBlockCount: number;
}
/**
 * Failed conversion result.
 */
export interface PageConversionFailure {
    success: false;
    error: string;
    attempts: PageConversionAttempt[];
}
/**
 * Result of page-to-blocks conversion.
 */
export type PageConversionResult = PageConversionSuccess | PageConversionFailure;
/**
 * Model tier overrides for page converter.
 * Allows overriding the default model for each tier.
 */
export interface ModelTierOverrides {
    /** Model for fast tier (segmentation, basic classification) */
    fast?: string;
    /** Model for balanced tier (block matching, content detection) */
    balanced?: string;
    /** Model for quality tier (layout generation, CSS styling) */
    quality?: string;
}
import type { DebugWriter } from '../manifest/debug';
import type { AiRuntime } from '../ai/runtime';
/**
 * Options for the page converter.
 */
export interface PageConverterOptions {
    /** AI runtime implementation (provider-specific; injected by caller) */
    ai: AiRuntime;
    /** Max retry attempts for validation failures */
    maxRetries?: number;
    /**
     * Override the AI model for ALL passes (bypasses tier system).
     * For per-tier control, use modelTiers instead.
     */
    model?: string;
    /**
     * Override models for specific tiers.
     * Example: { fast: 'gpt-5-nano', quality: 'gpt-5.2' }
     */
    modelTiers?: ModelTierOverrides;
    /** Temperature for LLM (default: 0.2) */
    temperature?: number;
    /** Callback for progress updates */
    onProgress?: (message: string) => void;
    /** Directory path for debug output files (creates file-based debug writer) */
    debugDir?: string;
    /**
     * Custom debug writer instance (e.g., in-memory writer for API use).
     * If provided, takes precedence over debugDir.
     */
    debugWriter?: DebugWriter;
    /** Page name for output */
    pageName?: string;
    /** Page path for output */
    pagePath?: string;
}
export {};
