@providerprotocol/ai 0.0.22 → 0.0.23

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 (48) hide show
  1. package/README.md +188 -6
  2. package/dist/anthropic/index.d.ts +1 -1
  3. package/dist/anthropic/index.js +30 -25
  4. package/dist/anthropic/index.js.map +1 -1
  5. package/dist/{chunk-7WYBJPJJ.js → chunk-55X3W2MN.js} +4 -3
  6. package/dist/chunk-55X3W2MN.js.map +1 -0
  7. package/dist/chunk-73IIE3QT.js +120 -0
  8. package/dist/chunk-73IIE3QT.js.map +1 -0
  9. package/dist/{chunk-M4BMM5IB.js → chunk-MF5ETY5O.js} +13 -4
  10. package/dist/chunk-MF5ETY5O.js.map +1 -0
  11. package/dist/{chunk-RFWLEFAB.js → chunk-QNJO7DSD.js} +61 -16
  12. package/dist/chunk-QNJO7DSD.js.map +1 -0
  13. package/dist/{chunk-RS7C25LS.js → chunk-SBCATNHA.js} +9 -5
  14. package/dist/chunk-SBCATNHA.js.map +1 -0
  15. package/dist/{chunk-I2VHCGQE.js → chunk-Z6DKC37J.js} +6 -5
  16. package/dist/chunk-Z6DKC37J.js.map +1 -0
  17. package/dist/google/index.d.ts +3 -2
  18. package/dist/google/index.js +38 -33
  19. package/dist/google/index.js.map +1 -1
  20. package/dist/http/index.d.ts +2 -2
  21. package/dist/http/index.js +3 -3
  22. package/dist/index.d.ts +8 -6
  23. package/dist/index.js +81 -121
  24. package/dist/index.js.map +1 -1
  25. package/dist/ollama/index.d.ts +5 -2
  26. package/dist/ollama/index.js +34 -29
  27. package/dist/ollama/index.js.map +1 -1
  28. package/dist/openai/index.d.ts +1 -1
  29. package/dist/openai/index.js +58 -53
  30. package/dist/openai/index.js.map +1 -1
  31. package/dist/openrouter/index.d.ts +1 -1
  32. package/dist/openrouter/index.js +57 -52
  33. package/dist/openrouter/index.js.map +1 -1
  34. package/dist/{provider-DWEAzeM5.d.ts → provider-DR1yins0.d.ts} +148 -52
  35. package/dist/proxy/index.d.ts +2 -2
  36. package/dist/proxy/index.js +11 -9
  37. package/dist/proxy/index.js.map +1 -1
  38. package/dist/{retry-DmPmqZL6.d.ts → retry-DJiqAslw.d.ts} +1 -1
  39. package/dist/{stream-DbkLOIbJ.d.ts → stream-BuTrqt_j.d.ts} +90 -38
  40. package/dist/xai/index.d.ts +1 -1
  41. package/dist/xai/index.js +71 -66
  42. package/dist/xai/index.js.map +1 -1
  43. package/package.json +1 -1
  44. package/dist/chunk-7WYBJPJJ.js.map +0 -1
  45. package/dist/chunk-I2VHCGQE.js.map +0 -1
  46. package/dist/chunk-M4BMM5IB.js.map +0 -1
  47. package/dist/chunk-RFWLEFAB.js.map +0 -1
  48. package/dist/chunk-RS7C25LS.js.map +0 -1
@@ -7,6 +7,68 @@
7
7
  *
8
8
  * @module types/content
9
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
+ /** Image content */
30
+ readonly Image: "image";
31
+ /** Audio content */
32
+ readonly Audio: "audio";
33
+ /** Video content */
34
+ readonly Video: "video";
35
+ /** Binary/arbitrary data content */
36
+ readonly Binary: "binary";
37
+ };
38
+ /**
39
+ * Content block type discriminator union.
40
+ *
41
+ * This type is derived from {@link ContentBlockType} constants.
42
+ */
43
+ type ContentBlockType = (typeof ContentBlockType)[keyof typeof ContentBlockType];
44
+ /**
45
+ * Image source type constants.
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * import { ImageSourceType } from 'upp';
50
+ *
51
+ * if (source.type === ImageSourceType.Base64) {
52
+ * // Handle base64 encoded image
53
+ * } else if (source.type === ImageSourceType.Url) {
54
+ * // Handle URL reference
55
+ * }
56
+ * ```
57
+ */
58
+ declare const ImageSourceType: {
59
+ /** Base64-encoded image data */
60
+ readonly Base64: "base64";
61
+ /** URL reference to image */
62
+ readonly Url: "url";
63
+ /** Raw bytes image data */
64
+ readonly Bytes: "bytes";
65
+ };
66
+ /**
67
+ * Image source type discriminator union.
68
+ *
69
+ * This type is derived from {@link ImageSourceType} constants.
70
+ */
71
+ type ImageSourceType = (typeof ImageSourceType)[keyof typeof ImageSourceType];
10
72
  /**
11
73
  * Image source variants for ImageBlock.
12
74
  *
@@ -282,70 +344,100 @@ declare function isBinaryBlock(block: ContentBlock): block is BinaryBlock;
282
344
  * @module types/errors
283
345
  */
284
346
  /**
285
- * Normalized error codes for cross-provider error handling.
347
+ * Error code constants for cross-provider error handling.
286
348
  *
287
- * These codes provide a consistent way to identify and handle errors
288
- * regardless of which AI provider generated them.
349
+ * Use these constants instead of raw strings for type-safe error handling:
289
350
  *
290
351
  * @example
291
352
  * ```typescript
353
+ * import { ErrorCode } from 'upp';
354
+ *
292
355
  * try {
293
356
  * await llm.generate('Hello');
294
357
  * } catch (error) {
295
358
  * if (error instanceof UPPError) {
296
359
  * switch (error.code) {
297
- * case 'RATE_LIMITED':
360
+ * case ErrorCode.RateLimited:
298
361
  * await delay(error.retryAfter);
299
362
  * break;
300
- * case 'AUTHENTICATION_FAILED':
363
+ * case ErrorCode.AuthenticationFailed:
301
364
  * throw new Error('Invalid API key');
302
365
  * }
303
366
  * }
304
367
  * }
305
368
  * ```
306
369
  */
307
- type ErrorCode =
308
- /** API key is invalid or expired */
309
- 'AUTHENTICATION_FAILED'
310
- /** Rate limit exceeded, retry after delay */
311
- | 'RATE_LIMITED'
312
- /** Input exceeds model's context window */
313
- | 'CONTEXT_LENGTH_EXCEEDED'
314
- /** Requested model does not exist */
315
- | 'MODEL_NOT_FOUND'
316
- /** Request parameters are malformed */
317
- | 'INVALID_REQUEST'
318
- /** Provider returned an unexpected response format */
319
- | 'INVALID_RESPONSE'
320
- /** Content was blocked by safety filters */
321
- | 'CONTENT_FILTERED'
322
- /** Account quota or credits exhausted */
323
- | 'QUOTA_EXCEEDED'
324
- /** Provider-specific error not covered by other codes */
325
- | 'PROVIDER_ERROR'
326
- /** Network connectivity issue */
327
- | 'NETWORK_ERROR'
328
- /** Request exceeded timeout limit */
329
- | 'TIMEOUT'
330
- /** Request was cancelled via AbortSignal */
331
- | 'CANCELLED';
332
- /**
333
- * Modality types supported by UPP.
334
- *
335
- * Each modality represents a different type of AI capability that
336
- * can be provided by a UPP-compatible provider.
337
- */
338
- type Modality =
339
- /** Large language model for text generation */
340
- 'llm'
341
- /** Text/image embedding model */
342
- | 'embedding'
343
- /** Image generation model */
344
- | 'image'
345
- /** Audio processing/generation model */
346
- | 'audio'
347
- /** Video processing/generation model */
348
- | 'video';
370
+ declare const ErrorCode: {
371
+ /** API key is invalid or expired */
372
+ readonly AuthenticationFailed: "AUTHENTICATION_FAILED";
373
+ /** Rate limit exceeded, retry after delay */
374
+ readonly RateLimited: "RATE_LIMITED";
375
+ /** Input exceeds model's context window */
376
+ readonly ContextLengthExceeded: "CONTEXT_LENGTH_EXCEEDED";
377
+ /** Requested model does not exist */
378
+ readonly ModelNotFound: "MODEL_NOT_FOUND";
379
+ /** Request parameters are malformed */
380
+ readonly InvalidRequest: "INVALID_REQUEST";
381
+ /** Provider returned an unexpected response format */
382
+ readonly InvalidResponse: "INVALID_RESPONSE";
383
+ /** Content was blocked by safety filters */
384
+ readonly ContentFiltered: "CONTENT_FILTERED";
385
+ /** Account quota or credits exhausted */
386
+ readonly QuotaExceeded: "QUOTA_EXCEEDED";
387
+ /** Provider-specific error not covered by other codes */
388
+ readonly ProviderError: "PROVIDER_ERROR";
389
+ /** Network connectivity issue */
390
+ readonly NetworkError: "NETWORK_ERROR";
391
+ /** Request exceeded timeout limit */
392
+ readonly Timeout: "TIMEOUT";
393
+ /** Request was cancelled via AbortSignal */
394
+ readonly Cancelled: "CANCELLED";
395
+ };
396
+ /**
397
+ * Error code discriminator union.
398
+ *
399
+ * This type is derived from {@link ErrorCode} constants. Use `ErrorCode.RateLimited`
400
+ * for constants or `type MyCode = ErrorCode` for type annotations.
401
+ */
402
+ type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
403
+ /**
404
+ * Modality type discriminator union.
405
+ *
406
+ * This type is derived from {@link ModalityType} constants. The name `Modality`
407
+ * is kept for backward compatibility; `ModalityType` works as both the const
408
+ * object and this type.
409
+ */
410
+ type Modality = (typeof ModalityType)[keyof typeof ModalityType];
411
+ /**
412
+ * Modality type constants.
413
+ *
414
+ * Use these constants for type-safe modality handling:
415
+ *
416
+ * @example
417
+ * ```typescript
418
+ * import { ModalityType } from 'upp';
419
+ *
420
+ * if (provider.modality === ModalityType.LLM) {
421
+ * // Handle LLM provider
422
+ * }
423
+ * ```
424
+ */
425
+ declare const ModalityType: {
426
+ /** Large language model for text generation */
427
+ readonly LLM: "llm";
428
+ /** Text/image embedding model */
429
+ readonly Embedding: "embedding";
430
+ /** Image generation model */
431
+ readonly Image: "image";
432
+ /** Audio processing/generation model */
433
+ readonly Audio: "audio";
434
+ /** Video processing/generation model */
435
+ readonly Video: "video";
436
+ };
437
+ /**
438
+ * Type alias for Modality, allowing `ModalityType` to work as both const and type.
439
+ */
440
+ type ModalityType = Modality;
349
441
  /**
350
442
  * Unified Provider Protocol Error.
351
443
  *
@@ -354,26 +446,30 @@ type Modality =
354
446
  *
355
447
  * @example
356
448
  * ```typescript
449
+ * import { ErrorCode, ModalityType } from 'upp';
450
+ *
357
451
  * throw new UPPError(
358
452
  * 'API key is invalid',
359
- * 'AUTHENTICATION_FAILED',
453
+ * ErrorCode.AuthenticationFailed,
360
454
  * 'openai',
361
- * 'llm',
455
+ * ModalityType.LLM,
362
456
  * 401
363
457
  * );
364
458
  * ```
365
459
  *
366
460
  * @example
367
461
  * ```typescript
462
+ * import { ErrorCode, ModalityType } from 'upp';
463
+ *
368
464
  * // Wrapping a provider error
369
465
  * try {
370
466
  * await openai.chat.completions.create({ ... });
371
467
  * } catch (err) {
372
468
  * throw new UPPError(
373
469
  * 'OpenAI request failed',
374
- * 'PROVIDER_ERROR',
470
+ * ErrorCode.ProviderError,
375
471
  * 'openai',
376
- * 'llm',
472
+ * ModalityType.LLM,
377
473
  * err.status,
378
474
  * err
379
475
  * );
@@ -1326,4 +1422,4 @@ type ImageProvider<TParams = unknown, TOptions = unknown> = Provider<TOptions> &
1326
1422
  readonly __params?: TParams;
1327
1423
  };
1328
1424
 
1329
- export { type ImageHandler$1 as $, type AssistantContent as A, type BoundEmbeddingModel as B, type ContentBlock as C, type ImageInput as D, type EmbeddingInput as E, type ImageEditInput as F, type ImageGenerateOptions as G, type GeneratedImage as H, type ImageOptions as I, type ImageUsage as J, type KeyStrategy as K, type LLMProvider as L, type ModelReference as M, type ImageResult as N, type ImageStreamEvent as O, type ProviderIdentity as P, type ImageStreamResult as Q, type RetryStrategy as R, type ImageCapabilities as S, type TextBlock as T, type UserContent as U, type VideoBlock as V, type ImageRequest as W, type ImageEditRequest as X, type ImageResponse as Y, type ImageProviderStreamResult as Z, type BoundImageModel as _, type ProviderConfig as a, type ImageModelInput as a0, type EmbeddingUsage as b, type ImageInstance as c, type LLMHandler as d, type EmbeddingHandler as e, type ImageHandler as f, type Provider as g, Image as h, UPPError as i, type ErrorCode as j, type Modality as k, type ImageBlock as l, type AudioBlock as m, type BinaryBlock as n, type ImageSource as o, isTextBlock as p, isImageBlock as q, isAudioBlock as r, isVideoBlock as s, text as t, isBinaryBlock as u, type EmbeddingProvider as v, type ImageProvider as w, type EmbeddingRequest as x, type EmbeddingResponse as y, type EmbeddingVector as z };
1425
+ export { type ImageResponse as $, type AssistantContent as A, type BoundEmbeddingModel as B, type ContentBlock as C, type EmbeddingRequest as D, type EmbeddingInput as E, type EmbeddingResponse as F, type EmbeddingVector as G, type ImageInput as H, type ImageOptions as I, type ImageEditInput as J, type KeyStrategy as K, type LLMProvider as L, type ModelReference as M, type ImageGenerateOptions as N, type GeneratedImage as O, type ProviderIdentity as P, type ImageUsage as Q, type RetryStrategy as R, type ImageResult as S, type TextBlock as T, type UserContent as U, type VideoBlock as V, type ImageStreamEvent as W, type ImageStreamResult as X, type ImageCapabilities as Y, type ImageRequest as Z, type ImageEditRequest as _, type ProviderConfig as a, type ImageProviderStreamResult as a0, type BoundImageModel as a1, type ImageHandler$1 as a2, type ImageModelInput as a3, type EmbeddingUsage as b, type ImageInstance as c, type LLMHandler as d, type EmbeddingHandler as e, type ImageHandler as f, type Provider as g, Image as h, UPPError as i, ErrorCode as j, ModalityType as k, type Modality as l, type ImageBlock as m, type AudioBlock as n, type BinaryBlock as o, type ImageSource as p, ContentBlockType as q, ImageSourceType as r, isTextBlock as s, text as t, isImageBlock as u, isAudioBlock as v, isVideoBlock as w, isBinaryBlock as x, type EmbeddingProvider as y, type ImageProvider as z };
@@ -1,5 +1,5 @@
1
- import { g as Provider, M as ModelReference } from '../provider-DWEAzeM5.js';
2
- import { M as Message, b as MessageJSON, T as Turn, H as TurnJSON, f as StreamEvent, S as StreamResult, J as JSONSchema, k as ToolMetadata, c as Tool } from '../stream-DbkLOIbJ.js';
1
+ import { g as Provider, M as ModelReference } from '../provider-DR1yins0.js';
2
+ import { M as Message, b as MessageJSON, T as Turn, I as TurnJSON, f as StreamEvent, S as StreamResult, J as JSONSchema, k as ToolMetadata, c as Tool } from '../stream-BuTrqt_j.js';
3
3
 
4
4
  /**
5
5
  * @fileoverview Proxy provider types.
@@ -3,20 +3,22 @@ import {
3
3
  } from "../chunk-MKDLXV4O.js";
4
4
  import {
5
5
  parseJsonResponse
6
- } from "../chunk-I2VHCGQE.js";
6
+ } from "../chunk-Z6DKC37J.js";
7
7
  import {
8
8
  AssistantMessage,
9
9
  ToolResultMessage,
10
10
  UserMessage,
11
11
  createProvider
12
- } from "../chunk-M4BMM5IB.js";
12
+ } from "../chunk-MF5ETY5O.js";
13
13
  import {
14
+ ErrorCode,
15
+ ModalityType,
14
16
  UPPError,
15
17
  doFetch,
16
18
  doStreamFetch,
17
19
  normalizeHttpError,
18
20
  toError
19
- } from "../chunk-RFWLEFAB.js";
21
+ } from "../chunk-QNJO7DSD.js";
20
22
 
21
23
  // src/providers/proxy/serialization.ts
22
24
  function serializeMessage(m) {
@@ -56,9 +58,9 @@ function deserializeMessage(json) {
56
58
  default:
57
59
  throw new UPPError(
58
60
  `Unknown message type: ${json.type}`,
59
- "INVALID_RESPONSE",
61
+ ErrorCode.InvalidResponse,
60
62
  "proxy",
61
- "llm"
63
+ ModalityType.LLM
62
64
  );
63
65
  }
64
66
  }
@@ -118,9 +120,9 @@ function createLLMHandler(options) {
118
120
  if (!providerRef) {
119
121
  throw new UPPError(
120
122
  "Provider reference not set. Handler must be used with createProvider().",
121
- "INVALID_REQUEST",
123
+ ErrorCode.InvalidRequest,
122
124
  "proxy",
123
- "llm"
125
+ ModalityType.LLM
124
126
  );
125
127
  }
126
128
  const model = {
@@ -184,9 +186,9 @@ function createLLMHandler(options) {
184
186
  if (!response.body) {
185
187
  throw new UPPError(
186
188
  "Response body is null",
187
- "PROVIDER_ERROR",
189
+ ErrorCode.ProviderError,
188
190
  "proxy",
189
- "llm"
191
+ ModalityType.LLM
190
192
  );
191
193
  }
192
194
  const reader = response.body.getReader();