@providerprotocol/ai 0.0.22 → 0.0.24

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 (51) hide show
  1. package/README.md +188 -6
  2. package/dist/anthropic/index.d.ts +1 -1
  3. package/dist/anthropic/index.js +95 -36
  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-M4BMM5IB.js → chunk-6AZVUI6H.js} +20 -4
  8. package/dist/chunk-6AZVUI6H.js.map +1 -0
  9. package/dist/chunk-73IIE3QT.js +120 -0
  10. package/dist/chunk-73IIE3QT.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-NWS5IKNR.js → chunk-TOJCZMVU.js} +3 -12
  16. package/dist/chunk-TOJCZMVU.js.map +1 -0
  17. package/dist/{chunk-I2VHCGQE.js → chunk-Z6DKC37J.js} +6 -5
  18. package/dist/chunk-Z6DKC37J.js.map +1 -0
  19. package/dist/google/index.d.ts +36 -4
  20. package/dist/google/index.js +98 -53
  21. package/dist/google/index.js.map +1 -1
  22. package/dist/http/index.d.ts +2 -2
  23. package/dist/http/index.js +4 -4
  24. package/dist/index.d.ts +8 -6
  25. package/dist/index.js +92 -122
  26. package/dist/index.js.map +1 -1
  27. package/dist/ollama/index.d.ts +5 -2
  28. package/dist/ollama/index.js +47 -36
  29. package/dist/ollama/index.js.map +1 -1
  30. package/dist/openai/index.d.ts +1 -1
  31. package/dist/openai/index.js +117 -56
  32. package/dist/openai/index.js.map +1 -1
  33. package/dist/openrouter/index.d.ts +1 -1
  34. package/dist/openrouter/index.js +58 -53
  35. package/dist/openrouter/index.js.map +1 -1
  36. package/dist/{provider-DWEAzeM5.d.ts → provider-x4RocsnK.d.ts} +199 -54
  37. package/dist/proxy/index.d.ts +2 -2
  38. package/dist/proxy/index.js +11 -9
  39. package/dist/proxy/index.js.map +1 -1
  40. package/dist/{retry-DmPmqZL6.d.ts → retry-DTfjXXPh.d.ts} +1 -1
  41. package/dist/{stream-DbkLOIbJ.d.ts → stream-ITNFNnO4.d.ts} +95 -38
  42. package/dist/xai/index.d.ts +1 -1
  43. package/dist/xai/index.js +221 -97
  44. package/dist/xai/index.js.map +1 -1
  45. package/package.json +1 -1
  46. package/dist/chunk-7WYBJPJJ.js.map +0 -1
  47. package/dist/chunk-I2VHCGQE.js.map +0 -1
  48. package/dist/chunk-M4BMM5IB.js.map +0 -1
  49. package/dist/chunk-NWS5IKNR.js.map +0 -1
  50. package/dist/chunk-RFWLEFAB.js.map +0 -1
  51. package/dist/chunk-RS7C25LS.js.map +0 -1
@@ -7,6 +7,70 @@
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
+ /** 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];
10
74
  /**
11
75
  * Image source variants for ImageBlock.
12
76
  *
@@ -62,6 +126,26 @@ interface TextBlock {
62
126
  /** The text content */
63
127
  text: string;
64
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
+ }
65
149
  /**
66
150
  * Image content block.
67
151
  *
@@ -176,7 +260,7 @@ interface BinaryBlock {
176
260
  *
177
261
  * Used when a function or property can accept any type of content block.
178
262
  */
179
- type ContentBlock = TextBlock | ImageBlock | AudioBlock | VideoBlock | BinaryBlock;
263
+ type ContentBlock = TextBlock | ReasoningBlock | ImageBlock | AudioBlock | VideoBlock | BinaryBlock;
180
264
  /**
181
265
  * Content types allowed in user messages.
182
266
  *
@@ -188,7 +272,7 @@ type UserContent = TextBlock | ImageBlock | AudioBlock | VideoBlock | BinaryBloc
188
272
  *
189
273
  * Assistants can generate text and media but not arbitrary binary data.
190
274
  */
191
- type AssistantContent = TextBlock | ImageBlock | AudioBlock | VideoBlock;
275
+ type AssistantContent = TextBlock | ReasoningBlock | ImageBlock | AudioBlock | VideoBlock;
192
276
  /**
193
277
  * Creates a text content block from a string.
194
278
  *
@@ -202,6 +286,19 @@ type AssistantContent = TextBlock | ImageBlock | AudioBlock | VideoBlock;
202
286
  * ```
203
287
  */
204
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;
205
302
  /**
206
303
  * Type guard for TextBlock.
207
304
  *
@@ -216,6 +313,20 @@ declare function text(content: string): TextBlock;
216
313
  * ```
217
314
  */
218
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;
219
330
  /**
220
331
  * Type guard for ImageBlock.
221
332
  *
@@ -282,70 +393,100 @@ declare function isBinaryBlock(block: ContentBlock): block is BinaryBlock;
282
393
  * @module types/errors
283
394
  */
284
395
  /**
285
- * Normalized error codes for cross-provider error handling.
396
+ * Error code constants for cross-provider error handling.
286
397
  *
287
- * These codes provide a consistent way to identify and handle errors
288
- * regardless of which AI provider generated them.
398
+ * Use these constants instead of raw strings for type-safe error handling:
289
399
  *
290
400
  * @example
291
401
  * ```typescript
402
+ * import { ErrorCode } from 'upp';
403
+ *
292
404
  * try {
293
405
  * await llm.generate('Hello');
294
406
  * } catch (error) {
295
407
  * if (error instanceof UPPError) {
296
408
  * switch (error.code) {
297
- * case 'RATE_LIMITED':
409
+ * case ErrorCode.RateLimited:
298
410
  * await delay(error.retryAfter);
299
411
  * break;
300
- * case 'AUTHENTICATION_FAILED':
412
+ * case ErrorCode.AuthenticationFailed:
301
413
  * throw new Error('Invalid API key');
302
414
  * }
303
415
  * }
304
416
  * }
305
417
  * ```
306
418
  */
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';
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;
349
490
  /**
350
491
  * Unified Provider Protocol Error.
351
492
  *
@@ -354,26 +495,30 @@ type Modality =
354
495
  *
355
496
  * @example
356
497
  * ```typescript
498
+ * import { ErrorCode, ModalityType } from 'upp';
499
+ *
357
500
  * throw new UPPError(
358
501
  * 'API key is invalid',
359
- * 'AUTHENTICATION_FAILED',
502
+ * ErrorCode.AuthenticationFailed,
360
503
  * 'openai',
361
- * 'llm',
504
+ * ModalityType.LLM,
362
505
  * 401
363
506
  * );
364
507
  * ```
365
508
  *
366
509
  * @example
367
510
  * ```typescript
511
+ * import { ErrorCode, ModalityType } from 'upp';
512
+ *
368
513
  * // Wrapping a provider error
369
514
  * try {
370
515
  * await openai.chat.completions.create({ ... });
371
516
  * } catch (err) {
372
517
  * throw new UPPError(
373
518
  * 'OpenAI request failed',
374
- * 'PROVIDER_ERROR',
519
+ * ErrorCode.ProviderError,
375
520
  * 'openai',
376
- * 'llm',
521
+ * ModalityType.LLM,
377
522
  * err.status,
378
523
  * err
379
524
  * );
@@ -1326,4 +1471,4 @@ type ImageProvider<TParams = unknown, TOptions = unknown> = Provider<TOptions> &
1326
1471
  readonly __params?: TParams;
1327
1472
  };
1328
1473
 
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 };
1474
+ export { type ImageCapabilities as $, type AssistantContent as A, type BoundEmbeddingModel as B, type ContentBlock as C, type RetryStrategy as D, type EmbeddingInput as E, type EmbeddingProvider as F, type ImageProvider as G, type EmbeddingRequest as H, type ImageOptions as I, type EmbeddingResponse as J, type KeyStrategy as K, type LLMProvider as L, type ModelReference as M, type EmbeddingVector 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 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, reasoning as s, text as t, isTextBlock as u, isReasoningBlock as v, isImageBlock as w, isAudioBlock as x, isVideoBlock as y, isBinaryBlock 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-x4RocsnK.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-ITNFNnO4.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-6AZVUI6H.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();