@ai-sdk/openai 4.0.0-canary.45 → 4.0.0-canary.47

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,20 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 4.0.0-canary.47
4
+
5
+ ### Patch Changes
6
+
7
+ - 5463d0d: feat(provider): align tool result output content file part types with top-level message file part types
8
+ - Updated dependencies [5463d0d]
9
+ - @ai-sdk/provider-utils@5.0.0-canary.32
10
+ - @ai-sdk/provider@4.0.0-canary.16
11
+
12
+ ## 4.0.0-canary.46
13
+
14
+ ### Patch Changes
15
+
16
+ - cd9c311: fix(openai, openai-compatible): only send null content for assistant messages with tool calls
17
+
3
18
  ## 4.0.0-canary.45
4
19
 
5
20
  ### Patch Changes
package/dist/index.js CHANGED
@@ -271,7 +271,7 @@ function convertToOpenAIChatMessages({
271
271
  }
272
272
  messages.push({
273
273
  role: "assistant",
274
- content: text || null,
274
+ content: toolCalls.length > 0 ? text || null : text,
275
275
  tool_calls: toolCalls.length > 0 ? toolCalls : void 0
276
276
  });
277
277
  break;
@@ -3471,29 +3471,42 @@ async function convertToOpenAIResponsesInput({
3471
3471
  switch (item.type) {
3472
3472
  case "text":
3473
3473
  return { type: "input_text", text: item.text };
3474
- case "file-data":
3475
- if (item.mediaType.startsWith("image/")) {
3474
+ case "file": {
3475
+ const topLevel = getTopLevelMediaType2(item.mediaType);
3476
+ if (item.data.type === "data") {
3477
+ const fullMediaType = resolveFullMediaType2({
3478
+ part: item
3479
+ });
3480
+ if (topLevel === "image") {
3481
+ return {
3482
+ type: "input_image",
3483
+ image_url: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`
3484
+ };
3485
+ }
3476
3486
  return {
3477
- type: "input_image",
3478
- image_url: `data:${item.mediaType};base64,${item.data}`
3487
+ type: "input_file",
3488
+ filename: (_a2 = item.filename) != null ? _a2 : "data",
3489
+ file_data: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`
3479
3490
  };
3480
3491
  }
3481
- return {
3482
- type: "input_file",
3483
- filename: (_a2 = item.filename) != null ? _a2 : "data",
3484
- file_data: `data:${item.mediaType};base64,${item.data}`
3485
- };
3486
- case "file-url":
3487
- if (item.mediaType.startsWith("image/")) {
3492
+ if (item.data.type === "url") {
3493
+ if (topLevel === "image") {
3494
+ return {
3495
+ type: "input_image",
3496
+ image_url: item.data.url.toString()
3497
+ };
3498
+ }
3488
3499
  return {
3489
- type: "input_image",
3490
- image_url: item.url
3500
+ type: "input_file",
3501
+ file_url: item.data.url.toString()
3491
3502
  };
3492
3503
  }
3493
- return {
3494
- type: "input_file",
3495
- file_url: item.url
3496
- };
3504
+ warnings.push({
3505
+ type: "other",
3506
+ message: `unsupported custom tool content part type: ${item.type} with data type: ${item.data.type}`
3507
+ });
3508
+ return void 0;
3509
+ }
3497
3510
  default:
3498
3511
  warnings.push({
3499
3512
  type: "other",
@@ -3533,30 +3546,41 @@ async function convertToOpenAIResponsesInput({
3533
3546
  case "text": {
3534
3547
  return { type: "input_text", text: item.text };
3535
3548
  }
3536
- case "file-data": {
3537
- if (item.mediaType.startsWith("image/")) {
3549
+ case "file": {
3550
+ const topLevel = getTopLevelMediaType2(item.mediaType);
3551
+ if (item.data.type === "data") {
3552
+ const fullMediaType = resolveFullMediaType2({
3553
+ part: item
3554
+ });
3555
+ if (topLevel === "image") {
3556
+ return {
3557
+ type: "input_image",
3558
+ image_url: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`
3559
+ };
3560
+ }
3538
3561
  return {
3539
- type: "input_image",
3540
- image_url: `data:${item.mediaType};base64,${item.data}`
3562
+ type: "input_file",
3563
+ filename: (_a2 = item.filename) != null ? _a2 : "data",
3564
+ file_data: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`
3541
3565
  };
3542
3566
  }
3543
- return {
3544
- type: "input_file",
3545
- filename: (_a2 = item.filename) != null ? _a2 : "data",
3546
- file_data: `data:${item.mediaType};base64,${item.data}`
3547
- };
3548
- }
3549
- case "file-url": {
3550
- if (item.mediaType.startsWith("image/")) {
3567
+ if (item.data.type === "url") {
3568
+ if (topLevel === "image") {
3569
+ return {
3570
+ type: "input_image",
3571
+ image_url: item.data.url.toString()
3572
+ };
3573
+ }
3551
3574
  return {
3552
- type: "input_image",
3553
- image_url: item.url
3575
+ type: "input_file",
3576
+ file_url: item.data.url.toString()
3554
3577
  };
3555
3578
  }
3556
- return {
3557
- type: "input_file",
3558
- file_url: item.url
3559
- };
3579
+ warnings.push({
3580
+ type: "other",
3581
+ message: `unsupported tool content part type: ${item.type} with data type: ${item.data.type}`
3582
+ });
3583
+ return void 0;
3560
3584
  }
3561
3585
  default: {
3562
3586
  warnings.push({
@@ -7227,7 +7251,7 @@ var OpenAISkills = class {
7227
7251
  };
7228
7252
 
7229
7253
  // src/version.ts
7230
- var VERSION = true ? "4.0.0-canary.45" : "0.0.0-test";
7254
+ var VERSION = true ? "4.0.0-canary.47" : "0.0.0-test";
7231
7255
 
7232
7256
  // src/openai-provider.ts
7233
7257
  function createOpenAI(options = {}) {