/** * Shared local-first LLM client (Phase 1, cross-cutting §1). * * Wraps the Vercel AI SDK (`generateText` / `generateObject`) over an * OpenAI-compatible provider configured from the top-level `config.llm` block. * Default backend is a local Ollama instance (http://localhost:11434/v1). * * Contract (cross-cutting §1): * (a) respect `timeoutMs` (via AbortSignal.timeout), * (b) degrade silently to a non-LLM path on any failure — never throw, * (c) be config-gated default-off (`config.llm.enabled`, env RLM_LLM_ENABLED). * * Consumers (Phase 1: consolidator; Phase 2: query-understanding; Phase 4: * bootstrap; Phase 5: auto-improve; Phase 7: compression) MUST treat a * `{ ok: false }` result as "fall through to the non-LLM path". */ import type { z } from "zod"; /** * Which model role a call targets. `"instruct"` (default) selects the * NL/instruction model (`config.llm.model`); `"code"` selects the coder model * (`config.llm.codeModel`) for code-oriented sites (bootstrap, reranker, * compression). This is the per-task routing knob (COVERAGE #1/#5/#7). */ export type LlmModelRole = "instruct" | "code"; export interface LlmCompleteOptions { /** Optional system prompt. */ system?: string; /** Per-call timeout override (ms). Defaults to `config.llm.timeoutMs`. */ timeoutMs?: number; /** Model role: `"instruct"` (default) or `"code"`. */ modelRole?: LlmModelRole; } export interface LlmObjectOptions extends LlmCompleteOptions { } export interface LlmResult { ok: boolean; value?: T; /** Present when ok === false. */ error?: string; } /** Whether the LLM is enabled at the current config. Cheap, side-effect-free. */ export declare function isLlmEnabled(): boolean; export declare function _setLlmEnabledForTesting(flag: boolean | null): void; /** * Best-effort `think:false` injection. Ollama's OpenAI-compat layer honors a * top-level `think` field for qwen3. Wrapped fetch keeps the SDK contract * intact and only mutates the JSON body for chat/completion POSTs. * * Typed loosely (input/init as unknown) and cast on return so it satisfies the * SDK's `FetchFunction` (Bun's fetch type includes a `preconnect` method that a * plain wrapper does not carry) without forcing callers to replicate it. * @internal */ export declare function _wrapFetchDisableThink(baseFetch: typeof globalThis.fetch): typeof globalThis.fetch; /** * Normalize the reasoning channel exposed by the AI SDK (v5+) into a single * string. Handles: array of `{type:"reasoning", text}` parts, a raw string, * `providerMetadata.openai.reasoningText`, and the Responses-API error shape * (`response.body.output[].summary[].text`). Returns "" when absent. * * Accepts either a successful `result` or a thrown `AI_NoObjectGeneratedError` * (which carries `response.body.output`). * @internal */ export declare function _reasoningToText(result: any): string; /** * Best-effort extraction of the first balanced JSON object from a free-text * (typically reasoning) string. Strips ```json fences first. Returns the * parsed object or `undefined` on any failure. Pure; safe to unit-test. * @internal */ export declare function _extractJsonObject(text: string): unknown | undefined; /** * Generate a free-form text completion. Returns `{ ok: false }` (never throws) * when the LLM is disabled, times out, or errors. When the content channel is * empty (qwen3 thinking-model failure mode), falls back to the reasoning * channel before degrading. */ export declare function llmComplete(prompt: string, opts?: LlmCompleteOptions): Promise>; /** * Generate a structured object validated against a zod schema. Returns * `{ ok: false }` (never throws) when the LLM is disabled, times out, returns * an invalid object, or errors. When the content channel is empty or the * schema fails (qwen3 thinking-model failure mode), attempts to recover JSON * from the reasoning channel before degrading. */ export declare function llmObject(prompt: string, schema: z.ZodSchema, opts?: LlmObjectOptions): Promise>; /** * Injectable handle bundling both calls, so callers (consolidator, etc.) can * be tested with a fake LLM without touching config or network. */ export declare const llm: { complete: typeof llmComplete; object: typeof llmObject; isEnabled: typeof isLlmEnabled; }; //# sourceMappingURL=llm-client.d.ts.map