@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/dist/index.mjs CHANGED
@@ -39,6 +39,15 @@ var openaiFailedResponseHandler = createJsonErrorResponseHandler({
39
39
  errorToMessage: (data) => data.error.message
40
40
  });
41
41
 
42
+ // src/openai-is-reasoning-model.ts
43
+ function isReasoningModel(modelId) {
44
+ if (modelId.startsWith("gpt-3")) return false;
45
+ if (modelId.startsWith("gpt-4")) return false;
46
+ if (modelId.startsWith("chatgpt-4o")) return false;
47
+ if (modelId.startsWith("gpt-5-chat")) return false;
48
+ return true;
49
+ }
50
+
42
51
  // src/chat/convert-to-openai-chat-messages.ts
43
52
  import {
44
53
  UnsupportedFunctionalityError
@@ -1044,9 +1053,6 @@ var OpenAIChatLanguageModel = class {
1044
1053
  };
1045
1054
  }
1046
1055
  };
1047
- function isReasoningModel(modelId) {
1048
- return (modelId.startsWith("o") || modelId.startsWith("gpt-5")) && !modelId.startsWith("gpt-5-chat");
1049
- }
1050
1056
  function supportsFlexProcessing(modelId) {
1051
1057
  return modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
1052
1058
  }
@@ -1054,32 +1060,8 @@ function supportsPriorityProcessing(modelId) {
1054
1060
  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");
1055
1061
  }
1056
1062
  function getSystemMessageMode(modelId) {
1057
- var _a, _b;
1058
- if (!isReasoningModel(modelId)) {
1059
- return "system";
1060
- }
1061
- return (_b = (_a = reasoningModels[modelId]) == null ? void 0 : _a.systemMessageMode) != null ? _b : "developer";
1063
+ return isReasoningModel(modelId) ? "developer" : "system";
1062
1064
  }
1063
- var reasoningModels = {
1064
- o3: {
1065
- systemMessageMode: "developer"
1066
- },
1067
- "o3-2025-04-16": {
1068
- systemMessageMode: "developer"
1069
- },
1070
- "o3-mini": {
1071
- systemMessageMode: "developer"
1072
- },
1073
- "o3-mini-2025-01-31": {
1074
- systemMessageMode: "developer"
1075
- },
1076
- "o4-mini": {
1077
- systemMessageMode: "developer"
1078
- },
1079
- "o4-mini-2025-04-16": {
1080
- systemMessageMode: "developer"
1081
- }
1082
- };
1083
1065
 
1084
1066
  // src/completion/openai-completion-language-model.ts
1085
1067
  import {
@@ -2691,6 +2673,20 @@ var openaiResponsesChunkSchema = lazySchema14(
2691
2673
  start_index: z16.number().nullish(),
2692
2674
  end_index: z16.number().nullish(),
2693
2675
  quote: z16.string().nullish()
2676
+ }),
2677
+ z16.object({
2678
+ type: z16.literal("container_file_citation"),
2679
+ container_id: z16.string(),
2680
+ file_id: z16.string(),
2681
+ filename: z16.string().nullish(),
2682
+ start_index: z16.number().nullish(),
2683
+ end_index: z16.number().nullish(),
2684
+ index: z16.number().nullish()
2685
+ }),
2686
+ z16.object({
2687
+ type: z16.literal("file_path"),
2688
+ file_id: z16.string(),
2689
+ index: z16.number().nullish()
2694
2690
  })
2695
2691
  ])
2696
2692
  }),
@@ -2776,7 +2772,18 @@ var openaiResponsesResponseSchema = lazySchema14(
2776
2772
  quote: z16.string().nullish()
2777
2773
  }),
2778
2774
  z16.object({
2779
- type: z16.literal("container_file_citation")
2775
+ type: z16.literal("container_file_citation"),
2776
+ container_id: z16.string(),
2777
+ file_id: z16.string(),
2778
+ filename: z16.string().nullish(),
2779
+ start_index: z16.number().nullish(),
2780
+ end_index: z16.number().nullish(),
2781
+ index: z16.number().nullish()
2782
+ }),
2783
+ z16.object({
2784
+ type: z16.literal("file_path"),
2785
+ file_id: z16.string(),
2786
+ index: z16.number().nullish()
2780
2787
  })
2781
2788
  ])
2782
2789
  )
@@ -3360,7 +3367,7 @@ var OpenAIResponsesLanguageModel = class {
3360
3367
  };
3361
3368
  }
3362
3369
  async doGenerate(options) {
3363
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
3370
+ 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;
3364
3371
  const {
3365
3372
  args: body,
3366
3373
  warnings,
@@ -3458,13 +3465,17 @@ var OpenAIResponsesLanguageModel = class {
3458
3465
  if (((_c = (_b = options.providerOptions) == null ? void 0 : _b.openai) == null ? void 0 : _c.logprobs) && contentPart.logprobs) {
3459
3466
  logprobs.push(contentPart.logprobs);
3460
3467
  }
3468
+ const providerMetadata2 = {
3469
+ itemId: part.id,
3470
+ ...contentPart.annotations.length > 0 && {
3471
+ annotations: contentPart.annotations
3472
+ }
3473
+ };
3461
3474
  content.push({
3462
3475
  type: "text",
3463
3476
  text: contentPart.text,
3464
3477
  providerMetadata: {
3465
- openai: {
3466
- itemId: part.id
3467
- }
3478
+ openai: providerMetadata2
3468
3479
  }
3469
3480
  });
3470
3481
  for (const annotation of contentPart.annotations) {
@@ -3492,6 +3503,37 @@ var OpenAIResponsesLanguageModel = class {
3492
3503
  }
3493
3504
  } : {}
3494
3505
  });
3506
+ } else if (annotation.type === "container_file_citation") {
3507
+ content.push({
3508
+ type: "source",
3509
+ sourceType: "document",
3510
+ id: (_o = (_n = (_m = this.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : generateId2(),
3511
+ mediaType: "text/plain",
3512
+ title: (_q = (_p = annotation.filename) != null ? _p : annotation.file_id) != null ? _q : "Document",
3513
+ filename: (_r = annotation.filename) != null ? _r : annotation.file_id,
3514
+ providerMetadata: {
3515
+ openai: {
3516
+ fileId: annotation.file_id,
3517
+ containerId: annotation.container_id,
3518
+ ...annotation.index != null ? { index: annotation.index } : {}
3519
+ }
3520
+ }
3521
+ });
3522
+ } else if (annotation.type === "file_path") {
3523
+ content.push({
3524
+ type: "source",
3525
+ sourceType: "document",
3526
+ id: (_u = (_t = (_s = this.config).generateId) == null ? void 0 : _t.call(_s)) != null ? _u : generateId2(),
3527
+ mediaType: "application/octet-stream",
3528
+ title: annotation.file_id,
3529
+ filename: annotation.file_id,
3530
+ providerMetadata: {
3531
+ openai: {
3532
+ fileId: annotation.file_id,
3533
+ ...annotation.index != null ? { index: annotation.index } : {}
3534
+ }
3535
+ }
3536
+ });
3495
3537
  }
3496
3538
  }
3497
3539
  }
@@ -3561,13 +3603,13 @@ var OpenAIResponsesLanguageModel = class {
3561
3603
  toolName: "file_search",
3562
3604
  result: {
3563
3605
  queries: part.queries,
3564
- results: (_n = (_m = part.results) == null ? void 0 : _m.map((result) => ({
3606
+ results: (_w = (_v = part.results) == null ? void 0 : _v.map((result) => ({
3565
3607
  attributes: result.attributes,
3566
3608
  fileId: result.file_id,
3567
3609
  filename: result.filename,
3568
3610
  score: result.score,
3569
3611
  text: result.text
3570
- }))) != null ? _n : null
3612
+ }))) != null ? _w : null
3571
3613
  }
3572
3614
  });
3573
3615
  break;
@@ -3607,15 +3649,15 @@ var OpenAIResponsesLanguageModel = class {
3607
3649
  return {
3608
3650
  content,
3609
3651
  finishReason: mapOpenAIResponseFinishReason({
3610
- finishReason: (_o = response.incomplete_details) == null ? void 0 : _o.reason,
3652
+ finishReason: (_x = response.incomplete_details) == null ? void 0 : _x.reason,
3611
3653
  hasFunctionCall
3612
3654
  }),
3613
3655
  usage: {
3614
3656
  inputTokens: response.usage.input_tokens,
3615
3657
  outputTokens: response.usage.output_tokens,
3616
3658
  totalTokens: response.usage.input_tokens + response.usage.output_tokens,
3617
- reasoningTokens: (_q = (_p = response.usage.output_tokens_details) == null ? void 0 : _p.reasoning_tokens) != null ? _q : void 0,
3618
- cachedInputTokens: (_s = (_r = response.usage.input_tokens_details) == null ? void 0 : _r.cached_tokens) != null ? _s : void 0
3659
+ reasoningTokens: (_z = (_y = response.usage.output_tokens_details) == null ? void 0 : _y.reasoning_tokens) != null ? _z : void 0,
3660
+ cachedInputTokens: (_B = (_A = response.usage.input_tokens_details) == null ? void 0 : _A.cached_tokens) != null ? _B : void 0
3619
3661
  },
3620
3662
  request: { body },
3621
3663
  response: {
@@ -3673,7 +3715,7 @@ var OpenAIResponsesLanguageModel = class {
3673
3715
  controller.enqueue({ type: "stream-start", warnings });
3674
3716
  },
3675
3717
  transform(chunk, controller) {
3676
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
3718
+ 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;
3677
3719
  if (options.includeRawChunks) {
3678
3720
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
3679
3721
  }
@@ -4078,6 +4120,37 @@ var OpenAIResponsesLanguageModel = class {
4078
4120
  }
4079
4121
  } : {}
4080
4122
  });
4123
+ } else if (value.annotation.type === "container_file_citation") {
4124
+ controller.enqueue({
4125
+ type: "source",
4126
+ sourceType: "document",
4127
+ id: (_y = (_x = (_w = self.config).generateId) == null ? void 0 : _x.call(_w)) != null ? _y : generateId2(),
4128
+ mediaType: "text/plain",
4129
+ title: (_A = (_z = value.annotation.filename) != null ? _z : value.annotation.file_id) != null ? _A : "Document",
4130
+ filename: (_B = value.annotation.filename) != null ? _B : value.annotation.file_id,
4131
+ providerMetadata: {
4132
+ openai: {
4133
+ fileId: value.annotation.file_id,
4134
+ containerId: value.annotation.container_id,
4135
+ ...value.annotation.index != null ? { index: value.annotation.index } : {}
4136
+ }
4137
+ }
4138
+ });
4139
+ } else if (value.annotation.type === "file_path") {
4140
+ controller.enqueue({
4141
+ type: "source",
4142
+ sourceType: "document",
4143
+ id: (_E = (_D = (_C = self.config).generateId) == null ? void 0 : _D.call(_C)) != null ? _E : generateId2(),
4144
+ mediaType: "application/octet-stream",
4145
+ title: value.annotation.file_id,
4146
+ filename: value.annotation.file_id,
4147
+ providerMetadata: {
4148
+ openai: {
4149
+ fileId: value.annotation.file_id,
4150
+ ...value.annotation.index != null ? { index: value.annotation.index } : {}
4151
+ }
4152
+ }
4153
+ });
4081
4154
  }
4082
4155
  } else if (isErrorChunk(value)) {
4083
4156
  controller.enqueue({ type: "error", error: value });
@@ -4145,27 +4218,13 @@ function isErrorChunk(chunk) {
4145
4218
  function getResponsesModelConfig(modelId) {
4146
4219
  const supportsFlexProcessing2 = modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
4147
4220
  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");
4148
- const defaults = {
4149
- systemMessageMode: "system",
4150
- supportsFlexProcessing: supportsFlexProcessing2,
4151
- supportsPriorityProcessing: supportsPriorityProcessing2
4152
- };
4153
- if (modelId.startsWith("gpt-5-chat")) {
4154
- return {
4155
- ...defaults,
4156
- isReasoningModel: false
4157
- };
4158
- }
4159
- if (modelId.startsWith("o") || modelId.startsWith("gpt-5") || modelId.startsWith("codex-") || modelId.startsWith("computer-use")) {
4160
- return {
4161
- ...defaults,
4162
- isReasoningModel: true,
4163
- systemMessageMode: "developer"
4164
- };
4165
- }
4221
+ const isReasoningModel2 = isReasoningModel(modelId);
4222
+ const systemMessageMode = isReasoningModel2 ? "developer" : "system";
4166
4223
  return {
4167
- ...defaults,
4168
- isReasoningModel: false
4224
+ systemMessageMode,
4225
+ supportsFlexProcessing: supportsFlexProcessing2,
4226
+ supportsPriorityProcessing: supportsPriorityProcessing2,
4227
+ isReasoningModel: isReasoningModel2
4169
4228
  };
4170
4229
  }
4171
4230
  function mapWebSearchOutput(action) {
@@ -4551,7 +4610,7 @@ var OpenAITranscriptionModel = class {
4551
4610
  };
4552
4611
 
4553
4612
  // src/version.ts
4554
- var VERSION = true ? "3.0.0-beta.50" : "0.0.0-test";
4613
+ var VERSION = true ? "3.0.0-beta.52" : "0.0.0-test";
4555
4614
 
4556
4615
  // src/openai-provider.ts
4557
4616
  function createOpenAI(options = {}) {