@ai-sdk/openai 4.0.53 → 4.0.55

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
@@ -2043,12 +2043,19 @@ var OpenAIEmbeddingModel = class _OpenAIEmbeddingModel {
2043
2043
  };
2044
2044
 
2045
2045
  // src/files/openai-files.ts
2046
+ import {
2047
+ InvalidArgumentError
2048
+ } from "@ai-sdk/provider";
2046
2049
  import {
2047
2050
  combineHeaders as combineHeaders4,
2048
2051
  convertInlineFileDataToUint8Array,
2052
+ createBinaryStreamResponseHandler,
2049
2053
  createJsonResponseHandler as createJsonResponseHandler4,
2054
+ deleteFromApi,
2055
+ getFromApi,
2050
2056
  parseProviderOptions as parseProviderOptions4,
2051
- postFormDataToApi
2057
+ postFormDataToApi,
2058
+ postMultipartStreamToApi
2052
2059
  } from "@ai-sdk/provider-utils";
2053
2060
 
2054
2061
  // src/files/openai-files-api.ts
@@ -2068,6 +2075,15 @@ var openaiFilesResponseSchema = lazySchema7(
2068
2075
  })
2069
2076
  )
2070
2077
  );
2078
+ var openaiFileDeleteResponseSchema = lazySchema7(
2079
+ () => zodSchema7(
2080
+ z8.object({
2081
+ id: z8.string(),
2082
+ object: z8.string().nullish(),
2083
+ deleted: z8.boolean()
2084
+ })
2085
+ )
2086
+ );
2071
2087
 
2072
2088
  // src/files/openai-files-options.ts
2073
2089
  import {
@@ -2090,6 +2106,10 @@ var openaiFilesOptionsSchema = lazySchema8(
2090
2106
  );
2091
2107
 
2092
2108
  // src/files/openai-files.ts
2109
+ function encodePathSegment(value) {
2110
+ const encodedValue = encodeURIComponent(value);
2111
+ return encodedValue === "." ? "%252E" : encodedValue === ".." ? "%252E%252E" : encodedValue;
2112
+ }
2093
2113
  var OpenAIFiles = class {
2094
2114
  constructor(config) {
2095
2115
  this.config = config;
@@ -2098,63 +2118,206 @@ var OpenAIFiles = class {
2098
2118
  get provider() {
2099
2119
  return this.config.provider;
2100
2120
  }
2121
+ getFileId(file) {
2122
+ const fileId = file.openai;
2123
+ if (fileId == null || fileId.trim() === "") {
2124
+ throw new InvalidArgumentError({
2125
+ argument: "file",
2126
+ message: "file reference is missing an 'openai' file id."
2127
+ });
2128
+ }
2129
+ return fileId;
2130
+ }
2131
+ getHeaders(headers) {
2132
+ return combineHeaders4(this.config.headers(), headers);
2133
+ }
2101
2134
  async uploadFile({
2102
2135
  data,
2103
2136
  mediaType,
2104
2137
  filename,
2138
+ abortSignal,
2139
+ headers,
2105
2140
  providerOptions
2106
2141
  }) {
2107
2142
  var _a2, _b, _c;
2108
- const openaiOptions = await parseProviderOptions4({
2109
- provider: "openai",
2110
- providerOptions,
2111
- schema: openaiFilesOptionsSchema
2112
- });
2113
- const fileBytes = convertInlineFileDataToUint8Array(data);
2114
- const blob = new Blob([fileBytes], {
2115
- type: mediaType
2116
- });
2117
- const formData = new FormData();
2118
- if (filename != null) {
2119
- formData.append("file", blob, filename);
2120
- } else {
2121
- formData.append("file", blob);
2143
+ let openaiOptions;
2144
+ try {
2145
+ openaiOptions = await parseProviderOptions4({
2146
+ provider: "openai",
2147
+ providerOptions,
2148
+ schema: openaiFilesOptionsSchema
2149
+ });
2150
+ } catch (error) {
2151
+ if (data.type === "stream") {
2152
+ await data.stream.cancel(error).catch(() => {
2153
+ });
2154
+ }
2155
+ throw error;
2122
2156
  }
2123
- formData.append("purpose", (_a2 = openaiOptions == null ? void 0 : openaiOptions.purpose) != null ? _a2 : "assistants");
2124
- if ((openaiOptions == null ? void 0 : openaiOptions.expiresAfter) != null) {
2125
- formData.append("expires_after[anchor]", "created_at");
2126
- formData.append(
2127
- "expires_after[seconds]",
2128
- String(openaiOptions.expiresAfter)
2129
- );
2157
+ const purpose = (_a2 = openaiOptions == null ? void 0 : openaiOptions.purpose) != null ? _a2 : "assistants";
2158
+ const requestHeaders = this.getHeaders(headers);
2159
+ const url = `${this.config.baseURL}/files`;
2160
+ let response;
2161
+ if (data.type === "stream") {
2162
+ const parts = [
2163
+ { type: "field", name: "purpose", value: purpose }
2164
+ ];
2165
+ if ((openaiOptions == null ? void 0 : openaiOptions.expiresAfter) != null) {
2166
+ parts.push(
2167
+ { type: "field", name: "expires_after[anchor]", value: "created_at" },
2168
+ {
2169
+ type: "field",
2170
+ name: "expires_after[seconds]",
2171
+ value: String(openaiOptions.expiresAfter)
2172
+ }
2173
+ );
2174
+ }
2175
+ parts.push({
2176
+ type: "file",
2177
+ name: "file",
2178
+ filename,
2179
+ mediaType,
2180
+ content: data.stream
2181
+ });
2182
+ ({ value: response } = await postMultipartStreamToApi({
2183
+ url,
2184
+ headers: requestHeaders,
2185
+ parts,
2186
+ failedResponseHandler: openaiFailedResponseHandler,
2187
+ successfulResponseHandler: createJsonResponseHandler4(
2188
+ openaiFilesResponseSchema
2189
+ ),
2190
+ abortSignal,
2191
+ fetch: this.config.fetch
2192
+ }));
2193
+ } else {
2194
+ const fileBytes = convertInlineFileDataToUint8Array(data);
2195
+ const blob = new Blob([fileBytes], {
2196
+ type: mediaType
2197
+ });
2198
+ const formData = new FormData();
2199
+ if (filename != null) {
2200
+ formData.append("file", blob, filename);
2201
+ } else {
2202
+ formData.append("file", blob);
2203
+ }
2204
+ formData.append("purpose", purpose);
2205
+ if ((openaiOptions == null ? void 0 : openaiOptions.expiresAfter) != null) {
2206
+ formData.append("expires_after[anchor]", "created_at");
2207
+ formData.append(
2208
+ "expires_after[seconds]",
2209
+ String(openaiOptions.expiresAfter)
2210
+ );
2211
+ }
2212
+ ({ value: response } = await postFormDataToApi({
2213
+ url,
2214
+ headers: requestHeaders,
2215
+ formData,
2216
+ failedResponseHandler: openaiFailedResponseHandler,
2217
+ successfulResponseHandler: createJsonResponseHandler4(
2218
+ openaiFilesResponseSchema
2219
+ ),
2220
+ abortSignal,
2221
+ fetch: this.config.fetch
2222
+ }));
2130
2223
  }
2131
- const { value: response } = await postFormDataToApi({
2132
- url: `${this.config.baseURL}/files`,
2133
- headers: combineHeaders4(this.config.headers()),
2134
- formData,
2224
+ return {
2225
+ warnings: [],
2226
+ providerReference: { openai: response.id },
2227
+ ...((_b = response.filename) != null ? _b : filename) ? { filename: (_c = response.filename) != null ? _c : filename } : {},
2228
+ ...mediaType != null ? { mediaType } : {},
2229
+ ...response.bytes != null ? { byteSize: response.bytes } : {},
2230
+ ...response.created_at != null ? { createdAt: new Date(response.created_at * 1e3) } : {},
2231
+ ...response.expires_at != null ? { expiresAt: new Date(response.expires_at * 1e3) } : {},
2232
+ providerMetadata: {
2233
+ openai: this.toFileMetadata(response)
2234
+ }
2235
+ };
2236
+ }
2237
+ async getFileMetadata({
2238
+ file,
2239
+ abortSignal,
2240
+ headers
2241
+ }) {
2242
+ const fileId = this.getFileId(file);
2243
+ const { value: response } = await getFromApi({
2244
+ url: `${this.config.baseURL}/files/${encodePathSegment(fileId)}`,
2245
+ headers: this.getHeaders(headers),
2135
2246
  failedResponseHandler: openaiFailedResponseHandler,
2136
2247
  successfulResponseHandler: createJsonResponseHandler4(
2137
2248
  openaiFilesResponseSchema
2138
2249
  ),
2139
- fetch: this.config.fetch
2250
+ abortSignal,
2251
+ fetch: this.config.fetch,
2252
+ validateUrl: false
2140
2253
  });
2141
2254
  return {
2142
2255
  warnings: [],
2143
2256
  providerReference: { openai: response.id },
2144
- ...((_b = response.filename) != null ? _b : filename) ? { filename: (_c = response.filename) != null ? _c : filename } : {},
2145
- ...mediaType != null ? { mediaType } : {},
2257
+ ...response.filename != null ? { filename: response.filename } : {},
2258
+ ...response.bytes != null ? { byteSize: response.bytes } : {},
2259
+ ...response.created_at != null ? { createdAt: new Date(response.created_at * 1e3) } : {},
2260
+ ...response.expires_at != null ? { expiresAt: new Date(response.expires_at * 1e3) } : {},
2146
2261
  providerMetadata: {
2147
- openai: {
2148
- ...response.filename != null ? { filename: response.filename } : {},
2149
- ...response.purpose != null ? { purpose: response.purpose } : {},
2150
- ...response.bytes != null ? { bytes: response.bytes } : {},
2151
- ...response.created_at != null ? { createdAt: response.created_at } : {},
2152
- ...response.status != null ? { status: response.status } : {},
2153
- ...response.expires_at != null ? { expiresAt: response.expires_at } : {}
2154
- }
2262
+ openai: this.toFileMetadata(response)
2155
2263
  }
2156
2264
  };
2157
2265
  }
2266
+ async downloadFile({
2267
+ file,
2268
+ abortSignal,
2269
+ headers
2270
+ }) {
2271
+ var _a2;
2272
+ const fileId = this.getFileId(file);
2273
+ const { value: content, responseHeaders } = await getFromApi({
2274
+ url: `${this.config.baseURL}/files/${encodePathSegment(fileId)}/content`,
2275
+ headers: this.getHeaders(headers),
2276
+ failedResponseHandler: openaiFailedResponseHandler,
2277
+ successfulResponseHandler: createBinaryStreamResponseHandler(),
2278
+ abortSignal,
2279
+ fetch: this.config.fetch,
2280
+ validateUrl: false
2281
+ });
2282
+ const mediaType = (_a2 = responseHeaders == null ? void 0 : responseHeaders["content-type"]) == null ? void 0 : _a2.split(";")[0].trim();
2283
+ return {
2284
+ warnings: [],
2285
+ content,
2286
+ ...mediaType ? { mediaType } : {}
2287
+ };
2288
+ }
2289
+ async deleteFile({
2290
+ file,
2291
+ abortSignal,
2292
+ headers
2293
+ }) {
2294
+ const fileId = this.getFileId(file);
2295
+ const { value: response } = await deleteFromApi({
2296
+ url: `${this.config.baseURL}/files/${encodePathSegment(fileId)}`,
2297
+ headers: this.getHeaders(headers),
2298
+ failedResponseHandler: openaiFailedResponseHandler,
2299
+ successfulResponseHandler: createJsonResponseHandler4(
2300
+ openaiFileDeleteResponseSchema
2301
+ ),
2302
+ abortSignal,
2303
+ fetch: this.config.fetch
2304
+ });
2305
+ return {
2306
+ warnings: [],
2307
+ providerReference: { openai: response.id },
2308
+ deleted: response.deleted
2309
+ };
2310
+ }
2311
+ toFileMetadata(response) {
2312
+ return {
2313
+ ...response.filename != null ? { filename: response.filename } : {},
2314
+ ...response.purpose != null ? { purpose: response.purpose } : {},
2315
+ ...response.bytes != null ? { bytes: response.bytes } : {},
2316
+ ...response.created_at != null ? { createdAt: response.created_at } : {},
2317
+ ...response.status != null ? { status: response.status } : {},
2318
+ ...response.expires_at != null ? { expiresAt: response.expires_at } : {}
2319
+ };
2320
+ }
2158
2321
  };
2159
2322
 
2160
2323
  // src/image/openai-image-model.ts
@@ -3355,7 +3518,7 @@ var openaiTools = {
3355
3518
 
3356
3519
  // src/openai-responses-batch.ts
3357
3520
  import {
3358
- InvalidArgumentError,
3521
+ InvalidArgumentError as InvalidArgumentError2,
3359
3522
  InvalidResponseDataError
3360
3523
  } from "@ai-sdk/provider";
3361
3524
  import {
@@ -3363,7 +3526,7 @@ import {
3363
3526
  convertAsyncIteratorToReadableStream,
3364
3527
  createJsonLinesResponseHandler,
3365
3528
  createJsonResponseHandler as createJsonResponseHandler7,
3366
- getFromApi,
3529
+ getFromApi as getFromApi2,
3367
3530
  lazySchema as lazySchema26,
3368
3531
  normalizeBatchRequestCounts,
3369
3532
  postJsonToApi as postJsonToApi6,
@@ -3669,7 +3832,7 @@ var openaiResponsesChunkSchema = lazySchema24(
3669
3832
  reasoning_tokens: z25.number().nullish(),
3670
3833
  orchestration_output_tokens: z25.number().nullish()
3671
3834
  }).nullish()
3672
- }),
3835
+ }).nullish(),
3673
3836
  reasoning: z25.object({
3674
3837
  context: z25.string().nullish()
3675
3838
  }).nullish(),
@@ -4501,7 +4664,7 @@ var openaiResponsesResponseSchema = lazySchema24(
4501
4664
  reasoning_tokens: z25.number().nullish(),
4502
4665
  orchestration_output_tokens: z25.number().nullish()
4503
4666
  }).nullish()
4504
- }).optional()
4667
+ }).nullish()
4505
4668
  })
4506
4669
  )
4507
4670
  );
@@ -7570,7 +7733,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7570
7733
  controller.enqueue({ type: "stream-start", warnings });
7571
7734
  },
7572
7735
  transform(chunk, controller) {
7573
- var _a3, _b2, _c2, _d2, _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, _M, _N, _O, _P, _Q, _R;
7736
+ var _a3, _b2, _c2, _d2, _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, _M, _N, _O, _P, _Q, _R, _S;
7574
7737
  if (options.includeRawChunks) {
7575
7738
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
7576
7739
  }
@@ -8505,15 +8668,15 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8505
8668
  raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
8506
8669
  };
8507
8670
  }
8508
- usage = value.response.usage;
8671
+ usage = (_A = value.response.usage) != null ? _A : void 0;
8509
8672
  if (typeof value.response.service_tier === "string") {
8510
8673
  serviceTier = value.response.service_tier;
8511
8674
  }
8512
- if (((_A = value.response.reasoning) == null ? void 0 : _A.context) != null) {
8675
+ if (((_B = value.response.reasoning) == null ? void 0 : _B.context) != null) {
8513
8676
  reasoningContext = value.response.reasoning.context;
8514
8677
  }
8515
8678
  } else if (isResponseFailedChunk(value)) {
8516
- const incompleteReason = (_B = value.response.incomplete_details) == null ? void 0 : _B.reason;
8679
+ const incompleteReason = (_C = value.response.incomplete_details) == null ? void 0 : _C.reason;
8517
8680
  finishReason = {
8518
8681
  unified: incompleteReason ? mapOpenAIResponseFinishReason({
8519
8682
  finishReason: incompleteReason,
@@ -8521,8 +8684,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8521
8684
  }) : "error",
8522
8685
  raw: incompleteReason != null ? incompleteReason : "error"
8523
8686
  };
8524
- usage = (_C = value.response.usage) != null ? _C : void 0;
8525
- if (((_D = value.response.reasoning) == null ? void 0 : _D.context) != null) {
8687
+ usage = (_D = value.response.usage) != null ? _D : void 0;
8688
+ if (((_E = value.response.reasoning) == null ? void 0 : _E.context) != null) {
8526
8689
  reasoningContext = value.response.reasoning.context;
8527
8690
  }
8528
8691
  if (!encounteredStreamError && value.response.error != null) {
@@ -8538,7 +8701,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8538
8701
  };
8539
8702
  controller.enqueue({
8540
8703
  type: "error",
8541
- error: (_E = createOpenAIProviderStreamError(error)) != null ? _E : error
8704
+ error: (_F = createOpenAIProviderStreamError(error)) != null ? _F : error
8542
8705
  });
8543
8706
  }
8544
8707
  } else if (isResponseAnnotationAddedChunk(value)) {
@@ -8547,7 +8710,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8547
8710
  controller.enqueue({
8548
8711
  type: "source",
8549
8712
  sourceType: "url",
8550
- id: (_H = (_G = (_F = self.config).generateId) == null ? void 0 : _G.call(_F)) != null ? _H : generateId2(),
8713
+ id: (_I = (_H = (_G = self.config).generateId) == null ? void 0 : _H.call(_G)) != null ? _I : generateId2(),
8551
8714
  url: value.annotation.url,
8552
8715
  title: value.annotation.title
8553
8716
  });
@@ -8555,7 +8718,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8555
8718
  controller.enqueue({
8556
8719
  type: "source",
8557
8720
  sourceType: "document",
8558
- id: (_K = (_J = (_I = self.config).generateId) == null ? void 0 : _J.call(_I)) != null ? _K : generateId2(),
8721
+ id: (_L = (_K = (_J = self.config).generateId) == null ? void 0 : _K.call(_J)) != null ? _L : generateId2(),
8559
8722
  mediaType: "text/plain",
8560
8723
  title: value.annotation.filename,
8561
8724
  filename: value.annotation.filename,
@@ -8571,7 +8734,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8571
8734
  controller.enqueue({
8572
8735
  type: "source",
8573
8736
  sourceType: "document",
8574
- id: (_N = (_M = (_L = self.config).generateId) == null ? void 0 : _M.call(_L)) != null ? _N : generateId2(),
8737
+ id: (_O = (_N = (_M = self.config).generateId) == null ? void 0 : _N.call(_M)) != null ? _O : generateId2(),
8575
8738
  mediaType: "text/plain",
8576
8739
  title: value.annotation.filename,
8577
8740
  filename: value.annotation.filename,
@@ -8587,7 +8750,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8587
8750
  controller.enqueue({
8588
8751
  type: "source",
8589
8752
  sourceType: "document",
8590
- id: (_Q = (_P = (_O = self.config).generateId) == null ? void 0 : _P.call(_O)) != null ? _Q : generateId2(),
8753
+ id: (_R = (_Q = (_P = self.config).generateId) == null ? void 0 : _Q.call(_P)) != null ? _R : generateId2(),
8591
8754
  mediaType: "application/octet-stream",
8592
8755
  title: value.annotation.file_id,
8593
8756
  filename: value.annotation.file_id,
@@ -8605,7 +8768,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8605
8768
  finishReason = { unified: "error", raw: "error" };
8606
8769
  controller.enqueue({
8607
8770
  type: "error",
8608
- error: (_R = createOpenAIProviderStreamError(value)) != null ? _R : value
8771
+ error: (_S = createOpenAIProviderStreamError(value)) != null ? _S : value
8609
8772
  });
8610
8773
  }
8611
8774
  },
@@ -8808,7 +8971,7 @@ var OpenAIResponsesBatch = class {
8808
8971
  this.options = options;
8809
8972
  }
8810
8973
  async startBatch(options) {
8811
- var _a2, _b, _c, _d;
8974
+ var _a2, _b, _c, _d, _e;
8812
8975
  const fileParts = [];
8813
8976
  const warnings = options.webhookUrl == null ? [] : [
8814
8977
  {
@@ -8833,6 +8996,18 @@ var OpenAIResponsesBatch = class {
8833
8996
  for (const warning of preparedRequest.warnings) {
8834
8997
  warnings.push({ requestId: request.id, warning });
8835
8998
  }
8999
+ for (const tool of (_a2 = request.options.tools) != null ? _a2 : []) {
9000
+ if (tool.type === "provider" && !openAIBatchConvertibleProviderToolIds.has(tool.id)) {
9001
+ warnings.push({
9002
+ requestId: request.id,
9003
+ warning: {
9004
+ type: "unsupported",
9005
+ feature: `batch result conversion for tool "${tool.name}"`,
9006
+ details: "OpenAI may return output for this tool that AI SDK text batches cannot currently convert."
9007
+ }
9008
+ });
9009
+ }
9010
+ }
8836
9011
  }
8837
9012
  const filename = "batch.jsonl";
8838
9013
  const file = new Blob(fileParts, {
@@ -8849,7 +9024,7 @@ var OpenAIResponsesBatch = class {
8849
9024
  );
8850
9025
  const { value: uploadedFile } = await postToApi({
8851
9026
  url: this.getUrl("/files"),
8852
- headers: combineHeaders7((_b = (_a2 = this.options.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
9027
+ headers: combineHeaders7((_c = (_b = this.options.config).headers) == null ? void 0 : _c.call(_b), options.headers),
8853
9028
  body: {
8854
9029
  content: formData,
8855
9030
  values: {
@@ -8874,7 +9049,7 @@ var OpenAIResponsesBatch = class {
8874
9049
  });
8875
9050
  const { value: batch } = await postJsonToApi6({
8876
9051
  url: this.getUrl("/batches"),
8877
- headers: combineHeaders7((_d = (_c = this.options.config).headers) == null ? void 0 : _d.call(_c), options.headers),
9052
+ headers: combineHeaders7((_e = (_d = this.options.config).headers) == null ? void 0 : _e.call(_d), options.headers),
8878
9053
  body: {
8879
9054
  input_file_id: uploadedFile.id,
8880
9055
  endpoint: openaiBatchEndpoint,
@@ -8901,7 +9076,7 @@ var OpenAIResponsesBatch = class {
8901
9076
  const batch = await this.retrieveBatch(options);
8902
9077
  const batchStatus = convertOpenAIBatchStatus(batch);
8903
9078
  if (batchStatus.status === "pending") {
8904
- throw new InvalidArgumentError({
9079
+ throw new InvalidArgumentError2({
8905
9080
  argument: "batchId",
8906
9081
  message: `OpenAI batch "${options.batchId}" is not complete.`
8907
9082
  });
@@ -8920,7 +9095,7 @@ var OpenAIResponsesBatch = class {
8920
9095
  }
8921
9096
  async retrieveBatch(options) {
8922
9097
  var _a2, _b;
8923
- const { value: batch } = await getFromApi({
9098
+ const { value: batch } = await getFromApi2({
8924
9099
  url: this.getUrl(`/batches/${encodeURIComponent(options.batchId)}`),
8925
9100
  headers: combineHeaders7((_b = (_a2 = this.options.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
8926
9101
  failedResponseHandler: openaiFailedResponseHandler,
@@ -8939,7 +9114,7 @@ var OpenAIResponsesBatch = class {
8939
9114
  }) {
8940
9115
  var _a2, _b;
8941
9116
  for (const fileId of fileIds) {
8942
- const { value: lines } = await getFromApi({
9117
+ const { value: lines } = await getFromApi2({
8943
9118
  url: this.getUrl(`/files/${encodeURIComponent(fileId)}/content`),
8944
9119
  headers: combineHeaders7(
8945
9120
  (_b = (_a2 = this.options.config).headers) == null ? void 0 : _b.call(_a2),
@@ -9015,6 +9190,13 @@ var OpenAIResponsesBatch = class {
9015
9190
  });
9016
9191
  }
9017
9192
  };
9193
+ var openAIBatchConvertibleProviderToolIds = /* @__PURE__ */ new Set([
9194
+ "openai.code_interpreter",
9195
+ "openai.custom",
9196
+ "openai.file_search",
9197
+ "openai.web_search",
9198
+ "openai.web_search_preview"
9199
+ ]);
9018
9200
  var OpenAIResponsesBatchLanguageModel = class _OpenAIResponsesBatchLanguageModel extends OpenAIResponsesLanguageModel {
9019
9201
  static [WORKFLOW_SERIALIZE6](model) {
9020
9202
  return OpenAIResponsesLanguageModel[WORKFLOW_SERIALIZE6](model);
@@ -9124,7 +9306,7 @@ async function convertOpenAIErrorResponse({
9124
9306
  };
9125
9307
  }
9126
9308
  async function convertOpenAIResponsesBatchResponse(body) {
9127
- var _a2, _b, _c, _d, _e, _f;
9309
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
9128
9310
  const validation = await safeValidateTypes({
9129
9311
  value: body,
9130
9312
  schema: openaiResponsesResponseSchema
@@ -9161,6 +9343,7 @@ async function convertOpenAIResponsesBatchResponse(body) {
9161
9343
  }
9162
9344
  const content = [];
9163
9345
  const logprobs = [];
9346
+ let hasFunctionCall = false;
9164
9347
  for (const part of response.output) {
9165
9348
  switch (part.type) {
9166
9349
  case "reasoning": {
@@ -9189,14 +9372,96 @@ async function convertOpenAIResponsesBatchResponse(body) {
9189
9372
  break;
9190
9373
  }
9191
9374
  case "function_call":
9192
- case "custom_tool_call":
9193
- return {
9194
- success: false,
9195
- error: {
9196
- message: "OpenAI returned a tool call, but tool calls are not supported in AI SDK text batches.",
9197
- code: "unsupported_content"
9375
+ hasFunctionCall = true;
9376
+ content.push({
9377
+ type: "tool-call",
9378
+ toolCallId: part.call_id,
9379
+ toolName: part.name,
9380
+ input: part.arguments,
9381
+ providerMetadata: {
9382
+ openai: {
9383
+ itemId: part.id,
9384
+ ...part.namespace != null && { namespace: part.namespace },
9385
+ ...part.caller != null && {
9386
+ caller: part.caller.type === "program" ? { type: "program", callerId: part.caller.caller_id } : part.caller
9387
+ }
9388
+ }
9198
9389
  }
9199
- };
9390
+ });
9391
+ break;
9392
+ case "custom_tool_call":
9393
+ hasFunctionCall = true;
9394
+ content.push({
9395
+ type: "tool-call",
9396
+ toolCallId: part.call_id,
9397
+ toolName: part.name,
9398
+ input: JSON.stringify(part.input),
9399
+ providerMetadata: { openai: { itemId: part.id } }
9400
+ });
9401
+ break;
9402
+ case "web_search_call":
9403
+ content.push({
9404
+ type: "tool-call",
9405
+ toolCallId: part.id,
9406
+ toolName: "web_search",
9407
+ input: "{}",
9408
+ providerExecuted: true,
9409
+ dynamic: true
9410
+ });
9411
+ content.push({
9412
+ type: "tool-result",
9413
+ toolCallId: part.id,
9414
+ toolName: "web_search",
9415
+ result: mapWebSearchOutput(part.action),
9416
+ dynamic: true
9417
+ });
9418
+ break;
9419
+ case "file_search_call":
9420
+ content.push({
9421
+ type: "tool-call",
9422
+ toolCallId: part.id,
9423
+ toolName: "file_search",
9424
+ input: "{}",
9425
+ providerExecuted: true,
9426
+ dynamic: true
9427
+ });
9428
+ content.push({
9429
+ type: "tool-result",
9430
+ toolCallId: part.id,
9431
+ toolName: "file_search",
9432
+ result: {
9433
+ queries: part.queries,
9434
+ results: (_d = (_c = part.results) == null ? void 0 : _c.map((result) => ({
9435
+ attributes: result.attributes,
9436
+ fileId: result.file_id,
9437
+ filename: result.filename,
9438
+ score: result.score,
9439
+ text: result.text
9440
+ }))) != null ? _d : null
9441
+ },
9442
+ dynamic: true
9443
+ });
9444
+ break;
9445
+ case "code_interpreter_call":
9446
+ content.push({
9447
+ type: "tool-call",
9448
+ toolCallId: part.id,
9449
+ toolName: "code_interpreter",
9450
+ input: JSON.stringify({
9451
+ code: part.code,
9452
+ containerId: part.container_id
9453
+ }),
9454
+ providerExecuted: true,
9455
+ dynamic: true
9456
+ });
9457
+ content.push({
9458
+ type: "tool-result",
9459
+ toolCallId: part.id,
9460
+ toolName: "code_interpreter",
9461
+ result: { outputs: part.outputs },
9462
+ dynamic: true
9463
+ });
9464
+ break;
9200
9465
  default:
9201
9466
  return {
9202
9467
  success: false,
@@ -9212,7 +9477,7 @@ async function convertOpenAIResponsesBatchResponse(body) {
9212
9477
  responseId: response.id,
9213
9478
  ...logprobs.length > 0 ? { logprobs } : {},
9214
9479
  ...typeof response.service_tier === "string" ? { serviceTier: response.service_tier } : {},
9215
- ...((_c = response.reasoning) == null ? void 0 : _c.context) != null ? { reasoningContext: response.reasoning.context } : {}
9480
+ ...((_e = response.reasoning) == null ? void 0 : _e.context) != null ? { reasoningContext: response.reasoning.context } : {}
9216
9481
  }
9217
9482
  };
9218
9483
  return {
@@ -9221,10 +9486,10 @@ async function convertOpenAIResponsesBatchResponse(body) {
9221
9486
  content,
9222
9487
  finishReason: {
9223
9488
  unified: mapOpenAIResponseFinishReason({
9224
- finishReason: (_d = response.incomplete_details) == null ? void 0 : _d.reason,
9225
- hasFunctionCall: false
9489
+ finishReason: (_f = response.incomplete_details) == null ? void 0 : _f.reason,
9490
+ hasFunctionCall
9226
9491
  }),
9227
- raw: (_f = (_e = response.incomplete_details) == null ? void 0 : _e.reason) != null ? _f : void 0
9492
+ raw: (_h = (_g = response.incomplete_details) == null ? void 0 : _g.reason) != null ? _h : void 0
9228
9493
  },
9229
9494
  usage: convertOpenAIResponsesUsage(response.usage),
9230
9495
  response: {
@@ -10298,7 +10563,7 @@ function getOpenAIRealtimeConnection(headers) {
10298
10563
 
10299
10564
  // src/speech-translation/openai-speech-translation-model.ts
10300
10565
  import {
10301
- InvalidArgumentError as InvalidArgumentError2
10566
+ InvalidArgumentError as InvalidArgumentError3
10302
10567
  } from "@ai-sdk/provider";
10303
10568
  import {
10304
10569
  combineHeaders as combineHeaders10,
@@ -10345,7 +10610,7 @@ var OpenAISpeechTranslationModel = class _OpenAISpeechTranslationModel {
10345
10610
  async doStream(options) {
10346
10611
  var _a2, _b, _c, _d, _e;
10347
10612
  if (options.targetLanguage == null) {
10348
- throw new InvalidArgumentError2({
10613
+ throw new InvalidArgumentError3({
10349
10614
  argument: "targetLanguage",
10350
10615
  message: `targetLanguage is required for translation model '${this.modelId}'.`
10351
10616
  });
@@ -10585,7 +10850,7 @@ function buildOpenAIRealtimeSpeechTranslationSession({
10585
10850
  }
10586
10851
  function validateOpenAISpeechTranslationInputAudioFormat(inputAudioFormat) {
10587
10852
  if (inputAudioFormat.type !== "audio/pcm" || inputAudioFormat.rate != null && inputAudioFormat.rate !== 24e3) {
10588
- throw new InvalidArgumentError2({
10853
+ throw new InvalidArgumentError3({
10589
10854
  argument: "inputAudioFormat",
10590
10855
  message: "The OpenAI Realtime translation API only supports 24kHz 16-bit PCM input audio."
10591
10856
  });
@@ -10698,7 +10963,7 @@ var OpenAISkills = class {
10698
10963
  };
10699
10964
 
10700
10965
  // src/version.ts
10701
- var VERSION = true ? "4.0.53" : "0.0.0-test";
10966
+ var VERSION = true ? "4.0.55" : "0.0.0-test";
10702
10967
 
10703
10968
  // src/openai-provider.ts
10704
10969
  function createOpenAI(options = {}) {