vern-llm 2.9.0 → 3.0.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/README.md +58 -24
- package/dist/adapters/index.cjs +12 -0
- package/dist/adapters/index.cjs.map +1 -0
- package/dist/adapters/index.d.cts +582 -0
- package/dist/adapters/index.d.cts.map +1 -0
- package/dist/adapters/index.d.mts +582 -0
- package/dist/adapters/index.d.mts.map +1 -0
- package/dist/adapters/index.mjs +12 -0
- package/dist/adapters/index.mjs.map +1 -0
- package/dist/client-HWxkwVvj.d.cts +1871 -0
- package/dist/client-HWxkwVvj.d.cts.map +1 -0
- package/dist/client-HWxkwVvj.d.mts +1871 -0
- package/dist/client-HWxkwVvj.d.mts.map +1 -0
- package/dist/index.cjs +2 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +176 -3665
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +176 -3665
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -14
- package/dist/index.mjs.map +1 -1
- package/dist/responseBody.utils-B2tQiGUi.mjs +2 -0
- package/dist/responseBody.utils-B2tQiGUi.mjs.map +1 -0
- package/dist/responseBody.utils-CknznUJA.cjs +2 -0
- package/dist/responseBody.utils-CknznUJA.cjs.map +1 -0
- package/package.json +19 -6
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
import { bt as ProviderRateLimitHint, n as LLMClient, v as WireStreamChunk } from "../client-HWxkwVvj.cjs";
|
|
2
|
+
//#region src/adapters/internal/nativeStructuredOutput.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* A list of model ids, or a predicate, naming models with a capability.
|
|
5
|
+
* Native structured output has no built in list: which models support it
|
|
6
|
+
* is the provider's call and changes over time, and a wrong guess would
|
|
7
|
+
* trade a clear local error for a confusing provider one.
|
|
8
|
+
*/
|
|
9
|
+
type ModelCapabilityOverride = string[] | ((model: string) => boolean);
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/adapters/internal/reasoningBudget.utils.d.ts
|
|
12
|
+
/**
|
|
13
|
+
* Converts between `reasoningEffort` tiers and `budgetTokens`, for a
|
|
14
|
+
* provider that only understands the other one. The numbers are a guess,
|
|
15
|
+
* not a provider guarantee, and each adapter's `reasoningEffortTokens`
|
|
16
|
+
* overrides them.
|
|
17
|
+
*/
|
|
18
|
+
type EffortTokenTable = Record<'minimal' | 'low' | 'medium' | 'high', number>;
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/adapters/internal/imageFormat.d.ts
|
|
21
|
+
/**
|
|
22
|
+
* `ImageBlock.mimeType` values every adapter accepts: the types all
|
|
23
|
+
* supported providers share, so content valid for one is valid for all.
|
|
24
|
+
*/
|
|
25
|
+
declare const SUPPORTED_IMAGE_MIME_TYPES: readonly ["image/png", "image/jpeg", "image/gif", "image/webp"];
|
|
26
|
+
type SupportedImageMimeType = (typeof SUPPORTED_IMAGE_MIME_TYPES)[number];
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/adapters/claude/types.d.ts
|
|
29
|
+
/** Anthropic's native per-block content shape for a message. */
|
|
30
|
+
type AnthropicContentBlock = {
|
|
31
|
+
type: 'text';
|
|
32
|
+
text: string;
|
|
33
|
+
} | {
|
|
34
|
+
type: 'image';
|
|
35
|
+
source: {
|
|
36
|
+
type: 'base64';
|
|
37
|
+
media_type: SupportedImageMimeType;
|
|
38
|
+
data: string;
|
|
39
|
+
};
|
|
40
|
+
} | {
|
|
41
|
+
type: 'tool_use';
|
|
42
|
+
id: string;
|
|
43
|
+
name: string;
|
|
44
|
+
input: unknown;
|
|
45
|
+
} | {
|
|
46
|
+
type: 'tool_result';
|
|
47
|
+
tool_use_id: string;
|
|
48
|
+
content: string;
|
|
49
|
+
is_error?: boolean;
|
|
50
|
+
} | {
|
|
51
|
+
type: 'thinking';
|
|
52
|
+
thinking: string;
|
|
53
|
+
signature: string;
|
|
54
|
+
} | {
|
|
55
|
+
type: 'redacted_thinking';
|
|
56
|
+
data: string;
|
|
57
|
+
};
|
|
58
|
+
/** The input side of Anthropic's `usage`, which carries the cache counts. */
|
|
59
|
+
interface AnthropicUsage {
|
|
60
|
+
input_tokens?: number | null;
|
|
61
|
+
cache_creation_input_tokens?: number | null;
|
|
62
|
+
cache_read_input_tokens?: number | null;
|
|
63
|
+
cache_creation?: {
|
|
64
|
+
ephemeral_5m_input_tokens?: number;
|
|
65
|
+
ephemeral_1h_input_tokens?: number;
|
|
66
|
+
} | null;
|
|
67
|
+
}
|
|
68
|
+
/** Minimal structural type for the Anthropic SDK's `messages.create` */
|
|
69
|
+
interface AnthropicClient {
|
|
70
|
+
messages: {
|
|
71
|
+
create(params: {
|
|
72
|
+
model: string;
|
|
73
|
+
max_tokens: number;
|
|
74
|
+
temperature?: number;
|
|
75
|
+
system?: string;
|
|
76
|
+
messages: Array<{
|
|
77
|
+
role: 'user' | 'assistant';
|
|
78
|
+
content: string | AnthropicContentBlock[];
|
|
79
|
+
}>;
|
|
80
|
+
tools?: Array<{
|
|
81
|
+
name: string;
|
|
82
|
+
description?: string;
|
|
83
|
+
input_schema: {
|
|
84
|
+
type: 'object';
|
|
85
|
+
[key: string]: unknown;
|
|
86
|
+
};
|
|
87
|
+
strict?: boolean;
|
|
88
|
+
}>;
|
|
89
|
+
tool_choice?: {
|
|
90
|
+
type: 'auto';
|
|
91
|
+
} | {
|
|
92
|
+
type: 'any';
|
|
93
|
+
} | {
|
|
94
|
+
type: 'none';
|
|
95
|
+
} | {
|
|
96
|
+
type: 'tool';
|
|
97
|
+
name: string;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* `format` is native structured output, which takes only `type` and
|
|
101
|
+
* `schema`. `effort` drives adaptive thinking.
|
|
102
|
+
*/
|
|
103
|
+
output_config?: {
|
|
104
|
+
format?: {
|
|
105
|
+
type: 'json_schema';
|
|
106
|
+
schema: Record<string, unknown>;
|
|
107
|
+
};
|
|
108
|
+
effort?: 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
109
|
+
};
|
|
110
|
+
/** Manual budget thinking, or adaptive thinking paired with `output_config.effort`. */
|
|
111
|
+
thinking?: {
|
|
112
|
+
type: 'enabled';
|
|
113
|
+
budget_tokens: number;
|
|
114
|
+
} | {
|
|
115
|
+
type: 'adaptive';
|
|
116
|
+
};
|
|
117
|
+
}, options: {
|
|
118
|
+
signal: AbortSignal;
|
|
119
|
+
}): Promise<{
|
|
120
|
+
content: Array<{
|
|
121
|
+
type: string;
|
|
122
|
+
text?: string;
|
|
123
|
+
id?: string;
|
|
124
|
+
name?: string;
|
|
125
|
+
input?: unknown;
|
|
126
|
+
thinking?: string;
|
|
127
|
+
signature?: string;
|
|
128
|
+
data?: string;
|
|
129
|
+
}>;
|
|
130
|
+
stop_reason?: string | null;
|
|
131
|
+
usage?: AnthropicUsage & {
|
|
132
|
+
output_tokens?: number;
|
|
133
|
+
output_tokens_details?: {
|
|
134
|
+
thinking_tokens?: number;
|
|
135
|
+
} | null;
|
|
136
|
+
};
|
|
137
|
+
}>;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/adapters/claude/anthropic.d.ts
|
|
142
|
+
/** Optional configuration for `fromAnthropic`. */
|
|
143
|
+
interface AnthropicAdapterOptions {
|
|
144
|
+
/**
|
|
145
|
+
* Models that support native structured output (`output_config.format`),
|
|
146
|
+
* which can be combined with real `tools`. No default: other models
|
|
147
|
+
* emulate `jsonSchema` as a forced tool call.
|
|
148
|
+
*/
|
|
149
|
+
nativeStructuredOutputModels?: ModelCapabilityOverride;
|
|
150
|
+
/** Overrides the token count each `reasoningEffort` tier maps onto. Omitted tiers keep the default. */
|
|
151
|
+
reasoningEffortTokens?: Partial<EffortTokenTable>;
|
|
152
|
+
/**
|
|
153
|
+
* Adds models that only accept adaptive thinking, on top of the built in
|
|
154
|
+
* rule (Claude Opus 4.7 and later, every Claude 5 tier model).
|
|
155
|
+
*/
|
|
156
|
+
adaptiveOnlyModels?: ModelCapabilityOverride;
|
|
157
|
+
/**
|
|
158
|
+
* Replaces the built in list of models that reject a forced `tool_choice`
|
|
159
|
+
* (Claude Fable 5.1 and later, Opus 5.5 and later, every Claude major 6
|
|
160
|
+
* and later). On these, `toolChoice: 'required'` or `{ name }` throws
|
|
161
|
+
* `unsupported_capability` before dispatch, and `jsonSchema` always uses
|
|
162
|
+
* native structured output.
|
|
163
|
+
*/
|
|
164
|
+
forcedToolChoiceUnsupportedModels?: ModelCapabilityOverride;
|
|
165
|
+
/**
|
|
166
|
+
* Whether `messages.create` supports `.withResponse()`, which AIMD's
|
|
167
|
+
* proactive path needs. Default `false`, since a fake or thin wrapper
|
|
168
|
+
* won't implement it.
|
|
169
|
+
*/
|
|
170
|
+
supportsWithResponse?: boolean;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Wraps an Anthropic SDK client as an `LLMClient`. `jsonSchema` uses native
|
|
174
|
+
* structured output on covered models and a forced tool call elsewhere,
|
|
175
|
+
* which can't be combined with `tools`. `json_object` throws, since
|
|
176
|
+
* Anthropic can't guarantee it.
|
|
177
|
+
*/
|
|
178
|
+
export declare function fromAnthropic(anthropicClient: AnthropicClient, options?: AnthropicAdapterOptions): LLMClient;
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/adapters/gemini/types.d.ts
|
|
181
|
+
/** Gemini's per-part content shape; object-typed args match the real SDK. */
|
|
182
|
+
type GeminiPart = {
|
|
183
|
+
text: string;
|
|
184
|
+
} | {
|
|
185
|
+
inlineData: {
|
|
186
|
+
mimeType: string;
|
|
187
|
+
data: string;
|
|
188
|
+
};
|
|
189
|
+
} | {
|
|
190
|
+
functionCall: {
|
|
191
|
+
id?: string;
|
|
192
|
+
name: string;
|
|
193
|
+
args: Record<string, unknown>;
|
|
194
|
+
};
|
|
195
|
+
} | {
|
|
196
|
+
functionResponse: {
|
|
197
|
+
id?: string;
|
|
198
|
+
name: string;
|
|
199
|
+
response: Record<string, unknown>;
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Structural type matching the model methods of the real `@google/genai`
|
|
204
|
+
* SDK (`ai.models`).
|
|
205
|
+
*
|
|
206
|
+
* Every field is shaped to be structurally assignable from the real SDK's
|
|
207
|
+
* generated types without importing them, so provider SDKs stay optional:
|
|
208
|
+
* `model` is required (the real SDK requires it), `functionCall.args` /
|
|
209
|
+
* `functionResponse.response` are `Record<string, unknown>` (matching the
|
|
210
|
+
* real SDK, not `unknown`), `toolConfig...mode` is `any` (TypeScript never
|
|
211
|
+
* treats a string-literal union as assignable to the real SDK's string
|
|
212
|
+
* enum), and response-side `functionCall.name` is optional (matching the
|
|
213
|
+
* real SDK).
|
|
214
|
+
*/
|
|
215
|
+
interface GeminiModels {
|
|
216
|
+
generateContent(params: {
|
|
217
|
+
model: string;
|
|
218
|
+
contents: Array<{
|
|
219
|
+
role: 'user' | 'model';
|
|
220
|
+
parts: GeminiPart[];
|
|
221
|
+
}>;
|
|
222
|
+
config?: {
|
|
223
|
+
systemInstruction?: {
|
|
224
|
+
parts: Array<{
|
|
225
|
+
text: string;
|
|
226
|
+
}>;
|
|
227
|
+
};
|
|
228
|
+
temperature?: number;
|
|
229
|
+
maxOutputTokens?: number;
|
|
230
|
+
responseMimeType?: string;
|
|
231
|
+
responseSchema?: Record<string, unknown>;
|
|
232
|
+
tools?: Array<{
|
|
233
|
+
functionDeclarations: Array<{
|
|
234
|
+
name: string;
|
|
235
|
+
description?: string;
|
|
236
|
+
parameters: Record<string, unknown>;
|
|
237
|
+
}>;
|
|
238
|
+
}>;
|
|
239
|
+
toolConfig?: {
|
|
240
|
+
functionCallingConfig: {
|
|
241
|
+
mode: any;
|
|
242
|
+
allowedFunctionNames?: string[];
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
/** `thinkingBudget` up to Gemini 2.5, `thinkingLevel` from Gemini 3 on. */
|
|
246
|
+
thinkingConfig?: {
|
|
247
|
+
thinkingBudget?: number;
|
|
248
|
+
thinkingLevel?: any;
|
|
249
|
+
};
|
|
250
|
+
abortSignal?: AbortSignal;
|
|
251
|
+
};
|
|
252
|
+
}): Promise<{
|
|
253
|
+
candidates?: Array<{
|
|
254
|
+
content?: {
|
|
255
|
+
parts?: Array<{
|
|
256
|
+
text?: string;
|
|
257
|
+
functionCall?: {
|
|
258
|
+
id?: string;
|
|
259
|
+
name?: string;
|
|
260
|
+
args?: unknown;
|
|
261
|
+
};
|
|
262
|
+
}>;
|
|
263
|
+
};
|
|
264
|
+
finishReason?: string;
|
|
265
|
+
}>;
|
|
266
|
+
usageMetadata?: {
|
|
267
|
+
promptTokenCount?: number;
|
|
268
|
+
candidatesTokenCount?: number;
|
|
269
|
+
totalTokenCount?: number;
|
|
270
|
+
thoughtsTokenCount?: number;
|
|
271
|
+
cachedContentTokenCount?: number;
|
|
272
|
+
};
|
|
273
|
+
}>;
|
|
274
|
+
/** Required only for `stream: true`. Resolves to an iterable of partial responses. */
|
|
275
|
+
generateContentStream?(params: Parameters<GeminiModels['generateContent']>[0]): Promise<AsyncIterable<{
|
|
276
|
+
candidates?: Array<{
|
|
277
|
+
content?: {
|
|
278
|
+
parts?: Array<{
|
|
279
|
+
text?: string;
|
|
280
|
+
functionCall?: {
|
|
281
|
+
id?: string;
|
|
282
|
+
name?: string;
|
|
283
|
+
args?: unknown;
|
|
284
|
+
};
|
|
285
|
+
}>;
|
|
286
|
+
};
|
|
287
|
+
}>;
|
|
288
|
+
usageMetadata?: {
|
|
289
|
+
promptTokenCount?: number;
|
|
290
|
+
candidatesTokenCount?: number;
|
|
291
|
+
totalTokenCount?: number;
|
|
292
|
+
thoughtsTokenCount?: number;
|
|
293
|
+
cachedContentTokenCount?: number;
|
|
294
|
+
};
|
|
295
|
+
}>>;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* The top level `@google/genai` client, `new GoogleGenAI(...)`:
|
|
299
|
+
*
|
|
300
|
+
* ```ts
|
|
301
|
+
* import { GoogleGenAI } from '@google/genai';
|
|
302
|
+
* const ai = new GoogleGenAI({ apiKey: '...' });
|
|
303
|
+
* const llm = new VernLLM({ client: fromGemini(ai), model: 'gemini-2.5-flash' });
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
interface GeminiClient {
|
|
307
|
+
models: GeminiModels;
|
|
308
|
+
/** Set by the SDK; names the provider as Vertex AI or the Gemini API. */
|
|
309
|
+
vertexai?: boolean;
|
|
310
|
+
}
|
|
311
|
+
//#endregion
|
|
312
|
+
//#region src/adapters/gemini/gemini.d.ts
|
|
313
|
+
/** Optional configuration for `fromGemini`. */
|
|
314
|
+
interface GeminiAdapterOptions {
|
|
315
|
+
/** Overrides the token count each `reasoningEffort` tier maps onto. Omitted tiers keep the default. */
|
|
316
|
+
reasoningEffortTokens?: Partial<EffortTokenTable>;
|
|
317
|
+
/**
|
|
318
|
+
* Adds models that use `thinkingLevel` instead of `thinkingBudget`, on top
|
|
319
|
+
* of the built in rule (Gemini 3 and later).
|
|
320
|
+
*/
|
|
321
|
+
thinkingLevelModels?: ModelCapabilityOverride;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Wraps the top level `@google/genai` client as an `LLMClient`. `ai.models`
|
|
325
|
+
* throws at construction, since only the top level client says whether it
|
|
326
|
+
* talks to Vertex AI or the Gemini API. `responseSchema` and `tools` combine
|
|
327
|
+
* natively.
|
|
328
|
+
*/
|
|
329
|
+
export declare function fromGemini(client: GeminiClient, options?: GeminiAdapterOptions): LLMClient;
|
|
330
|
+
//#endregion
|
|
331
|
+
//#region src/adapters/fetch/types.d.ts
|
|
332
|
+
/** The chat-completion-shaped request VernLLM builds internally */
|
|
333
|
+
type ChatRequest = Parameters<LLMClient['chat']['completions']['create']>[0];
|
|
334
|
+
/**
|
|
335
|
+
* The minimal response shape `fromFetch` reads. Native `fetch`'s `Response`
|
|
336
|
+
* satisfies it, as do thin wrappers around `axios`, `node-fetch` or `undici`.
|
|
337
|
+
*/
|
|
338
|
+
interface ResponseLike {
|
|
339
|
+
ok: boolean;
|
|
340
|
+
status: number;
|
|
341
|
+
headers: {
|
|
342
|
+
get(name: string): string | null;
|
|
343
|
+
};
|
|
344
|
+
text(): Promise<string>;
|
|
345
|
+
json(): Promise<unknown>;
|
|
346
|
+
}
|
|
347
|
+
/** A fetch-compatible request function; defaults to native `fetch` */
|
|
348
|
+
type RequestLike = (url: string, init: {
|
|
349
|
+
method: string;
|
|
350
|
+
headers: Record<string, string>;
|
|
351
|
+
body?: string;
|
|
352
|
+
signal?: AbortSignal;
|
|
353
|
+
}) => Promise<ResponseLike>;
|
|
354
|
+
/**
|
|
355
|
+
* A streaming request function: resolves to the response body as an
|
|
356
|
+
* `AsyncIterable` of `Uint8Array` or `string` chunks. Defaults to native
|
|
357
|
+
* `fetch`.
|
|
358
|
+
*/
|
|
359
|
+
type StreamRequestLike = (url: string, init: {
|
|
360
|
+
method: string;
|
|
361
|
+
headers: Record<string, string>;
|
|
362
|
+
body?: string;
|
|
363
|
+
signal?: AbortSignal;
|
|
364
|
+
}) => Promise<AsyncIterable<Uint8Array | string>>;
|
|
365
|
+
interface FetchAdapterConfig {
|
|
366
|
+
/** Endpoint URL, or a function of the request in case it depends on model/params */
|
|
367
|
+
url: string | ((params: ChatRequest) => string);
|
|
368
|
+
/** Static headers, or a function (sync or async) for things like refreshed auth tokens */
|
|
369
|
+
headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
370
|
+
/** HTTP method. Default 'POST' */
|
|
371
|
+
method?: string;
|
|
372
|
+
/**
|
|
373
|
+
* The provider behind `url`, in the OpenTelemetry `gen_ai.provider.name`
|
|
374
|
+
* vocabulary, reported on `AttemptContext.adapter`. Left unset when omitted.
|
|
375
|
+
*/
|
|
376
|
+
provider?: string;
|
|
377
|
+
/** The HTTP transport. Defaults to native `fetch`. */
|
|
378
|
+
request?: RequestLike;
|
|
379
|
+
/** Maps VernLLMs internal chat-completion request into the providers raw request body */
|
|
380
|
+
mapRequest: (params: ChatRequest) => unknown;
|
|
381
|
+
/**
|
|
382
|
+
* Maps the provider's JSON response. `content` may be empty when the model
|
|
383
|
+
* only called tools. Each tool call's `arguments` is the JSON-encoded
|
|
384
|
+
* string, as on OpenAI's wire; VernLLM parses and validates it.
|
|
385
|
+
*/
|
|
386
|
+
mapResponse: (json: unknown) => {
|
|
387
|
+
content?: string;
|
|
388
|
+
usage?: {
|
|
389
|
+
/** Every input token, cache reads and writes included. */
|
|
390
|
+
promptTokens?: number;
|
|
391
|
+
completionTokens?: number;
|
|
392
|
+
totalTokens?: number;
|
|
393
|
+
/** Cache reads, a subset of `promptTokens`. */
|
|
394
|
+
cacheReadTokens?: number;
|
|
395
|
+
/** Cache writes, a subset of `promptTokens`. */
|
|
396
|
+
cacheWriteTokens?: number;
|
|
397
|
+
/** `cacheWriteTokens` by TTL label, e.g. `{ '5m': 1200 }`. */
|
|
398
|
+
cacheWriteTokensByTtl?: Record<string, number>;
|
|
399
|
+
};
|
|
400
|
+
toolCalls?: Array<{
|
|
401
|
+
id: string;
|
|
402
|
+
name: string;
|
|
403
|
+
arguments: string;
|
|
404
|
+
}>;
|
|
405
|
+
};
|
|
406
|
+
/**
|
|
407
|
+
* The streaming transport. Defaults to native `fetch`, and is required for
|
|
408
|
+
* `stream: true` when `request` is set, since it never falls back to it.
|
|
409
|
+
*/
|
|
410
|
+
requestStream?: StreamRequestLike;
|
|
411
|
+
/**
|
|
412
|
+
* Splits the raw stream bytes into events. Defaults to Server-Sent Events
|
|
413
|
+
* framing (`parseSseStream`).
|
|
414
|
+
*/
|
|
415
|
+
parseStreamFrames?: (chunks: AsyncIterable<Uint8Array | string>) => AsyncIterable<unknown>;
|
|
416
|
+
/**
|
|
417
|
+
* Maps one parsed stream event into zero or more chunks; `undefined` skips
|
|
418
|
+
* it. Required for `stream: true`.
|
|
419
|
+
*/
|
|
420
|
+
mapStreamEvent?: (event: unknown) => WireStreamChunk | WireStreamChunk[] | undefined;
|
|
421
|
+
/**
|
|
422
|
+
* Reads AIMD's proactive rate limit hint off a successful response.
|
|
423
|
+
* Defaults to OpenAI's header set.
|
|
424
|
+
*/
|
|
425
|
+
parseRateLimitHint?: (headers: ResponseLike['headers']) => ProviderRateLimitHint;
|
|
426
|
+
}
|
|
427
|
+
//#endregion
|
|
428
|
+
//#region src/adapters/fetch/fetch.d.ts
|
|
429
|
+
/**
|
|
430
|
+
* A raw HTTP adapter for providers with no SDK: supply the URL, headers,
|
|
431
|
+
* and the request and response mapping. A non-2xx response throws an error
|
|
432
|
+
* carrying `status` and `headers`, so retries, `nonRetryableStatus` and
|
|
433
|
+
* Retry-After all apply.
|
|
434
|
+
*/
|
|
435
|
+
export declare function fromFetch(config: FetchAdapterConfig): LLMClient;
|
|
436
|
+
//#endregion
|
|
437
|
+
//#region src/adapters/internal/sse.d.ts
|
|
438
|
+
/**
|
|
439
|
+
* Parses a Server-Sent-Events stream of bytes or text into each frame's
|
|
440
|
+
* JSON `data:` payload, in order, over any transport. Multi-line data is
|
|
441
|
+
* joined with `\n`, comment-only frames yield `SSE_PING`, other fields are
|
|
442
|
+
* ignored, and a `[DONE]` frame ends iteration. `\r\n` and bare `\r` count
|
|
443
|
+
* as line endings, including a `\r\n` split across two chunks. Malformed
|
|
444
|
+
* JSON throws `LLMError('parse')`.
|
|
445
|
+
*/
|
|
446
|
+
export declare function parseSseStream(source: AsyncIterable<Uint8Array | string>): AsyncGenerator<unknown>;
|
|
447
|
+
/**
|
|
448
|
+
* Yielded for a comment-only frame, the SSE keep-alive ping, so a consumer
|
|
449
|
+
* can tell "still alive" apart from an empty frame.
|
|
450
|
+
*/
|
|
451
|
+
export declare const SSE_PING: unique symbol;
|
|
452
|
+
//#endregion
|
|
453
|
+
//#region src/adapters/openai/openaiCompatible.d.ts
|
|
454
|
+
/** Optional configuration for `fromOpenAICompatible`. */
|
|
455
|
+
interface OpenAICompatibleAdapterOptions {
|
|
456
|
+
/**
|
|
457
|
+
* Whether the provider accepts `stream_options.include_usage`. Default
|
|
458
|
+
* `true`. With `false`, `stream_options` is omitted and streams report no
|
|
459
|
+
* usage.
|
|
460
|
+
*/
|
|
461
|
+
supportsStreamUsage?: boolean;
|
|
462
|
+
/**
|
|
463
|
+
* Overrides the token counts `budgetTokens` buckets into when
|
|
464
|
+
* `reasoningEffort` isn't set. Omitted tiers keep the default.
|
|
465
|
+
*/
|
|
466
|
+
reasoningEffortTokens?: Partial<EffortTokenTable>;
|
|
467
|
+
/**
|
|
468
|
+
* Whether the client supports `.withResponse()`, which AIMD's proactive
|
|
469
|
+
* path needs. Default `false`, since the client can't be verified.
|
|
470
|
+
*/
|
|
471
|
+
supportsWithResponse?: boolean;
|
|
472
|
+
/**
|
|
473
|
+
* The provider, in the OpenTelemetry `gen_ai.provider.name` vocabulary,
|
|
474
|
+
* reported on `AttemptContext.adapter`. When omitted it is read off a well
|
|
475
|
+
* known `baseURL` host, and left unset otherwise.
|
|
476
|
+
*/
|
|
477
|
+
provider?: string;
|
|
478
|
+
/**
|
|
479
|
+
* Models that only take `tools` on Chat Completions with
|
|
480
|
+
* `reasoning_effort: "none"`, replacing the built in rule (bare `gpt-` ids
|
|
481
|
+
* of major 6 and later, except `-chat` ids). With tools, `"none"` is sent,
|
|
482
|
+
* or the call throws `unsupported_capability` when reasoning was asked for.
|
|
483
|
+
*/
|
|
484
|
+
noReasoningToolModels?: ModelCapabilityOverride;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Adapter for any client whose `chat.completions.create` speaks the OpenAI
|
|
488
|
+
* wire format. Requests pass through, except for message translation and
|
|
489
|
+
* the model specific rewrites above. The client is `unknown` because SDK
|
|
490
|
+
* types drift from `LLMClient`; the wire format is the contract.
|
|
491
|
+
*/
|
|
492
|
+
export declare function fromOpenAICompatible(client: unknown, options?: OpenAICompatibleAdapterOptions): LLMClient;
|
|
493
|
+
//#endregion
|
|
494
|
+
//#region src/adapters/openai/aliases.d.ts
|
|
495
|
+
/**
|
|
496
|
+
* The OpenAI SDK. Wrap it rather than passing it directly, since newer SDK
|
|
497
|
+
* content-part types no longer typecheck against `LLMClient`.
|
|
498
|
+
*/
|
|
499
|
+
export declare const fromOpenAI: typeof fromOpenAICompatible;
|
|
500
|
+
/** Groqs SDK matches the OpenAI wire format */
|
|
501
|
+
export declare const fromGroq: typeof fromOpenAICompatible;
|
|
502
|
+
/** Mistral's OpenAI-compatible endpoint, which accepts `stream_options.include_usage`. */
|
|
503
|
+
export declare const fromMistral: typeof fromOpenAICompatible;
|
|
504
|
+
/** DeepSeeks API is OpenAI-compatible */
|
|
505
|
+
export declare const fromDeepSeek: typeof fromOpenAICompatible;
|
|
506
|
+
/** Cerebras inference API is OpenAI-compatible */
|
|
507
|
+
export declare const fromCerebras: typeof fromOpenAICompatible;
|
|
508
|
+
/** Together AIs API is OpenAI-compatible */
|
|
509
|
+
export declare const fromTogether: typeof fromOpenAICompatible;
|
|
510
|
+
/** Fireworks AIs API is OpenAI-compatible */
|
|
511
|
+
export declare const fromFireworks: typeof fromOpenAICompatible;
|
|
512
|
+
/** Ollama's OpenAI-compatible `/v1/chat/completions` endpoint, not its native `/api/chat`. */
|
|
513
|
+
export declare const fromOllama: typeof fromOpenAICompatible;
|
|
514
|
+
/** OpenRouter's API is OpenAI-compatible */
|
|
515
|
+
export declare const fromOpenRouter: typeof fromOpenAICompatible;
|
|
516
|
+
/** Perplexity's API is OpenAI-compatible */
|
|
517
|
+
export declare const fromPerplexity: typeof fromOpenAICompatible;
|
|
518
|
+
/** DeepInfra's API is OpenAI-compatible */
|
|
519
|
+
export declare const fromDeepInfra: typeof fromOpenAICompatible;
|
|
520
|
+
/** Novita's API is OpenAI-compatible */
|
|
521
|
+
export declare const fromNovita: typeof fromOpenAICompatible;
|
|
522
|
+
/** Hyperbolic's API is OpenAI-compatible */
|
|
523
|
+
export declare const fromHyperbolic: typeof fromOpenAICompatible;
|
|
524
|
+
/** Moonshot's (Kimi) API is OpenAI-compatible */
|
|
525
|
+
export declare const fromMoonshot: typeof fromOpenAICompatible;
|
|
526
|
+
/** Zhipu's (GLM) API is OpenAI-compatible */
|
|
527
|
+
export declare const fromZhipu: typeof fromOpenAICompatible;
|
|
528
|
+
/**
|
|
529
|
+
* LM Studio exposes an OpenAI-compatible endpoint at `/v1/chat/completions`.
|
|
530
|
+
* Point an OpenAI SDK instance's `baseURL` at your local LM Studio server.
|
|
531
|
+
*/
|
|
532
|
+
export declare const fromLMStudio: typeof fromOpenAICompatible;
|
|
533
|
+
/**
|
|
534
|
+
* vLLM's OpenAI-compatible server mode exposes `/v1/chat/completions`.
|
|
535
|
+
* Point an OpenAI SDK instance's `baseURL` at your vLLM server.
|
|
536
|
+
*/
|
|
537
|
+
export declare const fromVLLM: typeof fromOpenAICompatible;
|
|
538
|
+
/** xAI's Grok API is OpenAI-compatible */
|
|
539
|
+
export declare const fromXAI: typeof fromOpenAICompatible;
|
|
540
|
+
/** NVIDIA NIM's hosted and self-hosted endpoints are OpenAI-compatible */
|
|
541
|
+
export declare const fromNvidiaNIM: typeof fromOpenAICompatible;
|
|
542
|
+
/** Vercel AI Gateway is OpenAI-compatible */
|
|
543
|
+
export declare const fromVercelAIGateway: typeof fromOpenAICompatible;
|
|
544
|
+
/** Cloudflare Workers AI exposes an OpenAI-compatible endpoint */
|
|
545
|
+
export declare const fromCloudflareWorkersAI: typeof fromOpenAICompatible;
|
|
546
|
+
/** Nebius AI Studio is OpenAI-compatible */
|
|
547
|
+
export declare const fromNebius: typeof fromOpenAICompatible;
|
|
548
|
+
/** SambaNova Cloud's API is OpenAI-compatible */
|
|
549
|
+
export declare const fromSambaNova: typeof fromOpenAICompatible;
|
|
550
|
+
/** Baseten's model hosting exposes an OpenAI-compatible endpoint */
|
|
551
|
+
export declare const fromBaseten: typeof fromOpenAICompatible;
|
|
552
|
+
/** Featherless AI's API is OpenAI-compatible */
|
|
553
|
+
export declare const fromFeatherless: typeof fromOpenAICompatible;
|
|
554
|
+
/** Friendli AI's serving endpoint is OpenAI-compatible */
|
|
555
|
+
export declare const fromFriendli: typeof fromOpenAICompatible;
|
|
556
|
+
/** SiliconFlow's API is OpenAI-compatible */
|
|
557
|
+
export declare const fromSiliconFlow: typeof fromOpenAICompatible;
|
|
558
|
+
/** Parasail's inference API is OpenAI-compatible */
|
|
559
|
+
export declare const fromParasail: typeof fromOpenAICompatible;
|
|
560
|
+
/** StepFun's API is OpenAI-compatible */
|
|
561
|
+
export declare const fromStepFun: typeof fromOpenAICompatible;
|
|
562
|
+
/** MiniMax's API is OpenAI-compatible */
|
|
563
|
+
export declare const fromMiniMax: typeof fromOpenAICompatible;
|
|
564
|
+
/** Lambda Labs' Inference API is OpenAI-compatible */
|
|
565
|
+
export declare const fromLambdaLabs: typeof fromOpenAICompatible;
|
|
566
|
+
/** Snowflake Cortex's LLM endpoint is OpenAI-compatible */
|
|
567
|
+
export declare const fromSnowflakeCortex: typeof fromOpenAICompatible;
|
|
568
|
+
/** Anyscale Endpoints' API is OpenAI-compatible */
|
|
569
|
+
export declare const fromAnyscale: typeof fromOpenAICompatible;
|
|
570
|
+
/** Lepton AI's inference API is OpenAI-compatible */
|
|
571
|
+
export declare const fromLepton: typeof fromOpenAICompatible;
|
|
572
|
+
/** Inference.net's API is OpenAI-compatible */
|
|
573
|
+
export declare const fromInferenceNet: typeof fromOpenAICompatible;
|
|
574
|
+
/** Infermatic's API is OpenAI-compatible */
|
|
575
|
+
export declare const fromInfermatic: typeof fromOpenAICompatible;
|
|
576
|
+
/** AtlasCloud's inference API is OpenAI-compatible */
|
|
577
|
+
export declare const fromAtlasCloud: typeof fromOpenAICompatible;
|
|
578
|
+
/** 01.AI's (Yi models) API is OpenAI-compatible */
|
|
579
|
+
export declare const from01AI: typeof fromOpenAICompatible;
|
|
580
|
+
//#endregion
|
|
581
|
+
export type { AnthropicAdapterOptions, AnthropicClient, FetchAdapterConfig, GeminiAdapterOptions, GeminiClient, OpenAICompatibleAdapterOptions, RequestLike, ResponseLike, StreamRequestLike };
|
|
582
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/adapters/internal/nativeStructuredOutput.ts","../../src/adapters/internal/reasoningBudget.utils.ts","../../src/adapters/internal/imageFormat.ts","../../src/adapters/claude/types.ts","../../src/adapters/claude/anthropic.ts","../../src/adapters/gemini/types.ts","../../src/adapters/gemini/gemini.ts","../../src/adapters/fetch/types.ts","../../src/adapters/fetch/fetch.ts","../../src/adapters/internal/sse.ts","../../src/adapters/openai/openaiCompatible.ts","../../src/adapters/openai/aliases.ts"],"mappings":"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"}
|