/** * Classify errors that surface during the Generate flow into structured * categories the UI can render with tailored CTAs. * * Strict policy: only the cases we are 100% confident about get their own * `kind`. Everything else falls through to `'unknown'` with the raw message * so we don't claim to know what happened when we don't. * * Sure cases (today): * - 'rate_limit' — `LaminaRateLimitError` instance from the SDK, * carries a `retryAfterSeconds` field. * - 'needs_choice' — `/v1/content/auto-generate` returned * `status: 'needs_choice'`. Server-defined enum, * not a string we're guessing at. * - 'insufficient_credits' — error message matches the exact server log * line `'Insufficient credits'` (verified from * real freestyle-fallback logs). * * Auth errors (`LaminaAuthError`) intentionally fall through to `'unknown'` * here — the OAuth refactor in `LaminaContext.tsx` already handles them by * clearing storage and re-rendering to the sign-in surface, so by the time * one would reach this classifier the user is already on the login screen. */ export type GenerationError = { kind: 'rate_limit'; retryAfterSeconds: number | null; message: string; } | { kind: 'needs_choice'; reason: string; } | { kind: 'insufficient_credits'; message: string; topUpUrl: string; } | { kind: 'unknown'; message: string; }; /** * Classify an exception thrown by an SDK call (`autoGenerate`, `runs.wait`, * etc.) into a structured error. */ export declare function classifyThrownError(err: unknown): GenerationError; /** * Classify an `auto-generate` response that didn't produce a runId. Returns * `null` when the response was the happy path (the caller's already moved on). */ export declare function classifyAutoGenerateResult(data: { status?: string; reason?: string; } | null | undefined): GenerationError | null; /** * Classify a run that polled to terminal `failed`. The run pipeline writes * the failure reason as a free-text string; we pattern-match for known * categories and fall through to `'unknown'` otherwise. */ export declare function classifyRunFailure(errorMessage: string | null | undefined): GenerationError;