import type { TokenUsage } from './types.ts';
/** Constructor signature for backend-specific error classes. */
export type BackendErrorCtor = new (message: string) => Error;
/**
 * Combine a caller-supplied AbortSignal with a per-call timeout via
 * `AbortSignal.any`. Returns the caller signal directly when no timeout is
 * configured; the timeout signal alone when no caller signal exists; a
 * composed signal when both apply.
 */
export declare function composeSignal(caller?: AbortSignal, timeoutMs?: number): AbortSignal | undefined;
/**
 * Write a token count to `usage` only when the value is a finite, non-negative
 * integer. Drops `NaN`, `Infinity`, negatives, and non-integers silently —
 * upstream-supplied bad counts would otherwise poison aggregates over
 * `hdb_model_calls` (`SUM(prompt_tokens)` returns `NaN` for the whole window
 * if any row carries `NaN`).
 */
export declare function assignFiniteTokenCount(usage: TokenUsage, key: 'promptTokens' | 'completionTokens' | 'embeddingTokens', value: unknown): void;
/**
 * Read a JSON response body and throw the backend's error class on parse
 * failure rather than leaking the raw `SyntaxError` (whose message can
 * include upstream-derived bytes). Matches the sanitization posture from
 * `analyticsTable.ts:35` ("Sanitized code (...). Never a raw upstream
 * message.").
 */
export declare function parseJsonResponse<T>(res: Response, endpoint: string, Err: BackendErrorCtor): Promise<T>;
/**
 * Assert that a model name was specified — either via `opts.model` (per-call
 * override) or the backend's configured default.
 */
export declare function requireModel(model: string | undefined, op: string, Err: BackendErrorCtor): asserts model is string;
/**
 * Validate a configured credential field (typically `apiKey`):
 * - must be present and non-empty
 * - must NOT be a literal `${VAR_NAME}` placeholder that survived because the
 *   env var was unset at boot (the `bootstrap.ts` expansion runs through
 *   `expandEnvVarsDeep`, but unresolved placeholders pass through unchanged)
 *
 * Returns the validated value or throws. The `backendLabel` prefixes the
 * error message so operators see which backend's config failed.
 */
export declare function requireCredential(value: string | undefined, backendLabel: string, fieldName: string, Err: BackendErrorCtor): string;
/**
 * Normalize a config-supplied host/origin into a fully-qualified base URL.
 *
 * - Falls back to `defaults.host` when value is empty
 * - Prepends `http://` or `https://` (per `defaults.secure`) when no scheme present
 * - Strips trailing slashes so callers can `${origin}${path}` cleanly
 *
 * Backend-specific behavior collapses to choosing the right `defaults`:
 * Ollama → `{ host: 'localhost:11434', secure: false }`; OpenAI →
 * `{ host: 'api.openai.com/v1', secure: true }`; etc.
 */
export declare function normalizeOrigin(value: string | undefined, defaults: {
    host: string;
    secure: boolean;
}): string;
