/**
 * Thread Protocol — Codex app-server style three-layer abstraction.
 *
 * Thread → Turn → Item
 *
 *  Thread: persistent conversation container (maps to a session)
 *  Turn: one user request → agent response cycle
 *  Item: individual components within a turn (message, tool_call, tool_result, etc.)
 *
 * This module defines the wire types. The existing `agent.turn` RPC continues
 * to work; these types provide the foundation for `thread/*` methods.
 */
export type ItemType = "message" | "tool_call" | "tool_result" | "tool_blocked" | "recovery" | "plan_update" | "skill_instruction";
export type ItemRole = "user" | "assistant" | "system";
/** A single atomic event within a turn. */
export interface ThreadItem {
    /** Unique item ID. */
    id: string;
    /** Item type (discriminator). */
    type: ItemType;
    /** Role of the actor. */
    role: ItemRole;
    /** Text content (for message items). */
    text?: string;
    /** Tool name (for tool_call / tool_result items). */
    toolName?: string;
    /** Tool call ID (LLM-assigned). */
    toolCallId?: string;
    /** Serialized arguments (for tool_call). */
    arguments?: string;
    /** Tool output (for tool_result). */
    output?: string;
    /** Whether the tool was approved. */
    approved?: boolean;
    /** Recovery strategy used (for recovery items). */
    strategy?: string;
    /** Timestamp (ISO 8601). */
    createdAt: string;
}
export type TurnStatus = "pending" | "in_progress" | "completed" | "failed" | "aborted";
/** Represents one user request → agent response cycle. */
export interface ThreadTurn {
    /** Unique turn ID. */
    id: string;
    /** Thread this turn belongs to. */
    threadId: string;
    /** Turn status. */
    status: TurnStatus;
    /** Items produced during this turn. */
    items: ThreadItem[];
    /** Model used for this turn. */
    model?: string;
    /** Token usage. */
    usage?: {
        promptTokens: number;
        completionTokens: number;
        totalTokens: number;
    };
    /** Cost in USD. */
    costUSD?: number;
    /** Turn creation time. */
    createdAt: string;
    /** Turn completion time. */
    completedAt?: string;
}
export type ThreadStatus = "active" | "archived" | "deleted";
/** Persistent conversation container. */
export interface Thread {
    /** Unique thread ID (maps to session ID). */
    id: string;
    /** Display title (auto-generated or user-set). */
    title?: string;
    /** Thread status. */
    status: ThreadStatus;
    /** All turns in this thread. */
    turns: ThreadTurn[];
    /** Working directory. */
    cwd?: string;
    /** Thread creation time. */
    createdAt: string;
    /** Last activity time. */
    lastActiveAt: string;
}
/**
 * `initialize` request params — superset of agent.hello.
 * Sent by host as the first message after transport connects.
 */
export interface InitializeParams {
    /** Protocol version. */
    protocolVersion: string;
    /** Host application info. */
    host: {
        name: string;
        version: string;
    };
    /** Host capabilities. */
    capabilities?: {
        /** Host can receive streaming deltas. */
        streaming?: boolean;
        /** Host supports tool approval flow. */
        toolApproval?: boolean;
        /** Host supports thread persistence. */
        threads?: boolean;
    };
    /** Optional initial configuration. */
    config?: Record<string, unknown>;
}
/** `initialize` response result. */
export interface InitializeResult {
    /** Agent protocol version. */
    protocolVersion: string;
    /** Agent info. */
    agent: {
        name: string;
        version: string;
    };
    /** Agent capabilities. */
    capabilities: {
        tools: string[];
        streaming: boolean;
        threads: boolean;
    };
}
/** `thread/create` params. */
export interface ThreadCreateParams {
    /** Optional thread ID (auto-generated if not provided). */
    id?: string;
    /** Optional title. */
    title?: string;
    /** Working directory. */
    cwd?: string;
    /** LLM configuration. */
    config?: Record<string, unknown>;
}
/** `thread/list` result. */
export interface ThreadListResult {
    threads: Array<{
        id: string;
        title?: string;
        status: ThreadStatus;
        turnCount: number;
        createdAt: string;
        lastActiveAt: string;
    }>;
}
