import { RetryConfig } from '../../utils/resilience.js';

type ToolCallRef = {
    id: string;
    type: 'function';
    function: {
        name: string;
        arguments: string;
    };
};
type ChatMessage = {
    role: 'system';
    content: string;
} | {
    role: 'user';
    content: string;
} | {
    role: 'assistant';
    content: string | null;
    tool_calls?: ToolCallRef[];
} | {
    role: 'tool';
    tool_call_id: string;
    content: string;
};
type ToolName = 'list_directory' | 'grep_search' | 'glob' | 'read' | 'finish';
type ToolCall = {
    name: ToolName;
    arguments?: Record<string, unknown>;
};
type FinishFileSpec = {
    path: string;
    lines: '*' | Array<[number, number]>;
};
type ResolvedContext = {
    path: string;
    ranges: '*' | Array<[number, number]>;
    content: string;
};
type AgentFinish = {
    files: FinishFileSpec[];
};
type ResolvedFile = {
    path: string;
    content: string;
};
type WarpGrepTurnMetrics = {
    turn: number;
    morph_api_ms: number;
    local_tools_ms: number;
};
type WarpGrepExecutionMetrics = {
    total_ms: number;
    timeout_ms: number;
    initial_state_ms: number;
    turns: WarpGrepTurnMetrics[];
    finish_resolution_ms?: number;
};
type AgentRunResult = {
    terminationReason: 'completed' | 'terminated' | 'error';
    messages: ChatMessage[];
    finish?: {
        payload: string;
        metadata?: AgentFinish;
        resolved?: ResolvedContext[];
    };
    errors?: Array<{
        message: string;
    }>;
    timings?: WarpGrepExecutionMetrics;
};
type SessionConfig = {
    searchTerm: string;
    model?: string;
    repoRoot: string;
    excludes?: string[];
    includes?: string[];
    debug?: boolean;
    provider?: unknown;
    /** Morph API key (defaults to MORPH_API_KEY env var) */
    morphApiKey?: string;
    /** Morph API base URL */
    morphApiUrl?: string;
    /** Retry configuration */
    retryConfig?: RetryConfig;
    /** Timeout for model calls in ms (defaults to MORPH_WARP_GREP_TIMEOUT env var, then 30000) */
    timeout?: number;
    /** Search type hint. When 'node_modules', uses shallower initial tree and includes node_modules in search. */
    search_type?: string;
};
/**
 * A single step yielded during streaming execution.
 * Contains the turn number and tool calls made during that turn.
 */
type WarpGrepStep = {
    turn: number;
    toolCalls: Array<{
        name: string;
        arguments: Record<string, unknown>;
    }>;
};

export type { AgentFinish, AgentRunResult, ChatMessage, FinishFileSpec, ResolvedContext, ResolvedFile, SessionConfig, ToolCall, ToolCallRef, ToolName, WarpGrepExecutionMetrics, WarpGrepStep, WarpGrepTurnMetrics };
