/** * Log10x API client — **USER-ACTION SURFACE** (api_key / `X-10X-Auth`). * * Every request out of this file authenticates with the user's api_key * (composed as `/` for env-scoped calls, or `` * for user-scoped ones). This is the user-action half of the gateway's * two-surface auth model — **don't reach for the license JWT or an * Auth0 Bearer token here**; the `tenx_api_authorizer` will reject them. * * For engine credentials (license JWT) see `./license-api.ts`. For the * Auth0-token → api_key mint that bootstraps this surface see * `./auth-api.ts`. Canonical model: [./auth-model.ts](./auth-model.ts). * * Handles Prometheus queries, user settings, env CRUD, billing, and AI * analysis via the Log10x REST API. * * All HTTP reads route through `fetchWithRetry` — 3 attempts with * exponential backoff + jitter. Retries fire on network errors and * 5xx / 429 responses; 4xx errors are surfaced immediately because they * indicate misconfiguration rather than transient failure. */ import type { EnvConfig } from './environments.js'; import './auth-model.js'; /** * Wrap fetch with retry-on-transient-failure. * * Retries when: * - the underlying fetch throws (network reset, DNS, connection refused) * - the response is 5xx * - the response is 429 (rate limited) * * Surfaces immediately on 4xx (other than 429) — these are caller errors * (auth, malformed query) and retrying won't help. */ export declare function fetchWithRetry(url: string, init: RequestInit, label: string): Promise; /** * Raw Prometheus instant query. * * Phase 4: delegates to the env's `MetricsBackend` adapter. For * `kind: 'log10x'` this hits `prometheus.log10x.com` with X-10X-Auth * (unchanged behavior); for other kinds it hits the customer's own * Prom-compatible store with the appropriate auth. */ export declare function queryInstant(env: EnvConfig, promql: string, timeoutMs?: number): Promise; /** Prometheus range query. Delegates to the env's MetricsBackend. */ export declare function queryRange(env: EnvConfig, promql: string, start: number, end: number, step: number, timeoutMs?: number): Promise; /** AI analysis query. Returns the AI text response. */ export declare function queryAi(env: EnvConfig, queryResult: string, prompt: string, ingestionCost: number): Promise; /** * Prometheus /api/v1/labels — list all label names in the workspace. * Delegates to the env's MetricsBackend (phase 4). */ export declare function fetchLabels(env: EnvConfig): Promise; /** * Prometheus /api/v1/label/{name}/values — list distinct values for a label. * * Without `opts.windowSeconds`, returns all values ever seen (bounded by * Prometheus retention). That means stale series whose last sample was * minutes-to-hours ago still contribute values. * * **Important**: Prometheus's `start`/`end` params on this endpoint filter * by BLOCK intersection, not by active sample presence. The current 2h * block still contains old label values from services that stopped * emitting, so `windowSeconds` here does NOT produce a truly-live set. * * For a truly-live set (label values with samples in the last N seconds), * use `fetchActiveLabelValues()` below — it runs a PromQL `group by` over * an `increase()` window, which is the correct "currently active" * semantic. */ export declare function fetchLabelValues(env: EnvConfig, labelName: string, opts?: { windowSeconds?: number; }): Promise; /** * Returns the distinct label values that have had at least one sample in * the last `windowSeconds` seconds — i.e., currently active, not stale. * * Implementation: `group by (