@ai-sdk/openai 4.0.75 → 4.0.78

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
  },
@@ -3604,8 +3570,9 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema12(
3604
3570
  *
3605
3571
  * Only supported by GPT-6 and later models in standard, single-agent mode. Cannot be
3606
3572
  * combined with automatic compaction or automatic truncation.
3573
+ * Supported efforts vary by model; 'none' is supported by GPT-6 Sol and Luna.
3607
3574
  */
3608
- reasoningEffortUpdate: z13.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
3575
+ reasoningEffortUpdate: z13.enum(["none", "low", "medium", "high", "xhigh", "max"]).optional(),
3609
3576
  /**
3610
3577
  * Controls how much model work GPT-5.6 performs before returning a final answer.
3611
3578
  * `standard` is the default. `pro` increases quality, latency, and token usage.
@@ -3733,7 +3700,7 @@ var openaiResponsesSystemMessageOptionsSchema = lazySchema12(
3733
3700
  *
3734
3701
  * @see https://developers.openai.com/api/docs/guides/reasoning#change-reasoning-mid-conversation
3735
3702
  */
3736
- reasoningEffortUpdate: z13.enum(["low", "medium", "high", "xhigh", "max"]).optional()
3703
+ reasoningEffortUpdate: z13.enum(["none", "low", "medium", "high", "xhigh", "max"]).optional()
3737
3704
  })
3738
3705
  )
3739
3706
  );
@@ -4081,15 +4048,14 @@ var programmaticToolCallingFactory = createProviderExecutedToolFactory({
4081
4048
  var programmaticToolCalling = () => experimental_toolCaller(programmaticToolCallingFactory({}), {
4082
4049
  type: "provider",
4083
4050
  prepareProviderOptions: (providerOptions) => {
4084
- var _a2;
4085
- const openaiOptions = providerOptions == null ? void 0 : providerOptions.openai;
4051
+ const openaiOptions = providerOptions?.openai;
4086
4052
  return {
4087
4053
  ...providerOptions,
4088
4054
  openai: {
4089
4055
  ...openaiOptions,
4090
4056
  allowedCallers: [
4091
4057
  .../* @__PURE__ */ new Set([
4092
- ...(_a2 = openaiOptions == null ? void 0 : openaiOptions.allowedCallers) != null ? _a2 : [],
4058
+ ...openaiOptions?.allowedCallers ?? [],
4093
4059
  "programmatic"
4094
4060
  ])
4095
4061
  ]
@@ -4109,8 +4075,7 @@ function getParallelToolCallMetadata({
4109
4075
  providerOptions,
4110
4076
  providerOptionsName
4111
4077
  }) {
4112
- var _a2;
4113
- const metadata = (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.parallelToolCall;
4078
+ const metadata = providerOptions?.[providerOptionsName]?.parallelToolCall;
4114
4079
  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
4080
  return void 0;
4116
4081
  }
@@ -4191,8 +4156,7 @@ async function convertFunctionToolResultOutput({
4191
4156
  providerOptionsName,
4192
4157
  warnings
4193
4158
  }) {
4194
- var _a2;
4195
- const hasOutputSchema = outputSchemaToolNames == null ? void 0 : outputSchemaToolNames.has(toolName);
4159
+ const hasOutputSchema = outputSchemaToolNames?.has(toolName);
4196
4160
  const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
4197
4161
  {
4198
4162
  type: "input_text",
@@ -4207,7 +4171,7 @@ async function convertFunctionToolResultOutput({
4207
4171
  hasOutputSchema ? JSON.stringify(output.value) : output.value
4208
4172
  );
4209
4173
  case "execution-denied": {
4210
- const reason = (_a2 = output.reason) != null ? _a2 : "Tool call execution denied.";
4174
+ const reason = output.reason ?? "Tool call execution denied.";
4211
4175
  return convertScalarOutput(
4212
4176
  hasOutputSchema ? JSON.stringify(reason) : reason
4213
4177
  );
@@ -4217,7 +4181,6 @@ async function convertFunctionToolResultOutput({
4217
4181
  return convertScalarOutput(JSON.stringify(output.value));
4218
4182
  case "content":
4219
4183
  return output.value.map((item) => {
4220
- var _a3, _b, _c;
4221
4184
  const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
4222
4185
  item.providerOptions,
4223
4186
  providerOptionsName
@@ -4234,7 +4197,7 @@ async function convertFunctionToolResultOutput({
4234
4197
  }
4235
4198
  case "file": {
4236
4199
  const topLevel = getTopLevelMediaType2(item.mediaType);
4237
- const imageDetail = (_b = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b.imageDetail;
4200
+ const imageDetail = item.providerOptions?.[providerOptionsName]?.imageDetail;
4238
4201
  if (item.data.type === "reference") {
4239
4202
  const fileId = resolveProviderReference2({
4240
4203
  reference: item.data.reference,
@@ -4272,7 +4235,7 @@ async function convertFunctionToolResultOutput({
4272
4235
  }
4273
4236
  return {
4274
4237
  type: "input_file",
4275
- filename: (_c = item.filename) != null ? _c : "data",
4238
+ filename: item.filename ?? "data",
4276
4239
  file_data: `data:${fullMediaType};base64,${convertToBase643(item.data.data)}`,
4277
4240
  ...promptCacheBreakpoint2 != null && {
4278
4241
  prompt_cache_breakpoint: promptCacheBreakpoint2
@@ -4373,16 +4336,14 @@ function collectCompleteParallelToolResultGroups({
4373
4336
  return completeGroups;
4374
4337
  }
4375
4338
  function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
4376
- var _a2;
4377
- return (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.promptCacheBreakpoint;
4339
+ return providerOptions?.[providerOptionsName]?.promptCacheBreakpoint;
4378
4340
  }
4379
4341
  function getScalarToolResultPromptCacheBreakpoint({
4380
4342
  output,
4381
4343
  toolResultProviderOptions,
4382
4344
  providerOptionsName
4383
4345
  }) {
4384
- var _a2;
4385
- return output.type === "content" ? void 0 : (_a2 = getPromptCacheBreakpoint2(output.providerOptions, providerOptionsName)) != null ? _a2 : getPromptCacheBreakpoint2(
4346
+ return output.type === "content" ? void 0 : getPromptCacheBreakpoint2(output.providerOptions, providerOptionsName) ?? getPromptCacheBreakpoint2(
4386
4347
  toolResultProviderOptions,
4387
4348
  providerOptionsName
4388
4349
  );
@@ -4411,7 +4372,6 @@ async function convertToOpenAIResponsesInput({
4411
4372
  outputSchemaToolNames,
4412
4373
  configurationUpdateUnsupportedReason
4413
4374
  }) {
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
4375
  let input = [];
4416
4376
  const warnings = [];
4417
4377
  const processedApprovalIds = /* @__PURE__ */ new Set();
@@ -4437,7 +4397,7 @@ async function convertToOpenAIResponsesInput({
4437
4397
  schema: openaiResponsesSystemMessageOptionsSchema
4438
4398
  });
4439
4399
  }
4440
- const effort = options == null ? void 0 : options.reasoningEffortUpdate;
4400
+ const effort = options?.reasoningEffortUpdate;
4441
4401
  if (effort != null) {
4442
4402
  const unsupportedReason = content !== "" ? "Message-level reasoningEffortUpdate requires empty system message content." : configurationUpdateUnsupportedReason;
4443
4403
  if (unsupportedReason != null) {
@@ -4510,7 +4470,6 @@ async function convertToOpenAIResponsesInput({
4510
4470
  ...explicitMessageItemType && { type: "message" },
4511
4471
  role: "user",
4512
4472
  content: content.map((part, index) => {
4513
- var _a3, _b2, _c2, _d2, _e2;
4514
4473
  switch (part.type) {
4515
4474
  case "text": {
4516
4475
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(
@@ -4540,7 +4499,7 @@ async function convertToOpenAIResponsesInput({
4540
4499
  return {
4541
4500
  type: "input_image",
4542
4501
  file_id: fileId,
4543
- detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
4502
+ detail: part.providerOptions?.[providerOptionsName]?.imageDetail,
4544
4503
  ...promptCacheBreakpoint != null && {
4545
4504
  prompt_cache_breakpoint: promptCacheBreakpoint
4546
4505
  }
@@ -4568,7 +4527,7 @@ async function convertToOpenAIResponsesInput({
4568
4527
  ...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
4528
  image_url: `data:${resolveFullMediaType2({ part })};base64,${convertToBase643(part.data.data)}`
4570
4529
  },
4571
- detail: (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail,
4530
+ detail: part.providerOptions?.[providerOptionsName]?.imageDetail,
4572
4531
  ...promptCacheBreakpoint != null && {
4573
4532
  prompt_cache_breakpoint: promptCacheBreakpoint
4574
4533
  }
@@ -4592,7 +4551,7 @@ async function convertToOpenAIResponsesInput({
4592
4551
  return {
4593
4552
  type: "input_file",
4594
4553
  ...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}`,
4554
+ filename: part.filename ?? (fullMediaType === "application/pdf" ? `part-${index}.pdf` : `part-${index}`),
4596
4555
  file_data: `data:${fullMediaType};base64,${convertToBase643(part.data.data)}`
4597
4556
  },
4598
4557
  ...promptCacheBreakpoint != null && {
@@ -4613,9 +4572,9 @@ async function convertToOpenAIResponsesInput({
4613
4572
  for (const part of content) {
4614
4573
  switch (part.type) {
4615
4574
  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;
4575
+ const providerOptions2 = part.providerOptions?.[providerOptionsName];
4576
+ const id = providerOptions2?.itemId;
4577
+ const phase = providerOptions2?.phase;
4619
4578
  if (hasConversation && id != null) {
4620
4579
  break;
4621
4580
  }
@@ -4660,11 +4619,11 @@ async function convertToOpenAIResponsesInput({
4660
4619
  }
4661
4620
  break;
4662
4621
  }
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") {
4622
+ const id = part.providerOptions?.[providerOptionsName]?.itemId ?? part.providerMetadata?.[providerOptionsName]?.itemId;
4623
+ const namespace = part.providerOptions?.[providerOptionsName]?.namespace ?? part.providerMetadata?.[providerOptionsName]?.namespace;
4624
+ const isAsync = part.providerOptions?.[providerOptionsName]?.async ?? part.providerMetadata?.[providerOptionsName]?.async;
4625
+ const caller = part.providerOptions?.[providerOptionsName]?.caller;
4626
+ if (caller?.type === "program") {
4668
4627
  programmaticToolCallIds.add(part.toolCallId);
4669
4628
  }
4670
4629
  if (hasConversation && id != null) {
@@ -4688,9 +4647,9 @@ async function convertToOpenAIResponsesInput({
4688
4647
  const execution = parsedInput.call_id != null ? "client" : "server";
4689
4648
  input.push({
4690
4649
  type: "tool_search_call",
4691
- id: id != null ? id : part.toolCallId,
4650
+ id: id ?? part.toolCallId,
4692
4651
  execution,
4693
- call_id: (_s = parsedInput.call_id) != null ? _s : null,
4652
+ call_id: parsedInput.call_id ?? null,
4694
4653
  status: "completed",
4695
4654
  arguments: parsedInput.arguments
4696
4655
  });
@@ -4707,7 +4666,7 @@ async function convertToOpenAIResponsesInput({
4707
4666
  });
4708
4667
  input.push({
4709
4668
  type: "program",
4710
- id: id != null ? id : part.toolCallId,
4669
+ id: id ?? part.toolCallId,
4711
4670
  call_id: part.toolCallId,
4712
4671
  code: parsedInput.code,
4713
4672
  fingerprint: parsedInput.fingerprint
@@ -4722,7 +4681,7 @@ async function convertToOpenAIResponsesInput({
4722
4681
  break;
4723
4682
  }
4724
4683
  }
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);
4684
+ const isProviderDefinedToolCall = hasLocalShellTool && resolvedToolName === "local_shell" || hasShellTool && resolvedToolName === "shell" || hasApplyPatchTool && resolvedToolName === "apply_patch" || hasComputerTool && resolvedToolName === "computer" || (customProviderToolNames?.has(resolvedToolName) ?? false);
4726
4685
  if (hasPreviousResponseId && store && id != null && isProviderDefinedToolCall) {
4727
4686
  break;
4728
4687
  }
@@ -4829,7 +4788,7 @@ async function convertToOpenAIResponsesInput({
4829
4788
  });
4830
4789
  break;
4831
4790
  }
4832
- if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
4791
+ if (customProviderToolNames?.has(resolvedToolName)) {
4833
4792
  input.push({
4834
4793
  type: "custom_tool_call",
4835
4794
  call_id: part.toolCallId,
@@ -4865,7 +4824,7 @@ async function convertToOpenAIResponsesInput({
4865
4824
  part.toolName
4866
4825
  );
4867
4826
  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;
4827
+ const itemId = part.providerOptions?.[providerOptionsName]?.itemId ?? part.providerMetadata?.[providerOptionsName]?.itemId ?? part.toolCallId;
4869
4828
  if (store) {
4870
4829
  input.push({ type: "item_reference", id: itemId });
4871
4830
  } else if (part.output.type === "json") {
@@ -4885,7 +4844,7 @@ async function convertToOpenAIResponsesInput({
4885
4844
  break;
4886
4845
  }
4887
4846
  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;
4847
+ const itemId = part.providerOptions?.[providerOptionsName]?.itemId ?? part.providerMetadata?.[providerOptionsName]?.itemId ?? part.toolCallId;
4889
4848
  if (store) {
4890
4849
  input.push({ type: "item_reference", id: itemId });
4891
4850
  } else if (part.output.type === "json") {
@@ -4925,7 +4884,7 @@ async function convertToOpenAIResponsesInput({
4925
4884
  break;
4926
4885
  }
4927
4886
  if (store) {
4928
- const itemId = (_I = (_H = (_G = part.providerOptions) == null ? void 0 : _G[providerOptionsName]) == null ? void 0 : _H.itemId) != null ? _I : part.toolCallId;
4887
+ const itemId = part.providerOptions?.[providerOptionsName]?.itemId ?? part.toolCallId;
4929
4888
  input.push({ type: "item_reference", id: itemId });
4930
4889
  } else {
4931
4890
  warnings.push({
@@ -4941,7 +4900,7 @@ async function convertToOpenAIResponsesInput({
4941
4900
  providerOptions: part.providerOptions,
4942
4901
  schema: openaiResponsesReasoningProviderOptionsSchema
4943
4902
  });
4944
- const reasoningId = providerOptions2 == null ? void 0 : providerOptions2.itemId;
4903
+ const reasoningId = providerOptions2?.itemId;
4945
4904
  if ((hasConversation || hasPreviousResponseId) && reasoningId != null) {
4946
4905
  break;
4947
4906
  }
@@ -4973,19 +4932,19 @@ async function convertToOpenAIResponsesInput({
4973
4932
  reasoningMessages[reasoningId] = {
4974
4933
  type: "reasoning",
4975
4934
  id: reasoningId,
4976
- encrypted_content: providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent,
4935
+ encrypted_content: providerOptions2?.reasoningEncryptedContent,
4977
4936
  summary: summaryParts
4978
4937
  };
4979
4938
  input.push(reasoningMessages[reasoningId]);
4980
4939
  } else {
4981
4940
  reasoningMessage.summary.push(...summaryParts);
4982
- if ((providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent) != null) {
4941
+ if (providerOptions2?.reasoningEncryptedContent != null) {
4983
4942
  reasoningMessage.encrypted_content = providerOptions2.reasoningEncryptedContent;
4984
4943
  }
4985
4944
  }
4986
4945
  }
4987
4946
  } else {
4988
- const encryptedContent = providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent;
4947
+ const encryptedContent = providerOptions2?.reasoningEncryptedContent;
4989
4948
  if (encryptedContent != null) {
4990
4949
  const summaryParts = [];
4991
4950
  if (part.text.length > 0) {
@@ -5010,8 +4969,8 @@ async function convertToOpenAIResponsesInput({
5010
4969
  }
5011
4970
  case "custom": {
5012
4971
  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;
4972
+ const providerOptions2 = part.providerOptions?.[providerOptionsName];
4973
+ const id = providerOptions2?.itemId;
5015
4974
  if (hasConversation && id != null) {
5016
4975
  break;
5017
4976
  }
@@ -5019,7 +4978,7 @@ async function convertToOpenAIResponsesInput({
5019
4978
  input.push({ type: "item_reference", id });
5020
4979
  break;
5021
4980
  }
5022
- const encryptedContent = providerOptions2 == null ? void 0 : providerOptions2.encryptedContent;
4981
+ const encryptedContent = providerOptions2?.encryptedContent;
5023
4982
  if (id != null) {
5024
4983
  input.push({
5025
4984
  type: "compaction",
@@ -5116,7 +5075,7 @@ ${text}`,
5116
5075
  }
5117
5076
  const output = part.output;
5118
5077
  if (output.type === "execution-denied") {
5119
- const approvalId = (_L = (_K = output.providerOptions) == null ? void 0 : _K.openai) == null ? void 0 : _L.approvalId;
5078
+ const approvalId = output.providerOptions?.openai?.approvalId;
5120
5079
  if (approvalId) {
5121
5080
  continue;
5122
5081
  }
@@ -5196,7 +5155,7 @@ ${text}`,
5196
5155
  file_id: parsedOutput.output.fileId,
5197
5156
  detail: parsedOutput.output.detail
5198
5157
  },
5199
- acknowledged_safety_checks: (_M = parsedOutput.acknowledgedSafetyChecks) == null ? void 0 : _M.map((safetyCheck) => ({
5158
+ acknowledged_safety_checks: parsedOutput.acknowledgedSafetyChecks?.map((safetyCheck) => ({
5200
5159
  id: safetyCheck.id,
5201
5160
  code: safetyCheck.code,
5202
5161
  message: safetyCheck.message
@@ -5204,7 +5163,7 @@ ${text}`,
5204
5163
  });
5205
5164
  continue;
5206
5165
  }
5207
- if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
5166
+ if (customProviderToolNames?.has(resolvedToolName)) {
5208
5167
  const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
5209
5168
  output,
5210
5169
  toolResultProviderOptions: part.providerOptions,
@@ -5225,7 +5184,7 @@ ${text}`,
5225
5184
  break;
5226
5185
  case "execution-denied":
5227
5186
  outputValue = convertScalarOutput(
5228
- (_N = output.reason) != null ? _N : "Tool call execution denied."
5187
+ output.reason ?? "Tool call execution denied."
5229
5188
  );
5230
5189
  break;
5231
5190
  case "json":
@@ -5234,7 +5193,6 @@ ${text}`,
5234
5193
  break;
5235
5194
  case "content":
5236
5195
  outputValue = output.value.map((item) => {
5237
- var _a3, _b2, _c2;
5238
5196
  const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
5239
5197
  item.providerOptions,
5240
5198
  providerOptionsName
@@ -5250,7 +5208,7 @@ ${text}`,
5250
5208
  };
5251
5209
  case "file": {
5252
5210
  const topLevel = getTopLevelMediaType2(item.mediaType);
5253
- const imageDetail = (_b2 = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail;
5211
+ const imageDetail = item.providerOptions?.[providerOptionsName]?.imageDetail;
5254
5212
  if (item.data.type === "data") {
5255
5213
  const fullMediaType = resolveFullMediaType2({
5256
5214
  part: item
@@ -5267,7 +5225,7 @@ ${text}`,
5267
5225
  }
5268
5226
  return {
5269
5227
  type: "input_file",
5270
- filename: (_c2 = item.filename) != null ? _c2 : "data",
5228
+ filename: item.filename ?? "data",
5271
5229
  file_data: `data:${fullMediaType};base64,${convertToBase643(item.data.data)}`,
5272
5230
  ...promptCacheBreakpoint2 != null && {
5273
5231
  prompt_cache_breakpoint: promptCacheBreakpoint2
@@ -5318,8 +5276,8 @@ ${text}`,
5318
5276
  });
5319
5277
  continue;
5320
5278
  }
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))) {
5279
+ const resultCaller = part.providerOptions?.[providerOptionsName]?.caller;
5280
+ if (output.type === "execution-denied" && (resultCaller?.type === "program" || programmaticToolCallIds.has(part.toolCallId))) {
5323
5281
  throw new UnsupportedFunctionalityError6({
5324
5282
  functionality: "execution-denied results for programmatic tool calls"
5325
5283
  });
@@ -6816,15 +6774,14 @@ async function prepareResponsesTools({
6816
6774
  outputSchemaToolNames,
6817
6775
  supportsAsyncToolCalling = true
6818
6776
  }) {
6819
- var _a2, _b, _c, _d;
6820
- tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
6777
+ tools = tools?.length ? tools : void 0;
6821
6778
  const toolWarnings = [];
6822
6779
  if (tools == null) {
6823
6780
  return { tools: void 0, toolChoice: void 0, toolWarnings };
6824
6781
  }
6825
6782
  const openaiTools = [];
6826
6783
  const namespaceTools = /* @__PURE__ */ new Map();
6827
- const resolvedCustomProviderToolNames = customProviderToolNames != null ? customProviderToolNames : /* @__PURE__ */ new Set();
6784
+ const resolvedCustomProviderToolNames = customProviderToolNames ?? /* @__PURE__ */ new Set();
6828
6785
  const allowedToolResolutions = /* @__PURE__ */ new Map();
6829
6786
  const allowedToolAliases = /* @__PURE__ */ new Map();
6830
6787
  const recordAllowedTool = (toolName, resolution, canonicalName) => {
@@ -6842,22 +6799,22 @@ async function prepareResponsesTools({
6842
6799
  for (const tool of tools) {
6843
6800
  switch (tool.type) {
6844
6801
  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);
6802
+ const openaiOptions = tool.providerOptions?.openai;
6803
+ if (openaiOptions?.outputSchema != null) {
6804
+ outputSchemaToolNames?.add(tool.name);
6848
6805
  }
6849
6806
  const openaiFunctionTool = prepareFunctionTool({
6850
6807
  tool,
6851
6808
  options: openaiOptions,
6852
6809
  toolWarnings,
6853
6810
  async: resolveAsyncToolOption({
6854
- value: openaiOptions == null ? void 0 : openaiOptions.async,
6811
+ value: openaiOptions?.async,
6855
6812
  supportsAsyncToolCalling,
6856
6813
  toolName: tool.name,
6857
6814
  toolWarnings
6858
6815
  })
6859
6816
  });
6860
- const namespace = openaiOptions == null ? void 0 : openaiOptions.namespace;
6817
+ const namespace = openaiOptions?.namespace;
6861
6818
  if (namespace == null) {
6862
6819
  openaiTools.push(openaiFunctionTool);
6863
6820
  } else {
@@ -6883,7 +6840,7 @@ async function prepareResponsesTools({
6883
6840
  namespace != null ? {
6884
6841
  supported: false,
6885
6842
  reason: "tools inside an OpenAI tool namespace are not visible to tool_choice.allowed_tools"
6886
- } : (openaiOptions == null ? void 0 : openaiOptions.deferLoading) === true ? {
6843
+ } : openaiOptions?.deferLoading === true ? {
6887
6844
  supported: false,
6888
6845
  reason: "deferred tools are not visible to tool_choice.allowed_tools"
6889
6846
  } : {
@@ -7029,7 +6986,7 @@ async function prepareResponsesTools({
7029
6986
  authorization: args.authorization,
7030
6987
  connector_id: args.connectorId,
7031
6988
  headers: args.headers,
7032
- require_approval: requireApprovalParam != null ? requireApprovalParam : "never",
6989
+ require_approval: requireApprovalParam ?? "never",
7033
6990
  server_description: args.serverDescription,
7034
6991
  server_url: args.serverUrl
7035
6992
  });
@@ -7080,7 +7037,7 @@ async function prepareResponsesTools({
7080
7037
  recordAllowedTool(
7081
7038
  tool.name,
7082
7039
  toAllowedToolResolution(openaiTool),
7083
- toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(tool.name)
7040
+ toolNameMapping?.toProviderToolName(tool.name)
7084
7041
  );
7085
7042
  }
7086
7043
  break;
@@ -7098,7 +7055,7 @@ async function prepareResponsesTools({
7098
7055
  const droppedToolNames = [];
7099
7056
  for (const name of allowedTools.toolNames) {
7100
7057
  const directResolution = allowedToolResolutions.get(name);
7101
- const resolution = directResolution != null ? directResolution : allowedToolAliases.get(name);
7058
+ const resolution = directResolution ?? allowedToolAliases.get(name);
7102
7059
  if (directResolution != null && allowedToolAliases.has(name)) {
7103
7060
  toolWarnings.push({
7104
7061
  type: "unsupported",
@@ -7123,7 +7080,7 @@ async function prepareResponsesTools({
7123
7080
  });
7124
7081
  allowedToolEntries.push({
7125
7082
  type: "function",
7126
- name: (_b = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(name)) != null ? _b : name
7083
+ name: toolNameMapping?.toProviderToolName(name) ?? name
7127
7084
  });
7128
7085
  continue;
7129
7086
  }
@@ -7149,7 +7106,7 @@ async function prepareResponsesTools({
7149
7106
  tools: openaiTools,
7150
7107
  toolChoice: {
7151
7108
  type: "allowed_tools",
7152
- mode: (_c = allowedTools.mode) != null ? _c : "auto",
7109
+ mode: allowedTools.mode ?? "auto",
7153
7110
  tools: allowedToolEntries
7154
7111
  },
7155
7112
  toolWarnings
@@ -7165,7 +7122,7 @@ async function prepareResponsesTools({
7165
7122
  case "required":
7166
7123
  return { tools: openaiTools, toolChoice: type, toolWarnings };
7167
7124
  case "tool": {
7168
- const resolvedToolName = (_d = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(toolChoice.toolName)) != null ? _d : toolChoice.toolName;
7125
+ const resolvedToolName = toolNameMapping?.toProviderToolName(toolChoice.toolName) ?? toolChoice.toolName;
7169
7126
  return {
7170
7127
  tools: openaiTools,
7171
7128
  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 +7190,12 @@ function prepareFunctionTool({
7233
7190
  toolWarnings,
7234
7191
  async
7235
7192
  }) {
7236
- var _a2;
7237
- const deferLoading = options == null ? void 0 : options.deferLoading;
7193
+ const deferLoading = options?.deferLoading;
7238
7194
  const normalizedInputSchema = normalizeOpenAIJsonSchema(tool.inputSchema);
7239
- const normalizedOutputSchema = (options == null ? void 0 : options.outputSchema) != null ? normalizeOpenAIJsonSchema(options.outputSchema) : void 0;
7195
+ const normalizedOutputSchema = options?.outputSchema != null ? normalizeOpenAIJsonSchema(options.outputSchema) : void 0;
7240
7196
  toolWarnings.push(
7241
7197
  ...normalizedInputSchema.warnings,
7242
- ...(_a2 = normalizedOutputSchema == null ? void 0 : normalizedOutputSchema.warnings) != null ? _a2 : []
7198
+ ...normalizedOutputSchema?.warnings ?? []
7243
7199
  );
7244
7200
  return {
7245
7201
  type: "function",
@@ -7247,10 +7203,10 @@ function prepareFunctionTool({
7247
7203
  description: tool.description,
7248
7204
  parameters: normalizedInputSchema.schema,
7249
7205
  ...async != null ? { async } : {},
7250
- ...tool.strict != null ? { strict: tool.strict } : {},
7206
+ strict: tool.strict ?? false,
7251
7207
  ...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 } : {}
7208
+ ...options?.allowedCallers != null ? { allowed_callers: options.allowedCallers } : {},
7209
+ ...options?.outputSchema != null ? { output_schema: normalizedOutputSchema?.schema } : {}
7254
7210
  };
7255
7211
  }
7256
7212
  function resolveAsyncToolOption({
@@ -7297,39 +7253,35 @@ function mapShellEnvironment(environment) {
7297
7253
  };
7298
7254
  }
7299
7255
  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
- };
7256
+ return skills?.map(
7257
+ (skill) => skill.type === "skillReference" ? {
7258
+ type: "skill_reference",
7259
+ skill_id: resolveProviderReference3({
7260
+ reference: skill.providerReference ?? {},
7261
+ provider: "openai"
7262
+ }),
7263
+ version: skill.version ?? "latest"
7264
+ } : {
7265
+ type: "inline",
7266
+ name: skill.name,
7267
+ description: skill.description,
7268
+ source: {
7269
+ type: "base64",
7270
+ media_type: skill.source.mediaType,
7271
+ data: skill.source.data
7272
+ }
7320
7273
  }
7321
7274
  );
7322
7275
  }
7323
7276
 
7324
7277
  // src/responses/openai-responses-language-model.ts
7325
7278
  function extractApprovalRequestIdToToolCallIdMapping(prompt) {
7326
- var _a2, _b;
7327
7279
  const mapping = {};
7328
7280
  for (const message of prompt) {
7329
7281
  if (message.role !== "assistant") continue;
7330
7282
  for (const part of message.content) {
7331
7283
  if (part.type !== "tool-call") continue;
7332
- const approvalRequestId = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.approvalRequestId;
7284
+ const approvalRequestId = part.providerOptions?.openai?.approvalRequestId;
7333
7285
  if (approvalRequestId != null) {
7334
7286
  mapping[approvalRequestId] = part.toolCallId;
7335
7287
  }
@@ -7392,16 +7344,15 @@ function mapComputerCallInput({
7392
7344
  pending_safety_checks,
7393
7345
  status
7394
7346
  }) {
7395
- var _a2;
7396
7347
  return {
7397
- actions: (actions != null ? actions : action != null ? [action] : []).map(
7348
+ actions: (actions ?? (action != null ? [action] : [])).map(
7398
7349
  mapComputerAction
7399
7350
  ),
7400
- pendingSafetyChecks: (_a2 = pending_safety_checks == null ? void 0 : pending_safety_checks.map((safetyCheck) => ({
7351
+ pendingSafetyChecks: pending_safety_checks?.map((safetyCheck) => ({
7401
7352
  id: safetyCheck.id,
7402
7353
  ...safetyCheck.code != null && { code: safetyCheck.code },
7403
7354
  ...safetyCheck.message != null && { message: safetyCheck.message }
7404
- }))) != null ? _a2 : [],
7355
+ })) ?? [],
7405
7356
  status
7406
7357
  };
7407
7358
  }
@@ -7416,7 +7367,7 @@ function getConfigurationUpdateUnsupportedReason({
7416
7367
  if (!modelCapabilities.supportsConfigurationUpdate) {
7417
7368
  return "reasoningEffortUpdate is only supported by GPT-6 and later models";
7418
7369
  }
7419
- if ((options == null ? void 0 : options.reasoningMode) === "pro" || (options == null ? void 0 : options.contextManagement) != null || (options == null ? void 0 : options.truncation) === "auto") {
7370
+ if (options?.reasoningMode === "pro" || options?.contextManagement != null || options?.truncation === "auto") {
7420
7371
  return "reasoningEffortUpdate requires standard reasoning mode without automatic compaction or automatic truncation";
7421
7372
  }
7422
7373
  return void 0;
@@ -7463,7 +7414,6 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7463
7414
  responseFormat
7464
7415
  }
7465
7416
  }) {
7466
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
7467
7417
  const warnings = [];
7468
7418
  const modelCapabilities = getOpenAILanguageModelCapabilities(modelId);
7469
7419
  if (topK != null) {
@@ -7494,7 +7444,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7494
7444
  schema: openaiLanguageModelResponsesOptionsSchema
7495
7445
  });
7496
7446
  }
7497
- let resolvedReasoningEffort = (_a2 = openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null ? _a2 : isCustomReasoning2(reasoning) ? reasoning : void 0;
7447
+ let resolvedReasoningEffort = openaiOptions?.reasoningEffort ?? (isCustomReasoning2(reasoning) ? reasoning : void 0);
7498
7448
  if (resolvedReasoningEffort != null && modelCapabilities.supportedReasoningEfforts != null && !modelCapabilities.supportedReasoningEfforts.includes(
7499
7449
  resolvedReasoningEffort
7500
7450
  )) {
@@ -7505,9 +7455,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7505
7455
  });
7506
7456
  resolvedReasoningEffort = void 0;
7507
7457
  }
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)) {
7458
+ const resolvedReasoningSummary = openaiOptions?.reasoningSummary !== void 0 ? openaiOptions.reasoningSummary : resolvedReasoningEffort != null && resolvedReasoningEffort !== "none" ? "detailed" : void 0;
7459
+ const isReasoningModel = openaiOptions?.forceReasoning ?? modelCapabilities.isReasoningModel;
7460
+ if (openaiOptions?.conversation && openaiOptions?.previousResponseId) {
7511
7461
  warnings.push({
7512
7462
  type: "unsupported",
7513
7463
  feature: "conversation",
@@ -7540,7 +7490,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7540
7490
  } = await prepareResponsesTools({
7541
7491
  tools,
7542
7492
  toolChoice,
7543
- allowedTools: (_c = openaiOptions == null ? void 0 : openaiOptions.allowedTools) != null ? _c : void 0,
7493
+ allowedTools: openaiOptions?.allowedTools ?? void 0,
7544
7494
  toolNameMapping,
7545
7495
  customProviderToolNames,
7546
7496
  outputSchemaToolNames,
@@ -7553,15 +7503,15 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7553
7503
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
7554
7504
  prompt,
7555
7505
  toolNameMapping,
7556
- systemMessageMode: (_d = openaiOptions == null ? void 0 : openaiOptions.systemMessageMode) != null ? _d : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode,
7506
+ systemMessageMode: openaiOptions?.systemMessageMode ?? (isReasoningModel ? "developer" : modelCapabilities.systemMessageMode),
7557
7507
  providerOptionsName,
7558
7508
  configurationUpdateUnsupportedReason,
7559
7509
  explicitMessageItemType: config.explicitMessageItemType,
7560
7510
  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,
7511
+ passThroughUnsupportedFiles: openaiOptions?.passThroughUnsupportedFiles ?? false,
7512
+ store: openaiOptions?.store ?? true,
7513
+ hasConversation: openaiOptions?.conversation != null,
7514
+ hasPreviousResponseId: openaiOptions?.previousResponseId != null,
7565
7515
  hasLocalShellTool: hasOpenAITool("openai.local_shell"),
7566
7516
  hasShellTool: hasOpenAITool("openai.shell"),
7567
7517
  hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
@@ -7571,16 +7521,31 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7571
7521
  outputSchemaToolNames: outputSchemaToolNames.size > 0 ? outputSchemaToolNames : void 0
7572
7522
  });
7573
7523
  warnings.push(...inputWarnings);
7574
- const reasoningEffortUpdate = openaiOptions == null ? void 0 : openaiOptions.reasoningEffortUpdate;
7575
- if (reasoningEffortUpdate != null && configurationUpdateUnsupportedReason != null) {
7524
+ const getUpdateEffortUnsupportedReason = (effort) => effort != null && modelCapabilities.supportedReasoningEfforts?.includes(effort) === false ? `${modelId} only supports the following reasoning efforts: ${modelCapabilities.supportedReasoningEfforts.join(", ")}` : void 0;
7525
+ for (const item of input) {
7526
+ if (item.type === "configuration_update") {
7527
+ const unsupportedReason = getUpdateEffortUnsupportedReason(
7528
+ item.reasoning.effort
7529
+ );
7530
+ if (unsupportedReason != null) {
7531
+ throw new UnsupportedFunctionalityError8({
7532
+ functionality: "Message-level reasoningEffortUpdate",
7533
+ message: unsupportedReason
7534
+ });
7535
+ }
7536
+ }
7537
+ }
7538
+ const reasoningEffortUpdate = openaiOptions?.reasoningEffortUpdate;
7539
+ const requestUpdateUnsupportedReason = configurationUpdateUnsupportedReason ?? getUpdateEffortUnsupportedReason(reasoningEffortUpdate);
7540
+ if (reasoningEffortUpdate != null && requestUpdateUnsupportedReason != null) {
7576
7541
  warnings.push({
7577
7542
  type: "unsupported",
7578
7543
  feature: "reasoningEffortUpdate",
7579
- details: configurationUpdateUnsupportedReason
7544
+ details: requestUpdateUnsupportedReason
7580
7545
  });
7581
7546
  } else if (reasoningEffortUpdate != null) {
7582
7547
  const firstItem = input[0];
7583
- if ((firstItem == null ? void 0 : firstItem.type) !== "configuration_update" || firstItem.reasoning.effort !== reasoningEffortUpdate) {
7548
+ if (firstItem?.type !== "configuration_update" || firstItem.reasoning.effort !== reasoningEffortUpdate) {
7584
7549
  input.unshift({
7585
7550
  type: "configuration_update",
7586
7551
  reasoning: { effort: reasoningEffortUpdate }
@@ -7594,15 +7559,15 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7594
7559
  });
7595
7560
  }
7596
7561
  }
7597
- if (openaiOptions == null ? void 0 : openaiOptions.compactionTrigger) {
7562
+ if (openaiOptions?.compactionTrigger) {
7598
7563
  input.push({ type: "compaction_trigger" });
7599
7564
  }
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;
7565
+ const strictJsonSchema = openaiOptions?.strictJsonSchema ?? true;
7566
+ const normalizedResponseFormatSchema = responseFormat?.type === "json" && responseFormat.schema != null ? normalizeOpenAIJsonSchema(responseFormat.schema) : void 0;
7602
7567
  if (normalizedResponseFormatSchema != null) {
7603
7568
  warnings.push(...normalizedResponseFormatSchema.warnings);
7604
7569
  }
7605
- let include = openaiOptions == null ? void 0 : openaiOptions.include;
7570
+ let include = openaiOptions?.include;
7606
7571
  function addInclude(key) {
7607
7572
  if (include == null) {
7608
7573
  include = [key];
@@ -7611,26 +7576,25 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7611
7576
  }
7612
7577
  }
7613
7578
  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;
7579
+ return tools?.find((tool) => tool.type === "provider" && tool.id === id)?.name;
7616
7580
  }
7617
7581
  function hasOpenAITool(id) {
7618
7582
  return getOpenAIToolName(id) != null;
7619
7583
  }
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;
7584
+ const topLogprobs = typeof openaiOptions?.logprobs === "number" ? openaiOptions?.logprobs : openaiOptions?.logprobs === true ? TOP_LOGPROBS_MAX : void 0;
7621
7585
  if (topLogprobs) {
7622
7586
  addInclude("message.output_text.logprobs");
7623
7587
  }
7624
- const webSearchToolName = (_h = tools == null ? void 0 : tools.find(
7588
+ const webSearchToolName = tools?.find(
7625
7589
  (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) {
7590
+ )?.name;
7591
+ if (webSearchToolName && config.supportsWebSearchSourcesInclude !== false && openaiOptions?.includeWebSearchSources !== false) {
7628
7592
  addInclude("web_search_call.action.sources");
7629
7593
  }
7630
7594
  if (hasOpenAITool("openai.code_interpreter")) {
7631
7595
  addInclude("code_interpreter_call.outputs");
7632
7596
  }
7633
- const store = openaiOptions == null ? void 0 : openaiOptions.store;
7597
+ const store = openaiOptions?.store;
7634
7598
  if (store === false && isReasoningModel) {
7635
7599
  addInclude("reasoning.encrypted_content");
7636
7600
  }
@@ -7640,48 +7604,48 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7640
7604
  temperature,
7641
7605
  top_p: topP,
7642
7606
  max_output_tokens: maxOutputTokens,
7643
- ...((responseFormat == null ? void 0 : responseFormat.type) === "json" || (openaiOptions == null ? void 0 : openaiOptions.textVerbosity)) && {
7607
+ ...(responseFormat?.type === "json" || openaiOptions?.textVerbosity) && {
7644
7608
  text: {
7645
- ...(responseFormat == null ? void 0 : responseFormat.type) === "json" && {
7609
+ ...responseFormat?.type === "json" && {
7646
7610
  format: normalizedResponseFormatSchema != null ? {
7647
7611
  type: "json_schema",
7648
7612
  strict: strictJsonSchema,
7649
- name: (_i = responseFormat.name) != null ? _i : "response",
7613
+ name: responseFormat.name ?? "response",
7650
7614
  description: responseFormat.description,
7651
7615
  schema: normalizedResponseFormatSchema.schema
7652
7616
  } : { type: "json_object" }
7653
7617
  },
7654
- ...(openaiOptions == null ? void 0 : openaiOptions.textVerbosity) && {
7618
+ ...openaiOptions?.textVerbosity && {
7655
7619
  verbosity: openaiOptions.textVerbosity
7656
7620
  }
7657
7621
  }
7658
7622
  },
7659
7623
  // 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,
7624
+ conversation: openaiOptions?.conversation,
7625
+ max_tool_calls: openaiOptions?.maxToolCalls,
7626
+ metadata: openaiOptions?.metadata,
7627
+ parallel_tool_calls: openaiOptions?.parallelToolCalls,
7628
+ previous_response_id: openaiOptions?.previousResponseId,
7665
7629
  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,
7630
+ user: openaiOptions?.user,
7631
+ instructions: openaiOptions?.instructions,
7632
+ service_tier: openaiOptions?.serviceTier,
7669
7633
  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,
7634
+ prompt_cache_key: openaiOptions?.promptCacheKey,
7635
+ prompt_cache_options: openaiOptions?.promptCacheOptions,
7636
+ prompt_cache_retention: openaiOptions?.promptCacheRetention,
7637
+ safety_identifier: openaiOptions?.safetyIdentifier,
7674
7638
  top_logprobs: topLogprobs,
7675
- truncation: openaiOptions == null ? void 0 : openaiOptions.truncation,
7639
+ truncation: openaiOptions?.truncation,
7676
7640
  // context management (server-side compaction):
7677
- ...(openaiOptions == null ? void 0 : openaiOptions.contextManagement) && {
7641
+ ...openaiOptions?.contextManagement && {
7678
7642
  context_management: openaiOptions.contextManagement.map((cm) => ({
7679
7643
  type: cm.type,
7680
7644
  compact_threshold: cm.compactThreshold
7681
7645
  }))
7682
7646
  },
7683
7647
  // model-specific settings:
7684
- ...isReasoningModel && (resolvedReasoningEffort != null || resolvedReasoningSummary != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningMode) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningContext) != null) && {
7648
+ ...isReasoningModel && (resolvedReasoningEffort != null || resolvedReasoningSummary != null || openaiOptions?.reasoningMode != null || openaiOptions?.reasoningContext != null) && {
7685
7649
  reasoning: {
7686
7650
  ...resolvedReasoningEffort != null && {
7687
7651
  effort: resolvedReasoningEffort
@@ -7689,10 +7653,10 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7689
7653
  ...resolvedReasoningSummary != null && {
7690
7654
  summary: resolvedReasoningSummary
7691
7655
  },
7692
- ...(openaiOptions == null ? void 0 : openaiOptions.reasoningMode) != null && {
7656
+ ...openaiOptions?.reasoningMode != null && {
7693
7657
  mode: openaiOptions.reasoningMode
7694
7658
  },
7695
- ...(openaiOptions == null ? void 0 : openaiOptions.reasoningContext) != null && {
7659
+ ...openaiOptions?.reasoningContext != null && {
7696
7660
  context: openaiOptions.reasoningContext
7697
7661
  }
7698
7662
  }
@@ -7724,9 +7688,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7724
7688
  details: "topP is not supported for reasoning models"
7725
7689
  });
7726
7690
  }
7727
- if (modelCapabilities.supportedReasoningEfforts != null && (baseArgs.top_logprobs != null || ((_j = baseArgs.include) == null ? void 0 : _j.includes("message.output_text.logprobs")))) {
7691
+ if (modelCapabilities.supportedReasoningEfforts != null && (baseArgs.top_logprobs != null || baseArgs.include?.includes("message.output_text.logprobs"))) {
7728
7692
  baseArgs.top_logprobs = void 0;
7729
- const filteredInclude = (_k = baseArgs.include) == null ? void 0 : _k.filter(
7693
+ const filteredInclude = baseArgs.include?.filter(
7730
7694
  (value) => value !== "message.output_text.logprobs"
7731
7695
  );
7732
7696
  baseArgs.include = filteredInclude != null && filteredInclude.length > 0 ? filteredInclude : void 0;
@@ -7738,28 +7702,28 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7738
7702
  }
7739
7703
  }
7740
7704
  } else {
7741
- if ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null) {
7705
+ if (openaiOptions?.reasoningEffort != null) {
7742
7706
  warnings.push({
7743
7707
  type: "unsupported",
7744
7708
  feature: "reasoningEffort",
7745
7709
  details: "reasoningEffort is not supported for non-reasoning models"
7746
7710
  });
7747
7711
  }
7748
- if ((openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) {
7712
+ if (openaiOptions?.reasoningSummary != null) {
7749
7713
  warnings.push({
7750
7714
  type: "unsupported",
7751
7715
  feature: "reasoningSummary",
7752
7716
  details: "reasoningSummary is not supported for non-reasoning models"
7753
7717
  });
7754
7718
  }
7755
- if ((openaiOptions == null ? void 0 : openaiOptions.reasoningMode) != null) {
7719
+ if (openaiOptions?.reasoningMode != null) {
7756
7720
  warnings.push({
7757
7721
  type: "unsupported",
7758
7722
  feature: "reasoningMode",
7759
7723
  details: "reasoningMode is not supported for non-reasoning models"
7760
7724
  });
7761
7725
  }
7762
- if ((openaiOptions == null ? void 0 : openaiOptions.reasoningContext) != null) {
7726
+ if (openaiOptions?.reasoningContext != null) {
7763
7727
  warnings.push({
7764
7728
  type: "unsupported",
7765
7729
  feature: "reasoningContext",
@@ -7767,7 +7731,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7767
7731
  });
7768
7732
  }
7769
7733
  }
7770
- if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "flex" && !modelCapabilities.supportsFlexProcessing) {
7734
+ if (openaiOptions?.serviceTier === "flex" && !modelCapabilities.supportsFlexProcessing) {
7771
7735
  warnings.push({
7772
7736
  type: "unsupported",
7773
7737
  feature: "serviceTier",
@@ -7775,7 +7739,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7775
7739
  });
7776
7740
  delete baseArgs.service_tier;
7777
7741
  }
7778
- if (((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "priority" || (openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "fast") && !modelCapabilities.supportsPriorityProcessing) {
7742
+ if ((openaiOptions?.serviceTier === "priority" || openaiOptions?.serviceTier === "fast") && !modelCapabilities.supportsPriorityProcessing) {
7779
7743
  warnings.push({
7780
7744
  type: "unsupported",
7781
7745
  feature: "serviceTier",
@@ -7783,9 +7747,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7783
7747
  });
7784
7748
  delete baseArgs.service_tier;
7785
7749
  }
7786
- const shellToolEnvType = (_n = (_m = (_l = tools == null ? void 0 : tools.find(
7750
+ const shellToolEnvType = tools?.find(
7787
7751
  (tool) => tool.type === "provider" && tool.id === "openai.shell"
7788
- )) == null ? void 0 : _l.args) == null ? void 0 : _m.environment) == null ? void 0 : _n.type;
7752
+ )?.args?.environment?.type;
7789
7753
  const isShellProviderExecuted = shellToolEnvType === "containerAuto" || shellToolEnvType === "containerReference";
7790
7754
  return {
7791
7755
  webSearchToolName,
@@ -7809,7 +7773,6 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7809
7773
  });
7810
7774
  }
7811
7775
  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
7776
  const {
7814
7777
  args: body,
7815
7778
  warnings,
@@ -7829,7 +7792,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7829
7792
  rawValue: rawResponse
7830
7793
  } = await postJsonToApi6({
7831
7794
  url,
7832
- headers: combineHeaders7((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
7795
+ headers: combineHeaders7(this.config.headers?.(), options.headers),
7833
7796
  body,
7834
7797
  failedResponseHandler: openaiFailedResponseHandler,
7835
7798
  successfulResponseHandler: createJsonResponseHandler6(
@@ -7850,7 +7813,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7850
7813
  });
7851
7814
  }
7852
7815
  if (response.output == null) {
7853
- const detail = (_c = response.incomplete_details) == null ? void 0 : _c.reason;
7816
+ const detail = response.incomplete_details?.reason;
7854
7817
  throw new APICallError2({
7855
7818
  message: detail ? `Responses API returned no output (${detail})` : "Responses API returned no output",
7856
7819
  url,
@@ -7863,9 +7826,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7863
7826
  }
7864
7827
  const content = [];
7865
7828
  const logprobs = [];
7866
- const functionTools = (_e = (_d = options.tools) == null ? void 0 : _d.filter(
7829
+ const functionTools = options.tools?.filter(
7867
7830
  (tool) => tool.type === "function"
7868
- )) != null ? _e : [];
7831
+ ) ?? [];
7869
7832
  let hasFunctionCall = false;
7870
7833
  const hostedToolSearchCallIds = [];
7871
7834
  for (const part of response.output) {
@@ -7881,7 +7844,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7881
7844
  providerMetadata: {
7882
7845
  [providerOptionsName]: {
7883
7846
  itemId: part.id,
7884
- reasoningEncryptedContent: (_f = part.encrypted_content) != null ? _f : null
7847
+ reasoningEncryptedContent: part.encrypted_content ?? null
7885
7848
  }
7886
7849
  }
7887
7850
  });
@@ -7907,7 +7870,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7907
7870
  break;
7908
7871
  }
7909
7872
  case "tool_search_call": {
7910
- const toolCallId = (_g = part.call_id) != null ? _g : part.id;
7873
+ const toolCallId = part.call_id ?? part.id;
7911
7874
  const isHosted = part.execution === "server";
7912
7875
  if (isHosted) {
7913
7876
  hostedToolSearchCallIds.push(toolCallId);
@@ -7930,7 +7893,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7930
7893
  break;
7931
7894
  }
7932
7895
  case "tool_search_output": {
7933
- const toolCallId = (_i = (_h = part.call_id) != null ? _h : hostedToolSearchCallIds.shift()) != null ? _i : part.id;
7896
+ const toolCallId = part.call_id ?? hostedToolSearchCallIds.shift() ?? part.id;
7934
7897
  content.push({
7935
7898
  type: "tool-result",
7936
7899
  toolCallId,
@@ -8001,7 +7964,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8001
7964
  }
8002
7965
  case "message": {
8003
7966
  for (const contentPart of part.content) {
8004
- if (((_k = (_j = options.providerOptions) == null ? void 0 : _j[providerOptionsName]) == null ? void 0 : _k.logprobs) && contentPart.logprobs) {
7967
+ if (options.providerOptions?.[providerOptionsName]?.logprobs && contentPart.logprobs) {
8005
7968
  logprobs.push(contentPart.logprobs);
8006
7969
  }
8007
7970
  const providerMetadata2 = {
@@ -8023,7 +7986,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8023
7986
  content.push({
8024
7987
  type: "source",
8025
7988
  sourceType: "url",
8026
- id: (_n = (_m = (_l = this.config).generateId) == null ? void 0 : _m.call(_l)) != null ? _n : generateId2(),
7989
+ id: this.config.generateId?.() ?? generateId2(),
8027
7990
  url: annotation.url,
8028
7991
  title: annotation.title
8029
7992
  });
@@ -8031,7 +7994,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8031
7994
  content.push({
8032
7995
  type: "source",
8033
7996
  sourceType: "document",
8034
- id: (_q = (_p = (_o = this.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : generateId2(),
7997
+ id: this.config.generateId?.() ?? generateId2(),
8035
7998
  mediaType: "text/plain",
8036
7999
  title: annotation.filename,
8037
8000
  filename: annotation.filename,
@@ -8047,7 +8010,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8047
8010
  content.push({
8048
8011
  type: "source",
8049
8012
  sourceType: "document",
8050
- id: (_t = (_s = (_r = this.config).generateId) == null ? void 0 : _s.call(_r)) != null ? _t : generateId2(),
8013
+ id: this.config.generateId?.() ?? generateId2(),
8051
8014
  mediaType: "text/plain",
8052
8015
  title: annotation.filename,
8053
8016
  filename: annotation.filename,
@@ -8063,7 +8026,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8063
8026
  content.push({
8064
8027
  type: "source",
8065
8028
  sourceType: "document",
8066
- id: (_w = (_v = (_u = this.config).generateId) == null ? void 0 : _v.call(_u)) != null ? _w : generateId2(),
8029
+ id: this.config.generateId?.() ?? generateId2(),
8067
8030
  mediaType: "application/octet-stream",
8068
8031
  title: annotation.file_id,
8069
8032
  filename: annotation.file_id,
@@ -8178,7 +8141,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8178
8141
  type: "tool-call",
8179
8142
  toolCallId: part.id,
8180
8143
  toolName: toolNameMapping.toCustomToolName(
8181
- webSearchToolName != null ? webSearchToolName : "web_search"
8144
+ webSearchToolName ?? "web_search"
8182
8145
  ),
8183
8146
  input: JSON.stringify({}),
8184
8147
  providerExecuted: true
@@ -8187,14 +8150,14 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8187
8150
  type: "tool-result",
8188
8151
  toolCallId: part.id,
8189
8152
  toolName: toolNameMapping.toCustomToolName(
8190
- webSearchToolName != null ? webSearchToolName : "web_search"
8153
+ webSearchToolName ?? "web_search"
8191
8154
  ),
8192
8155
  result: mapWebSearchOutput(part.action)
8193
8156
  });
8194
8157
  break;
8195
8158
  }
8196
8159
  case "mcp_call": {
8197
- const toolCallId = part.approval_request_id != null ? (_x = approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id]) != null ? _x : part.id : part.id;
8160
+ const toolCallId = part.approval_request_id != null ? approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id] ?? part.id : part.id;
8198
8161
  const toolName = `mcp.${part.name}`;
8199
8162
  content.push({
8200
8163
  type: "tool-call",
@@ -8228,8 +8191,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8228
8191
  break;
8229
8192
  }
8230
8193
  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();
8194
+ const approvalRequestId = part.approval_request_id ?? part.id;
8195
+ const dummyToolCallId = this.config.generateId?.() ?? generateId2();
8233
8196
  const toolName = `mcp.${part.name}`;
8234
8197
  content.push({
8235
8198
  type: "tool-call",
@@ -8295,13 +8258,13 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8295
8258
  toolName: toolNameMapping.toCustomToolName("file_search"),
8296
8259
  result: {
8297
8260
  queries: part.queries,
8298
- results: (_D = (_C = part.results) == null ? void 0 : _C.map((result) => ({
8261
+ results: part.results?.map((result) => ({
8299
8262
  attributes: result.attributes,
8300
8263
  fileId: result.file_id,
8301
8264
  filename: result.filename,
8302
8265
  score: result.score,
8303
8266
  text: result.text
8304
- }))) != null ? _D : null
8267
+ })) ?? null
8305
8268
  }
8306
8269
  });
8307
8270
  break;
@@ -8366,7 +8329,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8366
8329
  responseId: response.id,
8367
8330
  ...logprobs.length > 0 ? { logprobs } : {},
8368
8331
  ...typeof response.service_tier === "string" ? { serviceTier: response.service_tier } : {},
8369
- ...((_E = response.reasoning) == null ? void 0 : _E.context) != null ? { reasoningContext: response.reasoning.context } : {}
8332
+ ...response.reasoning?.context != null ? { reasoningContext: response.reasoning.context } : {}
8370
8333
  }
8371
8334
  };
8372
8335
  const usage = response.usage;
@@ -8374,10 +8337,10 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8374
8337
  content,
8375
8338
  finishReason: {
8376
8339
  unified: mapOpenAIResponseFinishReason({
8377
- finishReason: (_F = response.incomplete_details) == null ? void 0 : _F.reason,
8340
+ finishReason: response.incomplete_details?.reason,
8378
8341
  hasFunctionCall
8379
8342
  }),
8380
- raw: (_H = (_G = response.incomplete_details) == null ? void 0 : _G.reason) != null ? _H : void 0
8343
+ raw: response.incomplete_details?.reason ?? void 0
8381
8344
  },
8382
8345
  usage: convertOpenAIResponsesUsage(usage),
8383
8346
  request: { body },
@@ -8393,7 +8356,6 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8393
8356
  };
8394
8357
  }
8395
8358
  async doStream(options) {
8396
- var _a2, _b, _c, _d;
8397
8359
  const {
8398
8360
  args: body,
8399
8361
  warnings,
@@ -8409,7 +8371,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8409
8371
  });
8410
8372
  const { responseHeaders, value: response } = await postJsonToApi6({
8411
8373
  url,
8412
- headers: combineHeaders7((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
8374
+ headers: combineHeaders7(this.config.headers?.(), options.headers),
8413
8375
  body: {
8414
8376
  ...body,
8415
8377
  stream: true
@@ -8432,9 +8394,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8432
8394
  });
8433
8395
  const self = this;
8434
8396
  const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
8435
- const functionTools = (_d = (_c = options.tools) == null ? void 0 : _c.filter(
8397
+ const functionTools = options.tools?.filter(
8436
8398
  (tool) => tool.type === "function"
8437
- )) != null ? _d : [];
8399
+ ) ?? [];
8438
8400
  const approvalRequestIdToDummyToolCallIdFromStream = /* @__PURE__ */ new Map();
8439
8401
  let finishReason = {
8440
8402
  unified: "other",
@@ -8452,10 +8414,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8452
8414
  const resolveOutputItemId = ({
8453
8415
  itemId,
8454
8416
  outputIndex
8455
- }) => {
8456
- var _a3;
8457
- return outputIndex == null ? itemId : (_a3 = activeOutputItemIds[outputIndex]) != null ? _a3 : itemId;
8458
- };
8417
+ }) => outputIndex == null ? itemId : activeOutputItemIds[outputIndex] ?? itemId;
8459
8418
  let serviceTier;
8460
8419
  let reasoningContext;
8461
8420
  const hostedToolSearchCallIds = [];
@@ -8467,7 +8426,6 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8467
8426
  controller.enqueue({ type: "stream-start", warnings });
8468
8427
  },
8469
8428
  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
8429
  if (options.includeRawChunks) {
8472
8430
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
8473
8431
  }
@@ -8522,7 +8480,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8522
8480
  } else if (value.item.type === "web_search_call") {
8523
8481
  ongoingToolCalls[value.output_index] = {
8524
8482
  toolName: toolNameMapping.toCustomToolName(
8525
- webSearchToolName != null ? webSearchToolName : "web_search"
8483
+ webSearchToolName ?? "web_search"
8526
8484
  ),
8527
8485
  toolCallId: value.item.id
8528
8486
  };
@@ -8530,7 +8488,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8530
8488
  type: "tool-input-start",
8531
8489
  id: value.item.id,
8532
8490
  toolName: toolNameMapping.toCustomToolName(
8533
- webSearchToolName != null ? webSearchToolName : "web_search"
8491
+ webSearchToolName ?? "web_search"
8534
8492
  ),
8535
8493
  providerExecuted: true
8536
8494
  });
@@ -8542,13 +8500,13 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8542
8500
  type: "tool-call",
8543
8501
  toolCallId: value.item.id,
8544
8502
  toolName: toolNameMapping.toCustomToolName(
8545
- webSearchToolName != null ? webSearchToolName : "web_search"
8503
+ webSearchToolName ?? "web_search"
8546
8504
  ),
8547
8505
  input: JSON.stringify({}),
8548
8506
  providerExecuted: true
8549
8507
  });
8550
8508
  } else if (value.item.type === "computer_call") {
8551
- const toolCallId = (_a3 = value.item.call_id) != null ? _a3 : value.item.id;
8509
+ const toolCallId = value.item.call_id ?? value.item.id;
8552
8510
  ongoingToolCalls[value.output_index] = {
8553
8511
  toolName: toolNameMapping.toCustomToolName("computer"),
8554
8512
  toolCallId
@@ -8600,7 +8558,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8600
8558
  ongoingToolCalls[value.output_index] = {
8601
8559
  toolName,
8602
8560
  toolCallId,
8603
- toolSearchExecution: (_b2 = value.item.execution) != null ? _b2 : "server"
8561
+ toolSearchExecution: value.item.execution ?? "server"
8604
8562
  };
8605
8563
  if (isHosted) {
8606
8564
  controller.enqueue({
@@ -8658,7 +8616,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8658
8616
  } else if (value.item.type === "message") {
8659
8617
  activeOutputItemIds[value.output_index] = value.item.id;
8660
8618
  ongoingAnnotations.splice(0);
8661
- activeMessagePhase = (_c2 = value.item.phase) != null ? _c2 : void 0;
8619
+ activeMessagePhase = value.item.phase ?? void 0;
8662
8620
  controller.enqueue({
8663
8621
  type: "text-start",
8664
8622
  id: value.item.id,
@@ -8683,7 +8641,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8683
8641
  providerMetadata: {
8684
8642
  [providerOptionsName]: {
8685
8643
  itemId: value.item.id,
8686
- reasoningEncryptedContent: (_d2 = value.item.encrypted_content) != null ? _d2 : null
8644
+ reasoningEncryptedContent: value.item.encrypted_content ?? null
8687
8645
  }
8688
8646
  }
8689
8647
  });
@@ -8694,7 +8652,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8694
8652
  itemId: value.item.id,
8695
8653
  outputIndex: value.output_index
8696
8654
  });
8697
- const phase = (_e = value.item.phase) != null ? _e : activeMessagePhase;
8655
+ const phase = value.item.phase ?? activeMessagePhase;
8698
8656
  activeMessagePhase = void 0;
8699
8657
  controller.enqueue({
8700
8658
  type: "text-end",
@@ -8715,19 +8673,18 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8715
8673
  const ongoingToolCall = ongoingToolCalls[value.output_index];
8716
8674
  ongoingToolCalls[value.output_index] = void 0;
8717
8675
  hasFunctionCall = true;
8718
- const suppressInputStreaming = (_f = ongoingToolCall == null ? void 0 : ongoingToolCall.suppressInputStreaming) != null ? _f : isUndeclaredParallelToolCall({
8676
+ const suppressInputStreaming = ongoingToolCall?.suppressInputStreaming ?? isUndeclaredParallelToolCall({
8719
8677
  toolName: item.name,
8720
8678
  tools: functionTools
8721
8679
  });
8722
8680
  const enqueueUnexpandedToolCall = () => {
8723
- var _a4;
8724
8681
  if (suppressInputStreaming) {
8725
8682
  controller.enqueue({
8726
8683
  type: "tool-input-start",
8727
8684
  id: item.call_id,
8728
8685
  toolName: item.name
8729
8686
  });
8730
- const bufferedInputDeltas = (_a4 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a4 : [];
8687
+ const bufferedInputDeltas = ongoingToolCall?.bufferedInputDeltas ?? [];
8731
8688
  if (bufferedInputDeltas.length > 0) {
8732
8689
  for (const delta of bufferedInputDeltas) {
8733
8690
  controller.enqueue({
@@ -8763,7 +8720,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8763
8720
  providerMetadata: {
8764
8721
  [providerOptionsName]: {
8765
8722
  itemId: item.id,
8766
- ...item.async != null ? { async: item.async } : (ongoingToolCall == null ? void 0 : ongoingToolCall.async) != null ? { async: ongoingToolCall.async } : {},
8723
+ ...item.async != null ? { async: item.async } : ongoingToolCall?.async != null ? { async: ongoingToolCall.async } : {},
8767
8724
  ...item.namespace != null && {
8768
8725
  namespace: item.namespace
8769
8726
  },
@@ -8867,7 +8824,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8867
8824
  providerMetadata: {
8868
8825
  [providerOptionsName]: {
8869
8826
  itemId: value.item.id,
8870
- ...value.item.async != null ? { async: value.item.async } : (ongoingToolCall == null ? void 0 : ongoingToolCall.async) != null ? { async: ongoingToolCall.async } : {}
8827
+ ...value.item.async != null ? { async: value.item.async } : ongoingToolCall?.async != null ? { async: ongoingToolCall.async } : {}
8871
8828
  }
8872
8829
  }
8873
8830
  });
@@ -8877,7 +8834,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8877
8834
  type: "tool-result",
8878
8835
  toolCallId: value.item.id,
8879
8836
  toolName: toolNameMapping.toCustomToolName(
8880
- webSearchToolName != null ? webSearchToolName : "web_search"
8837
+ webSearchToolName ?? "web_search"
8881
8838
  ),
8882
8839
  result: mapWebSearchOutput(value.item.action)
8883
8840
  });
@@ -8937,13 +8894,13 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8937
8894
  toolName: toolNameMapping.toCustomToolName("file_search"),
8938
8895
  result: {
8939
8896
  queries: value.item.queries,
8940
- results: (_h = (_g = value.item.results) == null ? void 0 : _g.map((result2) => ({
8897
+ results: value.item.results?.map((result2) => ({
8941
8898
  attributes: result2.attributes,
8942
8899
  fileId: result2.file_id,
8943
8900
  filename: result2.filename,
8944
8901
  score: result2.score,
8945
8902
  text: result2.text
8946
- }))) != null ? _h : null
8903
+ })) ?? null
8947
8904
  }
8948
8905
  });
8949
8906
  } else if (value.item.type === "code_interpreter_call") {
@@ -8969,7 +8926,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8969
8926
  const toolCall = ongoingToolCalls[value.output_index];
8970
8927
  const isHosted = value.item.execution === "server";
8971
8928
  if (toolCall != null) {
8972
- const toolCallId = isHosted ? toolCall.toolCallId : (_i = value.item.call_id) != null ? _i : value.item.id;
8929
+ const toolCallId = isHosted ? toolCall.toolCallId : value.item.call_id ?? value.item.id;
8973
8930
  if (isHosted) {
8974
8931
  hostedToolSearchCallIds.push(toolCallId);
8975
8932
  } else {
@@ -9001,7 +8958,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9001
8958
  }
9002
8959
  ongoingToolCalls[value.output_index] = void 0;
9003
8960
  } 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;
8961
+ const toolCallId = value.item.call_id ?? hostedToolSearchCallIds.shift() ?? value.item.id;
9005
8962
  controller.enqueue({
9006
8963
  type: "tool-result",
9007
8964
  toolCallId,
@@ -9017,10 +8974,10 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9017
8974
  });
9018
8975
  } else if (value.item.type === "mcp_call") {
9019
8976
  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(
8977
+ const approvalRequestId = value.item.approval_request_id ?? void 0;
8978
+ const aliasedToolCallId = approvalRequestId != null ? approvalRequestIdToDummyToolCallIdFromStream.get(
9022
8979
  approvalRequestId
9023
- )) != null ? _m : approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId]) != null ? _n : value.item.id : value.item.id;
8980
+ ) ?? approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId] ?? value.item.id : value.item.id;
9024
8981
  const toolName = `mcp.${value.item.name}`;
9025
8982
  controller.enqueue({
9026
8983
  type: "tool-call",
@@ -9052,7 +9009,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9052
9009
  ongoingToolCalls[value.output_index] = void 0;
9053
9010
  } else if (value.item.type === "apply_patch_call") {
9054
9011
  const toolCall = ongoingToolCalls[value.output_index];
9055
- if ((toolCall == null ? void 0 : toolCall.applyPatch) && !toolCall.applyPatch.endEmitted && value.item.operation.type !== "delete_file") {
9012
+ if (toolCall?.applyPatch && !toolCall.applyPatch.endEmitted && value.item.operation.type !== "delete_file") {
9056
9013
  if (!toolCall.applyPatch.hasDiff) {
9057
9014
  controller.enqueue({
9058
9015
  type: "tool-input-delta",
@@ -9091,8 +9048,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9091
9048
  ongoingToolCalls[value.output_index] = void 0;
9092
9049
  } else if (value.item.type === "mcp_approval_request") {
9093
9050
  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;
9051
+ const dummyToolCallId = self.config.generateId?.() ?? generateId2();
9052
+ const approvalRequestId = value.item.approval_request_id ?? value.item.id;
9096
9053
  approvalRequestIdToDummyToolCallIdFromStream.set(
9097
9054
  approvalRequestId,
9098
9055
  dummyToolCallId
@@ -9186,7 +9143,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9186
9143
  providerMetadata: {
9187
9144
  [providerOptionsName]: {
9188
9145
  itemId,
9189
- reasoningEncryptedContent: (_s = value.item.encrypted_content) != null ? _s : null
9146
+ reasoningEncryptedContent: value.item.encrypted_content ?? null
9190
9147
  }
9191
9148
  }
9192
9149
  });
@@ -9211,7 +9168,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9211
9168
  const toolCall = ongoingToolCalls[value.output_index];
9212
9169
  if (toolCall != null) {
9213
9170
  if (toolCall.suppressInputStreaming) {
9214
- (_t = toolCall.bufferedInputDeltas) == null ? void 0 : _t.push(value.delta);
9171
+ toolCall.bufferedInputDeltas?.push(value.delta);
9215
9172
  } else {
9216
9173
  controller.enqueue({
9217
9174
  type: "tool-input-delta",
@@ -9231,7 +9188,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9231
9188
  }
9232
9189
  } else if (isResponseApplyPatchCallOperationDiffDeltaChunk(value)) {
9233
9190
  const toolCall = ongoingToolCalls[value.output_index];
9234
- if (toolCall == null ? void 0 : toolCall.applyPatch) {
9191
+ if (toolCall?.applyPatch) {
9235
9192
  controller.enqueue({
9236
9193
  type: "tool-input-delta",
9237
9194
  id: toolCall.toolCallId,
@@ -9241,7 +9198,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9241
9198
  }
9242
9199
  } else if (isResponseApplyPatchCallOperationDiffDoneChunk(value)) {
9243
9200
  const toolCall = ongoingToolCalls[value.output_index];
9244
- if ((toolCall == null ? void 0 : toolCall.applyPatch) && !toolCall.applyPatch.endEmitted) {
9201
+ if (toolCall?.applyPatch && !toolCall.applyPatch.endEmitted) {
9245
9202
  if (!toolCall.applyPatch.hasDiff) {
9246
9203
  controller.enqueue({
9247
9204
  type: "tool-input-delta",
@@ -9321,7 +9278,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9321
9278
  id: itemId,
9322
9279
  delta: value.delta
9323
9280
  });
9324
- if (((_v = (_u = options.providerOptions) == null ? void 0 : _u[providerOptionsName]) == null ? void 0 : _v.logprobs) && value.logprobs) {
9281
+ if (options.providerOptions?.[providerOptionsName]?.logprobs && value.logprobs) {
9325
9282
  logprobs.push(value.logprobs);
9326
9283
  }
9327
9284
  } else if (value.type === "response.reasoning_summary_part.added") {
@@ -9355,7 +9312,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9355
9312
  providerMetadata: {
9356
9313
  [providerOptionsName]: {
9357
9314
  itemId,
9358
- reasoningEncryptedContent: (_w = activeReasoningPart.encryptedContent) != null ? _w : null
9315
+ reasoningEncryptedContent: activeReasoningPart.encryptedContent ?? null
9359
9316
  }
9360
9317
  }
9361
9318
  });
@@ -9402,30 +9359,30 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9402
9359
  if (!encounteredStreamError) {
9403
9360
  finishReason = {
9404
9361
  unified: mapOpenAIResponseFinishReason({
9405
- finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
9362
+ finishReason: value.response.incomplete_details?.reason,
9406
9363
  hasFunctionCall
9407
9364
  }),
9408
- raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
9365
+ raw: value.response.incomplete_details?.reason ?? void 0
9409
9366
  };
9410
9367
  }
9411
- usage = (_A = value.response.usage) != null ? _A : void 0;
9368
+ usage = value.response.usage ?? void 0;
9412
9369
  if (typeof value.response.service_tier === "string") {
9413
9370
  serviceTier = value.response.service_tier;
9414
9371
  }
9415
- if (((_B = value.response.reasoning) == null ? void 0 : _B.context) != null) {
9372
+ if (value.response.reasoning?.context != null) {
9416
9373
  reasoningContext = value.response.reasoning.context;
9417
9374
  }
9418
9375
  } else if (isResponseFailedChunk(value)) {
9419
- const incompleteReason = (_C = value.response.incomplete_details) == null ? void 0 : _C.reason;
9376
+ const incompleteReason = value.response.incomplete_details?.reason;
9420
9377
  finishReason = {
9421
9378
  unified: incompleteReason ? mapOpenAIResponseFinishReason({
9422
9379
  finishReason: incompleteReason,
9423
9380
  hasFunctionCall
9424
9381
  }) : "error",
9425
- raw: incompleteReason != null ? incompleteReason : "error"
9382
+ raw: incompleteReason ?? "error"
9426
9383
  };
9427
- usage = (_D = value.response.usage) != null ? _D : void 0;
9428
- if (((_E = value.response.reasoning) == null ? void 0 : _E.context) != null) {
9384
+ usage = value.response.usage ?? void 0;
9385
+ if (value.response.reasoning?.context != null) {
9429
9386
  reasoningContext = value.response.reasoning.context;
9430
9387
  }
9431
9388
  if (!encounteredStreamError && value.response.error != null) {
@@ -9441,7 +9398,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9441
9398
  };
9442
9399
  controller.enqueue({
9443
9400
  type: "error",
9444
- error: (_F = createOpenAIProviderStreamError(error)) != null ? _F : error
9401
+ error: createOpenAIProviderStreamError(error) ?? error
9445
9402
  });
9446
9403
  }
9447
9404
  } else if (isResponseAnnotationAddedChunk(value)) {
@@ -9450,7 +9407,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9450
9407
  controller.enqueue({
9451
9408
  type: "source",
9452
9409
  sourceType: "url",
9453
- id: (_I = (_H = (_G = self.config).generateId) == null ? void 0 : _H.call(_G)) != null ? _I : generateId2(),
9410
+ id: self.config.generateId?.() ?? generateId2(),
9454
9411
  url: value.annotation.url,
9455
9412
  title: value.annotation.title
9456
9413
  });
@@ -9458,7 +9415,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9458
9415
  controller.enqueue({
9459
9416
  type: "source",
9460
9417
  sourceType: "document",
9461
- id: (_L = (_K = (_J = self.config).generateId) == null ? void 0 : _K.call(_J)) != null ? _L : generateId2(),
9418
+ id: self.config.generateId?.() ?? generateId2(),
9462
9419
  mediaType: "text/plain",
9463
9420
  title: value.annotation.filename,
9464
9421
  filename: value.annotation.filename,
@@ -9474,7 +9431,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9474
9431
  controller.enqueue({
9475
9432
  type: "source",
9476
9433
  sourceType: "document",
9477
- id: (_O = (_N = (_M = self.config).generateId) == null ? void 0 : _N.call(_M)) != null ? _O : generateId2(),
9434
+ id: self.config.generateId?.() ?? generateId2(),
9478
9435
  mediaType: "text/plain",
9479
9436
  title: value.annotation.filename,
9480
9437
  filename: value.annotation.filename,
@@ -9490,7 +9447,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9490
9447
  controller.enqueue({
9491
9448
  type: "source",
9492
9449
  sourceType: "document",
9493
- id: (_R = (_Q = (_P = self.config).generateId) == null ? void 0 : _Q.call(_P)) != null ? _R : generateId2(),
9450
+ id: self.config.generateId?.() ?? generateId2(),
9494
9451
  mediaType: "application/octet-stream",
9495
9452
  title: value.annotation.file_id,
9496
9453
  filename: value.annotation.file_id,
@@ -9508,14 +9465,13 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9508
9465
  finishReason = { unified: "error", raw: "error" };
9509
9466
  controller.enqueue({
9510
9467
  type: "error",
9511
- error: (_S = createOpenAIProviderStreamError(value)) != null ? _S : value
9468
+ error: createOpenAIProviderStreamError(value) ?? value
9512
9469
  });
9513
9470
  }
9514
9471
  },
9515
9472
  flush(controller) {
9516
- var _a3;
9517
9473
  for (const toolCall of Object.values(ongoingToolCalls)) {
9518
- if (!(toolCall == null ? void 0 : toolCall.suppressInputStreaming)) {
9474
+ if (!toolCall?.suppressInputStreaming) {
9519
9475
  continue;
9520
9476
  }
9521
9477
  controller.enqueue({
@@ -9523,7 +9479,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9523
9479
  id: toolCall.toolCallId,
9524
9480
  toolName: toolCall.toolName
9525
9481
  });
9526
- for (const delta of (_a3 = toolCall.bufferedInputDeltas) != null ? _a3 : []) {
9482
+ for (const delta of toolCall.bufferedInputDeltas ?? []) {
9527
9483
  controller.enqueue({
9528
9484
  type: "tool-input-delta",
9529
9485
  id: toolCall.toolCallId,
@@ -9631,7 +9587,6 @@ function isResponseOutputChunk(chunk) {
9631
9587
  return !(chunk.type === "response.created" || chunk.type === "response.in_progress" || chunk.type === "response.failed" || chunk.type === "error" || chunk.type === "unknown_chunk");
9632
9588
  }
9633
9589
  function mapWebSearchOutput(action) {
9634
- var _a2;
9635
9590
  if (action == null) {
9636
9591
  return {};
9637
9592
  }
@@ -9640,7 +9595,7 @@ function mapWebSearchOutput(action) {
9640
9595
  return {
9641
9596
  action: {
9642
9597
  type: "search",
9643
- query: (_a2 = action.query) != null ? _a2 : void 0,
9598
+ query: action.query ?? void 0,
9644
9599
  ...action.queries != null && { queries: action.queries }
9645
9600
  },
9646
9601
  // include sources when provided by the Responses API (behind include flag)