@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 +26 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +15 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -8
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +2 -2
- package/dist/internal/index.d.ts +2 -2
- package/package.json +1 -1
- package/src/chat/openai-compatible-chat-language-model.ts +15 -6
- package/src/completion/openai-compatible-completion-language-model.ts +2 -1
package/dist/internal/index.d.ts
CHANGED
|
@@ -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.$
|
|
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.$
|
|
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
|
@@ -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
|
-
.
|
|
804
|
+
.looseObject({
|
|
796
805
|
cached_tokens: z.number().nullish(),
|
|
797
806
|
})
|
|
798
807
|
.nullish(),
|
|
799
808
|
completion_tokens_details: z
|
|
800
|
-
.
|
|
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
|
-
|
|
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(),
|