import type { UseQueryOptions, UseMutationOptions } from "@tanstack/react-query"; /** @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. * * @internal exported for tests */ export declare function defaultActionQueryRetryDelay(failureCount: number): number; /** * 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 { } /** Resolves to the union of registered action names, or `string` if no registry exists. */ type ActionName = keyof ActionRegistry extends never ? string : (keyof ActionRegistry & string) | (string & {}); /** Resolves the return type of an action, or `any` if not in the registry. */ type ActionResult = T extends keyof ActionRegistry ? ActionRegistry[T] extends { result: infer R; } ? R : any : any; /** Resolves the parameter type of an action, or `Record` if not in the registry. */ 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; /** Abort signal for the underlying fetch. */ signal?: AbortSignal; /** Override the default 60s fetch timeout for long-running actions. */ timeoutMs?: number; } export declare function serializeActionQueryParams(params: Record): string; export interface ActionFetchOptions { /** * Abort signal from the caller (React Query passes one per queryFn * invocation so superseded requests — key change, unmount, refetch — cancel * the underlying network request instead of hogging a connection slot). */ signal?: AbortSignal; /** Per-call override for the fetch timeout. */ timeoutMs?: number; /** Keep the request alive while the document is being unloaded. */ keepalive?: boolean; /** Pre-serialized mutation body used by the keepalive budget coordinator. */ serializedBody?: string; /** Omit the tab echo-suppression tag for imperative callers. */ includeRequestSource?: boolean; } /** * Conservative per-document keepalive body budget. Browsers commonly enforce * an approximately 64 KiB aggregate limit across every in-flight keepalive * request; leaving headroom for other framework traffic prevents a request * that passed our guard from being rejected by the browser at send time. */ export declare const ACTION_KEEPALIVE_BODY_BUDGET_BYTES = 48000; /** * Imperatively call an action from browser/client code. * * Prefer `useActionQuery` / `useActionMutation` in React render flows. Use this * helper when a hook is not ergonomic; do not hand-write fetch calls to * `/_agent-native/actions/*` in components. */ export declare function callAction(actionName: TName, params?: ActionParams, options?: ClientActionCallOptions): Promise : TResult>; export type KeepaliveActionCallRejectionReason = "body-too-large" | "budget-exhausted"; export type KeepaliveActionCallResult = { accepted: true; bodyBytes: number; completion: Promise; } | { accepted: false; bodyBytes: number; reason: KeepaliveActionCallRejectionReason; completion: null; }; /** * Attempts an unload-safe action call without exceeding the browser's shared * keepalive request budget. The reservation remains held until the response * body has completed, because browsers count every in-flight keepalive body * against the same per-document quota. * * A rejected attempt is deliberately synchronous so callers can fall back to * a durable outbox before returning from `pagehide`. */ export declare function tryCallActionKeepalive(actionName: TName, params?: ActionParams, options?: Omit): KeepaliveActionCallResult : TResult>; /** * Query an action exposed as GET. * * When the action type registry is generated, the return type and parameter * types are inferred automatically from the action's `defineAction()` call. * * ```ts * // Type-safe — no manual generic needed * const { data } = useActionQuery("list-meals", { date: "2025-01-01" }); * * // Manual override still works when needed * const { data } = useActionQuery("list-meals"); * ``` */ export declare function useActionQuery(actionName: TName, params?: ActionParams, options?: Omit : TResult>, "queryKey" | "queryFn">): import("@tanstack/react-query").UseQueryResult : TResult>, Error>; /** * Mutate via an action exposed as POST (default), PUT, or DELETE. * * When the action type registry is generated, the return type and parameter * types are inferred automatically. * * ```ts * // Type-safe * const { mutate } = useActionMutation("log-meal"); * mutate({ name: "Salad", calories: 350 }); * ``` */ export declare function useActionMutation(actionName: TName, options?: Omit : TData, Error, TVariables extends undefined ? ActionParams : TVariables>, "mutationFn"> & { method?: "POST" | "PUT" | "DELETE"; skipActionQueryInvalidation?: boolean; }): import("@tanstack/react-query").UseMutationResult : TData, Error, TVariables extends undefined ? ActionParams : TVariables, unknown>; export {}; //# sourceMappingURL=use-action.d.ts.map