@providerprotocol/ai 0.0.27 → 0.0.28

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.
Files changed (37) hide show
  1. package/dist/anthropic/index.d.ts +1 -1
  2. package/dist/anthropic/index.js +38 -1
  3. package/dist/anthropic/index.js.map +1 -1
  4. package/dist/{chunk-6AZVUI6H.js → chunk-ILR2D5PN.js} +7 -1
  5. package/dist/chunk-ILR2D5PN.js.map +1 -0
  6. package/dist/{chunk-MKDLXV4O.js → chunk-NSE7QN3P.js} +1 -1
  7. package/dist/chunk-NSE7QN3P.js.map +1 -0
  8. package/dist/embedding-DtyOFIsS.d.ts +158 -0
  9. package/dist/google/index.d.ts +1 -1
  10. package/dist/google/index.js +41 -4
  11. package/dist/google/index.js.map +1 -1
  12. package/dist/http/index.d.ts +2 -2
  13. package/dist/index.d.ts +430 -514
  14. package/dist/index.js +627 -3
  15. package/dist/index.js.map +1 -1
  16. package/dist/llm-DgDEy9il.d.ts +3118 -0
  17. package/dist/ollama/index.d.ts +1 -1
  18. package/dist/ollama/index.js +2 -1
  19. package/dist/ollama/index.js.map +1 -1
  20. package/dist/openai/index.d.ts +1 -1
  21. package/dist/openai/index.js +70 -3
  22. package/dist/openai/index.js.map +1 -1
  23. package/dist/openrouter/index.d.ts +20 -2
  24. package/dist/openrouter/index.js +134 -13
  25. package/dist/openrouter/index.js.map +1 -1
  26. package/dist/proxy/index.d.ts +2 -2
  27. package/dist/proxy/index.js +3 -2
  28. package/dist/proxy/index.js.map +1 -1
  29. package/dist/{retry-BhX8mIrL.d.ts → retry-DXLQnTuU.d.ts} +1 -1
  30. package/dist/xai/index.d.ts +1 -1
  31. package/dist/xai/index.js +7 -3
  32. package/dist/xai/index.js.map +1 -1
  33. package/package.json +1 -1
  34. package/dist/chunk-6AZVUI6H.js.map +0 -1
  35. package/dist/chunk-MKDLXV4O.js.map +0 -1
  36. package/dist/embedding-CK5oa38O.d.ts +0 -1235
  37. package/dist/provider-6-mJYOOl.d.ts +0 -1474
@@ -1,1474 +0,0 @@
1
- /**
2
- * @fileoverview Content block types for multimodal messages.
3
- *
4
- * Defines the various content block types that can be included in
5
- * user and assistant messages, supporting text, images, audio, video,
6
- * and arbitrary binary data.
7
- *
8
- * @module types/content
9
- */
10
- /**
11
- * Content block type constants.
12
- *
13
- * Use these constants instead of raw strings for type-safe content handling:
14
- *
15
- * @example
16
- * ```typescript
17
- * import { ContentBlockType } from 'upp';
18
- *
19
- * if (block.type === ContentBlockType.Text) {
20
- * console.log(block.text);
21
- * } else if (block.type === ContentBlockType.Image) {
22
- * console.log(block.mimeType);
23
- * }
24
- * ```
25
- */
26
- declare const ContentBlockType: {
27
- /** Text content */
28
- readonly Text: "text";
29
- /** Reasoning/thinking content from extended thinking models */
30
- readonly Reasoning: "reasoning";
31
- /** Image content */
32
- readonly Image: "image";
33
- /** Audio content */
34
- readonly Audio: "audio";
35
- /** Video content */
36
- readonly Video: "video";
37
- /** Binary/arbitrary data content */
38
- readonly Binary: "binary";
39
- };
40
- /**
41
- * Content block type discriminator union.
42
- *
43
- * This type is derived from {@link ContentBlockType} constants.
44
- */
45
- type ContentBlockType = (typeof ContentBlockType)[keyof typeof ContentBlockType];
46
- /**
47
- * Image source type constants.
48
- *
49
- * @example
50
- * ```typescript
51
- * import { ImageSourceType } from 'upp';
52
- *
53
- * if (source.type === ImageSourceType.Base64) {
54
- * // Handle base64 encoded image
55
- * } else if (source.type === ImageSourceType.Url) {
56
- * // Handle URL reference
57
- * }
58
- * ```
59
- */
60
- declare const ImageSourceType: {
61
- /** Base64-encoded image data */
62
- readonly Base64: "base64";
63
- /** URL reference to image */
64
- readonly Url: "url";
65
- /** Raw bytes image data */
66
- readonly Bytes: "bytes";
67
- };
68
- /**
69
- * Image source type discriminator union.
70
- *
71
- * This type is derived from {@link ImageSourceType} constants.
72
- */
73
- type ImageSourceType = (typeof ImageSourceType)[keyof typeof ImageSourceType];
74
- /**
75
- * Image source variants for ImageBlock.
76
- *
77
- * Images can be provided as base64-encoded strings, URLs, or raw bytes.
78
- *
79
- * @example
80
- * ```typescript
81
- * // Base64 encoded image
82
- * const base64Source: ImageSource = {
83
- * type: 'base64',
84
- * data: 'iVBORw0KGgo...'
85
- * };
86
- *
87
- * // URL reference
88
- * const urlSource: ImageSource = {
89
- * type: 'url',
90
- * url: 'https://example.com/image.png'
91
- * };
92
- *
93
- * // Raw bytes
94
- * const bytesSource: ImageSource = {
95
- * type: 'bytes',
96
- * data: new Uint8Array([...])
97
- * };
98
- * ```
99
- */
100
- type ImageSource = {
101
- type: 'base64';
102
- data: string;
103
- } | {
104
- type: 'url';
105
- url: string;
106
- } | {
107
- type: 'bytes';
108
- data: Uint8Array;
109
- };
110
- /**
111
- * Text content block.
112
- *
113
- * The most common content block type, containing plain text content.
114
- *
115
- * @example
116
- * ```typescript
117
- * const textBlock: TextBlock = {
118
- * type: 'text',
119
- * text: 'Hello, world!'
120
- * };
121
- * ```
122
- */
123
- interface TextBlock {
124
- /** Discriminator for text blocks */
125
- type: 'text';
126
- /** The text content */
127
- text: string;
128
- }
129
- /**
130
- * Reasoning content block.
131
- *
132
- * Contains model reasoning/thinking from extended thinking or chain-of-thought.
133
- * This content represents the model's internal reasoning process.
134
- *
135
- * @example
136
- * ```typescript
137
- * const reasoningBlock: ReasoningBlock = {
138
- * type: 'reasoning',
139
- * text: 'Let me think about this step by step...'
140
- * };
141
- * ```
142
- */
143
- interface ReasoningBlock {
144
- /** Discriminator for reasoning blocks */
145
- type: 'reasoning';
146
- /** The reasoning/thinking text */
147
- text: string;
148
- }
149
- /**
150
- * Image content block.
151
- *
152
- * Contains an image with its source data and metadata.
153
- *
154
- * @example
155
- * ```typescript
156
- * const imageBlock: ImageBlock = {
157
- * type: 'image',
158
- * source: { type: 'url', url: 'https://example.com/photo.jpg' },
159
- * mimeType: 'image/jpeg',
160
- * width: 1920,
161
- * height: 1080
162
- * };
163
- * ```
164
- */
165
- interface ImageBlock {
166
- /** Discriminator for image blocks */
167
- type: 'image';
168
- /** The image data source */
169
- source: ImageSource;
170
- /** MIME type of the image (e.g., 'image/png', 'image/jpeg') */
171
- mimeType: string;
172
- /** Image width in pixels */
173
- width?: number;
174
- /** Image height in pixels */
175
- height?: number;
176
- }
177
- /**
178
- * Audio content block.
179
- *
180
- * Contains audio data with its metadata.
181
- *
182
- * @example
183
- * ```typescript
184
- * const audioBlock: AudioBlock = {
185
- * type: 'audio',
186
- * data: audioBytes,
187
- * mimeType: 'audio/mp3',
188
- * duration: 120.5
189
- * };
190
- * ```
191
- */
192
- interface AudioBlock {
193
- /** Discriminator for audio blocks */
194
- type: 'audio';
195
- /** Raw audio data */
196
- data: Uint8Array;
197
- /** MIME type of the audio (e.g., 'audio/mp3', 'audio/wav') */
198
- mimeType: string;
199
- /** Duration in seconds */
200
- duration?: number;
201
- }
202
- /**
203
- * Video content block.
204
- *
205
- * Contains video data with its metadata.
206
- *
207
- * @example
208
- * ```typescript
209
- * const videoBlock: VideoBlock = {
210
- * type: 'video',
211
- * data: videoBytes,
212
- * mimeType: 'video/mp4',
213
- * duration: 30,
214
- * width: 1920,
215
- * height: 1080
216
- * };
217
- * ```
218
- */
219
- interface VideoBlock {
220
- /** Discriminator for video blocks */
221
- type: 'video';
222
- /** Raw video data */
223
- data: Uint8Array;
224
- /** MIME type of the video (e.g., 'video/mp4', 'video/webm') */
225
- mimeType: string;
226
- /** Duration in seconds */
227
- duration?: number;
228
- /** Video width in pixels */
229
- width?: number;
230
- /** Video height in pixels */
231
- height?: number;
232
- }
233
- /**
234
- * Binary content block for arbitrary data.
235
- *
236
- * A generic block type for data that doesn't fit other categories.
237
- *
238
- * @example
239
- * ```typescript
240
- * const binaryBlock: BinaryBlock = {
241
- * type: 'binary',
242
- * data: pdfBytes,
243
- * mimeType: 'application/pdf',
244
- * metadata: { filename: 'document.pdf', pages: 10 }
245
- * };
246
- * ```
247
- */
248
- interface BinaryBlock {
249
- /** Discriminator for binary blocks */
250
- type: 'binary';
251
- /** Raw binary data */
252
- data: Uint8Array;
253
- /** MIME type of the data */
254
- mimeType: string;
255
- /** Additional metadata about the binary content */
256
- metadata?: Record<string, unknown>;
257
- }
258
- /**
259
- * Union of all content block types.
260
- *
261
- * Used when a function or property can accept any type of content block.
262
- */
263
- type ContentBlock = TextBlock | ReasoningBlock | ImageBlock | AudioBlock | VideoBlock | BinaryBlock;
264
- /**
265
- * Content types allowed in user messages.
266
- *
267
- * Users can send any type of content block including binary data.
268
- */
269
- type UserContent = TextBlock | ImageBlock | AudioBlock | VideoBlock | BinaryBlock;
270
- /**
271
- * Content types allowed in assistant messages.
272
- *
273
- * Assistants can generate text and media but not arbitrary binary data.
274
- */
275
- type AssistantContent = TextBlock | ReasoningBlock | ImageBlock | AudioBlock | VideoBlock;
276
- /**
277
- * Creates a text content block from a string.
278
- *
279
- * @param content - The text content
280
- * @returns A TextBlock containing the provided text
281
- *
282
- * @example
283
- * ```typescript
284
- * const block = text('Hello, world!');
285
- * // { type: 'text', text: 'Hello, world!' }
286
- * ```
287
- */
288
- declare function text(content: string): TextBlock;
289
- /**
290
- * Creates a reasoning content block from a string.
291
- *
292
- * @param content - The reasoning/thinking content
293
- * @returns A ReasoningBlock containing the provided text
294
- *
295
- * @example
296
- * ```typescript
297
- * const block = reasoning('Let me think step by step...');
298
- * // { type: 'reasoning', text: 'Let me think step by step...' }
299
- * ```
300
- */
301
- declare function reasoning(content: string): ReasoningBlock;
302
- /**
303
- * Type guard for TextBlock.
304
- *
305
- * @param block - The content block to check
306
- * @returns True if the block is a TextBlock
307
- *
308
- * @example
309
- * ```typescript
310
- * if (isTextBlock(block)) {
311
- * console.log(block.text);
312
- * }
313
- * ```
314
- */
315
- declare function isTextBlock(block: ContentBlock): block is TextBlock;
316
- /**
317
- * Type guard for ReasoningBlock.
318
- *
319
- * @param block - The content block to check
320
- * @returns True if the block is a ReasoningBlock
321
- *
322
- * @example
323
- * ```typescript
324
- * if (isReasoningBlock(block)) {
325
- * console.log(block.text);
326
- * }
327
- * ```
328
- */
329
- declare function isReasoningBlock(block: ContentBlock): block is ReasoningBlock;
330
- /**
331
- * Type guard for ImageBlock.
332
- *
333
- * @param block - The content block to check
334
- * @returns True if the block is an ImageBlock
335
- *
336
- * @example
337
- * ```typescript
338
- * if (isImageBlock(block)) {
339
- * console.log(block.mimeType, block.width, block.height);
340
- * }
341
- * ```
342
- */
343
- declare function isImageBlock(block: ContentBlock): block is ImageBlock;
344
- /**
345
- * Type guard for AudioBlock.
346
- *
347
- * @param block - The content block to check
348
- * @returns True if the block is an AudioBlock
349
- *
350
- * @example
351
- * ```typescript
352
- * if (isAudioBlock(block)) {
353
- * console.log(block.mimeType, block.duration);
354
- * }
355
- * ```
356
- */
357
- declare function isAudioBlock(block: ContentBlock): block is AudioBlock;
358
- /**
359
- * Type guard for VideoBlock.
360
- *
361
- * @param block - The content block to check
362
- * @returns True if the block is a VideoBlock
363
- *
364
- * @example
365
- * ```typescript
366
- * if (isVideoBlock(block)) {
367
- * console.log(block.mimeType, block.duration);
368
- * }
369
- * ```
370
- */
371
- declare function isVideoBlock(block: ContentBlock): block is VideoBlock;
372
- /**
373
- * Type guard for BinaryBlock.
374
- *
375
- * @param block - The content block to check
376
- * @returns True if the block is a BinaryBlock
377
- *
378
- * @example
379
- * ```typescript
380
- * if (isBinaryBlock(block)) {
381
- * console.log(block.mimeType, block.metadata);
382
- * }
383
- * ```
384
- */
385
- declare function isBinaryBlock(block: ContentBlock): block is BinaryBlock;
386
-
387
- /**
388
- * @fileoverview Error types for the Unified Provider Protocol.
389
- *
390
- * Provides normalized error codes and a unified error class for handling
391
- * errors across different AI providers in a consistent manner.
392
- *
393
- * @module types/errors
394
- */
395
- /**
396
- * Error code constants for cross-provider error handling.
397
- *
398
- * Use these constants instead of raw strings for type-safe error handling:
399
- *
400
- * @example
401
- * ```typescript
402
- * import { ErrorCode } from 'upp';
403
- *
404
- * try {
405
- * await llm.generate('Hello');
406
- * } catch (error) {
407
- * if (error instanceof UPPError) {
408
- * switch (error.code) {
409
- * case ErrorCode.RateLimited:
410
- * await delay(error.retryAfter);
411
- * break;
412
- * case ErrorCode.AuthenticationFailed:
413
- * throw new Error('Invalid API key');
414
- * }
415
- * }
416
- * }
417
- * ```
418
- */
419
- declare const ErrorCode: {
420
- /** API key is invalid or expired */
421
- readonly AuthenticationFailed: "AUTHENTICATION_FAILED";
422
- /** Rate limit exceeded, retry after delay */
423
- readonly RateLimited: "RATE_LIMITED";
424
- /** Input exceeds model's context window */
425
- readonly ContextLengthExceeded: "CONTEXT_LENGTH_EXCEEDED";
426
- /** Requested model does not exist */
427
- readonly ModelNotFound: "MODEL_NOT_FOUND";
428
- /** Request parameters are malformed */
429
- readonly InvalidRequest: "INVALID_REQUEST";
430
- /** Provider returned an unexpected response format */
431
- readonly InvalidResponse: "INVALID_RESPONSE";
432
- /** Content was blocked by safety filters */
433
- readonly ContentFiltered: "CONTENT_FILTERED";
434
- /** Account quota or credits exhausted */
435
- readonly QuotaExceeded: "QUOTA_EXCEEDED";
436
- /** Provider-specific error not covered by other codes */
437
- readonly ProviderError: "PROVIDER_ERROR";
438
- /** Network connectivity issue */
439
- readonly NetworkError: "NETWORK_ERROR";
440
- /** Request exceeded timeout limit */
441
- readonly Timeout: "TIMEOUT";
442
- /** Request was cancelled via AbortSignal */
443
- readonly Cancelled: "CANCELLED";
444
- };
445
- /**
446
- * Error code discriminator union.
447
- *
448
- * This type is derived from {@link ErrorCode} constants. Use `ErrorCode.RateLimited`
449
- * for constants or `type MyCode = ErrorCode` for type annotations.
450
- */
451
- type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
452
- /**
453
- * Modality type discriminator union.
454
- *
455
- * This type is derived from {@link ModalityType} constants. The name `Modality`
456
- * is kept for backward compatibility; `ModalityType` works as both the const
457
- * object and this type.
458
- */
459
- type Modality = (typeof ModalityType)[keyof typeof ModalityType];
460
- /**
461
- * Modality type constants.
462
- *
463
- * Use these constants for type-safe modality handling:
464
- *
465
- * @example
466
- * ```typescript
467
- * import { ModalityType } from 'upp';
468
- *
469
- * if (provider.modality === ModalityType.LLM) {
470
- * // Handle LLM provider
471
- * }
472
- * ```
473
- */
474
- declare const ModalityType: {
475
- /** Large language model for text generation */
476
- readonly LLM: "llm";
477
- /** Text/image embedding model */
478
- readonly Embedding: "embedding";
479
- /** Image generation model */
480
- readonly Image: "image";
481
- /** Audio processing/generation model */
482
- readonly Audio: "audio";
483
- /** Video processing/generation model */
484
- readonly Video: "video";
485
- };
486
- /**
487
- * Type alias for Modality, allowing `ModalityType` to work as both const and type.
488
- */
489
- type ModalityType = Modality;
490
- /**
491
- * Unified Provider Protocol Error.
492
- *
493
- * All provider-specific errors are normalized to this type, providing
494
- * a consistent interface for error handling across different AI providers.
495
- *
496
- * @example
497
- * ```typescript
498
- * import { ErrorCode, ModalityType } from 'upp';
499
- *
500
- * throw new UPPError(
501
- * 'API key is invalid',
502
- * ErrorCode.AuthenticationFailed,
503
- * 'openai',
504
- * ModalityType.LLM,
505
- * 401
506
- * );
507
- * ```
508
- *
509
- * @example
510
- * ```typescript
511
- * import { ErrorCode, ModalityType } from 'upp';
512
- *
513
- * // Wrapping a provider error
514
- * try {
515
- * await openai.chat.completions.create({ ... });
516
- * } catch (err) {
517
- * throw new UPPError(
518
- * 'OpenAI request failed',
519
- * ErrorCode.ProviderError,
520
- * 'openai',
521
- * ModalityType.LLM,
522
- * err.status,
523
- * err
524
- * );
525
- * }
526
- * ```
527
- */
528
- declare class UPPError extends Error {
529
- /** Normalized error code for programmatic handling */
530
- readonly code: ErrorCode;
531
- /** Name of the provider that generated the error */
532
- readonly provider: string;
533
- /** The modality that was being used when the error occurred */
534
- readonly modality: Modality;
535
- /** HTTP status code from the provider's response, if available */
536
- readonly statusCode?: number;
537
- /** The original error that caused this UPPError, if wrapping another error */
538
- readonly cause?: Error;
539
- /** Error class name, always 'UPPError' */
540
- readonly name = "UPPError";
541
- /**
542
- * Creates a new UPPError instance.
543
- *
544
- * @param message - Human-readable error description
545
- * @param code - Normalized error code for programmatic handling
546
- * @param provider - Name of the provider that generated the error
547
- * @param modality - The modality that was being used
548
- * @param statusCode - HTTP status code from the provider's response
549
- * @param cause - The original error being wrapped
550
- */
551
- constructor(message: string, code: ErrorCode, provider: string, modality: Modality, statusCode?: number, cause?: Error);
552
- /**
553
- * Creates a string representation of the error.
554
- *
555
- * @returns Formatted error string including code, message, provider, and modality
556
- */
557
- toString(): string;
558
- /**
559
- * Converts the error to a JSON-serializable object.
560
- *
561
- * @returns Plain object representation suitable for logging or transmission
562
- */
563
- toJSON(): Record<string, unknown>;
564
- }
565
-
566
- /**
567
- * @fileoverview Image content handling for the Universal Provider Protocol.
568
- *
569
- * Provides a unified Image class for working with images across different sources
570
- * (file paths, URLs, raw bytes, base64). Supports conversion between formats and
571
- * integration with UPP message content blocks.
572
- *
573
- * @module core/media/Image
574
- */
575
-
576
- /**
577
- * Represents an image that can be used in UPP messages.
578
- *
579
- * Images can be created from various sources (files, URLs, bytes, base64) and
580
- * converted to different formats as needed by providers. The class provides
581
- * a unified interface regardless of the underlying source type.
582
- *
583
- * @example
584
- * ```typescript
585
- * // Load from file
586
- * const fileImage = await Image.fromPath('./photo.jpg');
587
- *
588
- * // Reference by URL
589
- * const urlImage = Image.fromUrl('https://example.com/image.png');
590
- *
591
- * // From raw bytes
592
- * const bytesImage = Image.fromBytes(uint8Array, 'image/png');
593
- *
594
- * // Use in a message
595
- * const message = new UserMessage([image.toBlock()]);
596
- * ```
597
- */
598
- declare class Image {
599
- /** The underlying image source (bytes, base64, or URL) */
600
- readonly source: ImageSource;
601
- /** MIME type of the image (e.g., 'image/jpeg', 'image/png') */
602
- readonly mimeType: string;
603
- /** Image width in pixels, if known */
604
- readonly width?: number;
605
- /** Image height in pixels, if known */
606
- readonly height?: number;
607
- private constructor();
608
- /**
609
- * Whether this image has data loaded in memory.
610
- *
611
- * Returns `false` for URL-sourced images that reference external resources.
612
- * These must be fetched before their data can be accessed.
613
- */
614
- get hasData(): boolean;
615
- /**
616
- * Converts the image to a base64-encoded string.
617
- *
618
- * @returns The image data as a base64 string
619
- * @throws {Error} When the source is a URL (data must be fetched first)
620
- */
621
- toBase64(): string;
622
- /**
623
- * Converts the image to a data URL suitable for embedding in HTML or CSS.
624
- *
625
- * @returns A data URL in the format `data:{mimeType};base64,{data}`
626
- * @throws {Error} When the source is a URL (data must be fetched first)
627
- */
628
- toDataUrl(): string;
629
- /**
630
- * Gets the image data as raw bytes.
631
- *
632
- * @returns The image data as a Uint8Array
633
- * @throws {Error} When the source is a URL (data must be fetched first)
634
- */
635
- toBytes(): Uint8Array;
636
- /**
637
- * Gets the URL for URL-sourced images.
638
- *
639
- * @returns The image URL
640
- * @throws {Error} When the source is not a URL
641
- */
642
- toUrl(): string;
643
- /**
644
- * Converts this Image to an ImageBlock for use in UPP messages.
645
- *
646
- * @returns An ImageBlock that can be included in message content arrays
647
- */
648
- toBlock(): ImageBlock;
649
- /**
650
- * Creates an Image by reading a file from disk.
651
- *
652
- * The file is read into memory as bytes. MIME type is automatically
653
- * detected from the file extension.
654
- *
655
- * @param path - Path to the image file
656
- * @returns Promise resolving to an Image with the file contents
657
- *
658
- * @example
659
- * ```typescript
660
- * const image = await Image.fromPath('./photos/vacation.jpg');
661
- * ```
662
- */
663
- static fromPath(path: string): Promise<Image>;
664
- /**
665
- * Creates an Image from a URL reference.
666
- *
667
- * The URL is stored as a reference and not fetched. Providers will handle
668
- * URL-to-data conversion if needed. MIME type is detected from the URL
669
- * path if not provided.
670
- *
671
- * @param url - URL pointing to the image
672
- * @param mimeType - Optional MIME type override
673
- * @returns An Image referencing the URL
674
- *
675
- * @example
676
- * ```typescript
677
- * const image = Image.fromUrl('https://example.com/logo.png');
678
- * ```
679
- */
680
- static fromUrl(url: string, mimeType?: string): Image;
681
- /**
682
- * Creates an Image from raw byte data.
683
- *
684
- * @param data - The image data as a Uint8Array
685
- * @param mimeType - The MIME type of the image
686
- * @returns An Image containing the byte data
687
- *
688
- * @example
689
- * ```typescript
690
- * const image = Image.fromBytes(pngData, 'image/png');
691
- * ```
692
- */
693
- static fromBytes(data: Uint8Array, mimeType: string): Image;
694
- /**
695
- * Creates an Image from a base64-encoded string.
696
- *
697
- * @param base64 - The base64-encoded image data (without data URL prefix)
698
- * @param mimeType - The MIME type of the image
699
- * @returns An Image containing the base64 data
700
- *
701
- * @example
702
- * ```typescript
703
- * const image = Image.fromBase64(base64String, 'image/jpeg');
704
- * ```
705
- */
706
- static fromBase64(base64: string, mimeType: string): Image;
707
- /**
708
- * Creates an Image from an existing ImageBlock.
709
- *
710
- * Useful for converting content blocks received from providers back
711
- * into Image instances for further processing.
712
- *
713
- * @param block - An ImageBlock from message content
714
- * @returns An Image with the block's source and metadata
715
- */
716
- static fromBlock(block: ImageBlock): Image;
717
- }
718
-
719
- /**
720
- * @fileoverview Image generation types for the Universal Provider Protocol.
721
- *
722
- * Defines the interfaces for configuring and executing image generation operations,
723
- * including options, instances, requests, responses, streaming, and capabilities.
724
- *
725
- * @module types/image
726
- */
727
-
728
- /**
729
- * Structural type for image model input.
730
- * Uses structural typing to avoid generic variance issues with Provider generics.
731
- *
732
- * @remarks
733
- * This type mirrors {@link ModelReference} while keeping provider options
734
- * structurally compatible across providers.
735
- *
736
- * @see ModelReference
737
- */
738
- interface ImageModelInput {
739
- readonly modelId: string;
740
- readonly provider: ProviderIdentity;
741
- /** Optional provider configuration merged into requests */
742
- readonly providerConfig?: Partial<ProviderConfig>;
743
- }
744
- /**
745
- * Options for creating an image instance with the image() function.
746
- *
747
- * @typeParam TParams - Provider-specific parameter type
748
- *
749
- * @example
750
- * ```typescript
751
- * const options: ImageOptions<OpenAIImageParams> = {
752
- * model: openai('dall-e-3'),
753
- * config: { apiKey: process.env.OPENAI_API_KEY },
754
- * params: { size: '1024x1024', quality: 'hd' }
755
- * };
756
- * ```
757
- */
758
- interface ImageOptions<TParams = unknown> {
759
- /** A model reference from a provider factory */
760
- model: ImageModelInput;
761
- /** Provider infrastructure configuration */
762
- config?: ProviderConfig;
763
- /** Provider-specific parameters (passed through unchanged) */
764
- params?: TParams;
765
- }
766
- /**
767
- * Options for image generation.
768
- */
769
- interface ImageGenerateOptions {
770
- /** Abort signal for cancellation */
771
- signal?: AbortSignal;
772
- }
773
- /**
774
- * Input type for generate() - either a string prompt or object with prompt.
775
- */
776
- type ImageInput = string | {
777
- prompt: string;
778
- };
779
- /**
780
- * Input for edit() operations.
781
- */
782
- interface ImageEditInput {
783
- /** Base image to edit */
784
- image: Image;
785
- /** Mask indicating edit region (interpretation varies by provider) */
786
- mask?: Image;
787
- /** Edit instruction prompt */
788
- prompt: string;
789
- }
790
- /**
791
- * A single generated image with optional metadata.
792
- */
793
- interface GeneratedImage {
794
- /** The generated image */
795
- image: Image;
796
- /** Provider-specific per-image metadata */
797
- metadata?: Record<string, unknown>;
798
- }
799
- /**
800
- * Usage statistics for image generation.
801
- * Fields are optional because providers report usage differently.
802
- */
803
- interface ImageUsage {
804
- /** Number of images generated */
805
- imagesGenerated?: number;
806
- /** Input tokens consumed (token-based pricing) */
807
- inputTokens?: number;
808
- /** Output tokens consumed (token-based pricing) */
809
- outputTokens?: number;
810
- /** Provider-reported cost (credits, dollars, etc.) */
811
- cost?: number;
812
- }
813
- /**
814
- * Result from generate() or edit() calls.
815
- */
816
- interface ImageResult {
817
- /** Generated images */
818
- images: GeneratedImage[];
819
- /** Provider-specific response metadata */
820
- metadata?: Record<string, unknown>;
821
- /** Usage/billing information */
822
- usage?: ImageUsage;
823
- }
824
- /**
825
- * Stream events for image generation.
826
- */
827
- type ImageStreamEvent = {
828
- type: 'preview';
829
- image: Image;
830
- index: number;
831
- metadata?: Record<string, unknown>;
832
- } | {
833
- type: 'complete';
834
- image: GeneratedImage;
835
- index: number;
836
- };
837
- /**
838
- * Async iterable stream with final result accessor.
839
- * Returned when stream() is called.
840
- */
841
- interface ImageStreamResult extends AsyncIterable<ImageStreamEvent> {
842
- /** Promise resolving to complete result after streaming */
843
- readonly result: Promise<ImageResult>;
844
- /** Abort the generation */
845
- abort(): void;
846
- }
847
- /**
848
- * Image generation capabilities.
849
- */
850
- interface ImageCapabilities {
851
- /** Supports text-to-image generation */
852
- generate: boolean;
853
- /** Supports streaming with partial previews */
854
- streaming: boolean;
855
- /** Supports image editing/inpainting */
856
- edit: boolean;
857
- /** Maximum images per request (if known) */
858
- maxImages?: number;
859
- }
860
- /**
861
- * Image instance returned by the image() function.
862
- *
863
- * @typeParam TParams - Provider-specific parameter type
864
- *
865
- * @example
866
- * ```typescript
867
- * const dalle = image({ model: openai('dall-e-3') });
868
- *
869
- * // Simple generation
870
- * const result = await dalle.generate('A sunset over mountains');
871
- *
872
- * // Streaming (if supported)
873
- * if (dalle.capabilities.streaming && dalle.stream) {
874
- * const stream = dalle.stream('A cyberpunk cityscape');
875
- * for await (const event of stream) {
876
- * // Handle preview/complete events
877
- * }
878
- * }
879
- * ```
880
- */
881
- interface ImageInstance<TParams = unknown> {
882
- /**
883
- * Generate images from a text prompt.
884
- *
885
- * @param input - The prompt string or object with prompt
886
- * @param options - Optional generation options
887
- * @returns Promise resolving to the generated images
888
- */
889
- generate(input: ImageInput, options?: ImageGenerateOptions): Promise<ImageResult>;
890
- /**
891
- * Generate with streaming progress (if supported).
892
- * Only available when capabilities.streaming is true.
893
- *
894
- * @param input - The prompt string or object with prompt
895
- * @returns ImageStreamResult with events and final result
896
- */
897
- stream?(input: ImageInput): ImageStreamResult;
898
- /**
899
- * Edit an existing image (if supported).
900
- * Only available when capabilities.edit is true.
901
- *
902
- * @param input - Edit input with image, optional mask, and prompt
903
- * @returns Promise resolving to the edited images
904
- */
905
- edit?(input: ImageEditInput): Promise<ImageResult>;
906
- /** The bound image model */
907
- readonly model: BoundImageModel<TParams>;
908
- /** Current parameters */
909
- readonly params: TParams | undefined;
910
- /** Model capabilities */
911
- readonly capabilities: ImageCapabilities;
912
- }
913
- /**
914
- * Request passed from image() core to providers for generation.
915
- * @internal
916
- */
917
- interface ImageRequest<TParams = unknown> {
918
- /** Generation prompt */
919
- prompt: string;
920
- /** Provider-specific parameters (passed through unchanged) */
921
- params?: TParams;
922
- /** Provider infrastructure config */
923
- config: ProviderConfig;
924
- /** Abort signal for cancellation */
925
- signal?: AbortSignal;
926
- }
927
- /**
928
- * Request passed to providers for edit operations.
929
- * @internal
930
- */
931
- interface ImageEditRequest<TParams = unknown> {
932
- /** Base image to edit */
933
- image: Image;
934
- /** Edit mask */
935
- mask?: Image;
936
- /** Edit instruction prompt */
937
- prompt: string;
938
- /** Provider-specific parameters */
939
- params?: TParams;
940
- /** Provider infrastructure config */
941
- config: ProviderConfig;
942
- /** Abort signal for cancellation */
943
- signal?: AbortSignal;
944
- }
945
- /**
946
- * Response from provider's generate or edit method.
947
- * @internal
948
- */
949
- interface ImageResponse {
950
- /** Generated images */
951
- images: GeneratedImage[];
952
- /** Provider-specific response metadata */
953
- metadata?: Record<string, unknown>;
954
- /** Usage information */
955
- usage?: ImageUsage;
956
- }
957
- /**
958
- * Raw provider stream result.
959
- * An async iterable of ImageStreamEvent with a response promise.
960
- * @internal
961
- */
962
- interface ImageProviderStreamResult extends AsyncIterable<ImageStreamEvent> {
963
- /** Promise resolving to the complete response */
964
- readonly response: Promise<ImageResponse>;
965
- }
966
- /**
967
- * Bound image model - full definition.
968
- *
969
- * Represents an image model bound to a specific provider and model ID,
970
- * ready to execute generation requests.
971
- *
972
- * @typeParam TParams - Provider-specific parameter type
973
- */
974
- interface BoundImageModel<TParams = unknown> {
975
- /** The model identifier */
976
- readonly modelId: string;
977
- /** Reference to the parent provider */
978
- readonly provider: ImageProvider<TParams>;
979
- /** Model capabilities */
980
- readonly capabilities: ImageCapabilities;
981
- /**
982
- * Generate images from a prompt.
983
- *
984
- * @param request - The generation request
985
- * @returns Promise resolving to the response
986
- */
987
- generate(request: ImageRequest<TParams>): Promise<ImageResponse>;
988
- /**
989
- * Stream image generation (optional).
990
- *
991
- * @param request - The generation request
992
- * @returns Stream result with events and final response
993
- */
994
- stream?(request: ImageRequest<TParams>): ImageProviderStreamResult;
995
- /**
996
- * Edit an image (optional).
997
- *
998
- * @param request - The edit request
999
- * @returns Promise resolving to the response
1000
- */
1001
- edit?(request: ImageEditRequest<TParams>): Promise<ImageResponse>;
1002
- }
1003
- /**
1004
- * Image Handler interface for providers.
1005
- *
1006
- * Implemented by providers to enable image generation capabilities.
1007
- *
1008
- * @typeParam TParams - Provider-specific parameter type
1009
- */
1010
- interface ImageHandler$1<TParams = unknown> {
1011
- /**
1012
- * Binds a model ID to create an executable image model.
1013
- *
1014
- * @param modelId - The model identifier to bind
1015
- * @returns A bound image model ready for generation
1016
- */
1017
- bind(modelId: string): BoundImageModel<TParams>;
1018
- /**
1019
- * Sets the parent provider reference.
1020
- * Called by createProvider() after the provider is constructed.
1021
- *
1022
- * @param provider - The parent provider
1023
- * @internal
1024
- */
1025
- _setProvider?(provider: ImageProvider<TParams>): void;
1026
- }
1027
-
1028
- /**
1029
- * @fileoverview Provider types for AI service integrations.
1030
- *
1031
- * Defines the interfaces for provider factories, modality handlers,
1032
- * and configuration options for connecting to various AI providers.
1033
- *
1034
- * @module types/provider
1035
- */
1036
-
1037
- /**
1038
- * API key strategy interface for managing multiple keys.
1039
- *
1040
- * Implement this interface to provide custom key rotation or
1041
- * selection logic when working with multiple API keys.
1042
- *
1043
- * @example
1044
- * ```typescript
1045
- * class RoundRobinKeys implements KeyStrategy {
1046
- * private keys: string[];
1047
- * private index = 0;
1048
- *
1049
- * constructor(keys: string[]) {
1050
- * this.keys = keys;
1051
- * }
1052
- *
1053
- * getKey(): string {
1054
- * const key = this.keys[this.index];
1055
- * this.index = (this.index + 1) % this.keys.length;
1056
- * return key;
1057
- * }
1058
- * }
1059
- * ```
1060
- */
1061
- interface KeyStrategy {
1062
- /**
1063
- * Gets the next API key to use for a request.
1064
- *
1065
- * @returns The API key string, or a Promise resolving to it
1066
- */
1067
- getKey(): string | Promise<string>;
1068
- }
1069
- /**
1070
- * Retry strategy interface for handling request failures.
1071
- *
1072
- * Implement this interface to provide custom retry logic for
1073
- * handling rate limits, transient errors, and other failures.
1074
- *
1075
- * @example
1076
- * ```typescript
1077
- * class ExponentialBackoff implements RetryStrategy {
1078
- * private maxAttempts = 5;
1079
- * private baseDelay = 1000;
1080
- *
1081
- * onRetry(error: UPPError, attempt: number): number | null {
1082
- * if (attempt > this.maxAttempts) return null;
1083
- * if (error.code !== 'RATE_LIMITED') return null;
1084
- * return this.baseDelay * Math.pow(2, attempt - 1);
1085
- * }
1086
- * }
1087
- * ```
1088
- */
1089
- interface RetryStrategy {
1090
- /**
1091
- * Called when a request fails with a retryable error.
1092
- *
1093
- * @param error - The error that occurred
1094
- * @param attempt - The attempt number (1 = first retry)
1095
- * @returns Delay in ms before retrying, or null to stop retrying
1096
- */
1097
- onRetry(error: UPPError, attempt: number): number | null | Promise<number | null>;
1098
- /**
1099
- * Called before each request. Can be used to implement pre-emptive rate limiting.
1100
- *
1101
- * @returns Delay in ms to wait before making the request, or 0 to proceed immediately
1102
- */
1103
- beforeRequest?(): number | Promise<number>;
1104
- /**
1105
- * Reset the strategy state (e.g., after a successful request).
1106
- */
1107
- reset?(): void;
1108
- }
1109
- /**
1110
- * Provider identity shape for structural typing.
1111
- *
1112
- * Used in model input types to accept any provider instance
1113
- * without generic variance constraints.
1114
- */
1115
- interface ProviderIdentity {
1116
- /** Provider name (e.g., 'openai', 'anthropic') */
1117
- readonly name: string;
1118
- /** Provider version string */
1119
- readonly version: string;
1120
- }
1121
- /**
1122
- * Provider configuration for infrastructure and connection settings.
1123
- *
1124
- * These settings control how requests are made to the provider's API,
1125
- * including authentication, timeouts, and retry behavior.
1126
- *
1127
- * @example
1128
- * ```typescript
1129
- * const config: ProviderConfig = {
1130
- * apiKey: process.env.OPENAI_API_KEY,
1131
- * timeout: 30000,
1132
- * retryStrategy: new ExponentialBackoff()
1133
- * };
1134
- *
1135
- * // Or with a key strategy for key rotation
1136
- * const config: ProviderConfig = {
1137
- * apiKey: new RoundRobinKeys(['sk-1', 'sk-2', 'sk-3']),
1138
- * baseUrl: 'https://custom-proxy.example.com'
1139
- * };
1140
- * ```
1141
- */
1142
- interface ProviderConfig {
1143
- /**
1144
- * API key for authentication.
1145
- * Can be a string, async function, or KeyStrategy for advanced use cases.
1146
- */
1147
- apiKey?: string | (() => string | Promise<string>) | KeyStrategy;
1148
- /** Override the base API URL (for proxies, local models) */
1149
- baseUrl?: string;
1150
- /**
1151
- * Request timeout in milliseconds.
1152
- * Applied per attempt; total wall time can exceed this when retries are enabled.
1153
- */
1154
- timeout?: number;
1155
- /** Custom fetch implementation (for logging, caching, custom TLS) */
1156
- fetch?: typeof fetch;
1157
- /** API version override (provider-specific) */
1158
- apiVersion?: string;
1159
- /** Retry strategy for handling failures and rate limits */
1160
- retryStrategy?: RetryStrategy;
1161
- /**
1162
- * Custom headers to include in API requests.
1163
- *
1164
- * Use this to pass provider-specific headers such as:
1165
- * - Anthropic: `anthropic-beta` for beta features
1166
- * - OpenAI: `OpenAI-Organization`, `OpenAI-Project`
1167
- * - OpenRouter: `HTTP-Referer`, `X-Title` for attribution
1168
- * - Ollama: Proxy authentication headers
1169
- *
1170
- * @example
1171
- * ```typescript
1172
- * const config: ProviderConfig = {
1173
- * headers: { 'anthropic-beta': 'extended-cache-ttl-2025-04-11' }
1174
- * };
1175
- * ```
1176
- */
1177
- headers?: Record<string, string | undefined>;
1178
- /**
1179
- * Maximum Retry-After delay in seconds when honoring server headers.
1180
- * Defaults to 3600 seconds (1 hour).
1181
- */
1182
- retryAfterMaxSeconds?: number;
1183
- }
1184
- /**
1185
- * A reference to a model, created by a provider factory.
1186
- *
1187
- * Model references are lightweight objects that identify a model
1188
- * and its provider, used as input to the llm() function.
1189
- *
1190
- * @typeParam TOptions - Provider-specific options type
1191
- *
1192
- * @example
1193
- * ```typescript
1194
- * const model = openai('gpt-4');
1195
- * console.log(model.modelId); // 'gpt-4'
1196
- * console.log(model.provider.name); // 'openai'
1197
- * ```
1198
- */
1199
- interface ModelReference<TOptions = unknown> {
1200
- /** The model identifier (e.g., 'gpt-4', 'claude-3-opus') */
1201
- readonly modelId: string;
1202
- /** The provider that created this reference */
1203
- readonly provider: Provider<TOptions>;
1204
- /**
1205
- * Optional provider-specific configuration that gets merged into request config.
1206
- *
1207
- * This allows providers to store options set at model reference creation time
1208
- * (e.g., `anthropic('model', { betas: [...] })`) that should be applied to all requests.
1209
- * The `llm()` factory will merge these into the request config, with explicit config
1210
- * values taking precedence.
1211
- */
1212
- readonly providerConfig?: Partial<ProviderConfig>;
1213
- /**
1214
- * The original options passed when creating this model reference.
1215
- *
1216
- * Used by providers with multiple LLM handlers (e.g., OpenAI with responses/completions APIs)
1217
- * to resolve the correct handler at request time, avoiding race conditions from shared state.
1218
- */
1219
- readonly options?: TOptions;
1220
- }
1221
- /**
1222
- * LLM handler interface for providers.
1223
- *
1224
- * Implemented by providers to enable language model capabilities.
1225
- *
1226
- * @typeParam TParams - Provider-specific parameter type
1227
- * @internal
1228
- */
1229
- interface LLMHandler<TParams = unknown> {
1230
- /**
1231
- * Binds a model ID to create an executable model instance.
1232
- *
1233
- * @param modelId - The model identifier to bind
1234
- * @returns A bound LLM model ready for inference
1235
- */
1236
- bind(modelId: string): BoundLLMModel<TParams>;
1237
- /**
1238
- * Sets the parent provider reference.
1239
- * Called by createProvider() after the provider is constructed.
1240
- *
1241
- * @param provider - The parent provider
1242
- * @internal
1243
- */
1244
- _setProvider?(provider: LLMProvider<TParams>): void;
1245
- }
1246
- /**
1247
- * Embedding handler interface for providers.
1248
- *
1249
- * Implemented by providers to enable embedding capabilities.
1250
- *
1251
- * @typeParam TParams - Provider-specific parameter type
1252
- * @internal
1253
- */
1254
- interface EmbeddingHandler<TParams = unknown> {
1255
- /** Supported input types for embeddings */
1256
- readonly supportedInputs: ('text' | 'image')[];
1257
- /**
1258
- * Binds a model ID to create an executable embedding model.
1259
- *
1260
- * @param modelId - The model identifier to bind
1261
- * @returns A bound embedding model ready for use
1262
- */
1263
- bind(modelId: string): BoundEmbeddingModel<TParams>;
1264
- /**
1265
- * Sets the parent provider reference.
1266
- *
1267
- * @param provider - The parent provider
1268
- * @internal
1269
- */
1270
- _setProvider?(provider: EmbeddingProvider<TParams>): void;
1271
- }
1272
- /**
1273
- * Image handler interface for providers.
1274
- *
1275
- * Implemented by providers to enable image generation capabilities.
1276
- *
1277
- * @typeParam TParams - Provider-specific parameter type
1278
- * @internal
1279
- */
1280
- interface ImageHandler<TParams = unknown> {
1281
- /**
1282
- * Binds a model ID to create an executable image model.
1283
- *
1284
- * @param modelId - The model identifier to bind
1285
- * @returns A bound image model ready for generation
1286
- */
1287
- bind(modelId: string): BoundImageModel<TParams>;
1288
- /**
1289
- * Sets the parent provider reference.
1290
- *
1291
- * @param provider - The parent provider
1292
- * @internal
1293
- */
1294
- _setProvider?(provider: ImageProvider<TParams>): void;
1295
- }
1296
- /**
1297
- * Bound LLM model interface (forward declaration).
1298
- *
1299
- * Full definition is in llm.ts to avoid circular dependencies.
1300
- *
1301
- * @typeParam TParams - Provider-specific parameter type
1302
- */
1303
- interface BoundLLMModel<TParams = unknown> {
1304
- /** The model identifier */
1305
- readonly modelId: string;
1306
- /** Reference to the parent provider */
1307
- readonly provider: LLMProvider<TParams>;
1308
- }
1309
- /**
1310
- * Bound embedding model interface.
1311
- *
1312
- * Represents an embedding model bound to a specific model ID,
1313
- * ready to generate embeddings.
1314
- *
1315
- * @typeParam TParams - Provider-specific parameter type
1316
- */
1317
- interface BoundEmbeddingModel<TParams = unknown> {
1318
- /** The model identifier */
1319
- readonly modelId: string;
1320
- /** Reference to the parent provider */
1321
- readonly provider: EmbeddingProvider<TParams>;
1322
- /** Maximum number of inputs per batch request */
1323
- readonly maxBatchSize: number;
1324
- /** Maximum length of input text in tokens */
1325
- readonly maxInputLength: number;
1326
- /** Output embedding dimensions */
1327
- readonly dimensions: number;
1328
- /**
1329
- * Execute embedding request.
1330
- *
1331
- * @param request - The embedding request
1332
- * @returns Promise resolving to embedding response
1333
- */
1334
- embed(request: EmbeddingRequest<TParams>): Promise<EmbeddingResponse>;
1335
- }
1336
- /**
1337
- * Request passed to provider's embed method.
1338
- * @internal
1339
- */
1340
- interface EmbeddingRequest<TParams = unknown> {
1341
- /** Inputs to embed */
1342
- inputs: EmbeddingInput[];
1343
- /** Provider-specific parameters (passed through unchanged) */
1344
- params?: TParams;
1345
- /** Provider infrastructure config */
1346
- config: ProviderConfig;
1347
- /** Abort signal for cancellation */
1348
- signal?: AbortSignal;
1349
- }
1350
- /**
1351
- * Response from provider's embed method.
1352
- * @internal
1353
- */
1354
- interface EmbeddingResponse {
1355
- /** Embedding vectors */
1356
- embeddings: EmbeddingVector[];
1357
- /** Aggregate usage */
1358
- usage: EmbeddingUsage;
1359
- /** Provider-specific response metadata */
1360
- metadata?: Record<string, unknown>;
1361
- }
1362
- /**
1363
- * Single vector from provider response.
1364
- * @internal
1365
- */
1366
- interface EmbeddingVector {
1367
- /** The embedding vector (floats or base64 string) */
1368
- vector: number[] | string;
1369
- /** Index in input array */
1370
- index: number;
1371
- /** Token count for this input */
1372
- tokens?: number;
1373
- /** Provider-specific per-embedding metadata */
1374
- metadata?: Record<string, unknown>;
1375
- }
1376
- /**
1377
- * Usage statistics for embedding operations.
1378
- */
1379
- interface EmbeddingUsage {
1380
- /** Total tokens processed */
1381
- totalTokens: number;
1382
- }
1383
- /**
1384
- * Valid input types for embedding.
1385
- */
1386
- type EmbeddingInput = string | {
1387
- type: 'text';
1388
- text: string;
1389
- } | {
1390
- type: 'image';
1391
- source: unknown;
1392
- mimeType: string;
1393
- };
1394
- /**
1395
- * Bound image model interface.
1396
- *
1397
- * Represents an image generation model bound to a specific model ID.
1398
- *
1399
- * @typeParam TParams - Provider-specific parameter type
1400
- */
1401
- /**
1402
- * Provider factory function with metadata and modality handlers.
1403
- *
1404
- * The Provider interface represents a callable function that creates
1405
- * model references, along with metadata and modality-specific handlers.
1406
- *
1407
- * @typeParam TOptions - Provider-specific options passed to the factory
1408
- *
1409
- * @example
1410
- * ```typescript
1411
- * // Using a provider
1412
- * const model = openai('gpt-4', { temperature: 0.7 });
1413
- *
1414
- * // Accessing provider metadata
1415
- * console.log(openai.name); // 'openai'
1416
- * console.log(openai.version); // '1.0.0'
1417
- * ```
1418
- *
1419
- * @remarks
1420
- * Providers are intended to be used with `llm()`, `embedding()`, or `image()`.
1421
- * Direct handler access is not part of the public API.
1422
- */
1423
- interface Provider<TOptions = unknown> extends ProviderIdentity {
1424
- /**
1425
- * Creates a model reference with optional provider-specific options.
1426
- *
1427
- * @param modelId - The model identifier
1428
- * @param options - Provider-specific options
1429
- * @returns A model reference for use with llm() or other functions
1430
- */
1431
- (modelId: string, options?: TOptions): ModelReference<TOptions>;
1432
- /** Provider name (e.g., 'openai', 'anthropic') */
1433
- readonly name: string;
1434
- /** Provider version string */
1435
- readonly version: string;
1436
- }
1437
- /**
1438
- * Provider with LLM modality support.
1439
- *
1440
- * Type alias for providers that support language model inference.
1441
- *
1442
- * @typeParam TParams - Model-specific parameters type
1443
- * @typeParam TOptions - Provider-specific options type
1444
- */
1445
- type LLMProvider<TParams = unknown, TOptions = unknown> = Provider<TOptions> & {
1446
- /** @internal */
1447
- readonly __params?: TParams;
1448
- };
1449
- /**
1450
- * Provider with Embedding modality support.
1451
- *
1452
- * Type alias for providers that support embedding generation.
1453
- *
1454
- * @typeParam TParams - Model-specific parameters type
1455
- * @typeParam TOptions - Provider-specific options type
1456
- */
1457
- type EmbeddingProvider<TParams = unknown, TOptions = unknown> = Provider<TOptions> & {
1458
- /** @internal */
1459
- readonly __params?: TParams;
1460
- };
1461
- /**
1462
- * Provider with Image modality support.
1463
- *
1464
- * Type alias for providers that support image generation.
1465
- *
1466
- * @typeParam TParams - Model-specific parameters type
1467
- * @typeParam TOptions - Provider-specific options type
1468
- */
1469
- type ImageProvider<TParams = unknown, TOptions = unknown> = Provider<TOptions> & {
1470
- /** @internal */
1471
- readonly __params?: TParams;
1472
- };
1473
-
1474
- export { type ImageCapabilities as $, type AssistantContent as A, type BinaryBlock as B, type ContentBlock as C, type BoundEmbeddingModel as D, type EmbeddingHandler as E, type EmbeddingRequest as F, type EmbeddingResponse as G, type EmbeddingVector as H, type ImageOptions as I, type EmbeddingUsage as J, type KeyStrategy as K, type LLMProvider as L, type ModelReference as M, type EmbeddingInput as N, type ImageInput as O, type ProviderIdentity as P, type ImageEditInput as Q, type ReasoningBlock as R, type ImageGenerateOptions as S, type TextBlock as T, type UserContent as U, type VideoBlock as V, type GeneratedImage as W, type ImageUsage as X, type ImageResult as Y, type ImageStreamEvent as Z, type ImageStreamResult as _, type ProviderConfig as a, type ImageRequest as a0, type ImageEditRequest as a1, type ImageResponse as a2, type ImageProviderStreamResult as a3, type BoundImageModel as a4, type ImageHandler$1 as a5, type ImageModelInput as a6, type ImageInstance as b, type LLMHandler as c, type ImageHandler as d, type Provider as e, Image as f, UPPError as g, ErrorCode as h, ModalityType as i, type Modality as j, type ImageBlock as k, type AudioBlock as l, type ImageSource as m, ContentBlockType as n, ImageSourceType as o, isTextBlock as p, isReasoningBlock as q, reasoning as r, isImageBlock as s, text as t, isAudioBlock as u, isVideoBlock as v, isBinaryBlock as w, type RetryStrategy as x, type EmbeddingProvider as y, type ImageProvider as z };