@ai-sdk/openai 4.0.0-beta.30 → 4.0.0-beta.31

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.js CHANGED
@@ -18,7 +18,10 @@ import {
18
18
  isCustomReasoning,
19
19
  isParsableJson,
20
20
  parseProviderOptions,
21
- postJsonToApi
21
+ postJsonToApi,
22
+ serializeModelOptions,
23
+ WORKFLOW_DESERIALIZE,
24
+ WORKFLOW_SERIALIZE
22
25
  } from "@ai-sdk/provider-utils";
23
26
 
24
27
  // src/openai-error.ts
@@ -652,7 +655,7 @@ function prepareChatTools({
652
655
  }
653
656
 
654
657
  // src/chat/openai-chat-language-model.ts
655
- var OpenAIChatLanguageModel = class {
658
+ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
656
659
  constructor(modelId, config) {
657
660
  this.specificationVersion = "v4";
658
661
  this.supportedUrls = {
@@ -661,6 +664,15 @@ var OpenAIChatLanguageModel = class {
661
664
  this.modelId = modelId;
662
665
  this.config = config;
663
666
  }
667
+ static [WORKFLOW_SERIALIZE](model) {
668
+ return serializeModelOptions({
669
+ modelId: model.modelId,
670
+ config: model.config
671
+ });
672
+ }
673
+ static [WORKFLOW_DESERIALIZE](options) {
674
+ return new _OpenAIChatLanguageModel(options.modelId, options.config);
675
+ }
664
676
  get provider() {
665
677
  return this.config.provider;
666
678
  }
@@ -848,7 +860,7 @@ var OpenAIChatLanguageModel = class {
848
860
  };
849
861
  }
850
862
  async doGenerate(options) {
851
- var _a, _b, _c, _d, _e, _f;
863
+ var _a, _b, _c, _d, _e, _f, _g, _h;
852
864
  const { args: body, warnings } = await this.getArgs(options);
853
865
  const {
854
866
  responseHeaders,
@@ -859,7 +871,7 @@ var OpenAIChatLanguageModel = class {
859
871
  path: "/chat/completions",
860
872
  modelId: this.modelId
861
873
  }),
862
- headers: combineHeaders(this.config.headers(), options.headers),
874
+ headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
863
875
  body,
864
876
  failedResponseHandler: openaiFailedResponseHandler,
865
877
  successfulResponseHandler: createJsonResponseHandler(
@@ -874,15 +886,15 @@ var OpenAIChatLanguageModel = class {
874
886
  if (text != null && text.length > 0) {
875
887
  content.push({ type: "text", text });
876
888
  }
877
- for (const toolCall of (_a = choice.message.tool_calls) != null ? _a : []) {
889
+ for (const toolCall of (_c = choice.message.tool_calls) != null ? _c : []) {
878
890
  content.push({
879
891
  type: "tool-call",
880
- toolCallId: (_b = toolCall.id) != null ? _b : generateId(),
892
+ toolCallId: (_d = toolCall.id) != null ? _d : generateId(),
881
893
  toolName: toolCall.function.name,
882
894
  input: toolCall.function.arguments
883
895
  });
884
896
  }
885
- for (const annotation of (_c = choice.message.annotations) != null ? _c : []) {
897
+ for (const annotation of (_e = choice.message.annotations) != null ? _e : []) {
886
898
  content.push({
887
899
  type: "source",
888
900
  sourceType: "url",
@@ -891,7 +903,7 @@ var OpenAIChatLanguageModel = class {
891
903
  title: annotation.url_citation.title
892
904
  });
893
905
  }
894
- const completionTokenDetails = (_d = response.usage) == null ? void 0 : _d.completion_tokens_details;
906
+ const completionTokenDetails = (_f = response.usage) == null ? void 0 : _f.completion_tokens_details;
895
907
  const providerMetadata = { openai: {} };
896
908
  if ((completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens) != null) {
897
909
  providerMetadata.openai.acceptedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens;
@@ -899,14 +911,14 @@ var OpenAIChatLanguageModel = class {
899
911
  if ((completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens) != null) {
900
912
  providerMetadata.openai.rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
901
913
  }
902
- if (((_e = choice.logprobs) == null ? void 0 : _e.content) != null) {
914
+ if (((_g = choice.logprobs) == null ? void 0 : _g.content) != null) {
903
915
  providerMetadata.openai.logprobs = choice.logprobs.content;
904
916
  }
905
917
  return {
906
918
  content,
907
919
  finishReason: {
908
920
  unified: mapOpenAIFinishReason(choice.finish_reason),
909
- raw: (_f = choice.finish_reason) != null ? _f : void 0
921
+ raw: (_h = choice.finish_reason) != null ? _h : void 0
910
922
  },
911
923
  usage: convertOpenAIChatUsage(response.usage),
912
924
  request: { body },
@@ -920,6 +932,7 @@ var OpenAIChatLanguageModel = class {
920
932
  };
921
933
  }
922
934
  async doStream(options) {
935
+ var _a, _b;
923
936
  const { args, warnings } = await this.getArgs(options);
924
937
  const body = {
925
938
  ...args,
@@ -933,7 +946,7 @@ var OpenAIChatLanguageModel = class {
933
946
  path: "/chat/completions",
934
947
  modelId: this.modelId
935
948
  }),
936
- headers: combineHeaders(this.config.headers(), options.headers),
949
+ headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
937
950
  body,
938
951
  failedResponseHandler: openaiFailedResponseHandler,
939
952
  successfulResponseHandler: createEventSourceResponseHandler(
@@ -958,7 +971,7 @@ var OpenAIChatLanguageModel = class {
958
971
  controller.enqueue({ type: "stream-start", warnings });
959
972
  },
960
973
  transform(chunk, controller) {
961
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
974
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
962
975
  if (options.includeRawChunks) {
963
976
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
964
977
  }
@@ -985,8 +998,8 @@ var OpenAIChatLanguageModel = class {
985
998
  }
986
999
  if (value.usage != null) {
987
1000
  usage = value.usage;
988
- if (((_a = value.usage.completion_tokens_details) == null ? void 0 : _a.accepted_prediction_tokens) != null) {
989
- providerMetadata.openai.acceptedPredictionTokens = (_b = value.usage.completion_tokens_details) == null ? void 0 : _b.accepted_prediction_tokens;
1001
+ if (((_a2 = value.usage.completion_tokens_details) == null ? void 0 : _a2.accepted_prediction_tokens) != null) {
1002
+ providerMetadata.openai.acceptedPredictionTokens = (_b2 = value.usage.completion_tokens_details) == null ? void 0 : _b2.accepted_prediction_tokens;
990
1003
  }
991
1004
  if (((_c = value.usage.completion_tokens_details) == null ? void 0 : _c.rejected_prediction_tokens) != null) {
992
1005
  providerMetadata.openai.rejectedPredictionTokens = (_d = value.usage.completion_tokens_details) == null ? void 0 : _d.rejected_prediction_tokens;
@@ -1142,7 +1155,10 @@ import {
1142
1155
  createEventSourceResponseHandler as createEventSourceResponseHandler2,
1143
1156
  createJsonResponseHandler as createJsonResponseHandler2,
1144
1157
  parseProviderOptions as parseProviderOptions2,
1145
- postJsonToApi as postJsonToApi2
1158
+ postJsonToApi as postJsonToApi2,
1159
+ serializeModelOptions as serializeModelOptions2,
1160
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2,
1161
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2
1146
1162
  } from "@ai-sdk/provider-utils";
1147
1163
 
1148
1164
  // src/completion/convert-openai-completion-usage.ts
@@ -1397,7 +1413,7 @@ var openaiLanguageModelCompletionOptions = lazySchema4(
1397
1413
  );
1398
1414
 
1399
1415
  // src/completion/openai-completion-language-model.ts
1400
- var OpenAICompletionLanguageModel = class {
1416
+ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
1401
1417
  constructor(modelId, config) {
1402
1418
  this.specificationVersion = "v4";
1403
1419
  this.supportedUrls = {
@@ -1409,6 +1425,15 @@ var OpenAICompletionLanguageModel = class {
1409
1425
  get providerOptionsName() {
1410
1426
  return this.config.provider.split(".")[0].trim();
1411
1427
  }
1428
+ static [WORKFLOW_SERIALIZE2](model) {
1429
+ return serializeModelOptions2({
1430
+ modelId: model.modelId,
1431
+ config: model.config
1432
+ });
1433
+ }
1434
+ static [WORKFLOW_DESERIALIZE2](options) {
1435
+ return new _OpenAICompletionLanguageModel(options.modelId, options.config);
1436
+ }
1412
1437
  get provider() {
1413
1438
  return this.config.provider;
1414
1439
  }
@@ -1484,7 +1509,7 @@ var OpenAICompletionLanguageModel = class {
1484
1509
  };
1485
1510
  }
1486
1511
  async doGenerate(options) {
1487
- var _a;
1512
+ var _a, _b, _c;
1488
1513
  const { args, warnings } = await this.getArgs(options);
1489
1514
  const {
1490
1515
  responseHeaders,
@@ -1495,7 +1520,7 @@ var OpenAICompletionLanguageModel = class {
1495
1520
  path: "/completions",
1496
1521
  modelId: this.modelId
1497
1522
  }),
1498
- headers: combineHeaders2(this.config.headers(), options.headers),
1523
+ headers: combineHeaders2((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
1499
1524
  body: args,
1500
1525
  failedResponseHandler: openaiFailedResponseHandler,
1501
1526
  successfulResponseHandler: createJsonResponseHandler2(
@@ -1514,7 +1539,7 @@ var OpenAICompletionLanguageModel = class {
1514
1539
  usage: convertOpenAICompletionUsage(response.usage),
1515
1540
  finishReason: {
1516
1541
  unified: mapOpenAIFinishReason2(choice.finish_reason),
1517
- raw: (_a = choice.finish_reason) != null ? _a : void 0
1542
+ raw: (_c = choice.finish_reason) != null ? _c : void 0
1518
1543
  },
1519
1544
  request: { body: args },
1520
1545
  response: {
@@ -1527,6 +1552,7 @@ var OpenAICompletionLanguageModel = class {
1527
1552
  };
1528
1553
  }
1529
1554
  async doStream(options) {
1555
+ var _a, _b;
1530
1556
  const { args, warnings } = await this.getArgs(options);
1531
1557
  const body = {
1532
1558
  ...args,
@@ -1540,7 +1566,7 @@ var OpenAICompletionLanguageModel = class {
1540
1566
  path: "/completions",
1541
1567
  modelId: this.modelId
1542
1568
  }),
1543
- headers: combineHeaders2(this.config.headers(), options.headers),
1569
+ headers: combineHeaders2((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
1544
1570
  body,
1545
1571
  failedResponseHandler: openaiFailedResponseHandler,
1546
1572
  successfulResponseHandler: createEventSourceResponseHandler2(
@@ -1633,7 +1659,10 @@ import {
1633
1659
  combineHeaders as combineHeaders3,
1634
1660
  createJsonResponseHandler as createJsonResponseHandler3,
1635
1661
  parseProviderOptions as parseProviderOptions3,
1636
- postJsonToApi as postJsonToApi3
1662
+ postJsonToApi as postJsonToApi3,
1663
+ serializeModelOptions as serializeModelOptions3,
1664
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3,
1665
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3
1637
1666
  } from "@ai-sdk/provider-utils";
1638
1667
 
1639
1668
  // src/embedding/openai-embedding-options.ts
@@ -1669,7 +1698,7 @@ var openaiTextEmbeddingResponseSchema = lazySchema6(
1669
1698
  );
1670
1699
 
1671
1700
  // src/embedding/openai-embedding-model.ts
1672
- var OpenAIEmbeddingModel = class {
1701
+ var OpenAIEmbeddingModel = class _OpenAIEmbeddingModel {
1673
1702
  constructor(modelId, config) {
1674
1703
  this.specificationVersion = "v4";
1675
1704
  this.maxEmbeddingsPerCall = 2048;
@@ -1677,6 +1706,15 @@ var OpenAIEmbeddingModel = class {
1677
1706
  this.modelId = modelId;
1678
1707
  this.config = config;
1679
1708
  }
1709
+ static [WORKFLOW_SERIALIZE3](model) {
1710
+ return serializeModelOptions3({
1711
+ modelId: model.modelId,
1712
+ config: model.config
1713
+ });
1714
+ }
1715
+ static [WORKFLOW_DESERIALIZE3](options) {
1716
+ return new _OpenAIEmbeddingModel(options.modelId, options.config);
1717
+ }
1680
1718
  get provider() {
1681
1719
  return this.config.provider;
1682
1720
  }
@@ -1686,7 +1724,7 @@ var OpenAIEmbeddingModel = class {
1686
1724
  abortSignal,
1687
1725
  providerOptions
1688
1726
  }) {
1689
- var _a;
1727
+ var _a, _b, _c;
1690
1728
  if (values.length > this.maxEmbeddingsPerCall) {
1691
1729
  throw new TooManyEmbeddingValuesForCallError({
1692
1730
  provider: this.provider,
@@ -1709,7 +1747,7 @@ var OpenAIEmbeddingModel = class {
1709
1747
  path: "/embeddings",
1710
1748
  modelId: this.modelId
1711
1749
  }),
1712
- headers: combineHeaders3(this.config.headers(), headers),
1750
+ headers: combineHeaders3((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), headers),
1713
1751
  body: {
1714
1752
  model: this.modelId,
1715
1753
  input: values,
@@ -1849,7 +1887,10 @@ import {
1849
1887
  createJsonResponseHandler as createJsonResponseHandler5,
1850
1888
  downloadBlob,
1851
1889
  postFormDataToApi as postFormDataToApi2,
1852
- postJsonToApi as postJsonToApi4
1890
+ postJsonToApi as postJsonToApi4,
1891
+ serializeModelOptions as serializeModelOptions4,
1892
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE4,
1893
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE4
1853
1894
  } from "@ai-sdk/provider-utils";
1854
1895
 
1855
1896
  // src/image/openai-image-api.ts
@@ -1904,12 +1945,21 @@ function hasDefaultResponseFormat(modelId) {
1904
1945
  }
1905
1946
 
1906
1947
  // src/image/openai-image-model.ts
1907
- var OpenAIImageModel = class {
1948
+ var OpenAIImageModel = class _OpenAIImageModel {
1908
1949
  constructor(modelId, config) {
1909
1950
  this.modelId = modelId;
1910
1951
  this.config = config;
1911
1952
  this.specificationVersion = "v4";
1912
1953
  }
1954
+ static [WORKFLOW_SERIALIZE4](model) {
1955
+ return serializeModelOptions4({
1956
+ modelId: model.modelId,
1957
+ config: model.config
1958
+ });
1959
+ }
1960
+ static [WORKFLOW_DESERIALIZE4](options) {
1961
+ return new _OpenAIImageModel(options.modelId, options.config);
1962
+ }
1913
1963
  get maxImagesPerCall() {
1914
1964
  var _a;
1915
1965
  return (_a = modelMaxImagesPerCall[this.modelId]) != null ? _a : 1;
@@ -1929,7 +1979,7 @@ var OpenAIImageModel = class {
1929
1979
  headers,
1930
1980
  abortSignal
1931
1981
  }) {
1932
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1982
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1933
1983
  const warnings = [];
1934
1984
  if (aspectRatio != null) {
1935
1985
  warnings.push({
@@ -1948,7 +1998,7 @@ var OpenAIImageModel = class {
1948
1998
  path: "/images/edits",
1949
1999
  modelId: this.modelId
1950
2000
  }),
1951
- headers: combineHeaders5(this.config.headers(), headers),
2001
+ headers: combineHeaders5((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), headers),
1952
2002
  formData: convertToFormData({
1953
2003
  model: this.modelId,
1954
2004
  prompt,
@@ -1969,7 +2019,7 @@ var OpenAIImageModel = class {
1969
2019
  mask: mask != null ? await fileToBlob(mask) : void 0,
1970
2020
  n,
1971
2021
  size,
1972
- ...(_d = providerOptions.openai) != null ? _d : {}
2022
+ ...(_f = providerOptions.openai) != null ? _f : {}
1973
2023
  }),
1974
2024
  failedResponseHandler: openaiFailedResponseHandler,
1975
2025
  successfulResponseHandler: createJsonResponseHandler5(
@@ -1982,9 +2032,9 @@ var OpenAIImageModel = class {
1982
2032
  images: response2.data.map((item) => item.b64_json),
1983
2033
  warnings,
1984
2034
  usage: response2.usage != null ? {
1985
- inputTokens: (_e = response2.usage.input_tokens) != null ? _e : void 0,
1986
- outputTokens: (_f = response2.usage.output_tokens) != null ? _f : void 0,
1987
- totalTokens: (_g = response2.usage.total_tokens) != null ? _g : void 0
2035
+ inputTokens: (_g = response2.usage.input_tokens) != null ? _g : void 0,
2036
+ outputTokens: (_h = response2.usage.output_tokens) != null ? _h : void 0,
2037
+ totalTokens: (_i = response2.usage.total_tokens) != null ? _i : void 0
1988
2038
  } : void 0,
1989
2039
  response: {
1990
2040
  timestamp: currentDate,
@@ -2018,13 +2068,13 @@ var OpenAIImageModel = class {
2018
2068
  path: "/images/generations",
2019
2069
  modelId: this.modelId
2020
2070
  }),
2021
- headers: combineHeaders5(this.config.headers(), headers),
2071
+ headers: combineHeaders5((_k = (_j = this.config).headers) == null ? void 0 : _k.call(_j), headers),
2022
2072
  body: {
2023
2073
  model: this.modelId,
2024
2074
  prompt,
2025
2075
  n,
2026
2076
  size,
2027
- ...(_h = providerOptions.openai) != null ? _h : {},
2077
+ ...(_l = providerOptions.openai) != null ? _l : {},
2028
2078
  ...!hasDefaultResponseFormat(this.modelId) ? { response_format: "b64_json" } : {}
2029
2079
  },
2030
2080
  failedResponseHandler: openaiFailedResponseHandler,
@@ -2038,9 +2088,9 @@ var OpenAIImageModel = class {
2038
2088
  images: response.data.map((item) => item.b64_json),
2039
2089
  warnings,
2040
2090
  usage: response.usage != null ? {
2041
- inputTokens: (_i = response.usage.input_tokens) != null ? _i : void 0,
2042
- outputTokens: (_j = response.usage.output_tokens) != null ? _j : void 0,
2043
- totalTokens: (_k = response.usage.total_tokens) != null ? _k : void 0
2091
+ inputTokens: (_m = response.usage.input_tokens) != null ? _m : void 0,
2092
+ outputTokens: (_n = response.usage.output_tokens) != null ? _n : void 0,
2093
+ totalTokens: (_o = response.usage.total_tokens) != null ? _o : void 0
2044
2094
  } : void 0,
2045
2095
  response: {
2046
2096
  timestamp: currentDate,
@@ -2787,7 +2837,10 @@ import {
2787
2837
  generateId as generateId2,
2788
2838
  isCustomReasoning as isCustomReasoning2,
2789
2839
  parseProviderOptions as parseProviderOptions6,
2790
- postJsonToApi as postJsonToApi5
2840
+ postJsonToApi as postJsonToApi5,
2841
+ serializeModelOptions as serializeModelOptions5,
2842
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE5,
2843
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE5
2791
2844
  } from "@ai-sdk/provider-utils";
2792
2845
 
2793
2846
  // src/responses/convert-openai-responses-usage.ts
@@ -3359,23 +3412,25 @@ async function convertToOpenAIResponsesInput({
3359
3412
  switch (item.type) {
3360
3413
  case "text":
3361
3414
  return { type: "input_text", text: item.text };
3362
- case "image-data":
3363
- return {
3364
- type: "input_image",
3365
- image_url: `data:${item.mediaType};base64,${item.data}`
3366
- };
3367
- case "image-url":
3368
- return {
3369
- type: "input_image",
3370
- image_url: item.url
3371
- };
3372
3415
  case "file-data":
3416
+ if (item.mediaType.startsWith("image/")) {
3417
+ return {
3418
+ type: "input_image",
3419
+ image_url: `data:${item.mediaType};base64,${item.data}`
3420
+ };
3421
+ }
3373
3422
  return {
3374
3423
  type: "input_file",
3375
3424
  filename: (_a2 = item.filename) != null ? _a2 : "data",
3376
3425
  file_data: `data:${item.mediaType};base64,${item.data}`
3377
3426
  };
3378
3427
  case "file-url":
3428
+ if (item.mediaType.startsWith("image/")) {
3429
+ return {
3430
+ type: "input_image",
3431
+ image_url: item.url
3432
+ };
3433
+ }
3379
3434
  return {
3380
3435
  type: "input_file",
3381
3436
  file_url: item.url
@@ -3419,19 +3474,13 @@ async function convertToOpenAIResponsesInput({
3419
3474
  case "text": {
3420
3475
  return { type: "input_text", text: item.text };
3421
3476
  }
3422
- case "image-data": {
3423
- return {
3424
- type: "input_image",
3425
- image_url: `data:${item.mediaType};base64,${item.data}`
3426
- };
3427
- }
3428
- case "image-url": {
3429
- return {
3430
- type: "input_image",
3431
- image_url: item.url
3432
- };
3433
- }
3434
3477
  case "file-data": {
3478
+ if (item.mediaType.startsWith("image/")) {
3479
+ return {
3480
+ type: "input_image",
3481
+ image_url: `data:${item.mediaType};base64,${item.data}`
3482
+ };
3483
+ }
3435
3484
  return {
3436
3485
  type: "input_file",
3437
3486
  filename: (_a2 = item.filename) != null ? _a2 : "data",
@@ -3439,6 +3488,12 @@ async function convertToOpenAIResponsesInput({
3439
3488
  };
3440
3489
  }
3441
3490
  case "file-url": {
3491
+ if (item.mediaType.startsWith("image/")) {
3492
+ return {
3493
+ type: "input_image",
3494
+ image_url: item.url
3495
+ };
3496
+ }
3442
3497
  return {
3443
3498
  type: "input_file",
3444
3499
  file_url: item.url
@@ -4895,7 +4950,7 @@ function extractApprovalRequestIdToToolCallIdMapping(prompt) {
4895
4950
  }
4896
4951
  return mapping;
4897
4952
  }
4898
- var OpenAIResponsesLanguageModel = class {
4953
+ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
4899
4954
  constructor(modelId, config) {
4900
4955
  this.specificationVersion = "v4";
4901
4956
  this.supportedUrls = {
@@ -4905,6 +4960,15 @@ var OpenAIResponsesLanguageModel = class {
4905
4960
  this.modelId = modelId;
4906
4961
  this.config = config;
4907
4962
  }
4963
+ static [WORKFLOW_SERIALIZE5](model) {
4964
+ return serializeModelOptions5({
4965
+ modelId: model.modelId,
4966
+ config: model.config
4967
+ });
4968
+ }
4969
+ static [WORKFLOW_DESERIALIZE5](options) {
4970
+ return new _OpenAIResponsesLanguageModel(options.modelId, options.config);
4971
+ }
4908
4972
  get provider() {
4909
4973
  return this.config.provider;
4910
4974
  }
@@ -5160,7 +5224,7 @@ var OpenAIResponsesLanguageModel = class {
5160
5224
  };
5161
5225
  }
5162
5226
  async doGenerate(options) {
5163
- 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;
5227
+ 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;
5164
5228
  const {
5165
5229
  args: body,
5166
5230
  warnings,
@@ -5180,7 +5244,7 @@ var OpenAIResponsesLanguageModel = class {
5180
5244
  rawValue: rawResponse
5181
5245
  } = await postJsonToApi5({
5182
5246
  url,
5183
- headers: combineHeaders6(this.config.headers(), options.headers),
5247
+ headers: combineHeaders6((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
5184
5248
  body,
5185
5249
  failedResponseHandler: openaiFailedResponseHandler,
5186
5250
  successfulResponseHandler: createJsonResponseHandler6(
@@ -5217,7 +5281,7 @@ var OpenAIResponsesLanguageModel = class {
5217
5281
  providerMetadata: {
5218
5282
  [providerOptionsName]: {
5219
5283
  itemId: part.id,
5220
- reasoningEncryptedContent: (_a = part.encrypted_content) != null ? _a : null
5284
+ reasoningEncryptedContent: (_c = part.encrypted_content) != null ? _c : null
5221
5285
  }
5222
5286
  }
5223
5287
  });
@@ -5243,7 +5307,7 @@ var OpenAIResponsesLanguageModel = class {
5243
5307
  break;
5244
5308
  }
5245
5309
  case "tool_search_call": {
5246
- const toolCallId = (_b = part.call_id) != null ? _b : part.id;
5310
+ const toolCallId = (_d = part.call_id) != null ? _d : part.id;
5247
5311
  const isHosted = part.execution === "server";
5248
5312
  if (isHosted) {
5249
5313
  hostedToolSearchCallIds.push(toolCallId);
@@ -5266,7 +5330,7 @@ var OpenAIResponsesLanguageModel = class {
5266
5330
  break;
5267
5331
  }
5268
5332
  case "tool_search_output": {
5269
- const toolCallId = (_d = (_c = part.call_id) != null ? _c : hostedToolSearchCallIds.shift()) != null ? _d : part.id;
5333
+ const toolCallId = (_f = (_e = part.call_id) != null ? _e : hostedToolSearchCallIds.shift()) != null ? _f : part.id;
5270
5334
  content.push({
5271
5335
  type: "tool-result",
5272
5336
  toolCallId,
@@ -5337,7 +5401,7 @@ var OpenAIResponsesLanguageModel = class {
5337
5401
  }
5338
5402
  case "message": {
5339
5403
  for (const contentPart of part.content) {
5340
- if (((_f = (_e = options.providerOptions) == null ? void 0 : _e[providerOptionsName]) == null ? void 0 : _f.logprobs) && contentPart.logprobs) {
5404
+ if (((_h = (_g = options.providerOptions) == null ? void 0 : _g[providerOptionsName]) == null ? void 0 : _h.logprobs) && contentPart.logprobs) {
5341
5405
  logprobs.push(contentPart.logprobs);
5342
5406
  }
5343
5407
  const providerMetadata2 = {
@@ -5359,7 +5423,7 @@ var OpenAIResponsesLanguageModel = class {
5359
5423
  content.push({
5360
5424
  type: "source",
5361
5425
  sourceType: "url",
5362
- id: (_i = (_h = (_g = this.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i : generateId2(),
5426
+ id: (_k = (_j = (_i = this.config).generateId) == null ? void 0 : _j.call(_i)) != null ? _k : generateId2(),
5363
5427
  url: annotation.url,
5364
5428
  title: annotation.title
5365
5429
  });
@@ -5367,7 +5431,7 @@ var OpenAIResponsesLanguageModel = class {
5367
5431
  content.push({
5368
5432
  type: "source",
5369
5433
  sourceType: "document",
5370
- id: (_l = (_k = (_j = this.config).generateId) == null ? void 0 : _k.call(_j)) != null ? _l : generateId2(),
5434
+ id: (_n = (_m = (_l = this.config).generateId) == null ? void 0 : _m.call(_l)) != null ? _n : generateId2(),
5371
5435
  mediaType: "text/plain",
5372
5436
  title: annotation.filename,
5373
5437
  filename: annotation.filename,
@@ -5383,7 +5447,7 @@ var OpenAIResponsesLanguageModel = class {
5383
5447
  content.push({
5384
5448
  type: "source",
5385
5449
  sourceType: "document",
5386
- id: (_o = (_n = (_m = this.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : generateId2(),
5450
+ id: (_q = (_p = (_o = this.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : generateId2(),
5387
5451
  mediaType: "text/plain",
5388
5452
  title: annotation.filename,
5389
5453
  filename: annotation.filename,
@@ -5399,7 +5463,7 @@ var OpenAIResponsesLanguageModel = class {
5399
5463
  content.push({
5400
5464
  type: "source",
5401
5465
  sourceType: "document",
5402
- id: (_r = (_q = (_p = this.config).generateId) == null ? void 0 : _q.call(_p)) != null ? _r : generateId2(),
5466
+ id: (_t = (_s = (_r = this.config).generateId) == null ? void 0 : _s.call(_r)) != null ? _t : generateId2(),
5403
5467
  mediaType: "application/octet-stream",
5404
5468
  title: annotation.file_id,
5405
5469
  filename: annotation.file_id,
@@ -5468,7 +5532,7 @@ var OpenAIResponsesLanguageModel = class {
5468
5532
  break;
5469
5533
  }
5470
5534
  case "mcp_call": {
5471
- const toolCallId = part.approval_request_id != null ? (_s = approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id]) != null ? _s : part.id : part.id;
5535
+ const toolCallId = part.approval_request_id != null ? (_u = approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id]) != null ? _u : part.id : part.id;
5472
5536
  const toolName = `mcp.${part.name}`;
5473
5537
  content.push({
5474
5538
  type: "tool-call",
@@ -5502,8 +5566,8 @@ var OpenAIResponsesLanguageModel = class {
5502
5566
  break;
5503
5567
  }
5504
5568
  case "mcp_approval_request": {
5505
- const approvalRequestId = (_t = part.approval_request_id) != null ? _t : part.id;
5506
- const dummyToolCallId = (_w = (_v = (_u = this.config).generateId) == null ? void 0 : _v.call(_u)) != null ? _w : generateId2();
5569
+ const approvalRequestId = (_v = part.approval_request_id) != null ? _v : part.id;
5570
+ const dummyToolCallId = (_y = (_x = (_w = this.config).generateId) == null ? void 0 : _x.call(_w)) != null ? _y : generateId2();
5507
5571
  const toolName = `mcp.${part.name}`;
5508
5572
  content.push({
5509
5573
  type: "tool-call",
@@ -5553,13 +5617,13 @@ var OpenAIResponsesLanguageModel = class {
5553
5617
  toolName: toolNameMapping.toCustomToolName("file_search"),
5554
5618
  result: {
5555
5619
  queries: part.queries,
5556
- results: (_y = (_x = part.results) == null ? void 0 : _x.map((result) => ({
5620
+ results: (_A = (_z = part.results) == null ? void 0 : _z.map((result) => ({
5557
5621
  attributes: result.attributes,
5558
5622
  fileId: result.file_id,
5559
5623
  filename: result.filename,
5560
5624
  score: result.score,
5561
5625
  text: result.text
5562
- }))) != null ? _y : null
5626
+ }))) != null ? _A : null
5563
5627
  }
5564
5628
  });
5565
5629
  break;
@@ -5630,10 +5694,10 @@ var OpenAIResponsesLanguageModel = class {
5630
5694
  content,
5631
5695
  finishReason: {
5632
5696
  unified: mapOpenAIResponseFinishReason({
5633
- finishReason: (_z = response.incomplete_details) == null ? void 0 : _z.reason,
5697
+ finishReason: (_B = response.incomplete_details) == null ? void 0 : _B.reason,
5634
5698
  hasFunctionCall
5635
5699
  }),
5636
- raw: (_B = (_A = response.incomplete_details) == null ? void 0 : _A.reason) != null ? _B : void 0
5700
+ raw: (_D = (_C = response.incomplete_details) == null ? void 0 : _C.reason) != null ? _D : void 0
5637
5701
  },
5638
5702
  usage: convertOpenAIResponsesUsage(usage),
5639
5703
  request: { body },
@@ -5649,6 +5713,7 @@ var OpenAIResponsesLanguageModel = class {
5649
5713
  };
5650
5714
  }
5651
5715
  async doStream(options) {
5716
+ var _a, _b;
5652
5717
  const {
5653
5718
  args: body,
5654
5719
  warnings,
@@ -5663,7 +5728,7 @@ var OpenAIResponsesLanguageModel = class {
5663
5728
  path: "/responses",
5664
5729
  modelId: this.modelId
5665
5730
  }),
5666
- headers: combineHeaders6(this.config.headers(), options.headers),
5731
+ headers: combineHeaders6((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
5667
5732
  body: {
5668
5733
  ...body,
5669
5734
  stream: true
@@ -5699,7 +5764,7 @@ var OpenAIResponsesLanguageModel = class {
5699
5764
  controller.enqueue({ type: "stream-start", warnings });
5700
5765
  },
5701
5766
  transform(chunk, controller) {
5702
- 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, _F, _G, _H, _I, _J, _K, _L;
5767
+ var _a2, _b2, _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, _F, _G, _H, _I, _J, _K, _L;
5703
5768
  if (options.includeRawChunks) {
5704
5769
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
5705
5770
  }
@@ -5814,7 +5879,7 @@ var OpenAIResponsesLanguageModel = class {
5814
5879
  ongoingToolCalls[value.output_index] = {
5815
5880
  toolName,
5816
5881
  toolCallId,
5817
- toolSearchExecution: (_a = value.item.execution) != null ? _a : "server"
5882
+ toolSearchExecution: (_a2 = value.item.execution) != null ? _a2 : "server"
5818
5883
  };
5819
5884
  if (isHosted) {
5820
5885
  controller.enqueue({
@@ -5871,7 +5936,7 @@ var OpenAIResponsesLanguageModel = class {
5871
5936
  } else if (value.item.type === "shell_call_output") {
5872
5937
  } else if (value.item.type === "message") {
5873
5938
  ongoingAnnotations.splice(0, ongoingAnnotations.length);
5874
- activeMessagePhase = (_b = value.item.phase) != null ? _b : void 0;
5939
+ activeMessagePhase = (_b2 = value.item.phase) != null ? _b2 : void 0;
5875
5940
  controller.enqueue({
5876
5941
  type: "text-start",
5877
5942
  id: value.item.id,
@@ -6609,7 +6674,10 @@ import {
6609
6674
  combineHeaders as combineHeaders7,
6610
6675
  createBinaryResponseHandler,
6611
6676
  parseProviderOptions as parseProviderOptions7,
6612
- postJsonToApi as postJsonToApi6
6677
+ postJsonToApi as postJsonToApi6,
6678
+ serializeModelOptions as serializeModelOptions6,
6679
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE6,
6680
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE6
6613
6681
  } from "@ai-sdk/provider-utils";
6614
6682
 
6615
6683
  // src/speech/openai-speech-options.ts
@@ -6625,12 +6693,21 @@ var openaiSpeechModelOptionsSchema = lazySchema23(
6625
6693
  );
6626
6694
 
6627
6695
  // src/speech/openai-speech-model.ts
6628
- var OpenAISpeechModel = class {
6696
+ var OpenAISpeechModel = class _OpenAISpeechModel {
6629
6697
  constructor(modelId, config) {
6630
6698
  this.modelId = modelId;
6631
6699
  this.config = config;
6632
6700
  this.specificationVersion = "v4";
6633
6701
  }
6702
+ static [WORKFLOW_SERIALIZE6](model) {
6703
+ return serializeModelOptions6({
6704
+ modelId: model.modelId,
6705
+ config: model.config
6706
+ });
6707
+ }
6708
+ static [WORKFLOW_DESERIALIZE6](options) {
6709
+ return new _OpenAISpeechModel(options.modelId, options.config);
6710
+ }
6634
6711
  get provider() {
6635
6712
  return this.config.provider;
6636
6713
  }
@@ -6690,7 +6767,7 @@ var OpenAISpeechModel = class {
6690
6767
  };
6691
6768
  }
6692
6769
  async doGenerate(options) {
6693
- var _a, _b, _c;
6770
+ var _a, _b, _c, _d, _e;
6694
6771
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
6695
6772
  const { requestBody, warnings } = await this.getArgs(options);
6696
6773
  const {
@@ -6702,7 +6779,7 @@ var OpenAISpeechModel = class {
6702
6779
  path: "/audio/speech",
6703
6780
  modelId: this.modelId
6704
6781
  }),
6705
- headers: combineHeaders7(this.config.headers(), options.headers),
6782
+ headers: combineHeaders7((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), options.headers),
6706
6783
  body: requestBody,
6707
6784
  failedResponseHandler: openaiFailedResponseHandler,
6708
6785
  successfulResponseHandler: createBinaryResponseHandler(),
@@ -6732,7 +6809,10 @@ import {
6732
6809
  createJsonResponseHandler as createJsonResponseHandler7,
6733
6810
  mediaTypeToExtension,
6734
6811
  parseProviderOptions as parseProviderOptions8,
6735
- postFormDataToApi as postFormDataToApi3
6812
+ postFormDataToApi as postFormDataToApi3,
6813
+ serializeModelOptions as serializeModelOptions7,
6814
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE7,
6815
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE7
6736
6816
  } from "@ai-sdk/provider-utils";
6737
6817
 
6738
6818
  // src/transcription/openai-transcription-api.ts
@@ -6861,12 +6941,21 @@ var languageMap = {
6861
6941
  vietnamese: "vi",
6862
6942
  welsh: "cy"
6863
6943
  };
6864
- var OpenAITranscriptionModel = class {
6944
+ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
6865
6945
  constructor(modelId, config) {
6866
6946
  this.modelId = modelId;
6867
6947
  this.config = config;
6868
6948
  this.specificationVersion = "v4";
6869
6949
  }
6950
+ static [WORKFLOW_SERIALIZE7](model) {
6951
+ return serializeModelOptions7({
6952
+ modelId: model.modelId,
6953
+ config: model.config
6954
+ });
6955
+ }
6956
+ static [WORKFLOW_DESERIALIZE7](options) {
6957
+ return new _OpenAITranscriptionModel(options.modelId, options.config);
6958
+ }
6870
6959
  get provider() {
6871
6960
  return this.config.provider;
6872
6961
  }
@@ -6922,7 +7011,7 @@ var OpenAITranscriptionModel = class {
6922
7011
  };
6923
7012
  }
6924
7013
  async doGenerate(options) {
6925
- var _a, _b, _c, _d, _e, _f, _g, _h;
7014
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
6926
7015
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
6927
7016
  const { formData, warnings } = await this.getArgs(options);
6928
7017
  const {
@@ -6934,7 +7023,7 @@ var OpenAITranscriptionModel = class {
6934
7023
  path: "/audio/transcriptions",
6935
7024
  modelId: this.modelId
6936
7025
  }),
6937
- headers: combineHeaders8(this.config.headers(), options.headers),
7026
+ headers: combineHeaders8((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), options.headers),
6938
7027
  formData,
6939
7028
  failedResponseHandler: openaiFailedResponseHandler,
6940
7029
  successfulResponseHandler: createJsonResponseHandler7(
@@ -6946,17 +7035,17 @@ var OpenAITranscriptionModel = class {
6946
7035
  const language = response.language != null && response.language in languageMap ? languageMap[response.language] : void 0;
6947
7036
  return {
6948
7037
  text: response.text,
6949
- segments: (_g = (_f = (_d = response.segments) == null ? void 0 : _d.map((segment) => ({
7038
+ segments: (_i = (_h = (_f = response.segments) == null ? void 0 : _f.map((segment) => ({
6950
7039
  text: segment.text,
6951
7040
  startSecond: segment.start,
6952
7041
  endSecond: segment.end
6953
- }))) != null ? _f : (_e = response.words) == null ? void 0 : _e.map((word) => ({
7042
+ }))) != null ? _h : (_g = response.words) == null ? void 0 : _g.map((word) => ({
6954
7043
  text: word.word,
6955
7044
  startSecond: word.start,
6956
7045
  endSecond: word.end
6957
- }))) != null ? _g : [],
7046
+ }))) != null ? _i : [],
6958
7047
  language,
6959
- durationInSeconds: (_h = response.duration) != null ? _h : void 0,
7048
+ durationInSeconds: (_j = response.duration) != null ? _j : void 0,
6960
7049
  warnings,
6961
7050
  response: {
6962
7051
  timestamp: currentDate,
@@ -7053,7 +7142,7 @@ var OpenAISkills = class {
7053
7142
  };
7054
7143
 
7055
7144
  // src/version.ts
7056
- var VERSION = true ? "4.0.0-beta.30" : "0.0.0-test";
7145
+ var VERSION = true ? "4.0.0-beta.31" : "0.0.0-test";
7057
7146
 
7058
7147
  // src/openai-provider.ts
7059
7148
  function createOpenAI(options = {}) {