/**
 * Format a duration in milliseconds to a human-readable string.
 * Shows seconds (with 1 decimal) if >= 1000ms, otherwise shows ms.
 *
 * @example
 * formatDuration(450) // "450ms"
 * formatDuration(1234) // "1.2s"
 * formatDuration(5678) // "5.7s"
 */
export function formatDuration(ms) {
    if (!ms)
        return '';
    if (ms >= 1000) {
        return `${(ms / 1000).toFixed(1)}s`;
    }
    return `${ms}ms`;
}
/**
 * Check if a tool result is an error response.
 * Handles both the new ok: false pattern and legacy error patterns.
 */
export function isToolError(result) {
    if (!result || typeof result !== 'object')
        return false;
    const obj = result;
    return obj.ok === false || 'error' in obj || obj.success === false;
}
/**
 * Extract the error message from a tool result.
 * Checks multiple common fields: error, stderr, message, detail, details, reason.
 */
export function getErrorMessage(result) {
    if (!result || typeof result !== 'object')
        return null;
    const obj = result;
    const keys = ['error', 'stderr', 'message', 'detail', 'details', 'reason'];
    for (const key of keys) {
        const value = obj[key];
        if (typeof value === 'string') {
            const trimmed = value.trim();
            if (trimmed.length)
                return trimmed;
        }
    }
    return null;
}
/**
 * Extract error details from a tool result.
 * Returns the details object if present and valid.
 */
export function getErrorDetails(result) {
    if (!result || typeof result !== 'object')
        return null;
    const obj = result;
    if (obj.details && typeof obj.details === 'object') {
        return obj.details;
    }
    return null;
}
//# sourceMappingURL=utils.js.map