@ai-sdk/openai 4.0.75 → 4.0.77

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.
@@ -37,17 +37,16 @@ var openaiFailedResponseHandler = createJsonErrorResponseHandler({
37
37
 
38
38
  // src/openai-language-model-capabilities.ts
39
39
  function getOpenAILanguageModelCapabilities(modelId) {
40
- var _a2, _b, _c, _d, _e;
41
40
  const oSeriesVersion = getOSeriesVersion(modelId);
42
41
  const gptVersion = getGptVersion(modelId);
43
- const isGptChatModel = (gptVersion == null ? void 0 : gptVersion.minor) == null && ((_b = (_a2 = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _a2.startsWith("chat")) != null ? _b : false);
44
- const isGptNanoModel = (_d = (_c = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _c.startsWith("nano")) != null ? _d : false;
42
+ const isGptChatModel = gptVersion?.minor == null && (gptVersion?.variant?.startsWith("chat") ?? false);
43
+ const isGptNanoModel = gptVersion?.variant?.startsWith("nano") ?? false;
45
44
  const isGpt6OrLaterModel = gptVersion != null && gptVersion.major >= 6;
46
45
  const isGpt6SolOrLuna = modelId === "gpt-6-sol" || modelId === "gpt-6-luna";
47
46
  const supportsFlexProcessing = oSeriesVersion != null && oSeriesVersion >= 3 || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
48
47
  const supportsPriorityProcessing = modelId.startsWith("gpt-4") || gptVersion != null && gptVersion.major >= 5 && !isGptNanoModel && !isGptChatModel || oSeriesVersion != null && oSeriesVersion >= 3;
49
48
  const isReasoningModel = oSeriesVersion != null || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
50
- const supportsNonReasoningParameters = !isGpt6OrLaterModel && gptVersion != null && (gptVersion.major > 5 || gptVersion.major === 5 && ((_e = gptVersion.minor) != null ? _e : 0) >= 1);
49
+ const supportsNonReasoningParameters = !isGpt6OrLaterModel && gptVersion != null && (gptVersion.major > 5 || gptVersion.major === 5 && (gptVersion.minor ?? 0) >= 1);
51
50
  const systemMessageMode = isReasoningModel ? "developer" : "system";
52
51
  return {
53
52
  supportsFlexProcessing,
@@ -82,7 +81,6 @@ import {
82
81
  createProviderStreamError
83
82
  } from "@ai-sdk/provider-utils";
84
83
  function createOpenAIProviderStreamError(frame) {
85
- var _a2, _b;
86
84
  const streamError = parseStreamError(frame);
87
85
  if (streamError == null) {
88
86
  return void 0;
@@ -90,8 +88,8 @@ function createOpenAIProviderStreamError(frame) {
90
88
  const statusCode = getStatusCode(streamError);
91
89
  return createProviderStreamError({
92
90
  message: streamError.message,
93
- type: (_a2 = streamError.type) != null ? _a2 : void 0,
94
- code: (_b = streamError.code) != null ? _b : void 0,
91
+ type: streamError.type ?? void 0,
92
+ code: streamError.code ?? void 0,
95
93
  statusCode,
96
94
  isRetryable: isRetryableStreamError(streamError, statusCode),
97
95
  data: frame
@@ -147,7 +145,7 @@ async function throwIfOpenAIStreamErrorBeforeOutput({
147
145
  if (isOutputChunk(chunk.value)) {
148
146
  return streamForConsumer;
149
147
  }
150
- if (!accepted && (isAcceptedChunk == null ? void 0 : isAcceptedChunk(chunk.value)) === true) {
148
+ if (!accepted && isAcceptedChunk?.(chunk.value) === true) {
151
149
  accepted = true;
152
150
  }
153
151
  }
@@ -163,7 +161,7 @@ async function drainReader(reader) {
163
161
  try {
164
162
  while (!(await reader.read()).done) {
165
163
  }
166
- } catch (e) {
164
+ } catch {
167
165
  } finally {
168
166
  reader.releaseLock();
169
167
  }
@@ -193,35 +191,33 @@ function createOpenAIStreamError({
193
191
  requestBodyValues,
194
192
  responseHeaders
195
193
  }) {
196
- var _a2, _b;
197
194
  const streamError = createOpenAIProviderStreamError(frame);
198
195
  return new APICallError({
199
- message: (_a2 = streamError == null ? void 0 : streamError.message) != null ? _a2 : "OpenAI stream failed before any output was generated",
196
+ message: streamError?.message ?? "OpenAI stream failed before any output was generated",
200
197
  url,
201
198
  requestBodyValues,
202
- statusCode: (_b = streamError == null ? void 0 : streamError.statusCode) != null ? _b : 500,
199
+ statusCode: streamError?.statusCode ?? 500,
203
200
  responseHeaders,
204
201
  responseBody: JSON.stringify(frame),
205
202
  data: frame,
206
- isRetryable: streamError == null ? void 0 : streamError.isRetryable
203
+ isRetryable: streamError?.isRetryable
207
204
  });
208
205
  }
209
206
  function parseStreamError(frame) {
210
- var _a2;
211
207
  const value = asRecord(frame);
212
208
  if (value == null) {
213
209
  return void 0;
214
210
  }
215
211
  if (value.type === "response.failed") {
216
212
  const response = asRecord(value.response);
217
- const responseError = asRecord(response == null ? void 0 : response.error);
218
- return typeof (responseError == null ? void 0 : responseError.message) === "string" ? {
213
+ const responseError = asRecord(response?.error);
214
+ return typeof responseError?.message === "string" ? {
219
215
  message: responseError.message,
220
216
  code: getStringOrNumber(responseError.code),
221
217
  type: "response.failed"
222
218
  } : void 0;
223
219
  }
224
- const error = (_a2 = asRecord(value.error)) != null ? _a2 : value;
220
+ const error = asRecord(value.error) ?? value;
225
221
  return typeof error.message === "string" && (asRecord(value.error) != null || typeof error.type === "string" || "code" in error || "param" in error) ? {
226
222
  message: error.message,
227
223
  code: getStringOrNumber(error.code),
@@ -277,19 +273,18 @@ function isRetryableStreamError(error, statusCode) {
277
273
  // src/chat/convert-openai-chat-usage.ts
278
274
  import { createNullLanguageModelUsage } from "@ai-sdk/provider-utils";
279
275
  function convertOpenAIChatUsage(usage) {
280
- var _a2, _b, _c, _d, _e, _f, _g, _h;
281
276
  if (usage == null) {
282
277
  return createNullLanguageModelUsage();
283
278
  }
284
- const promptTokens = (_a2 = usage.prompt_tokens) != null ? _a2 : 0;
285
- const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
286
- const cachedTokens = (_d = (_c = usage.prompt_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : 0;
287
- const cacheWriteTokens = (_f = (_e = usage.prompt_tokens_details) == null ? void 0 : _e.cache_write_tokens) != null ? _f : void 0;
288
- const reasoningTokens = (_h = (_g = usage.completion_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : 0;
279
+ const promptTokens = usage.prompt_tokens ?? 0;
280
+ const completionTokens = usage.completion_tokens ?? 0;
281
+ const cachedTokens = usage.prompt_tokens_details?.cached_tokens ?? 0;
282
+ const cacheWriteTokens = usage.prompt_tokens_details?.cache_write_tokens ?? void 0;
283
+ const reasoningTokens = usage.completion_tokens_details?.reasoning_tokens ?? 0;
289
284
  return {
290
285
  inputTokens: {
291
286
  total: promptTokens,
292
- noCache: promptTokens - cachedTokens - (cacheWriteTokens != null ? cacheWriteTokens : 0),
287
+ noCache: promptTokens - cachedTokens - (cacheWriteTokens ?? 0),
293
288
  cacheRead: cachedTokens,
294
289
  cacheWrite: cacheWriteTokens
295
290
  },
@@ -318,14 +313,12 @@ function serializeToolCallArguments(input) {
318
313
  );
319
314
  }
320
315
  function getPromptCacheBreakpoint(providerOptions) {
321
- var _a2;
322
- return (_a2 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a2.promptCacheBreakpoint;
316
+ return providerOptions?.openai?.promptCacheBreakpoint;
323
317
  }
324
318
  function convertToOpenAIChatMessages({
325
319
  prompt,
326
320
  systemMessageMode = "system"
327
321
  }) {
328
- var _a2, _b;
329
322
  const messages = [];
330
323
  const warnings = [];
331
324
  for (const { role, content, providerOptions } of prompt) {
@@ -384,7 +377,6 @@ function convertToOpenAIChatMessages({
384
377
  messages.push({
385
378
  role: "user",
386
379
  content: content.map((part, index) => {
387
- var _a3, _b2, _c;
388
380
  switch (part.type) {
389
381
  case "text": {
390
382
  const promptCacheBreakpoint = getPromptCacheBreakpoint(
@@ -430,7 +422,7 @@ function convertToOpenAIChatMessages({
430
422
  type: "image_url",
431
423
  image_url: {
432
424
  url: part.data.type === "url" ? part.data.url.toString() : `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`,
433
- detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3.openai) == null ? void 0 : _b2.imageDetail
425
+ detail: part.providerOptions?.openai?.imageDetail
434
426
  },
435
427
  ...promptCacheBreakpoint != null && {
436
428
  prompt_cache_breakpoint: promptCacheBreakpoint
@@ -491,7 +483,7 @@ function convertToOpenAIChatMessages({
491
483
  return {
492
484
  type: "file",
493
485
  file: {
494
- filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
486
+ filename: part.filename ?? `part-${index}.pdf`,
495
487
  file_data: `data:application/pdf;base64,${convertToBase64(part.data.data)}`
496
488
  },
497
489
  ...promptCacheBreakpoint != null && {
@@ -526,7 +518,7 @@ function convertToOpenAIChatMessages({
526
518
  prompt_cache_breakpoint: promptCacheBreakpoint
527
519
  }
528
520
  });
529
- hasPromptCacheBreakpoint || (hasPromptCacheBreakpoint = promptCacheBreakpoint != null);
521
+ hasPromptCacheBreakpoint ||= promptCacheBreakpoint != null;
530
522
  break;
531
523
  }
532
524
  case "tool-call": {
@@ -555,7 +547,7 @@ function convertToOpenAIChatMessages({
555
547
  continue;
556
548
  }
557
549
  const output = toolResponse.output;
558
- const promptCacheBreakpoint = (_a2 = output.type === "content" ? output.value.map((part) => getPromptCacheBreakpoint(part.providerOptions)).find((breakpoint) => breakpoint != null) : getPromptCacheBreakpoint(output.providerOptions)) != null ? _a2 : getPromptCacheBreakpoint(toolResponse.providerOptions);
550
+ const promptCacheBreakpoint = (output.type === "content" ? output.value.map((part) => getPromptCacheBreakpoint(part.providerOptions)).find((breakpoint) => breakpoint != null) : getPromptCacheBreakpoint(output.providerOptions)) ?? getPromptCacheBreakpoint(toolResponse.providerOptions);
559
551
  let contentValue;
560
552
  switch (output.type) {
561
553
  case "text":
@@ -563,7 +555,7 @@ function convertToOpenAIChatMessages({
563
555
  contentValue = output.value;
564
556
  break;
565
557
  case "execution-denied":
566
- contentValue = (_b = output.reason) != null ? _b : "Tool call execution denied.";
558
+ contentValue = output.reason ?? "Tool call execution denied.";
567
559
  break;
568
560
  case "content":
569
561
  case "json":
@@ -1077,7 +1069,7 @@ function prepareChatTools({
1077
1069
  tools,
1078
1070
  toolChoice
1079
1071
  }) {
1080
- tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
1072
+ tools = tools?.length ? tools : void 0;
1081
1073
  const toolWarnings = [];
1082
1074
  if (tools == null) {
1083
1075
  return { tools: void 0, toolChoice: void 0, toolWarnings };
@@ -1176,15 +1168,14 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1176
1168
  reasoning,
1177
1169
  providerOptions
1178
1170
  }) {
1179
- var _a2, _b, _c, _d, _e, _f;
1180
1171
  const warnings = [];
1181
- const openaiOptions = (_a2 = await parseProviderOptions({
1172
+ const openaiOptions = await parseProviderOptions({
1182
1173
  provider: "openai",
1183
1174
  providerOptions,
1184
1175
  schema: openaiLanguageModelChatOptions
1185
- })) != null ? _a2 : {};
1176
+ }) ?? {};
1186
1177
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
1187
- let resolvedReasoningEffort = (_b = openaiOptions.reasoningEffort) != null ? _b : isCustomReasoning(reasoning) ? reasoning : void 0;
1178
+ let resolvedReasoningEffort = openaiOptions.reasoningEffort ?? (isCustomReasoning(reasoning) ? reasoning : void 0);
1188
1179
  if (resolvedReasoningEffort != null && modelCapabilities.supportedReasoningEfforts != null && !modelCapabilities.supportedReasoningEfforts.includes(
1189
1180
  resolvedReasoningEffort
1190
1181
  )) {
@@ -1195,19 +1186,19 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1195
1186
  });
1196
1187
  resolvedReasoningEffort = void 0;
1197
1188
  }
1198
- const isReasoningModel = (_c = openaiOptions.forceReasoning) != null ? _c : modelCapabilities.isReasoningModel;
1189
+ const isReasoningModel = openaiOptions.forceReasoning ?? modelCapabilities.isReasoningModel;
1199
1190
  if (topK != null) {
1200
1191
  warnings.push({ type: "unsupported", feature: "topK" });
1201
1192
  }
1202
1193
  const { messages, warnings: messageWarnings } = convertToOpenAIChatMessages(
1203
1194
  {
1204
1195
  prompt,
1205
- systemMessageMode: (_d = openaiOptions.systemMessageMode) != null ? _d : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode
1196
+ systemMessageMode: openaiOptions.systemMessageMode ?? (isReasoningModel ? "developer" : modelCapabilities.systemMessageMode)
1206
1197
  }
1207
1198
  );
1208
1199
  warnings.push(...messageWarnings);
1209
- const strictJsonSchema = (_e = openaiOptions.strictJsonSchema) != null ? _e : true;
1210
- const normalizedResponseFormatSchema = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? normalizeOpenAIJsonSchema(responseFormat.schema) : void 0;
1200
+ const strictJsonSchema = openaiOptions.strictJsonSchema ?? true;
1201
+ const normalizedResponseFormatSchema = responseFormat?.type === "json" && responseFormat.schema != null ? normalizeOpenAIJsonSchema(responseFormat.schema) : void 0;
1211
1202
  if (normalizedResponseFormatSchema != null) {
1212
1203
  warnings.push(...normalizedResponseFormatSchema.warnings);
1213
1204
  }
@@ -1226,12 +1217,12 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1226
1217
  top_p: topP,
1227
1218
  frequency_penalty: frequencyPenalty,
1228
1219
  presence_penalty: presencePenalty,
1229
- response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? normalizedResponseFormatSchema != null ? {
1220
+ response_format: responseFormat?.type === "json" ? normalizedResponseFormatSchema != null ? {
1230
1221
  type: "json_schema",
1231
1222
  json_schema: {
1232
1223
  schema: normalizedResponseFormatSchema.schema,
1233
1224
  strict: strictJsonSchema,
1234
- name: (_f = responseFormat.name) != null ? _f : "response",
1225
+ name: responseFormat.name ?? "response",
1235
1226
  description: responseFormat.description
1236
1227
  }
1237
1228
  } : { type: "json_object" } : void 0,
@@ -1367,7 +1358,6 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1367
1358
  };
1368
1359
  }
1369
1360
  async doGenerate(options) {
1370
- var _a2, _b, _c, _d, _e, _f, _g, _h;
1371
1361
  const { args: body, warnings } = await this.getArgs(options);
1372
1362
  const {
1373
1363
  responseHeaders,
@@ -1378,7 +1368,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1378
1368
  path: "/chat/completions",
1379
1369
  modelId: this.modelId
1380
1370
  }),
1381
- headers: combineHeaders((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
1371
+ headers: combineHeaders(this.config.headers?.(), options.headers),
1382
1372
  body,
1383
1373
  failedResponseHandler: openaiFailedResponseHandler,
1384
1374
  successfulResponseHandler: createJsonResponseHandler(
@@ -1395,11 +1385,11 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1395
1385
  });
1396
1386
  }
1397
1387
  const content = [];
1398
- const text = choice.message.content != null && choice.message.content.length > 0 ? choice.message.content : (_c = choice.message.audio) == null ? void 0 : _c.transcript;
1388
+ const text = choice.message.content != null && choice.message.content.length > 0 ? choice.message.content : choice.message.audio?.transcript;
1399
1389
  if (text != null && text.length > 0) {
1400
1390
  content.push({ type: "text", text });
1401
1391
  }
1402
- for (const toolCall of (_d = choice.message.tool_calls) != null ? _d : []) {
1392
+ for (const toolCall of choice.message.tool_calls ?? []) {
1403
1393
  content.push({
1404
1394
  type: "tool-call",
1405
1395
  toolCallId: toolCall.id || generateId(),
@@ -1407,7 +1397,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1407
1397
  input: toolCall.function.arguments
1408
1398
  });
1409
1399
  }
1410
- for (const annotation of (_e = choice.message.annotations) != null ? _e : []) {
1400
+ for (const annotation of choice.message.annotations ?? []) {
1411
1401
  content.push({
1412
1402
  type: "source",
1413
1403
  sourceType: "url",
@@ -1416,22 +1406,22 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1416
1406
  title: annotation.url_citation.title
1417
1407
  });
1418
1408
  }
1419
- const completionTokenDetails = (_f = response.usage) == null ? void 0 : _f.completion_tokens_details;
1409
+ const completionTokenDetails = response.usage?.completion_tokens_details;
1420
1410
  const providerMetadata = { openai: {} };
1421
- if ((completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens) != null) {
1422
- providerMetadata.openai.acceptedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens;
1411
+ if (completionTokenDetails?.accepted_prediction_tokens != null) {
1412
+ providerMetadata.openai.acceptedPredictionTokens = completionTokenDetails?.accepted_prediction_tokens;
1423
1413
  }
1424
- if ((completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens) != null) {
1425
- providerMetadata.openai.rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
1414
+ if (completionTokenDetails?.rejected_prediction_tokens != null) {
1415
+ providerMetadata.openai.rejectedPredictionTokens = completionTokenDetails?.rejected_prediction_tokens;
1426
1416
  }
1427
- if (((_g = choice.logprobs) == null ? void 0 : _g.content) != null) {
1417
+ if (choice.logprobs?.content != null) {
1428
1418
  providerMetadata.openai.logprobs = choice.logprobs.content;
1429
1419
  }
1430
1420
  return {
1431
1421
  content,
1432
1422
  finishReason: {
1433
1423
  unified: mapOpenAIFinishReason(choice.finish_reason),
1434
- raw: (_h = choice.finish_reason) != null ? _h : void 0
1424
+ raw: choice.finish_reason ?? void 0
1435
1425
  },
1436
1426
  usage: convertOpenAIChatUsage(response.usage),
1437
1427
  request: { body },
@@ -1445,7 +1435,6 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1445
1435
  };
1446
1436
  }
1447
1437
  async doStream(options) {
1448
- var _a2, _b;
1449
1438
  const { args, warnings } = await this.getArgs(options);
1450
1439
  const body = {
1451
1440
  ...args,
@@ -1460,7 +1449,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1460
1449
  });
1461
1450
  const { responseHeaders, value: response } = await postJsonToApi({
1462
1451
  url,
1463
- headers: combineHeaders((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
1452
+ headers: combineHeaders(this.config.headers?.(), options.headers),
1464
1453
  body,
1465
1454
  failedResponseHandler: openaiFailedResponseHandler,
1466
1455
  successfulResponseHandler: createEventSourceResponseHandler(
@@ -1497,7 +1486,6 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1497
1486
  controller.enqueue({ type: "stream-start", warnings });
1498
1487
  },
1499
1488
  transform(chunk, controller) {
1500
- var _a3, _b2, _c, _d, _e, _f;
1501
1489
  if (options.includeRawChunks) {
1502
1490
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1503
1491
  }
@@ -1511,7 +1499,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1511
1499
  finishReason = { unified: "error", raw: void 0 };
1512
1500
  controller.enqueue({
1513
1501
  type: "error",
1514
- error: (_a3 = createOpenAIProviderStreamError(value.error)) != null ? _a3 : value.error
1502
+ error: createOpenAIProviderStreamError(value.error) ?? value.error
1515
1503
  });
1516
1504
  return;
1517
1505
  }
@@ -1527,24 +1515,24 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1527
1515
  }
1528
1516
  if (value.usage != null) {
1529
1517
  usage = value.usage;
1530
- if (((_b2 = value.usage.completion_tokens_details) == null ? void 0 : _b2.accepted_prediction_tokens) != null) {
1531
- providerMetadata.openai.acceptedPredictionTokens = (_c = value.usage.completion_tokens_details) == null ? void 0 : _c.accepted_prediction_tokens;
1518
+ if (value.usage.completion_tokens_details?.accepted_prediction_tokens != null) {
1519
+ providerMetadata.openai.acceptedPredictionTokens = value.usage.completion_tokens_details?.accepted_prediction_tokens;
1532
1520
  }
1533
- if (((_d = value.usage.completion_tokens_details) == null ? void 0 : _d.rejected_prediction_tokens) != null) {
1534
- providerMetadata.openai.rejectedPredictionTokens = (_e = value.usage.completion_tokens_details) == null ? void 0 : _e.rejected_prediction_tokens;
1521
+ if (value.usage.completion_tokens_details?.rejected_prediction_tokens != null) {
1522
+ providerMetadata.openai.rejectedPredictionTokens = value.usage.completion_tokens_details?.rejected_prediction_tokens;
1535
1523
  }
1536
1524
  }
1537
1525
  const choice = value.choices[0];
1538
- if ((choice == null ? void 0 : choice.finish_reason) != null) {
1526
+ if (choice?.finish_reason != null) {
1539
1527
  finishReason = {
1540
1528
  unified: mapOpenAIFinishReason(choice.finish_reason),
1541
1529
  raw: choice.finish_reason
1542
1530
  };
1543
1531
  }
1544
- if (((_f = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _f.content) != null) {
1532
+ if (choice?.logprobs?.content != null) {
1545
1533
  providerMetadata.openai.logprobs = choice.logprobs.content;
1546
1534
  }
1547
- if ((choice == null ? void 0 : choice.delta) == null) {
1535
+ if (choice?.delta == null) {
1548
1536
  return;
1549
1537
  }
1550
1538
  const delta = choice.delta;
@@ -1602,7 +1590,7 @@ function isOpenAIChatOutputChunk(chunk) {
1602
1590
  }
1603
1591
  return chunk.choices.some((choice) => {
1604
1592
  const delta = choice.delta;
1605
- return (delta == null ? void 0 : delta.content) != null && delta.content.length > 0 || (delta == null ? void 0 : delta.tool_calls) != null && delta.tool_calls.length > 0 || (delta == null ? void 0 : delta.annotations) != null && delta.annotations.length > 0;
1593
+ return delta?.content != null && delta.content.length > 0 || delta?.tool_calls != null && delta.tool_calls.length > 0 || delta?.annotations != null && delta.annotations.length > 0;
1606
1594
  });
1607
1595
  }
1608
1596
 
@@ -1621,21 +1609,20 @@ import {
1621
1609
  // src/completion/convert-openai-completion-usage.ts
1622
1610
  import { createNullLanguageModelUsage as createNullLanguageModelUsage2 } from "@ai-sdk/provider-utils";
1623
1611
  function convertOpenAICompletionUsage(usage) {
1624
- var _a2, _b, _c, _d;
1625
1612
  if (usage == null) {
1626
1613
  return createNullLanguageModelUsage2();
1627
1614
  }
1628
- const promptTokens = (_a2 = usage.prompt_tokens) != null ? _a2 : 0;
1629
- const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
1615
+ const promptTokens = usage.prompt_tokens ?? 0;
1616
+ const completionTokens = usage.completion_tokens ?? 0;
1630
1617
  return {
1631
1618
  inputTokens: {
1632
- total: (_c = usage.prompt_tokens) != null ? _c : void 0,
1619
+ total: usage.prompt_tokens ?? void 0,
1633
1620
  noCache: promptTokens,
1634
1621
  cacheRead: void 0,
1635
1622
  cacheWrite: void 0
1636
1623
  },
1637
1624
  outputTokens: {
1638
- total: (_d = usage.completion_tokens) != null ? _d : void 0,
1625
+ total: usage.completion_tokens ?? void 0,
1639
1626
  text: completionTokens,
1640
1627
  reasoning: void 0
1641
1628
  },
@@ -1909,7 +1896,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
1909
1896
  if (topK != null) {
1910
1897
  warnings.push({ type: "unsupported", feature: "topK" });
1911
1898
  }
1912
- if (tools == null ? void 0 : tools.length) {
1899
+ if (tools?.length) {
1913
1900
  warnings.push({ type: "unsupported", feature: "tools" });
1914
1901
  }
1915
1902
  if (toolChoice != null) {
@@ -1923,7 +1910,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
1923
1910
  });
1924
1911
  }
1925
1912
  const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt });
1926
- const stop = [...stopSequences != null ? stopSequences : [], ...userStopSequences != null ? userStopSequences : []];
1913
+ const stop = [...stopSequences ?? [], ...userStopSequences ?? []];
1927
1914
  return {
1928
1915
  args: {
1929
1916
  // model id:
@@ -1931,7 +1918,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
1931
1918
  // model specific settings:
1932
1919
  echo: openaiOptions.echo,
1933
1920
  logit_bias: openaiOptions.logitBias,
1934
- logprobs: (openaiOptions == null ? void 0 : openaiOptions.logprobs) === true ? 0 : (openaiOptions == null ? void 0 : openaiOptions.logprobs) === false ? void 0 : openaiOptions == null ? void 0 : openaiOptions.logprobs,
1921
+ logprobs: openaiOptions?.logprobs === true ? 0 : openaiOptions?.logprobs === false ? void 0 : openaiOptions?.logprobs,
1935
1922
  suffix: openaiOptions.suffix,
1936
1923
  user: openaiOptions.user,
1937
1924
  // standardized settings:
@@ -1950,7 +1937,6 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
1950
1937
  };
1951
1938
  }
1952
1939
  async doGenerate(options) {
1953
- var _a2, _b, _c;
1954
1940
  const { args, warnings } = await this.getArgs(options);
1955
1941
  const {
1956
1942
  responseHeaders,
@@ -1961,7 +1947,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
1961
1947
  path: "/completions",
1962
1948
  modelId: this.modelId
1963
1949
  }),
1964
- headers: combineHeaders2((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
1950
+ headers: combineHeaders2(this.config.headers?.(), options.headers),
1965
1951
  body: args,
1966
1952
  failedResponseHandler: openaiFailedResponseHandler,
1967
1953
  successfulResponseHandler: createJsonResponseHandler2(
@@ -1980,7 +1966,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
1980
1966
  usage: convertOpenAICompletionUsage(response.usage),
1981
1967
  finishReason: {
1982
1968
  unified: mapOpenAIFinishReason2(choice.finish_reason),
1983
- raw: (_c = choice.finish_reason) != null ? _c : void 0
1969
+ raw: choice.finish_reason ?? void 0
1984
1970
  },
1985
1971
  request: { body: args },
1986
1972
  response: {
@@ -1993,7 +1979,6 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
1993
1979
  };
1994
1980
  }
1995
1981
  async doStream(options) {
1996
- var _a2, _b;
1997
1982
  const { args, warnings } = await this.getArgs(options);
1998
1983
  const body = {
1999
1984
  ...args,
@@ -2008,7 +1993,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
2008
1993
  });
2009
1994
  const { responseHeaders, value: response } = await postJsonToApi2({
2010
1995
  url,
2011
- headers: combineHeaders2((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
1996
+ headers: combineHeaders2(this.config.headers?.(), options.headers),
2012
1997
  body,
2013
1998
  failedResponseHandler: openaiFailedResponseHandler,
2014
1999
  successfulResponseHandler: createEventSourceResponseHandler2(
@@ -2039,7 +2024,6 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
2039
2024
  controller.enqueue({ type: "stream-start", warnings });
2040
2025
  },
2041
2026
  transform(chunk, controller) {
2042
- var _a3;
2043
2027
  if (options.includeRawChunks) {
2044
2028
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2045
2029
  }
@@ -2053,7 +2037,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
2053
2037
  finishReason = { unified: "error", raw: void 0 };
2054
2038
  controller.enqueue({
2055
2039
  type: "error",
2056
- error: (_a3 = createOpenAIProviderStreamError(value.error)) != null ? _a3 : value.error
2040
+ error: createOpenAIProviderStreamError(value.error) ?? value.error
2057
2041
  });
2058
2042
  return;
2059
2043
  }
@@ -2069,16 +2053,16 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
2069
2053
  usage = value.usage;
2070
2054
  }
2071
2055
  const choice = value.choices[0];
2072
- if ((choice == null ? void 0 : choice.finish_reason) != null) {
2056
+ if (choice?.finish_reason != null) {
2073
2057
  finishReason = {
2074
2058
  unified: mapOpenAIFinishReason2(choice.finish_reason),
2075
2059
  raw: choice.finish_reason
2076
2060
  };
2077
2061
  }
2078
- if ((choice == null ? void 0 : choice.logprobs) != null) {
2062
+ if (choice?.logprobs != null) {
2079
2063
  providerMetadata.openai.logprobs = choice.logprobs;
2080
2064
  }
2081
- if ((choice == null ? void 0 : choice.text) != null && choice.text.length > 0) {
2065
+ if (choice?.text != null && choice.text.length > 0) {
2082
2066
  controller.enqueue({
2083
2067
  type: "text-delta",
2084
2068
  id: "0",
@@ -2188,7 +2172,6 @@ var OpenAIEmbeddingModel = class _OpenAIEmbeddingModel {
2188
2172
  abortSignal,
2189
2173
  providerOptions
2190
2174
  }) {
2191
- var _a2, _b, _c;
2192
2175
  if (values.length > this.maxEmbeddingsPerCall) {
2193
2176
  throw new TooManyEmbeddingValuesForCallError({
2194
2177
  provider: this.provider,
@@ -2197,11 +2180,11 @@ var OpenAIEmbeddingModel = class _OpenAIEmbeddingModel {
2197
2180
  values
2198
2181
  });
2199
2182
  }
2200
- const openaiOptions = (_a2 = await parseProviderOptions3({
2183
+ const openaiOptions = await parseProviderOptions3({
2201
2184
  provider: "openai",
2202
2185
  providerOptions,
2203
2186
  schema: openaiEmbeddingModelOptions
2204
- })) != null ? _a2 : {};
2187
+ }) ?? {};
2205
2188
  const {
2206
2189
  responseHeaders,
2207
2190
  value: response,
@@ -2211,7 +2194,7 @@ var OpenAIEmbeddingModel = class _OpenAIEmbeddingModel {
2211
2194
  path: "/embeddings",
2212
2195
  modelId: this.modelId
2213
2196
  }),
2214
- headers: combineHeaders3((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), headers),
2197
+ headers: combineHeaders3(this.config.headers?.(), headers),
2215
2198
  body: {
2216
2199
  model: this.modelId,
2217
2200
  input: values,
@@ -2306,8 +2289,7 @@ function hasDefaultResponseFormat(modelId) {
2306
2289
  );
2307
2290
  }
2308
2291
  function getMaxImagesPerCall(modelId) {
2309
- var _a2;
2310
- return (_a2 = modelMaxImagesPerCall[modelId]) != null ? _a2 : modelId.startsWith("gpt-image-") ? 10 : 1;
2292
+ return modelMaxImagesPerCall[modelId] ?? (modelId.startsWith("gpt-image-") ? 10 : 1);
2311
2293
  }
2312
2294
  var baseImageModelOptionsObject = z9.object({
2313
2295
  /**
@@ -2404,7 +2386,6 @@ var OpenAIImageModel = class _OpenAIImageModel {
2404
2386
  headers,
2405
2387
  abortSignal
2406
2388
  }) {
2407
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
2408
2389
  const warnings = [];
2409
2390
  if (aspectRatio != null) {
2410
2391
  warnings.push({
@@ -2416,19 +2397,19 @@ var OpenAIImageModel = class _OpenAIImageModel {
2416
2397
  if (seed != null) {
2417
2398
  warnings.push({ type: "unsupported", feature: "seed" });
2418
2399
  }
2419
- const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
2400
+ const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
2420
2401
  if (files != null) {
2421
- const openaiOptions2 = (_d = await parseProviderOptions4({
2402
+ const openaiOptions2 = await parseProviderOptions4({
2422
2403
  provider: "openai",
2423
2404
  providerOptions,
2424
2405
  schema: openaiImageModelEditOptions
2425
- })) != null ? _d : {};
2406
+ }) ?? {};
2426
2407
  const { value: response2, responseHeaders: responseHeaders2 } = await postFormDataToApi({
2427
2408
  url: this.config.url({
2428
2409
  path: "/images/edits",
2429
2410
  modelId: this.modelId
2430
2411
  }),
2431
- headers: combineHeaders4((_f = (_e = this.config).headers) == null ? void 0 : _f.call(_e), headers),
2412
+ headers: combineHeaders4(this.config.headers?.(), headers),
2432
2413
  formData: convertToFormData({
2433
2414
  model: this.modelId,
2434
2415
  prompt,
@@ -2467,9 +2448,9 @@ var OpenAIImageModel = class _OpenAIImageModel {
2467
2448
  images: response2.data.map((item) => item.b64_json),
2468
2449
  warnings,
2469
2450
  usage: response2.usage != null ? {
2470
- inputTokens: (_g = response2.usage.input_tokens) != null ? _g : void 0,
2471
- outputTokens: (_h = response2.usage.output_tokens) != null ? _h : void 0,
2472
- totalTokens: (_i = response2.usage.total_tokens) != null ? _i : void 0
2451
+ inputTokens: response2.usage.input_tokens ?? void 0,
2452
+ outputTokens: response2.usage.output_tokens ?? void 0,
2453
+ totalTokens: response2.usage.total_tokens ?? void 0
2473
2454
  } : void 0,
2474
2455
  response: {
2475
2456
  timestamp: currentDate,
@@ -2478,37 +2459,34 @@ var OpenAIImageModel = class _OpenAIImageModel {
2478
2459
  },
2479
2460
  providerMetadata: {
2480
2461
  openai: {
2481
- images: response2.data.map((item, index) => {
2482
- var _a3, _b2, _c2, _d2, _e2, _f2;
2483
- return {
2484
- ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
2485
- created: (_a3 = response2.created) != null ? _a3 : void 0,
2486
- size: (_b2 = response2.size) != null ? _b2 : void 0,
2487
- quality: (_c2 = response2.quality) != null ? _c2 : void 0,
2488
- background: (_d2 = response2.background) != null ? _d2 : void 0,
2489
- outputFormat: (_e2 = response2.output_format) != null ? _e2 : void 0,
2490
- ...distributeTokenDetails(
2491
- (_f2 = response2.usage) == null ? void 0 : _f2.input_tokens_details,
2492
- index,
2493
- response2.data.length
2494
- )
2495
- };
2496
- })
2462
+ images: response2.data.map((item, index) => ({
2463
+ ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
2464
+ created: response2.created ?? void 0,
2465
+ size: response2.size ?? void 0,
2466
+ quality: response2.quality ?? void 0,
2467
+ background: response2.background ?? void 0,
2468
+ outputFormat: response2.output_format ?? void 0,
2469
+ ...distributeTokenDetails(
2470
+ response2.usage?.input_tokens_details,
2471
+ index,
2472
+ response2.data.length
2473
+ )
2474
+ }))
2497
2475
  }
2498
2476
  }
2499
2477
  };
2500
2478
  }
2501
- const openaiOptions = (_j = await parseProviderOptions4({
2479
+ const openaiOptions = await parseProviderOptions4({
2502
2480
  provider: "openai",
2503
2481
  providerOptions,
2504
2482
  schema: openaiImageModelGenerationOptions
2505
- })) != null ? _j : {};
2483
+ }) ?? {};
2506
2484
  const { value: response, responseHeaders } = await postJsonToApi4({
2507
2485
  url: this.config.url({
2508
2486
  path: "/images/generations",
2509
2487
  modelId: this.modelId
2510
2488
  }),
2511
- headers: combineHeaders4((_l = (_k = this.config).headers) == null ? void 0 : _l.call(_k), headers),
2489
+ headers: combineHeaders4(this.config.headers?.(), headers),
2512
2490
  body: {
2513
2491
  model: this.modelId,
2514
2492
  prompt,
@@ -2534,9 +2512,9 @@ var OpenAIImageModel = class _OpenAIImageModel {
2534
2512
  images: response.data.map((item) => item.b64_json),
2535
2513
  warnings,
2536
2514
  usage: response.usage != null ? {
2537
- inputTokens: (_m = response.usage.input_tokens) != null ? _m : void 0,
2538
- outputTokens: (_n = response.usage.output_tokens) != null ? _n : void 0,
2539
- totalTokens: (_o = response.usage.total_tokens) != null ? _o : void 0
2515
+ inputTokens: response.usage.input_tokens ?? void 0,
2516
+ outputTokens: response.usage.output_tokens ?? void 0,
2517
+ totalTokens: response.usage.total_tokens ?? void 0
2540
2518
  } : void 0,
2541
2519
  response: {
2542
2520
  timestamp: currentDate,
@@ -2545,22 +2523,19 @@ var OpenAIImageModel = class _OpenAIImageModel {
2545
2523
  },
2546
2524
  providerMetadata: {
2547
2525
  openai: {
2548
- images: response.data.map((item, index) => {
2549
- var _a3, _b2, _c2, _d2, _e2, _f2;
2550
- return {
2551
- ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
2552
- created: (_a3 = response.created) != null ? _a3 : void 0,
2553
- size: (_b2 = response.size) != null ? _b2 : void 0,
2554
- quality: (_c2 = response.quality) != null ? _c2 : void 0,
2555
- background: (_d2 = response.background) != null ? _d2 : void 0,
2556
- outputFormat: (_e2 = response.output_format) != null ? _e2 : void 0,
2557
- ...distributeTokenDetails(
2558
- (_f2 = response.usage) == null ? void 0 : _f2.input_tokens_details,
2559
- index,
2560
- response.data.length
2561
- )
2562
- };
2563
- })
2526
+ images: response.data.map((item, index) => ({
2527
+ ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
2528
+ created: response.created ?? void 0,
2529
+ size: response.size ?? void 0,
2530
+ quality: response.quality ?? void 0,
2531
+ background: response.background ?? void 0,
2532
+ outputFormat: response.output_format ?? void 0,
2533
+ ...distributeTokenDetails(
2534
+ response.usage?.input_tokens_details,
2535
+ index,
2536
+ response.data.length
2537
+ )
2538
+ }))
2564
2539
  }
2565
2540
  }
2566
2541
  };
@@ -2807,7 +2782,6 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
2807
2782
  mediaType,
2808
2783
  providerOptions
2809
2784
  }) {
2810
- var _a2, _b;
2811
2785
  const warnings = [];
2812
2786
  const openAIOptions = await parseProviderOptions5({
2813
2787
  provider: "openai",
@@ -2827,7 +2801,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
2827
2801
  formData.append("response_format", "verbose_json");
2828
2802
  }
2829
2803
  const isDiarizationModel = this.modelId === "gpt-4o-transcribe-diarize";
2830
- const chunkingStrategy = (_a2 = openAIOptions == null ? void 0 : openAIOptions.chunkingStrategy) != null ? _a2 : isDiarizationModel ? "auto" : void 0;
2804
+ const chunkingStrategy = openAIOptions?.chunkingStrategy ?? (isDiarizationModel ? "auto" : void 0);
2831
2805
  if (openAIOptions) {
2832
2806
  const isGpt4oTranscribeModel = [
2833
2807
  "gpt-4o-transcribe",
@@ -2840,7 +2814,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
2840
2814
  // https://platform.openai.com/docs/api-reference/audio/createTranscription#audio_createtranscription-response_format
2841
2815
  // prefer verbose_json to get segments for models that support it
2842
2816
  ...this.modelId !== "whisper-1" && {
2843
- response_format: (_b = openAIOptions.responseFormat) != null ? _b : isDiarizationModel ? "diarized_json" : isGpt4oTranscribeModel ? "json" : "verbose_json"
2817
+ response_format: openAIOptions.responseFormat ?? (isDiarizationModel ? "diarized_json" : isGpt4oTranscribeModel ? "json" : "verbose_json")
2844
2818
  },
2845
2819
  temperature: openAIOptions.temperature,
2846
2820
  timestamp_granularities: openAIOptions.timestampGranularities
@@ -2882,13 +2856,12 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
2882
2856
  };
2883
2857
  }
2884
2858
  async doGenerate(options) {
2885
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2886
2859
  if (isRealtimeTranscriptionModelId(this.modelId)) {
2887
2860
  throw new UnsupportedFunctionalityError5({
2888
2861
  functionality: `non-streaming transcription with ${this.modelId}`
2889
2862
  });
2890
2863
  }
2891
- const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
2864
+ const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
2892
2865
  const { formData, warnings } = await this.getArgs(options);
2893
2866
  const {
2894
2867
  value: response,
@@ -2899,7 +2872,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
2899
2872
  path: "/audio/transcriptions",
2900
2873
  modelId: this.modelId
2901
2874
  }),
2902
- headers: combineHeaders5((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), options.headers),
2875
+ headers: combineHeaders5(this.config.headers?.(), options.headers),
2903
2876
  formData,
2904
2877
  failedResponseHandler: openaiFailedResponseHandler,
2905
2878
  successfulResponseHandler: createJsonResponseHandler5(
@@ -2909,7 +2882,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
2909
2882
  fetch: this.config.fetch
2910
2883
  });
2911
2884
  const language = response.language != null && response.language in languageMap ? languageMap[response.language] : void 0;
2912
- const diarizedSegments = (_f = response.segments) == null ? void 0 : _f.flatMap(
2885
+ const diarizedSegments = response.segments?.flatMap(
2913
2886
  (segment) => "speaker" in segment ? [
2914
2887
  {
2915
2888
  text: segment.text,
@@ -2921,17 +2894,17 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
2921
2894
  );
2922
2895
  return {
2923
2896
  text: response.text,
2924
- segments: (_j = (_i = (_g = response.segments) == null ? void 0 : _g.map((segment) => ({
2897
+ segments: response.segments?.map((segment) => ({
2925
2898
  text: segment.text,
2926
2899
  startSecond: segment.start,
2927
2900
  endSecond: segment.end
2928
- }))) != null ? _i : (_h = response.words) == null ? void 0 : _h.map((word) => ({
2901
+ })) ?? response.words?.map((word) => ({
2929
2902
  text: word.word,
2930
2903
  startSecond: word.start,
2931
2904
  endSecond: word.end
2932
- }))) != null ? _j : [],
2905
+ })) ?? [],
2933
2906
  language,
2934
- durationInSeconds: (_k = response.duration) != null ? _k : void 0,
2907
+ durationInSeconds: response.duration ?? void 0,
2935
2908
  warnings,
2936
2909
  response: {
2937
2910
  timestamp: currentDate,
@@ -2949,20 +2922,19 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
2949
2922
  };
2950
2923
  }
2951
2924
  async doStream(options) {
2952
- var _a2, _b, _c, _d, _e, _f, _g;
2953
2925
  if (!isRealtimeTranscriptionModelId(this.modelId)) {
2954
2926
  throw new UnsupportedFunctionalityError5({
2955
2927
  functionality: `streaming transcription with ${this.modelId}`
2956
2928
  });
2957
2929
  }
2958
- const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
2930
+ const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
2959
2931
  const openAIOptions = await parseProviderOptions5({
2960
2932
  provider: "openai",
2961
2933
  providerOptions: options.providerOptions,
2962
2934
  schema: openAITranscriptionModelOptions
2963
2935
  });
2964
2936
  const warnings = [];
2965
- const rawOpenAIOptions = (_e = (_d = options.providerOptions) == null ? void 0 : _d.openai) != null ? _e : {};
2937
+ const rawOpenAIOptions = options.providerOptions?.openai ?? {};
2966
2938
  for (const option of [
2967
2939
  "include",
2968
2940
  "prompt",
@@ -2977,7 +2949,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
2977
2949
  });
2978
2950
  }
2979
2951
  }
2980
- const headers = combineHeaders5((_g = (_f = this.config).headers) == null ? void 0 : _g.call(_f), options.headers);
2952
+ const headers = combineHeaders5(this.config.headers?.(), options.headers);
2981
2953
  const sessionUpdate = buildOpenAIRealtimeTranscriptionSession({
2982
2954
  modelId: this.modelId,
2983
2955
  inputAudioFormat: options.inputAudioFormat,
@@ -2999,7 +2971,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
2999
2971
  ),
3000
2972
  headers,
3001
2973
  sessionUpdate,
3002
- language: openAIOptions == null ? void 0 : openAIOptions.language,
2974
+ language: openAIOptions?.language,
3003
2975
  warnings,
3004
2976
  audio: options.audio,
3005
2977
  abortSignal: options.abortSignal,
@@ -3035,7 +3007,7 @@ function createOpenAIRealtimeTranscriptionStream({
3035
3007
  void audio.cancel().catch(() => {
3036
3008
  });
3037
3009
  }
3038
- connection == null ? void 0 : connection.close(closeCode);
3010
+ connection?.close(closeCode);
3039
3011
  };
3040
3012
  const finishWithError = (error) => {
3041
3013
  if (finished) return;
@@ -3094,7 +3066,6 @@ function createOpenAIRealtimeTranscriptionStream({
3094
3066
  void sendAudio(socket).catch(finishWithError);
3095
3067
  },
3096
3068
  onMessageText: async (text) => {
3097
- var _a2, _b, _c, _d;
3098
3069
  const parsed = await safeParseJSON({ text });
3099
3070
  if (!parsed.success) return;
3100
3071
  const raw = parsed.value;
@@ -3106,17 +3077,17 @@ function createOpenAIRealtimeTranscriptionStream({
3106
3077
  controller.enqueue({
3107
3078
  type: "transcript-delta",
3108
3079
  id: raw.item_id,
3109
- delta: (_a2 = raw.delta) != null ? _a2 : ""
3080
+ delta: raw.delta ?? ""
3110
3081
  });
3111
3082
  break;
3112
3083
  }
3113
3084
  case "conversation.item.input_audio_transcription.completed": {
3114
- finish((_b = raw.transcript) != null ? _b : "", raw.item_id);
3085
+ finish(raw.transcript ?? "", raw.item_id);
3115
3086
  break;
3116
3087
  }
3117
3088
  case "error": {
3118
3089
  finishWithError(
3119
- new Error((_d = (_c = raw.error) == null ? void 0 : _c.message) != null ? _d : "OpenAI realtime error")
3090
+ new Error(raw.error?.message ?? "OpenAI realtime error")
3120
3091
  );
3121
3092
  break;
3122
3093
  }
@@ -3145,7 +3116,6 @@ function buildOpenAIRealtimeTranscriptionSession({
3145
3116
  inputAudioFormat,
3146
3117
  providerOptions
3147
3118
  }) {
3148
- var _a2, _b;
3149
3119
  return {
3150
3120
  type: "session.update",
3151
3121
  session: {
@@ -3158,25 +3128,24 @@ function buildOpenAIRealtimeTranscriptionSession({
3158
3128
  },
3159
3129
  transcription: {
3160
3130
  model: modelId,
3161
- ...(providerOptions == null ? void 0 : providerOptions.language) != null ? { language: providerOptions.language } : {},
3162
- ...((_a2 = providerOptions == null ? void 0 : providerOptions.streaming) == null ? void 0 : _a2.delay) != null ? { delay: providerOptions.streaming.delay } : {}
3131
+ ...providerOptions?.language != null ? { language: providerOptions.language } : {},
3132
+ ...providerOptions?.streaming?.delay != null ? { delay: providerOptions.streaming.delay } : {}
3163
3133
  },
3164
3134
  turn_detection: null
3165
3135
  }
3166
3136
  },
3167
- ...((_b = providerOptions == null ? void 0 : providerOptions.streaming) == null ? void 0 : _b.include) != null ? { include: providerOptions.streaming.include } : {}
3137
+ ...providerOptions?.streaming?.include != null ? { include: providerOptions.streaming.include } : {}
3168
3138
  }
3169
3139
  };
3170
3140
  }
3171
3141
  function getOpenAIRealtimeConnection(headers) {
3172
- var _a2;
3173
3142
  let authorization;
3174
3143
  for (const [key, value] of Object.entries(headers)) {
3175
3144
  if (key.toLowerCase() === "authorization" && value != null) {
3176
3145
  authorization = value;
3177
3146
  }
3178
3147
  }
3179
- const token = (_a2 = authorization == null ? void 0 : authorization.match(/^bearer\s+(.+)$/i)) == null ? void 0 : _a2[1];
3148
+ const token = authorization?.match(/^bearer\s+(.+)$/i)?.[1];
3180
3149
  if (token == null) {
3181
3150
  return { protocols: ["realtime"], headers };
3182
3151
  }
@@ -3244,7 +3213,6 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
3244
3213
  language,
3245
3214
  providerOptions
3246
3215
  }) {
3247
- var _a2, _b;
3248
3216
  const warnings = [];
3249
3217
  const openAIOptions = await parseProviderOptions6({
3250
3218
  provider: "openai",
@@ -3272,8 +3240,8 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
3272
3240
  }
3273
3241
  if (openAIOptions) {
3274
3242
  const speechModelOptions = {
3275
- speed: (_a2 = openAIOptions.speed) != null ? _a2 : void 0,
3276
- instructions: (_b = openAIOptions.instructions) != null ? _b : void 0
3243
+ speed: openAIOptions.speed ?? void 0,
3244
+ instructions: openAIOptions.instructions ?? void 0
3277
3245
  };
3278
3246
  for (const key in speechModelOptions) {
3279
3247
  const value = speechModelOptions[key];
@@ -3295,8 +3263,7 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
3295
3263
  };
3296
3264
  }
3297
3265
  async doGenerate(options) {
3298
- var _a2, _b, _c, _d, _e;
3299
- const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
3266
+ const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
3300
3267
  const { requestBody, warnings } = await this.getArgs(options);
3301
3268
  const {
3302
3269
  value: audio,
@@ -3307,7 +3274,7 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
3307
3274
  path: "/audio/speech",
3308
3275
  modelId: this.modelId
3309
3276
  }),
3310
- headers: combineHeaders6((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), options.headers),
3277
+ headers: combineHeaders6(this.config.headers?.(), options.headers),
3311
3278
  body: requestBody,
3312
3279
  failedResponseHandler: openaiFailedResponseHandler,
3313
3280
  successfulResponseHandler: createBinaryResponseHandler(),
@@ -3374,19 +3341,18 @@ function prepareOpenAIConfigForWorkflowDeserialize(config) {
3374
3341
  // src/responses/convert-openai-responses-usage.ts
3375
3342
  import { createNullLanguageModelUsage as createNullLanguageModelUsage3 } from "@ai-sdk/provider-utils";
3376
3343
  function convertOpenAIResponsesUsage(usage) {
3377
- var _a2, _b, _c, _d, _e, _f;
3378
3344
  if (usage == null) {
3379
3345
  return createNullLanguageModelUsage3();
3380
3346
  }
3381
3347
  const inputTokens = usage.input_tokens;
3382
3348
  const outputTokens = usage.output_tokens;
3383
- const cachedTokens = (_b = (_a2 = usage.input_tokens_details) == null ? void 0 : _a2.cached_tokens) != null ? _b : 0;
3384
- const cacheWriteTokens = (_d = (_c = usage.input_tokens_details) == null ? void 0 : _c.cache_write_tokens) != null ? _d : void 0;
3385
- const reasoningTokens = (_f = (_e = usage.output_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : 0;
3349
+ const cachedTokens = usage.input_tokens_details?.cached_tokens ?? 0;
3350
+ const cacheWriteTokens = usage.input_tokens_details?.cache_write_tokens ?? void 0;
3351
+ const reasoningTokens = usage.output_tokens_details?.reasoning_tokens ?? 0;
3386
3352
  return {
3387
3353
  inputTokens: {
3388
3354
  total: inputTokens,
3389
- noCache: inputTokens - cachedTokens - (cacheWriteTokens != null ? cacheWriteTokens : 0),
3355
+ noCache: inputTokens - cachedTokens - (cacheWriteTokens ?? 0),
3390
3356
  cacheRead: cachedTokens,
3391
3357
  cacheWrite: cacheWriteTokens
3392
3358
  },
@@ -4081,15 +4047,14 @@ var programmaticToolCallingFactory = createProviderExecutedToolFactory({
4081
4047
  var programmaticToolCalling = () => experimental_toolCaller(programmaticToolCallingFactory({}), {
4082
4048
  type: "provider",
4083
4049
  prepareProviderOptions: (providerOptions) => {
4084
- var _a2;
4085
- const openaiOptions = providerOptions == null ? void 0 : providerOptions.openai;
4050
+ const openaiOptions = providerOptions?.openai;
4086
4051
  return {
4087
4052
  ...providerOptions,
4088
4053
  openai: {
4089
4054
  ...openaiOptions,
4090
4055
  allowedCallers: [
4091
4056
  .../* @__PURE__ */ new Set([
4092
- ...(_a2 = openaiOptions == null ? void 0 : openaiOptions.allowedCallers) != null ? _a2 : [],
4057
+ ...openaiOptions?.allowedCallers ?? [],
4093
4058
  "programmatic"
4094
4059
  ])
4095
4060
  ]
@@ -4109,8 +4074,7 @@ function getParallelToolCallMetadata({
4109
4074
  providerOptions,
4110
4075
  providerOptionsName
4111
4076
  }) {
4112
- var _a2;
4113
- const metadata = (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.parallelToolCall;
4077
+ const metadata = providerOptions?.[providerOptionsName]?.parallelToolCall;
4114
4078
  if (!isJSONObject(metadata) || typeof metadata.itemId !== "string" || typeof metadata.toolCallId !== "string" || typeof metadata.toolName !== "string" || typeof metadata.input !== "string" || typeof metadata.index !== "number" || !Number.isInteger(metadata.index) || typeof metadata.count !== "number" || !Number.isInteger(metadata.count) || metadata.index < 0 || metadata.count <= metadata.index) {
4115
4079
  return void 0;
4116
4080
  }
@@ -4191,8 +4155,7 @@ async function convertFunctionToolResultOutput({
4191
4155
  providerOptionsName,
4192
4156
  warnings
4193
4157
  }) {
4194
- var _a2;
4195
- const hasOutputSchema = outputSchemaToolNames == null ? void 0 : outputSchemaToolNames.has(toolName);
4158
+ const hasOutputSchema = outputSchemaToolNames?.has(toolName);
4196
4159
  const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
4197
4160
  {
4198
4161
  type: "input_text",
@@ -4207,7 +4170,7 @@ async function convertFunctionToolResultOutput({
4207
4170
  hasOutputSchema ? JSON.stringify(output.value) : output.value
4208
4171
  );
4209
4172
  case "execution-denied": {
4210
- const reason = (_a2 = output.reason) != null ? _a2 : "Tool call execution denied.";
4173
+ const reason = output.reason ?? "Tool call execution denied.";
4211
4174
  return convertScalarOutput(
4212
4175
  hasOutputSchema ? JSON.stringify(reason) : reason
4213
4176
  );
@@ -4217,7 +4180,6 @@ async function convertFunctionToolResultOutput({
4217
4180
  return convertScalarOutput(JSON.stringify(output.value));
4218
4181
  case "content":
4219
4182
  return output.value.map((item) => {
4220
- var _a3, _b, _c;
4221
4183
  const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
4222
4184
  item.providerOptions,
4223
4185
  providerOptionsName
@@ -4234,7 +4196,7 @@ async function convertFunctionToolResultOutput({
4234
4196
  }
4235
4197
  case "file": {
4236
4198
  const topLevel = getTopLevelMediaType2(item.mediaType);
4237
- const imageDetail = (_b = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b.imageDetail;
4199
+ const imageDetail = item.providerOptions?.[providerOptionsName]?.imageDetail;
4238
4200
  if (item.data.type === "reference") {
4239
4201
  const fileId = resolveProviderReference2({
4240
4202
  reference: item.data.reference,
@@ -4272,7 +4234,7 @@ async function convertFunctionToolResultOutput({
4272
4234
  }
4273
4235
  return {
4274
4236
  type: "input_file",
4275
- filename: (_c = item.filename) != null ? _c : "data",
4237
+ filename: item.filename ?? "data",
4276
4238
  file_data: `data:${fullMediaType};base64,${convertToBase643(item.data.data)}`,
4277
4239
  ...promptCacheBreakpoint2 != null && {
4278
4240
  prompt_cache_breakpoint: promptCacheBreakpoint2
@@ -4373,16 +4335,14 @@ function collectCompleteParallelToolResultGroups({
4373
4335
  return completeGroups;
4374
4336
  }
4375
4337
  function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
4376
- var _a2;
4377
- return (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.promptCacheBreakpoint;
4338
+ return providerOptions?.[providerOptionsName]?.promptCacheBreakpoint;
4378
4339
  }
4379
4340
  function getScalarToolResultPromptCacheBreakpoint({
4380
4341
  output,
4381
4342
  toolResultProviderOptions,
4382
4343
  providerOptionsName
4383
4344
  }) {
4384
- var _a2;
4385
- return output.type === "content" ? void 0 : (_a2 = getPromptCacheBreakpoint2(output.providerOptions, providerOptionsName)) != null ? _a2 : getPromptCacheBreakpoint2(
4345
+ return output.type === "content" ? void 0 : getPromptCacheBreakpoint2(output.providerOptions, providerOptionsName) ?? getPromptCacheBreakpoint2(
4386
4346
  toolResultProviderOptions,
4387
4347
  providerOptionsName
4388
4348
  );
@@ -4411,7 +4371,6 @@ async function convertToOpenAIResponsesInput({
4411
4371
  outputSchemaToolNames,
4412
4372
  configurationUpdateUnsupportedReason
4413
4373
  }) {
4414
- var _a2, _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, _M, _N, _O, _P;
4415
4374
  let input = [];
4416
4375
  const warnings = [];
4417
4376
  const processedApprovalIds = /* @__PURE__ */ new Set();
@@ -4437,7 +4396,7 @@ async function convertToOpenAIResponsesInput({
4437
4396
  schema: openaiResponsesSystemMessageOptionsSchema
4438
4397
  });
4439
4398
  }
4440
- const effort = options == null ? void 0 : options.reasoningEffortUpdate;
4399
+ const effort = options?.reasoningEffortUpdate;
4441
4400
  if (effort != null) {
4442
4401
  const unsupportedReason = content !== "" ? "Message-level reasoningEffortUpdate requires empty system message content." : configurationUpdateUnsupportedReason;
4443
4402
  if (unsupportedReason != null) {
@@ -4510,7 +4469,6 @@ async function convertToOpenAIResponsesInput({
4510
4469
  ...explicitMessageItemType && { type: "message" },
4511
4470
  role: "user",
4512
4471
  content: content.map((part, index) => {
4513
- var _a3, _b2, _c2, _d2, _e2;
4514
4472
  switch (part.type) {
4515
4473
  case "text": {
4516
4474
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(
@@ -4540,7 +4498,7 @@ async function convertToOpenAIResponsesInput({
4540
4498
  return {
4541
4499
  type: "input_image",
4542
4500
  file_id: fileId,
4543
- detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
4501
+ detail: part.providerOptions?.[providerOptionsName]?.imageDetail,
4544
4502
  ...promptCacheBreakpoint != null && {
4545
4503
  prompt_cache_breakpoint: promptCacheBreakpoint
4546
4504
  }
@@ -4568,7 +4526,7 @@ async function convertToOpenAIResponsesInput({
4568
4526
  ...part.data.type === "url" ? { image_url: part.data.url.toString() } : typeof part.data.data === "string" && isFileId(part.data.data, fileIdPrefixes) ? { file_id: part.data.data } : {
4569
4527
  image_url: `data:${resolveFullMediaType2({ part })};base64,${convertToBase643(part.data.data)}`
4570
4528
  },
4571
- detail: (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail,
4529
+ detail: part.providerOptions?.[providerOptionsName]?.imageDetail,
4572
4530
  ...promptCacheBreakpoint != null && {
4573
4531
  prompt_cache_breakpoint: promptCacheBreakpoint
4574
4532
  }
@@ -4592,7 +4550,7 @@ async function convertToOpenAIResponsesInput({
4592
4550
  return {
4593
4551
  type: "input_file",
4594
4552
  ...typeof part.data.data === "string" && isFileId(part.data.data, fileIdPrefixes) ? { file_id: part.data.data } : {
4595
- filename: (_e2 = part.filename) != null ? _e2 : fullMediaType === "application/pdf" ? `part-${index}.pdf` : `part-${index}`,
4553
+ filename: part.filename ?? (fullMediaType === "application/pdf" ? `part-${index}.pdf` : `part-${index}`),
4596
4554
  file_data: `data:${fullMediaType};base64,${convertToBase643(part.data.data)}`
4597
4555
  },
4598
4556
  ...promptCacheBreakpoint != null && {
@@ -4613,9 +4571,9 @@ async function convertToOpenAIResponsesInput({
4613
4571
  for (const part of content) {
4614
4572
  switch (part.type) {
4615
4573
  case "text": {
4616
- const providerOptions2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName];
4617
- const id = providerOptions2 == null ? void 0 : providerOptions2.itemId;
4618
- const phase = providerOptions2 == null ? void 0 : providerOptions2.phase;
4574
+ const providerOptions2 = part.providerOptions?.[providerOptionsName];
4575
+ const id = providerOptions2?.itemId;
4576
+ const phase = providerOptions2?.phase;
4619
4577
  if (hasConversation && id != null) {
4620
4578
  break;
4621
4579
  }
@@ -4660,11 +4618,11 @@ async function convertToOpenAIResponsesInput({
4660
4618
  }
4661
4619
  break;
4662
4620
  }
4663
- const id = (_f = (_c = (_b = part.providerOptions) == null ? void 0 : _b[providerOptionsName]) == null ? void 0 : _c.itemId) != null ? _f : (_e = (_d = part.providerMetadata) == null ? void 0 : _d[providerOptionsName]) == null ? void 0 : _e.itemId;
4664
- const namespace = (_k = (_h = (_g = part.providerOptions) == null ? void 0 : _g[providerOptionsName]) == null ? void 0 : _h.namespace) != null ? _k : (_j = (_i = part.providerMetadata) == null ? void 0 : _i[providerOptionsName]) == null ? void 0 : _j.namespace;
4665
- const isAsync = (_p = (_m = (_l = part.providerOptions) == null ? void 0 : _l[providerOptionsName]) == null ? void 0 : _m.async) != null ? _p : (_o = (_n = part.providerMetadata) == null ? void 0 : _n[providerOptionsName]) == null ? void 0 : _o.async;
4666
- const caller = (_r = (_q = part.providerOptions) == null ? void 0 : _q[providerOptionsName]) == null ? void 0 : _r.caller;
4667
- if ((caller == null ? void 0 : caller.type) === "program") {
4621
+ const id = part.providerOptions?.[providerOptionsName]?.itemId ?? part.providerMetadata?.[providerOptionsName]?.itemId;
4622
+ const namespace = part.providerOptions?.[providerOptionsName]?.namespace ?? part.providerMetadata?.[providerOptionsName]?.namespace;
4623
+ const isAsync = part.providerOptions?.[providerOptionsName]?.async ?? part.providerMetadata?.[providerOptionsName]?.async;
4624
+ const caller = part.providerOptions?.[providerOptionsName]?.caller;
4625
+ if (caller?.type === "program") {
4668
4626
  programmaticToolCallIds.add(part.toolCallId);
4669
4627
  }
4670
4628
  if (hasConversation && id != null) {
@@ -4688,9 +4646,9 @@ async function convertToOpenAIResponsesInput({
4688
4646
  const execution = parsedInput.call_id != null ? "client" : "server";
4689
4647
  input.push({
4690
4648
  type: "tool_search_call",
4691
- id: id != null ? id : part.toolCallId,
4649
+ id: id ?? part.toolCallId,
4692
4650
  execution,
4693
- call_id: (_s = parsedInput.call_id) != null ? _s : null,
4651
+ call_id: parsedInput.call_id ?? null,
4694
4652
  status: "completed",
4695
4653
  arguments: parsedInput.arguments
4696
4654
  });
@@ -4707,7 +4665,7 @@ async function convertToOpenAIResponsesInput({
4707
4665
  });
4708
4666
  input.push({
4709
4667
  type: "program",
4710
- id: id != null ? id : part.toolCallId,
4668
+ id: id ?? part.toolCallId,
4711
4669
  call_id: part.toolCallId,
4712
4670
  code: parsedInput.code,
4713
4671
  fingerprint: parsedInput.fingerprint
@@ -4722,7 +4680,7 @@ async function convertToOpenAIResponsesInput({
4722
4680
  break;
4723
4681
  }
4724
4682
  }
4725
- const isProviderDefinedToolCall = hasLocalShellTool && resolvedToolName === "local_shell" || hasShellTool && resolvedToolName === "shell" || hasApplyPatchTool && resolvedToolName === "apply_patch" || hasComputerTool && resolvedToolName === "computer" || ((_t = customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) != null ? _t : false);
4683
+ const isProviderDefinedToolCall = hasLocalShellTool && resolvedToolName === "local_shell" || hasShellTool && resolvedToolName === "shell" || hasApplyPatchTool && resolvedToolName === "apply_patch" || hasComputerTool && resolvedToolName === "computer" || (customProviderToolNames?.has(resolvedToolName) ?? false);
4726
4684
  if (hasPreviousResponseId && store && id != null && isProviderDefinedToolCall) {
4727
4685
  break;
4728
4686
  }
@@ -4829,7 +4787,7 @@ async function convertToOpenAIResponsesInput({
4829
4787
  });
4830
4788
  break;
4831
4789
  }
4832
- if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
4790
+ if (customProviderToolNames?.has(resolvedToolName)) {
4833
4791
  input.push({
4834
4792
  type: "custom_tool_call",
4835
4793
  call_id: part.toolCallId,
@@ -4865,7 +4823,7 @@ async function convertToOpenAIResponsesInput({
4865
4823
  part.toolName
4866
4824
  );
4867
4825
  if (part.toolName === toolSearchToolName) {
4868
- const itemId = (_z = (_y = (_v = (_u = part.providerOptions) == null ? void 0 : _u[providerOptionsName]) == null ? void 0 : _v.itemId) != null ? _y : (_x = (_w = part.providerMetadata) == null ? void 0 : _w[providerOptionsName]) == null ? void 0 : _x.itemId) != null ? _z : part.toolCallId;
4826
+ const itemId = part.providerOptions?.[providerOptionsName]?.itemId ?? part.providerMetadata?.[providerOptionsName]?.itemId ?? part.toolCallId;
4869
4827
  if (store) {
4870
4828
  input.push({ type: "item_reference", id: itemId });
4871
4829
  } else if (part.output.type === "json") {
@@ -4885,7 +4843,7 @@ async function convertToOpenAIResponsesInput({
4885
4843
  break;
4886
4844
  }
4887
4845
  if (resolvedResultToolName === "programmatic_tool_calling") {
4888
- const itemId = (_F = (_E = (_B = (_A = part.providerOptions) == null ? void 0 : _A[providerOptionsName]) == null ? void 0 : _B.itemId) != null ? _E : (_D = (_C = part.providerMetadata) == null ? void 0 : _C[providerOptionsName]) == null ? void 0 : _D.itemId) != null ? _F : part.toolCallId;
4846
+ const itemId = part.providerOptions?.[providerOptionsName]?.itemId ?? part.providerMetadata?.[providerOptionsName]?.itemId ?? part.toolCallId;
4889
4847
  if (store) {
4890
4848
  input.push({ type: "item_reference", id: itemId });
4891
4849
  } else if (part.output.type === "json") {
@@ -4925,7 +4883,7 @@ async function convertToOpenAIResponsesInput({
4925
4883
  break;
4926
4884
  }
4927
4885
  if (store) {
4928
- const itemId = (_I = (_H = (_G = part.providerOptions) == null ? void 0 : _G[providerOptionsName]) == null ? void 0 : _H.itemId) != null ? _I : part.toolCallId;
4886
+ const itemId = part.providerOptions?.[providerOptionsName]?.itemId ?? part.toolCallId;
4929
4887
  input.push({ type: "item_reference", id: itemId });
4930
4888
  } else {
4931
4889
  warnings.push({
@@ -4941,7 +4899,7 @@ async function convertToOpenAIResponsesInput({
4941
4899
  providerOptions: part.providerOptions,
4942
4900
  schema: openaiResponsesReasoningProviderOptionsSchema
4943
4901
  });
4944
- const reasoningId = providerOptions2 == null ? void 0 : providerOptions2.itemId;
4902
+ const reasoningId = providerOptions2?.itemId;
4945
4903
  if ((hasConversation || hasPreviousResponseId) && reasoningId != null) {
4946
4904
  break;
4947
4905
  }
@@ -4973,19 +4931,19 @@ async function convertToOpenAIResponsesInput({
4973
4931
  reasoningMessages[reasoningId] = {
4974
4932
  type: "reasoning",
4975
4933
  id: reasoningId,
4976
- encrypted_content: providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent,
4934
+ encrypted_content: providerOptions2?.reasoningEncryptedContent,
4977
4935
  summary: summaryParts
4978
4936
  };
4979
4937
  input.push(reasoningMessages[reasoningId]);
4980
4938
  } else {
4981
4939
  reasoningMessage.summary.push(...summaryParts);
4982
- if ((providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent) != null) {
4940
+ if (providerOptions2?.reasoningEncryptedContent != null) {
4983
4941
  reasoningMessage.encrypted_content = providerOptions2.reasoningEncryptedContent;
4984
4942
  }
4985
4943
  }
4986
4944
  }
4987
4945
  } else {
4988
- const encryptedContent = providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent;
4946
+ const encryptedContent = providerOptions2?.reasoningEncryptedContent;
4989
4947
  if (encryptedContent != null) {
4990
4948
  const summaryParts = [];
4991
4949
  if (part.text.length > 0) {
@@ -5010,8 +4968,8 @@ async function convertToOpenAIResponsesInput({
5010
4968
  }
5011
4969
  case "custom": {
5012
4970
  if (part.kind === "openai.compaction") {
5013
- const providerOptions2 = (_J = part.providerOptions) == null ? void 0 : _J[providerOptionsName];
5014
- const id = providerOptions2 == null ? void 0 : providerOptions2.itemId;
4971
+ const providerOptions2 = part.providerOptions?.[providerOptionsName];
4972
+ const id = providerOptions2?.itemId;
5015
4973
  if (hasConversation && id != null) {
5016
4974
  break;
5017
4975
  }
@@ -5019,7 +4977,7 @@ async function convertToOpenAIResponsesInput({
5019
4977
  input.push({ type: "item_reference", id });
5020
4978
  break;
5021
4979
  }
5022
- const encryptedContent = providerOptions2 == null ? void 0 : providerOptions2.encryptedContent;
4980
+ const encryptedContent = providerOptions2?.encryptedContent;
5023
4981
  if (id != null) {
5024
4982
  input.push({
5025
4983
  type: "compaction",
@@ -5116,7 +5074,7 @@ ${text}`,
5116
5074
  }
5117
5075
  const output = part.output;
5118
5076
  if (output.type === "execution-denied") {
5119
- const approvalId = (_L = (_K = output.providerOptions) == null ? void 0 : _K.openai) == null ? void 0 : _L.approvalId;
5077
+ const approvalId = output.providerOptions?.openai?.approvalId;
5120
5078
  if (approvalId) {
5121
5079
  continue;
5122
5080
  }
@@ -5196,7 +5154,7 @@ ${text}`,
5196
5154
  file_id: parsedOutput.output.fileId,
5197
5155
  detail: parsedOutput.output.detail
5198
5156
  },
5199
- acknowledged_safety_checks: (_M = parsedOutput.acknowledgedSafetyChecks) == null ? void 0 : _M.map((safetyCheck) => ({
5157
+ acknowledged_safety_checks: parsedOutput.acknowledgedSafetyChecks?.map((safetyCheck) => ({
5200
5158
  id: safetyCheck.id,
5201
5159
  code: safetyCheck.code,
5202
5160
  message: safetyCheck.message
@@ -5204,7 +5162,7 @@ ${text}`,
5204
5162
  });
5205
5163
  continue;
5206
5164
  }
5207
- if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
5165
+ if (customProviderToolNames?.has(resolvedToolName)) {
5208
5166
  const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
5209
5167
  output,
5210
5168
  toolResultProviderOptions: part.providerOptions,
@@ -5225,7 +5183,7 @@ ${text}`,
5225
5183
  break;
5226
5184
  case "execution-denied":
5227
5185
  outputValue = convertScalarOutput(
5228
- (_N = output.reason) != null ? _N : "Tool call execution denied."
5186
+ output.reason ?? "Tool call execution denied."
5229
5187
  );
5230
5188
  break;
5231
5189
  case "json":
@@ -5234,7 +5192,6 @@ ${text}`,
5234
5192
  break;
5235
5193
  case "content":
5236
5194
  outputValue = output.value.map((item) => {
5237
- var _a3, _b2, _c2;
5238
5195
  const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
5239
5196
  item.providerOptions,
5240
5197
  providerOptionsName
@@ -5250,7 +5207,7 @@ ${text}`,
5250
5207
  };
5251
5208
  case "file": {
5252
5209
  const topLevel = getTopLevelMediaType2(item.mediaType);
5253
- const imageDetail = (_b2 = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail;
5210
+ const imageDetail = item.providerOptions?.[providerOptionsName]?.imageDetail;
5254
5211
  if (item.data.type === "data") {
5255
5212
  const fullMediaType = resolveFullMediaType2({
5256
5213
  part: item
@@ -5267,7 +5224,7 @@ ${text}`,
5267
5224
  }
5268
5225
  return {
5269
5226
  type: "input_file",
5270
- filename: (_c2 = item.filename) != null ? _c2 : "data",
5227
+ filename: item.filename ?? "data",
5271
5228
  file_data: `data:${fullMediaType};base64,${convertToBase643(item.data.data)}`,
5272
5229
  ...promptCacheBreakpoint2 != null && {
5273
5230
  prompt_cache_breakpoint: promptCacheBreakpoint2
@@ -5318,8 +5275,8 @@ ${text}`,
5318
5275
  });
5319
5276
  continue;
5320
5277
  }
5321
- const resultCaller = (_P = (_O = part.providerOptions) == null ? void 0 : _O[providerOptionsName]) == null ? void 0 : _P.caller;
5322
- if (output.type === "execution-denied" && ((resultCaller == null ? void 0 : resultCaller.type) === "program" || programmaticToolCallIds.has(part.toolCallId))) {
5278
+ const resultCaller = part.providerOptions?.[providerOptionsName]?.caller;
5279
+ if (output.type === "execution-denied" && (resultCaller?.type === "program" || programmaticToolCallIds.has(part.toolCallId))) {
5323
5280
  throw new UnsupportedFunctionalityError6({
5324
5281
  functionality: "execution-denied results for programmatic tool calls"
5325
5282
  });
@@ -6816,15 +6773,14 @@ async function prepareResponsesTools({
6816
6773
  outputSchemaToolNames,
6817
6774
  supportsAsyncToolCalling = true
6818
6775
  }) {
6819
- var _a2, _b, _c, _d;
6820
- tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
6776
+ tools = tools?.length ? tools : void 0;
6821
6777
  const toolWarnings = [];
6822
6778
  if (tools == null) {
6823
6779
  return { tools: void 0, toolChoice: void 0, toolWarnings };
6824
6780
  }
6825
6781
  const openaiTools = [];
6826
6782
  const namespaceTools = /* @__PURE__ */ new Map();
6827
- const resolvedCustomProviderToolNames = customProviderToolNames != null ? customProviderToolNames : /* @__PURE__ */ new Set();
6783
+ const resolvedCustomProviderToolNames = customProviderToolNames ?? /* @__PURE__ */ new Set();
6828
6784
  const allowedToolResolutions = /* @__PURE__ */ new Map();
6829
6785
  const allowedToolAliases = /* @__PURE__ */ new Map();
6830
6786
  const recordAllowedTool = (toolName, resolution, canonicalName) => {
@@ -6842,22 +6798,22 @@ async function prepareResponsesTools({
6842
6798
  for (const tool of tools) {
6843
6799
  switch (tool.type) {
6844
6800
  case "function": {
6845
- const openaiOptions = (_a2 = tool.providerOptions) == null ? void 0 : _a2.openai;
6846
- if ((openaiOptions == null ? void 0 : openaiOptions.outputSchema) != null) {
6847
- outputSchemaToolNames == null ? void 0 : outputSchemaToolNames.add(tool.name);
6801
+ const openaiOptions = tool.providerOptions?.openai;
6802
+ if (openaiOptions?.outputSchema != null) {
6803
+ outputSchemaToolNames?.add(tool.name);
6848
6804
  }
6849
6805
  const openaiFunctionTool = prepareFunctionTool({
6850
6806
  tool,
6851
6807
  options: openaiOptions,
6852
6808
  toolWarnings,
6853
6809
  async: resolveAsyncToolOption({
6854
- value: openaiOptions == null ? void 0 : openaiOptions.async,
6810
+ value: openaiOptions?.async,
6855
6811
  supportsAsyncToolCalling,
6856
6812
  toolName: tool.name,
6857
6813
  toolWarnings
6858
6814
  })
6859
6815
  });
6860
- const namespace = openaiOptions == null ? void 0 : openaiOptions.namespace;
6816
+ const namespace = openaiOptions?.namespace;
6861
6817
  if (namespace == null) {
6862
6818
  openaiTools.push(openaiFunctionTool);
6863
6819
  } else {
@@ -6883,7 +6839,7 @@ async function prepareResponsesTools({
6883
6839
  namespace != null ? {
6884
6840
  supported: false,
6885
6841
  reason: "tools inside an OpenAI tool namespace are not visible to tool_choice.allowed_tools"
6886
- } : (openaiOptions == null ? void 0 : openaiOptions.deferLoading) === true ? {
6842
+ } : openaiOptions?.deferLoading === true ? {
6887
6843
  supported: false,
6888
6844
  reason: "deferred tools are not visible to tool_choice.allowed_tools"
6889
6845
  } : {
@@ -7029,7 +6985,7 @@ async function prepareResponsesTools({
7029
6985
  authorization: args.authorization,
7030
6986
  connector_id: args.connectorId,
7031
6987
  headers: args.headers,
7032
- require_approval: requireApprovalParam != null ? requireApprovalParam : "never",
6988
+ require_approval: requireApprovalParam ?? "never",
7033
6989
  server_description: args.serverDescription,
7034
6990
  server_url: args.serverUrl
7035
6991
  });
@@ -7080,7 +7036,7 @@ async function prepareResponsesTools({
7080
7036
  recordAllowedTool(
7081
7037
  tool.name,
7082
7038
  toAllowedToolResolution(openaiTool),
7083
- toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(tool.name)
7039
+ toolNameMapping?.toProviderToolName(tool.name)
7084
7040
  );
7085
7041
  }
7086
7042
  break;
@@ -7098,7 +7054,7 @@ async function prepareResponsesTools({
7098
7054
  const droppedToolNames = [];
7099
7055
  for (const name of allowedTools.toolNames) {
7100
7056
  const directResolution = allowedToolResolutions.get(name);
7101
- const resolution = directResolution != null ? directResolution : allowedToolAliases.get(name);
7057
+ const resolution = directResolution ?? allowedToolAliases.get(name);
7102
7058
  if (directResolution != null && allowedToolAliases.has(name)) {
7103
7059
  toolWarnings.push({
7104
7060
  type: "unsupported",
@@ -7123,7 +7079,7 @@ async function prepareResponsesTools({
7123
7079
  });
7124
7080
  allowedToolEntries.push({
7125
7081
  type: "function",
7126
- name: (_b = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(name)) != null ? _b : name
7082
+ name: toolNameMapping?.toProviderToolName(name) ?? name
7127
7083
  });
7128
7084
  continue;
7129
7085
  }
@@ -7149,7 +7105,7 @@ async function prepareResponsesTools({
7149
7105
  tools: openaiTools,
7150
7106
  toolChoice: {
7151
7107
  type: "allowed_tools",
7152
- mode: (_c = allowedTools.mode) != null ? _c : "auto",
7108
+ mode: allowedTools.mode ?? "auto",
7153
7109
  tools: allowedToolEntries
7154
7110
  },
7155
7111
  toolWarnings
@@ -7165,7 +7121,7 @@ async function prepareResponsesTools({
7165
7121
  case "required":
7166
7122
  return { tools: openaiTools, toolChoice: type, toolWarnings };
7167
7123
  case "tool": {
7168
- const resolvedToolName = (_d = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(toolChoice.toolName)) != null ? _d : toolChoice.toolName;
7124
+ const resolvedToolName = toolNameMapping?.toProviderToolName(toolChoice.toolName) ?? toolChoice.toolName;
7169
7125
  return {
7170
7126
  tools: openaiTools,
7171
7127
  toolChoice: resolvedToolName === "code_interpreter" || resolvedToolName === "file_search" || resolvedToolName === "image_generation" || resolvedToolName === "web_search_preview" || resolvedToolName === "web_search" || resolvedToolName === "mcp" || resolvedToolName === "apply_patch" || resolvedToolName === "computer" || resolvedToolName === "programmatic_tool_calling" ? { type: resolvedToolName } : resolvedCustomProviderToolNames.has(resolvedToolName) ? { type: "custom", name: resolvedToolName } : { type: "function", name: resolvedToolName },
@@ -7233,13 +7189,12 @@ function prepareFunctionTool({
7233
7189
  toolWarnings,
7234
7190
  async
7235
7191
  }) {
7236
- var _a2;
7237
- const deferLoading = options == null ? void 0 : options.deferLoading;
7192
+ const deferLoading = options?.deferLoading;
7238
7193
  const normalizedInputSchema = normalizeOpenAIJsonSchema(tool.inputSchema);
7239
- const normalizedOutputSchema = (options == null ? void 0 : options.outputSchema) != null ? normalizeOpenAIJsonSchema(options.outputSchema) : void 0;
7194
+ const normalizedOutputSchema = options?.outputSchema != null ? normalizeOpenAIJsonSchema(options.outputSchema) : void 0;
7240
7195
  toolWarnings.push(
7241
7196
  ...normalizedInputSchema.warnings,
7242
- ...(_a2 = normalizedOutputSchema == null ? void 0 : normalizedOutputSchema.warnings) != null ? _a2 : []
7197
+ ...normalizedOutputSchema?.warnings ?? []
7243
7198
  );
7244
7199
  return {
7245
7200
  type: "function",
@@ -7247,10 +7202,10 @@ function prepareFunctionTool({
7247
7202
  description: tool.description,
7248
7203
  parameters: normalizedInputSchema.schema,
7249
7204
  ...async != null ? { async } : {},
7250
- ...tool.strict != null ? { strict: tool.strict } : {},
7205
+ strict: tool.strict ?? false,
7251
7206
  ...deferLoading != null ? { defer_loading: deferLoading } : {},
7252
- ...(options == null ? void 0 : options.allowedCallers) != null ? { allowed_callers: options.allowedCallers } : {},
7253
- ...(options == null ? void 0 : options.outputSchema) != null ? { output_schema: normalizedOutputSchema == null ? void 0 : normalizedOutputSchema.schema } : {}
7207
+ ...options?.allowedCallers != null ? { allowed_callers: options.allowedCallers } : {},
7208
+ ...options?.outputSchema != null ? { output_schema: normalizedOutputSchema?.schema } : {}
7254
7209
  };
7255
7210
  }
7256
7211
  function resolveAsyncToolOption({
@@ -7297,39 +7252,35 @@ function mapShellEnvironment(environment) {
7297
7252
  };
7298
7253
  }
7299
7254
  function mapShellSkills(skills) {
7300
- return skills == null ? void 0 : skills.map(
7301
- (skill) => {
7302
- var _a2, _b;
7303
- return skill.type === "skillReference" ? {
7304
- type: "skill_reference",
7305
- skill_id: resolveProviderReference3({
7306
- reference: (_a2 = skill.providerReference) != null ? _a2 : {},
7307
- provider: "openai"
7308
- }),
7309
- version: (_b = skill.version) != null ? _b : "latest"
7310
- } : {
7311
- type: "inline",
7312
- name: skill.name,
7313
- description: skill.description,
7314
- source: {
7315
- type: "base64",
7316
- media_type: skill.source.mediaType,
7317
- data: skill.source.data
7318
- }
7319
- };
7255
+ return skills?.map(
7256
+ (skill) => skill.type === "skillReference" ? {
7257
+ type: "skill_reference",
7258
+ skill_id: resolveProviderReference3({
7259
+ reference: skill.providerReference ?? {},
7260
+ provider: "openai"
7261
+ }),
7262
+ version: skill.version ?? "latest"
7263
+ } : {
7264
+ type: "inline",
7265
+ name: skill.name,
7266
+ description: skill.description,
7267
+ source: {
7268
+ type: "base64",
7269
+ media_type: skill.source.mediaType,
7270
+ data: skill.source.data
7271
+ }
7320
7272
  }
7321
7273
  );
7322
7274
  }
7323
7275
 
7324
7276
  // src/responses/openai-responses-language-model.ts
7325
7277
  function extractApprovalRequestIdToToolCallIdMapping(prompt) {
7326
- var _a2, _b;
7327
7278
  const mapping = {};
7328
7279
  for (const message of prompt) {
7329
7280
  if (message.role !== "assistant") continue;
7330
7281
  for (const part of message.content) {
7331
7282
  if (part.type !== "tool-call") continue;
7332
- const approvalRequestId = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.approvalRequestId;
7283
+ const approvalRequestId = part.providerOptions?.openai?.approvalRequestId;
7333
7284
  if (approvalRequestId != null) {
7334
7285
  mapping[approvalRequestId] = part.toolCallId;
7335
7286
  }
@@ -7392,16 +7343,15 @@ function mapComputerCallInput({
7392
7343
  pending_safety_checks,
7393
7344
  status
7394
7345
  }) {
7395
- var _a2;
7396
7346
  return {
7397
- actions: (actions != null ? actions : action != null ? [action] : []).map(
7347
+ actions: (actions ?? (action != null ? [action] : [])).map(
7398
7348
  mapComputerAction
7399
7349
  ),
7400
- pendingSafetyChecks: (_a2 = pending_safety_checks == null ? void 0 : pending_safety_checks.map((safetyCheck) => ({
7350
+ pendingSafetyChecks: pending_safety_checks?.map((safetyCheck) => ({
7401
7351
  id: safetyCheck.id,
7402
7352
  ...safetyCheck.code != null && { code: safetyCheck.code },
7403
7353
  ...safetyCheck.message != null && { message: safetyCheck.message }
7404
- }))) != null ? _a2 : [],
7354
+ })) ?? [],
7405
7355
  status
7406
7356
  };
7407
7357
  }
@@ -7416,7 +7366,7 @@ function getConfigurationUpdateUnsupportedReason({
7416
7366
  if (!modelCapabilities.supportsConfigurationUpdate) {
7417
7367
  return "reasoningEffortUpdate is only supported by GPT-6 and later models";
7418
7368
  }
7419
- if ((options == null ? void 0 : options.reasoningMode) === "pro" || (options == null ? void 0 : options.contextManagement) != null || (options == null ? void 0 : options.truncation) === "auto") {
7369
+ if (options?.reasoningMode === "pro" || options?.contextManagement != null || options?.truncation === "auto") {
7420
7370
  return "reasoningEffortUpdate requires standard reasoning mode without automatic compaction or automatic truncation";
7421
7371
  }
7422
7372
  return void 0;
@@ -7463,7 +7413,6 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7463
7413
  responseFormat
7464
7414
  }
7465
7415
  }) {
7466
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
7467
7416
  const warnings = [];
7468
7417
  const modelCapabilities = getOpenAILanguageModelCapabilities(modelId);
7469
7418
  if (topK != null) {
@@ -7494,7 +7443,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7494
7443
  schema: openaiLanguageModelResponsesOptionsSchema
7495
7444
  });
7496
7445
  }
7497
- let resolvedReasoningEffort = (_a2 = openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null ? _a2 : isCustomReasoning2(reasoning) ? reasoning : void 0;
7446
+ let resolvedReasoningEffort = openaiOptions?.reasoningEffort ?? (isCustomReasoning2(reasoning) ? reasoning : void 0);
7498
7447
  if (resolvedReasoningEffort != null && modelCapabilities.supportedReasoningEfforts != null && !modelCapabilities.supportedReasoningEfforts.includes(
7499
7448
  resolvedReasoningEffort
7500
7449
  )) {
@@ -7505,9 +7454,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7505
7454
  });
7506
7455
  resolvedReasoningEffort = void 0;
7507
7456
  }
7508
- const resolvedReasoningSummary = (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) !== void 0 ? openaiOptions.reasoningSummary : resolvedReasoningEffort != null && resolvedReasoningEffort !== "none" ? "detailed" : void 0;
7509
- const isReasoningModel = (_b = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _b : modelCapabilities.isReasoningModel;
7510
- if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) {
7457
+ const resolvedReasoningSummary = openaiOptions?.reasoningSummary !== void 0 ? openaiOptions.reasoningSummary : resolvedReasoningEffort != null && resolvedReasoningEffort !== "none" ? "detailed" : void 0;
7458
+ const isReasoningModel = openaiOptions?.forceReasoning ?? modelCapabilities.isReasoningModel;
7459
+ if (openaiOptions?.conversation && openaiOptions?.previousResponseId) {
7511
7460
  warnings.push({
7512
7461
  type: "unsupported",
7513
7462
  feature: "conversation",
@@ -7540,7 +7489,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7540
7489
  } = await prepareResponsesTools({
7541
7490
  tools,
7542
7491
  toolChoice,
7543
- allowedTools: (_c = openaiOptions == null ? void 0 : openaiOptions.allowedTools) != null ? _c : void 0,
7492
+ allowedTools: openaiOptions?.allowedTools ?? void 0,
7544
7493
  toolNameMapping,
7545
7494
  customProviderToolNames,
7546
7495
  outputSchemaToolNames,
@@ -7553,15 +7502,15 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7553
7502
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
7554
7503
  prompt,
7555
7504
  toolNameMapping,
7556
- systemMessageMode: (_d = openaiOptions == null ? void 0 : openaiOptions.systemMessageMode) != null ? _d : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode,
7505
+ systemMessageMode: openaiOptions?.systemMessageMode ?? (isReasoningModel ? "developer" : modelCapabilities.systemMessageMode),
7557
7506
  providerOptionsName,
7558
7507
  configurationUpdateUnsupportedReason,
7559
7508
  explicitMessageItemType: config.explicitMessageItemType,
7560
7509
  fileIdPrefixes: config.fileIdPrefixes,
7561
- passThroughUnsupportedFiles: (_e = openaiOptions == null ? void 0 : openaiOptions.passThroughUnsupportedFiles) != null ? _e : false,
7562
- store: (_f = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _f : true,
7563
- hasConversation: (openaiOptions == null ? void 0 : openaiOptions.conversation) != null,
7564
- hasPreviousResponseId: (openaiOptions == null ? void 0 : openaiOptions.previousResponseId) != null,
7510
+ passThroughUnsupportedFiles: openaiOptions?.passThroughUnsupportedFiles ?? false,
7511
+ store: openaiOptions?.store ?? true,
7512
+ hasConversation: openaiOptions?.conversation != null,
7513
+ hasPreviousResponseId: openaiOptions?.previousResponseId != null,
7565
7514
  hasLocalShellTool: hasOpenAITool("openai.local_shell"),
7566
7515
  hasShellTool: hasOpenAITool("openai.shell"),
7567
7516
  hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
@@ -7571,7 +7520,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7571
7520
  outputSchemaToolNames: outputSchemaToolNames.size > 0 ? outputSchemaToolNames : void 0
7572
7521
  });
7573
7522
  warnings.push(...inputWarnings);
7574
- const reasoningEffortUpdate = openaiOptions == null ? void 0 : openaiOptions.reasoningEffortUpdate;
7523
+ const reasoningEffortUpdate = openaiOptions?.reasoningEffortUpdate;
7575
7524
  if (reasoningEffortUpdate != null && configurationUpdateUnsupportedReason != null) {
7576
7525
  warnings.push({
7577
7526
  type: "unsupported",
@@ -7580,7 +7529,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7580
7529
  });
7581
7530
  } else if (reasoningEffortUpdate != null) {
7582
7531
  const firstItem = input[0];
7583
- if ((firstItem == null ? void 0 : firstItem.type) !== "configuration_update" || firstItem.reasoning.effort !== reasoningEffortUpdate) {
7532
+ if (firstItem?.type !== "configuration_update" || firstItem.reasoning.effort !== reasoningEffortUpdate) {
7584
7533
  input.unshift({
7585
7534
  type: "configuration_update",
7586
7535
  reasoning: { effort: reasoningEffortUpdate }
@@ -7594,15 +7543,15 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7594
7543
  });
7595
7544
  }
7596
7545
  }
7597
- if (openaiOptions == null ? void 0 : openaiOptions.compactionTrigger) {
7546
+ if (openaiOptions?.compactionTrigger) {
7598
7547
  input.push({ type: "compaction_trigger" });
7599
7548
  }
7600
- const strictJsonSchema = (_g = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _g : true;
7601
- const normalizedResponseFormatSchema = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? normalizeOpenAIJsonSchema(responseFormat.schema) : void 0;
7549
+ const strictJsonSchema = openaiOptions?.strictJsonSchema ?? true;
7550
+ const normalizedResponseFormatSchema = responseFormat?.type === "json" && responseFormat.schema != null ? normalizeOpenAIJsonSchema(responseFormat.schema) : void 0;
7602
7551
  if (normalizedResponseFormatSchema != null) {
7603
7552
  warnings.push(...normalizedResponseFormatSchema.warnings);
7604
7553
  }
7605
- let include = openaiOptions == null ? void 0 : openaiOptions.include;
7554
+ let include = openaiOptions?.include;
7606
7555
  function addInclude(key) {
7607
7556
  if (include == null) {
7608
7557
  include = [key];
@@ -7611,26 +7560,25 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7611
7560
  }
7612
7561
  }
7613
7562
  function getOpenAIToolName(id) {
7614
- var _a3;
7615
- return (_a3 = tools == null ? void 0 : tools.find((tool) => tool.type === "provider" && tool.id === id)) == null ? void 0 : _a3.name;
7563
+ return tools?.find((tool) => tool.type === "provider" && tool.id === id)?.name;
7616
7564
  }
7617
7565
  function hasOpenAITool(id) {
7618
7566
  return getOpenAIToolName(id) != null;
7619
7567
  }
7620
- const topLogprobs = typeof (openaiOptions == null ? void 0 : openaiOptions.logprobs) === "number" ? openaiOptions == null ? void 0 : openaiOptions.logprobs : (openaiOptions == null ? void 0 : openaiOptions.logprobs) === true ? TOP_LOGPROBS_MAX : void 0;
7568
+ const topLogprobs = typeof openaiOptions?.logprobs === "number" ? openaiOptions?.logprobs : openaiOptions?.logprobs === true ? TOP_LOGPROBS_MAX : void 0;
7621
7569
  if (topLogprobs) {
7622
7570
  addInclude("message.output_text.logprobs");
7623
7571
  }
7624
- const webSearchToolName = (_h = tools == null ? void 0 : tools.find(
7572
+ const webSearchToolName = tools?.find(
7625
7573
  (tool) => tool.type === "provider" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
7626
- )) == null ? void 0 : _h.name;
7627
- if (webSearchToolName && config.supportsWebSearchSourcesInclude !== false && (openaiOptions == null ? void 0 : openaiOptions.includeWebSearchSources) !== false) {
7574
+ )?.name;
7575
+ if (webSearchToolName && config.supportsWebSearchSourcesInclude !== false && openaiOptions?.includeWebSearchSources !== false) {
7628
7576
  addInclude("web_search_call.action.sources");
7629
7577
  }
7630
7578
  if (hasOpenAITool("openai.code_interpreter")) {
7631
7579
  addInclude("code_interpreter_call.outputs");
7632
7580
  }
7633
- const store = openaiOptions == null ? void 0 : openaiOptions.store;
7581
+ const store = openaiOptions?.store;
7634
7582
  if (store === false && isReasoningModel) {
7635
7583
  addInclude("reasoning.encrypted_content");
7636
7584
  }
@@ -7640,48 +7588,48 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7640
7588
  temperature,
7641
7589
  top_p: topP,
7642
7590
  max_output_tokens: maxOutputTokens,
7643
- ...((responseFormat == null ? void 0 : responseFormat.type) === "json" || (openaiOptions == null ? void 0 : openaiOptions.textVerbosity)) && {
7591
+ ...(responseFormat?.type === "json" || openaiOptions?.textVerbosity) && {
7644
7592
  text: {
7645
- ...(responseFormat == null ? void 0 : responseFormat.type) === "json" && {
7593
+ ...responseFormat?.type === "json" && {
7646
7594
  format: normalizedResponseFormatSchema != null ? {
7647
7595
  type: "json_schema",
7648
7596
  strict: strictJsonSchema,
7649
- name: (_i = responseFormat.name) != null ? _i : "response",
7597
+ name: responseFormat.name ?? "response",
7650
7598
  description: responseFormat.description,
7651
7599
  schema: normalizedResponseFormatSchema.schema
7652
7600
  } : { type: "json_object" }
7653
7601
  },
7654
- ...(openaiOptions == null ? void 0 : openaiOptions.textVerbosity) && {
7602
+ ...openaiOptions?.textVerbosity && {
7655
7603
  verbosity: openaiOptions.textVerbosity
7656
7604
  }
7657
7605
  }
7658
7606
  },
7659
7607
  // provider options:
7660
- conversation: openaiOptions == null ? void 0 : openaiOptions.conversation,
7661
- max_tool_calls: openaiOptions == null ? void 0 : openaiOptions.maxToolCalls,
7662
- metadata: openaiOptions == null ? void 0 : openaiOptions.metadata,
7663
- parallel_tool_calls: openaiOptions == null ? void 0 : openaiOptions.parallelToolCalls,
7664
- previous_response_id: openaiOptions == null ? void 0 : openaiOptions.previousResponseId,
7608
+ conversation: openaiOptions?.conversation,
7609
+ max_tool_calls: openaiOptions?.maxToolCalls,
7610
+ metadata: openaiOptions?.metadata,
7611
+ parallel_tool_calls: openaiOptions?.parallelToolCalls,
7612
+ previous_response_id: openaiOptions?.previousResponseId,
7665
7613
  store,
7666
- user: openaiOptions == null ? void 0 : openaiOptions.user,
7667
- instructions: openaiOptions == null ? void 0 : openaiOptions.instructions,
7668
- service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
7614
+ user: openaiOptions?.user,
7615
+ instructions: openaiOptions?.instructions,
7616
+ service_tier: openaiOptions?.serviceTier,
7669
7617
  include,
7670
- prompt_cache_key: openaiOptions == null ? void 0 : openaiOptions.promptCacheKey,
7671
- prompt_cache_options: openaiOptions == null ? void 0 : openaiOptions.promptCacheOptions,
7672
- prompt_cache_retention: openaiOptions == null ? void 0 : openaiOptions.promptCacheRetention,
7673
- safety_identifier: openaiOptions == null ? void 0 : openaiOptions.safetyIdentifier,
7618
+ prompt_cache_key: openaiOptions?.promptCacheKey,
7619
+ prompt_cache_options: openaiOptions?.promptCacheOptions,
7620
+ prompt_cache_retention: openaiOptions?.promptCacheRetention,
7621
+ safety_identifier: openaiOptions?.safetyIdentifier,
7674
7622
  top_logprobs: topLogprobs,
7675
- truncation: openaiOptions == null ? void 0 : openaiOptions.truncation,
7623
+ truncation: openaiOptions?.truncation,
7676
7624
  // context management (server-side compaction):
7677
- ...(openaiOptions == null ? void 0 : openaiOptions.contextManagement) && {
7625
+ ...openaiOptions?.contextManagement && {
7678
7626
  context_management: openaiOptions.contextManagement.map((cm) => ({
7679
7627
  type: cm.type,
7680
7628
  compact_threshold: cm.compactThreshold
7681
7629
  }))
7682
7630
  },
7683
7631
  // model-specific settings:
7684
- ...isReasoningModel && (resolvedReasoningEffort != null || resolvedReasoningSummary != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningMode) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningContext) != null) && {
7632
+ ...isReasoningModel && (resolvedReasoningEffort != null || resolvedReasoningSummary != null || openaiOptions?.reasoningMode != null || openaiOptions?.reasoningContext != null) && {
7685
7633
  reasoning: {
7686
7634
  ...resolvedReasoningEffort != null && {
7687
7635
  effort: resolvedReasoningEffort
@@ -7689,10 +7637,10 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7689
7637
  ...resolvedReasoningSummary != null && {
7690
7638
  summary: resolvedReasoningSummary
7691
7639
  },
7692
- ...(openaiOptions == null ? void 0 : openaiOptions.reasoningMode) != null && {
7640
+ ...openaiOptions?.reasoningMode != null && {
7693
7641
  mode: openaiOptions.reasoningMode
7694
7642
  },
7695
- ...(openaiOptions == null ? void 0 : openaiOptions.reasoningContext) != null && {
7643
+ ...openaiOptions?.reasoningContext != null && {
7696
7644
  context: openaiOptions.reasoningContext
7697
7645
  }
7698
7646
  }
@@ -7724,9 +7672,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7724
7672
  details: "topP is not supported for reasoning models"
7725
7673
  });
7726
7674
  }
7727
- if (modelCapabilities.supportedReasoningEfforts != null && (baseArgs.top_logprobs != null || ((_j = baseArgs.include) == null ? void 0 : _j.includes("message.output_text.logprobs")))) {
7675
+ if (modelCapabilities.supportedReasoningEfforts != null && (baseArgs.top_logprobs != null || baseArgs.include?.includes("message.output_text.logprobs"))) {
7728
7676
  baseArgs.top_logprobs = void 0;
7729
- const filteredInclude = (_k = baseArgs.include) == null ? void 0 : _k.filter(
7677
+ const filteredInclude = baseArgs.include?.filter(
7730
7678
  (value) => value !== "message.output_text.logprobs"
7731
7679
  );
7732
7680
  baseArgs.include = filteredInclude != null && filteredInclude.length > 0 ? filteredInclude : void 0;
@@ -7738,28 +7686,28 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7738
7686
  }
7739
7687
  }
7740
7688
  } else {
7741
- if ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null) {
7689
+ if (openaiOptions?.reasoningEffort != null) {
7742
7690
  warnings.push({
7743
7691
  type: "unsupported",
7744
7692
  feature: "reasoningEffort",
7745
7693
  details: "reasoningEffort is not supported for non-reasoning models"
7746
7694
  });
7747
7695
  }
7748
- if ((openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) {
7696
+ if (openaiOptions?.reasoningSummary != null) {
7749
7697
  warnings.push({
7750
7698
  type: "unsupported",
7751
7699
  feature: "reasoningSummary",
7752
7700
  details: "reasoningSummary is not supported for non-reasoning models"
7753
7701
  });
7754
7702
  }
7755
- if ((openaiOptions == null ? void 0 : openaiOptions.reasoningMode) != null) {
7703
+ if (openaiOptions?.reasoningMode != null) {
7756
7704
  warnings.push({
7757
7705
  type: "unsupported",
7758
7706
  feature: "reasoningMode",
7759
7707
  details: "reasoningMode is not supported for non-reasoning models"
7760
7708
  });
7761
7709
  }
7762
- if ((openaiOptions == null ? void 0 : openaiOptions.reasoningContext) != null) {
7710
+ if (openaiOptions?.reasoningContext != null) {
7763
7711
  warnings.push({
7764
7712
  type: "unsupported",
7765
7713
  feature: "reasoningContext",
@@ -7767,7 +7715,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7767
7715
  });
7768
7716
  }
7769
7717
  }
7770
- if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "flex" && !modelCapabilities.supportsFlexProcessing) {
7718
+ if (openaiOptions?.serviceTier === "flex" && !modelCapabilities.supportsFlexProcessing) {
7771
7719
  warnings.push({
7772
7720
  type: "unsupported",
7773
7721
  feature: "serviceTier",
@@ -7775,7 +7723,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7775
7723
  });
7776
7724
  delete baseArgs.service_tier;
7777
7725
  }
7778
- if (((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "priority" || (openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "fast") && !modelCapabilities.supportsPriorityProcessing) {
7726
+ if ((openaiOptions?.serviceTier === "priority" || openaiOptions?.serviceTier === "fast") && !modelCapabilities.supportsPriorityProcessing) {
7779
7727
  warnings.push({
7780
7728
  type: "unsupported",
7781
7729
  feature: "serviceTier",
@@ -7783,9 +7731,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7783
7731
  });
7784
7732
  delete baseArgs.service_tier;
7785
7733
  }
7786
- const shellToolEnvType = (_n = (_m = (_l = tools == null ? void 0 : tools.find(
7734
+ const shellToolEnvType = tools?.find(
7787
7735
  (tool) => tool.type === "provider" && tool.id === "openai.shell"
7788
- )) == null ? void 0 : _l.args) == null ? void 0 : _m.environment) == null ? void 0 : _n.type;
7736
+ )?.args?.environment?.type;
7789
7737
  const isShellProviderExecuted = shellToolEnvType === "containerAuto" || shellToolEnvType === "containerReference";
7790
7738
  return {
7791
7739
  webSearchToolName,
@@ -7809,7 +7757,6 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7809
7757
  });
7810
7758
  }
7811
7759
  async doGenerate(options) {
7812
- var _a2, _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;
7813
7760
  const {
7814
7761
  args: body,
7815
7762
  warnings,
@@ -7829,7 +7776,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7829
7776
  rawValue: rawResponse
7830
7777
  } = await postJsonToApi6({
7831
7778
  url,
7832
- headers: combineHeaders7((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
7779
+ headers: combineHeaders7(this.config.headers?.(), options.headers),
7833
7780
  body,
7834
7781
  failedResponseHandler: openaiFailedResponseHandler,
7835
7782
  successfulResponseHandler: createJsonResponseHandler6(
@@ -7850,7 +7797,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7850
7797
  });
7851
7798
  }
7852
7799
  if (response.output == null) {
7853
- const detail = (_c = response.incomplete_details) == null ? void 0 : _c.reason;
7800
+ const detail = response.incomplete_details?.reason;
7854
7801
  throw new APICallError2({
7855
7802
  message: detail ? `Responses API returned no output (${detail})` : "Responses API returned no output",
7856
7803
  url,
@@ -7863,9 +7810,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7863
7810
  }
7864
7811
  const content = [];
7865
7812
  const logprobs = [];
7866
- const functionTools = (_e = (_d = options.tools) == null ? void 0 : _d.filter(
7813
+ const functionTools = options.tools?.filter(
7867
7814
  (tool) => tool.type === "function"
7868
- )) != null ? _e : [];
7815
+ ) ?? [];
7869
7816
  let hasFunctionCall = false;
7870
7817
  const hostedToolSearchCallIds = [];
7871
7818
  for (const part of response.output) {
@@ -7881,7 +7828,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7881
7828
  providerMetadata: {
7882
7829
  [providerOptionsName]: {
7883
7830
  itemId: part.id,
7884
- reasoningEncryptedContent: (_f = part.encrypted_content) != null ? _f : null
7831
+ reasoningEncryptedContent: part.encrypted_content ?? null
7885
7832
  }
7886
7833
  }
7887
7834
  });
@@ -7907,7 +7854,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7907
7854
  break;
7908
7855
  }
7909
7856
  case "tool_search_call": {
7910
- const toolCallId = (_g = part.call_id) != null ? _g : part.id;
7857
+ const toolCallId = part.call_id ?? part.id;
7911
7858
  const isHosted = part.execution === "server";
7912
7859
  if (isHosted) {
7913
7860
  hostedToolSearchCallIds.push(toolCallId);
@@ -7930,7 +7877,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7930
7877
  break;
7931
7878
  }
7932
7879
  case "tool_search_output": {
7933
- const toolCallId = (_i = (_h = part.call_id) != null ? _h : hostedToolSearchCallIds.shift()) != null ? _i : part.id;
7880
+ const toolCallId = part.call_id ?? hostedToolSearchCallIds.shift() ?? part.id;
7934
7881
  content.push({
7935
7882
  type: "tool-result",
7936
7883
  toolCallId,
@@ -8001,7 +7948,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8001
7948
  }
8002
7949
  case "message": {
8003
7950
  for (const contentPart of part.content) {
8004
- if (((_k = (_j = options.providerOptions) == null ? void 0 : _j[providerOptionsName]) == null ? void 0 : _k.logprobs) && contentPart.logprobs) {
7951
+ if (options.providerOptions?.[providerOptionsName]?.logprobs && contentPart.logprobs) {
8005
7952
  logprobs.push(contentPart.logprobs);
8006
7953
  }
8007
7954
  const providerMetadata2 = {
@@ -8023,7 +7970,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8023
7970
  content.push({
8024
7971
  type: "source",
8025
7972
  sourceType: "url",
8026
- id: (_n = (_m = (_l = this.config).generateId) == null ? void 0 : _m.call(_l)) != null ? _n : generateId2(),
7973
+ id: this.config.generateId?.() ?? generateId2(),
8027
7974
  url: annotation.url,
8028
7975
  title: annotation.title
8029
7976
  });
@@ -8031,7 +7978,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8031
7978
  content.push({
8032
7979
  type: "source",
8033
7980
  sourceType: "document",
8034
- id: (_q = (_p = (_o = this.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : generateId2(),
7981
+ id: this.config.generateId?.() ?? generateId2(),
8035
7982
  mediaType: "text/plain",
8036
7983
  title: annotation.filename,
8037
7984
  filename: annotation.filename,
@@ -8047,7 +7994,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8047
7994
  content.push({
8048
7995
  type: "source",
8049
7996
  sourceType: "document",
8050
- id: (_t = (_s = (_r = this.config).generateId) == null ? void 0 : _s.call(_r)) != null ? _t : generateId2(),
7997
+ id: this.config.generateId?.() ?? generateId2(),
8051
7998
  mediaType: "text/plain",
8052
7999
  title: annotation.filename,
8053
8000
  filename: annotation.filename,
@@ -8063,7 +8010,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8063
8010
  content.push({
8064
8011
  type: "source",
8065
8012
  sourceType: "document",
8066
- id: (_w = (_v = (_u = this.config).generateId) == null ? void 0 : _v.call(_u)) != null ? _w : generateId2(),
8013
+ id: this.config.generateId?.() ?? generateId2(),
8067
8014
  mediaType: "application/octet-stream",
8068
8015
  title: annotation.file_id,
8069
8016
  filename: annotation.file_id,
@@ -8178,7 +8125,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8178
8125
  type: "tool-call",
8179
8126
  toolCallId: part.id,
8180
8127
  toolName: toolNameMapping.toCustomToolName(
8181
- webSearchToolName != null ? webSearchToolName : "web_search"
8128
+ webSearchToolName ?? "web_search"
8182
8129
  ),
8183
8130
  input: JSON.stringify({}),
8184
8131
  providerExecuted: true
@@ -8187,14 +8134,14 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8187
8134
  type: "tool-result",
8188
8135
  toolCallId: part.id,
8189
8136
  toolName: toolNameMapping.toCustomToolName(
8190
- webSearchToolName != null ? webSearchToolName : "web_search"
8137
+ webSearchToolName ?? "web_search"
8191
8138
  ),
8192
8139
  result: mapWebSearchOutput(part.action)
8193
8140
  });
8194
8141
  break;
8195
8142
  }
8196
8143
  case "mcp_call": {
8197
- const toolCallId = part.approval_request_id != null ? (_x = approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id]) != null ? _x : part.id : part.id;
8144
+ const toolCallId = part.approval_request_id != null ? approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id] ?? part.id : part.id;
8198
8145
  const toolName = `mcp.${part.name}`;
8199
8146
  content.push({
8200
8147
  type: "tool-call",
@@ -8228,8 +8175,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8228
8175
  break;
8229
8176
  }
8230
8177
  case "mcp_approval_request": {
8231
- const approvalRequestId = (_y = part.approval_request_id) != null ? _y : part.id;
8232
- const dummyToolCallId = (_B = (_A = (_z = this.config).generateId) == null ? void 0 : _A.call(_z)) != null ? _B : generateId2();
8178
+ const approvalRequestId = part.approval_request_id ?? part.id;
8179
+ const dummyToolCallId = this.config.generateId?.() ?? generateId2();
8233
8180
  const toolName = `mcp.${part.name}`;
8234
8181
  content.push({
8235
8182
  type: "tool-call",
@@ -8295,13 +8242,13 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8295
8242
  toolName: toolNameMapping.toCustomToolName("file_search"),
8296
8243
  result: {
8297
8244
  queries: part.queries,
8298
- results: (_D = (_C = part.results) == null ? void 0 : _C.map((result) => ({
8245
+ results: part.results?.map((result) => ({
8299
8246
  attributes: result.attributes,
8300
8247
  fileId: result.file_id,
8301
8248
  filename: result.filename,
8302
8249
  score: result.score,
8303
8250
  text: result.text
8304
- }))) != null ? _D : null
8251
+ })) ?? null
8305
8252
  }
8306
8253
  });
8307
8254
  break;
@@ -8366,7 +8313,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8366
8313
  responseId: response.id,
8367
8314
  ...logprobs.length > 0 ? { logprobs } : {},
8368
8315
  ...typeof response.service_tier === "string" ? { serviceTier: response.service_tier } : {},
8369
- ...((_E = response.reasoning) == null ? void 0 : _E.context) != null ? { reasoningContext: response.reasoning.context } : {}
8316
+ ...response.reasoning?.context != null ? { reasoningContext: response.reasoning.context } : {}
8370
8317
  }
8371
8318
  };
8372
8319
  const usage = response.usage;
@@ -8374,10 +8321,10 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8374
8321
  content,
8375
8322
  finishReason: {
8376
8323
  unified: mapOpenAIResponseFinishReason({
8377
- finishReason: (_F = response.incomplete_details) == null ? void 0 : _F.reason,
8324
+ finishReason: response.incomplete_details?.reason,
8378
8325
  hasFunctionCall
8379
8326
  }),
8380
- raw: (_H = (_G = response.incomplete_details) == null ? void 0 : _G.reason) != null ? _H : void 0
8327
+ raw: response.incomplete_details?.reason ?? void 0
8381
8328
  },
8382
8329
  usage: convertOpenAIResponsesUsage(usage),
8383
8330
  request: { body },
@@ -8393,7 +8340,6 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8393
8340
  };
8394
8341
  }
8395
8342
  async doStream(options) {
8396
- var _a2, _b, _c, _d;
8397
8343
  const {
8398
8344
  args: body,
8399
8345
  warnings,
@@ -8409,7 +8355,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8409
8355
  });
8410
8356
  const { responseHeaders, value: response } = await postJsonToApi6({
8411
8357
  url,
8412
- headers: combineHeaders7((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
8358
+ headers: combineHeaders7(this.config.headers?.(), options.headers),
8413
8359
  body: {
8414
8360
  ...body,
8415
8361
  stream: true
@@ -8432,9 +8378,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8432
8378
  });
8433
8379
  const self = this;
8434
8380
  const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
8435
- const functionTools = (_d = (_c = options.tools) == null ? void 0 : _c.filter(
8381
+ const functionTools = options.tools?.filter(
8436
8382
  (tool) => tool.type === "function"
8437
- )) != null ? _d : [];
8383
+ ) ?? [];
8438
8384
  const approvalRequestIdToDummyToolCallIdFromStream = /* @__PURE__ */ new Map();
8439
8385
  let finishReason = {
8440
8386
  unified: "other",
@@ -8452,10 +8398,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8452
8398
  const resolveOutputItemId = ({
8453
8399
  itemId,
8454
8400
  outputIndex
8455
- }) => {
8456
- var _a3;
8457
- return outputIndex == null ? itemId : (_a3 = activeOutputItemIds[outputIndex]) != null ? _a3 : itemId;
8458
- };
8401
+ }) => outputIndex == null ? itemId : activeOutputItemIds[outputIndex] ?? itemId;
8459
8402
  let serviceTier;
8460
8403
  let reasoningContext;
8461
8404
  const hostedToolSearchCallIds = [];
@@ -8467,7 +8410,6 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8467
8410
  controller.enqueue({ type: "stream-start", warnings });
8468
8411
  },
8469
8412
  transform(chunk, controller) {
8470
- 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;
8471
8413
  if (options.includeRawChunks) {
8472
8414
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
8473
8415
  }
@@ -8522,7 +8464,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8522
8464
  } else if (value.item.type === "web_search_call") {
8523
8465
  ongoingToolCalls[value.output_index] = {
8524
8466
  toolName: toolNameMapping.toCustomToolName(
8525
- webSearchToolName != null ? webSearchToolName : "web_search"
8467
+ webSearchToolName ?? "web_search"
8526
8468
  ),
8527
8469
  toolCallId: value.item.id
8528
8470
  };
@@ -8530,7 +8472,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8530
8472
  type: "tool-input-start",
8531
8473
  id: value.item.id,
8532
8474
  toolName: toolNameMapping.toCustomToolName(
8533
- webSearchToolName != null ? webSearchToolName : "web_search"
8475
+ webSearchToolName ?? "web_search"
8534
8476
  ),
8535
8477
  providerExecuted: true
8536
8478
  });
@@ -8542,13 +8484,13 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8542
8484
  type: "tool-call",
8543
8485
  toolCallId: value.item.id,
8544
8486
  toolName: toolNameMapping.toCustomToolName(
8545
- webSearchToolName != null ? webSearchToolName : "web_search"
8487
+ webSearchToolName ?? "web_search"
8546
8488
  ),
8547
8489
  input: JSON.stringify({}),
8548
8490
  providerExecuted: true
8549
8491
  });
8550
8492
  } else if (value.item.type === "computer_call") {
8551
- const toolCallId = (_a3 = value.item.call_id) != null ? _a3 : value.item.id;
8493
+ const toolCallId = value.item.call_id ?? value.item.id;
8552
8494
  ongoingToolCalls[value.output_index] = {
8553
8495
  toolName: toolNameMapping.toCustomToolName("computer"),
8554
8496
  toolCallId
@@ -8600,7 +8542,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8600
8542
  ongoingToolCalls[value.output_index] = {
8601
8543
  toolName,
8602
8544
  toolCallId,
8603
- toolSearchExecution: (_b2 = value.item.execution) != null ? _b2 : "server"
8545
+ toolSearchExecution: value.item.execution ?? "server"
8604
8546
  };
8605
8547
  if (isHosted) {
8606
8548
  controller.enqueue({
@@ -8658,7 +8600,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8658
8600
  } else if (value.item.type === "message") {
8659
8601
  activeOutputItemIds[value.output_index] = value.item.id;
8660
8602
  ongoingAnnotations.splice(0);
8661
- activeMessagePhase = (_c2 = value.item.phase) != null ? _c2 : void 0;
8603
+ activeMessagePhase = value.item.phase ?? void 0;
8662
8604
  controller.enqueue({
8663
8605
  type: "text-start",
8664
8606
  id: value.item.id,
@@ -8683,7 +8625,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8683
8625
  providerMetadata: {
8684
8626
  [providerOptionsName]: {
8685
8627
  itemId: value.item.id,
8686
- reasoningEncryptedContent: (_d2 = value.item.encrypted_content) != null ? _d2 : null
8628
+ reasoningEncryptedContent: value.item.encrypted_content ?? null
8687
8629
  }
8688
8630
  }
8689
8631
  });
@@ -8694,7 +8636,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8694
8636
  itemId: value.item.id,
8695
8637
  outputIndex: value.output_index
8696
8638
  });
8697
- const phase = (_e = value.item.phase) != null ? _e : activeMessagePhase;
8639
+ const phase = value.item.phase ?? activeMessagePhase;
8698
8640
  activeMessagePhase = void 0;
8699
8641
  controller.enqueue({
8700
8642
  type: "text-end",
@@ -8715,19 +8657,18 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8715
8657
  const ongoingToolCall = ongoingToolCalls[value.output_index];
8716
8658
  ongoingToolCalls[value.output_index] = void 0;
8717
8659
  hasFunctionCall = true;
8718
- const suppressInputStreaming = (_f = ongoingToolCall == null ? void 0 : ongoingToolCall.suppressInputStreaming) != null ? _f : isUndeclaredParallelToolCall({
8660
+ const suppressInputStreaming = ongoingToolCall?.suppressInputStreaming ?? isUndeclaredParallelToolCall({
8719
8661
  toolName: item.name,
8720
8662
  tools: functionTools
8721
8663
  });
8722
8664
  const enqueueUnexpandedToolCall = () => {
8723
- var _a4;
8724
8665
  if (suppressInputStreaming) {
8725
8666
  controller.enqueue({
8726
8667
  type: "tool-input-start",
8727
8668
  id: item.call_id,
8728
8669
  toolName: item.name
8729
8670
  });
8730
- const bufferedInputDeltas = (_a4 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a4 : [];
8671
+ const bufferedInputDeltas = ongoingToolCall?.bufferedInputDeltas ?? [];
8731
8672
  if (bufferedInputDeltas.length > 0) {
8732
8673
  for (const delta of bufferedInputDeltas) {
8733
8674
  controller.enqueue({
@@ -8763,7 +8704,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8763
8704
  providerMetadata: {
8764
8705
  [providerOptionsName]: {
8765
8706
  itemId: item.id,
8766
- ...item.async != null ? { async: item.async } : (ongoingToolCall == null ? void 0 : ongoingToolCall.async) != null ? { async: ongoingToolCall.async } : {},
8707
+ ...item.async != null ? { async: item.async } : ongoingToolCall?.async != null ? { async: ongoingToolCall.async } : {},
8767
8708
  ...item.namespace != null && {
8768
8709
  namespace: item.namespace
8769
8710
  },
@@ -8867,7 +8808,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8867
8808
  providerMetadata: {
8868
8809
  [providerOptionsName]: {
8869
8810
  itemId: value.item.id,
8870
- ...value.item.async != null ? { async: value.item.async } : (ongoingToolCall == null ? void 0 : ongoingToolCall.async) != null ? { async: ongoingToolCall.async } : {}
8811
+ ...value.item.async != null ? { async: value.item.async } : ongoingToolCall?.async != null ? { async: ongoingToolCall.async } : {}
8871
8812
  }
8872
8813
  }
8873
8814
  });
@@ -8877,7 +8818,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8877
8818
  type: "tool-result",
8878
8819
  toolCallId: value.item.id,
8879
8820
  toolName: toolNameMapping.toCustomToolName(
8880
- webSearchToolName != null ? webSearchToolName : "web_search"
8821
+ webSearchToolName ?? "web_search"
8881
8822
  ),
8882
8823
  result: mapWebSearchOutput(value.item.action)
8883
8824
  });
@@ -8937,13 +8878,13 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8937
8878
  toolName: toolNameMapping.toCustomToolName("file_search"),
8938
8879
  result: {
8939
8880
  queries: value.item.queries,
8940
- results: (_h = (_g = value.item.results) == null ? void 0 : _g.map((result2) => ({
8881
+ results: value.item.results?.map((result2) => ({
8941
8882
  attributes: result2.attributes,
8942
8883
  fileId: result2.file_id,
8943
8884
  filename: result2.filename,
8944
8885
  score: result2.score,
8945
8886
  text: result2.text
8946
- }))) != null ? _h : null
8887
+ })) ?? null
8947
8888
  }
8948
8889
  });
8949
8890
  } else if (value.item.type === "code_interpreter_call") {
@@ -8969,7 +8910,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8969
8910
  const toolCall = ongoingToolCalls[value.output_index];
8970
8911
  const isHosted = value.item.execution === "server";
8971
8912
  if (toolCall != null) {
8972
- const toolCallId = isHosted ? toolCall.toolCallId : (_i = value.item.call_id) != null ? _i : value.item.id;
8913
+ const toolCallId = isHosted ? toolCall.toolCallId : value.item.call_id ?? value.item.id;
8973
8914
  if (isHosted) {
8974
8915
  hostedToolSearchCallIds.push(toolCallId);
8975
8916
  } else {
@@ -9001,7 +8942,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9001
8942
  }
9002
8943
  ongoingToolCalls[value.output_index] = void 0;
9003
8944
  } else if (value.item.type === "tool_search_output") {
9004
- const toolCallId = (_k = (_j = value.item.call_id) != null ? _j : hostedToolSearchCallIds.shift()) != null ? _k : value.item.id;
8945
+ const toolCallId = value.item.call_id ?? hostedToolSearchCallIds.shift() ?? value.item.id;
9005
8946
  controller.enqueue({
9006
8947
  type: "tool-result",
9007
8948
  toolCallId,
@@ -9017,10 +8958,10 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9017
8958
  });
9018
8959
  } else if (value.item.type === "mcp_call") {
9019
8960
  ongoingToolCalls[value.output_index] = void 0;
9020
- const approvalRequestId = (_l = value.item.approval_request_id) != null ? _l : void 0;
9021
- const aliasedToolCallId = approvalRequestId != null ? (_n = (_m = approvalRequestIdToDummyToolCallIdFromStream.get(
8961
+ const approvalRequestId = value.item.approval_request_id ?? void 0;
8962
+ const aliasedToolCallId = approvalRequestId != null ? approvalRequestIdToDummyToolCallIdFromStream.get(
9022
8963
  approvalRequestId
9023
- )) != null ? _m : approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId]) != null ? _n : value.item.id : value.item.id;
8964
+ ) ?? approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId] ?? value.item.id : value.item.id;
9024
8965
  const toolName = `mcp.${value.item.name}`;
9025
8966
  controller.enqueue({
9026
8967
  type: "tool-call",
@@ -9052,7 +8993,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9052
8993
  ongoingToolCalls[value.output_index] = void 0;
9053
8994
  } else if (value.item.type === "apply_patch_call") {
9054
8995
  const toolCall = ongoingToolCalls[value.output_index];
9055
- if ((toolCall == null ? void 0 : toolCall.applyPatch) && !toolCall.applyPatch.endEmitted && value.item.operation.type !== "delete_file") {
8996
+ if (toolCall?.applyPatch && !toolCall.applyPatch.endEmitted && value.item.operation.type !== "delete_file") {
9056
8997
  if (!toolCall.applyPatch.hasDiff) {
9057
8998
  controller.enqueue({
9058
8999
  type: "tool-input-delta",
@@ -9091,8 +9032,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9091
9032
  ongoingToolCalls[value.output_index] = void 0;
9092
9033
  } else if (value.item.type === "mcp_approval_request") {
9093
9034
  ongoingToolCalls[value.output_index] = void 0;
9094
- const dummyToolCallId = (_q = (_p = (_o = self.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : generateId2();
9095
- const approvalRequestId = (_r = value.item.approval_request_id) != null ? _r : value.item.id;
9035
+ const dummyToolCallId = self.config.generateId?.() ?? generateId2();
9036
+ const approvalRequestId = value.item.approval_request_id ?? value.item.id;
9096
9037
  approvalRequestIdToDummyToolCallIdFromStream.set(
9097
9038
  approvalRequestId,
9098
9039
  dummyToolCallId
@@ -9186,7 +9127,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9186
9127
  providerMetadata: {
9187
9128
  [providerOptionsName]: {
9188
9129
  itemId,
9189
- reasoningEncryptedContent: (_s = value.item.encrypted_content) != null ? _s : null
9130
+ reasoningEncryptedContent: value.item.encrypted_content ?? null
9190
9131
  }
9191
9132
  }
9192
9133
  });
@@ -9211,7 +9152,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9211
9152
  const toolCall = ongoingToolCalls[value.output_index];
9212
9153
  if (toolCall != null) {
9213
9154
  if (toolCall.suppressInputStreaming) {
9214
- (_t = toolCall.bufferedInputDeltas) == null ? void 0 : _t.push(value.delta);
9155
+ toolCall.bufferedInputDeltas?.push(value.delta);
9215
9156
  } else {
9216
9157
  controller.enqueue({
9217
9158
  type: "tool-input-delta",
@@ -9231,7 +9172,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9231
9172
  }
9232
9173
  } else if (isResponseApplyPatchCallOperationDiffDeltaChunk(value)) {
9233
9174
  const toolCall = ongoingToolCalls[value.output_index];
9234
- if (toolCall == null ? void 0 : toolCall.applyPatch) {
9175
+ if (toolCall?.applyPatch) {
9235
9176
  controller.enqueue({
9236
9177
  type: "tool-input-delta",
9237
9178
  id: toolCall.toolCallId,
@@ -9241,7 +9182,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9241
9182
  }
9242
9183
  } else if (isResponseApplyPatchCallOperationDiffDoneChunk(value)) {
9243
9184
  const toolCall = ongoingToolCalls[value.output_index];
9244
- if ((toolCall == null ? void 0 : toolCall.applyPatch) && !toolCall.applyPatch.endEmitted) {
9185
+ if (toolCall?.applyPatch && !toolCall.applyPatch.endEmitted) {
9245
9186
  if (!toolCall.applyPatch.hasDiff) {
9246
9187
  controller.enqueue({
9247
9188
  type: "tool-input-delta",
@@ -9321,7 +9262,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9321
9262
  id: itemId,
9322
9263
  delta: value.delta
9323
9264
  });
9324
- if (((_v = (_u = options.providerOptions) == null ? void 0 : _u[providerOptionsName]) == null ? void 0 : _v.logprobs) && value.logprobs) {
9265
+ if (options.providerOptions?.[providerOptionsName]?.logprobs && value.logprobs) {
9325
9266
  logprobs.push(value.logprobs);
9326
9267
  }
9327
9268
  } else if (value.type === "response.reasoning_summary_part.added") {
@@ -9355,7 +9296,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9355
9296
  providerMetadata: {
9356
9297
  [providerOptionsName]: {
9357
9298
  itemId,
9358
- reasoningEncryptedContent: (_w = activeReasoningPart.encryptedContent) != null ? _w : null
9299
+ reasoningEncryptedContent: activeReasoningPart.encryptedContent ?? null
9359
9300
  }
9360
9301
  }
9361
9302
  });
@@ -9402,30 +9343,30 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9402
9343
  if (!encounteredStreamError) {
9403
9344
  finishReason = {
9404
9345
  unified: mapOpenAIResponseFinishReason({
9405
- finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
9346
+ finishReason: value.response.incomplete_details?.reason,
9406
9347
  hasFunctionCall
9407
9348
  }),
9408
- raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
9349
+ raw: value.response.incomplete_details?.reason ?? void 0
9409
9350
  };
9410
9351
  }
9411
- usage = (_A = value.response.usage) != null ? _A : void 0;
9352
+ usage = value.response.usage ?? void 0;
9412
9353
  if (typeof value.response.service_tier === "string") {
9413
9354
  serviceTier = value.response.service_tier;
9414
9355
  }
9415
- if (((_B = value.response.reasoning) == null ? void 0 : _B.context) != null) {
9356
+ if (value.response.reasoning?.context != null) {
9416
9357
  reasoningContext = value.response.reasoning.context;
9417
9358
  }
9418
9359
  } else if (isResponseFailedChunk(value)) {
9419
- const incompleteReason = (_C = value.response.incomplete_details) == null ? void 0 : _C.reason;
9360
+ const incompleteReason = value.response.incomplete_details?.reason;
9420
9361
  finishReason = {
9421
9362
  unified: incompleteReason ? mapOpenAIResponseFinishReason({
9422
9363
  finishReason: incompleteReason,
9423
9364
  hasFunctionCall
9424
9365
  }) : "error",
9425
- raw: incompleteReason != null ? incompleteReason : "error"
9366
+ raw: incompleteReason ?? "error"
9426
9367
  };
9427
- usage = (_D = value.response.usage) != null ? _D : void 0;
9428
- if (((_E = value.response.reasoning) == null ? void 0 : _E.context) != null) {
9368
+ usage = value.response.usage ?? void 0;
9369
+ if (value.response.reasoning?.context != null) {
9429
9370
  reasoningContext = value.response.reasoning.context;
9430
9371
  }
9431
9372
  if (!encounteredStreamError && value.response.error != null) {
@@ -9441,7 +9382,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9441
9382
  };
9442
9383
  controller.enqueue({
9443
9384
  type: "error",
9444
- error: (_F = createOpenAIProviderStreamError(error)) != null ? _F : error
9385
+ error: createOpenAIProviderStreamError(error) ?? error
9445
9386
  });
9446
9387
  }
9447
9388
  } else if (isResponseAnnotationAddedChunk(value)) {
@@ -9450,7 +9391,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9450
9391
  controller.enqueue({
9451
9392
  type: "source",
9452
9393
  sourceType: "url",
9453
- id: (_I = (_H = (_G = self.config).generateId) == null ? void 0 : _H.call(_G)) != null ? _I : generateId2(),
9394
+ id: self.config.generateId?.() ?? generateId2(),
9454
9395
  url: value.annotation.url,
9455
9396
  title: value.annotation.title
9456
9397
  });
@@ -9458,7 +9399,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9458
9399
  controller.enqueue({
9459
9400
  type: "source",
9460
9401
  sourceType: "document",
9461
- id: (_L = (_K = (_J = self.config).generateId) == null ? void 0 : _K.call(_J)) != null ? _L : generateId2(),
9402
+ id: self.config.generateId?.() ?? generateId2(),
9462
9403
  mediaType: "text/plain",
9463
9404
  title: value.annotation.filename,
9464
9405
  filename: value.annotation.filename,
@@ -9474,7 +9415,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9474
9415
  controller.enqueue({
9475
9416
  type: "source",
9476
9417
  sourceType: "document",
9477
- id: (_O = (_N = (_M = self.config).generateId) == null ? void 0 : _N.call(_M)) != null ? _O : generateId2(),
9418
+ id: self.config.generateId?.() ?? generateId2(),
9478
9419
  mediaType: "text/plain",
9479
9420
  title: value.annotation.filename,
9480
9421
  filename: value.annotation.filename,
@@ -9490,7 +9431,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9490
9431
  controller.enqueue({
9491
9432
  type: "source",
9492
9433
  sourceType: "document",
9493
- id: (_R = (_Q = (_P = self.config).generateId) == null ? void 0 : _Q.call(_P)) != null ? _R : generateId2(),
9434
+ id: self.config.generateId?.() ?? generateId2(),
9494
9435
  mediaType: "application/octet-stream",
9495
9436
  title: value.annotation.file_id,
9496
9437
  filename: value.annotation.file_id,
@@ -9508,14 +9449,13 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9508
9449
  finishReason = { unified: "error", raw: "error" };
9509
9450
  controller.enqueue({
9510
9451
  type: "error",
9511
- error: (_S = createOpenAIProviderStreamError(value)) != null ? _S : value
9452
+ error: createOpenAIProviderStreamError(value) ?? value
9512
9453
  });
9513
9454
  }
9514
9455
  },
9515
9456
  flush(controller) {
9516
- var _a3;
9517
9457
  for (const toolCall of Object.values(ongoingToolCalls)) {
9518
- if (!(toolCall == null ? void 0 : toolCall.suppressInputStreaming)) {
9458
+ if (!toolCall?.suppressInputStreaming) {
9519
9459
  continue;
9520
9460
  }
9521
9461
  controller.enqueue({
@@ -9523,7 +9463,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9523
9463
  id: toolCall.toolCallId,
9524
9464
  toolName: toolCall.toolName
9525
9465
  });
9526
- for (const delta of (_a3 = toolCall.bufferedInputDeltas) != null ? _a3 : []) {
9466
+ for (const delta of toolCall.bufferedInputDeltas ?? []) {
9527
9467
  controller.enqueue({
9528
9468
  type: "tool-input-delta",
9529
9469
  id: toolCall.toolCallId,
@@ -9631,7 +9571,6 @@ function isResponseOutputChunk(chunk) {
9631
9571
  return !(chunk.type === "response.created" || chunk.type === "response.in_progress" || chunk.type === "response.failed" || chunk.type === "error" || chunk.type === "unknown_chunk");
9632
9572
  }
9633
9573
  function mapWebSearchOutput(action) {
9634
- var _a2;
9635
9574
  if (action == null) {
9636
9575
  return {};
9637
9576
  }
@@ -9640,7 +9579,7 @@ function mapWebSearchOutput(action) {
9640
9579
  return {
9641
9580
  action: {
9642
9581
  type: "search",
9643
- query: (_a2 = action.query) != null ? _a2 : void 0,
9582
+ query: action.query ?? void 0,
9644
9583
  ...action.queries != null && { queries: action.queries }
9645
9584
  },
9646
9585
  // include sources when provided by the Responses API (behind include flag)