@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.
@@ -200,12 +200,12 @@ declare const openaiCompatibleTokenUsageSchema: z.ZodOptional<z.ZodNullable<z.Zo
200
200
  total_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
201
201
  prompt_tokens_details: z.ZodOptional<z.ZodNullable<z.ZodObject<{
202
202
  cached_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
203
- }, z.core.$strip>>>;
203
+ }, z.core.$loose>>>;
204
204
  completion_tokens_details: z.ZodOptional<z.ZodNullable<z.ZodObject<{
205
205
  reasoning_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
206
206
  accepted_prediction_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
207
207
  rejected_prediction_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
208
- }, z.core.$strip>>>;
208
+ }, z.core.$loose>>>;
209
209
  }, z.core.$loose>>>;
210
210
 
211
211
  export { type OpenAICompatibleChatConfig, convertOpenAICompatibleChatUsage, convertToOpenAICompatibleChatMessages, getResponseMetadata, mapOpenAICompatibleFinishReason, prepareTools };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/openai-compatible",
3
- "version": "2.0.68",
3
+ "version": "2.0.70",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -430,10 +430,7 @@ export class OpenAICompatibleChatLanguageModel implements LanguageModelV3 {
430
430
  }
431
431
  >();
432
432
 
433
- let finishReason: LanguageModelV3FinishReason = {
434
- unified: 'other',
435
- raw: undefined,
436
- };
433
+ let finishReason: LanguageModelV3FinishReason | undefined;
437
434
  let usage: z.infer<typeof openaiCompatibleTokenUsageSchema> | undefined =
438
435
  undefined;
439
436
  let isFirstChunk = true;
@@ -752,6 +749,17 @@ export class OpenAICompatibleChatLanguageModel implements LanguageModelV3 {
752
749
  });
753
750
  }
754
751
 
752
+ if (finishReason == null) {
753
+ finishReason = { unified: 'error', raw: undefined };
754
+ controller.enqueue({
755
+ type: 'error',
756
+ error: new InvalidResponseDataError({
757
+ data: undefined,
758
+ message: 'Response stream ended without a finish reason.',
759
+ }),
760
+ });
761
+ }
762
+
755
763
  const providerMetadata: SharedV3ProviderMetadata = {
756
764
  [providerOptionsName]: {},
757
765
  ...metadataExtractor?.buildMetadata(),
@@ -786,18 +794,19 @@ export class OpenAICompatibleChatLanguageModel implements LanguageModelV3 {
786
794
  }
787
795
  }
788
796
 
797
+ // Loose, nested objects included: the parsed value is returned as `usage.raw`.
789
798
  const openaiCompatibleTokenUsageSchema = z
790
799
  .looseObject({
791
800
  prompt_tokens: z.number().nullish(),
792
801
  completion_tokens: z.number().nullish(),
793
802
  total_tokens: z.number().nullish(),
794
803
  prompt_tokens_details: z
795
- .object({
804
+ .looseObject({
796
805
  cached_tokens: z.number().nullish(),
797
806
  })
798
807
  .nullish(),
799
808
  completion_tokens_details: z
800
- .object({
809
+ .looseObject({
801
810
  reasoning_tokens: z.number().nullish(),
802
811
  accepted_prediction_tokens: z.number().nullish(),
803
812
  rejected_prediction_tokens: z.number().nullish(),
@@ -350,7 +350,8 @@ export class OpenAICompatibleCompletionLanguageModel implements LanguageModelV3
350
350
  }
351
351
  }
352
352
 
353
- const usageSchema = z.object({
353
+ // Loose: the parsed value is returned as `usage.raw`.
354
+ const usageSchema = z.looseObject({
354
355
  prompt_tokens: z.number(),
355
356
  completion_tokens: z.number(),
356
357
  total_tokens: z.number(),