@ai-sdk/openai-compatible 2.0.68 → 2.0.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @ai-sdk/openai-compatible
2
2
 
3
+ ## 2.0.70
4
+
5
+ ### Patch Changes
6
+
7
+ - c79dd10: fix(openai-compatible): report truncated chat streams as errors
8
+
9
+ ## 2.0.69
10
+
11
+ ### Patch Changes
12
+
13
+ - 7440d89: fix(openai-compatible): preserve unmapped usage fields in `usage.raw`
14
+
15
+ `usage.raw` is specified as usage "in the shape that the provider returns",
16
+ and the chat model already parsed the usage object loosely so that extra
17
+ top-level fields survived. The nested `prompt_tokens_details` and
18
+ `completion_tokens_details` objects were still strict, so anything a provider
19
+ reported inside them was dropped — which is where providers put their most
20
+ distinguishing detail. The existing "should preserve extra usage fields"
21
+ fixture was itself losing `audio_tokens`, `image_tokens` and `text_tokens`
22
+ this way.
23
+
24
+ Both nested objects are now parsed loosely, as is the completion model's usage
25
+ schema, which was strict throughout despite feeding the same `raw` field.
26
+
27
+ Only `usage.raw` changes. The mapped token counts are unaffected.
28
+
3
29
  ## 2.0.68
4
30
 
5
31
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -123,12 +123,12 @@ declare const openaiCompatibleTokenUsageSchema: z.ZodOptional<z.ZodNullable<z.Zo
123
123
  total_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
124
124
  prompt_tokens_details: z.ZodOptional<z.ZodNullable<z.ZodObject<{
125
125
  cached_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
126
- }, z.core.$strip>>>;
126
+ }, z.core.$loose>>>;
127
127
  completion_tokens_details: z.ZodOptional<z.ZodNullable<z.ZodObject<{
128
128
  reasoning_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
129
129
  accepted_prediction_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
130
130
  rejected_prediction_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
131
- }, z.core.$strip>>>;
131
+ }, z.core.$loose>>>;
132
132
  }, z.core.$loose>>>;
133
133
 
134
134
  type OpenAICompatibleCompletionModelId = string;
package/dist/index.d.ts CHANGED
@@ -123,12 +123,12 @@ declare const openaiCompatibleTokenUsageSchema: z.ZodOptional<z.ZodNullable<z.Zo
123
123
  total_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
124
124
  prompt_tokens_details: z.ZodOptional<z.ZodNullable<z.ZodObject<{
125
125
  cached_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
126
- }, z.core.$strip>>>;
126
+ }, z.core.$loose>>>;
127
127
  completion_tokens_details: z.ZodOptional<z.ZodNullable<z.ZodObject<{
128
128
  reasoning_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
129
129
  accepted_prediction_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
130
130
  rejected_prediction_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
131
- }, z.core.$strip>>>;
131
+ }, z.core.$loose>>>;
132
132
  }, z.core.$loose>>>;
133
133
 
134
134
  type OpenAICompatibleCompletionModelId = string;
package/dist/index.js CHANGED
@@ -671,10 +671,7 @@ var OpenAICompatibleChatLanguageModel = class {
671
671
  });
672
672
  const toolCalls = [];
673
673
  const pendingToolCalls = /* @__PURE__ */ new Map();
674
- let finishReason = {
675
- unified: "other",
676
- raw: void 0
677
- };
674
+ let finishReason;
678
675
  let usage = void 0;
679
676
  let isFirstChunk = true;
680
677
  const providerOptionsName = metadataKey;
@@ -914,6 +911,16 @@ var OpenAICompatibleChatLanguageModel = class {
914
911
  } : {}
915
912
  });
916
913
  }
914
+ if (finishReason == null) {
915
+ finishReason = { unified: "error", raw: void 0 };
916
+ controller.enqueue({
917
+ type: "error",
918
+ error: new import_provider3.InvalidResponseDataError({
919
+ data: void 0,
920
+ message: "Response stream ended without a finish reason."
921
+ })
922
+ });
923
+ }
917
924
  const providerMetadata = {
918
925
  [providerOptionsName]: {},
919
926
  ...metadataExtractor == null ? void 0 : metadataExtractor.buildMetadata()
@@ -942,10 +949,10 @@ var openaiCompatibleTokenUsageSchema = import_v43.z.looseObject({
942
949
  prompt_tokens: import_v43.z.number().nullish(),
943
950
  completion_tokens: import_v43.z.number().nullish(),
944
951
  total_tokens: import_v43.z.number().nullish(),
945
- prompt_tokens_details: import_v43.z.object({
952
+ prompt_tokens_details: import_v43.z.looseObject({
946
953
  cached_tokens: import_v43.z.number().nullish()
947
954
  }).nullish(),
948
- completion_tokens_details: import_v43.z.object({
955
+ completion_tokens_details: import_v43.z.looseObject({
949
956
  reasoning_tokens: import_v43.z.number().nullish(),
950
957
  accepted_prediction_tokens: import_v43.z.number().nullish(),
951
958
  rejected_prediction_tokens: import_v43.z.number().nullish()
@@ -1426,7 +1433,7 @@ var OpenAICompatibleCompletionLanguageModel = class {
1426
1433
  };
1427
1434
  }
1428
1435
  };
1429
- var usageSchema = import_v45.z.object({
1436
+ var usageSchema = import_v45.z.looseObject({
1430
1437
  prompt_tokens: import_v45.z.number(),
1431
1438
  completion_tokens: import_v45.z.number(),
1432
1439
  total_tokens: import_v45.z.number()
@@ -1718,7 +1725,7 @@ async function fileToBlob(file) {
1718
1725
  var import_provider_utils6 = require("@ai-sdk/provider-utils");
1719
1726
 
1720
1727
  // src/version.ts
1721
- var VERSION = true ? "2.0.68" : "0.0.0-test";
1728
+ var VERSION = true ? "2.0.70" : "0.0.0-test";
1722
1729
 
1723
1730
  // src/openai-compatible-provider.ts
1724
1731
  function createOpenAICompatible(options) {