@ai-sdk/openai 3.0.0-beta.50 → 3.0.0-beta.52

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,17 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 3.0.0-beta.52
4
+
5
+ ### Patch Changes
6
+
7
+ - 348fd10: fix(openai): treat unknown models as reasoning
8
+
9
+ ## 3.0.0-beta.51
10
+
11
+ ### Patch Changes
12
+
13
+ - b82987c: feat(openai): support openai code-interpreter annotations
14
+
3
15
  ## 3.0.0-beta.50
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -52,6 +52,15 @@ var openaiFailedResponseHandler = (0, import_provider_utils.createJsonErrorRespo
52
52
  errorToMessage: (data) => data.error.message
53
53
  });
54
54
 
55
+ // src/openai-is-reasoning-model.ts
56
+ function isReasoningModel(modelId) {
57
+ if (modelId.startsWith("gpt-3")) return false;
58
+ if (modelId.startsWith("gpt-4")) return false;
59
+ if (modelId.startsWith("chatgpt-4o")) return false;
60
+ if (modelId.startsWith("gpt-5-chat")) return false;
61
+ return true;
62
+ }
63
+
55
64
  // src/chat/convert-to-openai-chat-messages.ts
56
65
  var import_provider = require("@ai-sdk/provider");
57
66
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
@@ -1053,9 +1062,6 @@ var OpenAIChatLanguageModel = class {
1053
1062
  };
1054
1063
  }
1055
1064
  };
1056
- function isReasoningModel(modelId) {
1057
- return (modelId.startsWith("o") || modelId.startsWith("gpt-5")) && !modelId.startsWith("gpt-5-chat");
1058
- }
1059
1065
  function supportsFlexProcessing(modelId) {
1060
1066
  return modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
1061
1067
  }
@@ -1063,32 +1069,8 @@ function supportsPriorityProcessing(modelId) {
1063
1069
  return modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
1064
1070
  }
1065
1071
  function getSystemMessageMode(modelId) {
1066
- var _a, _b;
1067
- if (!isReasoningModel(modelId)) {
1068
- return "system";
1069
- }
1070
- return (_b = (_a = reasoningModels[modelId]) == null ? void 0 : _a.systemMessageMode) != null ? _b : "developer";
1072
+ return isReasoningModel(modelId) ? "developer" : "system";
1071
1073
  }
1072
- var reasoningModels = {
1073
- o3: {
1074
- systemMessageMode: "developer"
1075
- },
1076
- "o3-2025-04-16": {
1077
- systemMessageMode: "developer"
1078
- },
1079
- "o3-mini": {
1080
- systemMessageMode: "developer"
1081
- },
1082
- "o3-mini-2025-01-31": {
1083
- systemMessageMode: "developer"
1084
- },
1085
- "o4-mini": {
1086
- systemMessageMode: "developer"
1087
- },
1088
- "o4-mini-2025-04-16": {
1089
- systemMessageMode: "developer"
1090
- }
1091
- };
1092
1074
 
1093
1075
  // src/completion/openai-completion-language-model.ts
1094
1076
  var import_provider_utils8 = require("@ai-sdk/provider-utils");
@@ -2640,6 +2622,20 @@ var openaiResponsesChunkSchema = (0, import_provider_utils21.lazySchema)(
2640
2622
  start_index: import_v416.z.number().nullish(),
2641
2623
  end_index: import_v416.z.number().nullish(),
2642
2624
  quote: import_v416.z.string().nullish()
2625
+ }),
2626
+ import_v416.z.object({
2627
+ type: import_v416.z.literal("container_file_citation"),
2628
+ container_id: import_v416.z.string(),
2629
+ file_id: import_v416.z.string(),
2630
+ filename: import_v416.z.string().nullish(),
2631
+ start_index: import_v416.z.number().nullish(),
2632
+ end_index: import_v416.z.number().nullish(),
2633
+ index: import_v416.z.number().nullish()
2634
+ }),
2635
+ import_v416.z.object({
2636
+ type: import_v416.z.literal("file_path"),
2637
+ file_id: import_v416.z.string(),
2638
+ index: import_v416.z.number().nullish()
2643
2639
  })
2644
2640
  ])
2645
2641
  }),
@@ -2725,7 +2721,18 @@ var openaiResponsesResponseSchema = (0, import_provider_utils21.lazySchema)(
2725
2721
  quote: import_v416.z.string().nullish()
2726
2722
  }),
2727
2723
  import_v416.z.object({
2728
- type: import_v416.z.literal("container_file_citation")
2724
+ type: import_v416.z.literal("container_file_citation"),
2725
+ container_id: import_v416.z.string(),
2726
+ file_id: import_v416.z.string(),
2727
+ filename: import_v416.z.string().nullish(),
2728
+ start_index: import_v416.z.number().nullish(),
2729
+ end_index: import_v416.z.number().nullish(),
2730
+ index: import_v416.z.number().nullish()
2731
+ }),
2732
+ import_v416.z.object({
2733
+ type: import_v416.z.literal("file_path"),
2734
+ file_id: import_v416.z.string(),
2735
+ index: import_v416.z.number().nullish()
2729
2736
  })
2730
2737
  ])
2731
2738
  )
@@ -3307,7 +3314,7 @@ var OpenAIResponsesLanguageModel = class {
3307
3314
  };
3308
3315
  }
3309
3316
  async doGenerate(options) {
3310
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
3317
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B;
3311
3318
  const {
3312
3319
  args: body,
3313
3320
  warnings,
@@ -3405,13 +3412,17 @@ var OpenAIResponsesLanguageModel = class {
3405
3412
  if (((_c = (_b = options.providerOptions) == null ? void 0 : _b.openai) == null ? void 0 : _c.logprobs) && contentPart.logprobs) {
3406
3413
  logprobs.push(contentPart.logprobs);
3407
3414
  }
3415
+ const providerMetadata2 = {
3416
+ itemId: part.id,
3417
+ ...contentPart.annotations.length > 0 && {
3418
+ annotations: contentPart.annotations
3419
+ }
3420
+ };
3408
3421
  content.push({
3409
3422
  type: "text",
3410
3423
  text: contentPart.text,
3411
3424
  providerMetadata: {
3412
- openai: {
3413
- itemId: part.id
3414
- }
3425
+ openai: providerMetadata2
3415
3426
  }
3416
3427
  });
3417
3428
  for (const annotation of contentPart.annotations) {
@@ -3439,6 +3450,37 @@ var OpenAIResponsesLanguageModel = class {
3439
3450
  }
3440
3451
  } : {}
3441
3452
  });
3453
+ } else if (annotation.type === "container_file_citation") {
3454
+ content.push({
3455
+ type: "source",
3456
+ sourceType: "document",
3457
+ id: (_o = (_n = (_m = this.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : (0, import_provider_utils24.generateId)(),
3458
+ mediaType: "text/plain",
3459
+ title: (_q = (_p = annotation.filename) != null ? _p : annotation.file_id) != null ? _q : "Document",
3460
+ filename: (_r = annotation.filename) != null ? _r : annotation.file_id,
3461
+ providerMetadata: {
3462
+ openai: {
3463
+ fileId: annotation.file_id,
3464
+ containerId: annotation.container_id,
3465
+ ...annotation.index != null ? { index: annotation.index } : {}
3466
+ }
3467
+ }
3468
+ });
3469
+ } else if (annotation.type === "file_path") {
3470
+ content.push({
3471
+ type: "source",
3472
+ sourceType: "document",
3473
+ id: (_u = (_t = (_s = this.config).generateId) == null ? void 0 : _t.call(_s)) != null ? _u : (0, import_provider_utils24.generateId)(),
3474
+ mediaType: "application/octet-stream",
3475
+ title: annotation.file_id,
3476
+ filename: annotation.file_id,
3477
+ providerMetadata: {
3478
+ openai: {
3479
+ fileId: annotation.file_id,
3480
+ ...annotation.index != null ? { index: annotation.index } : {}
3481
+ }
3482
+ }
3483
+ });
3442
3484
  }
3443
3485
  }
3444
3486
  }
@@ -3508,13 +3550,13 @@ var OpenAIResponsesLanguageModel = class {
3508
3550
  toolName: "file_search",
3509
3551
  result: {
3510
3552
  queries: part.queries,
3511
- results: (_n = (_m = part.results) == null ? void 0 : _m.map((result) => ({
3553
+ results: (_w = (_v = part.results) == null ? void 0 : _v.map((result) => ({
3512
3554
  attributes: result.attributes,
3513
3555
  fileId: result.file_id,
3514
3556
  filename: result.filename,
3515
3557
  score: result.score,
3516
3558
  text: result.text
3517
- }))) != null ? _n : null
3559
+ }))) != null ? _w : null
3518
3560
  }
3519
3561
  });
3520
3562
  break;
@@ -3554,15 +3596,15 @@ var OpenAIResponsesLanguageModel = class {
3554
3596
  return {
3555
3597
  content,
3556
3598
  finishReason: mapOpenAIResponseFinishReason({
3557
- finishReason: (_o = response.incomplete_details) == null ? void 0 : _o.reason,
3599
+ finishReason: (_x = response.incomplete_details) == null ? void 0 : _x.reason,
3558
3600
  hasFunctionCall
3559
3601
  }),
3560
3602
  usage: {
3561
3603
  inputTokens: response.usage.input_tokens,
3562
3604
  outputTokens: response.usage.output_tokens,
3563
3605
  totalTokens: response.usage.input_tokens + response.usage.output_tokens,
3564
- reasoningTokens: (_q = (_p = response.usage.output_tokens_details) == null ? void 0 : _p.reasoning_tokens) != null ? _q : void 0,
3565
- cachedInputTokens: (_s = (_r = response.usage.input_tokens_details) == null ? void 0 : _r.cached_tokens) != null ? _s : void 0
3606
+ reasoningTokens: (_z = (_y = response.usage.output_tokens_details) == null ? void 0 : _y.reasoning_tokens) != null ? _z : void 0,
3607
+ cachedInputTokens: (_B = (_A = response.usage.input_tokens_details) == null ? void 0 : _A.cached_tokens) != null ? _B : void 0
3566
3608
  },
3567
3609
  request: { body },
3568
3610
  response: {
@@ -3620,7 +3662,7 @@ var OpenAIResponsesLanguageModel = class {
3620
3662
  controller.enqueue({ type: "stream-start", warnings });
3621
3663
  },
3622
3664
  transform(chunk, controller) {
3623
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
3665
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E;
3624
3666
  if (options.includeRawChunks) {
3625
3667
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
3626
3668
  }
@@ -4025,6 +4067,37 @@ var OpenAIResponsesLanguageModel = class {
4025
4067
  }
4026
4068
  } : {}
4027
4069
  });
4070
+ } else if (value.annotation.type === "container_file_citation") {
4071
+ controller.enqueue({
4072
+ type: "source",
4073
+ sourceType: "document",
4074
+ id: (_y = (_x = (_w = self.config).generateId) == null ? void 0 : _x.call(_w)) != null ? _y : (0, import_provider_utils24.generateId)(),
4075
+ mediaType: "text/plain",
4076
+ title: (_A = (_z = value.annotation.filename) != null ? _z : value.annotation.file_id) != null ? _A : "Document",
4077
+ filename: (_B = value.annotation.filename) != null ? _B : value.annotation.file_id,
4078
+ providerMetadata: {
4079
+ openai: {
4080
+ fileId: value.annotation.file_id,
4081
+ containerId: value.annotation.container_id,
4082
+ ...value.annotation.index != null ? { index: value.annotation.index } : {}
4083
+ }
4084
+ }
4085
+ });
4086
+ } else if (value.annotation.type === "file_path") {
4087
+ controller.enqueue({
4088
+ type: "source",
4089
+ sourceType: "document",
4090
+ id: (_E = (_D = (_C = self.config).generateId) == null ? void 0 : _D.call(_C)) != null ? _E : (0, import_provider_utils24.generateId)(),
4091
+ mediaType: "application/octet-stream",
4092
+ title: value.annotation.file_id,
4093
+ filename: value.annotation.file_id,
4094
+ providerMetadata: {
4095
+ openai: {
4096
+ fileId: value.annotation.file_id,
4097
+ ...value.annotation.index != null ? { index: value.annotation.index } : {}
4098
+ }
4099
+ }
4100
+ });
4028
4101
  }
4029
4102
  } else if (isErrorChunk(value)) {
4030
4103
  controller.enqueue({ type: "error", error: value });
@@ -4092,27 +4165,13 @@ function isErrorChunk(chunk) {
4092
4165
  function getResponsesModelConfig(modelId) {
4093
4166
  const supportsFlexProcessing2 = modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
4094
4167
  const supportsPriorityProcessing2 = modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
4095
- const defaults = {
4096
- systemMessageMode: "system",
4097
- supportsFlexProcessing: supportsFlexProcessing2,
4098
- supportsPriorityProcessing: supportsPriorityProcessing2
4099
- };
4100
- if (modelId.startsWith("gpt-5-chat")) {
4101
- return {
4102
- ...defaults,
4103
- isReasoningModel: false
4104
- };
4105
- }
4106
- if (modelId.startsWith("o") || modelId.startsWith("gpt-5") || modelId.startsWith("codex-") || modelId.startsWith("computer-use")) {
4107
- return {
4108
- ...defaults,
4109
- isReasoningModel: true,
4110
- systemMessageMode: "developer"
4111
- };
4112
- }
4168
+ const isReasoningModel2 = isReasoningModel(modelId);
4169
+ const systemMessageMode = isReasoningModel2 ? "developer" : "system";
4113
4170
  return {
4114
- ...defaults,
4115
- isReasoningModel: false
4171
+ systemMessageMode,
4172
+ supportsFlexProcessing: supportsFlexProcessing2,
4173
+ supportsPriorityProcessing: supportsPriorityProcessing2,
4174
+ isReasoningModel: isReasoningModel2
4116
4175
  };
4117
4176
  }
4118
4177
  function mapWebSearchOutput(action) {
@@ -4486,7 +4545,7 @@ var OpenAITranscriptionModel = class {
4486
4545
  };
4487
4546
 
4488
4547
  // src/version.ts
4489
- var VERSION = true ? "3.0.0-beta.50" : "0.0.0-test";
4548
+ var VERSION = true ? "3.0.0-beta.52" : "0.0.0-test";
4490
4549
 
4491
4550
  // src/openai-provider.ts
4492
4551
  function createOpenAI(options = {}) {