import { LightSpanRecord, ListBranchesArgs, ListBranchesResponse, ListTracesArgs, ListTracesResponse } from '@mastra/core/storage';
import { InfiniteData } from '@tanstack/react-query';
import { TraceListMode } from '../trace-filters';
/** Tunables for live-tail polling. All fields optional — defaults below.
 *  Platform consumers override individual fields to throttle traffic or
 *  reshape the freshness/visibility trade-offs. */
export interface TracesPollingConfig {
    /** Interval between delta polls. Default 5_000ms. */
    deltaPollIntervalMs?: number;
    /** Refetch delay when the server signals `delta.hasMore` (chase remaining updates immediately). Default 100ms. */
    deltaChaseIntervalMs?: number;
    /** Max rows per delta poll. Server caps at 100. Default 100. */
    deltaLimit?: number;
    /** Page-mode refetch interval used when the configured store does not support delta polling. Default 10_000ms. */
    pageModeRefetchIntervalMs?: number;
    /** Periodic page-0 refetch interval while delta is active. Delta only delivers new rows, so this
     *  is how we surface status flips (running → success/error) on rows already visible. Default 60_000ms. */
    page0StatusRefreshIntervalMs?: number;
    /** When the tab returns from being hidden and the last successful poll was older than this, the
     *  cursor is treated as stale (ClickHouse delta tables TTL after 2 days; other stores may be more
     *  aggressive). The infinite query is reset so page 0 refetches and delta resumes from a fresh
     *  cursor. Default 900_000ms (15 min). */
    idleGuardThresholdMs?: number;
    /** Minimum visible duration for `isRefetching` after any query completes. On localhost a delta
     *  poll can resolve in tens of ms — too brief for the spinner's 1s rotation to register visually,
     *  and quick enough that React may batch the start/finish transitions. Pulsing for this duration
     *  on completion (~144° of rotation at 400ms) makes each poll perceptible as a heartbeat.
     *  Default 400ms. */
    minRefetchSpinMs?: number;
    /** Window during which a delta-arrived row's key stays in `recentlyAddedKeys` so the list view
     *  can apply its `animate-row-highlight` class. Should match the CSS animation duration
     *  (currently 1_000ms — see `index.css`). Default 1_000ms. */
    deltaHighlightMs?: number;
}
/** Returns true when the cursor should be considered stale and re-seeded.
 *  Exported for testing — pure function of timestamps. */
export declare function shouldResetAfterIdle(lastSuccessAt: number, now: number, thresholdMs: number): boolean;
export declare const TRACES_PER_PAGE = 25;
export interface TracesFilters {
    filters?: ListTracesArgs['filters'] | ListBranchesArgs['filters'];
    listMode?: TraceListMode;
}
/** Returns the next page number if the server indicates more pages are available. */
export declare function getTracesNextPageParam(lastPage: ListTracesResponse | ListBranchesResponse | undefined, _allPages: unknown, lastPageParam: number): number | undefined;
type TracesPageResponse = ListTracesResponse | ListBranchesResponse;
/** Deduplicates trace/branch rows by traceId + spanId across all loaded pages.
 *  Also surfaces page 0's deltaCursor so the live-tail query can read it reactively. */
export declare function selectUniqueTraces(data: {
    pages: TracesPageResponse[];
}): {
    spans: LightSpanRecord[];
    deltaCursor: string | undefined;
};
/** Replaces existing page-0 rows in place (keyed by traceId:spanId) with
 *  refreshed copies from the server. Rows the server doesn't return are kept
 *  as-is so delta-accumulated rows that have aged off the server's page 0
 *  aren't dropped from the UI. New rows aren't added here — delta polling
 *  delivers those. */
export declare function refreshPage0Rows(old: InfiniteData<TracesPageResponse> | undefined, refreshed: ListTracesResponse | ListBranchesResponse, listMode: TraceListMode): InfiniteData<TracesPageResponse> | undefined;
/** Prepends delta-mode rows into page 0 and advances its deltaCursor.
 *  Delta responses come back in server cursor order (insertion order into
 *  the per-store delta index), not the `startedAt DESC` order page-mode
 *  uses — so we re-sort the merged page 0 to match what the user sees on
 *  a fresh page-mode load. Cross-page duplication is handled later by
 *  selectUniqueTraces. */
export declare function mergeDeltaIntoPage0(old: InfiniteData<TracesPageResponse> | undefined, delta: ListTracesResponse | ListBranchesResponse, listMode: TraceListMode): InfiniteData<TracesPageResponse> | undefined;
export interface UseTracesArgs extends TracesFilters {
    /** Optional overrides for the live-tail polling tunables. Any omitted fields fall back to the
     *  built-in defaults; pass only what you want to change. */
    polling?: TracesPollingConfig;
}
interface UseTracesReturn {
    data: {
        spans: LightSpanRecord[];
        deltaCursor: string | undefined;
    } | undefined;
    hasNextPage: boolean;
    isFetchingNextPage: boolean;
    fetchNextPage: () => void;
    isLoading: boolean;
    isError: boolean;
    error: Error | null;
    setEndOfListElement: (node: HTMLDivElement | null) => void;
    isRefetching: boolean;
    autoRefetch: boolean;
    setAutoRefetch: (v: boolean) => void;
    recentlyAddedKeys: Set<string>;
    dataUpdatedAt: number;
    errorUpdatedAt: number;
    isFetching: boolean;
    isSuccess: boolean;
    fetchStatus: 'idle' | 'fetching' | 'paused';
    refetch: () => void;
}
export declare const useTraces: (args: UseTracesArgs) => UseTracesReturn;
export {};
