@ai-sdk/openai 2.0.10 → 2.0.11

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.
@@ -316,7 +316,20 @@ var openaiProviderOptions = z2.object({
316
316
  * Controls the verbosity of the model's responses.
317
317
  * Lower values will result in more concise responses, while higher values will result in more verbose responses.
318
318
  */
319
- textVerbosity: z2.enum(["low", "medium", "high"]).optional()
319
+ textVerbosity: z2.enum(["low", "medium", "high"]).optional(),
320
+ /**
321
+ * A cache key for prompt caching. Allows manual control over prompt caching behavior.
322
+ * Useful for improving cache hit rates and working around automatic caching issues.
323
+ */
324
+ promptCacheKey: z2.string().optional(),
325
+ /**
326
+ * A stable identifier used to help detect users of your application
327
+ * that may be violating OpenAI's usage policies. The IDs should be a
328
+ * string that uniquely identifies each user. We recommend hashing their
329
+ * username or email address, in order to avoid sending us any identifying
330
+ * information.
331
+ */
332
+ safetyIdentifier: z2.string().optional()
320
333
  });
321
334
 
322
335
  // src/chat/openai-chat-prepare-tools.ts
@@ -589,6 +602,8 @@ var OpenAIChatLanguageModel = class {
589
602
  prediction: openaiOptions.prediction,
590
603
  reasoning_effort: openaiOptions.reasoningEffort,
591
604
  service_tier: openaiOptions.serviceTier,
605
+ prompt_cache_key: openaiOptions.promptCacheKey,
606
+ safety_identifier: openaiOptions.safetyIdentifier,
592
607
  // messages:
593
608
  messages
594
609
  };
@@ -2109,9 +2124,14 @@ import {
2109
2124
  import { parseProviderOptions as parseProviderOptions6 } from "@ai-sdk/provider-utils";
2110
2125
  import { z as z14 } from "zod/v4";
2111
2126
  import { convertToBase64 as convertToBase642 } from "@ai-sdk/provider-utils";
2127
+ function isFileId(data, prefixes) {
2128
+ if (!prefixes) return false;
2129
+ return prefixes.some((prefix) => data.startsWith(prefix));
2130
+ }
2112
2131
  async function convertToOpenAIResponsesMessages({
2113
2132
  prompt,
2114
- systemMessageMode
2133
+ systemMessageMode,
2134
+ fileIdPrefixes
2115
2135
  }) {
2116
2136
  var _a, _b, _c, _d, _e, _f;
2117
2137
  const messages = [];
@@ -2158,7 +2178,7 @@ async function convertToOpenAIResponsesMessages({
2158
2178
  const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
2159
2179
  return {
2160
2180
  type: "input_image",
2161
- ...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && part.data.startsWith("file-") ? { file_id: part.data } : {
2181
+ ...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
2162
2182
  image_url: `data:${mediaType};base64,${convertToBase642(part.data)}`
2163
2183
  },
2164
2184
  detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail
@@ -2171,7 +2191,7 @@ async function convertToOpenAIResponsesMessages({
2171
2191
  }
2172
2192
  return {
2173
2193
  type: "input_file",
2174
- ...typeof part.data === "string" && part.data.startsWith("file-") ? { file_id: part.data } : {
2194
+ ...typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
2175
2195
  filename: (_c2 = part.filename) != null ? _c2 : `part-${index}.pdf`,
2176
2196
  file_data: `data:application/pdf;base64,${convertToBase642(part.data)}`
2177
2197
  }
@@ -2479,7 +2499,8 @@ var OpenAIResponsesLanguageModel = class {
2479
2499
  }
2480
2500
  const { messages, warnings: messageWarnings } = await convertToOpenAIResponsesMessages({
2481
2501
  prompt,
2482
- systemMessageMode: modelConfig.systemMessageMode
2502
+ systemMessageMode: modelConfig.systemMessageMode,
2503
+ fileIdPrefixes: this.config.fileIdPrefixes
2483
2504
  });
2484
2505
  warnings.push(...messageWarnings);
2485
2506
  const openaiOptions = await parseProviderOptions7({
@@ -2519,6 +2540,8 @@ var OpenAIResponsesLanguageModel = class {
2519
2540
  instructions: openaiOptions == null ? void 0 : openaiOptions.instructions,
2520
2541
  service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
2521
2542
  include: openaiOptions == null ? void 0 : openaiOptions.include,
2543
+ prompt_cache_key: openaiOptions == null ? void 0 : openaiOptions.promptCacheKey,
2544
+ safety_identifier: openaiOptions == null ? void 0 : openaiOptions.safetyIdentifier,
2522
2545
  // model-specific settings:
2523
2546
  ...modelConfig.isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
2524
2547
  reasoning: {
@@ -2668,7 +2691,18 @@ var OpenAIResponsesLanguageModel = class {
2668
2691
  z16.object({
2669
2692
  type: z16.literal("file_search_call"),
2670
2693
  id: z16.string(),
2671
- status: z16.string().optional()
2694
+ status: z16.string().optional(),
2695
+ queries: z16.array(z16.string()).nullish(),
2696
+ results: z16.array(
2697
+ z16.object({
2698
+ attributes: z16.object({
2699
+ file_id: z16.string(),
2700
+ filename: z16.string(),
2701
+ score: z16.number(),
2702
+ text: z16.string()
2703
+ })
2704
+ })
2705
+ ).nullish()
2672
2706
  }),
2673
2707
  z16.object({
2674
2708
  type: z16.literal("reasoning"),
@@ -2810,7 +2844,9 @@ var OpenAIResponsesLanguageModel = class {
2810
2844
  toolName: "file_search",
2811
2845
  result: {
2812
2846
  type: "file_search_tool_result",
2813
- status: part.status || "completed"
2847
+ status: part.status || "completed",
2848
+ ...part.queries && { queries: part.queries },
2849
+ ...part.results && { results: part.results }
2814
2850
  },
2815
2851
  providerExecuted: true
2816
2852
  });
@@ -2925,6 +2961,16 @@ var OpenAIResponsesLanguageModel = class {
2925
2961
  id: value.item.id,
2926
2962
  toolName: "computer_use"
2927
2963
  });
2964
+ } else if (value.item.type === "file_search_call") {
2965
+ ongoingToolCalls[value.output_index] = {
2966
+ toolName: "file_search",
2967
+ toolCallId: value.item.id
2968
+ };
2969
+ controller.enqueue({
2970
+ type: "tool-input-start",
2971
+ id: value.item.id,
2972
+ toolName: "file_search"
2973
+ });
2928
2974
  } else if (value.item.type === "message") {
2929
2975
  controller.enqueue({
2930
2976
  type: "text-start",
@@ -3018,6 +3064,32 @@ var OpenAIResponsesLanguageModel = class {
3018
3064
  },
3019
3065
  providerExecuted: true
3020
3066
  });
3067
+ } else if (value.item.type === "file_search_call") {
3068
+ ongoingToolCalls[value.output_index] = void 0;
3069
+ hasToolCalls = true;
3070
+ controller.enqueue({
3071
+ type: "tool-input-end",
3072
+ id: value.item.id
3073
+ });
3074
+ controller.enqueue({
3075
+ type: "tool-call",
3076
+ toolCallId: value.item.id,
3077
+ toolName: "file_search",
3078
+ input: "",
3079
+ providerExecuted: true
3080
+ });
3081
+ controller.enqueue({
3082
+ type: "tool-result",
3083
+ toolCallId: value.item.id,
3084
+ toolName: "file_search",
3085
+ result: {
3086
+ type: "file_search_tool_result",
3087
+ status: value.item.status || "completed",
3088
+ ...value.item.queries && { queries: value.item.queries },
3089
+ ...value.item.results && { results: value.item.results }
3090
+ },
3091
+ providerExecuted: true
3092
+ });
3021
3093
  } else if (value.item.type === "message") {
3022
3094
  controller.enqueue({
3023
3095
  type: "text-end",
@@ -3196,7 +3268,18 @@ var responseOutputItemAddedSchema = z16.object({
3196
3268
  z16.object({
3197
3269
  type: z16.literal("file_search_call"),
3198
3270
  id: z16.string(),
3199
- status: z16.string()
3271
+ status: z16.string(),
3272
+ queries: z16.array(z16.string()).nullish(),
3273
+ results: z16.array(
3274
+ z16.object({
3275
+ attributes: z16.object({
3276
+ file_id: z16.string(),
3277
+ filename: z16.string(),
3278
+ score: z16.number(),
3279
+ text: z16.string()
3280
+ })
3281
+ })
3282
+ ).optional()
3200
3283
  })
3201
3284
  ])
3202
3285
  });
@@ -3234,7 +3317,18 @@ var responseOutputItemDoneSchema = z16.object({
3234
3317
  z16.object({
3235
3318
  type: z16.literal("file_search_call"),
3236
3319
  id: z16.string(),
3237
- status: z16.literal("completed")
3320
+ status: z16.literal("completed"),
3321
+ queries: z16.array(z16.string()).nullish(),
3322
+ results: z16.array(
3323
+ z16.object({
3324
+ attributes: z16.object({
3325
+ file_id: z16.string(),
3326
+ filename: z16.string(),
3327
+ score: z16.number(),
3328
+ text: z16.string()
3329
+ })
3330
+ })
3331
+ ).nullish()
3238
3332
  })
3239
3333
  ])
3240
3334
  });
@@ -3352,7 +3446,9 @@ var openaiResponsesProviderOptionsSchema = z16.object({
3352
3446
  reasoningSummary: z16.string().nullish(),
3353
3447
  serviceTier: z16.enum(["auto", "flex", "priority"]).nullish(),
3354
3448
  include: z16.array(z16.enum(["reasoning.encrypted_content", "file_search_call.results"])).nullish(),
3355
- textVerbosity: z16.enum(["low", "medium", "high"]).nullish()
3449
+ textVerbosity: z16.enum(["low", "medium", "high"]).nullish(),
3450
+ promptCacheKey: z16.string().nullish(),
3451
+ safetyIdentifier: z16.string().nullish()
3356
3452
  });
3357
3453
  export {
3358
3454
  OpenAIChatLanguageModel,