@ai-sdk/openai 3.0.0-beta.108 → 3.0.0-beta.109

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
+ ## 3.0.0-beta.109
4
+
5
+ ### Patch Changes
6
+
7
+ - cbf52cd: feat: expose raw finish reason
8
+ - Updated dependencies [cbf52cd]
9
+ - @ai-sdk/provider@3.0.0-beta.30
10
+ - @ai-sdk/provider-utils@4.0.0-beta.57
11
+
3
12
  ## 3.0.0-beta.108
4
13
 
5
14
  ### Patch Changes
package/dist/index.js CHANGED
@@ -315,7 +315,7 @@ function mapOpenAIFinishReason(finishReason) {
315
315
  case "tool_calls":
316
316
  return "tool-calls";
317
317
  default:
318
- return "unknown";
318
+ return "other";
319
319
  }
320
320
  }
321
321
 
@@ -837,7 +837,7 @@ var OpenAIChatLanguageModel = class {
837
837
  };
838
838
  }
839
839
  async doGenerate(options) {
840
- var _a, _b, _c, _d, _e, _f;
840
+ var _a, _b, _c, _d, _e, _f, _g;
841
841
  const { args: body, warnings } = await this.getArgs(options);
842
842
  const {
843
843
  responseHeaders,
@@ -894,7 +894,10 @@ var OpenAIChatLanguageModel = class {
894
894
  }
895
895
  return {
896
896
  content,
897
- finishReason: mapOpenAIFinishReason(choice.finish_reason),
897
+ finishReason: {
898
+ unified: mapOpenAIFinishReason(choice.finish_reason),
899
+ raw: (_g = choice.finish_reason) != null ? _g : void 0
900
+ },
898
901
  usage: convertOpenAIChatUsage(response.usage),
899
902
  request: { body },
900
903
  response: {
@@ -930,7 +933,10 @@ var OpenAIChatLanguageModel = class {
930
933
  fetch: this.config.fetch
931
934
  });
932
935
  const toolCalls = [];
933
- let finishReason = "unknown";
936
+ let finishReason = {
937
+ unified: "other",
938
+ raw: void 0
939
+ };
934
940
  let usage = void 0;
935
941
  let metadataExtracted = false;
936
942
  let isActiveText = false;
@@ -947,13 +953,13 @@ var OpenAIChatLanguageModel = class {
947
953
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
948
954
  }
949
955
  if (!chunk.success) {
950
- finishReason = "error";
956
+ finishReason = { unified: "error", raw: void 0 };
951
957
  controller.enqueue({ type: "error", error: chunk.error });
952
958
  return;
953
959
  }
954
960
  const value = chunk.value;
955
961
  if ("error" in value) {
956
- finishReason = "error";
962
+ finishReason = { unified: "error", raw: void 0 };
957
963
  controller.enqueue({ type: "error", error: value.error });
958
964
  return;
959
965
  }
@@ -978,7 +984,10 @@ var OpenAIChatLanguageModel = class {
978
984
  }
979
985
  const choice = value.choices[0];
980
986
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
981
- finishReason = mapOpenAIFinishReason(choice.finish_reason);
987
+ finishReason = {
988
+ unified: mapOpenAIFinishReason(choice.finish_reason),
989
+ raw: choice.finish_reason
990
+ };
982
991
  }
983
992
  if (((_e = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _e.content) != null) {
984
993
  providerMetadata.openai.logprobs = choice.logprobs.content;
@@ -1258,7 +1267,7 @@ function mapOpenAIFinishReason2(finishReason) {
1258
1267
  case "tool_calls":
1259
1268
  return "tool-calls";
1260
1269
  default:
1261
- return "unknown";
1270
+ return "other";
1262
1271
  }
1263
1272
  }
1264
1273
 
@@ -1456,6 +1465,7 @@ var OpenAICompletionLanguageModel = class {
1456
1465
  };
1457
1466
  }
1458
1467
  async doGenerate(options) {
1468
+ var _a;
1459
1469
  const { args, warnings } = await this.getArgs(options);
1460
1470
  const {
1461
1471
  responseHeaders,
@@ -1483,7 +1493,10 @@ var OpenAICompletionLanguageModel = class {
1483
1493
  return {
1484
1494
  content: [{ type: "text", text: choice.text }],
1485
1495
  usage: convertOpenAICompletionUsage(response.usage),
1486
- finishReason: mapOpenAIFinishReason2(choice.finish_reason),
1496
+ finishReason: {
1497
+ unified: mapOpenAIFinishReason2(choice.finish_reason),
1498
+ raw: (_a = choice.finish_reason) != null ? _a : void 0
1499
+ },
1487
1500
  request: { body: args },
1488
1501
  response: {
1489
1502
  ...getResponseMetadata2(response),
@@ -1517,7 +1530,10 @@ var OpenAICompletionLanguageModel = class {
1517
1530
  abortSignal: options.abortSignal,
1518
1531
  fetch: this.config.fetch
1519
1532
  });
1520
- let finishReason = "unknown";
1533
+ let finishReason = {
1534
+ unified: "other",
1535
+ raw: void 0
1536
+ };
1521
1537
  const providerMetadata = { openai: {} };
1522
1538
  let usage = void 0;
1523
1539
  let isFirstChunk = true;
@@ -1532,13 +1548,13 @@ var OpenAICompletionLanguageModel = class {
1532
1548
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1533
1549
  }
1534
1550
  if (!chunk.success) {
1535
- finishReason = "error";
1551
+ finishReason = { unified: "error", raw: void 0 };
1536
1552
  controller.enqueue({ type: "error", error: chunk.error });
1537
1553
  return;
1538
1554
  }
1539
1555
  const value = chunk.value;
1540
1556
  if ("error" in value) {
1541
- finishReason = "error";
1557
+ finishReason = { unified: "error", raw: void 0 };
1542
1558
  controller.enqueue({ type: "error", error: value.error });
1543
1559
  return;
1544
1560
  }
@@ -1555,7 +1571,10 @@ var OpenAICompletionLanguageModel = class {
1555
1571
  }
1556
1572
  const choice = value.choices[0];
1557
1573
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
1558
- finishReason = mapOpenAIFinishReason2(choice.finish_reason);
1574
+ finishReason = {
1575
+ unified: mapOpenAIFinishReason2(choice.finish_reason),
1576
+ raw: choice.finish_reason
1577
+ };
1559
1578
  }
1560
1579
  if ((choice == null ? void 0 : choice.logprobs) != null) {
1561
1580
  providerMetadata.openai.logprobs = choice.logprobs;
@@ -2830,7 +2849,7 @@ function mapOpenAIResponseFinishReason({
2830
2849
  case "content_filter":
2831
2850
  return "content-filter";
2832
2851
  default:
2833
- return hasFunctionCall ? "tool-calls" : "unknown";
2852
+ return hasFunctionCall ? "tool-calls" : "other";
2834
2853
  }
2835
2854
  }
2836
2855
 
@@ -4146,7 +4165,7 @@ var OpenAIResponsesLanguageModel = class {
4146
4165
  };
4147
4166
  }
4148
4167
  async doGenerate(options) {
4149
- 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;
4168
+ 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;
4150
4169
  const {
4151
4170
  args: body,
4152
4171
  warnings,
@@ -4543,10 +4562,13 @@ var OpenAIResponsesLanguageModel = class {
4543
4562
  const usage = response.usage;
4544
4563
  return {
4545
4564
  content,
4546
- finishReason: mapOpenAIResponseFinishReason({
4547
- finishReason: (_x = response.incomplete_details) == null ? void 0 : _x.reason,
4548
- hasFunctionCall
4549
- }),
4565
+ finishReason: {
4566
+ unified: mapOpenAIResponseFinishReason({
4567
+ finishReason: (_x = response.incomplete_details) == null ? void 0 : _x.reason,
4568
+ hasFunctionCall
4569
+ }),
4570
+ raw: (_z = (_y = response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
4571
+ },
4550
4572
  usage: convertOpenAIResponsesUsage(usage),
4551
4573
  request: { body },
4552
4574
  response: {
@@ -4587,7 +4609,10 @@ var OpenAIResponsesLanguageModel = class {
4587
4609
  });
4588
4610
  const self = this;
4589
4611
  const providerKey = this.config.provider.replace(".responses", "");
4590
- let finishReason = "unknown";
4612
+ let finishReason = {
4613
+ unified: "other",
4614
+ raw: void 0
4615
+ };
4591
4616
  let usage = void 0;
4592
4617
  const logprobs = [];
4593
4618
  let responseId = null;
@@ -4603,12 +4628,12 @@ var OpenAIResponsesLanguageModel = class {
4603
4628
  controller.enqueue({ type: "stream-start", warnings });
4604
4629
  },
4605
4630
  transform(chunk, controller) {
4606
- 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;
4631
+ 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;
4607
4632
  if (options.includeRawChunks) {
4608
4633
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
4609
4634
  }
4610
4635
  if (!chunk.success) {
4611
- finishReason = "error";
4636
+ finishReason = { unified: "error", raw: void 0 };
4612
4637
  controller.enqueue({ type: "error", error: chunk.error });
4613
4638
  return;
4614
4639
  }
@@ -5107,10 +5132,13 @@ var OpenAIResponsesLanguageModel = class {
5107
5132
  activeReasoning[value.item_id].summaryParts[value.summary_index] = "can-conclude";
5108
5133
  }
5109
5134
  } else if (isResponseFinishedChunk(value)) {
5110
- finishReason = mapOpenAIResponseFinishReason({
5111
- finishReason: (_i = value.response.incomplete_details) == null ? void 0 : _i.reason,
5112
- hasFunctionCall
5113
- });
5135
+ finishReason = {
5136
+ unified: mapOpenAIResponseFinishReason({
5137
+ finishReason: (_i = value.response.incomplete_details) == null ? void 0 : _i.reason,
5138
+ hasFunctionCall
5139
+ }),
5140
+ raw: (_k = (_j = value.response.incomplete_details) == null ? void 0 : _j.reason) != null ? _k : void 0
5141
+ };
5114
5142
  usage = value.response.usage;
5115
5143
  if (typeof value.response.service_tier === "string") {
5116
5144
  serviceTier = value.response.service_tier;
@@ -5121,7 +5149,7 @@ var OpenAIResponsesLanguageModel = class {
5121
5149
  controller.enqueue({
5122
5150
  type: "source",
5123
5151
  sourceType: "url",
5124
- id: (_l = (_k = (_j = self.config).generateId) == null ? void 0 : _k.call(_j)) != null ? _l : (0, import_provider_utils27.generateId)(),
5152
+ id: (_n = (_m = (_l = self.config).generateId) == null ? void 0 : _m.call(_l)) != null ? _n : (0, import_provider_utils27.generateId)(),
5125
5153
  url: value.annotation.url,
5126
5154
  title: value.annotation.title
5127
5155
  });
@@ -5129,10 +5157,10 @@ var OpenAIResponsesLanguageModel = class {
5129
5157
  controller.enqueue({
5130
5158
  type: "source",
5131
5159
  sourceType: "document",
5132
- id: (_o = (_n = (_m = self.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : (0, import_provider_utils27.generateId)(),
5160
+ id: (_q = (_p = (_o = self.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : (0, import_provider_utils27.generateId)(),
5133
5161
  mediaType: "text/plain",
5134
- title: (_q = (_p = value.annotation.quote) != null ? _p : value.annotation.filename) != null ? _q : "Document",
5135
- filename: (_r = value.annotation.filename) != null ? _r : value.annotation.file_id,
5162
+ title: (_s = (_r = value.annotation.quote) != null ? _r : value.annotation.filename) != null ? _s : "Document",
5163
+ filename: (_t = value.annotation.filename) != null ? _t : value.annotation.file_id,
5136
5164
  ...value.annotation.file_id ? {
5137
5165
  providerMetadata: {
5138
5166
  [providerKey]: {
@@ -5145,10 +5173,10 @@ var OpenAIResponsesLanguageModel = class {
5145
5173
  controller.enqueue({
5146
5174
  type: "source",
5147
5175
  sourceType: "document",
5148
- id: (_u = (_t = (_s = self.config).generateId) == null ? void 0 : _t.call(_s)) != null ? _u : (0, import_provider_utils27.generateId)(),
5176
+ id: (_w = (_v = (_u = self.config).generateId) == null ? void 0 : _v.call(_u)) != null ? _w : (0, import_provider_utils27.generateId)(),
5149
5177
  mediaType: "text/plain",
5150
- title: (_w = (_v = value.annotation.filename) != null ? _v : value.annotation.file_id) != null ? _w : "Document",
5151
- filename: (_x = value.annotation.filename) != null ? _x : value.annotation.file_id,
5178
+ title: (_y = (_x = value.annotation.filename) != null ? _x : value.annotation.file_id) != null ? _y : "Document",
5179
+ filename: (_z = value.annotation.filename) != null ? _z : value.annotation.file_id,
5152
5180
  providerMetadata: {
5153
5181
  [providerKey]: {
5154
5182
  fileId: value.annotation.file_id,
@@ -5161,7 +5189,7 @@ var OpenAIResponsesLanguageModel = class {
5161
5189
  controller.enqueue({
5162
5190
  type: "source",
5163
5191
  sourceType: "document",
5164
- id: (_A = (_z = (_y = self.config).generateId) == null ? void 0 : _z.call(_y)) != null ? _A : (0, import_provider_utils27.generateId)(),
5192
+ id: (_C = (_B = (_A = self.config).generateId) == null ? void 0 : _B.call(_A)) != null ? _C : (0, import_provider_utils27.generateId)(),
5165
5193
  mediaType: "application/octet-stream",
5166
5194
  title: value.annotation.file_id,
5167
5195
  filename: value.annotation.file_id,
@@ -5611,7 +5639,7 @@ var OpenAITranscriptionModel = class {
5611
5639
  };
5612
5640
 
5613
5641
  // src/version.ts
5614
- var VERSION = true ? "3.0.0-beta.108" : "0.0.0-test";
5642
+ var VERSION = true ? "3.0.0-beta.109" : "0.0.0-test";
5615
5643
 
5616
5644
  // src/openai-provider.ts
5617
5645
  function createOpenAI(options = {}) {