/** * Pure, testable HTTP client for the atrium /api/v1 surface. * * This module never imports anything from the Convex app — it only speaks HTTP. * It reads two env vars: * - OPENCLAW_WEBCHAT_API_BASE : the deployment `.site` origin, WITHOUT the * `/api/v1` suffix (e.g. http://127.0.0.1:3213). The `/api/v1` prefix is * added here so tool/CLI call-sites stay clean (`apiFetch(cfg, "/traces")`). * - OPENCLAW_WEBCHAT_API_KEY : the `oc_live_...` Bearer key. * * The API key is only ever placed in the `Authorization` header — never in a * URL/query string and never logged. */ /** Default base origin for a local Convex deployment (.site origin). */ export declare const DEFAULT_API_BASE = "http://127.0.0.1:3213"; /** Path prefix for the observability API. Kept here so call-sites omit it. */ export declare const API_PREFIX = "/api/v1"; export interface Config { /** Base origin (no trailing slash, no /api/v1). */ base: string; /** The oc_live_ Bearer key. */ apiKey: string; } /** Minimal env shape so the resolver is injectable/testable. */ export type Env = Record; /** * Structured error for any non-2xx response (or a fetch/transport failure). * Carries the HTTP `status` and the parsed/raw `body` so callers can surface a * clear message without re-reading the response. Never contains the API key. */ export declare class ApiError extends Error { readonly status: number; readonly body: unknown; constructor(status: number, body: unknown, message?: string); } /** * Resolve config from an env bag (defaults to `process.env`). Throws a clear * error naming the missing variable — without ever printing its value. */ export declare function resolveConfig(env?: Env): Config; /** Build the absolute URL for an API path (prepending `${base}/api/v1`). */ export declare function buildUrl(base: string, path: string): string; /** Options for {@link apiFetch}. */ export interface ApiFetchOptions { /** Injected fetch implementation. Defaults to the global `fetch`. */ fetchImpl?: typeof fetch; } /** * Call the API at `path` (relative to `${base}/api/v1`), attaching the Bearer * header, and parse the JSON response. * * - 2xx -> returns the parsed JSON (or `null` for an empty body). * - non-2xx -> throws {@link ApiError} with `{status, body}` (body parsed as * JSON when possible, otherwise the raw text). * - transport failure -> throws {@link ApiError} with status 0. * * `fetch` is injectable for unit testing; no network call happens in tests. */ export declare function apiFetch(config: Config, path: string, init?: RequestInit, options?: ApiFetchOptions): Promise;