/**
 * ThreadService — CRUD + lifecycle management for agent threads.
 *
 * Agent threads are parallel running agent sessions, each powered by a
 * CliProviderAdapter (jait, codex, or claude-code). Threads persist their
 * status, configuration, and activity log in SQLite via Drizzle.
 */
import type { JaitDB } from "../db/connection.js";
import { agentThreads } from "../db/schema.js";
import type { ProviderId, RuntimeMode, ProviderEvent } from "../providers/contracts.js";
export type ThreadStatus = "idle" | "running" | "completed" | "error" | "interrupted";
export interface CreateThreadParams {
    userId?: string;
    sessionId?: string;
    title: string;
    providerId: ProviderId;
    model?: string;
    runtimeMode?: RuntimeMode;
    kind?: "delivery" | "delegation";
    skillIds?: string[] | null;
    workingDirectory?: string;
    branch?: string;
}
export interface UpdateThreadParams {
    title?: string;
    providerId?: ProviderId;
    model?: string;
    runtimeMode?: RuntimeMode;
    kind?: "delivery" | "delegation";
    skillIds?: string[] | null;
    workingDirectory?: string | null;
    branch?: string | null;
    prUrl?: string | null;
    prNumber?: number | null;
    prTitle?: string | null;
    prBaseBranch?: string | null;
    prState?: "creating" | "open" | "closed" | "merged" | null;
    status?: ThreadStatus;
    providerSessionId?: string | null;
    error?: string | null;
    completedAt?: string | null;
    executionNodeId?: string | null;
    executionNodeName?: string | null;
}
export interface ThreadActivity {
    id: string;
    threadId: string;
    kind: string;
    summary: string;
    payload?: unknown;
    createdAt: string;
}
type ThreadRowRecord = typeof agentThreads.$inferSelect;
export type ThreadRow = Omit<ThreadRowRecord, "skillIds"> & {
    skillIds: string[] | null;
};
export declare class ThreadService {
    private db;
    constructor(db: JaitDB);
    create(params: CreateThreadParams): ThreadRow;
    getById(id: string): ThreadRow | undefined;
    list(userId?: string, limit?: number): ThreadRow[];
    listBySession(sessionId: string, limit?: number): ThreadRow[];
    listRunning(): ThreadRow[];
    update(id: string, params: UpdateThreadParams): ThreadRow | undefined;
    delete(id: string): void;
    markRunning(id: string, providerSessionId: string): ThreadRow | undefined;
    markCompleted(id: string): ThreadRow | undefined;
    markCompletedAndClearSession(id: string): ThreadRow | undefined;
    /** Clear the provider session — called when a PR is merged or the thread is manually closed. */
    clearSession(id: string): ThreadRow | undefined;
    markError(id: string, error: string): ThreadRow | undefined;
    markInterrupted(id: string): ThreadRow | undefined;
    addActivity(threadId: string, kind: string, summary: string, payload?: unknown): ThreadActivity;
    getActivities(threadId: string, limit?: number, after?: string): ThreadActivity[];
    logProviderEvent(threadId: string, event: ProviderEvent): ThreadActivity | undefined;
}
export {};
//# sourceMappingURL=threads.d.ts.map