@ai-sdk/openai 2.0.1 → 2.0.3

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,18 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 2.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [90d212f]
8
+ - @ai-sdk/provider-utils@3.0.1
9
+
10
+ ## 2.0.2
11
+
12
+ ### Patch Changes
13
+
14
+ - 63e2016: fix(openai): missing url citations from web search tools
15
+
3
16
  ## 2.0.1
4
17
 
5
18
  ### Patch Changes
package/dist/index.js CHANGED
@@ -708,7 +708,7 @@ var OpenAIChatLanguageModel = class {
708
708
  };
709
709
  }
710
710
  async doGenerate(options) {
711
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
711
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
712
712
  const { args: body, warnings } = await this.getArgs(options);
713
713
  const {
714
714
  responseHeaders,
@@ -742,8 +742,17 @@ var OpenAIChatLanguageModel = class {
742
742
  input: toolCall.function.arguments
743
743
  });
744
744
  }
745
- const completionTokenDetails = (_c = response.usage) == null ? void 0 : _c.completion_tokens_details;
746
- const promptTokenDetails = (_d = response.usage) == null ? void 0 : _d.prompt_tokens_details;
745
+ for (const annotation of (_c = choice.message.annotations) != null ? _c : []) {
746
+ content.push({
747
+ type: "source",
748
+ sourceType: "url",
749
+ id: (0, import_provider_utils5.generateId)(),
750
+ url: annotation.url,
751
+ title: annotation.title
752
+ });
753
+ }
754
+ const completionTokenDetails = (_d = response.usage) == null ? void 0 : _d.completion_tokens_details;
755
+ const promptTokenDetails = (_e = response.usage) == null ? void 0 : _e.prompt_tokens_details;
747
756
  const providerMetadata = { openai: {} };
748
757
  if ((completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens) != null) {
749
758
  providerMetadata.openai.acceptedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens;
@@ -751,18 +760,18 @@ var OpenAIChatLanguageModel = class {
751
760
  if ((completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens) != null) {
752
761
  providerMetadata.openai.rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
753
762
  }
754
- if (((_e = choice.logprobs) == null ? void 0 : _e.content) != null) {
763
+ if (((_f = choice.logprobs) == null ? void 0 : _f.content) != null) {
755
764
  providerMetadata.openai.logprobs = choice.logprobs.content;
756
765
  }
757
766
  return {
758
767
  content,
759
768
  finishReason: mapOpenAIFinishReason(choice.finish_reason),
760
769
  usage: {
761
- inputTokens: (_g = (_f = response.usage) == null ? void 0 : _f.prompt_tokens) != null ? _g : void 0,
762
- outputTokens: (_i = (_h = response.usage) == null ? void 0 : _h.completion_tokens) != null ? _i : void 0,
763
- totalTokens: (_k = (_j = response.usage) == null ? void 0 : _j.total_tokens) != null ? _k : void 0,
764
- reasoningTokens: (_l = completionTokenDetails == null ? void 0 : completionTokenDetails.reasoning_tokens) != null ? _l : void 0,
765
- cachedInputTokens: (_m = promptTokenDetails == null ? void 0 : promptTokenDetails.cached_tokens) != null ? _m : void 0
770
+ inputTokens: (_h = (_g = response.usage) == null ? void 0 : _g.prompt_tokens) != null ? _h : void 0,
771
+ outputTokens: (_j = (_i = response.usage) == null ? void 0 : _i.completion_tokens) != null ? _j : void 0,
772
+ totalTokens: (_l = (_k = response.usage) == null ? void 0 : _k.total_tokens) != null ? _l : void 0,
773
+ reasoningTokens: (_m = completionTokenDetails == null ? void 0 : completionTokenDetails.reasoning_tokens) != null ? _m : void 0,
774
+ cachedInputTokens: (_n = promptTokenDetails == null ? void 0 : promptTokenDetails.cached_tokens) != null ? _n : void 0
766
775
  },
767
776
  request: { body },
768
777
  response: {
@@ -959,6 +968,17 @@ var OpenAIChatLanguageModel = class {
959
968
  }
960
969
  }
961
970
  }
971
+ if (delta.annotations != null) {
972
+ for (const annotation of delta.annotations) {
973
+ controller.enqueue({
974
+ type: "source",
975
+ sourceType: "url",
976
+ id: (0, import_provider_utils5.generateId)(),
977
+ url: annotation.url,
978
+ title: annotation.title
979
+ });
980
+ }
981
+ }
962
982
  },
963
983
  flush(controller) {
964
984
  if (isActiveText) {
@@ -1009,6 +1029,15 @@ var openaiChatResponseSchema = import_v45.z.object({
1009
1029
  arguments: import_v45.z.string()
1010
1030
  })
1011
1031
  })
1032
+ ).nullish(),
1033
+ annotations: import_v45.z.array(
1034
+ import_v45.z.object({
1035
+ type: import_v45.z.literal("url_citation"),
1036
+ start_index: import_v45.z.number(),
1037
+ end_index: import_v45.z.number(),
1038
+ url: import_v45.z.string(),
1039
+ title: import_v45.z.string()
1040
+ })
1012
1041
  ).nullish()
1013
1042
  }),
1014
1043
  index: import_v45.z.number(),
@@ -1051,6 +1080,15 @@ var openaiChatChunkSchema = import_v45.z.union([
1051
1080
  arguments: import_v45.z.string().nullish()
1052
1081
  })
1053
1082
  })
1083
+ ).nullish(),
1084
+ annotations: import_v45.z.array(
1085
+ import_v45.z.object({
1086
+ type: import_v45.z.literal("url_citation"),
1087
+ start_index: import_v45.z.number(),
1088
+ end_index: import_v45.z.number(),
1089
+ url: import_v45.z.string(),
1090
+ title: import_v45.z.string()
1091
+ })
1054
1092
  ).nullish()
1055
1093
  }).nullish(),
1056
1094
  logprobs: import_v45.z.object({