@ai-sdk/openai 4.0.63 → 4.0.64

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,14 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 4.0.64
4
+
5
+ ### Patch Changes
6
+
7
+ - ccb8952: fix(openai): return an AI SDK error for empty chat completion choices
8
+ - Updated dependencies [912fb01]
9
+ - @ai-sdk/provider@4.0.12
10
+ - @ai-sdk/provider-utils@5.0.38
11
+
3
12
  ## 4.0.63
4
13
 
5
14
  ### Patch Changes
package/dist/index.js CHANGED
@@ -8,6 +8,9 @@ import {
8
8
  } from "@ai-sdk/provider-utils";
9
9
 
10
10
  // src/chat/openai-chat-language-model.ts
11
+ import {
12
+ InvalidResponseDataError
13
+ } from "@ai-sdk/provider";
11
14
  import {
12
15
  StreamingToolCallTracker,
13
16
  combineHeaders,
@@ -1224,6 +1227,12 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1224
1227
  fetch: this.config.fetch
1225
1228
  });
1226
1229
  const choice = response.choices[0];
1230
+ if (choice == null) {
1231
+ throw new InvalidResponseDataError({
1232
+ data: rawResponse,
1233
+ message: "Response did not contain any choices."
1234
+ });
1235
+ }
1227
1236
  const content = [];
1228
1237
  const text = choice.message.content;
1229
1238
  if (text != null && text.length > 0) {
@@ -3553,7 +3562,7 @@ var openaiTools = {
3553
3562
  // src/openai-batch.ts
3554
3563
  import {
3555
3564
  InvalidArgumentError as InvalidArgumentError2,
3556
- InvalidResponseDataError
3565
+ InvalidResponseDataError as InvalidResponseDataError2
3557
3566
  } from "@ai-sdk/provider";
3558
3567
  import {
3559
3568
  combineHeaders as combineHeaders7,
@@ -9277,7 +9286,7 @@ var OpenAIBatch = class {
9277
9286
  (fileId) => fileId != null
9278
9287
  );
9279
9288
  if (batchStatus.status === "completed" && fileIds.length === 0) {
9280
- throw new InvalidResponseDataError({
9289
+ throw new InvalidResponseDataError2({
9281
9290
  data: batch,
9282
9291
  message: `OpenAI batch "${options.batchId}" completed without batch output.`
9283
9292
  });
@@ -11208,7 +11217,7 @@ var OpenAISkills = class {
11208
11217
  };
11209
11218
 
11210
11219
  // src/version.ts
11211
- var VERSION = true ? "4.0.63" : "0.0.0-test";
11220
+ var VERSION = true ? "4.0.64" : "0.0.0-test";
11212
11221
 
11213
11222
  // src/openai-provider.ts
11214
11223
  function createOpenAI(options = {}) {