import type { AgentMessage } from "@earendil-works/pi-agent-core";
import type { ImageContent, TextContent } from "@earendil-works/pi-ai/compat";
import type { SessionManager } from "./session-manager-core.ts";
export declare const CURRENT_SESSION_VERSION = 3;
/**
 * Workflow linkage persisted on internal (workflow-created) session headers.
 * Used to exclude workflow stage sessions from the standard `/resume` history
 * while keeping them resumable through the workflow-specific resume path.
 */
export interface SessionWorkflowMetadata {
    runId: string;
    stageId: string;
    stageName: string;
}
export interface SessionHeader {
    type: "session";
    version?: number;
    id: string;
    timestamp: string;
    cwd: string;
    parentSession?: string;
    /** Marks sessions created by automated machinery (e.g. workflow stages) so they can be excluded from standard resume history. */
    internal?: boolean;
    /** When internal, links the session to its owning workflow run/stage. */
    workflow?: SessionWorkflowMetadata;
}
export interface NewSessionOptions {
    id?: string;
    parentSession?: string;
    /** Mark the new session as internal (e.g. a workflow stage session). */
    internal?: boolean;
    /** Workflow run/stage linkage for internal workflow sessions. */
    workflow?: SessionWorkflowMetadata;
}
export interface SessionEntryBase {
    type: string;
    id: string;
    parentId: string | null;
    timestamp: string;
}
export interface SessionMessageEntry extends SessionEntryBase {
    type: "message";
    message: AgentMessage;
}
export interface ThinkingLevelChangeEntry extends SessionEntryBase {
    type: "thinking_level_change";
    thinkingLevel: string;
}
export interface ContextWindowChangeEntry extends SessionEntryBase {
    type: "context_window_change";
    contextWindow: number;
}
export interface ModelChangeEntry extends SessionEntryBase {
    type: "model_change";
    provider: string;
    modelId: string;
}
export interface CompactionEntry<T = unknown> extends SessionEntryBase {
    type: "compaction";
    summary: string;
    firstKeptEntryId: string;
    tokensBefore: number;
    /** Extension-specific data (e.g., ArtifactIndex, version markers for structured compaction) */
    details?: T;
    /** True if generated by an extension, undefined/false if pi-generated (backward compatible) */
    fromHook?: boolean;
}
export type ContextDeletionTarget = {
    kind: "entry";
    entryId: string;
} | {
    kind: "content_block";
    entryId: string;
    blockIndex: number;
};
export interface ContextCompactionStats {
    objectsBefore: number;
    objectsAfter: number;
    objectsDeleted: number;
    tokensBefore: number;
    tokensAfter: number;
    percentReduction: number;
}
export interface ContextCompactionEntry extends SessionEntryBase {
    type: "context_compaction";
    promptVersion: 1;
    deletedTargets: ContextDeletionTarget[];
    protectedEntryIds: string[];
    stats: ContextCompactionStats;
    backupPath?: string;
}
export interface BranchSummaryEntry<T = unknown> extends SessionEntryBase {
    type: "branch_summary";
    fromId: string;
    summary: string;
    /** Extension-specific data (not sent to LLM) */
    details?: T;
    /** True if generated by an extension, false if pi-generated */
    fromHook?: boolean;
}
/**
 * Custom entry for extensions to store extension-specific data in the session.
 * Use customType to identify your extension's entries.
 *
 * Purpose: Persist extension state across session reloads. On reload, extensions can
 * scan entries for their customType and reconstruct internal state.
 *
 * Does NOT participate in LLM context (ignored by buildSessionContext).
 * For injecting content into context, see CustomMessageEntry.
 */
export interface CustomEntry<T = unknown> extends SessionEntryBase {
    type: "custom";
    customType: string;
    data?: T;
}
/** Label entry for user-defined bookmarks/markers on entries. */
export interface LabelEntry extends SessionEntryBase {
    type: "label";
    targetId: string;
    label: string | undefined;
}
/** Session metadata entry (e.g., user-defined display name). */
export interface SessionInfoEntry extends SessionEntryBase {
    type: "session_info";
    name?: string;
}
/**
 * Custom message entry for extensions to inject messages into LLM context.
 * Use customType to identify your extension's entries.
 *
 * Unlike CustomEntry, this usually participates in LLM context.
 * The content is converted to a user message in buildSessionContext() unless
 * excludeFromContext is true. Use details for extension-specific metadata (not sent to LLM).
 *
 * display controls TUI rendering:
 * - false: hidden entirely
 * - true: rendered with distinct styling (different from user messages)
 */
export interface CustomMessageEntry<T = unknown> extends SessionEntryBase {
    type: "custom_message";
    customType: string;
    content: string | (TextContent | ImageContent)[];
    details?: T;
    display: boolean;
    excludeFromContext?: boolean;
}
/** Session entry - has id/parentId for tree structure (returned by "read" methods in SessionManager) */
export type SessionEntry = SessionMessageEntry | ThinkingLevelChangeEntry | ContextWindowChangeEntry | ModelChangeEntry | CompactionEntry | ContextCompactionEntry | BranchSummaryEntry | CustomEntry | CustomMessageEntry | LabelEntry | SessionInfoEntry;
/** Raw file entry (includes header) */
export type FileEntry = SessionHeader | SessionEntry;
/** Tree node for getTree() - defensive copy of session structure */
export interface SessionTreeNode {
    entry: SessionEntry;
    children: SessionTreeNode[];
    /** Resolved label for this entry, if any */
    label?: string;
    /** Timestamp of the latest label change for this entry, if any */
    labelTimestamp?: string;
}
export interface SessionContext {
    messages: AgentMessage[];
    thinkingLevel: string;
    contextWindow: number | undefined;
    model: {
        provider: string;
        modelId: string;
    } | null;
}
export interface SessionInfo {
    path: string;
    id: string;
    /** Working directory where the session was started. Empty string for old sessions. */
    cwd: string;
    /** User-defined display name from session_info entries. */
    name?: string;
    /** Path to the parent session (if this session was forked). */
    parentSessionPath?: string;
    /** True when this session was created by automated machinery (e.g. a workflow stage). */
    internal?: boolean;
    /** Workflow run/stage linkage when the session is an internal workflow session. */
    workflow?: SessionWorkflowMetadata;
    created: Date;
    modified: Date;
    messageCount: number;
    firstMessage: string;
    allMessagesText: string;
}
export interface ContextDeletionFilters {
    deletedEntryIds: Set<string>;
    deletedContentBlocks: Map<string, Set<number>>;
}
export type SessionListProgress = (loaded: number, total: number) => void;
export type ReadonlySessionManager = Pick<SessionManager, "getCwd" | "getSessionDir" | "usesDefaultSessionDir" | "getSessionId" | "getSessionFile" | "getLeafId" | "getLeafEntry" | "getEntry" | "getLabel" | "getBranch" | "getHeader" | "getEntries" | "getTree" | "getSessionName">;
//# sourceMappingURL=session-manager-types.d.ts.map