import type { Query, QueryClient, UseQueryOptions, UseMutationOptions } from "@tanstack/react-query"; import { actionErrorCode } from "./action-failure-circuit.js"; export { actionErrorCode }; /** @internal exported for tests */ export declare function defaultActionQueryRetry(failureCount: number, error: unknown): boolean; /** @internal alias kept for existing specs. */ export declare const shouldRetryActionQueryForError: typeof defaultActionQueryRetry; /** * Default retry backoff for action queries. React Query's stock retryDelay * (1s → 2s → 4s) makes a failing query sit on a spinner for ~7s before the * error surfaces; interactive data fetches want failures visible fast. The * delay is jittered into the upper half of the step so clients that failed * together do not retry together. * * React Query passes the error as a second argument, so this takes no * randomness parameter. * * @internal exported for tests */ export declare function defaultActionQueryRetryDelay(failureCount: number): number; export declare function actionErrorMessage(error: unknown): string | undefined; /** * Action type registry. This interface is empty by default and gets augmented * by the auto-generated `.generated/action-types.d.ts` file. When augmented, * it maps action names to their parameter and return types, enabling * end-to-end type safety for `useActionQuery` and `useActionMutation`. */ declare global { interface AgentNativeActionRegistry { } } export interface ActionRegistry extends AgentNativeActionRegistry { } type ActionName = keyof ActionRegistry extends never ? string : (keyof ActionRegistry & string) | (string & {}); type ActionResult = T extends keyof ActionRegistry ? ActionRegistry[T] extends { result: infer R; } ? R : any : any; type ActionParams = T extends keyof ActionRegistry ? ActionRegistry[T] extends { params: infer P; } ? P : Record : Record; export type ClientActionMethod = "GET" | "POST" | "PUT" | "DELETE"; export interface ClientActionCallOptions { method?: ClientActionMethod; signal?: AbortSignal; timeoutMs?: number; headers?: Record; /** Set when the action is declared `uiOnly`, so its first request carries the UI capability. */ uiOnly?: boolean; /** Sees each HTTP response, e.g. to pass to `recordActionQueryBrowserPersist`. */ onResponse?: (response: Response) => void; } export declare function serializeActionQueryParams(params: Record): string; export interface ActionFetchOptions { signal?: AbortSignal; timeoutMs?: number; keepalive?: boolean; serializedBody?: string; responseType?: "blob"; includeRequestSource?: boolean; headers?: Record; uiOnly?: boolean; } /** Drop the remembered capability so the next call that needs one mints it. */ export declare function forgetUiActionCapability(): void; export declare const ACTION_KEEPALIVE_BODY_BUDGET_BYTES = 48000; /** * `undefined` when there is no document to ask (SSR, a non-browser caller) — * "unknown" must stay absent rather than default to a guessed `false`. * * `hiddenEpochAtStart`/`hiddenEpochNow` only catch a transition INTO hidden * that happens during the call. A call that starts already hidden (a * background tab load, a cmd-click, a hidden desktop webview) sees no such * transition even if the tab surfaces again before the call completes, so * `hiddenAtStart` is checked directly instead of being inferred from a * transition that never fires. * * @internal exported for tests */ export declare function computePageHidden(hiddenAtStart: boolean, hiddenEpochAtStart: number, hiddenEpochNow: number, visibilityState: DocumentVisibilityState | undefined): boolean | undefined; export declare function callAction(actionName: TName, params?: ActionParams, options?: ClientActionCallOptions): Promise : TResult>; export declare function callActionBlob(actionName: TName, params?: ActionParams, options?: ClientActionCallOptions): Promise; export type RetriedActionCallOptions = Omit & { method?: "GET"; }; export declare function callActionWithRetry(actionName: TName, params?: ActionParams, options?: RetriedActionCallOptions): Promise : TResult>; export type KeepaliveActionCallRejectionReason = "body-too-large" | "budget-exhausted" | "api-disabled"; export type KeepaliveActionCallResult = { accepted: true; bodyBytes: number; completion: Promise; } | { accepted: false; bodyBytes: number; reason: KeepaliveActionCallRejectionReason; completion: null; }; export declare function tryCallActionKeepalive(actionName: TName, params?: ActionParams, options?: Omit & { method?: "POST" | "PUT"; }): KeepaliveActionCallResult : TResult>; /** * Wraps a caller-supplied `refetchInterval` so polling stops once the query's * last error says it is over (401/403/410, or a non-retryable typed code such * as `not_found`) instead of reissuing the identical rejection on every tick, * and stretches the interval to the circuit's remaining cooldown after * repeated refusals or a named Retry-After. A plain 404 keeps polling (see * `endsActionPolling`). A remount, a mutation's invalidation, or an explicit * `refetch()` still retries: this only gates the interval timer, not the * query's error state. * * @internal exported for tests */ export declare function guardActionQueryRefetchInterval(refetchInterval: NonNullable["refetchInterval"]>): NonNullable["refetchInterval"]>; /** @internal exported for tests */ export declare function resolveActionQueryRetry(retry: unknown, failureCount: number, error: unknown): boolean; /** @internal exported for tests */ export declare function resetActionCircuitTripEventsForTests(): void; export declare function registerActionQueryCacheRevoker(client: QueryClient, revoke: () => void, bindingToken?: object): void; /** @internal set only by the scoped action-query cache binder. */ export declare function setActionQueryCacheBindingToken(token: object | undefined): void; export declare function setAccessDeniedActionQueryBinding(query: Query, token: object | undefined): void; export declare function getAccessDeniedActionQueryBinding(query: Query): object | undefined; export declare function clearAccessDeniedActionQueryBinding(query: Query): void; /** @internal read by the persisted query cache. */ export declare function isBrowserPersistableActionQuery(query: Query): boolean; /** @internal a response is persistable only in the binding active at fetch start. */ export declare function isBrowserPersistableActionQueryForBinding(query: Query, token: object): boolean; /** @internal used only after a persisted action result is accepted and hydrated. */ export declare function markRestoredBrowserPersistableActionQuery(query: Query, token?: object): void; export declare function revokeBrowserPersistableActionQuery(query: Query): void; /** The persisted-cache binding to capture when a fetch starts, for `recordActionQueryBrowserPersist`. */ export declare function currentActionQueryCacheBinding(): object | undefined; /** * Lets an `["action", ...]` query filled by a hand-written `queryFn` or * `setQueryData` join the browser's persisted query cache the way a * `useActionQuery` result does: only when its response carried the persist * header, and only into the binding that was active when the fetch began, so a * result fetched for one user is never written into another user's record. */ export declare function recordActionQueryBrowserPersist(query: Query, response: Response | undefined, bindingTokenAtFetch: object | undefined): void; export declare function useActionQuery(actionName: TName, params?: ActionParams, options?: Omit : TResult>, "queryKey" | "queryFn"> & { queryKeyScope?: readonly unknown[]; /** * The resource types this query reads (matching a write's `resources` and a * sync event's `resourceType`). Omit it and every resource-scoped change * still refetches the query. */ resources?: readonly string[]; /** * Set false when the UI holds a placeholder until a fresh read lands * instead of showing cached data. While any component reading the query * sets it, the query's refetches go alone, like a first fetch, rather * than waiting on the other reads in their batch. */ batchRefetches?: boolean; }): import("@tanstack/react-query").UseQueryResult : TResult>, Error>; export declare function useActionMutation(actionName: TName, options?: Omit : TData, Error, TVariables extends undefined ? ActionParams : TVariables>, "mutationFn"> & { method?: "POST" | "PUT" | "DELETE"; skipActionQueryInvalidation?: boolean; /** The resource types this write changes; see `useActionQuery`. */ resources?: readonly string[]; timeoutMs?: number; /** Set when the action is declared `uiOnly`, so its first request carries the UI capability. */ uiOnly?: boolean; headers?: Record | ((variables: TVariables extends undefined ? ActionParams : TVariables) => Record | undefined); }): import("@tanstack/react-query").UseMutationResult : TData, Error, TVariables extends undefined ? ActionParams : TVariables, unknown>;