vern-llm 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +6 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -4
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -279,7 +279,9 @@ var VernLLM = class {
|
|
|
279
279
|
this.nonRetryableStatus = options.nonRetryableStatus ?? [
|
|
280
280
|
400,
|
|
281
281
|
401,
|
|
282
|
-
403
|
|
282
|
+
403,
|
|
283
|
+
404,
|
|
284
|
+
422
|
|
283
285
|
];
|
|
284
286
|
this.parseJson = options.parseJson ?? defaultParseJson;
|
|
285
287
|
this.onUsage = options.onUsage;
|
|
@@ -300,11 +302,11 @@ var VernLLM = class {
|
|
|
300
302
|
}
|
|
301
303
|
/**
|
|
302
304
|
* Returns the caller supplied logger, or a console-based logger whose
|
|
303
|
-
* debug output is gated by the `debug` option (defaulting to
|
|
304
|
-
*
|
|
305
|
+
* debug output is gated by the `debug` option (defaulting to off,
|
|
306
|
+
* so response content isn't unintentionally written to logs)
|
|
305
307
|
*/
|
|
306
308
|
resolveLogger(options) {
|
|
307
|
-
return options.logger ?? new ConsoleLogger(options.debug ??
|
|
309
|
+
return options.logger ?? new ConsoleLogger(options.debug ?? false);
|
|
308
310
|
}
|
|
309
311
|
/**
|
|
310
312
|
* Builds a circuit breaker if `circuitBreaker` is truthy on the
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["message: string","type: LLMErrorType","status?: number","issues?: unknown","err: unknown","options: CircuitBreakerOptions","content: string","err: unknown","fn: (signal: AbortSignal) => Promise<T>","timeoutMs: number","externalSignal?: AbortSignal","baseDelayMs: number","attempt: number","delay: number","signal?: AbortSignal","debugEnabled: boolean","message: string","meta?: Record<string, unknown>","key: string","value: T","ttl: number","options: VernLLMOptions","params: CallParams<T>","fn: () => Promise<T>","requestId: string","signal?: AbortSignal","lastError: unknown","error: unknown","history: ConversationTurn[]","previousRole: 'user' | 'assistant' | undefined","jsonSchema: CallParams<unknown>['jsonSchema']","useJson: boolean","response: Awaited<ReturnType<LLMClient['chat']['completions']['create']>>","model: string","content: string","schema?: CallParams<T>['schema']","parsed: unknown","attempt: number","key: string","params: CachedCallParams<T>","params: Omit<CachedCallParams<T>, 'fn'> & { call: CallParams<T> }","anthropicClient: AnthropicClient","jsonInstruction: string | undefined","tools:\n | NonNullable<Parameters<AnthropicClient['messages']['create']>[0]['tools']>\n | undefined","text: string","geminiClient: GeminiClient","generationConfig: NonNullable<\n Parameters<GeminiClient['generateContent']>[0]['generationConfig']\n >","bedrockClient: BedrockConverseClient","jsonInstruction: string | undefined","toolConfig:\n | NonNullable<Parameters<BedrockConverseClient['converse']>[0]['toolConfig']>\n | undefined","text","text: string","config: FetchAdapterConfig","client: unknown"],"sources":["../src/types/errors.ts","../src/circuitBreaker.ts","../src/internal/vernLLM.utils.ts","../src/logger.ts","../src/types/cache.ts","../src/vernLLM.ts","../src/adapters/anthropic.ts","../src/adapters/gemini.ts","../src/adapters/bedrock.ts","../src/adapters/fetch.ts","../src/adapters/openaiCompatible.ts"],"sourcesContent":["export type LLMErrorType =\n | 'timeout'\n | 'api'\n | 'parse'\n | 'validation'\n | 'circuit_open'\n | 'unknown'\n | 'aborted';\n\nexport class LLMError extends Error {\n constructor(\n message: string,\n public type: LLMErrorType,\n public status?: number,\n public issues?: unknown,\n ) {\n super(message);\n this.name = 'LLMError';\n }\n}\n\nexport function isLLMError(err: unknown): err is LLMError {\n return err instanceof LLMError;\n}\n","import { LLMError } from './types/errors.js';\n\nexport interface CircuitBreakerOptions {\n /** Consecutive failures before the circuit opens, default 5 */\n threshold?: number;\n /** How long the circuit stays open before allowing a trial request, in ms. Default 30000 */\n cooldownMs?: number;\n}\n\ntype CircuitState = 'closed' | 'open' | 'half-open';\n\n/**\n * Per retry VernLLM-instance circuit breaker. Tracks consecutive failures across\n * calls. Once the threshold is hit, short-circuits new calls with an\n * LLMError('circuit_open') instead of hitting the provider, until the\n * cooldown elapses and a single trial call is allowed through\n */\nexport class CircuitBreaker {\n private state: CircuitState = 'closed';\n private consecutiveFailures = 0;\n private openedAt = 0;\n private threshold: number;\n private cooldownMs: number;\n\n constructor(options: CircuitBreakerOptions = {}) {\n this.threshold = options.threshold ?? 5;\n this.cooldownMs = options.cooldownMs ?? 30_000;\n }\n\n /** Throws if the circuit is open and the cooldown hasnt elapsed */\n assertClosed(): void {\n if (this.state !== 'open') return;\n\n const elapsed = Date.now() - this.openedAt;\n if (elapsed >= this.cooldownMs) {\n this.state = 'half-open';\n return;\n }\n\n throw new LLMError(\n `Circuit open — provider has failed ${this.consecutiveFailures} times in a row. Retry in ${Math.ceil((this.cooldownMs - elapsed) / 1000)}s.`,\n 'circuit_open',\n );\n }\n\n recordSuccess(): void {\n this.consecutiveFailures = 0;\n this.state = 'closed';\n }\n\n recordFailure(): void {\n this.consecutiveFailures += 1;\n\n if (this.state === 'half-open') {\n // Trial call failed: reopen and reset the cooldown window.\n this.state = 'open';\n this.openedAt = Date.now();\n return;\n }\n\n if (this.consecutiveFailures >= this.threshold) {\n this.state = 'open';\n this.openedAt = Date.now();\n }\n }\n\n getState(): CircuitState {\n return this.state;\n }\n}\n","import { LLMError } from '../types/errors.js';\n\nexport function defaultParseJson(content: string): unknown {\n try {\n return JSON.parse(content);\n } catch {\n return undefined;\n }\n}\n\n/**\n * Looks inside an unknown error value and pulls out an http status code\n * if one is present. Checks the status field first then the status code\n * field since different client libraries use different names for this.\n * Returns undefined when the error is not an object or carries no status\n */\nexport function extractStatus(err: unknown): number | undefined {\n if (!err || typeof err !== 'object') return undefined;\n\n const error = err as {\n status?: unknown;\n statusCode?: unknown;\n };\n\n if (typeof error.status === 'number') return error.status;\n if (typeof error.statusCode === 'number') return error.statusCode;\n\n return undefined;\n}\n\n/**\n * Runs an async function and cancels it if it takes longer than the given\n * timeout. Creates an internal abort controller that fires after the\n * timeout elapses, and combines it with any external signal the caller\n * passed in so either one can cancel the underlying call. If the internal\n * timeout triggers and the underlying operation aborts, the error is\n * converted into an LLMError with type \"timeout\". External cancellations\n * continue to propagate as aborted errors. The internal timer is always\n * cleared afterward, whether the function succeeds, fails, or is aborted,\n * so nothing is left running in the background.\n */\nexport async function withTimeout<T>(\n fn: (signal: AbortSignal) => Promise<T>,\n timeoutMs: number,\n externalSignal?: AbortSignal,\n): Promise<T> {\n const controller = new AbortController();\n\n const timer = setTimeout(() => {\n controller.abort();\n }, timeoutMs);\n\n const signal = externalSignal\n ? AbortSignal.any([externalSignal, controller.signal])\n : controller.signal;\n\n try {\n return await fn(signal);\n } catch (err) {\n if (\n controller.signal.aborted &&\n !externalSignal?.aborted &&\n err instanceof DOMException &&\n err.name === 'AbortError'\n ) {\n throw new LLMError('Request timed out', 'timeout');\n }\n\n throw err;\n } finally {\n clearTimeout(timer);\n }\n}\n\n/**\n * Exponential backoff with jitter, capped at maxDelayMs.\n * Jitter avoids thundering-herd retries when many callers back off in lockstep,\n * the cap prevents unbounded delays when maxRetries is high\n */\nexport function getBackoffDelay(baseDelayMs: number, attempt: number, maxDelayMs = 10_000): number {\n const exp = Math.min(baseDelayMs * 2 ** attempt, maxDelayMs);\n return exp / 2 + Math.random() * (exp / 2);\n}\n\n/**\n * Pauses execution for the given delay before a retry attempt. If an\n * abort signal is provided and it fires while waiting, the pending\n * timer is cancelled immediately and the wait rejects right away with\n * an aborted error instead of continuing to sit idle until the delay\n * would have finished on its own\n */\nexport async function waitForRetry(delay: number, signal?: AbortSignal): Promise<void> {\n await new Promise<void>((resolve, reject) => {\n const onAbort = () => {\n clearTimeout(timer);\n reject(new LLMError('Operation aborted', 'aborted'));\n };\n\n const timer = setTimeout(() => {\n signal?.removeEventListener('abort', onAbort);\n resolve();\n }, delay);\n\n signal?.addEventListener('abort', onAbort, { once: true });\n });\n}\n","export interface Logger {\n debug(message: string): void;\n warn(message: string): void;\n error(message: string, meta?: Record<string, unknown>): void;\n}\n\n/**\n * Default logger. `debug` is gated by the `debug` option on VernLLM\n * warn/error always fire since they indicate real problems (retries, cache failures)\n */\nexport class ConsoleLogger implements Logger {\n constructor(private debugEnabled: boolean) {}\n\n debug(message: string): void {\n if (this.debugEnabled) console.debug(message);\n }\n\n warn(message: string): void {\n console.warn(message);\n }\n\n error(message: string, meta?: Record<string, unknown>): void {\n console.error(message, meta ?? '');\n }\n}\n","export interface CacheAdapter<T = unknown> {\n get(key: string): Promise<{ hit: boolean; value: T | null }>;\n set(key: string, value: T, ttl: number): Promise<void>;\n delete?(key: string): Promise<void>;\n}\n\n/**\n * Trivial default so the package works out of the box with no external deps\n * Not shared across processes, swap in Redis/Upstash/etc for production\n */\nexport class InMemoryCacheAdapter<T = unknown> implements CacheAdapter<T> {\n private store = new Map<string, { value: T; expiresAt: number }>();\n\n constructor(private readonly maxSize = 1000) {}\n\n async get(key: string): Promise<{ hit: boolean; value: T | null }> {\n const entry = this.store.get(key);\n\n if (!entry) return { hit: false, value: null };\n\n if (Date.now() >= entry.expiresAt) {\n this.store.delete(key);\n return { hit: false, value: null };\n }\n\n return { hit: true, value: entry.value };\n }\n\n async set(key: string, value: T, ttl: number): Promise<void> {\n this.cleanupExpiredEntries();\n\n this.store.set(key, {\n value,\n expiresAt: Date.now() + ttl * 1000,\n });\n\n this.enforceSizeLimit();\n }\n\n async delete(key: string): Promise<void> {\n this.store.delete(key);\n }\n\n private cleanupExpiredEntries(): void {\n const now = Date.now();\n\n for (const [key, entry] of this.store) {\n if (now >= entry.expiresAt) {\n this.store.delete(key);\n }\n }\n }\n\n private enforceSizeLimit(): void {\n while (this.store.size > this.maxSize) {\n const oldestKey = this.store.keys().next().value;\n\n if (oldestKey === undefined) break;\n\n this.store.delete(oldestKey);\n }\n }\n}\n","import { randomUUID } from 'crypto';\n\nimport { CircuitBreaker } from './circuitBreaker.js';\nimport {\n defaultParseJson,\n extractStatus,\n withTimeout,\n getBackoffDelay,\n waitForRetry,\n} from './internal/vernLLM.utils.js';\nimport { ConsoleLogger, type Logger } from './logger.js';\nimport {\n InMemoryCacheAdapter,\n LLMError,\n type CacheAdapter,\n type CachedCallParams,\n type CallParams,\n type ConversationTurn,\n type LLMClient,\n type VernLLMOptions,\n} from './types/index.js';\n\n/**\n * A resilient wrapper around an LLM chat completions client, this is VernLLM!\n *\n * Adds retry with exponential backoff and jitter, per-attempt timeouts,\n * an optional circuit breaker, JSON parsing with optional schema\n * validation, usage tracking, and an optional response cache, all\n * configurable, all opt-in beyond sensible defaults\n */\nexport class VernLLM {\n private readonly client: LLMClient;\n private readonly model: string;\n\n private readonly maxRetries: number;\n private readonly timeoutMs: number;\n private readonly baseDelayMs: number;\n private readonly defaultMaxTokens: number;\n\n private readonly cache: CacheAdapter<unknown>;\n private readonly nonRetryableStatus: number[];\n\n private readonly parseJson: (content: string) => unknown;\n private readonly onUsage?: VernLLMOptions['onUsage'];\n\n private readonly logger: Logger;\n private readonly breaker?: CircuitBreaker;\n\n /**\n * @param options: Client, model, and all tunables (retries, timeout,\n * backoff, cache, circuit breaker, logger, etc). See VernLLMOptions in `types.ts`\n * for individual defaults\n */\n constructor(options: VernLLMOptions) {\n this.client = options.client;\n this.model = options.model;\n\n const retryConfig = this.resolveRetryConfig(options);\n this.maxRetries = retryConfig.maxRetries;\n this.timeoutMs = retryConfig.timeoutMs;\n this.baseDelayMs = retryConfig.baseDelayMs;\n this.defaultMaxTokens = retryConfig.defaultMaxTokens;\n\n this.cache = options.cache ?? new InMemoryCacheAdapter();\n this.nonRetryableStatus = options.nonRetryableStatus ?? [400, 401, 403];\n\n this.parseJson = options.parseJson ?? defaultParseJson;\n this.onUsage = options.onUsage;\n\n this.logger = this.resolveLogger(options);\n this.breaker = this.resolveCircuitBreaker(options);\n }\n\n /**\n * Resolves retry/timeout/token defaults from the given options,\n * falling back to the librarys built-in defaults for anything unset\n */\n private resolveRetryConfig(options: VernLLMOptions) {\n return {\n maxRetries: options.maxRetries ?? 1,\n timeoutMs: options.timeoutMs ?? 25_000,\n baseDelayMs: options.baseDelayMs ?? 500,\n defaultMaxTokens: options.defaultMaxTokens ?? 1000,\n };\n }\n\n /**\n * Returns the caller supplied logger, or a console-based logger whose\n * debug output is gated by the `debug` option (defaulting to on\n * outside production)\n */\n private resolveLogger(options: VernLLMOptions): Logger {\n return (\n options.logger ?? new ConsoleLogger(options.debug ?? process.env.NODE_ENV !== 'production')\n );\n }\n\n /**\n * Builds a circuit breaker if `circuitBreaker` is truthy on the\n * options. Passing `true` uses default thresholds, passing an options\n * object tunes them. Returns undefined when the breaker is disabled\n */\n private resolveCircuitBreaker(options: VernLLMOptions): CircuitBreaker | undefined {\n if (!options.circuitBreaker) return undefined;\n\n return new CircuitBreaker(options.circuitBreaker === true ? undefined : options.circuitBreaker);\n }\n\n /**\n * Makes a single logical LLM call, transparently retrying on failure\n * according to the configured retry policy\n *\n * Fails fast if the circuit breaker is open or the signal is already\n * aborted, before any request is dispatched. On exhausting all\n * retries, records a circuit breaker failure and rejects with a\n * normalized LLMError\n *\n * @param params : System/user content plus per call overrides\n * (model, temperature, jsonMode, schema, signal, etc)\n * @returns The parsed and optionally schema-validated response, or\n * the raw string content when jsonMode is disabled\n */\n async call<T = unknown>(params: CallParams<T>): Promise<T> {\n this.breaker?.assertClosed();\n\n if (params.signal?.aborted) {\n throw new LLMError('LLM request aborted', 'aborted');\n }\n\n const requestId = params.requestId ?? randomUUID();\n\n try {\n const result = await this.retryWithBackoff(\n () => this.executeCall(params, requestId),\n requestId,\n params.signal,\n );\n\n return result;\n } catch (error) {\n this.breaker?.recordFailure();\n throw this.normalizeError(error, params.signal);\n }\n }\n\n /**\n * Runs `fn`, retrying with backoff according to `shouldRetry` policy\n * Purely mechanical: knows nothing about LLM specifics beyond the retry\n * predicate, so its testable independent of request/response shaping\n */\n private async retryWithBackoff<T>(\n fn: () => Promise<T>,\n requestId: string,\n signal?: AbortSignal,\n ): Promise<T> {\n let lastError: unknown;\n\n for (let attempt = 0; attempt <= this.maxRetries; attempt++) {\n try {\n if (attempt > 0) {\n await this.recoverDelay(requestId, attempt, signal);\n }\n\n return await fn();\n } catch (error) {\n lastError = error;\n\n if (!this.shouldRetry(error, signal)) {\n break;\n }\n }\n }\n\n throw lastError;\n }\n\n /**\n * Converts any thrown value into a well-typed LLMError for the public\n * API surface. Preserves an existing LLMError as is, reports aborted\n * signals as such, classifies errors carrying an http status as\n * type api, and otherwise falls back to a generic unknown error.\n */\n private normalizeError(error: unknown, signal?: AbortSignal): LLMError {\n if (signal?.aborted) {\n return new LLMError('LLM request aborted', 'aborted');\n }\n\n if (error instanceof LLMError) {\n return error;\n }\n\n const status = extractStatus(error);\n\n if (status !== undefined) {\n return new LLMError('LLM request failed', 'api', status);\n }\n\n return new LLMError('LLM request failed', 'unknown');\n }\n\n /**\n * Performs a single attempt: builds the request, dispatches it with a\n * timeout, and shapes the response. Throws on an empty response so\n * the retry loop treats it like any other transient failure. Records\n * usage and a circuit breaker success before returning\n */\n private async executeCall<T>(params: CallParams<T>, requestId: string): Promise<T> {\n const { useJson, model, request } = this.buildRequestPayload(params);\n\n const response = await withTimeout(\n (attemptSignal) => this.client.chat.completions.create(request, { signal: attemptSignal }),\n this.timeoutMs,\n params.signal,\n );\n\n const content = response.choices?.[0]?.message?.content?.trim();\n\n if (!content) {\n throw new LLMError('Empty LLM response', 'api');\n }\n\n this.logger.debug(`[vern:${requestId}] output:\\n${content.slice(0, 800)}`);\n\n this.recordUsage(response, requestId, model);\n\n this.breaker?.recordSuccess();\n\n if (!useJson) {\n return content as T;\n }\n\n return this.parseAndValidate(content, params.schema);\n }\n\n /**\n * Anthropic and Gemini both require strict user/assistant alternation\n * (and reject or silently mishandle two consecutive same-role turns), so\n * this validates `history` up front rather than letting a malformed\n * request surface as a confusing provider-side error. Thrown as a\n * validation LLMError, which `shouldRetry` never retries, since retrying\n * the same malformed input can't succeed\n */\n private validateHistory(history: ConversationTurn[]): void {\n let previousRole: 'user' | 'assistant' | undefined;\n\n for (const [index, turn] of history.entries()) {\n if (turn.role !== 'user' && turn.role !== 'assistant') {\n throw new LLMError(\n `Invalid history[${index}].role \"${turn.role}\": must be \"user\" or \"assistant\"`,\n 'validation',\n );\n }\n\n if (turn.role === previousRole) {\n throw new LLMError(\n `history must alternate user/assistant turns: consecutive \"${turn.role}\" turns at history[${index - 1}] and history[${index}]`,\n 'validation',\n );\n }\n\n previousRole = turn.role;\n }\n\n if (previousRole === 'user') {\n throw new LLMError(\n 'The last entry in history is a \"user\" turn, which would collide with the current userContent turn. history must end with an \"assistant\" turn (or be empty).',\n 'validation',\n );\n }\n }\n\n /**\n * Applies per call defaults and shapes the params into the request\n * object expected by the underlying client, including the resolved\n * response format. Also returns whether JSON parsing should be\n * applied to the response and which model was ultimately used\n */\n private buildRequestPayload<T>(params: CallParams<T>) {\n const {\n systemPrompt,\n userContent,\n history = [],\n temperature = 0.2,\n jsonMode = true,\n maxTokens = this.defaultMaxTokens,\n model = this.model,\n reasoningEffort,\n jsonSchema,\n } = params;\n\n const useJson = jsonMode || Boolean(jsonSchema);\n const responseFormat = this.buildResponseFormat(jsonSchema, useJson);\n\n this.validateHistory(history);\n\n const request = {\n model,\n temperature,\n max_tokens: maxTokens,\n ...(responseFormat ? { response_format: responseFormat } : {}),\n ...(reasoningEffort ? { reasoning_effort: reasoningEffort } : {}),\n messages: [\n ...(systemPrompt ? [{ role: 'system' as const, content: systemPrompt }] : []),\n ...history.map((turn) => ({ role: turn.role, content: turn.content })),\n { role: 'user' as const, content: userContent },\n ],\n };\n\n return { useJson, model, request };\n }\n\n /**\n * Chooses the response format to send to the provider. A provider\n * native json schema takes priority when supplied, constraining\n * generation directly, otherwise falls back to the looser json\n * object mode when JSON output is requested, or no format at all\n * for plain text responses\n */\n private buildResponseFormat(jsonSchema: CallParams<unknown>['jsonSchema'], useJson: boolean) {\n if (jsonSchema) {\n return {\n type: 'json_schema' as const,\n json_schema: {\n name: jsonSchema.name,\n schema: jsonSchema.schema,\n strict: jsonSchema.strict ?? true,\n description: jsonSchema.description,\n },\n };\n }\n\n return useJson ? { type: 'json_object' as const } : undefined;\n }\n\n /**\n * Reports token usage to the caller supplied onUsage callback, when\n * both a callback was configured and the provider actually returned\n * usage data on this response. A no op otherwise.\n */\n private recordUsage(\n response: Awaited<ReturnType<LLMClient['chat']['completions']['create']>>,\n requestId: string,\n model: string,\n ): void {\n if (!response.usage || !this.onUsage) return;\n\n this.onUsage({\n promptTokens: response.usage.prompt_tokens ?? 0,\n completionTokens: response.usage.completion_tokens ?? 0,\n totalTokens: response.usage.total_tokens ?? 0,\n requestId,\n model,\n });\n }\n\n /**\n * Parses the raw response content as JSON and, when a schema is\n * supplied, validates the parsed value against it. Throws a parse\n * type LLMError on malformed JSON and a validation type LLMError,\n * carrying the schemas issues, on a failed validation\n */\n private parseAndValidate<T>(content: string, schema?: CallParams<T>['schema']): T {\n let parsed: unknown;\n\n try {\n parsed = this.parseJson(content);\n } catch {\n throw new LLMError('Invalid JSON response', 'parse');\n }\n\n if (parsed === null || parsed === undefined) {\n throw new LLMError('Invalid JSON response', 'parse');\n }\n\n if (!schema) {\n return parsed as T;\n }\n\n const result = schema.safeParse(parsed);\n\n if (!result.success) {\n throw new LLMError('Schema validation failed', 'validation', undefined, result.error);\n }\n\n return result.data;\n }\n\n /**\n * Waits out the backoff delay for a given retry attempt, logging the\n * attempt for observability before the wait begins. Rejects early if\n * the signal aborts during the wait\n */\n private async recoverDelay(requestId: string, attempt: number, signal?: AbortSignal) {\n const delay = getBackoffDelay(this.baseDelayMs, attempt);\n\n this.logger.warn(\n `[vern:${requestId}] recovery attempt ${attempt}/${this.maxRetries}, waiting ${delay}ms`,\n );\n\n await waitForRetry(delay, signal);\n }\n\n /**\n * Decides whether a failed attempt is worth retrying. Never retries\n * once the signal has aborted, never retries a parse or validation\n * failure since those stem from the response content rather than a\n * transient fault, and never retries a status code the caller has\n * marked as non retryable. Retries everything else\n */\n private shouldRetry(error: unknown, signal?: AbortSignal): boolean {\n if (signal?.aborted) {\n return false;\n }\n\n if (error instanceof LLMError && (error.type === 'parse' || error.type === 'validation')) {\n return false;\n }\n\n const status = extractStatus(error);\n\n if (status !== undefined && this.nonRetryableStatus.includes(status)) {\n return false;\n }\n\n return true;\n }\n\n /**\n * Removes a cached response by key when the configured cache adapter\n * supports deletion.\n *\n * Cache invalidation remains the responsibility of the caller because\n * only the application knows when cached data is stale.\n */\n async deleteCache(key: string): Promise<void> {\n if (!this.cache.delete) {\n return;\n }\n\n await this.cache.delete(key);\n }\n\n /**\n * Thin cache wrapper around caller supplied logic. `params.fn` is expected\n * to be a call that itself invokes `this.call(...)` (see `cachedLLMCall`\n * below for a convenience wrapper that wires this up automatically),\n * `cachedCall` does not itself apply retry/timeout policy.\n */\n async cachedCall<T>(params: CachedCallParams<T>): Promise<T> {\n const cached = await this.cache.get(params.cacheKey);\n\n if (cached.hit) {\n return cached.value as T;\n }\n\n try {\n await params.reserveUsage?.();\n\n const result = await params.fn();\n\n try {\n await this.cache.set(params.cacheKey, result, params.ttl);\n } catch (error) {\n this.logger.error('[VernLLM] cache write failed', {\n message: error instanceof Error ? error.message : 'unknown',\n });\n }\n\n return result;\n } catch (error) {\n try {\n await params.refundUsage?.();\n } catch (refundError) {\n this.logger.error('[VernLLM] refundUsage failed', {\n message: refundError instanceof Error ? refundError.message : 'unknown',\n });\n }\n\n throw error;\n }\n }\n\n /**\n * Convenience wrapper composing `call` + `cachedCall`, so cached LLM calls\n * automatically get retry/timeout/circuit-breaker behavior without callers\n * having to remember to wire `fn: () => this.call(...)` themselves\n */\n async cachedLLMCall<T>(\n params: Omit<CachedCallParams<T>, 'fn'> & { call: CallParams<T> },\n ): Promise<T> {\n const { call: callParams, ...cacheParams } = params;\n\n return this.cachedCall({\n ...cacheParams,\n fn: () => this.call(callParams),\n });\n }\n\n /**\n * Returns the current circuit breaker state, or undefined when no\n * circuit breaker was configured on this instance\n */\n getCircuitState() {\n return this.breaker?.getState();\n }\n}\n","import type { LLMClient } from '../types/index.js';\n\n/** Minimal structural type for the Anthropic SDKs `messages.create` */\nexport interface AnthropicClient {\n messages: {\n create(\n params: {\n model: string;\n max_tokens: number;\n temperature?: number;\n system?: string;\n messages: Array<{ role: 'user' | 'assistant'; content: string }>;\n tools?: Array<{\n name: string;\n description?: string;\n input_schema: Record<string, unknown>;\n }>;\n tool_choice?: { type: 'tool'; name: string };\n },\n options: { signal: AbortSignal },\n ): Promise<{\n content: Array<{ type: string; text?: string; name?: string; input?: unknown }>;\n usage?: { input_tokens?: number; output_tokens?: number };\n }>;\n };\n}\n\n/**\n * Wraps an Anthropic SDK client so it satisfies the same `LLMClient`\n * interface VernLLM uses for OpenAI/Groq.\n *\n * `response_format: json_schema` is mapped to Anthropics forced tool-use:\n * a single tool is defined with `input_schema` set to the caller's schema,\n * and `tool_choice` forces the model to call it, so the output is\n * provider-constrained to match the schema rather than merely instructed\n * to via prompt text (the same guarantee OpenAIs native `json_schema` mode\n * gives, built on Anthropics tool-calling primitive instead).\n *\n * `response_format: json_object` (no schema to build a tool from) falls\n * back to a system-prompt instruction, since theres nothing to constrain\n * generation against.\n */\nexport function fromAnthropic(anthropicClient: AnthropicClient): LLMClient {\n return {\n chat: {\n completions: {\n async create(params, options) {\n const systemMessage = params.messages.find((m) => m.role === 'system');\n // Keep both user and assistant turns, in order, so multi-turn history\n // survives instead of collapsing to consecutive user messages.\n const conversationMessages = params.messages.filter(\n (m): m is typeof m & { role: 'user' | 'assistant' } =>\n m.role === 'user' || m.role === 'assistant',\n );\n\n const toolName =\n params.response_format?.type === 'json_schema'\n ? params.response_format.json_schema.name\n : undefined;\n\n let jsonInstruction: string | undefined;\n let tools:\n | NonNullable<Parameters<AnthropicClient['messages']['create']>[0]['tools']>\n | undefined;\n\n if (params.response_format?.type === 'json_schema' && toolName) {\n const { schema, description } = params.response_format.json_schema;\n tools = [{ name: toolName, description, input_schema: schema }];\n } else if (params.response_format?.type === 'json_object') {\n // No schema to build a tool from, fall back to a prompt instruction\n jsonInstruction = 'Respond with valid JSON only, no prose or markdown fences.';\n }\n\n // `reasoning_effort` (OpenAI o-series/gpt-5 style) has no direct Anthropic\n // equivalent, Claudes extended thinking uses a token budget, not a tier\n // string, so its intentionally dropped here rather than guessed at.\n\n const system = [systemMessage?.content, jsonInstruction].filter(Boolean).join('\\n\\n');\n\n const response = await anthropicClient.messages.create(\n {\n model: params.model,\n max_tokens: params.max_tokens,\n temperature: params.temperature,\n system: system || undefined,\n messages: conversationMessages.map((m) => ({ role: m.role, content: m.content })),\n ...(tools ? { tools, tool_choice: { type: 'tool' as const, name: toolName! } } : {}),\n },\n options,\n );\n\n let text: string;\n if (toolName) {\n // Forced tool-use: the schema-conforming payload arrives as the\n // tool_use block's already-parsed `input`, not as text. Re-serialize\n // it to JSON so it flows through the same string-content contract\n // every other adapter uses (VernLLM JSON.parses the content itself).\n const toolUse = response.content.find(\n (block) => block.type === 'tool_use' && block.name === toolName,\n );\n text = toolUse ? JSON.stringify(toolUse.input) : '';\n } else {\n text = response.content.find((block) => block.type === 'text')?.text ?? '';\n }\n\n return {\n choices: [{ message: { content: text } }],\n usage: {\n prompt_tokens: response.usage?.input_tokens,\n completion_tokens: response.usage?.output_tokens,\n total_tokens:\n (response.usage?.input_tokens ?? 0) + (response.usage?.output_tokens ?? 0),\n },\n };\n },\n },\n },\n };\n}\n","import type { LLMClient } from '../types/index.js';\n\n/**\n * Minimal structural type for Geminis `generateContent`, matching both the\n * legacy `@google/generative-ai` SDKs `model.generateContent(...)` and the\n * newer `@google/genai` SDKs `ai.models.generateContent({ model, ... })`\n * closely enough to adapt either — pass whichever `.generateContent` you have.\n */\nexport interface GeminiClient {\n generateContent(\n params: {\n model?: string;\n contents: Array<{ role: 'user' | 'model'; parts: Array<{ text: string }> }>;\n systemInstruction?: { parts: Array<{ text: string }> };\n generationConfig?: {\n temperature?: number;\n maxOutputTokens?: number;\n responseMimeType?: string;\n responseSchema?: Record<string, unknown>;\n };\n },\n options: { signal: AbortSignal },\n ): Promise<{\n candidates?: Array<{ content?: { parts?: Array<{ text?: string }> } }>;\n usageMetadata?: {\n promptTokenCount?: number;\n candidatesTokenCount?: number;\n totalTokenCount?: number;\n };\n }>;\n}\n\n/**\n * Wraps a Gemini client so it satisfies the `LLMClient` interface VernLLM\n * uses for OpenAI/Groq. Geminis shape differs on nearly every axis: a\n * `contents` array instead of `messages`, a separate `systemInstruction`\n * field instead of a `system` role message, `generationConfig` instead of\n * top-level `temperature`/`max_tokens`, and native JSON Schema support via\n * `responseMimeType: 'application/json'` + `responseSchema` (so `jsonSchema`\n * is provider-enforced here, unlike the Anthropic adapters prompt-embedding\n * fallback). `reasoning_effort` has no equivalent. Geminis thinking models\n * use a token budget, not an effort tier, so its dropped, same as Anthropic.\n */\nexport function fromGemini(geminiClient: GeminiClient): LLMClient {\n return {\n chat: {\n completions: {\n async create(params, options) {\n const systemMessage = params.messages.find((m) => m.role === 'system');\n // Keep both user and assistant turns, in order. Gemini calls the\n // assistant role 'model' rather than 'assistant'.\n const conversationMessages = params.messages.filter(\n (m) => m.role === 'user' || m.role === 'assistant',\n );\n\n const wantsJson = Boolean(params.response_format);\n const generationConfig: NonNullable<\n Parameters<GeminiClient['generateContent']>[0]['generationConfig']\n > = {\n temperature: params.temperature,\n maxOutputTokens: params.max_tokens,\n };\n\n if (wantsJson) {\n generationConfig.responseMimeType = 'application/json';\n }\n if (params.response_format?.type === 'json_schema') {\n generationConfig.responseSchema = params.response_format.json_schema.schema;\n }\n\n const response = await geminiClient.generateContent(\n {\n model: params.model,\n contents: conversationMessages.map((m) => ({\n role: m.role === 'assistant' ? ('model' as const) : ('user' as const),\n parts: [{ text: m.content }],\n })),\n systemInstruction: systemMessage\n ? { parts: [{ text: systemMessage.content }] }\n : undefined,\n generationConfig,\n },\n options,\n );\n\n const text =\n response.candidates?.[0]?.content?.parts?.map((p) => p.text ?? '').join('') ?? '';\n\n return {\n choices: [{ message: { content: text } }],\n usage: {\n prompt_tokens: response.usageMetadata?.promptTokenCount,\n completion_tokens: response.usageMetadata?.candidatesTokenCount,\n total_tokens: response.usageMetadata?.totalTokenCount,\n },\n };\n },\n },\n },\n };\n}\n","import type { LLMClient } from '../types/index.js';\n\n/**\n * Minimal structural type matching AWS Bedrocks Converse API. This is\n * intentionally NOT `BedrockRuntimeClient` itself, the AWS SDK v3 client\n * exposes `.send(command)`, not a direct `.converse()` method, and pulling\n * in `@aws-sdk/client-bedrock-runtime` as a dependency just for its types\n * isn't worth it for a structural adapter. Wrap your client, e.g:\n *\n * ```ts\n * import { BedrockRuntimeClient, ConverseCommand } from '@aws-sdk/client-bedrock-runtime';\n * const client = new BedrockRuntimeClient({ region: 'us-east-1' });\n * const converseClient = {\n * converse: (params, options) =>\n * client.send(new ConverseCommand(params), { abortSignal: options.signal }),\n * };\n * ```\n */\nexport interface BedrockConverseClient {\n converse(\n params: {\n modelId: string;\n messages: Array<{ role: 'user' | 'assistant'; content: Array<{ text: string }> }>;\n system?: Array<{ text: string }>;\n inferenceConfig?: { temperature?: number; maxTokens?: number };\n toolConfig?: {\n tools: Array<{\n toolSpec: {\n name: string;\n description?: string;\n inputSchema: { json: Record<string, unknown> };\n };\n }>;\n toolChoice?: { tool: { name: string } };\n };\n },\n options: { signal: AbortSignal },\n ): Promise<{\n output?: {\n message?: {\n content?: Array<{ text?: string; toolUse?: { name?: string; input?: unknown } }>;\n };\n };\n usage?: { inputTokens?: number; outputTokens?: number; totalTokens?: number };\n }>;\n}\n\n/**\n * Wraps a Bedrock Converse-API client so it satisfies the `LLMClient`\n * interface VernLLM uses for OpenAI/Groq. The Converse API is unified\n * across Bedrocks model families (Anthropic, Titan, Llama, Mistral, etc.),\n * so unlike raw per-model Bedrock invocation, this one adapter works\n * regardless of which underlying model `modelId` points at, as long as\n * that model supports Converse (most current-generation ones do)\n *\n * `response_format: json_schema` is mapped to Converses `toolConfig`: a\n * single tool is defined from the schema and `toolChoice` forces the model\n * to call it, constraining output at generation time rather than merely\n * instructing for it via prompt text. Native tool support varies by model\n * family (most current-generation ones support it via Converse; check your\n * specific `modelId` if a call fails with an unsupported-parameter error).\n * `response_format: json_object` (no schema to build a tool from) and\n * `reasoning_effort` (no Converse equivalent) fall back to a system-prompt\n * instruction and are dropped respectively.\n */\nexport function fromBedrock(bedrockClient: BedrockConverseClient): LLMClient {\n return {\n chat: {\n completions: {\n async create(params, options) {\n const systemMessage = params.messages.find((m) => m.role === 'system');\n // Keep both user and assistant turns, in order, so conversation\n // history survives instead of collapsing to consecutive user turns.\n const conversationMessages = params.messages.filter(\n (m): m is typeof m & { role: 'user' | 'assistant' } =>\n m.role === 'user' || m.role === 'assistant',\n );\n\n const toolName =\n params.response_format?.type === 'json_schema'\n ? params.response_format.json_schema.name\n : undefined;\n\n let jsonInstruction: string | undefined;\n let toolConfig:\n | NonNullable<Parameters<BedrockConverseClient['converse']>[0]['toolConfig']>\n | undefined;\n\n if (params.response_format?.type === 'json_schema' && toolName) {\n const { schema, description } = params.response_format.json_schema;\n toolConfig = {\n tools: [{ toolSpec: { name: toolName, description, inputSchema: { json: schema } } }],\n toolChoice: { tool: { name: toolName } },\n };\n } else if (params.response_format?.type === 'json_object') {\n // No schema to build a tool from, fall back to a prompt instruction\n jsonInstruction = 'Respond with valid JSON only, no prose or markdown fences.';\n }\n\n const systemParts = [systemMessage?.content, jsonInstruction].filter((s): s is string =>\n Boolean(s),\n );\n\n const response = await bedrockClient.converse(\n {\n modelId: params.model,\n messages: conversationMessages.map((m) => ({\n role: m.role,\n content: [{ text: m.content }],\n })),\n system: systemParts.length ? systemParts.map((text) => ({ text })) : undefined,\n inferenceConfig: {\n temperature: params.temperature,\n maxTokens: params.max_tokens,\n },\n ...(toolConfig ? { toolConfig } : {}),\n },\n options,\n );\n\n let text: string;\n if (toolName) {\n // Forced tool-use: the schema-conforming payload arrives as the\n // toolUse content block's already-parsed `input`, not as text.\n // Re-serialize it to JSON so it flows through the same\n // string-content contract every other adapter uses.\n const toolUseBlock = response.output?.message?.content?.find(\n (block) => block.toolUse?.name === toolName,\n );\n text = toolUseBlock?.toolUse ? JSON.stringify(toolUseBlock.toolUse.input) : '';\n } else {\n text = response.output?.message?.content?.map((c) => c.text ?? '').join('') ?? '';\n }\n\n return {\n choices: [{ message: { content: text } }],\n usage: {\n prompt_tokens: response.usage?.inputTokens,\n completion_tokens: response.usage?.outputTokens,\n total_tokens: response.usage?.totalTokens,\n },\n };\n },\n },\n },\n };\n}\n","import type { LLMClient } from '../types/index.js';\n\n/** The chat-completion-shaped request VernLLM builds internally */\ntype ChatRequest = Parameters<LLMClient['chat']['completions']['create']>[0];\n\nexport interface FetchAdapterConfig {\n /** Endpoint URL, or a function of the request in case it depends on model/params */\n url: string | ((params: ChatRequest) => string);\n /** Static headers, or a function (sync or async) for things like refreshed auth tokens */\n headers?:\n | Record<string, string>\n | (() => Record<string, string> | Promise<Record<string, string>>);\n /** HTTP method. Default 'POST' */\n method?: string;\n /** Maps VernLLMs internal chat-completion request into the providers raw request body */\n mapRequest: (params: ChatRequest) => unknown;\n /**\n * Maps the providers raw JSON response into `{ content, usage? }`\n * `content` is the assistants text (JSON string when JSON mode was requested)\n */\n mapResponse: (json: unknown) => {\n content: string;\n usage?: { promptTokens?: number; completionTokens?: number; totalTokens?: number };\n };\n}\n\n/**\n * A fetch-based escape hatch for providers with no SDK, or where pulling one\n * in isnt worth it. You supply the URL, headers, and two small mapping\n * functions; this handles the HTTP call and slots the result into the same\n * `LLMClient` shape every other adapter produces, so retries, timeouts,\n * the circuit breaker, and JSON/schema handling all still work unmodified\n *\n * Non-2xx responses throw an error with `.status` set to the HTTP status\n * code, so VernLLMs `nonRetryableStatus` handling (e.g. failing fast on\n * 401/403) applies here too\n */\nexport function fromFetch(config: FetchAdapterConfig): LLMClient {\n return {\n chat: {\n completions: {\n async create(params, options) {\n const url = typeof config.url === 'function' ? config.url(params) : config.url;\n const headers =\n typeof config.headers === 'function' ? await config.headers() : config.headers;\n\n const res = await fetch(url, {\n method: config.method ?? 'POST',\n headers: { 'Content-Type': 'application/json', ...headers },\n body: JSON.stringify(config.mapRequest(params)),\n signal: options.signal,\n });\n\n if (!res.ok) {\n const body = await res.text().catch(() => '');\n const err = new Error(\n `Fetch adapter request failed (${res.status}): ${body.slice(0, 500)}`,\n ) as Error & { status?: number };\n err.status = res.status;\n throw err;\n }\n\n const json = await res.json();\n const { content, usage } = config.mapResponse(json);\n\n return {\n choices: [{ message: { content } }],\n usage: usage\n ? {\n prompt_tokens: usage.promptTokens,\n completion_tokens: usage.completionTokens,\n total_tokens: usage.totalTokens,\n }\n : undefined,\n };\n },\n },\n },\n };\n}\n","import type { LLMClient } from '../types/index.js';\n\n/**\n * Passthrough adapter for any SDK/client whose `chat.completions.create`\n * already matches the OpenAI wire format 1:1 : this covers most hosted\n * inference providers, since \"OpenAI-compatible\" is a de facto standard for\n * chat completion APIs. No transformation happens here, this exists purely\n * so call sites read clearly (`fromMistral(client)` vs handing a Mistral\n * client to something typed for OpenAI) and so a real transformation could\n * be added later, per-provider, without a breaking change.\n *\n * Not every SDKs own TypeScript types line up exactly with `LLMClient`\n * (extra fields, stricter unions, etc.), so this takes `unknown` and casts:\n * the actual compatibility contract is the JSON each provider sends and\n * receives over the wire, not the SDKs TS types.\n */\nexport function fromOpenAICompatible(client: unknown): LLMClient {\n return client as LLMClient;\n}\n\n/** Groqs SDK matches the OpenAI wire format */\nexport const fromGroq = fromOpenAICompatible;\n\n/** Mistrals `chat.completions`-shaped client (or their OpenAI-compat endpoint) */\nexport const fromMistral = fromOpenAICompatible;\n\n/** DeepSeeks API is OpenAI-compatible */\nexport const fromDeepSeek = fromOpenAICompatible;\n\n/** Cerebras inference API is OpenAI-compatible */\nexport const fromCerebras = fromOpenAICompatible;\n\n/** Together AIs API is OpenAI-compatible */\nexport const fromTogether = fromOpenAICompatible;\n\n/** Fireworks AIs API is OpenAI-compatible */\nexport const fromFireworks = fromOpenAICompatible;\n\n/**\n * Ollama exposes an OpenAI-compatible endpoint at `/v1/chat/completions`\n * (as opposed to its native `/api/chat` format, which differs). Point an\n * OpenAI SDK instances `baseURL` at your Ollama server and pass it here:\n * this does not talk to Ollamas native API directly.\n */\nexport const fromOllama = fromOpenAICompatible;\n\n/** OpenRouter's API is OpenAI-compatible */\nexport const fromOpenRouter = fromOpenAICompatible;\n\n/** Perplexity's API is OpenAI-compatible */\nexport const fromPerplexity = fromOpenAICompatible;\n\n/** DeepInfra's API is OpenAI-compatible */\nexport const fromDeepInfra = fromOpenAICompatible;\n\n/** Novita's API is OpenAI-compatible */\nexport const fromNovita = fromOpenAICompatible;\n\n/** Hyperbolic's API is OpenAI-compatible */\nexport const fromHyperbolic = fromOpenAICompatible;\n\n/** Moonshot's (Kimi) API is OpenAI-compatible */\nexport const fromMoonshot = fromOpenAICompatible;\n\n/** Zhipu's (GLM) API is OpenAI-compatible */\nexport const fromZhipu = fromOpenAICompatible;\n\n/**\n * LM Studio exposes an OpenAI-compatible endpoint at `/v1/chat/completions`.\n * Point an OpenAI SDK instance's `baseURL` at your local LM Studio server.\n */\nexport const fromLMStudio = fromOpenAICompatible;\n\n/**\n * vLLM's OpenAI-compatible server mode exposes `/v1/chat/completions`.\n * Point an OpenAI SDK instance's `baseURL` at your vLLM server.\n */\nexport const fromVLLM = fromOpenAICompatible;\n\n/** xAI's Grok API is OpenAI-compatible */\nexport const fromXAI = fromOpenAICompatible;\n\n/** NVIDIA NIM's hosted and self-hosted endpoints are OpenAI-compatible */\nexport const fromNvidiaNIM = fromOpenAICompatible;\n\n/** Vercel AI Gateway is OpenAI-compatible */\nexport const fromVercelAIGateway = fromOpenAICompatible;\n\n/** Cloudflare Workers AI exposes an OpenAI-compatible endpoint */\nexport const fromCloudflareWorkersAI = fromOpenAICompatible;\n\n/** GitHub Models is OpenAI-compatible */\nexport const fromGitHubModels = fromOpenAICompatible;\n\n/** Nebius AI Studio is OpenAI-compatible */\nexport const fromNebius = fromOpenAICompatible;\n\n/** SambaNova Cloud's API is OpenAI-compatible */\nexport const fromSambaNova = fromOpenAICompatible;\n\n/** Baseten's model hosting exposes an OpenAI-compatible endpoint */\nexport const fromBaseten = fromOpenAICompatible;\n\n/** Featherless AI's API is OpenAI-compatible */\nexport const fromFeatherless = fromOpenAICompatible;\n\n/** Friendli AI's serving endpoint is OpenAI-compatible */\nexport const fromFriendli = fromOpenAICompatible;\n\n/** SiliconFlow's API is OpenAI-compatible */\nexport const fromSiliconFlow = fromOpenAICompatible;\n\n/** Parasail's inference API is OpenAI-compatible */\nexport const fromParasail = fromOpenAICompatible;\n\n/** StepFun's API is OpenAI-compatible */\nexport const fromStepFun = fromOpenAICompatible;\n\n/** MiniMax's API is OpenAI-compatible */\nexport const fromMiniMax = fromOpenAICompatible;\n\n/** Lambda Labs' Inference API is OpenAI-compatible */\nexport const fromLambdaLabs = fromOpenAICompatible;\n\n/** Snowflake Cortex's LLM endpoint is OpenAI-compatible */\nexport const fromSnowflakeCortex = fromOpenAICompatible;\n\n/** Anyscale Endpoints' API is OpenAI-compatible */\nexport const fromAnyscale = fromOpenAICompatible;\n\n/** Lepton AI's inference API is OpenAI-compatible */\nexport const fromLepton = fromOpenAICompatible;\n\n/** kluster.ai's inference API is OpenAI-compatible */\nexport const fromKlusterAI = fromOpenAICompatible;\n\n/** Inference.net's API is OpenAI-compatible */\nexport const fromInferenceNet = fromOpenAICompatible;\n\n/** Infermatic's API is OpenAI-compatible */\nexport const fromInfermatic = fromOpenAICompatible;\n\n/** AtlasCloud's inference API is OpenAI-compatible */\nexport const fromAtlasCloud = fromOpenAICompatible;\n\n/** 01.AI's (Yi models) API is OpenAI-compatible */\nexport const from01AI = fromOpenAICompatible;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,IAAa,WAAb,cAA8B,MAAM;CAClC,YACEA,SACOC,MACAC,QACAC,QACP;AACA,QAAM,QAAQ;EAQjB,KAZU;EAYT,KAXS;EA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mBAAmB;;AAGhC,MAAa,aAAa;;AAG1B,MAAa,gBAAgB;;AAG7B,MAAa,cAAc;;AAG3B,MAAa,kBAAkB;;AAG/B,MAAa,eAAe;;AAG5B,MAAa,kBAAkB;;AAG/B,MAAa,eAAe;;AAG5B,MAAa,cAAc;;AAG3B,MAAa,cAAc;;AAG3B,MAAa,iBAAiB;;AAG9B,MAAa,sBAAsB;;AAGnC,MAAa,eAAe;;AAG5B,MAAa,aAAa;;AAG1B,MAAa,gBAAgB;;AAG7B,MAAa,mBAAmB;;AAGhC,MAAa,iBAAiB;;AAG9B,MAAa,iBAAiB;;AAG9B,MAAa,WAAW"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["message: string","type: LLMErrorType","status?: number","issues?: unknown","err: unknown","options: CircuitBreakerOptions","content: string","err: unknown","fn: (signal: AbortSignal) => Promise<T>","timeoutMs: number","externalSignal?: AbortSignal","baseDelayMs: number","attempt: number","delay: number","signal?: AbortSignal","debugEnabled: boolean","message: string","meta?: Record<string, unknown>","key: string","value: T","ttl: number","options: VernLLMOptions","params: CallParams<T>","fn: () => Promise<T>","requestId: string","signal?: AbortSignal","lastError: unknown","error: unknown","history: ConversationTurn[]","previousRole: 'user' | 'assistant' | undefined","jsonSchema: CallParams<unknown>['jsonSchema']","useJson: boolean","response: Awaited<ReturnType<LLMClient['chat']['completions']['create']>>","model: string","content: string","schema?: CallParams<T>['schema']","parsed: unknown","attempt: number","key: string","params: CachedCallParams<T>","params: Omit<CachedCallParams<T>, 'fn'> & { call: CallParams<T> }","anthropicClient: AnthropicClient","jsonInstruction: string | undefined","tools:\n | NonNullable<Parameters<AnthropicClient['messages']['create']>[0]['tools']>\n | undefined","text: string","geminiClient: GeminiClient","generationConfig: NonNullable<\n Parameters<GeminiClient['generateContent']>[0]['generationConfig']\n >","bedrockClient: BedrockConverseClient","jsonInstruction: string | undefined","toolConfig:\n | NonNullable<Parameters<BedrockConverseClient['converse']>[0]['toolConfig']>\n | undefined","text","text: string","config: FetchAdapterConfig","client: unknown"],"sources":["../src/types/errors.ts","../src/circuitBreaker.ts","../src/internal/vernLLM.utils.ts","../src/logger.ts","../src/types/cache.ts","../src/vernLLM.ts","../src/adapters/anthropic.ts","../src/adapters/gemini.ts","../src/adapters/bedrock.ts","../src/adapters/fetch.ts","../src/adapters/openaiCompatible.ts"],"sourcesContent":["export type LLMErrorType =\n | 'timeout'\n | 'api'\n | 'parse'\n | 'validation'\n | 'circuit_open'\n | 'unknown'\n | 'aborted';\n\nexport class LLMError extends Error {\n constructor(\n message: string,\n public type: LLMErrorType,\n public status?: number,\n public issues?: unknown,\n ) {\n super(message);\n this.name = 'LLMError';\n }\n}\n\nexport function isLLMError(err: unknown): err is LLMError {\n return err instanceof LLMError;\n}\n","import { LLMError } from './types/errors.js';\n\nexport interface CircuitBreakerOptions {\n /** Consecutive failures before the circuit opens, default 5 */\n threshold?: number;\n /** How long the circuit stays open before allowing a trial request, in ms. Default 30000 */\n cooldownMs?: number;\n}\n\ntype CircuitState = 'closed' | 'open' | 'half-open';\n\n/**\n * Per retry VernLLM-instance circuit breaker. Tracks consecutive failures across\n * calls. Once the threshold is hit, short-circuits new calls with an\n * LLMError('circuit_open') instead of hitting the provider, until the\n * cooldown elapses and a single trial call is allowed through\n */\nexport class CircuitBreaker {\n private state: CircuitState = 'closed';\n private consecutiveFailures = 0;\n private openedAt = 0;\n private threshold: number;\n private cooldownMs: number;\n\n constructor(options: CircuitBreakerOptions = {}) {\n this.threshold = options.threshold ?? 5;\n this.cooldownMs = options.cooldownMs ?? 30_000;\n }\n\n /** Throws if the circuit is open and the cooldown hasnt elapsed */\n assertClosed(): void {\n if (this.state !== 'open') return;\n\n const elapsed = Date.now() - this.openedAt;\n if (elapsed >= this.cooldownMs) {\n this.state = 'half-open';\n return;\n }\n\n throw new LLMError(\n `Circuit open — provider has failed ${this.consecutiveFailures} times in a row. Retry in ${Math.ceil((this.cooldownMs - elapsed) / 1000)}s.`,\n 'circuit_open',\n );\n }\n\n recordSuccess(): void {\n this.consecutiveFailures = 0;\n this.state = 'closed';\n }\n\n recordFailure(): void {\n this.consecutiveFailures += 1;\n\n if (this.state === 'half-open') {\n // Trial call failed: reopen and reset the cooldown window.\n this.state = 'open';\n this.openedAt = Date.now();\n return;\n }\n\n if (this.consecutiveFailures >= this.threshold) {\n this.state = 'open';\n this.openedAt = Date.now();\n }\n }\n\n getState(): CircuitState {\n return this.state;\n }\n}\n","import { LLMError } from '../types/errors.js';\n\nexport function defaultParseJson(content: string): unknown {\n try {\n return JSON.parse(content);\n } catch {\n return undefined;\n }\n}\n\n/**\n * Looks inside an unknown error value and pulls out an http status code\n * if one is present. Checks the status field first then the status code\n * field since different client libraries use different names for this.\n * Returns undefined when the error is not an object or carries no status\n */\nexport function extractStatus(err: unknown): number | undefined {\n if (!err || typeof err !== 'object') return undefined;\n\n const error = err as {\n status?: unknown;\n statusCode?: unknown;\n };\n\n if (typeof error.status === 'number') return error.status;\n if (typeof error.statusCode === 'number') return error.statusCode;\n\n return undefined;\n}\n\n/**\n * Runs an async function and cancels it if it takes longer than the given\n * timeout. Creates an internal abort controller that fires after the\n * timeout elapses, and combines it with any external signal the caller\n * passed in so either one can cancel the underlying call. If the internal\n * timeout triggers and the underlying operation aborts, the error is\n * converted into an LLMError with type \"timeout\". External cancellations\n * continue to propagate as aborted errors. The internal timer is always\n * cleared afterward, whether the function succeeds, fails, or is aborted,\n * so nothing is left running in the background.\n */\nexport async function withTimeout<T>(\n fn: (signal: AbortSignal) => Promise<T>,\n timeoutMs: number,\n externalSignal?: AbortSignal,\n): Promise<T> {\n const controller = new AbortController();\n\n const timer = setTimeout(() => {\n controller.abort();\n }, timeoutMs);\n\n const signal = externalSignal\n ? AbortSignal.any([externalSignal, controller.signal])\n : controller.signal;\n\n try {\n return await fn(signal);\n } catch (err) {\n if (\n controller.signal.aborted &&\n !externalSignal?.aborted &&\n err instanceof DOMException &&\n err.name === 'AbortError'\n ) {\n throw new LLMError('Request timed out', 'timeout');\n }\n\n throw err;\n } finally {\n clearTimeout(timer);\n }\n}\n\n/**\n * Exponential backoff with jitter, capped at maxDelayMs.\n * Jitter avoids thundering-herd retries when many callers back off in lockstep,\n * the cap prevents unbounded delays when maxRetries is high\n */\nexport function getBackoffDelay(baseDelayMs: number, attempt: number, maxDelayMs = 10_000): number {\n const exp = Math.min(baseDelayMs * 2 ** attempt, maxDelayMs);\n return exp / 2 + Math.random() * (exp / 2);\n}\n\n/**\n * Pauses execution for the given delay before a retry attempt. If an\n * abort signal is provided and it fires while waiting, the pending\n * timer is cancelled immediately and the wait rejects right away with\n * an aborted error instead of continuing to sit idle until the delay\n * would have finished on its own\n */\nexport async function waitForRetry(delay: number, signal?: AbortSignal): Promise<void> {\n await new Promise<void>((resolve, reject) => {\n const onAbort = () => {\n clearTimeout(timer);\n reject(new LLMError('Operation aborted', 'aborted'));\n };\n\n const timer = setTimeout(() => {\n signal?.removeEventListener('abort', onAbort);\n resolve();\n }, delay);\n\n signal?.addEventListener('abort', onAbort, { once: true });\n });\n}\n","export interface Logger {\n debug(message: string): void;\n warn(message: string): void;\n error(message: string, meta?: Record<string, unknown>): void;\n}\n\n/**\n * Default logger. `debug` is gated by the `debug` option on VernLLM\n * warn/error always fire since they indicate real problems (retries, cache failures)\n */\nexport class ConsoleLogger implements Logger {\n constructor(private debugEnabled: boolean) {}\n\n debug(message: string): void {\n if (this.debugEnabled) console.debug(message);\n }\n\n warn(message: string): void {\n console.warn(message);\n }\n\n error(message: string, meta?: Record<string, unknown>): void {\n console.error(message, meta ?? '');\n }\n}\n","export interface CacheAdapter<T = unknown> {\n get(key: string): Promise<{ hit: boolean; value: T | null }>;\n set(key: string, value: T, ttl: number): Promise<void>;\n delete?(key: string): Promise<void>;\n}\n\n/**\n * Trivial default so the package works out of the box with no external deps\n * Not shared across processes, swap in Redis/Upstash/etc for production\n */\nexport class InMemoryCacheAdapter<T = unknown> implements CacheAdapter<T> {\n private store = new Map<string, { value: T; expiresAt: number }>();\n\n constructor(private readonly maxSize = 1000) {}\n\n async get(key: string): Promise<{ hit: boolean; value: T | null }> {\n const entry = this.store.get(key);\n\n if (!entry) return { hit: false, value: null };\n\n if (Date.now() >= entry.expiresAt) {\n this.store.delete(key);\n return { hit: false, value: null };\n }\n\n return { hit: true, value: entry.value };\n }\n\n async set(key: string, value: T, ttl: number): Promise<void> {\n this.cleanupExpiredEntries();\n\n this.store.set(key, {\n value,\n expiresAt: Date.now() + ttl * 1000,\n });\n\n this.enforceSizeLimit();\n }\n\n async delete(key: string): Promise<void> {\n this.store.delete(key);\n }\n\n private cleanupExpiredEntries(): void {\n const now = Date.now();\n\n for (const [key, entry] of this.store) {\n if (now >= entry.expiresAt) {\n this.store.delete(key);\n }\n }\n }\n\n private enforceSizeLimit(): void {\n while (this.store.size > this.maxSize) {\n const oldestKey = this.store.keys().next().value;\n\n if (oldestKey === undefined) break;\n\n this.store.delete(oldestKey);\n }\n }\n}\n","import { randomUUID } from 'crypto';\n\nimport { CircuitBreaker } from './circuitBreaker.js';\nimport {\n defaultParseJson,\n extractStatus,\n withTimeout,\n getBackoffDelay,\n waitForRetry,\n} from './internal/vernLLM.utils.js';\nimport { ConsoleLogger, type Logger } from './logger.js';\nimport {\n InMemoryCacheAdapter,\n LLMError,\n type CacheAdapter,\n type CachedCallParams,\n type CallParams,\n type ConversationTurn,\n type LLMClient,\n type VernLLMOptions,\n} from './types/index.js';\n\n/**\n * A resilient wrapper around an LLM chat completions client, this is VernLLM!\n *\n * Adds retry with exponential backoff and jitter, per-attempt timeouts,\n * an optional circuit breaker, JSON parsing with optional schema\n * validation, usage tracking, and an optional response cache, all\n * configurable, all opt-in beyond sensible defaults\n */\nexport class VernLLM {\n private readonly client: LLMClient;\n private readonly model: string;\n\n private readonly maxRetries: number;\n private readonly timeoutMs: number;\n private readonly baseDelayMs: number;\n private readonly defaultMaxTokens: number;\n\n private readonly cache: CacheAdapter<unknown>;\n private readonly nonRetryableStatus: number[];\n\n private readonly parseJson: (content: string) => unknown;\n private readonly onUsage?: VernLLMOptions['onUsage'];\n\n private readonly logger: Logger;\n private readonly breaker?: CircuitBreaker;\n\n /**\n * @param options: Client, model, and all tunables (retries, timeout,\n * backoff, cache, circuit breaker, logger, etc). See VernLLMOptions in `types.ts`\n * for individual defaults\n */\n constructor(options: VernLLMOptions) {\n this.client = options.client;\n this.model = options.model;\n\n const retryConfig = this.resolveRetryConfig(options);\n this.maxRetries = retryConfig.maxRetries;\n this.timeoutMs = retryConfig.timeoutMs;\n this.baseDelayMs = retryConfig.baseDelayMs;\n this.defaultMaxTokens = retryConfig.defaultMaxTokens;\n\n this.cache = options.cache ?? new InMemoryCacheAdapter();\n this.nonRetryableStatus = options.nonRetryableStatus ?? [400, 401, 403, 404, 422];\n\n this.parseJson = options.parseJson ?? defaultParseJson;\n this.onUsage = options.onUsage;\n\n this.logger = this.resolveLogger(options);\n this.breaker = this.resolveCircuitBreaker(options);\n }\n\n /**\n * Resolves retry/timeout/token defaults from the given options,\n * falling back to the librarys built-in defaults for anything unset\n */\n private resolveRetryConfig(options: VernLLMOptions) {\n return {\n maxRetries: options.maxRetries ?? 1,\n timeoutMs: options.timeoutMs ?? 25_000,\n baseDelayMs: options.baseDelayMs ?? 500,\n defaultMaxTokens: options.defaultMaxTokens ?? 1000,\n };\n }\n\n /**\n * Returns the caller supplied logger, or a console-based logger whose\n * debug output is gated by the `debug` option (defaulting to off,\n * so response content isn't unintentionally written to logs)\n */\n private resolveLogger(options: VernLLMOptions): Logger {\n return options.logger ?? new ConsoleLogger(options.debug ?? false);\n }\n\n /**\n * Builds a circuit breaker if `circuitBreaker` is truthy on the\n * options. Passing `true` uses default thresholds, passing an options\n * object tunes them. Returns undefined when the breaker is disabled\n */\n private resolveCircuitBreaker(options: VernLLMOptions): CircuitBreaker | undefined {\n if (!options.circuitBreaker) return undefined;\n\n return new CircuitBreaker(options.circuitBreaker === true ? undefined : options.circuitBreaker);\n }\n\n /**\n * Makes a single logical LLM call, transparently retrying on failure\n * according to the configured retry policy\n *\n * Fails fast if the circuit breaker is open or the signal is already\n * aborted, before any request is dispatched. On exhausting all\n * retries, records a circuit breaker failure and rejects with a\n * normalized LLMError\n *\n * @param params : System/user content plus per call overrides\n * (model, temperature, jsonMode, schema, signal, etc)\n * @returns The parsed and optionally schema-validated response, or\n * the raw string content when jsonMode is disabled\n */\n async call<T = unknown>(params: CallParams<T>): Promise<T> {\n this.breaker?.assertClosed();\n\n if (params.signal?.aborted) {\n throw new LLMError('LLM request aborted', 'aborted');\n }\n\n const requestId = params.requestId ?? randomUUID();\n\n try {\n const result = await this.retryWithBackoff(\n () => this.executeCall(params, requestId),\n requestId,\n params.signal,\n );\n\n return result;\n } catch (error) {\n this.breaker?.recordFailure();\n throw this.normalizeError(error, params.signal);\n }\n }\n\n /**\n * Runs `fn`, retrying with backoff according to `shouldRetry` policy\n * Purely mechanical: knows nothing about LLM specifics beyond the retry\n * predicate, so its testable independent of request/response shaping\n */\n private async retryWithBackoff<T>(\n fn: () => Promise<T>,\n requestId: string,\n signal?: AbortSignal,\n ): Promise<T> {\n let lastError: unknown;\n\n for (let attempt = 0; attempt <= this.maxRetries; attempt++) {\n try {\n if (attempt > 0) {\n await this.recoverDelay(requestId, attempt, signal);\n }\n\n return await fn();\n } catch (error) {\n lastError = error;\n\n if (!this.shouldRetry(error, signal)) {\n break;\n }\n }\n }\n\n throw lastError;\n }\n\n /**\n * Converts any thrown value into a well-typed LLMError for the public\n * API surface. Preserves an existing LLMError as is, reports aborted\n * signals as such, classifies errors carrying an http status as\n * type api, and otherwise falls back to a generic unknown error.\n */\n private normalizeError(error: unknown, signal?: AbortSignal): LLMError {\n if (signal?.aborted) {\n return new LLMError('LLM request aborted', 'aborted');\n }\n\n if (error instanceof LLMError) {\n return error;\n }\n\n const status = extractStatus(error);\n\n if (status !== undefined) {\n return new LLMError('LLM request failed', 'api', status);\n }\n\n return new LLMError('LLM request failed', 'unknown');\n }\n\n /**\n * Performs a single attempt: builds the request, dispatches it with a\n * timeout, and shapes the response. Throws on an empty response so\n * the retry loop treats it like any other transient failure. Records\n * usage and a circuit breaker success before returning\n */\n private async executeCall<T>(params: CallParams<T>, requestId: string): Promise<T> {\n const { useJson, model, request } = this.buildRequestPayload(params);\n\n const response = await withTimeout(\n (attemptSignal) => this.client.chat.completions.create(request, { signal: attemptSignal }),\n this.timeoutMs,\n params.signal,\n );\n\n const content = response.choices?.[0]?.message?.content?.trim();\n\n if (!content) {\n throw new LLMError('Empty LLM response', 'api');\n }\n\n this.logger.debug(`[vern:${requestId}] output:\\n${content.slice(0, 800)}`);\n\n this.recordUsage(response, requestId, model);\n\n this.breaker?.recordSuccess();\n\n if (!useJson) {\n return content as T;\n }\n\n return this.parseAndValidate(content, params.schema);\n }\n\n /**\n * Anthropic and Gemini both require strict user/assistant alternation\n * (and reject or silently mishandle two consecutive same-role turns), so\n * this validates `history` up front rather than letting a malformed\n * request surface as a confusing provider-side error. Thrown as a\n * validation LLMError, which `shouldRetry` never retries, since retrying\n * the same malformed input can't succeed\n */\n private validateHistory(history: ConversationTurn[]): void {\n let previousRole: 'user' | 'assistant' | undefined;\n\n for (const [index, turn] of history.entries()) {\n if (turn.role !== 'user' && turn.role !== 'assistant') {\n throw new LLMError(\n `Invalid history[${index}].role \"${turn.role}\": must be \"user\" or \"assistant\"`,\n 'validation',\n );\n }\n\n if (turn.role === previousRole) {\n throw new LLMError(\n `history must alternate user/assistant turns: consecutive \"${turn.role}\" turns at history[${index - 1}] and history[${index}]`,\n 'validation',\n );\n }\n\n previousRole = turn.role;\n }\n\n if (previousRole === 'user') {\n throw new LLMError(\n 'The last entry in history is a \"user\" turn, which would collide with the current userContent turn. history must end with an \"assistant\" turn (or be empty).',\n 'validation',\n );\n }\n }\n\n /**\n * Applies per call defaults and shapes the params into the request\n * object expected by the underlying client, including the resolved\n * response format. Also returns whether JSON parsing should be\n * applied to the response and which model was ultimately used\n */\n private buildRequestPayload<T>(params: CallParams<T>) {\n const {\n systemPrompt,\n userContent,\n history = [],\n temperature = 0.2,\n jsonMode = true,\n maxTokens = this.defaultMaxTokens,\n model = this.model,\n reasoningEffort,\n jsonSchema,\n } = params;\n\n const useJson = jsonMode || Boolean(jsonSchema);\n const responseFormat = this.buildResponseFormat(jsonSchema, useJson);\n\n this.validateHistory(history);\n\n const request = {\n model,\n temperature,\n max_tokens: maxTokens,\n ...(responseFormat ? { response_format: responseFormat } : {}),\n ...(reasoningEffort ? { reasoning_effort: reasoningEffort } : {}),\n messages: [\n ...(systemPrompt ? [{ role: 'system' as const, content: systemPrompt }] : []),\n ...history.map((turn) => ({ role: turn.role, content: turn.content })),\n { role: 'user' as const, content: userContent },\n ],\n };\n\n return { useJson, model, request };\n }\n\n /**\n * Chooses the response format to send to the provider. A provider\n * native json schema takes priority when supplied, constraining\n * generation directly, otherwise falls back to the looser json\n * object mode when JSON output is requested, or no format at all\n * for plain text responses\n */\n private buildResponseFormat(jsonSchema: CallParams<unknown>['jsonSchema'], useJson: boolean) {\n if (jsonSchema) {\n return {\n type: 'json_schema' as const,\n json_schema: {\n name: jsonSchema.name,\n schema: jsonSchema.schema,\n strict: jsonSchema.strict ?? true,\n description: jsonSchema.description,\n },\n };\n }\n\n return useJson ? { type: 'json_object' as const } : undefined;\n }\n\n /**\n * Reports token usage to the caller supplied onUsage callback, when\n * both a callback was configured and the provider actually returned\n * usage data on this response. A no op otherwise.\n */\n private recordUsage(\n response: Awaited<ReturnType<LLMClient['chat']['completions']['create']>>,\n requestId: string,\n model: string,\n ): void {\n if (!response.usage || !this.onUsage) return;\n\n this.onUsage({\n promptTokens: response.usage.prompt_tokens ?? 0,\n completionTokens: response.usage.completion_tokens ?? 0,\n totalTokens: response.usage.total_tokens ?? 0,\n requestId,\n model,\n });\n }\n\n /**\n * Parses the raw response content as JSON and, when a schema is\n * supplied, validates the parsed value against it. Throws a parse\n * type LLMError on malformed JSON and a validation type LLMError,\n * carrying the schemas issues, on a failed validation\n */\n private parseAndValidate<T>(content: string, schema?: CallParams<T>['schema']): T {\n let parsed: unknown;\n\n try {\n parsed = this.parseJson(content);\n } catch {\n throw new LLMError('Invalid JSON response', 'parse');\n }\n\n if (parsed === null || parsed === undefined) {\n throw new LLMError('Invalid JSON response', 'parse');\n }\n\n if (!schema) {\n return parsed as T;\n }\n\n const result = schema.safeParse(parsed);\n\n if (!result.success) {\n throw new LLMError('Schema validation failed', 'validation', undefined, result.error);\n }\n\n return result.data;\n }\n\n /**\n * Waits out the backoff delay for a given retry attempt, logging the\n * attempt for observability before the wait begins. Rejects early if\n * the signal aborts during the wait\n */\n private async recoverDelay(requestId: string, attempt: number, signal?: AbortSignal) {\n const delay = getBackoffDelay(this.baseDelayMs, attempt);\n\n this.logger.warn(\n `[vern:${requestId}] recovery attempt ${attempt}/${this.maxRetries}, waiting ${delay}ms`,\n );\n\n await waitForRetry(delay, signal);\n }\n\n /**\n * Decides whether a failed attempt is worth retrying. Never retries\n * once the signal has aborted, never retries a parse or validation\n * failure since those stem from the response content rather than a\n * transient fault, and never retries a status code the caller has\n * marked as non retryable. Retries everything else\n */\n private shouldRetry(error: unknown, signal?: AbortSignal): boolean {\n if (signal?.aborted) {\n return false;\n }\n\n if (error instanceof LLMError && (error.type === 'parse' || error.type === 'validation')) {\n return false;\n }\n\n const status = extractStatus(error);\n\n if (status !== undefined && this.nonRetryableStatus.includes(status)) {\n return false;\n }\n\n return true;\n }\n\n /**\n * Removes a cached response by key when the configured cache adapter\n * supports deletion.\n *\n * Cache invalidation remains the responsibility of the caller because\n * only the application knows when cached data is stale.\n */\n async deleteCache(key: string): Promise<void> {\n if (!this.cache.delete) {\n return;\n }\n\n await this.cache.delete(key);\n }\n\n /**\n * Thin cache wrapper around caller supplied logic. `params.fn` is expected\n * to be a call that itself invokes `this.call(...)` (see `cachedLLMCall`\n * below for a convenience wrapper that wires this up automatically),\n * `cachedCall` does not itself apply retry/timeout policy.\n */\n async cachedCall<T>(params: CachedCallParams<T>): Promise<T> {\n const cached = await this.cache.get(params.cacheKey);\n\n if (cached.hit) {\n return cached.value as T;\n }\n\n try {\n await params.reserveUsage?.();\n\n const result = await params.fn();\n\n try {\n await this.cache.set(params.cacheKey, result, params.ttl);\n } catch (error) {\n this.logger.error('[VernLLM] cache write failed', {\n message: error instanceof Error ? error.message : 'unknown',\n });\n }\n\n return result;\n } catch (error) {\n try {\n await params.refundUsage?.();\n } catch (refundError) {\n this.logger.error('[VernLLM] refundUsage failed', {\n message: refundError instanceof Error ? refundError.message : 'unknown',\n });\n }\n\n throw error;\n }\n }\n\n /**\n * Convenience wrapper composing `call` + `cachedCall`, so cached LLM calls\n * automatically get retry/timeout/circuit-breaker behavior without callers\n * having to remember to wire `fn: () => this.call(...)` themselves\n */\n async cachedLLMCall<T>(\n params: Omit<CachedCallParams<T>, 'fn'> & { call: CallParams<T> },\n ): Promise<T> {\n const { call: callParams, ...cacheParams } = params;\n\n return this.cachedCall({\n ...cacheParams,\n fn: () => this.call(callParams),\n });\n }\n\n /**\n * Returns the current circuit breaker state, or undefined when no\n * circuit breaker was configured on this instance\n */\n getCircuitState() {\n return this.breaker?.getState();\n }\n}\n","import type { LLMClient } from '../types/index.js';\n\n/** Minimal structural type for the Anthropic SDKs `messages.create` */\nexport interface AnthropicClient {\n messages: {\n create(\n params: {\n model: string;\n max_tokens: number;\n temperature?: number;\n system?: string;\n messages: Array<{ role: 'user' | 'assistant'; content: string }>;\n tools?: Array<{\n name: string;\n description?: string;\n input_schema: Record<string, unknown>;\n }>;\n tool_choice?: { type: 'tool'; name: string };\n },\n options: { signal: AbortSignal },\n ): Promise<{\n content: Array<{ type: string; text?: string; name?: string; input?: unknown }>;\n usage?: { input_tokens?: number; output_tokens?: number };\n }>;\n };\n}\n\n/**\n * Wraps an Anthropic SDK client so it satisfies the same `LLMClient`\n * interface VernLLM uses for OpenAI/Groq.\n *\n * `response_format: json_schema` is mapped to Anthropics forced tool-use:\n * a single tool is defined with `input_schema` set to the caller's schema,\n * and `tool_choice` forces the model to call it, so the output is\n * provider-constrained to match the schema rather than merely instructed\n * to via prompt text (the same guarantee OpenAIs native `json_schema` mode\n * gives, built on Anthropics tool-calling primitive instead).\n *\n * `response_format: json_object` (no schema to build a tool from) falls\n * back to a system-prompt instruction, since theres nothing to constrain\n * generation against.\n */\nexport function fromAnthropic(anthropicClient: AnthropicClient): LLMClient {\n return {\n chat: {\n completions: {\n async create(params, options) {\n const systemMessage = params.messages.find((m) => m.role === 'system');\n // Keep both user and assistant turns, in order, so multi-turn history\n // survives instead of collapsing to consecutive user messages.\n const conversationMessages = params.messages.filter(\n (m): m is typeof m & { role: 'user' | 'assistant' } =>\n m.role === 'user' || m.role === 'assistant',\n );\n\n const toolName =\n params.response_format?.type === 'json_schema'\n ? params.response_format.json_schema.name\n : undefined;\n\n let jsonInstruction: string | undefined;\n let tools:\n | NonNullable<Parameters<AnthropicClient['messages']['create']>[0]['tools']>\n | undefined;\n\n if (params.response_format?.type === 'json_schema' && toolName) {\n const { schema, description } = params.response_format.json_schema;\n tools = [{ name: toolName, description, input_schema: schema }];\n } else if (params.response_format?.type === 'json_object') {\n // No schema to build a tool from, fall back to a prompt instruction\n jsonInstruction = 'Respond with valid JSON only, no prose or markdown fences.';\n }\n\n // `reasoning_effort` (OpenAI o-series/gpt-5 style) has no direct Anthropic\n // equivalent, Claudes extended thinking uses a token budget, not a tier\n // string, so its intentionally dropped here rather than guessed at.\n\n const system = [systemMessage?.content, jsonInstruction].filter(Boolean).join('\\n\\n');\n\n const response = await anthropicClient.messages.create(\n {\n model: params.model,\n max_tokens: params.max_tokens,\n temperature: params.temperature,\n system: system || undefined,\n messages: conversationMessages.map((m) => ({ role: m.role, content: m.content })),\n ...(tools ? { tools, tool_choice: { type: 'tool' as const, name: toolName! } } : {}),\n },\n options,\n );\n\n let text: string;\n if (toolName) {\n // Forced tool-use: the schema-conforming payload arrives as the\n // tool_use block's already-parsed `input`, not as text. Re-serialize\n // it to JSON so it flows through the same string-content contract\n // every other adapter uses (VernLLM JSON.parses the content itself).\n const toolUse = response.content.find(\n (block) => block.type === 'tool_use' && block.name === toolName,\n );\n text = toolUse ? JSON.stringify(toolUse.input) : '';\n } else {\n text = response.content.find((block) => block.type === 'text')?.text ?? '';\n }\n\n return {\n choices: [{ message: { content: text } }],\n usage: {\n prompt_tokens: response.usage?.input_tokens,\n completion_tokens: response.usage?.output_tokens,\n total_tokens:\n (response.usage?.input_tokens ?? 0) + (response.usage?.output_tokens ?? 0),\n },\n };\n },\n },\n },\n };\n}\n","import type { LLMClient } from '../types/index.js';\n\n/**\n * Minimal structural type for Geminis `generateContent`, matching both the\n * legacy `@google/generative-ai` SDKs `model.generateContent(...)` and the\n * newer `@google/genai` SDKs `ai.models.generateContent({ model, ... })`\n * closely enough to adapt either — pass whichever `.generateContent` you have.\n */\nexport interface GeminiClient {\n generateContent(\n params: {\n model?: string;\n contents: Array<{ role: 'user' | 'model'; parts: Array<{ text: string }> }>;\n systemInstruction?: { parts: Array<{ text: string }> };\n generationConfig?: {\n temperature?: number;\n maxOutputTokens?: number;\n responseMimeType?: string;\n responseSchema?: Record<string, unknown>;\n };\n },\n options: { signal: AbortSignal },\n ): Promise<{\n candidates?: Array<{ content?: { parts?: Array<{ text?: string }> } }>;\n usageMetadata?: {\n promptTokenCount?: number;\n candidatesTokenCount?: number;\n totalTokenCount?: number;\n };\n }>;\n}\n\n/**\n * Wraps a Gemini client so it satisfies the `LLMClient` interface VernLLM\n * uses for OpenAI/Groq. Geminis shape differs on nearly every axis: a\n * `contents` array instead of `messages`, a separate `systemInstruction`\n * field instead of a `system` role message, `generationConfig` instead of\n * top-level `temperature`/`max_tokens`, and native JSON Schema support via\n * `responseMimeType: 'application/json'` + `responseSchema` (so `jsonSchema`\n * is provider-enforced here, unlike the Anthropic adapters prompt-embedding\n * fallback). `reasoning_effort` has no equivalent. Geminis thinking models\n * use a token budget, not an effort tier, so its dropped, same as Anthropic.\n */\nexport function fromGemini(geminiClient: GeminiClient): LLMClient {\n return {\n chat: {\n completions: {\n async create(params, options) {\n const systemMessage = params.messages.find((m) => m.role === 'system');\n // Keep both user and assistant turns, in order. Gemini calls the\n // assistant role 'model' rather than 'assistant'.\n const conversationMessages = params.messages.filter(\n (m) => m.role === 'user' || m.role === 'assistant',\n );\n\n const wantsJson = Boolean(params.response_format);\n const generationConfig: NonNullable<\n Parameters<GeminiClient['generateContent']>[0]['generationConfig']\n > = {\n temperature: params.temperature,\n maxOutputTokens: params.max_tokens,\n };\n\n if (wantsJson) {\n generationConfig.responseMimeType = 'application/json';\n }\n if (params.response_format?.type === 'json_schema') {\n generationConfig.responseSchema = params.response_format.json_schema.schema;\n }\n\n const response = await geminiClient.generateContent(\n {\n model: params.model,\n contents: conversationMessages.map((m) => ({\n role: m.role === 'assistant' ? ('model' as const) : ('user' as const),\n parts: [{ text: m.content }],\n })),\n systemInstruction: systemMessage\n ? { parts: [{ text: systemMessage.content }] }\n : undefined,\n generationConfig,\n },\n options,\n );\n\n const text =\n response.candidates?.[0]?.content?.parts?.map((p) => p.text ?? '').join('') ?? '';\n\n return {\n choices: [{ message: { content: text } }],\n usage: {\n prompt_tokens: response.usageMetadata?.promptTokenCount,\n completion_tokens: response.usageMetadata?.candidatesTokenCount,\n total_tokens: response.usageMetadata?.totalTokenCount,\n },\n };\n },\n },\n },\n };\n}\n","import type { LLMClient } from '../types/index.js';\n\n/**\n * Minimal structural type matching AWS Bedrocks Converse API. This is\n * intentionally NOT `BedrockRuntimeClient` itself, the AWS SDK v3 client\n * exposes `.send(command)`, not a direct `.converse()` method, and pulling\n * in `@aws-sdk/client-bedrock-runtime` as a dependency just for its types\n * isn't worth it for a structural adapter. Wrap your client, e.g:\n *\n * ```ts\n * import { BedrockRuntimeClient, ConverseCommand } from '@aws-sdk/client-bedrock-runtime';\n * const client = new BedrockRuntimeClient({ region: 'us-east-1' });\n * const converseClient = {\n * converse: (params, options) =>\n * client.send(new ConverseCommand(params), { abortSignal: options.signal }),\n * };\n * ```\n */\nexport interface BedrockConverseClient {\n converse(\n params: {\n modelId: string;\n messages: Array<{ role: 'user' | 'assistant'; content: Array<{ text: string }> }>;\n system?: Array<{ text: string }>;\n inferenceConfig?: { temperature?: number; maxTokens?: number };\n toolConfig?: {\n tools: Array<{\n toolSpec: {\n name: string;\n description?: string;\n inputSchema: { json: Record<string, unknown> };\n };\n }>;\n toolChoice?: { tool: { name: string } };\n };\n },\n options: { signal: AbortSignal },\n ): Promise<{\n output?: {\n message?: {\n content?: Array<{ text?: string; toolUse?: { name?: string; input?: unknown } }>;\n };\n };\n usage?: { inputTokens?: number; outputTokens?: number; totalTokens?: number };\n }>;\n}\n\n/**\n * Wraps a Bedrock Converse-API client so it satisfies the `LLMClient`\n * interface VernLLM uses for OpenAI/Groq. The Converse API is unified\n * across Bedrocks model families (Anthropic, Titan, Llama, Mistral, etc.),\n * so unlike raw per-model Bedrock invocation, this one adapter works\n * regardless of which underlying model `modelId` points at, as long as\n * that model supports Converse (most current-generation ones do)\n *\n * `response_format: json_schema` is mapped to Converses `toolConfig`: a\n * single tool is defined from the schema and `toolChoice` forces the model\n * to call it, constraining output at generation time rather than merely\n * instructing for it via prompt text. Native tool support varies by model\n * family (most current-generation ones support it via Converse; check your\n * specific `modelId` if a call fails with an unsupported-parameter error).\n * `response_format: json_object` (no schema to build a tool from) and\n * `reasoning_effort` (no Converse equivalent) fall back to a system-prompt\n * instruction and are dropped respectively.\n */\nexport function fromBedrock(bedrockClient: BedrockConverseClient): LLMClient {\n return {\n chat: {\n completions: {\n async create(params, options) {\n const systemMessage = params.messages.find((m) => m.role === 'system');\n // Keep both user and assistant turns, in order, so conversation\n // history survives instead of collapsing to consecutive user turns.\n const conversationMessages = params.messages.filter(\n (m): m is typeof m & { role: 'user' | 'assistant' } =>\n m.role === 'user' || m.role === 'assistant',\n );\n\n const toolName =\n params.response_format?.type === 'json_schema'\n ? params.response_format.json_schema.name\n : undefined;\n\n let jsonInstruction: string | undefined;\n let toolConfig:\n | NonNullable<Parameters<BedrockConverseClient['converse']>[0]['toolConfig']>\n | undefined;\n\n if (params.response_format?.type === 'json_schema' && toolName) {\n const { schema, description } = params.response_format.json_schema;\n toolConfig = {\n tools: [{ toolSpec: { name: toolName, description, inputSchema: { json: schema } } }],\n toolChoice: { tool: { name: toolName } },\n };\n } else if (params.response_format?.type === 'json_object') {\n // No schema to build a tool from, fall back to a prompt instruction\n jsonInstruction = 'Respond with valid JSON only, no prose or markdown fences.';\n }\n\n const systemParts = [systemMessage?.content, jsonInstruction].filter((s): s is string =>\n Boolean(s),\n );\n\n const response = await bedrockClient.converse(\n {\n modelId: params.model,\n messages: conversationMessages.map((m) => ({\n role: m.role,\n content: [{ text: m.content }],\n })),\n system: systemParts.length ? systemParts.map((text) => ({ text })) : undefined,\n inferenceConfig: {\n temperature: params.temperature,\n maxTokens: params.max_tokens,\n },\n ...(toolConfig ? { toolConfig } : {}),\n },\n options,\n );\n\n let text: string;\n if (toolName) {\n // Forced tool-use: the schema-conforming payload arrives as the\n // toolUse content block's already-parsed `input`, not as text.\n // Re-serialize it to JSON so it flows through the same\n // string-content contract every other adapter uses.\n const toolUseBlock = response.output?.message?.content?.find(\n (block) => block.toolUse?.name === toolName,\n );\n text = toolUseBlock?.toolUse ? JSON.stringify(toolUseBlock.toolUse.input) : '';\n } else {\n text = response.output?.message?.content?.map((c) => c.text ?? '').join('') ?? '';\n }\n\n return {\n choices: [{ message: { content: text } }],\n usage: {\n prompt_tokens: response.usage?.inputTokens,\n completion_tokens: response.usage?.outputTokens,\n total_tokens: response.usage?.totalTokens,\n },\n };\n },\n },\n },\n };\n}\n","import type { LLMClient } from '../types/index.js';\n\n/** The chat-completion-shaped request VernLLM builds internally */\ntype ChatRequest = Parameters<LLMClient['chat']['completions']['create']>[0];\n\nexport interface FetchAdapterConfig {\n /** Endpoint URL, or a function of the request in case it depends on model/params */\n url: string | ((params: ChatRequest) => string);\n /** Static headers, or a function (sync or async) for things like refreshed auth tokens */\n headers?:\n | Record<string, string>\n | (() => Record<string, string> | Promise<Record<string, string>>);\n /** HTTP method. Default 'POST' */\n method?: string;\n /** Maps VernLLMs internal chat-completion request into the providers raw request body */\n mapRequest: (params: ChatRequest) => unknown;\n /**\n * Maps the providers raw JSON response into `{ content, usage? }`\n * `content` is the assistants text (JSON string when JSON mode was requested)\n */\n mapResponse: (json: unknown) => {\n content: string;\n usage?: { promptTokens?: number; completionTokens?: number; totalTokens?: number };\n };\n}\n\n/**\n * A fetch-based escape hatch for providers with no SDK, or where pulling one\n * in isnt worth it. You supply the URL, headers, and two small mapping\n * functions; this handles the HTTP call and slots the result into the same\n * `LLMClient` shape every other adapter produces, so retries, timeouts,\n * the circuit breaker, and JSON/schema handling all still work unmodified\n *\n * Non-2xx responses throw an error with `.status` set to the HTTP status\n * code, so VernLLMs `nonRetryableStatus` handling (e.g. failing fast on\n * 401/403) applies here too\n */\nexport function fromFetch(config: FetchAdapterConfig): LLMClient {\n return {\n chat: {\n completions: {\n async create(params, options) {\n const url = typeof config.url === 'function' ? config.url(params) : config.url;\n const headers =\n typeof config.headers === 'function' ? await config.headers() : config.headers;\n\n const res = await fetch(url, {\n method: config.method ?? 'POST',\n headers: { 'Content-Type': 'application/json', ...headers },\n body: JSON.stringify(config.mapRequest(params)),\n signal: options.signal,\n });\n\n if (!res.ok) {\n const body = await res.text().catch(() => '');\n const err = new Error(\n `Fetch adapter request failed (${res.status}): ${body.slice(0, 500)}`,\n ) as Error & { status?: number };\n err.status = res.status;\n throw err;\n }\n\n const json = await res.json();\n const { content, usage } = config.mapResponse(json);\n\n return {\n choices: [{ message: { content } }],\n usage: usage\n ? {\n prompt_tokens: usage.promptTokens,\n completion_tokens: usage.completionTokens,\n total_tokens: usage.totalTokens,\n }\n : undefined,\n };\n },\n },\n },\n };\n}\n","import type { LLMClient } from '../types/index.js';\n\n/**\n * Passthrough adapter for any SDK/client whose `chat.completions.create`\n * already matches the OpenAI wire format 1:1 : this covers most hosted\n * inference providers, since \"OpenAI-compatible\" is a de facto standard for\n * chat completion APIs. No transformation happens here, this exists purely\n * so call sites read clearly (`fromMistral(client)` vs handing a Mistral\n * client to something typed for OpenAI) and so a real transformation could\n * be added later, per-provider, without a breaking change.\n *\n * Not every SDKs own TypeScript types line up exactly with `LLMClient`\n * (extra fields, stricter unions, etc.), so this takes `unknown` and casts:\n * the actual compatibility contract is the JSON each provider sends and\n * receives over the wire, not the SDKs TS types.\n */\nexport function fromOpenAICompatible(client: unknown): LLMClient {\n return client as LLMClient;\n}\n\n/** Groqs SDK matches the OpenAI wire format */\nexport const fromGroq = fromOpenAICompatible;\n\n/** Mistrals `chat.completions`-shaped client (or their OpenAI-compat endpoint) */\nexport const fromMistral = fromOpenAICompatible;\n\n/** DeepSeeks API is OpenAI-compatible */\nexport const fromDeepSeek = fromOpenAICompatible;\n\n/** Cerebras inference API is OpenAI-compatible */\nexport const fromCerebras = fromOpenAICompatible;\n\n/** Together AIs API is OpenAI-compatible */\nexport const fromTogether = fromOpenAICompatible;\n\n/** Fireworks AIs API is OpenAI-compatible */\nexport const fromFireworks = fromOpenAICompatible;\n\n/**\n * Ollama exposes an OpenAI-compatible endpoint at `/v1/chat/completions`\n * (as opposed to its native `/api/chat` format, which differs). Point an\n * OpenAI SDK instances `baseURL` at your Ollama server and pass it here:\n * this does not talk to Ollamas native API directly.\n */\nexport const fromOllama = fromOpenAICompatible;\n\n/** OpenRouter's API is OpenAI-compatible */\nexport const fromOpenRouter = fromOpenAICompatible;\n\n/** Perplexity's API is OpenAI-compatible */\nexport const fromPerplexity = fromOpenAICompatible;\n\n/** DeepInfra's API is OpenAI-compatible */\nexport const fromDeepInfra = fromOpenAICompatible;\n\n/** Novita's API is OpenAI-compatible */\nexport const fromNovita = fromOpenAICompatible;\n\n/** Hyperbolic's API is OpenAI-compatible */\nexport const fromHyperbolic = fromOpenAICompatible;\n\n/** Moonshot's (Kimi) API is OpenAI-compatible */\nexport const fromMoonshot = fromOpenAICompatible;\n\n/** Zhipu's (GLM) API is OpenAI-compatible */\nexport const fromZhipu = fromOpenAICompatible;\n\n/**\n * LM Studio exposes an OpenAI-compatible endpoint at `/v1/chat/completions`.\n * Point an OpenAI SDK instance's `baseURL` at your local LM Studio server.\n */\nexport const fromLMStudio = fromOpenAICompatible;\n\n/**\n * vLLM's OpenAI-compatible server mode exposes `/v1/chat/completions`.\n * Point an OpenAI SDK instance's `baseURL` at your vLLM server.\n */\nexport const fromVLLM = fromOpenAICompatible;\n\n/** xAI's Grok API is OpenAI-compatible */\nexport const fromXAI = fromOpenAICompatible;\n\n/** NVIDIA NIM's hosted and self-hosted endpoints are OpenAI-compatible */\nexport const fromNvidiaNIM = fromOpenAICompatible;\n\n/** Vercel AI Gateway is OpenAI-compatible */\nexport const fromVercelAIGateway = fromOpenAICompatible;\n\n/** Cloudflare Workers AI exposes an OpenAI-compatible endpoint */\nexport const fromCloudflareWorkersAI = fromOpenAICompatible;\n\n/** GitHub Models is OpenAI-compatible */\nexport const fromGitHubModels = fromOpenAICompatible;\n\n/** Nebius AI Studio is OpenAI-compatible */\nexport const fromNebius = fromOpenAICompatible;\n\n/** SambaNova Cloud's API is OpenAI-compatible */\nexport const fromSambaNova = fromOpenAICompatible;\n\n/** Baseten's model hosting exposes an OpenAI-compatible endpoint */\nexport const fromBaseten = fromOpenAICompatible;\n\n/** Featherless AI's API is OpenAI-compatible */\nexport const fromFeatherless = fromOpenAICompatible;\n\n/** Friendli AI's serving endpoint is OpenAI-compatible */\nexport const fromFriendli = fromOpenAICompatible;\n\n/** SiliconFlow's API is OpenAI-compatible */\nexport const fromSiliconFlow = fromOpenAICompatible;\n\n/** Parasail's inference API is OpenAI-compatible */\nexport const fromParasail = fromOpenAICompatible;\n\n/** StepFun's API is OpenAI-compatible */\nexport const fromStepFun = fromOpenAICompatible;\n\n/** MiniMax's API is OpenAI-compatible */\nexport const fromMiniMax = fromOpenAICompatible;\n\n/** Lambda Labs' Inference API is OpenAI-compatible */\nexport const fromLambdaLabs = fromOpenAICompatible;\n\n/** Snowflake Cortex's LLM endpoint is OpenAI-compatible */\nexport const fromSnowflakeCortex = fromOpenAICompatible;\n\n/** Anyscale Endpoints' API is OpenAI-compatible */\nexport const fromAnyscale = fromOpenAICompatible;\n\n/** Lepton AI's inference API is OpenAI-compatible */\nexport const fromLepton = fromOpenAICompatible;\n\n/** kluster.ai's inference API is OpenAI-compatible */\nexport const fromKlusterAI = fromOpenAICompatible;\n\n/** Inference.net's API is OpenAI-compatible */\nexport const fromInferenceNet = fromOpenAICompatible;\n\n/** Infermatic's API is OpenAI-compatible */\nexport const fromInfermatic = fromOpenAICompatible;\n\n/** AtlasCloud's inference API is OpenAI-compatible */\nexport const fromAtlasCloud = fromOpenAICompatible;\n\n/** 01.AI's (Yi models) API is OpenAI-compatible */\nexport const from01AI = fromOpenAICompatible;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,IAAa,WAAb,cAA8B,MAAM;CAClC,YACEA,SACOC,MACAC,QACAC,QACP;AACA,QAAM,QAAQ;EAQjB,KAZU;EAYT,KAXS;EAWR,KAVQ;AAGP,OAAK,OAAO;CACb;AACF;AAED,SAAgB,WAAWC,KAA+B;AACxD,QAAO,eAAe;AACvB;;;;;;;;;;ACND,IAAa,iBAAb,MAA4B;CAC1B,AAAQ,QAAsB;CAC9B,AAAQ,sBAAsB;CAC9B,AAAQ,WAAW;CACnB,AAAQ;CACR,AAAQ;CAER,YAAYC,UAAiC,CAAE,GAAE;AAC/C,OAAK,YAAY,QAAQ,aAAa;AACtC,OAAK,aAAa,QAAQ,cAAc;CACzC;;CAGD,eAAqB;AACnB,MAAI,KAAK,UAAU,OAAQ;EAE3B,MAAM,UAAU,KAAK,KAAK,GAAG,KAAK;AAClC,MAAI,WAAW,KAAK,YAAY;AAC9B,QAAK,QAAQ;AACb;EACD;AAED,QAAM,IAAI,UACP,qCAAqC,KAAK,oBAAoB,4BAA4B,KAAK,MAAM,KAAK,aAAa,WAAW,IAAK,CAAC,KACzI;CAEH;CAED,gBAAsB;AACpB,OAAK,sBAAsB;AAC3B,OAAK,QAAQ;CACd;CAED,gBAAsB;AACpB,OAAK,uB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AAM;GACrB;EAEN;CACF,EACF,EACF,EACF;AACF;;;;;;;;;;;;;;;;;;AC/DD,SAAgB,qBAAqBC,QAA4B;AAC/D,QAAO;AACR;;AAGD,MAAa,WAAW;;AAGxB,MAAa,cAAc;;AAG3B,MAAa,eAAe;;AAG5B,MAAa,eAAe;;AAG5B,MAAa,eAAe;;AAG5B,MAAa,gBAAgB;;;;;;;AAQ7B,MAAa,aAAa;;AAG1B,MAAa,iBAAiB;;AAG9B,MAAa,iBAAiB;;AAG9B,MAAa,gBAAgB;;AAG7B,MAAa,aAAa;;AAG1B,MAAa,iBAAiB;;AAG9B,MAAa,eAAe;;AAG5B,MAAa,YAAY;;;;;AAMzB,MAAa,eAAe;;;;;AAM5B,MAAa,WAAW;;AAGxB,MAAa,UAAU;;AAGvB,MAAa,gBAAgB;;AAG7B,MAAa,sBAAsB;;AAGnC,MAAa,0BAA0B;;AAGvC,MAAa,mBAAmB;;AAGhC,MAAa,aAAa;;AAG1B,MAAa,gBAAgB;;AAG7B,MAAa,cAAc;;AAG3B,MAAa,kBAAkB;;AAG/B,MAAa,eAAe;;AAG5B,MAAa,kBAAkB;;AAG/B,MAAa,eAAe;;AAG5B,MAAa,cAAc;;AAG3B,MAAa,cAAc;;AAG3B,MAAa,iBAAiB;;AAG9B,MAAa,sBAAsB;;AAGnC,MAAa,eAAe;;AAG5B,MAAa,aAAa;;AAG1B,MAAa,gBAAgB;;AAG7B,MAAa,mBAAmB;;AAGhC,MAAa,iBAAiB;;AAG9B,MAAa,iBAAiB;;AAG9B,MAAa,WAAW"}
|
package/dist/index.d.cts
CHANGED
|
@@ -200,11 +200,12 @@ interface VernLLMOptions {
|
|
|
200
200
|
baseDelayMs?: number;
|
|
201
201
|
/** Default max_tokens for calls that don't override it. Default 1000 */
|
|
202
202
|
defaultMaxTokens?: number;
|
|
203
|
-
/** Enables debug logging of raw model output
|
|
203
|
+
/** Enables debug logging of raw model output (logs up to 800 chars of each
|
|
204
|
+
* response). Off by default */
|
|
204
205
|
debug?: boolean;
|
|
205
206
|
/** Cache adapter for cachedCall. Defaults to an in-memory adapter */
|
|
206
207
|
cache?: CacheAdapter;
|
|
207
|
-
/** HTTP status codes that should fail fast without retrying. Default [400, 401, 403] */
|
|
208
|
+
/** HTTP status codes that should fail fast without retrying. Default [400, 401, 403, 404, 422] */
|
|
208
209
|
nonRetryableStatus?: number[];
|
|
209
210
|
/** Custom JSON parser. Must return undefined/null on failure. Default: JSON.parse wrapped in try/catch */
|
|
210
211
|
parseJson?: (content: string) => unknown;
|
|
@@ -312,8 +313,8 @@ declare class VernLLM {
|
|
|
312
313
|
private resolveRetryConfig;
|
|
313
314
|
/**
|
|
314
315
|
* Returns the caller supplied logger, or a console-based logger whose
|
|
315
|
-
* debug output is gated by the `debug` option (defaulting to
|
|
316
|
-
*
|
|
316
|
+
* debug output is gated by the `debug` option (defaulting to off,
|
|
317
|
+
* so response content isn't unintentionally written to logs)
|
|
317
318
|
*/
|
|
318
319
|
private resolveLogger;
|
|
319
320
|
/**
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types/errors.ts","../src/types/cache.ts","../src/types/client.ts","../src/types/usage.ts","../src/types/schema.ts","../src/circuitBreaker.ts","../src/logger.ts","../src/types/options.ts","../src/types/call.ts","../src/vernLLM.ts","../src/adapters/anthropic.ts","../src/adapters/gemini.ts","../src/adapters/bedrock.ts","../src/adapters/fetch.ts","../src/adapters/openaiCompatible.ts"],"sourcesContent":null,"mappings":";KAAY,YAAA;AAAA,cASC,QAAA,SAAiB,KAAA,CATN;EASX,IAAA,EAGI,YAHK;EAAA,MAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAAA,MAGL,CAAA,EAAA,OAAA,GAAA,SAAA;EAAY,WAAZ,CAAA,OAAA,EAAA,MAAA,EAAA,IAAA,EAAA,YAAA,EAAA,MAAA,CAAA,EAAA,MAAA,GAAA,SAAA,EAAA,MAAA,CAAA,EAAA,OAAA,GAAA,SAAA;;AAHkB,iBAYnB,UAAA,CAZmB,GAAA,EAAA,OAAA,CAAA,EAAA,GAAA,IAYc,QAZd;;;;AAYnC;UCrBiB;EDAL,GAAA,CAAA,GAAA,EAAA,MAAY,CAAA,ECCJ,ODDI,CAAA;IASX,GAAA,EAAA,OAAS;IAAA,KAAA,ECR6B,CDQ7B,GAAA,IAAA;EAAA,CAAA,CAAA;EAGO,GAAZ,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,ECVS,CDUT,EAAA,GAAA,EAAA,MAAA,CAAA,ECV0B,ODU1B,CAAA,IAAA,CAAA;EAAY,MAHC,EAAA,GAAA,EAAA,MAAA,CAAA,ECNN,ODMM,CAAA,IAAA,CAAA;AAAK;AAYnC;;;;ACrBiB,cAUJ,oBAVgB,CAAA,IAAA,OAAA,CAAA,YAU6B,YAV7B,CAU0C,CAV1C,CAAA,CAAA;EAAA,iBAAA,OAAA;EAAA,QACsB,KAAA;EAAC,WAAhC,CAAA,OAAA,CAAA,EAAA,MAAA;EAAO,GACD,CAAA,GAAA,EAAA,MAAA,CAAA,EAaA,OAbA,CAAA;IAAiB,GAAA,EAAA,OAAA;IACnB,KAAA,EAYiC,CAZjC,GAAA,IAAA;EAAO,CAAA,CAAA;0BAyBC,iBAAiB;uBAWpB;;;AA7B7B;;;;;;ADVA;AASA;;;;;AAAmC;AAYnB,UEbC,SAAA,
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types/errors.ts","../src/types/cache.ts","../src/types/client.ts","../src/types/usage.ts","../src/types/schema.ts","../src/circuitBreaker.ts","../src/logger.ts","../src/types/options.ts","../src/types/call.ts","../src/vernLLM.ts","../src/adapters/anthropic.ts","../src/adapters/gemini.ts","../src/adapters/bedrock.ts","../src/adapters/fetch.ts","../src/adapters/openaiCompatible.ts"],"sourcesContent":null,"mappings":";KAAY,YAAA;AAAA,cASC,QAAA,SAAiB,KAAA,CATN;EASX,IAAA,EAGI,YAHK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B,oBbrB+B;;;;;;AALa;cakCzD,mBAAU;;cAGV,uBAAc;;cAGd,uBAAc;;cAGd,sBAAa;;cAGb,mBAAU;;cAGV,uBAAc;AZnD3B;AAA0B,cYsDb,YZtDa,EAAA,OYsDD,oBZtDC;;AAqBN,cYoCP,SZpCO,EAAA,OYoCE,oBZpCF;;;;AAGJ;cYuCH,qBAAY;;;AXvEzB;AACA;AAEiB,cW0EJ,QX1Ec,EAAA,OW0EN,oBX1EM;AAQ3B;cWqEa,gBAAO;;cAGP,sBAAa;;cAGb,4BAAmB;;cAGnB,gCAAuB;;AVpFnB,cUuFJ,gBVtFuC,EAAA,OUsFvB,oBVtFuB;;cUyFvC,mBAAU;;cAGV,sBAAa;;cAGb,oBAAW;;cAGX,wBAAe;AVvF5B;cU0Fa,qBAAY;;cAGZ,wBAAe;AT5G5B;AAOK,cSwGQ,YTxGI,EAAA,OSwGQ,oBTxGR;;cS2GJ,oBAAW;;cAGX,oBAAW;;cAGX,uBAAc;ATzG3B;AAA2B,cS4Gd,mBT5Gc,EAAA,OS4GK,oBT5GL;;AAiDb,cS8DD,YT9DC,EAAA,OS8DW,oBT9DX;AAAY;cSiEb,mBAAU;;cAGV,sBAAa;ARtI1B;cQyIa,yBAAgB;;cAGhB,uBAAc;;ARlId,cQqIA,cRrIc,EAAA,OQqIA,oBRrIA;;AAWK,cQ6HnB,QR7HmB,EAAA,OQ6HX,oBR7HW"}
|
package/dist/index.d.ts
CHANGED
|
@@ -200,11 +200,12 @@ interface VernLLMOptions {
|
|
|
200
200
|
baseDelayMs?: number;
|
|
201
201
|
/** Default max_tokens for calls that don't override it. Default 1000 */
|
|
202
202
|
defaultMaxTokens?: number;
|
|
203
|
-
/** Enables debug logging of raw model output
|
|
203
|
+
/** Enables debug logging of raw model output (logs up to 800 chars of each
|
|
204
|
+
* response). Off by default */
|
|
204
205
|
debug?: boolean;
|
|
205
206
|
/** Cache adapter for cachedCall. Defaults to an in-memory adapter */
|
|
206
207
|
cache?: CacheAdapter;
|
|
207
|
-
/** HTTP status codes that should fail fast without retrying. Default [400, 401, 403] */
|
|
208
|
+
/** HTTP status codes that should fail fast without retrying. Default [400, 401, 403, 404, 422] */
|
|
208
209
|
nonRetryableStatus?: number[];
|
|
209
210
|
/** Custom JSON parser. Must return undefined/null on failure. Default: JSON.parse wrapped in try/catch */
|
|
210
211
|
parseJson?: (content: string) => unknown;
|
|
@@ -312,8 +313,8 @@ declare class VernLLM {
|
|
|
312
313
|
private resolveRetryConfig;
|
|
313
314
|
/**
|
|
314
315
|
* Returns the caller supplied logger, or a console-based logger whose
|
|
315
|
-
* debug output is gated by the `debug` option (defaulting to
|
|
316
|
-
*
|
|
316
|
+
* debug output is gated by the `debug` option (defaulting to off,
|
|
317
|
+
* so response content isn't unintentionally written to logs)
|
|
317
318
|
*/
|
|
318
319
|
private resolveLogger;
|
|
319
320
|
/**
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types/errors.ts","../src/types/cache.ts","../src/types/client.ts","../src/types/usage.ts","../src/types/schema.ts","../src/circuitBreaker.ts","../src/logger.ts","../src/types/options.ts","../src/types/call.ts","../src/vernLLM.ts","../src/adapters/anthropic.ts","../src/adapters/gemini.ts","../src/adapters/bedrock.ts","../src/adapters/fetch.ts","../src/adapters/openaiCompatible.ts"],"sourcesContent":null,"mappings":";KAAY,YAAA;AAAA,cASC,QAAA,SAAiB,KAAA,CATN;EASX,IAAA,EAGI,YAHK;EAAA,MAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAAA,MAGL,CAAA,EAAA,OAAA,GAAA,SAAA;EAAY,WAAZ,CAAA,OAAA,EAAA,MAAA,EAAA,IAAA,EAAA,YAAA,EAAA,MAAA,CAAA,EAAA,MAAA,GAAA,SAAA,EAAA,MAAA,CAAA,EAAA,OAAA,GAAA,SAAA;;AAHkB,iBAYnB,UAAA,CAZmB,GAAA,EAAA,OAAA,CAAA,EAA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,OAAA,EAAA,MAAA,EAAA,IAAA,CAAA,EMNU,MNMV,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,EAAA,IAAA;;;;AAAa;AAYnC;cMXa,aAAA,YAAyB;;;ELVrB,KAAA,CAAA,OAAA,EAAY,MAAA,CAAA,EAAA,IAAA;EAAA,IAAA,CAAA,OAAA,EAAA,MAAA,CAAA,EAAA,IAAA;EAAA,KACsB,CAAA,OAAA,EAAA,MAAA,EAAA,IAAA,CAAA,EKoBnB,MLpBmB,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,EAAA,IAAA;;;;;;ADWlC,UONA,cAAA,CPMA;EAAY,MAHC,EOFpB,SPEoB;EAAK,KAAA,EAAA,MAAA;EAYnB;;;;ECrBC;EAAY,WAAA,CAAA,EAAA,MAAA;EAAA;EACuB,gBAAhC,CAAA,EAAA,MAAA;EAAO
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types/errors.ts","../src/types/cache.ts","../src/types/client.ts","../src/types/usage.ts","../src/types/schema.ts","../src/circuitBreaker.ts","../src/logger.ts","../src/types/options.ts","../src/types/call.ts","../src/vernLLM.ts","../src/adapters/anthropic.ts","../src/adapters/gemini.ts","../src/adapters/bedrock.ts","../src/adapters/fetch.ts","../src/adapters/openaiCompatible.ts"],"sourcesContent":null,"mappings":";KAAY,YAAA;AAAA,cASC,QAAA,SAAiB,KAAA,CATN;EASX,IAAA,EAGI,YAHK;EAAA,MAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAAA,MAGL,CAAA,EAAA,OAAA,GAAA,SAAA;EAAY,WAAZ,CAAA,OAAA,EAAA,MAAA,EAAA,IAAA,EAAA,YAAA,EAAA,MAAA,CAAA,EAAA,MAAA,GAAA,SAAA,EAAA,MAAA,CAAA,EAAA,OAAA,GAAA,SAAA;;AAHkB,iBAYnB,UAAA,CAZmB,GAAA,EAAA,OAAA,CAAA,EAAA,GAAA,IAYc,QAZd;;;;AAYnC;UCrBiB;EDAL,GAAA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B;;cAGnB,gCAAuB;;AVpFnB,cUuFJ,gBVtFuC,EAAA,OUsFvB,oBVtFuB;;cUyFvC,mBAAU;;cAGV,sBAAa;;cAGb,oBAAW;;cAGX,wBAAe;AVvF5B;cU0Fa,qBAAY;;cAGZ,wBAAe;AT5G5B;AAOK,cSwGQ,YTxGI,EAAA,OSwGQ,oBTxGR;;cS2GJ,oBAAW;;cAGX,oBAAW;;cAGX,uBAAc;ATzG3B;AAA2B,cS4Gd,mBT5Gc,EAAA,OS4GK,oBT5GL;;AAiDb,cS8DD,YT9DC,EAAA,OS8DW,oBT9DX;AAAY;cSiEb,mBAAU;;cAGV,sBAAa;ARtI1B;cQyIa,yBAAgB;;cAGhB,uBAAc;;ARlId,cQqIA,cRrIc,EAAA,OQqIA,oBRrIA;;AAWK,cQ6HnB,QR7HmB,EAAA,OQ6HX,oBR7HW"}
|
package/dist/index.js
CHANGED
|
@@ -255,7 +255,9 @@ var VernLLM = class {
|
|
|
255
255
|
this.nonRetryableStatus = options.nonRetryableStatus ?? [
|
|
256
256
|
400,
|
|
257
257
|
401,
|
|
258
|
-
403
|
|
258
|
+
403,
|
|
259
|
+
404,
|
|
260
|
+
422
|
|
259
261
|
];
|
|
260
262
|
this.parseJson = options.parseJson ?? defaultParseJson;
|
|
261
263
|
this.onUsage = options.onUsage;
|
|
@@ -276,11 +278,11 @@ var VernLLM = class {
|
|
|
276
278
|
}
|
|
277
279
|
/**
|
|
278
280
|
* Returns the caller supplied logger, or a console-based logger whose
|
|
279
|
-
* debug output is gated by the `debug` option (defaulting to
|
|
280
|
-
*
|
|
281
|
+
* debug output is gated by the `debug` option (defaulting to off,
|
|
282
|
+
* so response content isn't unintentionally written to logs)
|
|
281
283
|
*/
|
|
282
284
|
resolveLogger(options) {
|
|
283
|
-
return options.logger ?? new ConsoleLogger(options.debug ??
|
|
285
|
+
return options.logger ?? new ConsoleLogger(options.debug ?? false);
|
|
284
286
|
}
|
|
285
287
|
/**
|
|
286
288
|
* Builds a circuit breaker if `circuitBreaker` is truthy on the
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["message: string","type: LLMErrorType","status?: number","issues?: unknown","err: unknown","options: CircuitBreakerOptions","content: string","err: unknown","fn: (signal: AbortSignal) => Promise<T>","timeoutMs: number","externalSignal?: AbortSignal","baseDelayMs: number","attempt: number","delay: number","signal?: AbortSignal","debugEnabled: boolean","message: string","meta?: Record<string, unknown>","key: string","value: T","ttl: number","options: VernLLMOptions","params: CallParams<T>","fn: () => Promise<T>","requestId: string","signal?: AbortSignal","lastError: unknown","error: unknown","history: ConversationTurn[]","previousRole: 'user' | 'assistant' | undefined","jsonSchema: CallParams<unknown>['jsonSchema']","useJson: boolean","response: Awaited<ReturnType<LLMClient['chat']['completions']['create']>>","model: string","content: string","schema?: CallParams<T>['schema']","parsed: unknown","attempt: number","key: string","params: CachedCallParams<T>","params: Omit<CachedCallParams<T>, 'fn'> & { call: CallParams<T> }","anthropicClient: AnthropicClient","jsonInstruction: string | undefined","tools:\n | NonNullable<Parameters<AnthropicClient['messages']['create']>[0]['tools']>\n | undefined","text: string","geminiClient: GeminiClient","generationConfig: NonNullable<\n Parameters<GeminiClient['generateContent']>[0]['generationConfig']\n >","bedrockClient: BedrockConverseClient","jsonInstruction: string | undefined","toolConfig:\n | NonNullable<Parameters<BedrockConverseClient['converse']>[0]['toolConfig']>\n | undefined","text","text: string","config: FetchAdapterConfig","client: unknown"],"sources":["../src/types/errors.ts","../src/circuitBreaker.ts","../src/internal/vernLLM.utils.ts","../src/logger.ts","../src/types/cache.ts","../src/vernLLM.ts","../src/adapters/anthropic.ts","../src/adapters/gemini.ts","../src/adapters/bedrock.ts","../src/adapters/fetch.ts","../src/adapters/openaiCompatible.ts"],"sourcesContent":["export type LLMErrorType =\n | 'timeout'\n | 'api'\n | 'parse'\n | 'validation'\n | 'circuit_open'\n | 'unknown'\n | 'aborted';\n\nexport class LLMError extends Error {\n constructor(\n message: string,\n public type: LLMErrorType,\n public status?: number,\n public issues?: unknown,\n ) {\n super(message);\n this.name = 'LLMError';\n }\n}\n\nexport function isLLMError(err: unknown): err is LLMError {\n return err instanceof LLMError;\n}\n","import { LLMError } from './types/errors.js';\n\nexport interface CircuitBreakerOptions {\n /** Consecutive failures before the circuit opens, default 5 */\n threshold?: number;\n /** How long the circuit stays open before allowing a trial request, in ms. Default 30000 */\n cooldownMs?: number;\n}\n\ntype CircuitState = 'closed' | 'open' | 'half-open';\n\n/**\n * Per retry VernLLM-instance circuit breaker. Tracks consecutive failures across\n * calls. Once the threshold is hit, short-circuits new calls with an\n * LLMError('circuit_open') instead of hitting the provider, until the\n * cooldown elapses and a single trial call is allowed through\n */\nexport class CircuitBreaker {\n private state: CircuitState = 'closed';\n private consecutiveFailures = 0;\n private openedAt = 0;\n private threshold: number;\n private cooldownMs: number;\n\n constructor(options: CircuitBreakerOptions = {}) {\n this.threshold = options.threshold ?? 5;\n this.cooldownMs = options.cooldownMs ?? 30_000;\n }\n\n /** Throws if the circuit is open and the cooldown hasnt elapsed */\n assertClosed(): void {\n if (this.state !== 'open') return;\n\n const elapsed = Date.now() - this.openedAt;\n if (elapsed >= this.cooldownMs) {\n this.state = 'half-open';\n return;\n }\n\n throw new LLMError(\n `Circuit open — provider has failed ${this.consecutiveFailures} times in a row. Retry in ${Math.ceil((this.cooldownMs - elapsed) / 1000)}s.`,\n 'circuit_open',\n );\n }\n\n recordSuccess(): void {\n this.consecutiveFailures = 0;\n this.state = 'closed';\n }\n\n recordFailure(): void {\n this.consecutiveFailures += 1;\n\n if (this.state === 'half-open') {\n // Trial call failed: reopen and reset the cooldown window.\n this.state = 'open';\n this.openedAt = Date.now();\n return;\n }\n\n if (this.consecutiveFailures >= this.threshold) {\n this.state = 'open';\n this.openedAt = Date.now();\n }\n }\n\n getState(): CircuitState {\n return this.state;\n }\n}\n","import { LLMError } from '../types/errors.js';\n\nexport function defaultParseJson(content: string): unknown {\n try {\n return JSON.parse(content);\n } catch {\n return undefined;\n }\n}\n\n/**\n * Looks inside an unknown error value and pulls out an http status code\n * if one is present. Checks the status field first then the status code\n * field since different client libraries use different names for this.\n * Returns undefined when the error is not an object or carries no status\n */\nexport function extractStatus(err: unknown): number | undefined {\n if (!err || typeof err !== 'object') return undefined;\n\n const error = err as {\n status?: unknown;\n statusCode?: unknown;\n };\n\n if (typeof error.status === 'number') return error.status;\n if (typeof error.statusCode === 'number') return error.statusCode;\n\n return undefined;\n}\n\n/**\n * Runs an async function and cancels it if it takes longer than the given\n * timeout. Creates an internal abort controller that fires after the\n * timeout elapses, and combines it with any external signal the caller\n * passed in so either one can cancel the underlying call. If the internal\n * timeout triggers and the underlying operation aborts, the error is\n * converted into an LLMError with type \"timeout\". External cancellations\n * continue to propagate as aborted errors. The internal timer is always\n * cleared afterward, whether the function succeeds, fails, or is aborted,\n * so nothing is left running in the background.\n */\nexport async function withTimeout<T>(\n fn: (signal: AbortSignal) => Promise<T>,\n timeoutMs: number,\n externalSignal?: AbortSignal,\n): Promise<T> {\n const controller = new AbortController();\n\n const timer = setTimeout(() => {\n controller.abort();\n }, timeoutMs);\n\n const signal = externalSignal\n ? AbortSignal.any([externalSignal, controller.signal])\n : controller.signal;\n\n try {\n return await fn(signal);\n } catch (err) {\n if (\n controller.signal.aborted &&\n !externalSignal?.aborted &&\n err instanceof DOMException &&\n err.name === 'AbortError'\n ) {\n throw new LLMError('Request timed out', 'timeout');\n }\n\n throw err;\n } finally {\n clearTimeout(timer);\n }\n}\n\n/**\n * Exponential backoff with jitter, capped at maxDelayMs.\n * Jitter avoids thundering-herd retries when many callers back off in lockstep,\n * the cap prevents unbounded delays when maxRetries is high\n */\nexport function getBackoffDelay(baseDelayMs: number, attempt: number, maxDelayMs = 10_000): number {\n const exp = Math.min(baseDelayMs * 2 ** attempt, maxDelayMs);\n return exp / 2 + Math.random() * (exp / 2);\n}\n\n/**\n * Pauses execution for the given delay before a retry attempt. If an\n * abort signal is provided and it fires while waiting, the pending\n * timer is cancelled immediately and the wait rejects right away with\n * an aborted error instead of continuing to sit idle until the delay\n * would have finished on its own\n */\nexport async function waitForRetry(delay: number, signal?: AbortSignal): Promise<void> {\n await new Promise<void>((resolve, reject) => {\n const onAbort = () => {\n clearTimeout(timer);\n reject(new LLMError('Operation aborted', 'aborted'));\n };\n\n const timer = setTimeout(() => {\n signal?.removeEventListener('abort', onAbort);\n resolve();\n }, delay);\n\n signal?.addEventListener('abort', onAbort, { once: true });\n });\n}\n","export interface Logger {\n debug(message: string): void;\n warn(message: string): void;\n error(message: string, meta?: Record<string, unknown>): void;\n}\n\n/**\n * Default logger. `debug` is gated by the `debug` option on VernLLM\n * warn/error always fire since they indicate real problems (retries, cache failures)\n */\nexport class ConsoleLogger implements Logger {\n constructor(private debugEnabled: boolean) {}\n\n debug(message: string): void {\n if (this.debugEnabled) console.debug(message);\n }\n\n warn(message: string): void {\n console.warn(message);\n }\n\n error(message: string, meta?: Record<string, unknown>): void {\n console.error(message, meta ?? '');\n }\n}\n","export interface CacheAdapter<T = unknown> {\n get(key: string): Promise<{ hit: boolean; value: T | null }>;\n set(key: string, value: T, ttl: number): Promise<void>;\n delete?(key: string): Promise<void>;\n}\n\n/**\n * Trivial default so the package works out of the box with no external deps\n * Not shared across processes, swap in Redis/Upstash/etc for production\n */\nexport class InMemoryCacheAdapter<T = unknown> implements CacheAdapter<T> {\n private store = new Map<string, { value: T; expiresAt: number }>();\n\n constructor(private readonly maxSize = 1000) {}\n\n async get(key: string): Promise<{ hit: boolean; value: T | null }> {\n const entry = this.store.get(key);\n\n if (!entry) return { hit: false, value: null };\n\n if (Date.now() >= entry.expiresAt) {\n this.store.delete(key);\n return { hit: false, value: null };\n }\n\n return { hit: true, value: entry.value };\n }\n\n async set(key: string, value: T, ttl: number): Promise<void> {\n this.cleanupExpiredEntries();\n\n this.store.set(key, {\n value,\n expiresAt: Date.now() + ttl * 1000,\n });\n\n this.enforceSizeLimit();\n }\n\n async delete(key: string): Promise<void> {\n this.store.delete(key);\n }\n\n private cleanupExpiredEntries(): void {\n const now = Date.now();\n\n for (const [key, entry] of this.store) {\n if (now >= entry.expiresAt) {\n this.store.delete(key);\n }\n }\n }\n\n private enforceSizeLimit(): void {\n while (this.store.size > this.maxSize) {\n const oldestKey = this.store.keys().next().value;\n\n if (oldestKey === undefined) break;\n\n this.store.delete(oldestKey);\n }\n }\n}\n","import { randomUUID } from 'crypto';\n\nimport { CircuitBreaker } from './circuitBreaker.js';\nimport {\n defaultParseJson,\n extractStatus,\n withTimeout,\n getBackoffDelay,\n waitForRetry,\n} from './internal/vernLLM.utils.js';\nimport { ConsoleLogger, type Logger } from './logger.js';\nimport {\n InMemoryCacheAdapter,\n LLMError,\n type CacheAdapter,\n type CachedCallParams,\n type CallParams,\n type ConversationTurn,\n type LLMClient,\n type VernLLMOptions,\n} from './types/index.js';\n\n/**\n * A resilient wrapper around an LLM chat completions client, this is VernLLM!\n *\n * Adds retry with exponential backoff and jitter, per-attempt timeouts,\n * an optional circuit breaker, JSON parsing with optional schema\n * validation, usage tracking, and an optional response cache, all\n * configurable, all opt-in beyond sensible defaults\n */\nexport class VernLLM {\n private readonly client: LLMClient;\n private readonly model: string;\n\n private readonly maxRetries: number;\n private readonly timeoutMs: number;\n private readonly baseDelayMs: number;\n private readonly defaultMaxTokens: number;\n\n private readonly cache: CacheAdapter<unknown>;\n private readonly nonRetryableStatus: number[];\n\n private readonly parseJson: (content: string) => unknown;\n private readonly onUsage?: VernLLMOptions['onUsage'];\n\n private readonly logger: Logger;\n private readonly breaker?: CircuitBreaker;\n\n /**\n * @param options: Client, model, and all tunables (retries, timeout,\n * backoff, cache, circuit breaker, logger, etc). See VernLLMOptions in `types.ts`\n * for individual defaults\n */\n constructor(options: VernLLMOptions) {\n this.client = options.client;\n this.model = options.model;\n\n const retryConfig = this.resolveRetryConfig(options);\n this.maxRetries = retryConfig.maxRetries;\n this.timeoutMs = retryConfig.timeoutMs;\n this.baseDelayMs = retryConfig.baseDelayMs;\n this.defaultMaxTokens = retryConfig.defaultMaxTokens;\n\n this.cache = options.cache ?? new InMemoryCacheAdapter();\n this.nonRetryableStatus = options.nonRetryableStatus ?? [400, 401, 403];\n\n this.parseJson = options.parseJson ?? defaultParseJson;\n this.onUsage = options.onUsage;\n\n this.logger = this.resolveLogger(options);\n this.breaker = this.resolveCircuitBreaker(options);\n }\n\n /**\n * Resolves retry/timeout/token defaults from the given options,\n * falling back to the librarys built-in defaults for anything unset\n */\n private resolveRetryConfig(options: VernLLMOptions) {\n return {\n maxRetries: options.maxRetries ?? 1,\n timeoutMs: options.timeoutMs ?? 25_000,\n baseDelayMs: options.baseDelayMs ?? 500,\n defaultMaxTokens: options.defaultMaxTokens ?? 1000,\n };\n }\n\n /**\n * Returns the caller supplied logger, or a console-based logger whose\n * debug output is gated by the `debug` option (defaulting to on\n * outside production)\n */\n private resolveLogger(options: VernLLMOptions): Logger {\n return (\n options.logger ?? new ConsoleLogger(options.debug ?? process.env.NODE_ENV !== 'production')\n );\n }\n\n /**\n * Builds a circuit breaker if `circuitBreaker` is truthy on the\n * options. Passing `true` uses default thresholds, passing an options\n * object tunes them. Returns undefined when the breaker is disabled\n */\n private resolveCircuitBreaker(options: VernLLMOptions): CircuitBreaker | undefined {\n if (!options.circuitBreaker) return undefined;\n\n return new CircuitBreaker(options.circuitBreaker === true ? undefined : options.circuitBreaker);\n }\n\n /**\n * Makes a single logical LLM call, transparently retrying on failure\n * according to the configured retry policy\n *\n * Fails fast if the circuit breaker is open or the signal is already\n * aborted, before any request is dispatched. On exhausting all\n * retries, records a circuit breaker failure and rejects with a\n * normalized LLMError\n *\n * @param params : System/user content plus per call overrides\n * (model, temperature, jsonMode, schema, signal, etc)\n * @returns The parsed and optionally schema-validated response, or\n * the raw string content when jsonMode is disabled\n */\n async call<T = unknown>(params: CallParams<T>): Promise<T> {\n this.breaker?.assertClosed();\n\n if (params.signal?.aborted) {\n throw new LLMError('LLM request aborted', 'aborted');\n }\n\n const requestId = params.requestId ?? randomUUID();\n\n try {\n const result = await this.retryWithBackoff(\n () => this.executeCall(params, requestId),\n requestId,\n params.signal,\n );\n\n return result;\n } catch (error) {\n this.breaker?.recordFailure();\n throw this.normalizeError(error, params.signal);\n }\n }\n\n /**\n * Runs `fn`, retrying with backoff according to `shouldRetry` policy\n * Purely mechanical: knows nothing about LLM specifics beyond the retry\n * predicate, so its testable independent of request/response shaping\n */\n private async retryWithBackoff<T>(\n fn: () => Promise<T>,\n requestId: string,\n signal?: AbortSignal,\n ): Promise<T> {\n let lastError: unknown;\n\n for (let attempt = 0; attempt <= this.maxRetries; attempt++) {\n try {\n if (attempt > 0) {\n await this.recoverDelay(requestId, attempt, signal);\n }\n\n return await fn();\n } catch (error) {\n lastError = error;\n\n if (!this.shouldRetry(error, signal)) {\n break;\n }\n }\n }\n\n throw lastError;\n }\n\n /**\n * Converts any thrown value into a well-typed LLMError for the public\n * API surface. Preserves an existing LLMError as is, reports aborted\n * signals as such, classifies errors carrying an http status as\n * type api, and otherwise falls back to a generic unknown error.\n */\n private normalizeError(error: unknown, signal?: AbortSignal): LLMError {\n if (signal?.aborted) {\n return new LLMError('LLM request aborted', 'aborted');\n }\n\n if (error instanceof LLMError) {\n return error;\n }\n\n const status = extractStatus(error);\n\n if (status !== undefined) {\n return new LLMError('LLM request failed', 'api', status);\n }\n\n return new LLMError('LLM request failed', 'unknown');\n }\n\n /**\n * Performs a single attempt: builds the request, dispatches it with a\n * timeout, and shapes the response. Throws on an empty response so\n * the retry loop treats it like any other transient failure. Records\n * usage and a circuit breaker success before returning\n */\n private async executeCall<T>(params: CallParams<T>, requestId: string): Promise<T> {\n const { useJson, model, request } = this.buildRequestPayload(params);\n\n const response = await withTimeout(\n (attemptSignal) => this.client.chat.completions.create(request, { signal: attemptSignal }),\n this.timeoutMs,\n params.signal,\n );\n\n const content = response.choices?.[0]?.message?.content?.trim();\n\n if (!content) {\n throw new LLMError('Empty LLM response', 'api');\n }\n\n this.logger.debug(`[vern:${requestId}] output:\\n${content.slice(0, 800)}`);\n\n this.recordUsage(response, requestId, model);\n\n this.breaker?.recordSuccess();\n\n if (!useJson) {\n return content as T;\n }\n\n return this.parseAndValidate(content, params.schema);\n }\n\n /**\n * Anthropic and Gemini both require strict user/assistant alternation\n * (and reject or silently mishandle two consecutive same-role turns), so\n * this validates `history` up front rather than letting a malformed\n * request surface as a confusing provider-side error. Thrown as a\n * validation LLMError, which `shouldRetry` never retries, since retrying\n * the same malformed input can't succeed\n */\n private validateHistory(history: ConversationTurn[]): void {\n let previousRole: 'user' | 'assistant' | undefined;\n\n for (const [index, turn] of history.entries()) {\n if (turn.role !== 'user' && turn.role !== 'assistant') {\n throw new LLMError(\n `Invalid history[${index}].role \"${turn.role}\": must be \"user\" or \"assistant\"`,\n 'validation',\n );\n }\n\n if (turn.role === previousRole) {\n throw new LLMError(\n `history must alternate user/assistant turns: consecutive \"${turn.role}\" turns at history[${index - 1}] and history[${index}]`,\n 'validation',\n );\n }\n\n previousRole = turn.role;\n }\n\n if (previousRole === 'user') {\n throw new LLMError(\n 'The last entry in history is a \"user\" turn, which would collide with the current userContent turn. history must end with an \"assistant\" turn (or be empty).',\n 'validation',\n );\n }\n }\n\n /**\n * Applies per call defaults and shapes the params into the request\n * object expected by the underlying client, including the resolved\n * response format. Also returns whether JSON parsing should be\n * applied to the response and which model was ultimately used\n */\n private buildRequestPayload<T>(params: CallParams<T>) {\n const {\n systemPrompt,\n userContent,\n history = [],\n temperature = 0.2,\n jsonMode = true,\n maxTokens = this.defaultMaxTokens,\n model = this.model,\n reasoningEffort,\n jsonSchema,\n } = params;\n\n const useJson = jsonMode || Boolean(jsonSchema);\n const responseFormat = this.buildResponseFormat(jsonSchema, useJson);\n\n this.validateHistory(history);\n\n const request = {\n model,\n temperature,\n max_tokens: maxTokens,\n ...(responseFormat ? { response_format: responseFormat } : {}),\n ...(reasoningEffort ? { reasoning_effort: reasoningEffort } : {}),\n messages: [\n ...(systemPrompt ? [{ role: 'system' as const, content: systemPrompt }] : []),\n ...history.map((turn) => ({ role: turn.role, content: turn.content })),\n { role: 'user' as const, content: userContent },\n ],\n };\n\n return { useJson, model, request };\n }\n\n /**\n * Chooses the response format to send to the provider. A provider\n * native json schema takes priority when supplied, constraining\n * generation directly, otherwise falls back to the looser json\n * object mode when JSON output is requested, or no format at all\n * for plain text responses\n */\n private buildResponseFormat(jsonSchema: CallParams<unknown>['jsonSchema'], useJson: boolean) {\n if (jsonSchema) {\n return {\n type: 'json_schema' as const,\n json_schema: {\n name: jsonSchema.name,\n schema: jsonSchema.schema,\n strict: jsonSchema.strict ?? true,\n description: jsonSchema.description,\n },\n };\n }\n\n return useJson ? { type: 'json_object' as const } : undefined;\n }\n\n /**\n * Reports token usage to the caller supplied onUsage callback, when\n * both a callback was configured and the provider actually returned\n * usage data on this response. A no op otherwise.\n */\n private recordUsage(\n response: Awaited<ReturnType<LLMClient['chat']['completions']['create']>>,\n requestId: string,\n model: string,\n ): void {\n if (!response.usage || !this.onUsage) return;\n\n this.onUsage({\n promptTokens: response.usage.prompt_tokens ?? 0,\n completionTokens: response.usage.completion_tokens ?? 0,\n totalTokens: response.usage.total_tokens ?? 0,\n requestId,\n model,\n });\n }\n\n /**\n * Parses the raw response content as JSON and, when a schema is\n * supplied, validates the parsed value against it. Throws a parse\n * type LLMError on malformed JSON and a validation type LLMError,\n * carrying the schemas issues, on a failed validation\n */\n private parseAndValidate<T>(content: string, schema?: CallParams<T>['schema']): T {\n let parsed: unknown;\n\n try {\n parsed = this.parseJson(content);\n } catch {\n throw new LLMError('Invalid JSON response', 'parse');\n }\n\n if (parsed === null || parsed === undefined) {\n throw new LLMError('Invalid JSON response', 'parse');\n }\n\n if (!schema) {\n return parsed as T;\n }\n\n const result = schema.safeParse(parsed);\n\n if (!result.success) {\n throw new LLMError('Schema validation failed', 'validation', undefined, result.error);\n }\n\n return result.data;\n }\n\n /**\n * Waits out the backoff delay for a given retry attempt, logging the\n * attempt for observability before the wait begins. Rejects early if\n * the signal aborts during the wait\n */\n private async recoverDelay(requestId: string, attempt: number, signal?: AbortSignal) {\n const delay = getBackoffDelay(this.baseDelayMs, attempt);\n\n this.logger.warn(\n `[vern:${requestId}] recovery attempt ${attempt}/${this.maxRetries}, waiting ${delay}ms`,\n );\n\n await waitForRetry(delay, signal);\n }\n\n /**\n * Decides whether a failed attempt is worth retrying. Never retries\n * once the signal has aborted, never retries a parse or validation\n * failure since those stem from the response content rather than a\n * transient fault, and never retries a status code the caller has\n * marked as non retryable. Retries everything else\n */\n private shouldRetry(error: unknown, signal?: AbortSignal): boolean {\n if (signal?.aborted) {\n return false;\n }\n\n if (error instanceof LLMError && (error.type === 'parse' || error.type === 'validation')) {\n return false;\n }\n\n const status = extractStatus(error);\n\n if (status !== undefined && this.nonRetryableStatus.includes(status)) {\n return false;\n }\n\n return true;\n }\n\n /**\n * Removes a cached response by key when the configured cache adapter\n * supports deletion.\n *\n * Cache invalidation remains the responsibility of the caller because\n * only the application knows when cached data is stale.\n */\n async deleteCache(key: string): Promise<void> {\n if (!this.cache.delete) {\n return;\n }\n\n await this.cache.delete(key);\n }\n\n /**\n * Thin cache wrapper around caller supplied logic. `params.fn` is expected\n * to be a call that itself invokes `this.call(...)` (see `cachedLLMCall`\n * below for a convenience wrapper that wires this up automatically),\n * `cachedCall` does not itself apply retry/timeout policy.\n */\n async cachedCall<T>(params: CachedCallParams<T>): Promise<T> {\n const cached = await this.cache.get(params.cacheKey);\n\n if (cached.hit) {\n return cached.value as T;\n }\n\n try {\n await params.reserveUsage?.();\n\n const result = await params.fn();\n\n try {\n await this.cache.set(params.cacheKey, result, params.ttl);\n } catch (error) {\n this.logger.error('[VernLLM] cache write failed', {\n message: error instanceof Error ? error.message : 'unknown',\n });\n }\n\n return result;\n } catch (error) {\n try {\n await params.refundUsage?.();\n } catch (refundError) {\n this.logger.error('[VernLLM] refundUsage failed', {\n message: refundError instanceof Error ? refundError.message : 'unknown',\n });\n }\n\n throw error;\n }\n }\n\n /**\n * Convenience wrapper composing `call` + `cachedCall`, so cached LLM calls\n * automatically get retry/timeout/circuit-breaker behavior without callers\n * having to remember to wire `fn: () => this.call(...)` themselves\n */\n async cachedLLMCall<T>(\n params: Omit<CachedCallParams<T>, 'fn'> & { call: CallParams<T> },\n ): Promise<T> {\n const { call: callParams, ...cacheParams } = params;\n\n return this.cachedCall({\n ...cacheParams,\n fn: () => this.call(callParams),\n });\n }\n\n /**\n * Returns the current circuit breaker state, or undefined when no\n * circuit breaker was configured on this instance\n */\n getCircuitState() {\n return this.breaker?.getState();\n }\n}\n","import type { LLMClient } from '../types/index.js';\n\n/** Minimal structural type for the Anthropic SDKs `messages.create` */\nexport interface AnthropicClient {\n messages: {\n create(\n params: {\n model: string;\n max_tokens: number;\n temperature?: number;\n system?: string;\n messages: Array<{ role: 'user' | 'assistant'; content: string }>;\n tools?: Array<{\n name: string;\n description?: string;\n input_schema: Record<string, unknown>;\n }>;\n tool_choice?: { type: 'tool'; name: string };\n },\n options: { signal: AbortSignal },\n ): Promise<{\n content: Array<{ type: string; text?: string; name?: string; input?: unknown }>;\n usage?: { input_tokens?: number; output_tokens?: number };\n }>;\n };\n}\n\n/**\n * Wraps an Anthropic SDK client so it satisfies the same `LLMClient`\n * interface VernLLM uses for OpenAI/Groq.\n *\n * `response_format: json_schema` is mapped to Anthropics forced tool-use:\n * a single tool is defined with `input_schema` set to the caller's schema,\n * and `tool_choice` forces the model to call it, so the output is\n * provider-constrained to match the schema rather than merely instructed\n * to via prompt text (the same guarantee OpenAIs native `json_schema` mode\n * gives, built on Anthropics tool-calling primitive instead).\n *\n * `response_format: json_object` (no schema to build a tool from) falls\n * back to a system-prompt instruction, since theres nothing to constrain\n * generation against.\n */\nexport function fromAnthropic(anthropicClient: AnthropicClient): LLMClient {\n return {\n chat: {\n completions: {\n async create(params, options) {\n const systemMessage = params.messages.find((m) => m.role === 'system');\n // Keep both user and assistant turns, in order, so multi-turn history\n // survives instead of collapsing to consecutive user messages.\n const conversationMessages = params.messages.filter(\n (m): m is typeof m & { role: 'user' | 'assistant' } =>\n m.role === 'user' || m.role === 'assistant',\n );\n\n const toolName =\n params.response_format?.type === 'json_schema'\n ? params.response_format.json_schema.name\n : undefined;\n\n let jsonInstruction: string | undefined;\n let tools:\n | NonNullable<Parameters<AnthropicClient['messages']['create']>[0]['tools']>\n | undefined;\n\n if (params.response_format?.type === 'json_schema' && toolName) {\n const { schema, description } = params.response_format.json_schema;\n tools = [{ name: toolName, description, input_schema: schema }];\n } else if (params.response_format?.type === 'json_object') {\n // No schema to build a tool from, fall back to a prompt instruction\n jsonInstruction = 'Respond with valid JSON only, no prose or markdown fences.';\n }\n\n // `reasoning_effort` (OpenAI o-series/gpt-5 style) has no direct Anthropic\n // equivalent, Claudes extended thinking uses a token budget, not a tier\n // string, so its intentionally dropped here rather than guessed at.\n\n const system = [systemMessage?.content, jsonInstruction].filter(Boolean).join('\\n\\n');\n\n const response = await anthropicClient.messages.create(\n {\n model: params.model,\n max_tokens: params.max_tokens,\n temperature: params.temperature,\n system: system || undefined,\n messages: conversationMessages.map((m) => ({ role: m.role, content: m.content })),\n ...(tools ? { tools, tool_choice: { type: 'tool' as const, name: toolName! } } : {}),\n },\n options,\n );\n\n let text: string;\n if (toolName) {\n // Forced tool-use: the schema-conforming payload arrives as the\n // tool_use block's already-parsed `input`, not as text. Re-serialize\n // it to JSON so it flows through the same string-content contract\n // every other adapter uses (VernLLM JSON.parses the content itself).\n const toolUse = response.content.find(\n (block) => block.type === 'tool_use' && block.name === toolName,\n );\n text = toolUse ? JSON.stringify(toolUse.input) : '';\n } else {\n text = response.content.find((block) => block.type === 'text')?.text ?? '';\n }\n\n return {\n choices: [{ message: { content: text } }],\n usage: {\n prompt_tokens: response.usage?.input_tokens,\n completion_tokens: response.usage?.output_tokens,\n total_tokens:\n (response.usage?.input_tokens ?? 0) + (response.usage?.output_tokens ?? 0),\n },\n };\n },\n },\n },\n };\n}\n","import type { LLMClient } from '../types/index.js';\n\n/**\n * Minimal structural type for Geminis `generateContent`, matching both the\n * legacy `@google/generative-ai` SDKs `model.generateContent(...)` and the\n * newer `@google/genai` SDKs `ai.models.generateContent({ model, ... })`\n * closely enough to adapt either — pass whichever `.generateContent` you have.\n */\nexport interface GeminiClient {\n generateContent(\n params: {\n model?: string;\n contents: Array<{ role: 'user' | 'model'; parts: Array<{ text: string }> }>;\n systemInstruction?: { parts: Array<{ text: string }> };\n generationConfig?: {\n temperature?: number;\n maxOutputTokens?: number;\n responseMimeType?: string;\n responseSchema?: Record<string, unknown>;\n };\n },\n options: { signal: AbortSignal },\n ): Promise<{\n candidates?: Array<{ content?: { parts?: Array<{ text?: string }> } }>;\n usageMetadata?: {\n promptTokenCount?: number;\n candidatesTokenCount?: number;\n totalTokenCount?: number;\n };\n }>;\n}\n\n/**\n * Wraps a Gemini client so it satisfies the `LLMClient` interface VernLLM\n * uses for OpenAI/Groq. Geminis shape differs on nearly every axis: a\n * `contents` array instead of `messages`, a separate `systemInstruction`\n * field instead of a `system` role message, `generationConfig` instead of\n * top-level `temperature`/`max_tokens`, and native JSON Schema support via\n * `responseMimeType: 'application/json'` + `responseSchema` (so `jsonSchema`\n * is provider-enforced here, unlike the Anthropic adapters prompt-embedding\n * fallback). `reasoning_effort` has no equivalent. Geminis thinking models\n * use a token budget, not an effort tier, so its dropped, same as Anthropic.\n */\nexport function fromGemini(geminiClient: GeminiClient): LLMClient {\n return {\n chat: {\n completions: {\n async create(params, options) {\n const systemMessage = params.messages.find((m) => m.role === 'system');\n // Keep both user and assistant turns, in order. Gemini calls the\n // assistant role 'model' rather than 'assistant'.\n const conversationMessages = params.messages.filter(\n (m) => m.role === 'user' || m.role === 'assistant',\n );\n\n const wantsJson = Boolean(params.response_format);\n const generationConfig: NonNullable<\n Parameters<GeminiClient['generateContent']>[0]['generationConfig']\n > = {\n temperature: params.temperature,\n maxOutputTokens: params.max_tokens,\n };\n\n if (wantsJson) {\n generationConfig.responseMimeType = 'application/json';\n }\n if (params.response_format?.type === 'json_schema') {\n generationConfig.responseSchema = params.response_format.json_schema.schema;\n }\n\n const response = await geminiClient.generateContent(\n {\n model: params.model,\n contents: conversationMessages.map((m) => ({\n role: m.role === 'assistant' ? ('model' as const) : ('user' as const),\n parts: [{ text: m.content }],\n })),\n systemInstruction: systemMessage\n ? { parts: [{ text: systemMessage.content }] }\n : undefined,\n generationConfig,\n },\n options,\n );\n\n const text =\n response.candidates?.[0]?.content?.parts?.map((p) => p.text ?? '').join('') ?? '';\n\n return {\n choices: [{ message: { content: text } }],\n usage: {\n prompt_tokens: response.usageMetadata?.promptTokenCount,\n completion_tokens: response.usageMetadata?.candidatesTokenCount,\n total_tokens: response.usageMetadata?.totalTokenCount,\n },\n };\n },\n },\n },\n };\n}\n","import type { LLMClient } from '../types/index.js';\n\n/**\n * Minimal structural type matching AWS Bedrocks Converse API. This is\n * intentionally NOT `BedrockRuntimeClient` itself, the AWS SDK v3 client\n * exposes `.send(command)`, not a direct `.converse()` method, and pulling\n * in `@aws-sdk/client-bedrock-runtime` as a dependency just for its types\n * isn't worth it for a structural adapter. Wrap your client, e.g:\n *\n * ```ts\n * import { BedrockRuntimeClient, ConverseCommand } from '@aws-sdk/client-bedrock-runtime';\n * const client = new BedrockRuntimeClient({ region: 'us-east-1' });\n * const converseClient = {\n * converse: (params, options) =>\n * client.send(new ConverseCommand(params), { abortSignal: options.signal }),\n * };\n * ```\n */\nexport interface BedrockConverseClient {\n converse(\n params: {\n modelId: string;\n messages: Array<{ role: 'user' | 'assistant'; content: Array<{ text: string }> }>;\n system?: Array<{ text: string }>;\n inferenceConfig?: { temperature?: number; maxTokens?: number };\n toolConfig?: {\n tools: Array<{\n toolSpec: {\n name: string;\n description?: string;\n inputSchema: { json: Record<string, unknown> };\n };\n }>;\n toolChoice?: { tool: { name: string } };\n };\n },\n options: { signal: AbortSignal },\n ): Promise<{\n output?: {\n message?: {\n content?: Array<{ text?: string; toolUse?: { name?: string; input?: unknown } }>;\n };\n };\n usage?: { inputTokens?: number; outputTokens?: number; totalTokens?: number };\n }>;\n}\n\n/**\n * Wraps a Bedrock Converse-API client so it satisfies the `LLMClient`\n * interface VernLLM uses for OpenAI/Groq. The Converse API is unified\n * across Bedrocks model families (Anthropic, Titan, Llama, Mistral, etc.),\n * so unlike raw per-model Bedrock invocation, this one adapter works\n * regardless of which underlying model `modelId` points at, as long as\n * that model supports Converse (most current-generation ones do)\n *\n * `response_format: json_schema` is mapped to Converses `toolConfig`: a\n * single tool is defined from the schema and `toolChoice` forces the model\n * to call it, constraining output at generation time rather than merely\n * instructing for it via prompt text. Native tool support varies by model\n * family (most current-generation ones support it via Converse; check your\n * specific `modelId` if a call fails with an unsupported-parameter error).\n * `response_format: json_object` (no schema to build a tool from) and\n * `reasoning_effort` (no Converse equivalent) fall back to a system-prompt\n * instruction and are dropped respectively.\n */\nexport function fromBedrock(bedrockClient: BedrockConverseClient): LLMClient {\n return {\n chat: {\n completions: {\n async create(params, options) {\n const systemMessage = params.messages.find((m) => m.role === 'system');\n // Keep both user and assistant turns, in order, so conversation\n // history survives instead of collapsing to consecutive user turns.\n const conversationMessages = params.messages.filter(\n (m): m is typeof m & { role: 'user' | 'assistant' } =>\n m.role === 'user' || m.role === 'assistant',\n );\n\n const toolName =\n params.response_format?.type === 'json_schema'\n ? params.response_format.json_schema.name\n : undefined;\n\n let jsonInstruction: string | undefined;\n let toolConfig:\n | NonNullable<Parameters<BedrockConverseClient['converse']>[0]['toolConfig']>\n | undefined;\n\n if (params.response_format?.type === 'json_schema' && toolName) {\n const { schema, description } = params.response_format.json_schema;\n toolConfig = {\n tools: [{ toolSpec: { name: toolName, description, inputSchema: { json: schema } } }],\n toolChoice: { tool: { name: toolName } },\n };\n } else if (params.response_format?.type === 'json_object') {\n // No schema to build a tool from, fall back to a prompt instruction\n jsonInstruction = 'Respond with valid JSON only, no prose or markdown fences.';\n }\n\n const systemParts = [systemMessage?.content, jsonInstruction].filter((s): s is string =>\n Boolean(s),\n );\n\n const response = await bedrockClient.converse(\n {\n modelId: params.model,\n messages: conversationMessages.map((m) => ({\n role: m.role,\n content: [{ text: m.content }],\n })),\n system: systemParts.length ? systemParts.map((text) => ({ text })) : undefined,\n inferenceConfig: {\n temperature: params.temperature,\n maxTokens: params.max_tokens,\n },\n ...(toolConfig ? { toolConfig } : {}),\n },\n options,\n );\n\n let text: string;\n if (toolName) {\n // Forced tool-use: the schema-conforming payload arrives as the\n // toolUse content block's already-parsed `input`, not as text.\n // Re-serialize it to JSON so it flows through the same\n // string-content contract every other adapter uses.\n const toolUseBlock = response.output?.message?.content?.find(\n (block) => block.toolUse?.name === toolName,\n );\n text = toolUseBlock?.toolUse ? JSON.stringify(toolUseBlock.toolUse.input) : '';\n } else {\n text = response.output?.message?.content?.map((c) => c.text ?? '').join('') ?? '';\n }\n\n return {\n choices: [{ message: { content: text } }],\n usage: {\n prompt_tokens: response.usage?.inputTokens,\n completion_tokens: response.usage?.outputTokens,\n total_tokens: response.usage?.totalTokens,\n },\n };\n },\n },\n },\n };\n}\n","import type { LLMClient } from '../types/index.js';\n\n/** The chat-completion-shaped request VernLLM builds internally */\ntype ChatRequest = Parameters<LLMClient['chat']['completions']['create']>[0];\n\nexport interface FetchAdapterConfig {\n /** Endpoint URL, or a function of the request in case it depends on model/params */\n url: string | ((params: ChatRequest) => string);\n /** Static headers, or a function (sync or async) for things like refreshed auth tokens */\n headers?:\n | Record<string, string>\n | (() => Record<string, string> | Promise<Record<string, string>>);\n /** HTTP method. Default 'POST' */\n method?: string;\n /** Maps VernLLMs internal chat-completion request into the providers raw request body */\n mapRequest: (params: ChatRequest) => unknown;\n /**\n * Maps the providers raw JSON response into `{ content, usage? }`\n * `content` is the assistants text (JSON string when JSON mode was requested)\n */\n mapResponse: (json: unknown) => {\n content: string;\n usage?: { promptTokens?: number; completionTokens?: number; totalTokens?: number };\n };\n}\n\n/**\n * A fetch-based escape hatch for providers with no SDK, or where pulling one\n * in isnt worth it. You supply the URL, headers, and two small mapping\n * functions; this handles the HTTP call and slots the result into the same\n * `LLMClient` shape every other adapter produces, so retries, timeouts,\n * the circuit breaker, and JSON/schema handling all still work unmodified\n *\n * Non-2xx responses throw an error with `.status` set to the HTTP status\n * code, so VernLLMs `nonRetryableStatus` handling (e.g. failing fast on\n * 401/403) applies here too\n */\nexport function fromFetch(config: FetchAdapterConfig): LLMClient {\n return {\n chat: {\n completions: {\n async create(params, options) {\n const url = typeof config.url === 'function' ? config.url(params) : config.url;\n const headers =\n typeof config.headers === 'function' ? await config.headers() : config.headers;\n\n const res = await fetch(url, {\n method: config.method ?? 'POST',\n headers: { 'Content-Type': 'application/json', ...headers },\n body: JSON.stringify(config.mapRequest(params)),\n signal: options.signal,\n });\n\n if (!res.ok) {\n const body = await res.text().catch(() => '');\n const err = new Error(\n `Fetch adapter request failed (${res.status}): ${body.slice(0, 500)}`,\n ) as Error & { status?: number };\n err.status = res.status;\n throw err;\n }\n\n const json = await res.json();\n const { content, usage } = config.mapResponse(json);\n\n return {\n choices: [{ message: { content } }],\n usage: usage\n ? {\n prompt_tokens: usage.promptTokens,\n completion_tokens: usage.completionTokens,\n total_tokens: usage.totalTokens,\n }\n : undefined,\n };\n },\n },\n },\n };\n}\n","import type { LLMClient } from '../types/index.js';\n\n/**\n * Passthrough adapter for any SDK/client whose `chat.completions.create`\n * already matches the OpenAI wire format 1:1 : this covers most hosted\n * inference providers, since \"OpenAI-compatible\" is a de facto standard for\n * chat completion APIs. No transformation happens here, this exists purely\n * so call sites read clearly (`fromMistral(client)` vs handing a Mistral\n * client to something typed for OpenAI) and so a real transformation could\n * be added later, per-provider, without a breaking change.\n *\n * Not every SDKs own TypeScript types line up exactly with `LLMClient`\n * (extra fields, stricter unions, etc.), so this takes `unknown` and casts:\n * the actual compatibility contract is the JSON each provider sends and\n * receives over the wire, not the SDKs TS types.\n */\nexport function fromOpenAICompatible(client: unknown): LLMClient {\n return client as LLMClient;\n}\n\n/** Groqs SDK matches the OpenAI wire format */\nexport const fromGroq = fromOpenAICompatible;\n\n/** Mistrals `chat.completions`-shaped client (or their OpenAI-compat endpoint) */\nexport const fromMistral = fromOpenAICompatible;\n\n/** DeepSeeks API is OpenAI-compatible */\nexport const fromDeepSeek = fromOpenAICompatible;\n\n/** Cerebras inference API is OpenAI-compatible */\nexport const fromCerebras = fromOpenAICompatible;\n\n/** Together AIs API is OpenAI-compatible */\nexport const fromTogether = fromOpenAICompatible;\n\n/** Fireworks AIs API is OpenAI-compatible */\nexport const fromFireworks = fromOpenAICompatible;\n\n/**\n * Ollama exposes an OpenAI-compatible endpoint at `/v1/chat/completions`\n * (as opposed to its native `/api/chat` format, which differs). Point an\n * OpenAI SDK instances `baseURL` at your Ollama server and pass it here:\n * this does not talk to Ollamas native API directly.\n */\nexport const fromOllama = fromOpenAICompatible;\n\n/** OpenRouter's API is OpenAI-compatible */\nexport const fromOpenRouter = fromOpenAICompatible;\n\n/** Perplexity's API is OpenAI-compatible */\nexport const fromPerplexity = fromOpenAICompatible;\n\n/** DeepInfra's API is OpenAI-compatible */\nexport const fromDeepInfra = fromOpenAICompatible;\n\n/** Novita's API is OpenAI-compatible */\nexport const fromNovita = fromOpenAICompatible;\n\n/** Hyperbolic's API is OpenAI-compatible */\nexport const fromHyperbolic = fromOpenAICompatible;\n\n/** Moonshot's (Kimi) API is OpenAI-compatible */\nexport const fromMoonshot = fromOpenAICompatible;\n\n/** Zhipu's (GLM) API is OpenAI-compatible */\nexport const fromZhipu = fromOpenAICompatible;\n\n/**\n * LM Studio exposes an OpenAI-compatible endpoint at `/v1/chat/completions`.\n * Point an OpenAI SDK instance's `baseURL` at your local LM Studio server.\n */\nexport const fromLMStudio = fromOpenAICompatible;\n\n/**\n * vLLM's OpenAI-compatible server mode exposes `/v1/chat/completions`.\n * Point an OpenAI SDK instance's `baseURL` at your vLLM server.\n */\nexport const fromVLLM = fromOpenAICompatible;\n\n/** xAI's Grok API is OpenAI-compatible */\nexport const fromXAI = fromOpenAICompatible;\n\n/** NVIDIA NIM's hosted and self-hosted endpoints are OpenAI-compatible */\nexport const fromNvidiaNIM = fromOpenAICompatible;\n\n/** Vercel AI Gateway is OpenAI-compatible */\nexport const fromVercelAIGateway = fromOpenAICompatible;\n\n/** Cloudflare Workers AI exposes an OpenAI-compatible endpoint */\nexport const fromCloudflareWorkersAI = fromOpenAICompatible;\n\n/** GitHub Models is OpenAI-compatible */\nexport const fromGitHubModels = fromOpenAICompatible;\n\n/** Nebius AI Studio is OpenAI-compatible */\nexport const fromNebius = fromOpenAICompatible;\n\n/** SambaNova Cloud's API is OpenAI-compatible */\nexport const fromSambaNova = fromOpenAICompatible;\n\n/** Baseten's model hosting exposes an OpenAI-compatible endpoint */\nexport const fromBaseten = fromOpenAICompatible;\n\n/** Featherless AI's API is OpenAI-compatible */\nexport const fromFeatherless = fromOpenAICompatible;\n\n/** Friendli AI's serving endpoint is OpenAI-compatible */\nexport const fromFriendli = fromOpenAICompatible;\n\n/** SiliconFlow's API is OpenAI-compatible */\nexport const fromSiliconFlow = fromOpenAICompatible;\n\n/** Parasail's inference API is OpenAI-compatible */\nexport const fromParasail = fromOpenAICompatible;\n\n/** StepFun's API is OpenAI-compatible */\nexport const fromStepFun = fromOpenAICompatible;\n\n/** MiniMax's API is OpenAI-compatible */\nexport const fromMiniMax = fromOpenAICompatible;\n\n/** Lambda Labs' Inference API is OpenAI-compatible */\nexport const fromLambdaLabs = fromOpenAICompatible;\n\n/** Snowflake Cortex's LLM endpoint is OpenAI-compatible */\nexport const fromSnowflakeCortex = fromOpenAICompatible;\n\n/** Anyscale Endpoints' API is OpenAI-compatible */\nexport const fromAnyscale = fromOpenAICompatible;\n\n/** Lepton AI's inference API is OpenAI-compatible */\nexport const fromLepton = fromOpenAICompatible;\n\n/** kluster.ai's inference API is OpenAI-compatible */\nexport const fromKlusterAI = fromOpenAICompatible;\n\n/** Inference.net's API is OpenAI-compatible */\nexport const fromInferenceNet = fromOpenAICompatible;\n\n/** Infermatic's API is OpenAI-compatible */\nexport const fromInfermatic = fromOpenAICompatible;\n\n/** AtlasCloud's inference API is OpenAI-compatible */\nexport const fromAtlasCloud = fromOpenAICompatible;\n\n/** 01.AI's (Yi models) API is OpenAI-compatible */\nexport const from01AI = fromOpenAICompatible;\n"],"mappings":";;;AASA,IAAa,WAAb,cAA8B,MAAM;CAClC,YACEA,SACOC,MACAC,QACAC,QACP;AACA,QAAM,QAAQ;EAQjB,KAZU;EAYT,KAXS;EAWR,KAVQ;AAGP,OAAK,OAAO;CACb;AACF;AAED,SAAgB,WAAWC,KAA+B;AACxD,QAAO,eAAe;AACvB;;;;;;;;;;ACND,IAAa,iBAAb,MAA4B;CAC1B,AAAQ,QAAsB;CAC9B,AAAQ,sBAAsB;CAC9B,AAAQ,WAAW;CACnB,AAAQ;CACR,AAAQ;CAER,YAAYC,UAAiC,CAAE,GAAE;AAC/C,OAAK,YAAY,QAAQ,aAAa;AACtC,OAAK,aAAa,QAAQ,cAAc;CACzC;;CAGD,eAAqB;AACnB,MAAI,KAAK,UAAU,OAAQ;EAE3B,MAAM,UAAU,KAAK,KAAK,GAAG,KAAK;AAClC,MAAI,WAAW,KAAK,YAAY;AAC9B,QAAK,QAAQ;AACb;EACD;AAED,QAAM,IAAI,UACP,qCAAqC,KAAK,oBAAoB,4BAA4B,KAAK,MAAM,KAAK,aAAa,WAAW,IAAK,CAAC,KACzI;CAEH;CAED,gBAAsB;AACpB,OAAK,sBAAsB;AAC3B,OAAK,QAAQ;CACd;CAED,gBAAsB;AACpB,OAAK,uBAAuB;AAE5B,MAAI,KAAK,UAAU,aAAa;AAE9B,QAAK,QAAQ;AACb,QAAK,WAAW,KAAK,KAAK;AAC1B;EACD;AAED,MAAI,KAAK,uBAAuB,KAAK,WAAW;AAC9C,QAAK,QAAQ;AACb,QAAK,WAAW,KAAK,KAAK;EAC3B;CACF;CAED,WAAyB;AACvB,SAAO,KAAK;CACb;AACF;;;;ACnED,SAAgB,iBAAiBC,SAA0B;AACzD,KAAI;AACF,SAAO,KAAK,MAAM,QAAQ;CAC3B,QAAO;AACN;CACD;AACF;;;;;;;AAQD,SAAgB,cA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,MAAa,iBAAiB;;AAG9B,MAAa,eAAe;;AAG5B,MAAa,YAAY;;;;;AAMzB,MAAa,eAAe;;;;;AAM5B,MAAa,WAAW;;AAGxB,MAAa,UAAU;;AAGvB,MAAa,gBAAgB;;AAG7B,MAAa,sBAAsB;;AAGnC,MAAa,0BAA0B;;AAGvC,MAAa,mBAAmB;;AAGhC,MAAa,aAAa;;AAG1B,MAAa,gBAAgB;;AAG7B,MAAa,cAAc;;AAG3B,MAAa,kBAAkB;;AAG/B,MAAa,eAAe;;AAG5B,MAAa,kBAAkB;;AAG/B,MAAa,eAAe;;AAG5B,MAAa,cAAc;;AAG3B,MAAa,cAAc;;AAG3B,MAAa,iBAAiB;;AAG9B,MAAa,sBAAsB;;AAGnC,MAAa,eAAe;;AAG5B,MAAa,aAAa;;AAG1B,MAAa,gBAAgB;;AAG7B,MAAa,mBAAmB;;AAGhC,MAAa,iBAAiB;;AAG9B,MAAa,iBAAiB;;AAG9B,MAAa,WAAW"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["message: string","type: LLMErrorType","status?: number","issues?: unknown","err: unknown","options: CircuitBreakerOptions","content: string","err: unknown","fn: (signal: AbortSignal) => Promise<T>","timeoutMs: number","externalSignal?: AbortSignal","baseDelayMs: number","attempt: number","delay: number","signal?: AbortSignal","debugEnabled: boolean","message: string","meta?: Record<string, unknown>","key: string","value: T","ttl: number","options: VernLLMOptions","params: CallParams<T>","fn: () => Promise<T>","requestId: string","signal?: AbortSignal","lastError: unknown","error: unknown","history: ConversationTurn[]","previousRole: 'user' | 'assistant' | undefined","jsonSchema: CallParams<unknown>['jsonSchema']","useJson: boolean","response: Awaited<ReturnType<LLMClient['chat']['completions']['create']>>","model: string","content: string","schema?: CallParams<T>['schema']","parsed: unknown","attempt: number","key: string","params: CachedCallParams<T>","params: Omit<CachedCallParams<T>, 'fn'> & { call: CallParams<T> }","anthropicClient: AnthropicClient","jsonInstruction: string | undefined","tools:\n | NonNullable<Parameters<AnthropicClient['messages']['create']>[0]['tools']>\n | undefined","text: string","geminiClient: GeminiClient","generationConfig: NonNullable<\n Parameters<GeminiClient['generateContent']>[0]['generationConfig']\n >","bedrockClient: BedrockConverseClient","jsonInstruction: string | undefined","toolConfig:\n | NonNullable<Parameters<BedrockConverseClient['converse']>[0]['toolConfig']>\n | undefined","text","text: string","config: FetchAdapterConfig","client: unknown"],"sources":["../src/types/errors.ts","../src/circuitBreaker.ts","../src/internal/vernLLM.utils.ts","../src/logger.ts","../src/types/cache.ts","../src/vernLLM.ts","../src/adapters/anthropic.ts","../src/adapters/gemini.ts","../src/adapters/bedrock.ts","../src/adapters/fetch.ts","../src/adapters/openaiCompatible.ts"],"sourcesContent":["export type LLMErrorType =\n | 'timeout'\n | 'api'\n | 'parse'\n | 'validation'\n | 'circuit_open'\n | 'unknown'\n | 'aborted';\n\nexport class LLMError extends Error {\n constructor(\n message: string,\n public type: LLMErrorType,\n public status?: number,\n public issues?: unknown,\n ) {\n super(message);\n this.name = 'LLMError';\n }\n}\n\nexport function isLLMError(err: unknown): err is LLMError {\n return err instanceof LLMError;\n}\n","import { LLMError } from './types/errors.js';\n\nexport interface CircuitBreakerOptions {\n /** Consecutive failures before the circuit opens, default 5 */\n threshold?: number;\n /** How long the circuit stays open before allowing a trial request, in ms. Default 30000 */\n cooldownMs?: number;\n}\n\ntype CircuitState = 'closed' | 'open' | 'half-open';\n\n/**\n * Per retry VernLLM-instance circuit breaker. Tracks consecutive failures across\n * calls. Once the threshold is hit, short-circuits new calls with an\n * LLMError('circuit_open') instead of hitting the provider, until the\n * cooldown elapses and a single trial call is allowed through\n */\nexport class CircuitBreaker {\n private state: CircuitState = 'closed';\n private consecutiveFailures = 0;\n private openedAt = 0;\n private threshold: number;\n private cooldownMs: number;\n\n constructor(options: CircuitBreakerOptions = {}) {\n this.threshold = options.threshold ?? 5;\n this.cooldownMs = options.cooldownMs ?? 30_000;\n }\n\n /** Throws if the circuit is open and the cooldown hasnt elapsed */\n assertClosed(): void {\n if (this.state !== 'open') return;\n\n const elapsed = Date.now() - this.openedAt;\n if (elapsed >= this.cooldownMs) {\n this.state = 'half-open';\n return;\n }\n\n throw new LLMError(\n `Circuit open — provider has failed ${this.consecutiveFailures} times in a row. Retry in ${Math.ceil((this.cooldownMs - elapsed) / 1000)}s.`,\n 'circuit_open',\n );\n }\n\n recordSuccess(): void {\n this.consecutiveFailures = 0;\n this.state = 'closed';\n }\n\n recordFailure(): void {\n this.consecutiveFailures += 1;\n\n if (this.state === 'half-open') {\n // Trial call failed: reopen and reset the cooldown window.\n this.state = 'open';\n this.openedAt = Date.now();\n return;\n }\n\n if (this.consecutiveFailures >= this.threshold) {\n this.state = 'open';\n this.openedAt = Date.now();\n }\n }\n\n getState(): CircuitState {\n return this.state;\n }\n}\n","import { LLMError } from '../types/errors.js';\n\nexport function defaultParseJson(content: string): unknown {\n try {\n return JSON.parse(content);\n } catch {\n return undefined;\n }\n}\n\n/**\n * Looks inside an unknown error value and pulls out an http status code\n * if one is present. Checks the status field first then the status code\n * field since different client libraries use different names for this.\n * Returns undefined when the error is not an object or carries no status\n */\nexport function extractStatus(err: unknown): number | undefined {\n if (!err || typeof err !== 'object') return undefined;\n\n const error = err as {\n status?: unknown;\n statusCode?: unknown;\n };\n\n if (typeof error.status === 'number') return error.status;\n if (typeof error.statusCode === 'number') return error.statusCode;\n\n return undefined;\n}\n\n/**\n * Runs an async function and cancels it if it takes longer than the given\n * timeout. Creates an internal abort controller that fires after the\n * timeout elapses, and combines it with any external signal the caller\n * passed in so either one can cancel the underlying call. If the internal\n * timeout triggers and the underlying operation aborts, the error is\n * converted into an LLMError with type \"timeout\". External cancellations\n * continue to propagate as aborted errors. The internal timer is always\n * cleared afterward, whether the function succeeds, fails, or is aborted,\n * so nothing is left running in the background.\n */\nexport async function withTimeout<T>(\n fn: (signal: AbortSignal) => Promise<T>,\n timeoutMs: number,\n externalSignal?: AbortSignal,\n): Promise<T> {\n const controller = new AbortController();\n\n const timer = setTimeout(() => {\n controller.abort();\n }, timeoutMs);\n\n const signal = externalSignal\n ? AbortSignal.any([externalSignal, controller.signal])\n : controller.signal;\n\n try {\n return await fn(signal);\n } catch (err) {\n if (\n controller.signal.aborted &&\n !externalSignal?.aborted &&\n err instanceof DOMException &&\n err.name === 'AbortError'\n ) {\n throw new LLMError('Request timed out', 'timeout');\n }\n\n throw err;\n } finally {\n clearTimeout(timer);\n }\n}\n\n/**\n * Exponential backoff with jitter, capped at maxDelayMs.\n * Jitter avoids thundering-herd retries when many callers back off in lockstep,\n * the cap prevents unbounded delays when maxRetries is high\n */\nexport function getBackoffDelay(baseDelayMs: number, attempt: number, maxDelayMs = 10_000): number {\n const exp = Math.min(baseDelayMs * 2 ** attempt, maxDelayMs);\n return exp / 2 + Math.random() * (exp / 2);\n}\n\n/**\n * Pauses execution for the given delay before a retry attempt. If an\n * abort signal is provided and it fires while waiting, the pending\n * timer is cancelled immediately and the wait rejects right away with\n * an aborted error instead of continuing to sit idle until the delay\n * would have finished on its own\n */\nexport async function waitForRetry(delay: number, signal?: AbortSignal): Promise<void> {\n await new Promise<void>((resolve, reject) => {\n const onAbort = () => {\n clearTimeout(timer);\n reject(new LLMError('Operation aborted', 'aborted'));\n };\n\n const timer = setTimeout(() => {\n signal?.removeEventListener('abort', onAbort);\n resolve();\n }, delay);\n\n signal?.addEventListener('abort', onAbort, { once: true });\n });\n}\n","export interface Logger {\n debug(message: string): void;\n warn(message: string): void;\n error(message: string, meta?: Record<string, unknown>): void;\n}\n\n/**\n * Default logger. `debug` is gated by the `debug` option on VernLLM\n * warn/error always fire since they indicate real problems (retries, cache failures)\n */\nexport class ConsoleLogger implements Logger {\n constructor(private debugEnabled: boolean) {}\n\n debug(message: string): void {\n if (this.debugEnabled) console.debug(message);\n }\n\n warn(message: string): void {\n console.warn(message);\n }\n\n error(message: string, meta?: Record<string, unknown>): void {\n console.error(message, meta ?? '');\n }\n}\n","export interface CacheAdapter<T = unknown> {\n get(key: string): Promise<{ hit: boolean; value: T | null }>;\n set(key: string, value: T, ttl: number): Promise<void>;\n delete?(key: string): Promise<void>;\n}\n\n/**\n * Trivial default so the package works out of the box with no external deps\n * Not shared across processes, swap in Redis/Upstash/etc for production\n */\nexport class InMemoryCacheAdapter<T = unknown> implements CacheAdapter<T> {\n private store = new Map<string, { value: T; expiresAt: number }>();\n\n constructor(private readonly maxSize = 1000) {}\n\n async get(key: string): Promise<{ hit: boolean; value: T | null }> {\n const entry = this.store.get(key);\n\n if (!entry) return { hit: false, value: null };\n\n if (Date.now() >= entry.expiresAt) {\n this.store.delete(key);\n return { hit: false, value: null };\n }\n\n return { hit: true, value: entry.value };\n }\n\n async set(key: string, value: T, ttl: number): Promise<void> {\n this.cleanupExpiredEntries();\n\n this.store.set(key, {\n value,\n expiresAt: Date.now() + ttl * 1000,\n });\n\n this.enforceSizeLimit();\n }\n\n async delete(key: string): Promise<void> {\n this.store.delete(key);\n }\n\n private cleanupExpiredEntries(): void {\n const now = Date.now();\n\n for (const [key, entry] of this.store) {\n if (now >= entry.expiresAt) {\n this.store.delete(key);\n }\n }\n }\n\n private enforceSizeLimit(): void {\n while (this.store.size > this.maxSize) {\n const oldestKey = this.store.keys().next().value;\n\n if (oldestKey === undefined) break;\n\n this.store.delete(oldestKey);\n }\n }\n}\n","import { randomUUID } from 'crypto';\n\nimport { CircuitBreaker } from './circuitBreaker.js';\nimport {\n defaultParseJson,\n extractStatus,\n withTimeout,\n getBackoffDelay,\n waitForRetry,\n} from './internal/vernLLM.utils.js';\nimport { ConsoleLogger, type Logger } from './logger.js';\nimport {\n InMemoryCacheAdapter,\n LLMError,\n type CacheAdapter,\n type CachedCallParams,\n type CallParams,\n type ConversationTurn,\n type LLMClient,\n type VernLLMOptions,\n} from './types/index.js';\n\n/**\n * A resilient wrapper around an LLM chat completions client, this is VernLLM!\n *\n * Adds retry with exponential backoff and jitter, per-attempt timeouts,\n * an optional circuit breaker, JSON parsing with optional schema\n * validation, usage tracking, and an optional response cache, all\n * configurable, all opt-in beyond sensible defaults\n */\nexport class VernLLM {\n private readonly client: LLMClient;\n private readonly model: string;\n\n private readonly maxRetries: number;\n private readonly timeoutMs: number;\n private readonly baseDelayMs: number;\n private readonly defaultMaxTokens: number;\n\n private readonly cache: CacheAdapter<unknown>;\n private readonly nonRetryableStatus: number[];\n\n private readonly parseJson: (content: string) => unknown;\n private readonly onUsage?: VernLLMOptions['onUsage'];\n\n private readonly logger: Logger;\n private readonly breaker?: CircuitBreaker;\n\n /**\n * @param options: Client, model, and all tunables (retries, timeout,\n * backoff, cache, circuit breaker, logger, etc). See VernLLMOptions in `types.ts`\n * for individual defaults\n */\n constructor(options: VernLLMOptions) {\n this.client = options.client;\n this.model = options.model;\n\n const retryConfig = this.resolveRetryConfig(options);\n this.maxRetries = retryConfig.maxRetries;\n this.timeoutMs = retryConfig.timeoutMs;\n this.baseDelayMs = retryConfig.baseDelayMs;\n this.defaultMaxTokens = retryConfig.defaultMaxTokens;\n\n this.cache = options.cache ?? new InMemoryCacheAdapter();\n this.nonRetryableStatus = options.nonRetryableStatus ?? [400, 401, 403, 404, 422];\n\n this.parseJson = options.parseJson ?? defaultParseJson;\n this.onUsage = options.onUsage;\n\n this.logger = this.resolveLogger(options);\n this.breaker = this.resolveCircuitBreaker(options);\n }\n\n /**\n * Resolves retry/timeout/token defaults from the given options,\n * falling back to the librarys built-in defaults for anything unset\n */\n private resolveRetryConfig(options: VernLLMOptions) {\n return {\n maxRetries: options.maxRetries ?? 1,\n timeoutMs: options.timeoutMs ?? 25_000,\n baseDelayMs: options.baseDelayMs ?? 500,\n defaultMaxTokens: options.defaultMaxTokens ?? 1000,\n };\n }\n\n /**\n * Returns the caller supplied logger, or a console-based logger whose\n * debug output is gated by the `debug` option (defaulting to off,\n * so response content isn't unintentionally written to logs)\n */\n private resolveLogger(options: VernLLMOptions): Logger {\n return options.logger ?? new ConsoleLogger(options.debug ?? false);\n }\n\n /**\n * Builds a circuit breaker if `circuitBreaker` is truthy on the\n * options. Passing `true` uses default thresholds, passing an options\n * object tunes them. Returns undefined when the breaker is disabled\n */\n private resolveCircuitBreaker(options: VernLLMOptions): CircuitBreaker | undefined {\n if (!options.circuitBreaker) return undefined;\n\n return new CircuitBreaker(options.circuitBreaker === true ? undefined : options.circuitBreaker);\n }\n\n /**\n * Makes a single logical LLM call, transparently retrying on failure\n * according to the configured retry policy\n *\n * Fails fast if the circuit breaker is open or the signal is already\n * aborted, before any request is dispatched. On exhausting all\n * retries, records a circuit breaker failure and rejects with a\n * normalized LLMError\n *\n * @param params : System/user content plus per call overrides\n * (model, temperature, jsonMode, schema, signal, etc)\n * @returns The parsed and optionally schema-validated response, or\n * the raw string content when jsonMode is disabled\n */\n async call<T = unknown>(params: CallParams<T>): Promise<T> {\n this.breaker?.assertClosed();\n\n if (params.signal?.aborted) {\n throw new LLMError('LLM request aborted', 'aborted');\n }\n\n const requestId = params.requestId ?? randomUUID();\n\n try {\n const result = await this.retryWithBackoff(\n () => this.executeCall(params, requestId),\n requestId,\n params.signal,\n );\n\n return result;\n } catch (error) {\n this.breaker?.recordFailure();\n throw this.normalizeError(error, params.signal);\n }\n }\n\n /**\n * Runs `fn`, retrying with backoff according to `shouldRetry` policy\n * Purely mechanical: knows nothing about LLM specifics beyond the retry\n * predicate, so its testable independent of request/response shaping\n */\n private async retryWithBackoff<T>(\n fn: () => Promise<T>,\n requestId: string,\n signal?: AbortSignal,\n ): Promise<T> {\n let lastError: unknown;\n\n for (let attempt = 0; attempt <= this.maxRetries; attempt++) {\n try {\n if (attempt > 0) {\n await this.recoverDelay(requestId, attempt, signal);\n }\n\n return await fn();\n } catch (error) {\n lastError = error;\n\n if (!this.shouldRetry(error, signal)) {\n break;\n }\n }\n }\n\n throw lastError;\n }\n\n /**\n * Converts any thrown value into a well-typed LLMError for the public\n * API surface. Preserves an existing LLMError as is, reports aborted\n * signals as such, classifies errors carrying an http status as\n * type api, and otherwise falls back to a generic unknown error.\n */\n private normalizeError(error: unknown, signal?: AbortSignal): LLMError {\n if (signal?.aborted) {\n return new LLMError('LLM request aborted', 'aborted');\n }\n\n if (error instanceof LLMError) {\n return error;\n }\n\n const status = extractStatus(error);\n\n if (status !== undefined) {\n return new LLMError('LLM request failed', 'api', status);\n }\n\n return new LLMError('LLM request failed', 'unknown');\n }\n\n /**\n * Performs a single attempt: builds the request, dispatches it with a\n * timeout, and shapes the response. Throws on an empty response so\n * the retry loop treats it like any other transient failure. Records\n * usage and a circuit breaker success before returning\n */\n private async executeCall<T>(params: CallParams<T>, requestId: string): Promise<T> {\n const { useJson, model, request } = this.buildRequestPayload(params);\n\n const response = await withTimeout(\n (attemptSignal) => this.client.chat.completions.create(request, { signal: attemptSignal }),\n this.timeoutMs,\n params.signal,\n );\n\n const content = response.choices?.[0]?.message?.content?.trim();\n\n if (!content) {\n throw new LLMError('Empty LLM response', 'api');\n }\n\n this.logger.debug(`[vern:${requestId}] output:\\n${content.slice(0, 800)}`);\n\n this.recordUsage(response, requestId, model);\n\n this.breaker?.recordSuccess();\n\n if (!useJson) {\n return content as T;\n }\n\n return this.parseAndValidate(content, params.schema);\n }\n\n /**\n * Anthropic and Gemini both require strict user/assistant alternation\n * (and reject or silently mishandle two consecutive same-role turns), so\n * this validates `history` up front rather than letting a malformed\n * request surface as a confusing provider-side error. Thrown as a\n * validation LLMError, which `shouldRetry` never retries, since retrying\n * the same malformed input can't succeed\n */\n private validateHistory(history: ConversationTurn[]): void {\n let previousRole: 'user' | 'assistant' | undefined;\n\n for (const [index, turn] of history.entries()) {\n if (turn.role !== 'user' && turn.role !== 'assistant') {\n throw new LLMError(\n `Invalid history[${index}].role \"${turn.role}\": must be \"user\" or \"assistant\"`,\n 'validation',\n );\n }\n\n if (turn.role === previousRole) {\n throw new LLMError(\n `history must alternate user/assistant turns: consecutive \"${turn.role}\" turns at history[${index - 1}] and history[${index}]`,\n 'validation',\n );\n }\n\n previousRole = turn.role;\n }\n\n if (previousRole === 'user') {\n throw new LLMError(\n 'The last entry in history is a \"user\" turn, which would collide with the current userContent turn. history must end with an \"assistant\" turn (or be empty).',\n 'validation',\n );\n }\n }\n\n /**\n * Applies per call defaults and shapes the params into the request\n * object expected by the underlying client, including the resolved\n * response format. Also returns whether JSON parsing should be\n * applied to the response and which model was ultimately used\n */\n private buildRequestPayload<T>(params: CallParams<T>) {\n const {\n systemPrompt,\n userContent,\n history = [],\n temperature = 0.2,\n jsonMode = true,\n maxTokens = this.defaultMaxTokens,\n model = this.model,\n reasoningEffort,\n jsonSchema,\n } = params;\n\n const useJson = jsonMode || Boolean(jsonSchema);\n const responseFormat = this.buildResponseFormat(jsonSchema, useJson);\n\n this.validateHistory(history);\n\n const request = {\n model,\n temperature,\n max_tokens: maxTokens,\n ...(responseFormat ? { response_format: responseFormat } : {}),\n ...(reasoningEffort ? { reasoning_effort: reasoningEffort } : {}),\n messages: [\n ...(systemPrompt ? [{ role: 'system' as const, content: systemPrompt }] : []),\n ...history.map((turn) => ({ role: turn.role, content: turn.content })),\n { role: 'user' as const, content: userContent },\n ],\n };\n\n return { useJson, model, request };\n }\n\n /**\n * Chooses the response format to send to the provider. A provider\n * native json schema takes priority when supplied, constraining\n * generation directly, otherwise falls back to the looser json\n * object mode when JSON output is requested, or no format at all\n * for plain text responses\n */\n private buildResponseFormat(jsonSchema: CallParams<unknown>['jsonSchema'], useJson: boolean) {\n if (jsonSchema) {\n return {\n type: 'json_schema' as const,\n json_schema: {\n name: jsonSchema.name,\n schema: jsonSchema.schema,\n strict: jsonSchema.strict ?? true,\n description: jsonSchema.description,\n },\n };\n }\n\n return useJson ? { type: 'json_object' as const } : undefined;\n }\n\n /**\n * Reports token usage to the caller supplied onUsage callback, when\n * both a callback was configured and the provider actually returned\n * usage data on this response. A no op otherwise.\n */\n private recordUsage(\n response: Awaited<ReturnType<LLMClient['chat']['completions']['create']>>,\n requestId: string,\n model: string,\n ): void {\n if (!response.usage || !this.onUsage) return;\n\n this.onUsage({\n promptTokens: response.usage.prompt_tokens ?? 0,\n completionTokens: response.usage.completion_tokens ?? 0,\n totalTokens: response.usage.total_tokens ?? 0,\n requestId,\n model,\n });\n }\n\n /**\n * Parses the raw response content as JSON and, when a schema is\n * supplied, validates the parsed value against it. Throws a parse\n * type LLMError on malformed JSON and a validation type LLMError,\n * carrying the schemas issues, on a failed validation\n */\n private parseAndValidate<T>(content: string, schema?: CallParams<T>['schema']): T {\n let parsed: unknown;\n\n try {\n parsed = this.parseJson(content);\n } catch {\n throw new LLMError('Invalid JSON response', 'parse');\n }\n\n if (parsed === null || parsed === undefined) {\n throw new LLMError('Invalid JSON response', 'parse');\n }\n\n if (!schema) {\n return parsed as T;\n }\n\n const result = schema.safeParse(parsed);\n\n if (!result.success) {\n throw new LLMError('Schema validation failed', 'validation', undefined, result.error);\n }\n\n return result.data;\n }\n\n /**\n * Waits out the backoff delay for a given retry attempt, logging the\n * attempt for observability before the wait begins. Rejects early if\n * the signal aborts during the wait\n */\n private async recoverDelay(requestId: string, attempt: number, signal?: AbortSignal) {\n const delay = getBackoffDelay(this.baseDelayMs, attempt);\n\n this.logger.warn(\n `[vern:${requestId}] recovery attempt ${attempt}/${this.maxRetries}, waiting ${delay}ms`,\n );\n\n await waitForRetry(delay, signal);\n }\n\n /**\n * Decides whether a failed attempt is worth retrying. Never retries\n * once the signal has aborted, never retries a parse or validation\n * failure since those stem from the response content rather than a\n * transient fault, and never retries a status code the caller has\n * marked as non retryable. Retries everything else\n */\n private shouldRetry(error: unknown, signal?: AbortSignal): boolean {\n if (signal?.aborted) {\n return false;\n }\n\n if (error instanceof LLMError && (error.type === 'parse' || error.type === 'validation')) {\n return false;\n }\n\n const status = extractStatus(error);\n\n if (status !== undefined && this.nonRetryableStatus.includes(status)) {\n return false;\n }\n\n return true;\n }\n\n /**\n * Removes a cached response by key when the configured cache adapter\n * supports deletion.\n *\n * Cache invalidation remains the responsibility of the caller because\n * only the application knows when cached data is stale.\n */\n async deleteCache(key: string): Promise<void> {\n if (!this.cache.delete) {\n return;\n }\n\n await this.cache.delete(key);\n }\n\n /**\n * Thin cache wrapper around caller supplied logic. `params.fn` is expected\n * to be a call that itself invokes `this.call(...)` (see `cachedLLMCall`\n * below for a convenience wrapper that wires this up automatically),\n * `cachedCall` does not itself apply retry/timeout policy.\n */\n async cachedCall<T>(params: CachedCallParams<T>): Promise<T> {\n const cached = await this.cache.get(params.cacheKey);\n\n if (cached.hit) {\n return cached.value as T;\n }\n\n try {\n await params.reserveUsage?.();\n\n const result = await params.fn();\n\n try {\n await this.cache.set(params.cacheKey, result, params.ttl);\n } catch (error) {\n this.logger.error('[VernLLM] cache write failed', {\n message: error instanceof Error ? error.message : 'unknown',\n });\n }\n\n return result;\n } catch (error) {\n try {\n await params.refundUsage?.();\n } catch (refundError) {\n this.logger.error('[VernLLM] refundUsage failed', {\n message: refundError instanceof Error ? refundError.message : 'unknown',\n });\n }\n\n throw error;\n }\n }\n\n /**\n * Convenience wrapper composing `call` + `cachedCall`, so cached LLM calls\n * automatically get retry/timeout/circuit-breaker behavior without callers\n * having to remember to wire `fn: () => this.call(...)` themselves\n */\n async cachedLLMCall<T>(\n params: Omit<CachedCallParams<T>, 'fn'> & { call: CallParams<T> },\n ): Promise<T> {\n const { call: callParams, ...cacheParams } = params;\n\n return this.cachedCall({\n ...cacheParams,\n fn: () => this.call(callParams),\n });\n }\n\n /**\n * Returns the current circuit breaker state, or undefined when no\n * circuit breaker was configured on this instance\n */\n getCircuitState() {\n return this.breaker?.getState();\n }\n}\n","import type { LLMClient } from '../types/index.js';\n\n/** Minimal structural type for the Anthropic SDKs `messages.create` */\nexport interface AnthropicClient {\n messages: {\n create(\n params: {\n model: string;\n max_tokens: number;\n temperature?: number;\n system?: string;\n messages: Array<{ role: 'user' | 'assistant'; content: string }>;\n tools?: Array<{\n name: string;\n description?: string;\n input_schema: Record<string, unknown>;\n }>;\n tool_choice?: { type: 'tool'; name: string };\n },\n options: { signal: AbortSignal },\n ): Promise<{\n content: Array<{ type: string; text?: string; name?: string; input?: unknown }>;\n usage?: { input_tokens?: number; output_tokens?: number };\n }>;\n };\n}\n\n/**\n * Wraps an Anthropic SDK client so it satisfies the same `LLMClient`\n * interface VernLLM uses for OpenAI/Groq.\n *\n * `response_format: json_schema` is mapped to Anthropics forced tool-use:\n * a single tool is defined with `input_schema` set to the caller's schema,\n * and `tool_choice` forces the model to call it, so the output is\n * provider-constrained to match the schema rather than merely instructed\n * to via prompt text (the same guarantee OpenAIs native `json_schema` mode\n * gives, built on Anthropics tool-calling primitive instead).\n *\n * `response_format: json_object` (no schema to build a tool from) falls\n * back to a system-prompt instruction, since theres nothing to constrain\n * generation against.\n */\nexport function fromAnthropic(anthropicClient: AnthropicClient): LLMClient {\n return {\n chat: {\n completions: {\n async create(params, options) {\n const systemMessage = params.messages.find((m) => m.role === 'system');\n // Keep both user and assistant turns, in order, so multi-turn history\n // survives instead of collapsing to consecutive user messages.\n const conversationMessages = params.messages.filter(\n (m): m is typeof m & { role: 'user' | 'assistant' } =>\n m.role === 'user' || m.role === 'assistant',\n );\n\n const toolName =\n params.response_format?.type === 'json_schema'\n ? params.response_format.json_schema.name\n : undefined;\n\n let jsonInstruction: string | undefined;\n let tools:\n | NonNullable<Parameters<AnthropicClient['messages']['create']>[0]['tools']>\n | undefined;\n\n if (params.response_format?.type === 'json_schema' && toolName) {\n const { schema, description } = params.response_format.json_schema;\n tools = [{ name: toolName, description, input_schema: schema }];\n } else if (params.response_format?.type === 'json_object') {\n // No schema to build a tool from, fall back to a prompt instruction\n jsonInstruction = 'Respond with valid JSON only, no prose or markdown fences.';\n }\n\n // `reasoning_effort` (OpenAI o-series/gpt-5 style) has no direct Anthropic\n // equivalent, Claudes extended thinking uses a token budget, not a tier\n // string, so its intentionally dropped here rather than guessed at.\n\n const system = [systemMessage?.content, jsonInstruction].filter(Boolean).join('\\n\\n');\n\n const response = await anthropicClient.messages.create(\n {\n model: params.model,\n max_tokens: params.max_tokens,\n temperature: params.temperature,\n system: system || undefined,\n messages: conversationMessages.map((m) => ({ role: m.role, content: m.content })),\n ...(tools ? { tools, tool_choice: { type: 'tool' as const, name: toolName! } } : {}),\n },\n options,\n );\n\n let text: string;\n if (toolName) {\n // Forced tool-use: the schema-conforming payload arrives as the\n // tool_use block's already-parsed `input`, not as text. Re-serialize\n // it to JSON so it flows through the same string-content contract\n // every other adapter uses (VernLLM JSON.parses the content itself).\n const toolUse = response.content.find(\n (block) => block.type === 'tool_use' && block.name === toolName,\n );\n text = toolUse ? JSON.stringify(toolUse.input) : '';\n } else {\n text = response.content.find((block) => block.type === 'text')?.text ?? '';\n }\n\n return {\n choices: [{ message: { content: text } }],\n usage: {\n prompt_tokens: response.usage?.input_tokens,\n completion_tokens: response.usage?.output_tokens,\n total_tokens:\n (response.usage?.input_tokens ?? 0) + (response.usage?.output_tokens ?? 0),\n },\n };\n },\n },\n },\n };\n}\n","import type { LLMClient } from '../types/index.js';\n\n/**\n * Minimal structural type for Geminis `generateContent`, matching both the\n * legacy `@google/generative-ai` SDKs `model.generateContent(...)` and the\n * newer `@google/genai` SDKs `ai.models.generateContent({ model, ... })`\n * closely enough to adapt either — pass whichever `.generateContent` you have.\n */\nexport interface GeminiClient {\n generateContent(\n params: {\n model?: string;\n contents: Array<{ role: 'user' | 'model'; parts: Array<{ text: string }> }>;\n systemInstruction?: { parts: Array<{ text: string }> };\n generationConfig?: {\n temperature?: number;\n maxOutputTokens?: number;\n responseMimeType?: string;\n responseSchema?: Record<string, unknown>;\n };\n },\n options: { signal: AbortSignal },\n ): Promise<{\n candidates?: Array<{ content?: { parts?: Array<{ text?: string }> } }>;\n usageMetadata?: {\n promptTokenCount?: number;\n candidatesTokenCount?: number;\n totalTokenCount?: number;\n };\n }>;\n}\n\n/**\n * Wraps a Gemini client so it satisfies the `LLMClient` interface VernLLM\n * uses for OpenAI/Groq. Geminis shape differs on nearly every axis: a\n * `contents` array instead of `messages`, a separate `systemInstruction`\n * field instead of a `system` role message, `generationConfig` instead of\n * top-level `temperature`/`max_tokens`, and native JSON Schema support via\n * `responseMimeType: 'application/json'` + `responseSchema` (so `jsonSchema`\n * is provider-enforced here, unlike the Anthropic adapters prompt-embedding\n * fallback). `reasoning_effort` has no equivalent. Geminis thinking models\n * use a token budget, not an effort tier, so its dropped, same as Anthropic.\n */\nexport function fromGemini(geminiClient: GeminiClient): LLMClient {\n return {\n chat: {\n completions: {\n async create(params, options) {\n const systemMessage = params.messages.find((m) => m.role === 'system');\n // Keep both user and assistant turns, in order. Gemini calls the\n // assistant role 'model' rather than 'assistant'.\n const conversationMessages = params.messages.filter(\n (m) => m.role === 'user' || m.role === 'assistant',\n );\n\n const wantsJson = Boolean(params.response_format);\n const generationConfig: NonNullable<\n Parameters<GeminiClient['generateContent']>[0]['generationConfig']\n > = {\n temperature: params.temperature,\n maxOutputTokens: params.max_tokens,\n };\n\n if (wantsJson) {\n generationConfig.responseMimeType = 'application/json';\n }\n if (params.response_format?.type === 'json_schema') {\n generationConfig.responseSchema = params.response_format.json_schema.schema;\n }\n\n const response = await geminiClient.generateContent(\n {\n model: params.model,\n contents: conversationMessages.map((m) => ({\n role: m.role === 'assistant' ? ('model' as const) : ('user' as const),\n parts: [{ text: m.content }],\n })),\n systemInstruction: systemMessage\n ? { parts: [{ text: systemMessage.content }] }\n : undefined,\n generationConfig,\n },\n options,\n );\n\n const text =\n response.candidates?.[0]?.content?.parts?.map((p) => p.text ?? '').join('') ?? '';\n\n return {\n choices: [{ message: { content: text } }],\n usage: {\n prompt_tokens: response.usageMetadata?.promptTokenCount,\n completion_tokens: response.usageMetadata?.candidatesTokenCount,\n total_tokens: response.usageMetadata?.totalTokenCount,\n },\n };\n },\n },\n },\n };\n}\n","import type { LLMClient } from '../types/index.js';\n\n/**\n * Minimal structural type matching AWS Bedrocks Converse API. This is\n * intentionally NOT `BedrockRuntimeClient` itself, the AWS SDK v3 client\n * exposes `.send(command)`, not a direct `.converse()` method, and pulling\n * in `@aws-sdk/client-bedrock-runtime` as a dependency just for its types\n * isn't worth it for a structural adapter. Wrap your client, e.g:\n *\n * ```ts\n * import { BedrockRuntimeClient, ConverseCommand } from '@aws-sdk/client-bedrock-runtime';\n * const client = new BedrockRuntimeClient({ region: 'us-east-1' });\n * const converseClient = {\n * converse: (params, options) =>\n * client.send(new ConverseCommand(params), { abortSignal: options.signal }),\n * };\n * ```\n */\nexport interface BedrockConverseClient {\n converse(\n params: {\n modelId: string;\n messages: Array<{ role: 'user' | 'assistant'; content: Array<{ text: string }> }>;\n system?: Array<{ text: string }>;\n inferenceConfig?: { temperature?: number; maxTokens?: number };\n toolConfig?: {\n tools: Array<{\n toolSpec: {\n name: string;\n description?: string;\n inputSchema: { json: Record<string, unknown> };\n };\n }>;\n toolChoice?: { tool: { name: string } };\n };\n },\n options: { signal: AbortSignal },\n ): Promise<{\n output?: {\n message?: {\n content?: Array<{ text?: string; toolUse?: { name?: string; input?: unknown } }>;\n };\n };\n usage?: { inputTokens?: number; outputTokens?: number; totalTokens?: number };\n }>;\n}\n\n/**\n * Wraps a Bedrock Converse-API client so it satisfies the `LLMClient`\n * interface VernLLM uses for OpenAI/Groq. The Converse API is unified\n * across Bedrocks model families (Anthropic, Titan, Llama, Mistral, etc.),\n * so unlike raw per-model Bedrock invocation, this one adapter works\n * regardless of which underlying model `modelId` points at, as long as\n * that model supports Converse (most current-generation ones do)\n *\n * `response_format: json_schema` is mapped to Converses `toolConfig`: a\n * single tool is defined from the schema and `toolChoice` forces the model\n * to call it, constraining output at generation time rather than merely\n * instructing for it via prompt text. Native tool support varies by model\n * family (most current-generation ones support it via Converse; check your\n * specific `modelId` if a call fails with an unsupported-parameter error).\n * `response_format: json_object` (no schema to build a tool from) and\n * `reasoning_effort` (no Converse equivalent) fall back to a system-prompt\n * instruction and are dropped respectively.\n */\nexport function fromBedrock(bedrockClient: BedrockConverseClient): LLMClient {\n return {\n chat: {\n completions: {\n async create(params, options) {\n const systemMessage = params.messages.find((m) => m.role === 'system');\n // Keep both user and assistant turns, in order, so conversation\n // history survives instead of collapsing to consecutive user turns.\n const conversationMessages = params.messages.filter(\n (m): m is typeof m & { role: 'user' | 'assistant' } =>\n m.role === 'user' || m.role === 'assistant',\n );\n\n const toolName =\n params.response_format?.type === 'json_schema'\n ? params.response_format.json_schema.name\n : undefined;\n\n let jsonInstruction: string | undefined;\n let toolConfig:\n | NonNullable<Parameters<BedrockConverseClient['converse']>[0]['toolConfig']>\n | undefined;\n\n if (params.response_format?.type === 'json_schema' && toolName) {\n const { schema, description } = params.response_format.json_schema;\n toolConfig = {\n tools: [{ toolSpec: { name: toolName, description, inputSchema: { json: schema } } }],\n toolChoice: { tool: { name: toolName } },\n };\n } else if (params.response_format?.type === 'json_object') {\n // No schema to build a tool from, fall back to a prompt instruction\n jsonInstruction = 'Respond with valid JSON only, no prose or markdown fences.';\n }\n\n const systemParts = [systemMessage?.content, jsonInstruction].filter((s): s is string =>\n Boolean(s),\n );\n\n const response = await bedrockClient.converse(\n {\n modelId: params.model,\n messages: conversationMessages.map((m) => ({\n role: m.role,\n content: [{ text: m.content }],\n })),\n system: systemParts.length ? systemParts.map((text) => ({ text })) : undefined,\n inferenceConfig: {\n temperature: params.temperature,\n maxTokens: params.max_tokens,\n },\n ...(toolConfig ? { toolConfig } : {}),\n },\n options,\n );\n\n let text: string;\n if (toolName) {\n // Forced tool-use: the schema-conforming payload arrives as the\n // toolUse content block's already-parsed `input`, not as text.\n // Re-serialize it to JSON so it flows through the same\n // string-content contract every other adapter uses.\n const toolUseBlock = response.output?.message?.content?.find(\n (block) => block.toolUse?.name === toolName,\n );\n text = toolUseBlock?.toolUse ? JSON.stringify(toolUseBlock.toolUse.input) : '';\n } else {\n text = response.output?.message?.content?.map((c) => c.text ?? '').join('') ?? '';\n }\n\n return {\n choices: [{ message: { content: text } }],\n usage: {\n prompt_tokens: response.usage?.inputTokens,\n completion_tokens: response.usage?.outputTokens,\n total_tokens: response.usage?.totalTokens,\n },\n };\n },\n },\n },\n };\n}\n","import type { LLMClient } from '../types/index.js';\n\n/** The chat-completion-shaped request VernLLM builds internally */\ntype ChatRequest = Parameters<LLMClient['chat']['completions']['create']>[0];\n\nexport interface FetchAdapterConfig {\n /** Endpoint URL, or a function of the request in case it depends on model/params */\n url: string | ((params: ChatRequest) => string);\n /** Static headers, or a function (sync or async) for things like refreshed auth tokens */\n headers?:\n | Record<string, string>\n | (() => Record<string, string> | Promise<Record<string, string>>);\n /** HTTP method. Default 'POST' */\n method?: string;\n /** Maps VernLLMs internal chat-completion request into the providers raw request body */\n mapRequest: (params: ChatRequest) => unknown;\n /**\n * Maps the providers raw JSON response into `{ content, usage? }`\n * `content` is the assistants text (JSON string when JSON mode was requested)\n */\n mapResponse: (json: unknown) => {\n content: string;\n usage?: { promptTokens?: number; completionTokens?: number; totalTokens?: number };\n };\n}\n\n/**\n * A fetch-based escape hatch for providers with no SDK, or where pulling one\n * in isnt worth it. You supply the URL, headers, and two small mapping\n * functions; this handles the HTTP call and slots the result into the same\n * `LLMClient` shape every other adapter produces, so retries, timeouts,\n * the circuit breaker, and JSON/schema handling all still work unmodified\n *\n * Non-2xx responses throw an error with `.status` set to the HTTP status\n * code, so VernLLMs `nonRetryableStatus` handling (e.g. failing fast on\n * 401/403) applies here too\n */\nexport function fromFetch(config: FetchAdapterConfig): LLMClient {\n return {\n chat: {\n completions: {\n async create(params, options) {\n const url = typeof config.url === 'function' ? config.url(params) : config.url;\n const headers =\n typeof config.headers === 'function' ? await config.headers() : config.headers;\n\n const res = await fetch(url, {\n method: config.method ?? 'POST',\n headers: { 'Content-Type': 'application/json', ...headers },\n body: JSON.stringify(config.mapRequest(params)),\n signal: options.signal,\n });\n\n if (!res.ok) {\n const body = await res.text().catch(() => '');\n const err = new Error(\n `Fetch adapter request failed (${res.status}): ${body.slice(0, 500)}`,\n ) as Error & { status?: number };\n err.status = res.status;\n throw err;\n }\n\n const json = await res.json();\n const { content, usage } = config.mapResponse(json);\n\n return {\n choices: [{ message: { content } }],\n usage: usage\n ? {\n prompt_tokens: usage.promptTokens,\n completion_tokens: usage.completionTokens,\n total_tokens: usage.totalTokens,\n }\n : undefined,\n };\n },\n },\n },\n };\n}\n","import type { LLMClient } from '../types/index.js';\n\n/**\n * Passthrough adapter for any SDK/client whose `chat.completions.create`\n * already matches the OpenAI wire format 1:1 : this covers most hosted\n * inference providers, since \"OpenAI-compatible\" is a de facto standard for\n * chat completion APIs. No transformation happens here, this exists purely\n * so call sites read clearly (`fromMistral(client)` vs handing a Mistral\n * client to something typed for OpenAI) and so a real transformation could\n * be added later, per-provider, without a breaking change.\n *\n * Not every SDKs own TypeScript types line up exactly with `LLMClient`\n * (extra fields, stricter unions, etc.), so this takes `unknown` and casts:\n * the actual compatibility contract is the JSON each provider sends and\n * receives over the wire, not the SDKs TS types.\n */\nexport function fromOpenAICompatible(client: unknown): LLMClient {\n return client as LLMClient;\n}\n\n/** Groqs SDK matches the OpenAI wire format */\nexport const fromGroq = fromOpenAICompatible;\n\n/** Mistrals `chat.completions`-shaped client (or their OpenAI-compat endpoint) */\nexport const fromMistral = fromOpenAICompatible;\n\n/** DeepSeeks API is OpenAI-compatible */\nexport const fromDeepSeek = fromOpenAICompatible;\n\n/** Cerebras inference API is OpenAI-compatible */\nexport const fromCerebras = fromOpenAICompatible;\n\n/** Together AIs API is OpenAI-compatible */\nexport const fromTogether = fromOpenAICompatible;\n\n/** Fireworks AIs API is OpenAI-compatible */\nexport const fromFireworks = fromOpenAICompatible;\n\n/**\n * Ollama exposes an OpenAI-compatible endpoint at `/v1/chat/completions`\n * (as opposed to its native `/api/chat` format, which differs). Point an\n * OpenAI SDK instances `baseURL` at your Ollama server and pass it here:\n * this does not talk to Ollamas native API directly.\n */\nexport const fromOllama = fromOpenAICompatible;\n\n/** OpenRouter's API is OpenAI-compatible */\nexport const fromOpenRouter = fromOpenAICompatible;\n\n/** Perplexity's API is OpenAI-compatible */\nexport const fromPerplexity = fromOpenAICompatible;\n\n/** DeepInfra's API is OpenAI-compatible */\nexport const fromDeepInfra = fromOpenAICompatible;\n\n/** Novita's API is OpenAI-compatible */\nexport const fromNovita = fromOpenAICompatible;\n\n/** Hyperbolic's API is OpenAI-compatible */\nexport const fromHyperbolic = fromOpenAICompatible;\n\n/** Moonshot's (Kimi) API is OpenAI-compatible */\nexport const fromMoonshot = fromOpenAICompatible;\n\n/** Zhipu's (GLM) API is OpenAI-compatible */\nexport const fromZhipu = fromOpenAICompatible;\n\n/**\n * LM Studio exposes an OpenAI-compatible endpoint at `/v1/chat/completions`.\n * Point an OpenAI SDK instance's `baseURL` at your local LM Studio server.\n */\nexport const fromLMStudio = fromOpenAICompatible;\n\n/**\n * vLLM's OpenAI-compatible server mode exposes `/v1/chat/completions`.\n * Point an OpenAI SDK instance's `baseURL` at your vLLM server.\n */\nexport const fromVLLM = fromOpenAICompatible;\n\n/** xAI's Grok API is OpenAI-compatible */\nexport const fromXAI = fromOpenAICompatible;\n\n/** NVIDIA NIM's hosted and self-hosted endpoints are OpenAI-compatible */\nexport const fromNvidiaNIM = fromOpenAICompatible;\n\n/** Vercel AI Gateway is OpenAI-compatible */\nexport const fromVercelAIGateway = fromOpenAICompatible;\n\n/** Cloudflare Workers AI exposes an OpenAI-compatible endpoint */\nexport const fromCloudflareWorkersAI = fromOpenAICompatible;\n\n/** GitHub Models is OpenAI-compatible */\nexport const fromGitHubModels = fromOpenAICompatible;\n\n/** Nebius AI Studio is OpenAI-compatible */\nexport const fromNebius = fromOpenAICompatible;\n\n/** SambaNova Cloud's API is OpenAI-compatible */\nexport const fromSambaNova = fromOpenAICompatible;\n\n/** Baseten's model hosting exposes an OpenAI-compatible endpoint */\nexport const fromBaseten = fromOpenAICompatible;\n\n/** Featherless AI's API is OpenAI-compatible */\nexport const fromFeatherless = fromOpenAICompatible;\n\n/** Friendli AI's serving endpoint is OpenAI-compatible */\nexport const fromFriendli = fromOpenAICompatible;\n\n/** SiliconFlow's API is OpenAI-compatible */\nexport const fromSiliconFlow = fromOpenAICompatible;\n\n/** Parasail's inference API is OpenAI-compatible */\nexport const fromParasail = fromOpenAICompatible;\n\n/** StepFun's API is OpenAI-compatible */\nexport const fromStepFun = fromOpenAICompatible;\n\n/** MiniMax's API is OpenAI-compatible */\nexport const fromMiniMax = fromOpenAICompatible;\n\n/** Lambda Labs' Inference API is OpenAI-compatible */\nexport const fromLambdaLabs = fromOpenAICompatible;\n\n/** Snowflake Cortex's LLM endpoint is OpenAI-compatible */\nexport const fromSnowflakeCortex = fromOpenAICompatible;\n\n/** Anyscale Endpoints' API is OpenAI-compatible */\nexport const fromAnyscale = fromOpenAICompatible;\n\n/** Lepton AI's inference API is OpenAI-compatible */\nexport const fromLepton = fromOpenAICompatible;\n\n/** kluster.ai's inference API is OpenAI-compatible */\nexport const fromKlusterAI = fromOpenAICompatible;\n\n/** Inference.net's API is OpenAI-compatible */\nexport const fromInferenceNet = fromOpenAICompatible;\n\n/** Infermatic's API is OpenAI-compatible */\nexport const fromInfermatic = fromOpenAICompatible;\n\n/** AtlasCloud's inference API is OpenAI-compatible */\nexport const fromAtlasCloud = fromOpenAICompatible;\n\n/** 01.AI's (Yi models) API is OpenAI-compatible */\nexport const from01AI = fromOpenAICompatible;\n"],"mappings":";;;AASA,IAAa,WAAb,cAA8B,MAAM;CAClC,YACEA,SACOC,MACAC,QACAC,QACP;AACA,QAAM,QAAQ;EAQjB,KAZU;EAYT,KAXS;EAWR,KAVQ;AAGP,OAAK,OAAO;CACb;AACF;AAED,SAAgB,WAAWC,KAA+B;AACxD,QAAO,eAAe;AACvB;;;;;;;;;;ACND,IAAa,iBAAb,MAA4B;CAC1B,AAAQ,QAAsB;CAC9B,AAAQ,sBAAsB;CAC9B,AAAQ,WAAW;CACnB,AAAQ;CACR,AAAQ;CAER,YAAYC,UAAiC,CAAE,GAAE;AAC/C,OAAK,YAAY,QAAQ,aAAa;AACtC,OAAK,aAAa,QAAQ,cAAc;CACzC;;CAGD,eAAqB;AACnB,MAAI,KAAK,UAAU,OAAQ;EAE3B,MAAM,UAAU,KAAK,KAAK,GAAG,KAAK;AAClC,MAAI,WAAW,KAAK,YAAY;AAC9B,QAAK,QAAQ;AACb;EACD;AAED,QAAM,IAAI,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
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Production-ready resilience for LLM calls: retries, timeouts, caching, and circuit breaking behind one typed interface, with adapters for OpenAI-compatible APIs (OpenAI, Groq, and more), Anthropic, Gemini, and Bedrock.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"llm",
|