vern-llm 0.1.0 → 0.2.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/LICENSE.md +1 -1
- package/README.md +9 -5
- package/dist/index.cjs +30 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -25
- package/dist/index.js.map +1 -1
- package/package.json +20 -21
package/LICENSE.md
CHANGED
|
@@ -4,4 +4,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
4
4
|
|
|
5
5
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
6
|
|
|
7
|
-
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -97,8 +97,8 @@ const llm = new VernLLM({ client: openai, model: 'gpt-4o-mini' }); // default mo
|
|
|
97
97
|
await llm.call({
|
|
98
98
|
systemPrompt: '...',
|
|
99
99
|
userContent: '...',
|
|
100
|
-
model: 'o3',
|
|
101
|
-
reasoningEffort: 'high',
|
|
100
|
+
model: 'o3', // overrides the instance default for this call only
|
|
101
|
+
reasoningEffort: 'high', // passed through as `reasoning_effort`; ignored by models that don't support it
|
|
102
102
|
});
|
|
103
103
|
```
|
|
104
104
|
|
|
@@ -146,8 +146,12 @@ const result = await llm.cachedLLMCall({
|
|
|
146
146
|
import type { CacheAdapter } from 'vern-llm';
|
|
147
147
|
|
|
148
148
|
class UpstashCacheAdapter implements CacheAdapter {
|
|
149
|
-
async get(key: string) {
|
|
150
|
-
|
|
149
|
+
async get(key: string) {
|
|
150
|
+
/* ... */
|
|
151
|
+
}
|
|
152
|
+
async set(key: string, value: unknown, ttl: number) {
|
|
153
|
+
/* ... */
|
|
154
|
+
}
|
|
151
155
|
}
|
|
152
156
|
```
|
|
153
157
|
|
|
@@ -312,4 +316,4 @@ pnpm run test:coverage # vitest run --coverage (v8 provider)
|
|
|
312
316
|
pnpm run changeset # record a change for the next release
|
|
313
317
|
```
|
|
314
318
|
|
|
315
|
-
Tests live in `tests/`, mirroring `src/`: `VernLLM.call.test.ts` and `VernLLM.schema.test.ts` cover retry/backoff/timeout/abort/schema/model-override/usage behavior, `circuitBreaker.test.ts` covers the breaker as a unit and its integration with `call()`, `cachedCall.test.ts` covers caching and usage reservation/refund, `logger.test.ts` covers the injectable logger, and `test/adapters/*.test.ts` cover each provider adapter's request/response translation against a fake client, no real API calls are made anywhere in the suite.
|
|
319
|
+
Tests live in `tests/`, mirroring `src/`: `VernLLM.call.test.ts` and `VernLLM.schema.test.ts` cover retry/backoff/timeout/abort/schema/model-override/usage behavior, `circuitBreaker.test.ts` covers the breaker as a unit and its integration with `call()`, `cachedCall.test.ts` covers caching and usage reservation/refund, `logger.test.ts` covers the injectable logger, and `test/adapters/*.test.ts` cover each provider adapter's request/response translation against a fake client, no real API calls are made anywhere in the suite.
|
package/dist/index.cjs
CHANGED
|
@@ -109,27 +109,6 @@ var CircuitBreaker = class {
|
|
|
109
109
|
}
|
|
110
110
|
};
|
|
111
111
|
|
|
112
|
-
//#endregion
|
|
113
|
-
//#region src/logger.ts
|
|
114
|
-
/**
|
|
115
|
-
* Default logger. `debug` is gated by the `debug` option on VernLLM
|
|
116
|
-
* warn/error always fire since they indicate real problems (retries, cache failures)
|
|
117
|
-
*/
|
|
118
|
-
var ConsoleLogger = class {
|
|
119
|
-
constructor(debugEnabled) {
|
|
120
|
-
this.debugEnabled = debugEnabled;
|
|
121
|
-
}
|
|
122
|
-
debug(message) {
|
|
123
|
-
if (this.debugEnabled) console.debug(message);
|
|
124
|
-
}
|
|
125
|
-
warn(message) {
|
|
126
|
-
console.warn(message);
|
|
127
|
-
}
|
|
128
|
-
error(message, meta) {
|
|
129
|
-
console.error(message, meta ?? "");
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
|
|
133
112
|
//#endregion
|
|
134
113
|
//#region src/internal/vernLLM.utilts.ts
|
|
135
114
|
function defaultParseJson(content) {
|
|
@@ -202,6 +181,27 @@ async function waitForRetry(delay, signal) {
|
|
|
202
181
|
});
|
|
203
182
|
}
|
|
204
183
|
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/logger.ts
|
|
186
|
+
/**
|
|
187
|
+
* Default logger. `debug` is gated by the `debug` option on VernLLM
|
|
188
|
+
* warn/error always fire since they indicate real problems (retries, cache failures)
|
|
189
|
+
*/
|
|
190
|
+
var ConsoleLogger = class {
|
|
191
|
+
constructor(debugEnabled) {
|
|
192
|
+
this.debugEnabled = debugEnabled;
|
|
193
|
+
}
|
|
194
|
+
debug(message) {
|
|
195
|
+
if (this.debugEnabled) console.debug(message);
|
|
196
|
+
}
|
|
197
|
+
warn(message) {
|
|
198
|
+
console.warn(message);
|
|
199
|
+
}
|
|
200
|
+
error(message, meta) {
|
|
201
|
+
console.error(message, meta ?? "");
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
205
205
|
//#endregion
|
|
206
206
|
//#region src/vernLLM.ts
|
|
207
207
|
/**
|
|
@@ -421,8 +421,13 @@ var VernLLM = class {
|
|
|
421
421
|
* carrying the schemas issues, on a failed validation
|
|
422
422
|
*/
|
|
423
423
|
parseAndValidate(content, schema) {
|
|
424
|
-
|
|
425
|
-
|
|
424
|
+
let parsed;
|
|
425
|
+
try {
|
|
426
|
+
parsed = this.parseJson(content);
|
|
427
|
+
} catch {
|
|
428
|
+
throw new LLMError("Invalid JSON response", "parse");
|
|
429
|
+
}
|
|
430
|
+
if (parsed === null || parsed === void 0) throw new LLMError("Invalid JSON response", "parse");
|
|
426
431
|
if (!schema) return parsed;
|
|
427
432
|
const result = schema.safeParse(parsed);
|
|
428
433
|
if (!result.success) throw new LLMError("Schema validation failed", "validation", void 0, result.error);
|
|
@@ -455,12 +460,12 @@ var VernLLM = class {
|
|
|
455
460
|
/**
|
|
456
461
|
* Thin cache wrapper around caller supplied logic. `params.fn` is expected
|
|
457
462
|
* to be a call that itself invokes `this.call(...)` (see `cachedLLMCall`
|
|
458
|
-
* below for a convenience wrapper that wires this up automatically),
|
|
463
|
+
* below for a convenience wrapper that wires this up automatically),
|
|
459
464
|
* `cachedCall` does not itself apply retry/timeout policy.
|
|
460
465
|
*/
|
|
461
466
|
async cachedCall(params) {
|
|
462
467
|
const cached = await this.cache.get(params.cacheKey);
|
|
463
|
-
if (cached
|
|
468
|
+
if (cached !== null) return cached;
|
|
464
469
|
try {
|
|
465
470
|
await params.reserveUsage?.();
|
|
466
471
|
const result = await params.fn();
|
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","key: string","value: T","ttl: number","options: CircuitBreakerOptions","debugEnabled: boolean","message: string","meta?: Record<string, unknown>","content: string","err: unknown","fn: (signal: AbortSignal) => Promise<T>","timeoutMs: number","externalSignal?: AbortSignal","baseDelayMs: number","attempt: number","delay: number","signal?: AbortSignal","options: VernLLMOptions","params: CallParams<T>","fn: () => Promise<T>","requestId: string","signal?: AbortSignal","lastError: unknown","error: unknown","jsonSchema: CallParams<unknown>['jsonSchema']","useJson: boolean","response: Awaited<\n ReturnType<LLMClient['chat']['completions']['create']>\n >","model: string","content: string","schema?: CallParams<T>['schema']","attempt: number","params: CachedCallParams<T>","params: Omit<CachedCallParams<T>, 'fn'> & { call: CallParams<T> }","anthropicClient: AnthropicClient","jsonInstruction: string | undefined","geminiClient: GeminiClient","generationConfig: NonNullable<\n Parameters<GeminiClient['generateContent']>[0]['generationConfig']\n >","bedrockClient: BedrockConverseClient","jsonInstruction: string | undefined","text","config: FetchAdapterConfig","client: unknown"],"sources":["../src/types.ts","../src/circuitBreaker.ts","../src/logger.ts","../src/internal/vernLLM.utilts.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\nexport interface CacheAdapter<T = unknown> {\n get(key: string): Promise<T | null>;\n set(key: string, value: T, ttl: number): 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 async get(key: string): Promise<T | null> {\n const entry = this.store.get(key);\n if (!entry) return null;\n if (Date.now() > entry.expiresAt) {\n this.store.delete(key);\n return null;\n }\n return entry.value;\n }\n\n async set(key: string, value: T, ttl: number): Promise<void> {\n this.store.set(key, { value, expiresAt: Date.now() + ttl * 1000 });\n }\n}\n\n/**\n * Minimal shape compatible with the OpenAI SDKs chat.completions.create,\n * so consumers can pass an OpenAI client directly\n * `response_format.json_schema` and `reasoning_effort` are optional on the wire\n * providers that don't support them will just ignore fields they don't recognize,\n * but not every SDKs TS types accept them, hence this being a structural type\n * rather than importing the SDKs own params type\n */\nexport interface LLMClient {\n chat: {\n completions: {\n create(\n params: {\n model: string;\n temperature: number;\n max_tokens: number;\n response_format?:\n | { type: 'json_object' }\n | {\n type: 'json_schema';\n json_schema: {\n name: string;\n schema: Record<string, unknown>;\n strict?: boolean;\n description?: string;\n };\n };\n /** OpenAI reasoning-model param (o-series, gpt-5), ignored by providers that don't support it */\n reasoning_effort?: 'minimal' | 'low' | 'medium' | 'high';\n messages: Array<{ role: 'system' | 'user'; content: string }>;\n },\n options: { signal: AbortSignal },\n ): Promise<{\n choices?: Array<{ message?: { content?: string | null } }>;\n usage?: {\n prompt_tokens?: number;\n completion_tokens?: number;\n total_tokens?: number;\n };\n }>;\n };\n };\n}\n\nexport type ReserveUsage = () => Promise<void>;\nexport type RefundUsage = () => Promise<void>;\n\nexport interface TokenUsage {\n promptTokens: number;\n completionTokens: number;\n totalTokens: number;\n requestId: string;\n model: string;\n}\n\nexport type OnUsage = (usage: TokenUsage) => void;\n\n/**\n * Minimal structural type for a Zod-like schema, so this package doesnt need\n * a hard dependency on a specific Zod major version. Any object exposing\n * `safeParse` (Zod v3/v4, and most Zod-compatible validators) should satisfy this\n */\nexport interface SchemaLike<T> {\n safeParse(data: unknown):\n | { success: true; data: T }\n | { success: false; error: unknown };\n}\n\n\nexport interface VernLLMOptions {\n client: LLMClient;\n model: string;\n /** Max retries after the first attempt. Default 1 (2 attempts total) */\n maxRetries?: number;\n /** Per-attempt timeout in ms. Default 25000 */\n timeoutMs?: number;\n /** Base delay for exponential backoff in ms. Default 500 */\n baseDelayMs?: number;\n /** Default max_tokens for calls that don't override it. Default 1000 */\n defaultMaxTokens?: number;\n /** Enables debug logging of raw model output. Default: NODE_ENV !== 'production' */\n debug?: boolean;\n /** Cache adapter for cachedCall. Defaults to an in-memory adapter */\n cache?: CacheAdapter;\n /** HTTP status codes that should fail fast without retrying. Default [400, 401, 403] */\n nonRetryableStatus?: number[];\n /** Custom JSON parser. Must return undefined/null on failure. Default: JSON.parse wrapped in try/catch */\n parseJson?: (content: string) => unknown;\n /** Called after every successful call with token usage, if the provider reports it */\n onUsage?: OnUsage;\n /** Injectable logger. Defaults to a console-based logger gated by `debug` */\n logger?: import('./logger.js').Logger;\n /**\n * Enables a circuit breaker that short-circuits calls after repeated\n * consecutive failures, instead of continuing to hammer a down provider\n * Pass `true` for defaults, or an options object to tune threshold/cooldown\n */\n circuitBreaker?: boolean | import('./circuitBreaker.js').CircuitBreakerOptions;\n}\n\n/**\n * A provider-native JSON Schema for structured outputs (OpenAI/Groq\n * `response_format: { type: 'json_schema' }`) This is the wire-format\n * schema the model is constrained to generate against, distinct from\n * `schema`, which is a client-side Zod validator run on the parsed result\n * You can use one, both, or neither; using both gets you provider-level\n * constraint plus client-side type inference/validation as a safety net\n */\nexport interface JsonSchemaSpec {\n name: string;\n schema: Record<string, unknown>;\n /** Enforces the schema strictly (OpenAI-specific), default true when supported */\n strict?: boolean;\n description?: string;\n}\n\nexport interface CallParams<T = unknown> {\n systemPrompt: string;\n userContent: string;\n temperature?: number;\n jsonMode?: boolean;\n maxTokens?: number;\n requestId?: string;\n signal?: AbortSignal;\n /** Overrides the model set on the VernLLM instance for this call only */\n model?: string;\n /**\n * OpenAI-style reasoning effort for reasoning models (o-series, gpt-5, etc).\n * Passed through as-is, providers/models that don't support it ignore it\n */\n reasoningEffort?: 'minimal' | 'low' | 'medium' | 'high';\n /**\n * Provider-native JSON Schema structured-output mode. When set, this is sent\n * as `response_format: { type: 'json_schema', json_schema: ... }` instead of\n * the looser `json_object` mode, constraining the models output shape at\n * generation time (not just validating it after the fact). Implies jsonMode: true.\n */\n jsonSchema?: JsonSchemaSpec;\n /**\n * Optional Zod (or Zod-compatible) schema. When provided, the parsed JSON\n * is validated against it; on failure an LLMError('validation') is thrown\n * with `.issues` set to the schema's error object. Implies jsonMode: true.\n * Can be combined with `jsonSchema` for provider-level constraint + client-side typing.\n */\n schema?: SchemaLike<T>;\n}\n\nexport interface CachedCallParams<T> {\n cacheKey: string;\n ttl: number;\n fn: () => Promise<T>;\n reserveUsage?: ReserveUsage;\n refundUsage?: RefundUsage;\n}","import { LLMError } from './types.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}","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}","import { LLMError } from \"../types.js\";\n\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. The internal\n * timer is always cleared afterward, whether the function succeeds,\n * fails, or is aborted, 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 } 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(\n baseDelayMs: number,\n attempt: number,\n maxDelayMs = 10_000,\n): 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(\n delay: number,\n signal?: AbortSignal,\n): 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}","import { randomUUID } from 'crypto';\n\nimport { CircuitBreaker } from './circuitBreaker.js';\nimport { ConsoleLogger, type Logger } from './logger.js';\nimport {\n LLMError,\n InMemoryCacheAdapter,\n type VernLLMOptions,\n type CallParams,\n type CachedCallParams,\n type CacheAdapter,\n type LLMClient,\n} from './types.js';\nimport {\n defaultParseJson,\n extractStatus,\n withTimeout,\n getBackoffDelay,\n waitForRetry,\n} from './internal/vernLLM.utilts.js';\n\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 /**\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 ??\n 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(\n options: VernLLMOptions,\n ): CircuitBreaker | undefined {\n if (!options.circuitBreaker) return undefined;\n\n return new CircuitBreaker(\n options.circuitBreaker === true ? undefined : options.circuitBreaker,\n );\n }\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 /**\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 /**\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 /**\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>(\n params: CallParams<T>,\n requestId: string,\n ): Promise<T> {\n const { useJson, model, request } = this.buildRequestPayload(params);\n\n const response = await withTimeout(\n (attemptSignal) =>\n 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(\n `[vern:${requestId}] output:\\n${content.slice(0, 800)}`,\n );\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 /**\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 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 const request = {\n model,\n temperature,\n max_tokens: maxTokens,\n ...(responseFormat ? { response_format: responseFormat } : {}),\n ...(reasoningEffort ? { reasoning_effort: reasoningEffort } : {}),\n messages: [\n { role: 'system' as const, content: systemPrompt },\n { role: 'user' as const, content: userContent },\n ],\n };\n\n return { useJson, model, request };\n }\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(\n jsonSchema: CallParams<unknown>['jsonSchema'],\n useJson: boolean,\n ) {\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 /**\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<\n ReturnType<LLMClient['chat']['completions']['create']>\n >,\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 /**\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>(\n content: string,\n schema?: CallParams<T>['schema'],\n ): T {\n const parsed = this.parseJson(content);\n\n if (parsed == null) {\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(\n 'Schema validation failed',\n 'validation',\n undefined,\n result.error,\n );\n }\n\n return result.data;\n }\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(\n requestId: string,\n attempt: number,\n signal?: AbortSignal,\n ) {\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 /**\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 (\n error instanceof LLMError &&\n (error.type === 'parse' || error.type === 'validation')\n ) {\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 /**\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 != null) {\n return cached 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:\n refundError instanceof Error ? refundError.message : 'unknown',\n });\n }\n\n throw error;\n }\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 /**\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}","import type { LLMClient } from '../types.js';\n\n/** Minimal structural type for the Anthropic SDKs `messages.create` */\ninterface 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 },\n options: { signal: AbortSignal },\n ): Promise<{\n content: Array<{ type: string; text?: string }>;\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. Anthropics Messages API has no\n * `response_format: json_object` equivalent, so when the caller requests\n * JSON mode, this adapter appends an instruction to the system prompt\n * asking the model to respond with JSON only\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 const userMessages = params.messages.filter((m) => m.role === 'user');\n\n // Anthropics Messages API has no `response_format: json_object` or\n // `json_schema` equivalent, so both are emulated via system prompt\n // instructions. For json_schema, the schema itself is embedded so the\n // model has something concrete to conform to (not provider-enforced,\n // unlike OpenAIs native structured outputs)\n let jsonInstruction: string | undefined;\n if (params.response_format?.type === 'json_schema') {\n const { name, schema } = params.response_format.json_schema;\n jsonInstruction = `Respond with valid JSON only, no prose or markdown fences. The JSON must conform to this schema (name: \"${name}\"):\\n${JSON.stringify(schema)}`;\n } else if (params.response_format?.type === 'json_object') {\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: userMessages.map((m) => ({ role: 'user' as const, content: m.content })),\n },\n options,\n );\n\n const text = response.content.find((block) => block.type === 'text')?.text ?? '';\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}","import type { LLMClient } from '../types.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 */\ninterface GeminiClient {\n generateContent(\n params: {\n model?: string;\n contents: Array<{ role: \"user\"; 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 const userMessages = params.messages.filter((m) => m.role === 'user');\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: userMessages.map((m) => ({\n role: '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}","import type { LLMClient } from '../types.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 */\ninterface BedrockConverseClient {\n converse(\n params: {\n modelId: string;\n messages: Array<{ role: 'user'; content: Array<{ text: string }> }>;\n system?: Array<{ text: string }>;\n inferenceConfig?: { temperature?: number; maxTokens?: number };\n },\n options: { signal: AbortSignal },\n ): Promise<{\n output?: { message?: { content?: Array<{ text?: string }> } };\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 * Theres no uniform native JSON Schema enforcement across families here\n * (some support it via forced tool-use, which varies per model), so\n * `jsonSchema`/`jsonMode` are emulated via a system-prompt instruction, same\n * approach as the Anthropic adapter. `reasoning_effort` has no Converse\n * equivalent and is dropped\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 const userMessages = params.messages.filter((m) => m.role === 'user');\n\n let jsonInstruction: string | undefined;\n if (params.response_format?.type === 'json_schema') {\n const { name, schema } = params.response_format.json_schema;\n jsonInstruction = `Respond with valid JSON only, no prose or markdown fences. The JSON must conform to this schema (name: \"${name}\"):\\n${JSON.stringify(schema)}`;\n } else if (params.response_format?.type === 'json_object') {\n jsonInstruction = 'Respond with valid JSON only, no prose or markdown fences.';\n }\n\n const systemParts = [systemMessage?.content, jsonInstruction].filter(\n (s): s is string => Boolean(s),\n );\n\n const response = await bedrockClient.converse(\n {\n modelId: params.model,\n messages: userMessages.map((m) => ({\n role: 'user' as const,\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 },\n options,\n );\n\n const text =\n response.output?.message?.content?.map((c) => c.text ?? '').join('') ?? '';\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}","import type { LLMClient } from '../types.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}","import type { LLMClient } from \"../types.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;"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,IAAa,WAAb,cAA8B,MAAM;CAClC,YACEA,SACOC,MACAC,QACAC,QACP;AACA,QAAM,QAAQ;EA6LhB,KAjMS;EAiMR,KAhMQ;EAgMP,KA/LO;AAGP,OAAK,OAAO;CACb;AACF;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OAAO;EAEzE,MAAM,MAAM,MAAM,MAAM,KAAK;GAC3B,QAAQ,OAAO,UAAU;GACzB,SAAS;IAAE,gBAAgB;IAAoB,GAAG;GAAS;GAC3D,MAAM,KAAK,UAAU,OAAO,WAAW,OAAO,CAAC;GAC/C,QAAQ,QAAQ;EACjB,EAAC;AAEF,OAAK,IAAI,IAAI;GACX,MAAM,OAAO,MAAM,IAAI,MAAM,CAAC,MAAM,MAAM,GAAG;GAC7C,MAAM,MAAM,IAAI,OACb,gCAAgC,IAAI,OAAO,KAAK,KAAK,MAAM,GAAG,IAAI,CAAC;AAEtE,OAAI,SAAS,IAAI;AACjB,SAAM;EACP;EAED,MAAM,OAAO,MAAM,IAAI,MAAM;EAC7B,MAAM,EAAE,SAAS,OAAO,GAAG,OAAO,YAAY,KAAK;AAEnD,SAAO;GACL,SAAS,CAAC,EAAE,SAAS,EAAE,QAAS,EAAE,CAAC;GACnC,OAAO,QACH;IACE,eAAe,MAAM;IACrB,mBAAmB,MAAM;IACzB,cAAc,MAAM;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"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["message: string","type: LLMErrorType","status?: number","issues?: unknown","err: unknown","key: string","value: T","ttl: number","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>","options: VernLLMOptions","params: CallParams<T>","fn: () => Promise<T>","requestId: string","signal?: AbortSignal","lastError: unknown","error: unknown","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","params: CachedCallParams<T>","params: Omit<CachedCallParams<T>, 'fn'> & { call: CallParams<T> }","anthropicClient: AnthropicClient","jsonInstruction: string | undefined","geminiClient: GeminiClient","generationConfig: NonNullable<\n Parameters<GeminiClient['generateContent']>[0]['generationConfig']\n >","bedrockClient: BedrockConverseClient","jsonInstruction: string | undefined","text","config: FetchAdapterConfig","client: unknown"],"sources":["../src/types.ts","../src/circuitBreaker.ts","../src/internal/vernLLM.utilts.ts","../src/logger.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\nexport interface CacheAdapter<T = unknown> {\n get(key: string): Promise<T | null>;\n set(key: string, value: T, ttl: number): 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 async get(key: string): Promise<T | null> {\n const entry = this.store.get(key);\n if (!entry) return null;\n if (Date.now() > entry.expiresAt) {\n this.store.delete(key);\n return null;\n }\n return entry.value;\n }\n\n async set(key: string, value: T, ttl: number): Promise<void> {\n this.store.set(key, { value, expiresAt: Date.now() + ttl * 1000 });\n }\n}\n\n/**\n * Minimal shape compatible with the OpenAI SDKs chat.completions.create,\n * so consumers can pass an OpenAI client directly\n * `response_format.json_schema` and `reasoning_effort` are optional on the wire\n * providers that don't support them will just ignore fields they don't recognize,\n * but not every SDKs TS types accept them, hence this being a structural type\n * rather than importing the SDKs own params type\n */\nexport interface LLMClient {\n chat: {\n completions: {\n create(\n params: {\n model: string;\n temperature: number;\n max_tokens: number;\n response_format?:\n | { type: 'json_object' }\n | {\n type: 'json_schema';\n json_schema: {\n name: string;\n schema: Record<string, unknown>;\n strict?: boolean;\n description?: string;\n };\n };\n /** OpenAI reasoning-model param (o-series, gpt-5), ignored by providers that don't support it */\n reasoning_effort?: 'minimal' | 'low' | 'medium' | 'high';\n messages: Array<{ role: 'system' | 'user'; content: string }>;\n },\n options: { signal: AbortSignal },\n ): Promise<{\n choices?: Array<{ message?: { content?: string | null } }>;\n usage?: {\n prompt_tokens?: number;\n completion_tokens?: number;\n total_tokens?: number;\n };\n }>;\n };\n };\n}\n\nexport type ReserveUsage = () => Promise<void>;\nexport type RefundUsage = () => Promise<void>;\n\nexport interface TokenUsage {\n promptTokens: number;\n completionTokens: number;\n totalTokens: number;\n requestId: string;\n model: string;\n}\n\nexport type OnUsage = (usage: TokenUsage) => void;\n\n/**\n * Minimal structural type for a Zod-like schema, so this package doesnt need\n * a hard dependency on a specific Zod major version. Any object exposing\n * `safeParse` (Zod v3/v4, and most Zod-compatible validators) should satisfy this\n */\nexport interface SchemaLike<T> {\n safeParse(data: unknown): { success: true; data: T } | { success: false; error: unknown };\n}\n\nexport interface VernLLMOptions {\n client: LLMClient;\n model: string;\n /** Max retries after the first attempt. Default 1 (2 attempts total) */\n maxRetries?: number;\n /** Per-attempt timeout in ms. Default 25000 */\n timeoutMs?: number;\n /** Base delay for exponential backoff in ms. Default 500 */\n baseDelayMs?: number;\n /** Default max_tokens for calls that don't override it. Default 1000 */\n defaultMaxTokens?: number;\n /** Enables debug logging of raw model output. Default: NODE_ENV !== 'production' */\n debug?: boolean;\n /** Cache adapter for cachedCall. Defaults to an in-memory adapter */\n cache?: CacheAdapter;\n /** HTTP status codes that should fail fast without retrying. Default [400, 401, 403] */\n nonRetryableStatus?: number[];\n /** Custom JSON parser. Must return undefined/null on failure. Default: JSON.parse wrapped in try/catch */\n parseJson?: (content: string) => unknown;\n /** Called after every successful call with token usage, if the provider reports it */\n onUsage?: OnUsage;\n /** Injectable logger. Defaults to a console-based logger gated by `debug` */\n logger?: import('./logger.js').Logger;\n /**\n * Enables a circuit breaker that short-circuits calls after repeated\n * consecutive failures, instead of continuing to hammer a down provider\n * Pass `true` for defaults, or an options object to tune threshold/cooldown\n */\n circuitBreaker?: boolean | import('./circuitBreaker.js').CircuitBreakerOptions;\n}\n\n/**\n * A provider-native JSON Schema for structured outputs (OpenAI/Groq\n * `response_format: { type: 'json_schema' }`) This is the wire-format\n * schema the model is constrained to generate against, distinct from\n * `schema`, which is a client-side Zod validator run on the parsed result\n * You can use one, both, or neither; using both gets you provider-level\n * constraint plus client-side type inference/validation as a safety net\n */\nexport interface JsonSchemaSpec {\n name: string;\n schema: Record<string, unknown>;\n /** Enforces the schema strictly (OpenAI-specific), default true when supported */\n strict?: boolean;\n description?: string;\n}\n\nexport interface CallParams<T = unknown> {\n systemPrompt: string;\n userContent: string;\n temperature?: number;\n jsonMode?: boolean;\n maxTokens?: number;\n requestId?: string;\n signal?: AbortSignal;\n /** Overrides the model set on the VernLLM instance for this call only */\n model?: string;\n /**\n * OpenAI-style reasoning effort for reasoning models (o-series, gpt-5, etc).\n * Passed through as-is, providers/models that don't support it ignore it\n */\n reasoningEffort?: 'minimal' | 'low' | 'medium' | 'high';\n /**\n * Provider-native JSON Schema structured-output mode. When set, this is sent\n * as `response_format: { type: 'json_schema', json_schema: ... }` instead of\n * the looser `json_object` mode, constraining the models output shape at\n * generation time (not just validating it after the fact). Implies jsonMode: true.\n */\n jsonSchema?: JsonSchemaSpec;\n /**\n * Optional Zod (or Zod-compatible) schema. When provided, the parsed JSON\n * is validated against it; on failure an LLMError('validation') is thrown\n * with `.issues` set to the schema's error object. Implies jsonMode: true.\n * Can be combined with `jsonSchema` for provider-level constraint + client-side typing.\n */\n schema?: SchemaLike<T>;\n}\n\nexport interface CachedCallParams<T> {\n cacheKey: string;\n ttl: number;\n fn: () => Promise<T>;\n reserveUsage?: ReserveUsage;\n refundUsage?: RefundUsage;\n}\n","import { LLMError } from './types.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.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. The internal\n * timer is always cleared afterward, whether the function succeeds,\n * fails, or is aborted, 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 } 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","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.utilts.js';\nimport { ConsoleLogger, type Logger } from './logger.js';\nimport {\n LLMError,\n InMemoryCacheAdapter,\n type VernLLMOptions,\n type CallParams,\n type CachedCallParams,\n type CacheAdapter,\n type LLMClient,\n} from './types.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 * 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 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 const request = {\n model,\n temperature,\n max_tokens: maxTokens,\n ...(responseFormat ? { response_format: responseFormat } : {}),\n ...(reasoningEffort ? { reasoning_effort: reasoningEffort } : {}),\n messages: [\n { role: 'system' as const, content: systemPrompt },\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 * 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 !== null) {\n return cached 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.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 },\n options: { signal: AbortSignal },\n ): Promise<{\n content: Array<{ type: string; text?: string }>;\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. Anthropics Messages API has no\n * `response_format: json_object` equivalent, so when the caller requests\n * JSON mode, this adapter appends an instruction to the system prompt\n * asking the model to respond with JSON only\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 const userMessages = params.messages.filter((m) => m.role === 'user');\n\n // Anthropics Messages API has no `response_format: json_object` or\n // `json_schema` equivalent, so both are emulated via system prompt\n // instructions. For json_schema, the schema itself is embedded so the\n // model has something concrete to conform to (not provider-enforced,\n // unlike OpenAIs native structured outputs)\n let jsonInstruction: string | undefined;\n if (params.response_format?.type === 'json_schema') {\n const { name, schema } = params.response_format.json_schema;\n jsonInstruction = `Respond with valid JSON only, no prose or markdown fences. The JSON must conform to this schema (name: \"${name}\"):\\n${JSON.stringify(schema)}`;\n } else if (params.response_format?.type === 'json_object') {\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: userMessages.map((m) => ({ role: 'user' as const, content: m.content })),\n },\n options,\n );\n\n const text = response.content.find((block) => block.type === 'text')?.text ?? '';\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.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'; 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 const userMessages = params.messages.filter((m) => m.role === 'user');\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: userMessages.map((m) => ({\n role: '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.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'; content: Array<{ text: string }> }>;\n system?: Array<{ text: string }>;\n inferenceConfig?: { temperature?: number; maxTokens?: number };\n },\n options: { signal: AbortSignal },\n ): Promise<{\n output?: { message?: { content?: Array<{ text?: string }> } };\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 * Theres no uniform native JSON Schema enforcement across families here\n * (some support it via forced tool-use, which varies per model), so\n * `jsonSchema`/`jsonMode` are emulated via a system-prompt instruction, same\n * approach as the Anthropic adapter. `reasoning_effort` has no Converse\n * equivalent and is dropped\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 const userMessages = params.messages.filter((m) => m.role === 'user');\n\n let jsonInstruction: string | undefined;\n if (params.response_format?.type === 'json_schema') {\n const { name, schema } = params.response_format.json_schema;\n jsonInstruction = `Respond with valid JSON only, no prose or markdown fences. The JSON must conform to this schema (name: \"${name}\"):\\n${JSON.stringify(schema)}`;\n } else if (params.response_format?.type === 'json_object') {\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: userMessages.map((m) => ({\n role: 'user' as const,\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 },\n options,\n );\n\n const text = response.output?.message?.content?.map((c) => c.text ?? '').join('') ?? '';\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.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.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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,IAAa,WAAb,cAA8B,MAAM;CAClC,YACEA,SACOC,MACAC,QACAC,QACP;AACA,QAAM,QAAQ;EA2LjB,KA/LU;EA+LT,KA9LS;EA8LR,KA7LQ;AAGP,OAAK,OAAO;CACb;AACF;AAED,SAAgB,WAAWC,KAA+B;AACxD,QAAO,eAAe;AACvB;;;;;AAWD,IAAa,uBAAb,MAA0E;CACxE,AAAQ,QAAQ,IAAI;CAEpB,MAAM,IAAIC,KAAgC;EACxC,MAAM,QAAQ,KAAK,MAAM,IAAI,IAAI;AACjC,OAAK,MAAO,QAAO;AACnB,MAAI,KAAK,KAAK,GAAG,MAAM,WAAW;AAChC,QAAK,MAAM,OAAO,IAAI;AACtB,UAAO;EACR;AACD,SAAO,MAAM;CAC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AAQ,QAAQ;EACjB,EAAC;AAEF,OAAK,IAAI,IAAI;GACX,MAAM,OAAO,MAAM,IAAI,MAAM,CAAC,MAAM,MAAM,GAAG;GAC7C,MAAM,MAAM,IAAI,OACb,gCAAgC,IAAI,OAAO,KAAK,KAAK,MAAM,GAAG,IAAI,CAAC;AAEtE,OAAI,SAAS,IAAI;AACjB,SAAM;EACP;EAED,MAAM,OAAO,MAAM,IAAI,MAAM;EAC7B,MAAM,EAAE,SAAS,OAAO,GAAG,OAAO,YAAY,KAAK;AAEnD,SAAO;GACL,SAAS,CAAC,EAAE,SAAS,EAAE,QAAS,EAAE,CAAC;GACnC,OAAO,QACH;IACE,eAAe,MAAM;IACrB,mBAAmB,MAAM;IACzB,cAAc,MAAM;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"}
|
package/dist/index.d.cts
CHANGED
|
@@ -16,6 +16,8 @@ declare class ConsoleLogger implements Logger {
|
|
|
16
16
|
error(message: string, meta?: Record<string, unknown>): void;
|
|
17
17
|
} //#endregion
|
|
18
18
|
//#region src/circuitBreaker.d.ts
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
19
21
|
interface CircuitBreakerOptions {
|
|
20
22
|
/** Consecutive failures before the circuit opens, default 5 */
|
|
21
23
|
threshold?: number;
|
|
@@ -222,6 +224,8 @@ interface CachedCallParams<T> {
|
|
|
222
224
|
refundUsage?: RefundUsage;
|
|
223
225
|
} //#endregion
|
|
224
226
|
//#region src/vernLLM.d.ts
|
|
227
|
+
|
|
228
|
+
//# sourceMappingURL=types.d.ts.map
|
|
225
229
|
/**
|
|
226
230
|
* A resilient wrapper around an LLM chat completions client, this is VernLLM!
|
|
227
231
|
*
|
|
@@ -367,6 +371,7 @@ declare class VernLLM {
|
|
|
367
371
|
|
|
368
372
|
//#endregion
|
|
369
373
|
//#region src/adapters/anthropic.d.ts
|
|
374
|
+
//# sourceMappingURL=vernLLM.d.ts.map
|
|
370
375
|
/** Minimal structural type for the Anthropic SDKs `messages.create` */
|
|
371
376
|
interface AnthropicClient {
|
|
372
377
|
messages: {
|
|
@@ -404,6 +409,7 @@ declare function fromAnthropic(anthropicClient: AnthropicClient): LLMClient;
|
|
|
404
409
|
|
|
405
410
|
//#endregion
|
|
406
411
|
//#region src/adapters/gemini.d.ts
|
|
412
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
407
413
|
/**
|
|
408
414
|
* Minimal structural type for Geminis `generateContent`, matching both the
|
|
409
415
|
* legacy `@google/generative-ai` SDKs `model.generateContent(...)` and the
|
|
@@ -414,7 +420,7 @@ interface GeminiClient {
|
|
|
414
420
|
generateContent(params: {
|
|
415
421
|
model?: string;
|
|
416
422
|
contents: Array<{
|
|
417
|
-
role:
|
|
423
|
+
role: 'user';
|
|
418
424
|
parts: Array<{
|
|
419
425
|
text: string;
|
|
420
426
|
}>;
|
|
@@ -462,6 +468,7 @@ declare function fromGemini(geminiClient: GeminiClient): LLMClient;
|
|
|
462
468
|
|
|
463
469
|
//#endregion
|
|
464
470
|
//#region src/adapters/bedrock.d.ts
|
|
471
|
+
//# sourceMappingURL=gemini.d.ts.map
|
|
465
472
|
/**
|
|
466
473
|
* Minimal structural type matching AWS Bedrocks Converse API. This is
|
|
467
474
|
* intentionally NOT `BedrockRuntimeClient` itself, the AWS SDK v3 client
|
|
@@ -529,6 +536,7 @@ declare function fromBedrock(bedrockClient: BedrockConverseClient): LLMClient;
|
|
|
529
536
|
|
|
530
537
|
//#endregion
|
|
531
538
|
//#region src/adapters/fetch.d.ts
|
|
539
|
+
//# sourceMappingURL=bedrock.d.ts.map
|
|
532
540
|
/** The chat-completion-shaped request VernLLM builds internally */
|
|
533
541
|
type ChatRequest = Parameters<LLMClient['chat']['completions']['create']>[0];
|
|
534
542
|
interface FetchAdapterConfig {
|
|
@@ -604,5 +612,7 @@ declare const fromFireworks: typeof fromOpenAICompatible;
|
|
|
604
612
|
declare const fromOllama: typeof fromOpenAICompatible;
|
|
605
613
|
|
|
606
614
|
//#endregion
|
|
615
|
+
//# sourceMappingURL=openaiCompatible.d.ts.map
|
|
616
|
+
|
|
607
617
|
export { CacheAdapter, CachedCallParams, CallParams, CircuitBreaker, CircuitBreakerOptions, ConsoleLogger, FetchAdapterConfig, InMemoryCacheAdapter, JsonSchemaSpec, LLMClient, LLMError, LLMErrorType, Logger, OnUsage, RefundUsage, ReserveUsage, SchemaLike, TokenUsage, VernLLM, VernLLMOptions, fromAnthropic, fromBedrock, fromCerebras, fromDeepSeek, fromFetch, fromFireworks, fromGemini, fromGroq, fromMistral, fromOllama, fromOpenAICompatible, fromTogether, isLLMError };
|
|
608
618
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/logger.
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/logger.ts","../src/circuitBreaker.ts","../src/types.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":";UAAiB,MAAA;EAAA,KAAA,CAAA,OAAM,EAAA,MAGS,CAAA,EAAA,IAAM;;gCAAN;;;AAOhC;;;AAAsC,cAAzB,aAAA,YAAyB,MAAA,CAAA;EAAM,QAAA,YAAA;;;;ECR3B,KAAA,CAAA,OAAA,EAAA,MAAA,EAAA,IAAqB,CAAA,EDmBN,MCnBM,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,EAAA,IAAA;AAKrC,CAAA;;;;UALgB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B,MPDnB,CAAA,MAAA,EAAA,MAAA,CAAA,CAAA,CAAA;EAAA;EAWW,MAXA,CAAA,EAAA,MAAA;EAAM;uBOKrB;;;ANbvB;AAKC;;;;;;;IAUY,CAAA;EAAc,CAAA;;;AAiDD;;;;AClE1B;AASA;;;;;AAAmC,iBK4BnB,SAAA,CL5BmB,MAAA,EK4BD,kBL5BC,CAAA,EK4BoB,SL5BpB;;;;AFTnC;;;;;AAUA;;;;AAA4C;;;;ACR5C;AAOK,iBOOW,oBAAA,CPPC,MAAA,EAAA,OAAA,CAAA,EOOsC,SPPtC;;cOYJ,iBAAQ;;cAGR,oBAAW;;cAGX,qBAAY;APVzB;AAA2B,cOad,YPbc,EAAA,OOaF,oBPbE;;AAiDb,cOjCD,YPiCC,EAAA,OOjCW,oBPiCX;AAAY;cO9Bb,sBAAa;;;ANpC1B;AASA;;;AAGiB,cMgCJ,UNhCI,EAAA,OMgCM,oBNhCN"}
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ declare class ConsoleLogger implements Logger {
|
|
|
16
16
|
error(message: string, meta?: Record<string, unknown>): void;
|
|
17
17
|
} //#endregion
|
|
18
18
|
//#region src/circuitBreaker.d.ts
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
19
21
|
interface CircuitBreakerOptions {
|
|
20
22
|
/** Consecutive failures before the circuit opens, default 5 */
|
|
21
23
|
threshold?: number;
|
|
@@ -222,6 +224,8 @@ interface CachedCallParams<T> {
|
|
|
222
224
|
refundUsage?: RefundUsage;
|
|
223
225
|
} //#endregion
|
|
224
226
|
//#region src/vernLLM.d.ts
|
|
227
|
+
|
|
228
|
+
//# sourceMappingURL=types.d.ts.map
|
|
225
229
|
/**
|
|
226
230
|
* A resilient wrapper around an LLM chat completions client, this is VernLLM!
|
|
227
231
|
*
|
|
@@ -367,6 +371,7 @@ declare class VernLLM {
|
|
|
367
371
|
|
|
368
372
|
//#endregion
|
|
369
373
|
//#region src/adapters/anthropic.d.ts
|
|
374
|
+
//# sourceMappingURL=vernLLM.d.ts.map
|
|
370
375
|
/** Minimal structural type for the Anthropic SDKs `messages.create` */
|
|
371
376
|
interface AnthropicClient {
|
|
372
377
|
messages: {
|
|
@@ -404,6 +409,7 @@ declare function fromAnthropic(anthropicClient: AnthropicClient): LLMClient;
|
|
|
404
409
|
|
|
405
410
|
//#endregion
|
|
406
411
|
//#region src/adapters/gemini.d.ts
|
|
412
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
407
413
|
/**
|
|
408
414
|
* Minimal structural type for Geminis `generateContent`, matching both the
|
|
409
415
|
* legacy `@google/generative-ai` SDKs `model.generateContent(...)` and the
|
|
@@ -414,7 +420,7 @@ interface GeminiClient {
|
|
|
414
420
|
generateContent(params: {
|
|
415
421
|
model?: string;
|
|
416
422
|
contents: Array<{
|
|
417
|
-
role:
|
|
423
|
+
role: 'user';
|
|
418
424
|
parts: Array<{
|
|
419
425
|
text: string;
|
|
420
426
|
}>;
|
|
@@ -462,6 +468,7 @@ declare function fromGemini(geminiClient: GeminiClient): LLMClient;
|
|
|
462
468
|
|
|
463
469
|
//#endregion
|
|
464
470
|
//#region src/adapters/bedrock.d.ts
|
|
471
|
+
//# sourceMappingURL=gemini.d.ts.map
|
|
465
472
|
/**
|
|
466
473
|
* Minimal structural type matching AWS Bedrocks Converse API. This is
|
|
467
474
|
* intentionally NOT `BedrockRuntimeClient` itself, the AWS SDK v3 client
|
|
@@ -529,6 +536,7 @@ declare function fromBedrock(bedrockClient: BedrockConverseClient): LLMClient;
|
|
|
529
536
|
|
|
530
537
|
//#endregion
|
|
531
538
|
//#region src/adapters/fetch.d.ts
|
|
539
|
+
//# sourceMappingURL=bedrock.d.ts.map
|
|
532
540
|
/** The chat-completion-shaped request VernLLM builds internally */
|
|
533
541
|
type ChatRequest = Parameters<LLMClient['chat']['completions']['create']>[0];
|
|
534
542
|
interface FetchAdapterConfig {
|
|
@@ -604,5 +612,7 @@ declare const fromFireworks: typeof fromOpenAICompatible;
|
|
|
604
612
|
declare const fromOllama: typeof fromOpenAICompatible;
|
|
605
613
|
|
|
606
614
|
//#endregion
|
|
615
|
+
//# sourceMappingURL=openaiCompatible.d.ts.map
|
|
616
|
+
|
|
607
617
|
export { CacheAdapter, CachedCallParams, CallParams, CircuitBreaker, CircuitBreakerOptions, ConsoleLogger, FetchAdapterConfig, InMemoryCacheAdapter, JsonSchemaSpec, LLMClient, LLMError, LLMErrorType, Logger, OnUsage, RefundUsage, ReserveUsage, SchemaLike, TokenUsage, VernLLM, VernLLMOptions, fromAnthropic, fromBedrock, fromCerebras, fromDeepSeek, fromFetch, fromFireworks, fromGemini, fromGroq, fromMistral, fromOllama, fromOpenAICompatible, fromTogether, isLLMError };
|
|
608
618
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/logger.
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/logger.ts","../src/circuitBreaker.ts","../src/types.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":";UAAiB,MAAA;EAAA,KAAA,CAAA,OAAM,EAAA,MAGS,CAAA,EAAA,IAAM;;gCAAN;;;AAOhC;;;AAAsC,cAAzB,aAAA,YAAyB,MAAA,CAAA;EAAM,QAAA,YAAA;;;;ECR3B,KAAA,CAAA,OAAA,EAAA,MAAA,EAAA,IAAqB,CAAA,EDmBN,MCnBM,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,EAAA,IAAA;AAKrC,CAAA;;;;UALgB,qBAAA;EDFA;;;;;AAUjB,KCDK,YAAA,GDCsB,QAAA,GAAA,MAAA,GAAA,WAAA;;;;AAAiB;;;cCO/B,cAAA;EAfI,QAAA,KAAA;EAOZ,QAAA,mBAAY;;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,CAAA;;;AAiDD;;;;AClE1B;AASA;;;;;AAAmC,iBK4BnB,SAAA,CL5BmB,MAAA,EK4BD,kBL5BC,CAAA,EK4BoB,SL5BpB;;;;AFTnC;;;;;AAUA;;;;AAA4C;;;;ACR5C;AAOK,iBOOW,oBAAA,CPPC,MAAA,EAAA,OAAA,CAAA,EOOsC,SPPtC;;cOYJ,iBAAQ;;cAGR,oBAAW;;cAGX,qBAAY;APVzB;AAA2B,cOad,YPbc,EAAA,OOaF,oBPbE;;AAiDb,cOjCD,YPiCC,EAAA,OOjCW,oBPiCX;AAAY;cO9Bb,sBAAa;;;ANpC1B;AASA;;;AAGiB,cMgCJ,UNhCI,EAAA,OMgCM,oBNhCN"}
|
package/dist/index.js
CHANGED
|
@@ -85,27 +85,6 @@ var CircuitBreaker = class {
|
|
|
85
85
|
}
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
-
//#endregion
|
|
89
|
-
//#region src/logger.ts
|
|
90
|
-
/**
|
|
91
|
-
* Default logger. `debug` is gated by the `debug` option on VernLLM
|
|
92
|
-
* warn/error always fire since they indicate real problems (retries, cache failures)
|
|
93
|
-
*/
|
|
94
|
-
var ConsoleLogger = class {
|
|
95
|
-
constructor(debugEnabled) {
|
|
96
|
-
this.debugEnabled = debugEnabled;
|
|
97
|
-
}
|
|
98
|
-
debug(message) {
|
|
99
|
-
if (this.debugEnabled) console.debug(message);
|
|
100
|
-
}
|
|
101
|
-
warn(message) {
|
|
102
|
-
console.warn(message);
|
|
103
|
-
}
|
|
104
|
-
error(message, meta) {
|
|
105
|
-
console.error(message, meta ?? "");
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
88
|
//#endregion
|
|
110
89
|
//#region src/internal/vernLLM.utilts.ts
|
|
111
90
|
function defaultParseJson(content) {
|
|
@@ -178,6 +157,27 @@ async function waitForRetry(delay, signal) {
|
|
|
178
157
|
});
|
|
179
158
|
}
|
|
180
159
|
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/logger.ts
|
|
162
|
+
/**
|
|
163
|
+
* Default logger. `debug` is gated by the `debug` option on VernLLM
|
|
164
|
+
* warn/error always fire since they indicate real problems (retries, cache failures)
|
|
165
|
+
*/
|
|
166
|
+
var ConsoleLogger = class {
|
|
167
|
+
constructor(debugEnabled) {
|
|
168
|
+
this.debugEnabled = debugEnabled;
|
|
169
|
+
}
|
|
170
|
+
debug(message) {
|
|
171
|
+
if (this.debugEnabled) console.debug(message);
|
|
172
|
+
}
|
|
173
|
+
warn(message) {
|
|
174
|
+
console.warn(message);
|
|
175
|
+
}
|
|
176
|
+
error(message, meta) {
|
|
177
|
+
console.error(message, meta ?? "");
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
181
|
//#endregion
|
|
182
182
|
//#region src/vernLLM.ts
|
|
183
183
|
/**
|
|
@@ -397,8 +397,13 @@ var VernLLM = class {
|
|
|
397
397
|
* carrying the schemas issues, on a failed validation
|
|
398
398
|
*/
|
|
399
399
|
parseAndValidate(content, schema) {
|
|
400
|
-
|
|
401
|
-
|
|
400
|
+
let parsed;
|
|
401
|
+
try {
|
|
402
|
+
parsed = this.parseJson(content);
|
|
403
|
+
} catch {
|
|
404
|
+
throw new LLMError("Invalid JSON response", "parse");
|
|
405
|
+
}
|
|
406
|
+
if (parsed === null || parsed === void 0) throw new LLMError("Invalid JSON response", "parse");
|
|
402
407
|
if (!schema) return parsed;
|
|
403
408
|
const result = schema.safeParse(parsed);
|
|
404
409
|
if (!result.success) throw new LLMError("Schema validation failed", "validation", void 0, result.error);
|
|
@@ -431,12 +436,12 @@ var VernLLM = class {
|
|
|
431
436
|
/**
|
|
432
437
|
* Thin cache wrapper around caller supplied logic. `params.fn` is expected
|
|
433
438
|
* to be a call that itself invokes `this.call(...)` (see `cachedLLMCall`
|
|
434
|
-
* below for a convenience wrapper that wires this up automatically),
|
|
439
|
+
* below for a convenience wrapper that wires this up automatically),
|
|
435
440
|
* `cachedCall` does not itself apply retry/timeout policy.
|
|
436
441
|
*/
|
|
437
442
|
async cachedCall(params) {
|
|
438
443
|
const cached = await this.cache.get(params.cacheKey);
|
|
439
|
-
if (cached
|
|
444
|
+
if (cached !== null) return cached;
|
|
440
445
|
try {
|
|
441
446
|
await params.reserveUsage?.();
|
|
442
447
|
const result = await params.fn();
|
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","key: string","value: T","ttl: number","options: CircuitBreakerOptions","debugEnabled: boolean","message: string","meta?: Record<string, unknown>","content: string","err: unknown","fn: (signal: AbortSignal) => Promise<T>","timeoutMs: number","externalSignal?: AbortSignal","baseDelayMs: number","attempt: number","delay: number","signal?: AbortSignal","options: VernLLMOptions","params: CallParams<T>","fn: () => Promise<T>","requestId: string","signal?: AbortSignal","lastError: unknown","error: unknown","jsonSchema: CallParams<unknown>['jsonSchema']","useJson: boolean","response: Awaited<\n ReturnType<LLMClient['chat']['completions']['create']>\n >","model: string","content: string","schema?: CallParams<T>['schema']","attempt: number","params: CachedCallParams<T>","params: Omit<CachedCallParams<T>, 'fn'> & { call: CallParams<T> }","anthropicClient: AnthropicClient","jsonInstruction: string | undefined","geminiClient: GeminiClient","generationConfig: NonNullable<\n Parameters<GeminiClient['generateContent']>[0]['generationConfig']\n >","bedrockClient: BedrockConverseClient","jsonInstruction: string | undefined","text","config: FetchAdapterConfig","client: unknown"],"sources":["../src/types.ts","../src/circuitBreaker.ts","../src/logger.ts","../src/internal/vernLLM.utilts.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\nexport interface CacheAdapter<T = unknown> {\n get(key: string): Promise<T | null>;\n set(key: string, value: T, ttl: number): 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 async get(key: string): Promise<T | null> {\n const entry = this.store.get(key);\n if (!entry) return null;\n if (Date.now() > entry.expiresAt) {\n this.store.delete(key);\n return null;\n }\n return entry.value;\n }\n\n async set(key: string, value: T, ttl: number): Promise<void> {\n this.store.set(key, { value, expiresAt: Date.now() + ttl * 1000 });\n }\n}\n\n/**\n * Minimal shape compatible with the OpenAI SDKs chat.completions.create,\n * so consumers can pass an OpenAI client directly\n * `response_format.json_schema` and `reasoning_effort` are optional on the wire\n * providers that don't support them will just ignore fields they don't recognize,\n * but not every SDKs TS types accept them, hence this being a structural type\n * rather than importing the SDKs own params type\n */\nexport interface LLMClient {\n chat: {\n completions: {\n create(\n params: {\n model: string;\n temperature: number;\n max_tokens: number;\n response_format?:\n | { type: 'json_object' }\n | {\n type: 'json_schema';\n json_schema: {\n name: string;\n schema: Record<string, unknown>;\n strict?: boolean;\n description?: string;\n };\n };\n /** OpenAI reasoning-model param (o-series, gpt-5), ignored by providers that don't support it */\n reasoning_effort?: 'minimal' | 'low' | 'medium' | 'high';\n messages: Array<{ role: 'system' | 'user'; content: string }>;\n },\n options: { signal: AbortSignal },\n ): Promise<{\n choices?: Array<{ message?: { content?: string | null } }>;\n usage?: {\n prompt_tokens?: number;\n completion_tokens?: number;\n total_tokens?: number;\n };\n }>;\n };\n };\n}\n\nexport type ReserveUsage = () => Promise<void>;\nexport type RefundUsage = () => Promise<void>;\n\nexport interface TokenUsage {\n promptTokens: number;\n completionTokens: number;\n totalTokens: number;\n requestId: string;\n model: string;\n}\n\nexport type OnUsage = (usage: TokenUsage) => void;\n\n/**\n * Minimal structural type for a Zod-like schema, so this package doesnt need\n * a hard dependency on a specific Zod major version. Any object exposing\n * `safeParse` (Zod v3/v4, and most Zod-compatible validators) should satisfy this\n */\nexport interface SchemaLike<T> {\n safeParse(data: unknown):\n | { success: true; data: T }\n | { success: false; error: unknown };\n}\n\n\nexport interface VernLLMOptions {\n client: LLMClient;\n model: string;\n /** Max retries after the first attempt. Default 1 (2 attempts total) */\n maxRetries?: number;\n /** Per-attempt timeout in ms. Default 25000 */\n timeoutMs?: number;\n /** Base delay for exponential backoff in ms. Default 500 */\n baseDelayMs?: number;\n /** Default max_tokens for calls that don't override it. Default 1000 */\n defaultMaxTokens?: number;\n /** Enables debug logging of raw model output. Default: NODE_ENV !== 'production' */\n debug?: boolean;\n /** Cache adapter for cachedCall. Defaults to an in-memory adapter */\n cache?: CacheAdapter;\n /** HTTP status codes that should fail fast without retrying. Default [400, 401, 403] */\n nonRetryableStatus?: number[];\n /** Custom JSON parser. Must return undefined/null on failure. Default: JSON.parse wrapped in try/catch */\n parseJson?: (content: string) => unknown;\n /** Called after every successful call with token usage, if the provider reports it */\n onUsage?: OnUsage;\n /** Injectable logger. Defaults to a console-based logger gated by `debug` */\n logger?: import('./logger.js').Logger;\n /**\n * Enables a circuit breaker that short-circuits calls after repeated\n * consecutive failures, instead of continuing to hammer a down provider\n * Pass `true` for defaults, or an options object to tune threshold/cooldown\n */\n circuitBreaker?: boolean | import('./circuitBreaker.js').CircuitBreakerOptions;\n}\n\n/**\n * A provider-native JSON Schema for structured outputs (OpenAI/Groq\n * `response_format: { type: 'json_schema' }`) This is the wire-format\n * schema the model is constrained to generate against, distinct from\n * `schema`, which is a client-side Zod validator run on the parsed result\n * You can use one, both, or neither; using both gets you provider-level\n * constraint plus client-side type inference/validation as a safety net\n */\nexport interface JsonSchemaSpec {\n name: string;\n schema: Record<string, unknown>;\n /** Enforces the schema strictly (OpenAI-specific), default true when supported */\n strict?: boolean;\n description?: string;\n}\n\nexport interface CallParams<T = unknown> {\n systemPrompt: string;\n userContent: string;\n temperature?: number;\n jsonMode?: boolean;\n maxTokens?: number;\n requestId?: string;\n signal?: AbortSignal;\n /** Overrides the model set on the VernLLM instance for this call only */\n model?: string;\n /**\n * OpenAI-style reasoning effort for reasoning models (o-series, gpt-5, etc).\n * Passed through as-is, providers/models that don't support it ignore it\n */\n reasoningEffort?: 'minimal' | 'low' | 'medium' | 'high';\n /**\n * Provider-native JSON Schema structured-output mode. When set, this is sent\n * as `response_format: { type: 'json_schema', json_schema: ... }` instead of\n * the looser `json_object` mode, constraining the models output shape at\n * generation time (not just validating it after the fact). Implies jsonMode: true.\n */\n jsonSchema?: JsonSchemaSpec;\n /**\n * Optional Zod (or Zod-compatible) schema. When provided, the parsed JSON\n * is validated against it; on failure an LLMError('validation') is thrown\n * with `.issues` set to the schema's error object. Implies jsonMode: true.\n * Can be combined with `jsonSchema` for provider-level constraint + client-side typing.\n */\n schema?: SchemaLike<T>;\n}\n\nexport interface CachedCallParams<T> {\n cacheKey: string;\n ttl: number;\n fn: () => Promise<T>;\n reserveUsage?: ReserveUsage;\n refundUsage?: RefundUsage;\n}","import { LLMError } from './types.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}","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}","import { LLMError } from \"../types.js\";\n\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. The internal\n * timer is always cleared afterward, whether the function succeeds,\n * fails, or is aborted, 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 } 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(\n baseDelayMs: number,\n attempt: number,\n maxDelayMs = 10_000,\n): 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(\n delay: number,\n signal?: AbortSignal,\n): 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}","import { randomUUID } from 'crypto';\n\nimport { CircuitBreaker } from './circuitBreaker.js';\nimport { ConsoleLogger, type Logger } from './logger.js';\nimport {\n LLMError,\n InMemoryCacheAdapter,\n type VernLLMOptions,\n type CallParams,\n type CachedCallParams,\n type CacheAdapter,\n type LLMClient,\n} from './types.js';\nimport {\n defaultParseJson,\n extractStatus,\n withTimeout,\n getBackoffDelay,\n waitForRetry,\n} from './internal/vernLLM.utilts.js';\n\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 /**\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 ??\n 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(\n options: VernLLMOptions,\n ): CircuitBreaker | undefined {\n if (!options.circuitBreaker) return undefined;\n\n return new CircuitBreaker(\n options.circuitBreaker === true ? undefined : options.circuitBreaker,\n );\n }\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 /**\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 /**\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 /**\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>(\n params: CallParams<T>,\n requestId: string,\n ): Promise<T> {\n const { useJson, model, request } = this.buildRequestPayload(params);\n\n const response = await withTimeout(\n (attemptSignal) =>\n 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(\n `[vern:${requestId}] output:\\n${content.slice(0, 800)}`,\n );\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 /**\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 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 const request = {\n model,\n temperature,\n max_tokens: maxTokens,\n ...(responseFormat ? { response_format: responseFormat } : {}),\n ...(reasoningEffort ? { reasoning_effort: reasoningEffort } : {}),\n messages: [\n { role: 'system' as const, content: systemPrompt },\n { role: 'user' as const, content: userContent },\n ],\n };\n\n return { useJson, model, request };\n }\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(\n jsonSchema: CallParams<unknown>['jsonSchema'],\n useJson: boolean,\n ) {\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 /**\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<\n ReturnType<LLMClient['chat']['completions']['create']>\n >,\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 /**\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>(\n content: string,\n schema?: CallParams<T>['schema'],\n ): T {\n const parsed = this.parseJson(content);\n\n if (parsed == null) {\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(\n 'Schema validation failed',\n 'validation',\n undefined,\n result.error,\n );\n }\n\n return result.data;\n }\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(\n requestId: string,\n attempt: number,\n signal?: AbortSignal,\n ) {\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 /**\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 (\n error instanceof LLMError &&\n (error.type === 'parse' || error.type === 'validation')\n ) {\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 /**\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 != null) {\n return cached 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:\n refundError instanceof Error ? refundError.message : 'unknown',\n });\n }\n\n throw error;\n }\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 /**\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}","import type { LLMClient } from '../types.js';\n\n/** Minimal structural type for the Anthropic SDKs `messages.create` */\ninterface 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 },\n options: { signal: AbortSignal },\n ): Promise<{\n content: Array<{ type: string; text?: string }>;\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. Anthropics Messages API has no\n * `response_format: json_object` equivalent, so when the caller requests\n * JSON mode, this adapter appends an instruction to the system prompt\n * asking the model to respond with JSON only\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 const userMessages = params.messages.filter((m) => m.role === 'user');\n\n // Anthropics Messages API has no `response_format: json_object` or\n // `json_schema` equivalent, so both are emulated via system prompt\n // instructions. For json_schema, the schema itself is embedded so the\n // model has something concrete to conform to (not provider-enforced,\n // unlike OpenAIs native structured outputs)\n let jsonInstruction: string | undefined;\n if (params.response_format?.type === 'json_schema') {\n const { name, schema } = params.response_format.json_schema;\n jsonInstruction = `Respond with valid JSON only, no prose or markdown fences. The JSON must conform to this schema (name: \"${name}\"):\\n${JSON.stringify(schema)}`;\n } else if (params.response_format?.type === 'json_object') {\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: userMessages.map((m) => ({ role: 'user' as const, content: m.content })),\n },\n options,\n );\n\n const text = response.content.find((block) => block.type === 'text')?.text ?? '';\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}","import type { LLMClient } from '../types.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 */\ninterface GeminiClient {\n generateContent(\n params: {\n model?: string;\n contents: Array<{ role: \"user\"; 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 const userMessages = params.messages.filter((m) => m.role === 'user');\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: userMessages.map((m) => ({\n role: '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}","import type { LLMClient } from '../types.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 */\ninterface BedrockConverseClient {\n converse(\n params: {\n modelId: string;\n messages: Array<{ role: 'user'; content: Array<{ text: string }> }>;\n system?: Array<{ text: string }>;\n inferenceConfig?: { temperature?: number; maxTokens?: number };\n },\n options: { signal: AbortSignal },\n ): Promise<{\n output?: { message?: { content?: Array<{ text?: string }> } };\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 * Theres no uniform native JSON Schema enforcement across families here\n * (some support it via forced tool-use, which varies per model), so\n * `jsonSchema`/`jsonMode` are emulated via a system-prompt instruction, same\n * approach as the Anthropic adapter. `reasoning_effort` has no Converse\n * equivalent and is dropped\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 const userMessages = params.messages.filter((m) => m.role === 'user');\n\n let jsonInstruction: string | undefined;\n if (params.response_format?.type === 'json_schema') {\n const { name, schema } = params.response_format.json_schema;\n jsonInstruction = `Respond with valid JSON only, no prose or markdown fences. The JSON must conform to this schema (name: \"${name}\"):\\n${JSON.stringify(schema)}`;\n } else if (params.response_format?.type === 'json_object') {\n jsonInstruction = 'Respond with valid JSON only, no prose or markdown fences.';\n }\n\n const systemParts = [systemMessage?.content, jsonInstruction].filter(\n (s): s is string => Boolean(s),\n );\n\n const response = await bedrockClient.converse(\n {\n modelId: params.model,\n messages: userMessages.map((m) => ({\n role: 'user' as const,\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 },\n options,\n );\n\n const text =\n response.output?.message?.content?.map((c) => c.text ?? '').join('') ?? '';\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}","import type { LLMClient } from '../types.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}","import type { LLMClient } from \"../types.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;"],"mappings":";;;AASA,IAAa,WAAb,cAA8B,MAAM;CAClC,YACEA,SACOC,MACAC,QACAC,QACP;AACA,QAAM,QAAQ;EA6LhB,KAjMS;EAiMR,KAhMQ;EAgMP,KA/LO;AAGP,OAAK,OAAO;CACb;AACF;AAED,SAAgB,WAAWC,KAA+B;AACxD,QAAO,eAAe;AACvB;;;;;AAWD,IAAa,uBAAb,MAA0E;CACxE,AAAQ,QAAQ,IAAI;CAEpB,MAAM,IAAIC,KAAgC;EACxC,MAAM,QAAQ,KAAK,MAAM,IAAI,IAAI;AACjC,OAAK,MAAO,QAAO;AACnB,MAAI,KAAK,KAAK,GAAG,MAAM,WAAW;AAChC,QAAK,MAAM,OAAO,IAAI;AACtB,UAAO;EACR;AACD,SAAO,MAAM;CACd;CAED,MAAM,IAAIA,KAAaC,OAAUC,KAA4B;AAC3D,OAAK,MAAM,IAAI,KAAK;GAAE;GAAO,WAAW,KAAK,KAAK,GAAG,MAAM;EAAM,EAAC;CACnE;AACF;;;;;;;;;;ACjCD,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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MErrorType","status?: number","issues?: unknown","err: unknown","key: string","value: T","ttl: number","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>","options: VernLLMOptions","params: CallParams<T>","fn: () => Promise<T>","requestId: string","signal?: AbortSignal","lastError: unknown","error: unknown","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","params: CachedCallParams<T>","params: Omit<CachedCallParams<T>, 'fn'> & { call: CallParams<T> }","anthropicClient: AnthropicClient","jsonInstruction: string | undefined","geminiClient: GeminiClient","generationConfig: NonNullable<\n Parameters<GeminiClient['generateContent']>[0]['generationConfig']\n >","bedrockClient: BedrockConverseClient","jsonInstruction: string | undefined","text","config: FetchAdapterConfig","client: unknown"],"sources":["../src/types.ts","../src/circuitBreaker.ts","../src/internal/vernLLM.utilts.ts","../src/logger.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\nexport interface CacheAdapter<T = unknown> {\n get(key: string): Promise<T | null>;\n set(key: string, value: T, ttl: number): 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 async get(key: string): Promise<T | null> {\n const entry = this.store.get(key);\n if (!entry) return null;\n if (Date.now() > entry.expiresAt) {\n this.store.delete(key);\n return null;\n }\n return entry.value;\n }\n\n async set(key: string, value: T, ttl: number): Promise<void> {\n this.store.set(key, { value, expiresAt: Date.now() + ttl * 1000 });\n }\n}\n\n/**\n * Minimal shape compatible with the OpenAI SDKs chat.completions.create,\n * so consumers can pass an OpenAI client directly\n * `response_format.json_schema` and `reasoning_effort` are optional on the wire\n * providers that don't support them will just ignore fields they don't recognize,\n * but not every SDKs TS types accept them, hence this being a structural type\n * rather than importing the SDKs own params type\n */\nexport interface LLMClient {\n chat: {\n completions: {\n create(\n params: {\n model: string;\n temperature: number;\n max_tokens: number;\n response_format?:\n | { type: 'json_object' }\n | {\n type: 'json_schema';\n json_schema: {\n name: string;\n schema: Record<string, unknown>;\n strict?: boolean;\n description?: string;\n };\n };\n /** OpenAI reasoning-model param (o-series, gpt-5), ignored by providers that don't support it */\n reasoning_effort?: 'minimal' | 'low' | 'medium' | 'high';\n messages: Array<{ role: 'system' | 'user'; content: string }>;\n },\n options: { signal: AbortSignal },\n ): Promise<{\n choices?: Array<{ message?: { content?: string | null } }>;\n usage?: {\n prompt_tokens?: number;\n completion_tokens?: number;\n total_tokens?: number;\n };\n }>;\n };\n };\n}\n\nexport type ReserveUsage = () => Promise<void>;\nexport type RefundUsage = () => Promise<void>;\n\nexport interface TokenUsage {\n promptTokens: number;\n completionTokens: number;\n totalTokens: number;\n requestId: string;\n model: string;\n}\n\nexport type OnUsage = (usage: TokenUsage) => void;\n\n/**\n * Minimal structural type for a Zod-like schema, so this package doesnt need\n * a hard dependency on a specific Zod major version. Any object exposing\n * `safeParse` (Zod v3/v4, and most Zod-compatible validators) should satisfy this\n */\nexport interface SchemaLike<T> {\n safeParse(data: unknown): { success: true; data: T } | { success: false; error: unknown };\n}\n\nexport interface VernLLMOptions {\n client: LLMClient;\n model: string;\n /** Max retries after the first attempt. Default 1 (2 attempts total) */\n maxRetries?: number;\n /** Per-attempt timeout in ms. Default 25000 */\n timeoutMs?: number;\n /** Base delay for exponential backoff in ms. Default 500 */\n baseDelayMs?: number;\n /** Default max_tokens for calls that don't override it. Default 1000 */\n defaultMaxTokens?: number;\n /** Enables debug logging of raw model output. Default: NODE_ENV !== 'production' */\n debug?: boolean;\n /** Cache adapter for cachedCall. Defaults to an in-memory adapter */\n cache?: CacheAdapter;\n /** HTTP status codes that should fail fast without retrying. Default [400, 401, 403] */\n nonRetryableStatus?: number[];\n /** Custom JSON parser. Must return undefined/null on failure. Default: JSON.parse wrapped in try/catch */\n parseJson?: (content: string) => unknown;\n /** Called after every successful call with token usage, if the provider reports it */\n onUsage?: OnUsage;\n /** Injectable logger. Defaults to a console-based logger gated by `debug` */\n logger?: import('./logger.js').Logger;\n /**\n * Enables a circuit breaker that short-circuits calls after repeated\n * consecutive failures, instead of continuing to hammer a down provider\n * Pass `true` for defaults, or an options object to tune threshold/cooldown\n */\n circuitBreaker?: boolean | import('./circuitBreaker.js').CircuitBreakerOptions;\n}\n\n/**\n * A provider-native JSON Schema for structured outputs (OpenAI/Groq\n * `response_format: { type: 'json_schema' }`) This is the wire-format\n * schema the model is constrained to generate against, distinct from\n * `schema`, which is a client-side Zod validator run on the parsed result\n * You can use one, both, or neither; using both gets you provider-level\n * constraint plus client-side type inference/validation as a safety net\n */\nexport interface JsonSchemaSpec {\n name: string;\n schema: Record<string, unknown>;\n /** Enforces the schema strictly (OpenAI-specific), default true when supported */\n strict?: boolean;\n description?: string;\n}\n\nexport interface CallParams<T = unknown> {\n systemPrompt: string;\n userContent: string;\n temperature?: number;\n jsonMode?: boolean;\n maxTokens?: number;\n requestId?: string;\n signal?: AbortSignal;\n /** Overrides the model set on the VernLLM instance for this call only */\n model?: string;\n /**\n * OpenAI-style reasoning effort for reasoning models (o-series, gpt-5, etc).\n * Passed through as-is, providers/models that don't support it ignore it\n */\n reasoningEffort?: 'minimal' | 'low' | 'medium' | 'high';\n /**\n * Provider-native JSON Schema structured-output mode. When set, this is sent\n * as `response_format: { type: 'json_schema', json_schema: ... }` instead of\n * the looser `json_object` mode, constraining the models output shape at\n * generation time (not just validating it after the fact). Implies jsonMode: true.\n */\n jsonSchema?: JsonSchemaSpec;\n /**\n * Optional Zod (or Zod-compatible) schema. When provided, the parsed JSON\n * is validated against it; on failure an LLMError('validation') is thrown\n * with `.issues` set to the schema's error object. Implies jsonMode: true.\n * Can be combined with `jsonSchema` for provider-level constraint + client-side typing.\n */\n schema?: SchemaLike<T>;\n}\n\nexport interface CachedCallParams<T> {\n cacheKey: string;\n ttl: number;\n fn: () => Promise<T>;\n reserveUsage?: ReserveUsage;\n refundUsage?: RefundUsage;\n}\n","import { LLMError } from './types.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.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. The internal\n * timer is always cleared afterward, whether the function succeeds,\n * fails, or is aborted, 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 } 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","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.utilts.js';\nimport { ConsoleLogger, type Logger } from './logger.js';\nimport {\n LLMError,\n InMemoryCacheAdapter,\n type VernLLMOptions,\n type CallParams,\n type CachedCallParams,\n type CacheAdapter,\n type LLMClient,\n} from './types.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 * 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 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 const request = {\n model,\n temperature,\n max_tokens: maxTokens,\n ...(responseFormat ? { response_format: responseFormat } : {}),\n ...(reasoningEffort ? { reasoning_effort: reasoningEffort } : {}),\n messages: [\n { role: 'system' as const, content: systemPrompt },\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 * 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 !== null) {\n return cached 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.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 },\n options: { signal: AbortSignal },\n ): Promise<{\n content: Array<{ type: string; text?: string }>;\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. Anthropics Messages API has no\n * `response_format: json_object` equivalent, so when the caller requests\n * JSON mode, this adapter appends an instruction to the system prompt\n * asking the model to respond with JSON only\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 const userMessages = params.messages.filter((m) => m.role === 'user');\n\n // Anthropics Messages API has no `response_format: json_object` or\n // `json_schema` equivalent, so both are emulated via system prompt\n // instructions. For json_schema, the schema itself is embedded so the\n // model has something concrete to conform to (not provider-enforced,\n // unlike OpenAIs native structured outputs)\n let jsonInstruction: string | undefined;\n if (params.response_format?.type === 'json_schema') {\n const { name, schema } = params.response_format.json_schema;\n jsonInstruction = `Respond with valid JSON only, no prose or markdown fences. The JSON must conform to this schema (name: \"${name}\"):\\n${JSON.stringify(schema)}`;\n } else if (params.response_format?.type === 'json_object') {\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: userMessages.map((m) => ({ role: 'user' as const, content: m.content })),\n },\n options,\n );\n\n const text = response.content.find((block) => block.type === 'text')?.text ?? '';\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.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'; 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 const userMessages = params.messages.filter((m) => m.role === 'user');\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: userMessages.map((m) => ({\n role: '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.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'; content: Array<{ text: string }> }>;\n system?: Array<{ text: string }>;\n inferenceConfig?: { temperature?: number; maxTokens?: number };\n },\n options: { signal: AbortSignal },\n ): Promise<{\n output?: { message?: { content?: Array<{ text?: string }> } };\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 * Theres no uniform native JSON Schema enforcement across families here\n * (some support it via forced tool-use, which varies per model), so\n * `jsonSchema`/`jsonMode` are emulated via a system-prompt instruction, same\n * approach as the Anthropic adapter. `reasoning_effort` has no Converse\n * equivalent and is dropped\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 const userMessages = params.messages.filter((m) => m.role === 'user');\n\n let jsonInstruction: string | undefined;\n if (params.response_format?.type === 'json_schema') {\n const { name, schema } = params.response_format.json_schema;\n jsonInstruction = `Respond with valid JSON only, no prose or markdown fences. The JSON must conform to this schema (name: \"${name}\"):\\n${JSON.stringify(schema)}`;\n } else if (params.response_format?.type === 'json_object') {\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: userMessages.map((m) => ({\n role: 'user' as const,\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 },\n options,\n );\n\n const text = response.output?.message?.content?.map((c) => c.text ?? '').join('') ?? '';\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.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.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"],"mappings":";;;AASA,IAAa,WAAb,cAA8B,MAAM;CAClC,YACEA,SACOC,MACAC,QACAC,QACP;AACA,QAAM,QAAQ;EA2LjB,KA/LU;EA+LT,KA9LS;EA8LR,KA7LQ;AAGP,OAAK,OAAO;CACb;AACF;AAED,SAAgB,WAAWC,KAA+B;AACxD,QAAO,eAAe;AACvB;;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IAAI,OAAO,GAAG,OAAO;EAC3E,MAAM,iBACG,OAAO,YAAY,aAAa,MAAM,OAAO,SAAS,GAAG,OAAO;EAEzE,MAAM,MAAM,MAAM,MAAM,KAAK;GAC3B,QAAQ,OAAO,UAAU;GACzB,SAAS;IAAE,gBAAgB;IAAoB,GAAG;GAAS;GAC3D,MAAM,KAAK,UAAU,OAAO,WAAW,OAAO,CAAC;GAC/C,QAAQ,QAAQ;EACjB,EAAC;AAEF,OAAK,IAAI,IAAI;GACX,MAAM,OAAO,MAAM,IAAI,MAAM,CAAC,MAAM,MAAM,GAAG;GAC7C,MAAM,MAAM,IAAI,OACb,gCAAgC,IAAI,OAAO,KAAK,KAAK,MAAM,GAAG,IAAI,CAAC;AAEtE,OAAI,SAAS,IAAI;AACjB,SAAM;EACP;EAED,MAAM,OAAO,MAAM,IAAI,MAAM;EAC7B,MAAM,EAAE,SAAS,OAAO,GAAG,OAAO,YAAY,KAAK;AAEnD,SAAO;GACL,SAAS,CAAC,EAAE,SAAS,EAAE,QAAS,EAAE,CAAC;GACnC,OAAO,QACH;IACE,eAAe,MAAM;IACrB,mBAAmB,MAAM;IACzB,cAAc,MAAM;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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vern-llm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Retry + timeout + cache wrapper for OpenAI-compatible LLM chat completion calls (OpenAI, Groq, etc).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -19,24 +19,6 @@
|
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=20"
|
|
21
21
|
},
|
|
22
|
-
"scripts": {
|
|
23
|
-
"build": "tsdown",
|
|
24
|
-
"dev": "tsdown --watch",
|
|
25
|
-
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
26
|
-
"typecheck:test": "tsc --noEmit -p tsconfig.test.json",
|
|
27
|
-
|
|
28
|
-
"test": "vitest run",
|
|
29
|
-
"test:unit": "vitest run --project unit",
|
|
30
|
-
"test:int": "vitest run --project integration",
|
|
31
|
-
|
|
32
|
-
"test:watch": "vitest",
|
|
33
|
-
"test:coverage": "vitest run --coverage",
|
|
34
|
-
|
|
35
|
-
"changeset": "changeset",
|
|
36
|
-
"version-packages": "changeset version",
|
|
37
|
-
"release": "pnpm run build && changeset publish",
|
|
38
|
-
"prepublishOnly": "pnpm run typecheck && pnpm run build"
|
|
39
|
-
},
|
|
40
22
|
"peerDependencies": {
|
|
41
23
|
"openai": "^4.0.0"
|
|
42
24
|
},
|
|
@@ -54,6 +36,23 @@
|
|
|
54
36
|
"vitest": "^4.1.10",
|
|
55
37
|
"zod": "^4.4.3"
|
|
56
38
|
},
|
|
57
|
-
"
|
|
58
|
-
"
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public",
|
|
42
|
+
"provenance": true
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsdown",
|
|
46
|
+
"dev": "tsdown --watch",
|
|
47
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
48
|
+
"typecheck:test": "tsc --noEmit -p tsconfig.test.json",
|
|
49
|
+
"test": "vitest run",
|
|
50
|
+
"test:unit": "vitest run --project unit",
|
|
51
|
+
"test:int": "vitest run --project integration",
|
|
52
|
+
"test:watch": "vitest",
|
|
53
|
+
"test:coverage": "vitest run --coverage",
|
|
54
|
+
"changeset": "changeset",
|
|
55
|
+
"version-packages": "changeset version",
|
|
56
|
+
"release": "pnpm run build && changeset publish"
|
|
57
|
+
}
|
|
59
58
|
}
|