/** * Multi-provider LLM scan core. * * This module hosts the unified {@link LlmProviderOptions} interface, the * {@link LlmProviderType} enum, and the {@link createLlmProvider} factory * that dispatches to a concrete provider implementation. The OpenAI- * compatible provider ({@link OpenAICompatibleLlmProvider}) lives here as * the reference implementation; Gemini and Anthropic providers live in * sibling modules and are wired up through the factory. * * Shared parsing/validation helpers and the {@link LlmProviderError} class * are imported from {@link ./parse.js} so every provider reuses the same * logic instead of duplicating it. */ import type { LlmScanReport } from "../scanner/types.js"; export { LlmProviderError } from "./parse.js"; export { GeminiLlmProvider } from "./gemini.js"; export { AnthropicLlmProvider } from "./anthropic.js"; /** * Input passed to an LLM scan provider. */ export interface LlmScanInput { readonly packageName: string; readonly version: string; readonly description: string; readonly readme: string; readonly packageJson?: Record; /** * Optional external abort signal. When supplied, the provider combines it * with its own timeout controller via `AbortSignal.any` so an abort during * an in-flight scan settles the promise promptly with an `AbortError` * `DOMException` (cooperative cancellation). */ readonly signal?: AbortSignal; } /** * Contract every LLM scan provider implements. */ export interface LlmScanProvider { scan(input: LlmScanInput): Promise; testConnection(): Promise; } /** * Supported LLM provider backends. */ export declare enum LlmProviderType { OpenAi = "openai", Gemini = "gemini", Anthropic = "anthropic" } /** * Unified options accepted by {@link createLlmProvider} and every concrete * provider constructor. Fields not relevant to a given backend are ignored * by that backend. */ export interface LlmProviderOptions { /** Backend to instantiate. @default {@link LlmProviderType.OpenAi} */ readonly provider?: LlmProviderType; /** API key. Falls back to a backend-specific env var when omitted. */ readonly apiKey?: string; /** Base URL of the LLM API endpoint. */ readonly baseUrl?: string; /** Model identifier to use for completions. */ readonly model?: string; /** Request timeout in milliseconds. @default 30000 */ readonly timeoutMs?: number; /** Maximum README characters to send to the model. @default 12000 */ readonly maxInputChars?: number; /** Maximum response tokens. @default 4096 */ readonly maxTokens?: number; } /** * Deprecated alias for {@link LlmProviderOptions}. * @deprecated Use {@link LlmProviderOptions} instead. */ export type OpenAICompatibleLlmOptions = LlmProviderOptions; /** * Construct an {@link LlmScanProvider} for the backend selected via * {@link LlmProviderOptions.provider}. Defaults to the OpenAI-compatible * provider. * * @param options - Provider configuration. When omitted, an OpenAI- * compatible provider is constructed with environment-derived defaults. * @returns A concrete {@link LlmScanProvider} instance. */ export declare function createLlmProvider(options?: LlmProviderOptions): LlmScanProvider; /** * OpenAI-compatible chat completions LLM scan provider. * * Talks to any endpoint that implements the `/chat/completions` surface * (OpenAI, Azure OpenAI, local LM Studio / Ollama OpenAI shims, etc.). */ export declare class OpenAICompatibleLlmProvider implements LlmScanProvider { private readonly apiKey?; private readonly baseUrl; private readonly model; private readonly timeoutMs; private readonly maxInputChars; private readonly maxTokens; /** * @param options - Provider configuration. Env-var fallbacks: * `apiKey` defaults to `process.env.OPENAI_API_KEY`. */ constructor(options?: LlmProviderOptions); /** @inheritdoc */ scan(input: LlmScanInput): Promise; /** @inheritdoc */ testConnection(): Promise; /** * Issue a POST to `/chat/completions` with timeout and error normalization. * * @param body - The JSON request body. * @param signal - Optional external abort signal combined with the owned * timeout controller via `AbortSignal.any`. An external abort propagates * as `DOMException('The operation was aborted.', 'AbortError')`. * @returns The `choices[0].message.content` string from the response. * @throws {LlmProviderError} On network, timeout, HTTP, or shape errors. * @throws {DOMException} With name `AbortError` when `signal` is aborted. */ private request; } //# sourceMappingURL=provider.d.ts.map