@providerprotocol/ai 0.0.19 → 0.0.21
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 +82 -9
- package/dist/anthropic/index.d.ts +184 -14
- package/dist/anthropic/index.js +214 -86
- package/dist/anthropic/index.js.map +1 -1
- package/dist/{chunk-5FEAOEXV.js → chunk-EDENPF3E.js} +57 -103
- package/dist/chunk-EDENPF3E.js.map +1 -0
- package/dist/{chunk-UMKWXGO3.js → chunk-M4BMM5IB.js} +86 -2
- package/dist/chunk-M4BMM5IB.js.map +1 -0
- package/dist/chunk-Y3GBJNA2.js +120 -0
- package/dist/chunk-Y3GBJNA2.js.map +1 -0
- package/dist/{chunk-U4JJC2YX.js → chunk-Z4ILICF5.js} +2 -2
- package/dist/chunk-Z4ILICF5.js.map +1 -0
- package/dist/google/index.d.ts +16 -19
- package/dist/google/index.js +18 -40
- package/dist/google/index.js.map +1 -1
- package/dist/http/index.d.ts +2 -2
- package/dist/http/index.js +5 -4
- package/dist/index.d.ts +101 -38
- package/dist/index.js +69 -43
- package/dist/index.js.map +1 -1
- package/dist/ollama/index.d.ts +14 -16
- package/dist/ollama/index.js +9 -11
- package/dist/ollama/index.js.map +1 -1
- package/dist/openai/index.d.ts +25 -133
- package/dist/openai/index.js +31 -85
- package/dist/openai/index.js.map +1 -1
- package/dist/openrouter/index.d.ts +28 -53
- package/dist/openrouter/index.js +24 -47
- package/dist/openrouter/index.js.map +1 -1
- package/dist/provider-DGQHYE6I.d.ts +1319 -0
- package/dist/proxy/index.d.ts +194 -12
- package/dist/proxy/index.js +37 -65
- package/dist/proxy/index.js.map +1 -1
- package/dist/{retry-DR7YRJDz.d.ts → retry-Pcs3hnbu.d.ts} +2 -2
- package/dist/{stream-DRHy6q1a.d.ts → stream-Di9acos2.d.ts} +1 -1
- package/dist/xai/index.d.ts +16 -88
- package/dist/xai/index.js +34 -62
- package/dist/xai/index.js.map +1 -1
- package/package.json +4 -1
- package/dist/chunk-5FEAOEXV.js.map +0 -1
- package/dist/chunk-DZQHVGNV.js +0 -71
- package/dist/chunk-DZQHVGNV.js.map +0 -1
- package/dist/chunk-MSR5P65T.js +0 -39
- package/dist/chunk-MSR5P65T.js.map +0 -1
- package/dist/chunk-U4JJC2YX.js.map +0 -1
- package/dist/chunk-UMKWXGO3.js.map +0 -1
- package/dist/content-DEl3z_W2.d.ts +0 -276
- package/dist/image-Dhq-Yuq4.d.ts +0 -456
- package/dist/provider-BBMBZuGn.d.ts +0 -570
|
@@ -1,570 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Error types for the Unified Provider Protocol.
|
|
3
|
-
*
|
|
4
|
-
* Provides normalized error codes and a unified error class for handling
|
|
5
|
-
* errors across different AI providers in a consistent manner.
|
|
6
|
-
*
|
|
7
|
-
* @module types/errors
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Normalized error codes for cross-provider error handling.
|
|
11
|
-
*
|
|
12
|
-
* These codes provide a consistent way to identify and handle errors
|
|
13
|
-
* regardless of which AI provider generated them.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* try {
|
|
18
|
-
* await llm.generate('Hello');
|
|
19
|
-
* } catch (error) {
|
|
20
|
-
* if (error instanceof UPPError) {
|
|
21
|
-
* switch (error.code) {
|
|
22
|
-
* case 'RATE_LIMITED':
|
|
23
|
-
* await delay(error.retryAfter);
|
|
24
|
-
* break;
|
|
25
|
-
* case 'AUTHENTICATION_FAILED':
|
|
26
|
-
* throw new Error('Invalid API key');
|
|
27
|
-
* }
|
|
28
|
-
* }
|
|
29
|
-
* }
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
type ErrorCode =
|
|
33
|
-
/** API key is invalid or expired */
|
|
34
|
-
'AUTHENTICATION_FAILED'
|
|
35
|
-
/** Rate limit exceeded, retry after delay */
|
|
36
|
-
| 'RATE_LIMITED'
|
|
37
|
-
/** Input exceeds model's context window */
|
|
38
|
-
| 'CONTEXT_LENGTH_EXCEEDED'
|
|
39
|
-
/** Requested model does not exist */
|
|
40
|
-
| 'MODEL_NOT_FOUND'
|
|
41
|
-
/** Request parameters are malformed */
|
|
42
|
-
| 'INVALID_REQUEST'
|
|
43
|
-
/** Provider returned an unexpected response format */
|
|
44
|
-
| 'INVALID_RESPONSE'
|
|
45
|
-
/** Content was blocked by safety filters */
|
|
46
|
-
| 'CONTENT_FILTERED'
|
|
47
|
-
/** Account quota or credits exhausted */
|
|
48
|
-
| 'QUOTA_EXCEEDED'
|
|
49
|
-
/** Provider-specific error not covered by other codes */
|
|
50
|
-
| 'PROVIDER_ERROR'
|
|
51
|
-
/** Network connectivity issue */
|
|
52
|
-
| 'NETWORK_ERROR'
|
|
53
|
-
/** Request exceeded timeout limit */
|
|
54
|
-
| 'TIMEOUT'
|
|
55
|
-
/** Request was cancelled via AbortSignal */
|
|
56
|
-
| 'CANCELLED';
|
|
57
|
-
/**
|
|
58
|
-
* Modality types supported by UPP.
|
|
59
|
-
*
|
|
60
|
-
* Each modality represents a different type of AI capability that
|
|
61
|
-
* can be provided by a UPP-compatible provider.
|
|
62
|
-
*/
|
|
63
|
-
type Modality =
|
|
64
|
-
/** Large language model for text generation */
|
|
65
|
-
'llm'
|
|
66
|
-
/** Text/image embedding model */
|
|
67
|
-
| 'embedding'
|
|
68
|
-
/** Image generation model */
|
|
69
|
-
| 'image'
|
|
70
|
-
/** Audio processing/generation model */
|
|
71
|
-
| 'audio'
|
|
72
|
-
/** Video processing/generation model */
|
|
73
|
-
| 'video';
|
|
74
|
-
/**
|
|
75
|
-
* Unified Provider Protocol Error.
|
|
76
|
-
*
|
|
77
|
-
* All provider-specific errors are normalized to this type, providing
|
|
78
|
-
* a consistent interface for error handling across different AI providers.
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```typescript
|
|
82
|
-
* throw new UPPError(
|
|
83
|
-
* 'API key is invalid',
|
|
84
|
-
* 'AUTHENTICATION_FAILED',
|
|
85
|
-
* 'openai',
|
|
86
|
-
* 'llm',
|
|
87
|
-
* 401
|
|
88
|
-
* );
|
|
89
|
-
* ```
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* ```typescript
|
|
93
|
-
* // Wrapping a provider error
|
|
94
|
-
* try {
|
|
95
|
-
* await openai.chat.completions.create({ ... });
|
|
96
|
-
* } catch (err) {
|
|
97
|
-
* throw new UPPError(
|
|
98
|
-
* 'OpenAI request failed',
|
|
99
|
-
* 'PROVIDER_ERROR',
|
|
100
|
-
* 'openai',
|
|
101
|
-
* 'llm',
|
|
102
|
-
* err.status,
|
|
103
|
-
* err
|
|
104
|
-
* );
|
|
105
|
-
* }
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
declare class UPPError extends Error {
|
|
109
|
-
/** Normalized error code for programmatic handling */
|
|
110
|
-
readonly code: ErrorCode;
|
|
111
|
-
/** Name of the provider that generated the error */
|
|
112
|
-
readonly provider: string;
|
|
113
|
-
/** The modality that was being used when the error occurred */
|
|
114
|
-
readonly modality: Modality;
|
|
115
|
-
/** HTTP status code from the provider's response, if available */
|
|
116
|
-
readonly statusCode?: number;
|
|
117
|
-
/** The original error that caused this UPPError, if wrapping another error */
|
|
118
|
-
readonly cause?: Error;
|
|
119
|
-
/** Error class name, always 'UPPError' */
|
|
120
|
-
readonly name = "UPPError";
|
|
121
|
-
/**
|
|
122
|
-
* Creates a new UPPError instance.
|
|
123
|
-
*
|
|
124
|
-
* @param message - Human-readable error description
|
|
125
|
-
* @param code - Normalized error code for programmatic handling
|
|
126
|
-
* @param provider - Name of the provider that generated the error
|
|
127
|
-
* @param modality - The modality that was being used
|
|
128
|
-
* @param statusCode - HTTP status code from the provider's response
|
|
129
|
-
* @param cause - The original error being wrapped
|
|
130
|
-
*/
|
|
131
|
-
constructor(message: string, code: ErrorCode, provider: string, modality: Modality, statusCode?: number, cause?: Error);
|
|
132
|
-
/**
|
|
133
|
-
* Creates a string representation of the error.
|
|
134
|
-
*
|
|
135
|
-
* @returns Formatted error string including code, message, provider, and modality
|
|
136
|
-
*/
|
|
137
|
-
toString(): string;
|
|
138
|
-
/**
|
|
139
|
-
* Converts the error to a JSON-serializable object.
|
|
140
|
-
*
|
|
141
|
-
* @returns Plain object representation suitable for logging or transmission
|
|
142
|
-
*/
|
|
143
|
-
toJSON(): Record<string, unknown>;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* @fileoverview Provider types for AI service integrations.
|
|
148
|
-
*
|
|
149
|
-
* Defines the interfaces for provider factories, modality handlers,
|
|
150
|
-
* and configuration options for connecting to various AI providers.
|
|
151
|
-
*
|
|
152
|
-
* @module types/provider
|
|
153
|
-
*/
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* API key strategy interface for managing multiple keys.
|
|
157
|
-
*
|
|
158
|
-
* Implement this interface to provide custom key rotation or
|
|
159
|
-
* selection logic when working with multiple API keys.
|
|
160
|
-
*
|
|
161
|
-
* @example
|
|
162
|
-
* ```typescript
|
|
163
|
-
* class RoundRobinKeys implements KeyStrategy {
|
|
164
|
-
* private keys: string[];
|
|
165
|
-
* private index = 0;
|
|
166
|
-
*
|
|
167
|
-
* constructor(keys: string[]) {
|
|
168
|
-
* this.keys = keys;
|
|
169
|
-
* }
|
|
170
|
-
*
|
|
171
|
-
* getKey(): string {
|
|
172
|
-
* const key = this.keys[this.index];
|
|
173
|
-
* this.index = (this.index + 1) % this.keys.length;
|
|
174
|
-
* return key;
|
|
175
|
-
* }
|
|
176
|
-
* }
|
|
177
|
-
* ```
|
|
178
|
-
*/
|
|
179
|
-
interface KeyStrategy {
|
|
180
|
-
/**
|
|
181
|
-
* Gets the next API key to use for a request.
|
|
182
|
-
*
|
|
183
|
-
* @returns The API key string, or a Promise resolving to it
|
|
184
|
-
*/
|
|
185
|
-
getKey(): string | Promise<string>;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Retry strategy interface for handling request failures.
|
|
189
|
-
*
|
|
190
|
-
* Implement this interface to provide custom retry logic for
|
|
191
|
-
* handling rate limits, transient errors, and other failures.
|
|
192
|
-
*
|
|
193
|
-
* @example
|
|
194
|
-
* ```typescript
|
|
195
|
-
* class ExponentialBackoff implements RetryStrategy {
|
|
196
|
-
* private maxAttempts = 5;
|
|
197
|
-
* private baseDelay = 1000;
|
|
198
|
-
*
|
|
199
|
-
* onRetry(error: UPPError, attempt: number): number | null {
|
|
200
|
-
* if (attempt > this.maxAttempts) return null;
|
|
201
|
-
* if (error.code !== 'RATE_LIMITED') return null;
|
|
202
|
-
* return this.baseDelay * Math.pow(2, attempt - 1);
|
|
203
|
-
* }
|
|
204
|
-
* }
|
|
205
|
-
* ```
|
|
206
|
-
*/
|
|
207
|
-
interface RetryStrategy {
|
|
208
|
-
/**
|
|
209
|
-
* Called when a request fails with a retryable error.
|
|
210
|
-
*
|
|
211
|
-
* @param error - The error that occurred
|
|
212
|
-
* @param attempt - The attempt number (1 = first retry)
|
|
213
|
-
* @returns Delay in ms before retrying, or null to stop retrying
|
|
214
|
-
*/
|
|
215
|
-
onRetry(error: UPPError, attempt: number): number | null | Promise<number | null>;
|
|
216
|
-
/**
|
|
217
|
-
* Called before each request. Can be used to implement pre-emptive rate limiting.
|
|
218
|
-
*
|
|
219
|
-
* @returns Delay in ms to wait before making the request, or 0 to proceed immediately
|
|
220
|
-
*/
|
|
221
|
-
beforeRequest?(): number | Promise<number>;
|
|
222
|
-
/**
|
|
223
|
-
* Reset the strategy state (e.g., after a successful request).
|
|
224
|
-
*/
|
|
225
|
-
reset?(): void;
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Provider configuration for infrastructure and connection settings.
|
|
229
|
-
*
|
|
230
|
-
* These settings control how requests are made to the provider's API,
|
|
231
|
-
* including authentication, timeouts, and retry behavior.
|
|
232
|
-
*
|
|
233
|
-
* @example
|
|
234
|
-
* ```typescript
|
|
235
|
-
* const config: ProviderConfig = {
|
|
236
|
-
* apiKey: process.env.OPENAI_API_KEY,
|
|
237
|
-
* timeout: 30000,
|
|
238
|
-
* retryStrategy: new ExponentialBackoff()
|
|
239
|
-
* };
|
|
240
|
-
*
|
|
241
|
-
* // Or with a key strategy for key rotation
|
|
242
|
-
* const config: ProviderConfig = {
|
|
243
|
-
* apiKey: new RoundRobinKeys(['sk-1', 'sk-2', 'sk-3']),
|
|
244
|
-
* baseUrl: 'https://custom-proxy.example.com'
|
|
245
|
-
* };
|
|
246
|
-
* ```
|
|
247
|
-
*/
|
|
248
|
-
interface ProviderConfig {
|
|
249
|
-
/**
|
|
250
|
-
* API key for authentication.
|
|
251
|
-
* Can be a string, async function, or KeyStrategy for advanced use cases.
|
|
252
|
-
*/
|
|
253
|
-
apiKey?: string | (() => string | Promise<string>) | KeyStrategy;
|
|
254
|
-
/** Override the base API URL (for proxies, local models) */
|
|
255
|
-
baseUrl?: string;
|
|
256
|
-
/** Request timeout in milliseconds */
|
|
257
|
-
timeout?: number;
|
|
258
|
-
/** Custom fetch implementation (for logging, caching, custom TLS) */
|
|
259
|
-
fetch?: typeof fetch;
|
|
260
|
-
/** API version override (provider-specific) */
|
|
261
|
-
apiVersion?: string;
|
|
262
|
-
/** Retry strategy for handling failures and rate limits */
|
|
263
|
-
retryStrategy?: RetryStrategy;
|
|
264
|
-
/**
|
|
265
|
-
* Custom headers to include in API requests.
|
|
266
|
-
*
|
|
267
|
-
* Use this to pass provider-specific headers such as:
|
|
268
|
-
* - Anthropic: `anthropic-beta` for beta features
|
|
269
|
-
* - OpenAI: `OpenAI-Organization`, `OpenAI-Project`
|
|
270
|
-
* - OpenRouter: `HTTP-Referer`, `X-Title` for attribution
|
|
271
|
-
* - Ollama: Proxy authentication headers
|
|
272
|
-
*
|
|
273
|
-
* @example
|
|
274
|
-
* ```typescript
|
|
275
|
-
* const config: ProviderConfig = {
|
|
276
|
-
* headers: { 'anthropic-beta': 'extended-cache-ttl-2025-04-11' }
|
|
277
|
-
* };
|
|
278
|
-
* ```
|
|
279
|
-
*/
|
|
280
|
-
headers?: Record<string, string | undefined>;
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* A reference to a model, created by a provider factory.
|
|
284
|
-
*
|
|
285
|
-
* Model references are lightweight objects that identify a model
|
|
286
|
-
* and its provider, used as input to the llm() function.
|
|
287
|
-
*
|
|
288
|
-
* @typeParam TOptions - Provider-specific options type
|
|
289
|
-
*
|
|
290
|
-
* @example
|
|
291
|
-
* ```typescript
|
|
292
|
-
* const model = openai('gpt-4');
|
|
293
|
-
* console.log(model.modelId); // 'gpt-4'
|
|
294
|
-
* console.log(model.provider.name); // 'openai'
|
|
295
|
-
* ```
|
|
296
|
-
*/
|
|
297
|
-
interface ModelReference<TOptions = unknown> {
|
|
298
|
-
/** The model identifier (e.g., 'gpt-4', 'claude-3-opus') */
|
|
299
|
-
readonly modelId: string;
|
|
300
|
-
/** The provider that created this reference */
|
|
301
|
-
readonly provider: Provider<TOptions>;
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* LLM handler interface for providers.
|
|
305
|
-
*
|
|
306
|
-
* Implemented by providers to enable language model capabilities.
|
|
307
|
-
*
|
|
308
|
-
* @typeParam TParams - Provider-specific parameter type
|
|
309
|
-
* @internal
|
|
310
|
-
*/
|
|
311
|
-
interface LLMHandler<TParams = unknown> {
|
|
312
|
-
/**
|
|
313
|
-
* Binds a model ID to create an executable model instance.
|
|
314
|
-
*
|
|
315
|
-
* @param modelId - The model identifier to bind
|
|
316
|
-
* @returns A bound LLM model ready for inference
|
|
317
|
-
*/
|
|
318
|
-
bind(modelId: string): BoundLLMModel<TParams>;
|
|
319
|
-
/**
|
|
320
|
-
* Sets the parent provider reference.
|
|
321
|
-
* Called by createProvider() after the provider is constructed.
|
|
322
|
-
*
|
|
323
|
-
* @param provider - The parent provider
|
|
324
|
-
* @internal
|
|
325
|
-
*/
|
|
326
|
-
_setProvider?(provider: LLMProvider<TParams>): void;
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* Embedding handler interface for providers.
|
|
330
|
-
*
|
|
331
|
-
* Implemented by providers to enable embedding capabilities.
|
|
332
|
-
*
|
|
333
|
-
* @typeParam TParams - Provider-specific parameter type
|
|
334
|
-
* @internal
|
|
335
|
-
*/
|
|
336
|
-
interface EmbeddingHandler<TParams = unknown> {
|
|
337
|
-
/** Supported input types for embeddings */
|
|
338
|
-
readonly supportedInputs: ('text' | 'image')[];
|
|
339
|
-
/**
|
|
340
|
-
* Binds a model ID to create an executable embedding model.
|
|
341
|
-
*
|
|
342
|
-
* @param modelId - The model identifier to bind
|
|
343
|
-
* @returns A bound embedding model ready for use
|
|
344
|
-
*/
|
|
345
|
-
bind(modelId: string): BoundEmbeddingModel<TParams>;
|
|
346
|
-
/**
|
|
347
|
-
* Sets the parent provider reference.
|
|
348
|
-
*
|
|
349
|
-
* @param provider - The parent provider
|
|
350
|
-
* @internal
|
|
351
|
-
*/
|
|
352
|
-
_setProvider?(provider: EmbeddingProvider<TParams>): void;
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* Image handler interface for providers.
|
|
356
|
-
*
|
|
357
|
-
* Implemented by providers to enable image generation capabilities.
|
|
358
|
-
*
|
|
359
|
-
* @typeParam TParams - Provider-specific parameter type
|
|
360
|
-
* @internal
|
|
361
|
-
*/
|
|
362
|
-
interface ImageHandler<TParams = unknown> {
|
|
363
|
-
/**
|
|
364
|
-
* Binds a model ID to create an executable image model.
|
|
365
|
-
*
|
|
366
|
-
* @param modelId - The model identifier to bind
|
|
367
|
-
* @returns A bound image model ready for generation
|
|
368
|
-
*/
|
|
369
|
-
bind(modelId: string): BoundImageModel<TParams>;
|
|
370
|
-
/**
|
|
371
|
-
* Sets the parent provider reference.
|
|
372
|
-
*
|
|
373
|
-
* @param provider - The parent provider
|
|
374
|
-
* @internal
|
|
375
|
-
*/
|
|
376
|
-
_setProvider?(provider: ImageProvider<TParams>): void;
|
|
377
|
-
}
|
|
378
|
-
/**
|
|
379
|
-
* Bound LLM model interface (forward declaration).
|
|
380
|
-
*
|
|
381
|
-
* Full definition is in llm.ts to avoid circular dependencies.
|
|
382
|
-
*
|
|
383
|
-
* @typeParam TParams - Provider-specific parameter type
|
|
384
|
-
*/
|
|
385
|
-
interface BoundLLMModel<TParams = unknown> {
|
|
386
|
-
/** The model identifier */
|
|
387
|
-
readonly modelId: string;
|
|
388
|
-
/** Reference to the parent provider */
|
|
389
|
-
readonly provider: LLMProvider<TParams>;
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* Bound embedding model interface.
|
|
393
|
-
*
|
|
394
|
-
* Represents an embedding model bound to a specific model ID,
|
|
395
|
-
* ready to generate embeddings.
|
|
396
|
-
*
|
|
397
|
-
* @typeParam TParams - Provider-specific parameter type
|
|
398
|
-
*/
|
|
399
|
-
interface BoundEmbeddingModel<TParams = unknown> {
|
|
400
|
-
/** The model identifier */
|
|
401
|
-
readonly modelId: string;
|
|
402
|
-
/** Reference to the parent provider */
|
|
403
|
-
readonly provider: EmbeddingProvider<TParams>;
|
|
404
|
-
/** Maximum number of inputs per batch request */
|
|
405
|
-
readonly maxBatchSize: number;
|
|
406
|
-
/** Maximum length of input text in tokens */
|
|
407
|
-
readonly maxInputLength: number;
|
|
408
|
-
/** Output embedding dimensions */
|
|
409
|
-
readonly dimensions: number;
|
|
410
|
-
/**
|
|
411
|
-
* Execute embedding request.
|
|
412
|
-
*
|
|
413
|
-
* @param request - The embedding request
|
|
414
|
-
* @returns Promise resolving to embedding response
|
|
415
|
-
*/
|
|
416
|
-
embed(request: EmbeddingRequest<TParams>): Promise<EmbeddingResponse>;
|
|
417
|
-
}
|
|
418
|
-
/**
|
|
419
|
-
* Request passed to provider's embed method.
|
|
420
|
-
* @internal
|
|
421
|
-
*/
|
|
422
|
-
interface EmbeddingRequest<TParams = unknown> {
|
|
423
|
-
/** Inputs to embed */
|
|
424
|
-
inputs: EmbeddingInput[];
|
|
425
|
-
/** Provider-specific parameters (passed through unchanged) */
|
|
426
|
-
params?: TParams;
|
|
427
|
-
/** Provider infrastructure config */
|
|
428
|
-
config: ProviderConfig;
|
|
429
|
-
/** Abort signal for cancellation */
|
|
430
|
-
signal?: AbortSignal;
|
|
431
|
-
}
|
|
432
|
-
/**
|
|
433
|
-
* Response from provider's embed method.
|
|
434
|
-
* @internal
|
|
435
|
-
*/
|
|
436
|
-
interface EmbeddingResponse {
|
|
437
|
-
/** Embedding vectors */
|
|
438
|
-
embeddings: EmbeddingVector[];
|
|
439
|
-
/** Aggregate usage */
|
|
440
|
-
usage: EmbeddingUsage;
|
|
441
|
-
/** Provider-specific response metadata */
|
|
442
|
-
metadata?: Record<string, unknown>;
|
|
443
|
-
}
|
|
444
|
-
/**
|
|
445
|
-
* Single vector from provider response.
|
|
446
|
-
* @internal
|
|
447
|
-
*/
|
|
448
|
-
interface EmbeddingVector {
|
|
449
|
-
/** The embedding vector (floats or base64 string) */
|
|
450
|
-
vector: number[] | string;
|
|
451
|
-
/** Index in input array */
|
|
452
|
-
index: number;
|
|
453
|
-
/** Token count for this input */
|
|
454
|
-
tokens?: number;
|
|
455
|
-
/** Provider-specific per-embedding metadata */
|
|
456
|
-
metadata?: Record<string, unknown>;
|
|
457
|
-
}
|
|
458
|
-
/**
|
|
459
|
-
* Usage statistics for embedding operations.
|
|
460
|
-
*/
|
|
461
|
-
interface EmbeddingUsage {
|
|
462
|
-
/** Total tokens processed */
|
|
463
|
-
totalTokens: number;
|
|
464
|
-
}
|
|
465
|
-
/**
|
|
466
|
-
* Valid input types for embedding.
|
|
467
|
-
*/
|
|
468
|
-
type EmbeddingInput = string | {
|
|
469
|
-
type: 'text';
|
|
470
|
-
text: string;
|
|
471
|
-
} | {
|
|
472
|
-
type: 'image';
|
|
473
|
-
source: unknown;
|
|
474
|
-
mimeType: string;
|
|
475
|
-
};
|
|
476
|
-
/**
|
|
477
|
-
* Bound image model interface.
|
|
478
|
-
*
|
|
479
|
-
* Represents an image generation model bound to a specific model ID.
|
|
480
|
-
*
|
|
481
|
-
* @typeParam TParams - Provider-specific parameter type
|
|
482
|
-
*/
|
|
483
|
-
interface BoundImageModel<TParams = unknown> {
|
|
484
|
-
/** The model identifier */
|
|
485
|
-
readonly modelId: string;
|
|
486
|
-
/** Reference to the parent provider */
|
|
487
|
-
readonly provider: ImageProvider<TParams>;
|
|
488
|
-
}
|
|
489
|
-
/**
|
|
490
|
-
* Provider factory function with metadata and modality handlers.
|
|
491
|
-
*
|
|
492
|
-
* The Provider interface represents a callable function that creates
|
|
493
|
-
* model references, along with metadata and modality-specific handlers.
|
|
494
|
-
*
|
|
495
|
-
* @typeParam TOptions - Provider-specific options passed to the factory
|
|
496
|
-
*
|
|
497
|
-
* @example
|
|
498
|
-
* ```typescript
|
|
499
|
-
* // Using a provider
|
|
500
|
-
* const model = openai('gpt-4', { temperature: 0.7 });
|
|
501
|
-
*
|
|
502
|
-
* // Accessing provider metadata
|
|
503
|
-
* console.log(openai.name); // 'openai'
|
|
504
|
-
* console.log(openai.version); // '1.0.0'
|
|
505
|
-
*
|
|
506
|
-
* // Accessing modality handlers
|
|
507
|
-
* const llmHandler = openai.modalities.llm;
|
|
508
|
-
* ```
|
|
509
|
-
*/
|
|
510
|
-
interface Provider<TOptions = unknown> {
|
|
511
|
-
/**
|
|
512
|
-
* Creates a model reference with optional provider-specific options.
|
|
513
|
-
*
|
|
514
|
-
* @param modelId - The model identifier
|
|
515
|
-
* @param options - Provider-specific options
|
|
516
|
-
* @returns A model reference for use with llm() or other functions
|
|
517
|
-
*/
|
|
518
|
-
(modelId: string, options?: TOptions): ModelReference<TOptions>;
|
|
519
|
-
/** Provider name (e.g., 'openai', 'anthropic') */
|
|
520
|
-
readonly name: string;
|
|
521
|
-
/** Provider version string */
|
|
522
|
-
readonly version: string;
|
|
523
|
-
/** Supported modalities and their handlers */
|
|
524
|
-
readonly modalities: {
|
|
525
|
-
llm?: LLMHandler;
|
|
526
|
-
embedding?: EmbeddingHandler;
|
|
527
|
-
image?: ImageHandler;
|
|
528
|
-
};
|
|
529
|
-
}
|
|
530
|
-
/**
|
|
531
|
-
* Provider with LLM modality support.
|
|
532
|
-
*
|
|
533
|
-
* Type alias for providers that support language model inference.
|
|
534
|
-
*
|
|
535
|
-
* @typeParam TParams - Model-specific parameters type
|
|
536
|
-
* @typeParam TOptions - Provider-specific options type
|
|
537
|
-
*/
|
|
538
|
-
type LLMProvider<TParams = unknown, TOptions = unknown> = Provider<TOptions> & {
|
|
539
|
-
readonly modalities: {
|
|
540
|
-
llm: LLMHandler<TParams>;
|
|
541
|
-
};
|
|
542
|
-
};
|
|
543
|
-
/**
|
|
544
|
-
* Provider with Embedding modality support.
|
|
545
|
-
*
|
|
546
|
-
* Type alias for providers that support embedding generation.
|
|
547
|
-
*
|
|
548
|
-
* @typeParam TParams - Model-specific parameters type
|
|
549
|
-
* @typeParam TOptions - Provider-specific options type
|
|
550
|
-
*/
|
|
551
|
-
type EmbeddingProvider<TParams = unknown, TOptions = unknown> = Provider<TOptions> & {
|
|
552
|
-
readonly modalities: {
|
|
553
|
-
embedding: EmbeddingHandler<TParams>;
|
|
554
|
-
};
|
|
555
|
-
};
|
|
556
|
-
/**
|
|
557
|
-
* Provider with Image modality support.
|
|
558
|
-
*
|
|
559
|
-
* Type alias for providers that support image generation.
|
|
560
|
-
*
|
|
561
|
-
* @typeParam TParams - Model-specific parameters type
|
|
562
|
-
* @typeParam TOptions - Provider-specific options type
|
|
563
|
-
*/
|
|
564
|
-
type ImageProvider<TParams = unknown, TOptions = unknown> = Provider<TOptions> & {
|
|
565
|
-
readonly modalities: {
|
|
566
|
-
image: ImageHandler<TParams>;
|
|
567
|
-
};
|
|
568
|
-
};
|
|
569
|
-
|
|
570
|
-
export { type BoundEmbeddingModel as B, type EmbeddingInput as E, type ImageHandler as I, type KeyStrategy as K, type LLMProvider as L, type Modality as M, type ProviderConfig as P, type RetryStrategy as R, UPPError as U, type EmbeddingUsage as a, type LLMHandler as b, type EmbeddingHandler as c, type Provider as d, type ErrorCode as e, type ModelReference as f, type EmbeddingProvider as g, type ImageProvider as h, type EmbeddingRequest as i, type EmbeddingResponse as j, type EmbeddingVector as k };
|