@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
package/dist/index.js CHANGED
@@ -6,9 +6,22 @@ import {
6
6
  import {
7
7
  Image
8
8
  } from "./chunk-WAKD3OO5.js";
9
+ import {
10
+ StreamEventType,
11
+ contentBlockStart,
12
+ contentBlockStop,
13
+ createStreamResult,
14
+ messageStart,
15
+ messageStop,
16
+ textDelta,
17
+ toolCallDelta,
18
+ toolExecutionEnd,
19
+ toolExecutionStart
20
+ } from "./chunk-73IIE3QT.js";
9
21
  import {
10
22
  AssistantMessage,
11
23
  Message,
24
+ MessageRole,
12
25
  ToolResultMessage,
13
26
  UserMessage,
14
27
  createProvider,
@@ -19,124 +32,73 @@ import {
19
32
  resolveEmbeddingHandler,
20
33
  resolveImageHandler,
21
34
  resolveLLMHandler
22
- } from "./chunk-M4BMM5IB.js";
35
+ } from "./chunk-6AZVUI6H.js";
23
36
  import {
24
37
  ExponentialBackoff,
25
38
  LinearBackoff,
26
39
  NoRetry,
27
40
  RetryAfterStrategy,
28
41
  TokenBucket
29
- } from "./chunk-RS7C25LS.js";
30
- import "./chunk-NWS5IKNR.js";
42
+ } from "./chunk-SBCATNHA.js";
43
+ import "./chunk-TOJCZMVU.js";
31
44
  import {
32
45
  DynamicKey,
33
46
  RoundRobinKeys,
34
47
  WeightedKeys
35
- } from "./chunk-7WYBJPJJ.js";
48
+ } from "./chunk-55X3W2MN.js";
36
49
  import {
50
+ ErrorCode,
51
+ ModalityType,
37
52
  UPPError,
38
53
  toError
39
- } from "./chunk-RFWLEFAB.js";
54
+ } from "./chunk-QNJO7DSD.js";
40
55
 
41
56
  // src/types/content.ts
57
+ var ContentBlockType = {
58
+ /** Text content */
59
+ Text: "text",
60
+ /** Reasoning/thinking content from extended thinking models */
61
+ Reasoning: "reasoning",
62
+ /** Image content */
63
+ Image: "image",
64
+ /** Audio content */
65
+ Audio: "audio",
66
+ /** Video content */
67
+ Video: "video",
68
+ /** Binary/arbitrary data content */
69
+ Binary: "binary"
70
+ };
71
+ var ImageSourceType = {
72
+ /** Base64-encoded image data */
73
+ Base64: "base64",
74
+ /** URL reference to image */
75
+ Url: "url",
76
+ /** Raw bytes image data */
77
+ Bytes: "bytes"
78
+ };
42
79
  function text(content) {
43
- return { type: "text", text: content };
80
+ return { type: ContentBlockType.Text, text: content };
81
+ }
82
+ function reasoning(content) {
83
+ return { type: ContentBlockType.Reasoning, text: content };
44
84
  }
45
85
  function isTextBlock(block) {
46
- return block.type === "text";
86
+ return block.type === ContentBlockType.Text;
87
+ }
88
+ function isReasoningBlock(block) {
89
+ return block.type === ContentBlockType.Reasoning;
47
90
  }
48
91
  function isImageBlock(block) {
49
- return block.type === "image";
92
+ return block.type === ContentBlockType.Image;
50
93
  }
51
94
  function isAudioBlock(block) {
52
- return block.type === "audio";
95
+ return block.type === ContentBlockType.Audio;
53
96
  }
54
97
  function isVideoBlock(block) {
55
- return block.type === "video";
98
+ return block.type === ContentBlockType.Video;
56
99
  }
57
100
  function isBinaryBlock(block) {
58
- return block.type === "binary";
59
- }
60
-
61
- // src/types/stream.ts
62
- function createStreamResult(generator, turnPromiseOrFactory, abortController) {
63
- let cachedTurn = null;
64
- const getTurn = () => {
65
- if (typeof turnPromiseOrFactory === "function") {
66
- if (!cachedTurn) {
67
- cachedTurn = turnPromiseOrFactory();
68
- }
69
- return cachedTurn;
70
- }
71
- return turnPromiseOrFactory;
72
- };
73
- return {
74
- [Symbol.asyncIterator]() {
75
- return generator;
76
- },
77
- get turn() {
78
- return getTurn();
79
- },
80
- abort() {
81
- abortController.abort();
82
- }
83
- };
84
- }
85
- function textDelta(text2, index = 0) {
86
- return {
87
- type: "text_delta",
88
- index,
89
- delta: { text: text2 }
90
- };
91
- }
92
- function toolCallDelta(toolCallId, toolName, argumentsJson, index = 0) {
93
- return {
94
- type: "tool_call_delta",
95
- index,
96
- delta: { toolCallId, toolName, argumentsJson }
97
- };
98
- }
99
- function messageStart() {
100
- return {
101
- type: "message_start",
102
- index: 0,
103
- delta: {}
104
- };
105
- }
106
- function messageStop() {
107
- return {
108
- type: "message_stop",
109
- index: 0,
110
- delta: {}
111
- };
112
- }
113
- function contentBlockStart(index) {
114
- return {
115
- type: "content_block_start",
116
- index,
117
- delta: {}
118
- };
119
- }
120
- function contentBlockStop(index) {
121
- return {
122
- type: "content_block_stop",
123
- index,
124
- delta: {}
125
- };
126
- }
127
- function toolExecutionStart(toolCallId, toolName, timestamp, index = 0) {
128
- return {
129
- type: "tool_execution_start",
130
- index,
131
- delta: { toolCallId, toolName, timestamp }
132
- };
133
- }
134
- function toolExecutionEnd(toolCallId, toolName, result, isError, timestamp, index = 0) {
135
- return {
136
- type: "tool_execution_end",
137
- index,
138
- delta: { toolCallId, toolName, result, isError, timestamp }
139
- };
101
+ return block.type === ContentBlockType.Binary;
140
102
  }
141
103
 
142
104
  // src/core/llm.ts
@@ -157,9 +119,9 @@ function llm(options) {
157
119
  if (!llmHandler) {
158
120
  throw new UPPError(
159
121
  `Provider '${provider.name}' does not support LLM modality`,
160
- "INVALID_REQUEST",
122
+ ErrorCode.InvalidRequest,
161
123
  provider.name,
162
- "llm"
124
+ ModalityType.LLM
163
125
  );
164
126
  }
165
127
  const boundModel = llmHandler.bind(modelRef.modelId);
@@ -167,17 +129,17 @@ function llm(options) {
167
129
  if (structure && !capabilities.structuredOutput) {
168
130
  throw new UPPError(
169
131
  `Provider '${provider.name}' does not support structured output`,
170
- "INVALID_REQUEST",
132
+ ErrorCode.InvalidRequest,
171
133
  provider.name,
172
- "llm"
134
+ ModalityType.LLM
173
135
  );
174
136
  }
175
137
  if (tools && tools.length > 0 && !capabilities.tools) {
176
138
  throw new UPPError(
177
139
  `Provider '${provider.name}' does not support tools`,
178
- "INVALID_REQUEST",
140
+ ErrorCode.InvalidRequest,
179
141
  provider.name,
180
- "llm"
142
+ ModalityType.LLM
181
143
  );
182
144
  }
183
145
  const instance = {
@@ -203,9 +165,9 @@ function llm(options) {
203
165
  if (!capabilities.streaming) {
204
166
  throw new UPPError(
205
167
  `Provider '${provider.name}' does not support streaming`,
206
- "INVALID_REQUEST",
168
+ ErrorCode.InvalidRequest,
207
169
  provider.name,
208
- "llm"
170
+ ModalityType.LLM
209
171
  );
210
172
  }
211
173
  const { history, messages } = parseInputs(historyOrInput, inputs);
@@ -322,9 +284,9 @@ async function executeGenerate(model, config, system, params, tools, toolStrateg
322
284
  await toolStrategy?.onMaxIterations?.(maxIterations);
323
285
  throw new UPPError(
324
286
  `Tool execution exceeded maximum iterations (${maxIterations})`,
325
- "INVALID_REQUEST",
287
+ ErrorCode.InvalidRequest,
326
288
  model.provider.name,
327
- "llm"
289
+ ModalityType.LLM
328
290
  );
329
291
  }
330
292
  const results = await executeTools(
@@ -385,14 +347,14 @@ function executeStream(model, config, system, params, tools, toolStrategy, struc
385
347
  });
386
348
  const maxIterations = toolStrategy?.maxIterations ?? DEFAULT_MAX_ITERATIONS;
387
349
  const onAbort = () => {
388
- const error = new UPPError("Stream cancelled", "CANCELLED", model.provider.name, "llm");
350
+ const error = new UPPError("Stream cancelled", ErrorCode.Cancelled, model.provider.name, ModalityType.LLM);
389
351
  generatorError = error;
390
352
  rejectGenerator(error);
391
353
  };
392
354
  abortController.signal.addEventListener("abort", onAbort, { once: true });
393
355
  const ensureNotAborted = () => {
394
356
  if (abortController.signal.aborted) {
395
- throw new UPPError("Stream cancelled", "CANCELLED", model.provider.name, "llm");
357
+ throw new UPPError("Stream cancelled", ErrorCode.Cancelled, model.provider.name, ModalityType.LLM);
396
358
  }
397
359
  };
398
360
  async function* generateStream() {
@@ -429,9 +391,9 @@ function executeStream(model, config, system, params, tools, toolStrategy, struc
429
391
  await toolStrategy?.onMaxIterations?.(maxIterations);
430
392
  throw new UPPError(
431
393
  `Tool execution exceeded maximum iterations (${maxIterations})`,
432
- "INVALID_REQUEST",
394
+ ErrorCode.InvalidRequest,
433
395
  model.provider.name,
434
- "llm"
396
+ ModalityType.LLM
435
397
  );
436
398
  }
437
399
  const toolEvents = [];
@@ -461,7 +423,7 @@ function executeStream(model, config, system, params, tools, toolStrategy, struc
461
423
  } finally {
462
424
  abortController.signal.removeEventListener("abort", onAbort);
463
425
  if (!generatorCompleted && !generatorSettled) {
464
- const error = new UPPError("Stream cancelled", "CANCELLED", model.provider.name, "llm");
426
+ const error = new UPPError("Stream cancelled", ErrorCode.Cancelled, model.provider.name, ModalityType.LLM);
465
427
  generatorError = error;
466
428
  if (!abortController.signal.aborted) {
467
429
  abortController.abort();
@@ -630,25 +592,25 @@ function validateMediaCapabilities(messages, capabilities, providerName) {
630
592
  if (block.type === "image" && !capabilities.imageInput) {
631
593
  throw new UPPError(
632
594
  `Provider '${providerName}' does not support image input`,
633
- "INVALID_REQUEST",
595
+ ErrorCode.InvalidRequest,
634
596
  providerName,
635
- "llm"
597
+ ModalityType.LLM
636
598
  );
637
599
  }
638
600
  if (block.type === "video" && !capabilities.videoInput) {
639
601
  throw new UPPError(
640
602
  `Provider '${providerName}' does not support video input`,
641
- "INVALID_REQUEST",
603
+ ErrorCode.InvalidRequest,
642
604
  providerName,
643
- "llm"
605
+ ModalityType.LLM
644
606
  );
645
607
  }
646
608
  if (block.type === "audio" && !capabilities.audioInput) {
647
609
  throw new UPPError(
648
610
  `Provider '${providerName}' does not support audio input`,
649
- "INVALID_REQUEST",
611
+ ErrorCode.InvalidRequest,
650
612
  providerName,
651
- "llm"
613
+ ModalityType.LLM
652
614
  );
653
615
  }
654
616
  }
@@ -672,9 +634,9 @@ function embedding(options) {
672
634
  if (!handler) {
673
635
  throw new UPPError(
674
636
  `Provider '${provider.name}' does not support embedding modality`,
675
- "INVALID_REQUEST",
637
+ ErrorCode.InvalidRequest,
676
638
  provider.name,
677
- "embedding"
639
+ ModalityType.Embedding
678
640
  );
679
641
  }
680
642
  const boundModel = handler.bind(modelRef.modelId);
@@ -735,9 +697,9 @@ function decodeBase64(b64, providerName) {
735
697
  const cause = error instanceof Error ? error : new Error("Failed to decode base64 vector");
736
698
  throw new UPPError(
737
699
  "Invalid base64 embedding vector",
738
- "INVALID_RESPONSE",
700
+ ErrorCode.InvalidResponse,
739
701
  providerName,
740
- "embedding",
702
+ ModalityType.Embedding,
741
703
  void 0,
742
704
  cause
743
705
  );
@@ -766,9 +728,9 @@ function createChunkedStream(model, inputs, params, config, options) {
766
728
  });
767
729
  const cancelError = () => new UPPError(
768
730
  "Embedding cancelled",
769
- "CANCELLED",
731
+ ErrorCode.Cancelled,
770
732
  model.provider.name,
771
- "embedding"
733
+ ModalityType.Embedding
772
734
  );
773
735
  const onAbort = () => {
774
736
  rejectResult(cancelError());
@@ -875,9 +837,9 @@ function image(options) {
875
837
  if (!imageHandler) {
876
838
  throw new UPPError(
877
839
  `Provider '${provider.name}' does not support image modality`,
878
- "INVALID_REQUEST",
840
+ ErrorCode.InvalidRequest,
879
841
  provider.name,
880
- "image"
842
+ ModalityType.Image
881
843
  );
882
844
  }
883
845
  const boundModel = imageHandler.bind(modelRef.modelId);
@@ -887,7 +849,7 @@ function image(options) {
887
849
  return error;
888
850
  }
889
851
  const err = toError(error);
890
- return new UPPError(err.message, "PROVIDER_ERROR", provider.name, "image", void 0, err);
852
+ return new UPPError(err.message, ErrorCode.ProviderError, provider.name, ModalityType.Image, void 0, err);
891
853
  };
892
854
  const instance = {
893
855
  model: boundModel,
@@ -1240,14 +1202,20 @@ var ai = {
1240
1202
  };
1241
1203
  export {
1242
1204
  AssistantMessage,
1205
+ ContentBlockType,
1243
1206
  DynamicKey,
1207
+ ErrorCode,
1244
1208
  ExponentialBackoff,
1245
1209
  Image,
1210
+ ImageSourceType,
1246
1211
  LinearBackoff,
1247
1212
  Message,
1213
+ MessageRole,
1214
+ ModalityType,
1248
1215
  NoRetry,
1249
1216
  RetryAfterStrategy,
1250
1217
  RoundRobinKeys,
1218
+ StreamEventType,
1251
1219
  Thread,
1252
1220
  TokenBucket,
1253
1221
  ToolResultMessage,
@@ -1268,6 +1236,7 @@ export {
1268
1236
  isAudioBlock,
1269
1237
  isBinaryBlock,
1270
1238
  isImageBlock,
1239
+ isReasoningBlock,
1271
1240
  isTextBlock,
1272
1241
  isToolResultMessage,
1273
1242
  isUserMessage,
@@ -1275,6 +1244,7 @@ export {
1275
1244
  llm,
1276
1245
  messageStart,
1277
1246
  messageStop,
1247
+ reasoning,
1278
1248
  text,
1279
1249
  textDelta,
1280
1250
  toolCallDelta