@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.
package/dist/index.js CHANGED
@@ -47,17 +47,16 @@ var openaiFailedResponseHandler = createJsonErrorResponseHandler({
47
47
 
48
48
  // src/openai-language-model-capabilities.ts
49
49
  function getOpenAILanguageModelCapabilities(modelId) {
50
- var _a2, _b, _c, _d, _e;
51
50
  const oSeriesVersion = getOSeriesVersion(modelId);
52
51
  const gptVersion = getGptVersion(modelId);
53
- 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);
54
- const isGptNanoModel = (_d = (_c = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _c.startsWith("nano")) != null ? _d : false;
52
+ const isGptChatModel = gptVersion?.minor == null && (gptVersion?.variant?.startsWith("chat") ?? false);
53
+ const isGptNanoModel = gptVersion?.variant?.startsWith("nano") ?? false;
55
54
  const isGpt6OrLaterModel = gptVersion != null && gptVersion.major >= 6;
56
55
  const isGpt6SolOrLuna = modelId === "gpt-6-sol" || modelId === "gpt-6-luna";
57
56
  const supportsFlexProcessing = oSeriesVersion != null && oSeriesVersion >= 3 || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
58
57
  const supportsPriorityProcessing = modelId.startsWith("gpt-4") || gptVersion != null && gptVersion.major >= 5 && !isGptNanoModel && !isGptChatModel || oSeriesVersion != null && oSeriesVersion >= 3;
59
58
  const isReasoningModel = oSeriesVersion != null || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
60
- const supportsNonReasoningParameters = !isGpt6OrLaterModel && gptVersion != null && (gptVersion.major > 5 || gptVersion.major === 5 && ((_e = gptVersion.minor) != null ? _e : 0) >= 1);
59
+ const supportsNonReasoningParameters = !isGpt6OrLaterModel && gptVersion != null && (gptVersion.major > 5 || gptVersion.major === 5 && (gptVersion.minor ?? 0) >= 1);
61
60
  const systemMessageMode = isReasoningModel ? "developer" : "system";
62
61
  return {
63
62
  supportsFlexProcessing,
@@ -92,7 +91,6 @@ import {
92
91
  createProviderStreamError
93
92
  } from "@ai-sdk/provider-utils";
94
93
  function createOpenAIProviderStreamError(frame) {
95
- var _a2, _b;
96
94
  const streamError = parseStreamError(frame);
97
95
  if (streamError == null) {
98
96
  return void 0;
@@ -100,8 +98,8 @@ function createOpenAIProviderStreamError(frame) {
100
98
  const statusCode = getStatusCode(streamError);
101
99
  return createProviderStreamError({
102
100
  message: streamError.message,
103
- type: (_a2 = streamError.type) != null ? _a2 : void 0,
104
- code: (_b = streamError.code) != null ? _b : void 0,
101
+ type: streamError.type ?? void 0,
102
+ code: streamError.code ?? void 0,
105
103
  statusCode,
106
104
  isRetryable: isRetryableStreamError(streamError, statusCode),
107
105
  data: frame
@@ -157,7 +155,7 @@ async function throwIfOpenAIStreamErrorBeforeOutput({
157
155
  if (isOutputChunk(chunk.value)) {
158
156
  return streamForConsumer;
159
157
  }
160
- if (!accepted && (isAcceptedChunk == null ? void 0 : isAcceptedChunk(chunk.value)) === true) {
158
+ if (!accepted && isAcceptedChunk?.(chunk.value) === true) {
161
159
  accepted = true;
162
160
  }
163
161
  }
@@ -173,7 +171,7 @@ async function drainReader(reader) {
173
171
  try {
174
172
  while (!(await reader.read()).done) {
175
173
  }
176
- } catch (e) {
174
+ } catch {
177
175
  } finally {
178
176
  reader.releaseLock();
179
177
  }
@@ -203,35 +201,33 @@ function createOpenAIStreamError({
203
201
  requestBodyValues,
204
202
  responseHeaders
205
203
  }) {
206
- var _a2, _b;
207
204
  const streamError = createOpenAIProviderStreamError(frame);
208
205
  return new APICallError({
209
- message: (_a2 = streamError == null ? void 0 : streamError.message) != null ? _a2 : "OpenAI stream failed before any output was generated",
206
+ message: streamError?.message ?? "OpenAI stream failed before any output was generated",
210
207
  url,
211
208
  requestBodyValues,
212
- statusCode: (_b = streamError == null ? void 0 : streamError.statusCode) != null ? _b : 500,
209
+ statusCode: streamError?.statusCode ?? 500,
213
210
  responseHeaders,
214
211
  responseBody: JSON.stringify(frame),
215
212
  data: frame,
216
- isRetryable: streamError == null ? void 0 : streamError.isRetryable
213
+ isRetryable: streamError?.isRetryable
217
214
  });
218
215
  }
219
216
  function parseStreamError(frame) {
220
- var _a2;
221
217
  const value = asRecord(frame);
222
218
  if (value == null) {
223
219
  return void 0;
224
220
  }
225
221
  if (value.type === "response.failed") {
226
222
  const response = asRecord(value.response);
227
- const responseError = asRecord(response == null ? void 0 : response.error);
228
- return typeof (responseError == null ? void 0 : responseError.message) === "string" ? {
223
+ const responseError = asRecord(response?.error);
224
+ return typeof responseError?.message === "string" ? {
229
225
  message: responseError.message,
230
226
  code: getStringOrNumber(responseError.code),
231
227
  type: "response.failed"
232
228
  } : void 0;
233
229
  }
234
- const error = (_a2 = asRecord(value.error)) != null ? _a2 : value;
230
+ const error = asRecord(value.error) ?? value;
235
231
  return typeof error.message === "string" && (asRecord(value.error) != null || typeof error.type === "string" || "code" in error || "param" in error) ? {
236
232
  message: error.message,
237
233
  code: getStringOrNumber(error.code),
@@ -287,19 +283,18 @@ function isRetryableStreamError(error, statusCode) {
287
283
  // src/chat/convert-openai-chat-usage.ts
288
284
  import { createNullLanguageModelUsage } from "@ai-sdk/provider-utils";
289
285
  function convertOpenAIChatUsage(usage) {
290
- var _a2, _b, _c, _d, _e, _f, _g, _h;
291
286
  if (usage == null) {
292
287
  return createNullLanguageModelUsage();
293
288
  }
294
- const promptTokens = (_a2 = usage.prompt_tokens) != null ? _a2 : 0;
295
- const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
296
- const cachedTokens = (_d = (_c = usage.prompt_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : 0;
297
- const cacheWriteTokens = (_f = (_e = usage.prompt_tokens_details) == null ? void 0 : _e.cache_write_tokens) != null ? _f : void 0;
298
- const reasoningTokens = (_h = (_g = usage.completion_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : 0;
289
+ const promptTokens = usage.prompt_tokens ?? 0;
290
+ const completionTokens = usage.completion_tokens ?? 0;
291
+ const cachedTokens = usage.prompt_tokens_details?.cached_tokens ?? 0;
292
+ const cacheWriteTokens = usage.prompt_tokens_details?.cache_write_tokens ?? void 0;
293
+ const reasoningTokens = usage.completion_tokens_details?.reasoning_tokens ?? 0;
299
294
  return {
300
295
  inputTokens: {
301
296
  total: promptTokens,
302
- noCache: promptTokens - cachedTokens - (cacheWriteTokens != null ? cacheWriteTokens : 0),
297
+ noCache: promptTokens - cachedTokens - (cacheWriteTokens ?? 0),
303
298
  cacheRead: cachedTokens,
304
299
  cacheWrite: cacheWriteTokens
305
300
  },
@@ -328,14 +323,12 @@ function serializeToolCallArguments(input) {
328
323
  );
329
324
  }
330
325
  function getPromptCacheBreakpoint(providerOptions) {
331
- var _a2;
332
- return (_a2 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a2.promptCacheBreakpoint;
326
+ return providerOptions?.openai?.promptCacheBreakpoint;
333
327
  }
334
328
  function convertToOpenAIChatMessages({
335
329
  prompt,
336
330
  systemMessageMode = "system"
337
331
  }) {
338
- var _a2, _b;
339
332
  const messages = [];
340
333
  const warnings = [];
341
334
  for (const { role, content, providerOptions } of prompt) {
@@ -394,7 +387,6 @@ function convertToOpenAIChatMessages({
394
387
  messages.push({
395
388
  role: "user",
396
389
  content: content.map((part, index) => {
397
- var _a3, _b2, _c;
398
390
  switch (part.type) {
399
391
  case "text": {
400
392
  const promptCacheBreakpoint = getPromptCacheBreakpoint(
@@ -440,7 +432,7 @@ function convertToOpenAIChatMessages({
440
432
  type: "image_url",
441
433
  image_url: {
442
434
  url: part.data.type === "url" ? part.data.url.toString() : `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`,
443
- detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3.openai) == null ? void 0 : _b2.imageDetail
435
+ detail: part.providerOptions?.openai?.imageDetail
444
436
  },
445
437
  ...promptCacheBreakpoint != null && {
446
438
  prompt_cache_breakpoint: promptCacheBreakpoint
@@ -501,7 +493,7 @@ function convertToOpenAIChatMessages({
501
493
  return {
502
494
  type: "file",
503
495
  file: {
504
- filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
496
+ filename: part.filename ?? `part-${index}.pdf`,
505
497
  file_data: `data:application/pdf;base64,${convertToBase64(part.data.data)}`
506
498
  },
507
499
  ...promptCacheBreakpoint != null && {
@@ -536,7 +528,7 @@ function convertToOpenAIChatMessages({
536
528
  prompt_cache_breakpoint: promptCacheBreakpoint
537
529
  }
538
530
  });
539
- hasPromptCacheBreakpoint || (hasPromptCacheBreakpoint = promptCacheBreakpoint != null);
531
+ hasPromptCacheBreakpoint ||= promptCacheBreakpoint != null;
540
532
  break;
541
533
  }
542
534
  case "tool-call": {
@@ -565,7 +557,7 @@ function convertToOpenAIChatMessages({
565
557
  continue;
566
558
  }
567
559
  const output = toolResponse.output;
568
- 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);
560
+ const promptCacheBreakpoint = (output.type === "content" ? output.value.map((part) => getPromptCacheBreakpoint(part.providerOptions)).find((breakpoint) => breakpoint != null) : getPromptCacheBreakpoint(output.providerOptions)) ?? getPromptCacheBreakpoint(toolResponse.providerOptions);
569
561
  let contentValue;
570
562
  switch (output.type) {
571
563
  case "text":
@@ -573,7 +565,7 @@ function convertToOpenAIChatMessages({
573
565
  contentValue = output.value;
574
566
  break;
575
567
  case "execution-denied":
576
- contentValue = (_b = output.reason) != null ? _b : "Tool call execution denied.";
568
+ contentValue = output.reason ?? "Tool call execution denied.";
577
569
  break;
578
570
  case "content":
579
571
  case "json":
@@ -1087,7 +1079,7 @@ function prepareChatTools({
1087
1079
  tools,
1088
1080
  toolChoice
1089
1081
  }) {
1090
- tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
1082
+ tools = tools?.length ? tools : void 0;
1091
1083
  const toolWarnings = [];
1092
1084
  if (tools == null) {
1093
1085
  return { tools: void 0, toolChoice: void 0, toolWarnings };
@@ -1186,15 +1178,14 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1186
1178
  reasoning,
1187
1179
  providerOptions
1188
1180
  }) {
1189
- var _a2, _b, _c, _d, _e, _f;
1190
1181
  const warnings = [];
1191
- const openaiOptions = (_a2 = await parseProviderOptions({
1182
+ const openaiOptions = await parseProviderOptions({
1192
1183
  provider: "openai",
1193
1184
  providerOptions,
1194
1185
  schema: openaiLanguageModelChatOptions
1195
- })) != null ? _a2 : {};
1186
+ }) ?? {};
1196
1187
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
1197
- let resolvedReasoningEffort = (_b = openaiOptions.reasoningEffort) != null ? _b : isCustomReasoning(reasoning) ? reasoning : void 0;
1188
+ let resolvedReasoningEffort = openaiOptions.reasoningEffort ?? (isCustomReasoning(reasoning) ? reasoning : void 0);
1198
1189
  if (resolvedReasoningEffort != null && modelCapabilities.supportedReasoningEfforts != null && !modelCapabilities.supportedReasoningEfforts.includes(
1199
1190
  resolvedReasoningEffort
1200
1191
  )) {
@@ -1205,19 +1196,19 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1205
1196
  });
1206
1197
  resolvedReasoningEffort = void 0;
1207
1198
  }
1208
- const isReasoningModel = (_c = openaiOptions.forceReasoning) != null ? _c : modelCapabilities.isReasoningModel;
1199
+ const isReasoningModel = openaiOptions.forceReasoning ?? modelCapabilities.isReasoningModel;
1209
1200
  if (topK != null) {
1210
1201
  warnings.push({ type: "unsupported", feature: "topK" });
1211
1202
  }
1212
1203
  const { messages, warnings: messageWarnings } = convertToOpenAIChatMessages(
1213
1204
  {
1214
1205
  prompt,
1215
- systemMessageMode: (_d = openaiOptions.systemMessageMode) != null ? _d : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode
1206
+ systemMessageMode: openaiOptions.systemMessageMode ?? (isReasoningModel ? "developer" : modelCapabilities.systemMessageMode)
1216
1207
  }
1217
1208
  );
1218
1209
  warnings.push(...messageWarnings);
1219
- const strictJsonSchema = (_e = openaiOptions.strictJsonSchema) != null ? _e : true;
1220
- const normalizedResponseFormatSchema = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? normalizeOpenAIJsonSchema(responseFormat.schema) : void 0;
1210
+ const strictJsonSchema = openaiOptions.strictJsonSchema ?? true;
1211
+ const normalizedResponseFormatSchema = responseFormat?.type === "json" && responseFormat.schema != null ? normalizeOpenAIJsonSchema(responseFormat.schema) : void 0;
1221
1212
  if (normalizedResponseFormatSchema != null) {
1222
1213
  warnings.push(...normalizedResponseFormatSchema.warnings);
1223
1214
  }
@@ -1236,12 +1227,12 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1236
1227
  top_p: topP,
1237
1228
  frequency_penalty: frequencyPenalty,
1238
1229
  presence_penalty: presencePenalty,
1239
- response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? normalizedResponseFormatSchema != null ? {
1230
+ response_format: responseFormat?.type === "json" ? normalizedResponseFormatSchema != null ? {
1240
1231
  type: "json_schema",
1241
1232
  json_schema: {
1242
1233
  schema: normalizedResponseFormatSchema.schema,
1243
1234
  strict: strictJsonSchema,
1244
- name: (_f = responseFormat.name) != null ? _f : "response",
1235
+ name: responseFormat.name ?? "response",
1245
1236
  description: responseFormat.description
1246
1237
  }
1247
1238
  } : { type: "json_object" } : void 0,
@@ -1377,7 +1368,6 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1377
1368
  };
1378
1369
  }
1379
1370
  async doGenerate(options) {
1380
- var _a2, _b, _c, _d, _e, _f, _g, _h;
1381
1371
  const { args: body, warnings } = await this.getArgs(options);
1382
1372
  const {
1383
1373
  responseHeaders,
@@ -1388,7 +1378,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1388
1378
  path: "/chat/completions",
1389
1379
  modelId: this.modelId
1390
1380
  }),
1391
- headers: combineHeaders((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
1381
+ headers: combineHeaders(this.config.headers?.(), options.headers),
1392
1382
  body,
1393
1383
  failedResponseHandler: openaiFailedResponseHandler,
1394
1384
  successfulResponseHandler: createJsonResponseHandler(
@@ -1405,11 +1395,11 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1405
1395
  });
1406
1396
  }
1407
1397
  const content = [];
1408
- const text = choice.message.content != null && choice.message.content.length > 0 ? choice.message.content : (_c = choice.message.audio) == null ? void 0 : _c.transcript;
1398
+ const text = choice.message.content != null && choice.message.content.length > 0 ? choice.message.content : choice.message.audio?.transcript;
1409
1399
  if (text != null && text.length > 0) {
1410
1400
  content.push({ type: "text", text });
1411
1401
  }
1412
- for (const toolCall of (_d = choice.message.tool_calls) != null ? _d : []) {
1402
+ for (const toolCall of choice.message.tool_calls ?? []) {
1413
1403
  content.push({
1414
1404
  type: "tool-call",
1415
1405
  toolCallId: toolCall.id || generateId(),
@@ -1417,7 +1407,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1417
1407
  input: toolCall.function.arguments
1418
1408
  });
1419
1409
  }
1420
- for (const annotation of (_e = choice.message.annotations) != null ? _e : []) {
1410
+ for (const annotation of choice.message.annotations ?? []) {
1421
1411
  content.push({
1422
1412
  type: "source",
1423
1413
  sourceType: "url",
@@ -1426,22 +1416,22 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1426
1416
  title: annotation.url_citation.title
1427
1417
  });
1428
1418
  }
1429
- const completionTokenDetails = (_f = response.usage) == null ? void 0 : _f.completion_tokens_details;
1419
+ const completionTokenDetails = response.usage?.completion_tokens_details;
1430
1420
  const providerMetadata = { openai: {} };
1431
- if ((completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens) != null) {
1432
- providerMetadata.openai.acceptedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens;
1421
+ if (completionTokenDetails?.accepted_prediction_tokens != null) {
1422
+ providerMetadata.openai.acceptedPredictionTokens = completionTokenDetails?.accepted_prediction_tokens;
1433
1423
  }
1434
- if ((completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens) != null) {
1435
- providerMetadata.openai.rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
1424
+ if (completionTokenDetails?.rejected_prediction_tokens != null) {
1425
+ providerMetadata.openai.rejectedPredictionTokens = completionTokenDetails?.rejected_prediction_tokens;
1436
1426
  }
1437
- if (((_g = choice.logprobs) == null ? void 0 : _g.content) != null) {
1427
+ if (choice.logprobs?.content != null) {
1438
1428
  providerMetadata.openai.logprobs = choice.logprobs.content;
1439
1429
  }
1440
1430
  return {
1441
1431
  content,
1442
1432
  finishReason: {
1443
1433
  unified: mapOpenAIFinishReason(choice.finish_reason),
1444
- raw: (_h = choice.finish_reason) != null ? _h : void 0
1434
+ raw: choice.finish_reason ?? void 0
1445
1435
  },
1446
1436
  usage: convertOpenAIChatUsage(response.usage),
1447
1437
  request: { body },
@@ -1455,7 +1445,6 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1455
1445
  };
1456
1446
  }
1457
1447
  async doStream(options) {
1458
- var _a2, _b;
1459
1448
  const { args, warnings } = await this.getArgs(options);
1460
1449
  const body = {
1461
1450
  ...args,
@@ -1470,7 +1459,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1470
1459
  });
1471
1460
  const { responseHeaders, value: response } = await postJsonToApi({
1472
1461
  url,
1473
- headers: combineHeaders((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
1462
+ headers: combineHeaders(this.config.headers?.(), options.headers),
1474
1463
  body,
1475
1464
  failedResponseHandler: openaiFailedResponseHandler,
1476
1465
  successfulResponseHandler: createEventSourceResponseHandler(
@@ -1507,7 +1496,6 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1507
1496
  controller.enqueue({ type: "stream-start", warnings });
1508
1497
  },
1509
1498
  transform(chunk, controller) {
1510
- var _a3, _b2, _c, _d, _e, _f;
1511
1499
  if (options.includeRawChunks) {
1512
1500
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1513
1501
  }
@@ -1521,7 +1509,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1521
1509
  finishReason = { unified: "error", raw: void 0 };
1522
1510
  controller.enqueue({
1523
1511
  type: "error",
1524
- error: (_a3 = createOpenAIProviderStreamError(value.error)) != null ? _a3 : value.error
1512
+ error: createOpenAIProviderStreamError(value.error) ?? value.error
1525
1513
  });
1526
1514
  return;
1527
1515
  }
@@ -1537,24 +1525,24 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1537
1525
  }
1538
1526
  if (value.usage != null) {
1539
1527
  usage = value.usage;
1540
- if (((_b2 = value.usage.completion_tokens_details) == null ? void 0 : _b2.accepted_prediction_tokens) != null) {
1541
- providerMetadata.openai.acceptedPredictionTokens = (_c = value.usage.completion_tokens_details) == null ? void 0 : _c.accepted_prediction_tokens;
1528
+ if (value.usage.completion_tokens_details?.accepted_prediction_tokens != null) {
1529
+ providerMetadata.openai.acceptedPredictionTokens = value.usage.completion_tokens_details?.accepted_prediction_tokens;
1542
1530
  }
1543
- if (((_d = value.usage.completion_tokens_details) == null ? void 0 : _d.rejected_prediction_tokens) != null) {
1544
- providerMetadata.openai.rejectedPredictionTokens = (_e = value.usage.completion_tokens_details) == null ? void 0 : _e.rejected_prediction_tokens;
1531
+ if (value.usage.completion_tokens_details?.rejected_prediction_tokens != null) {
1532
+ providerMetadata.openai.rejectedPredictionTokens = value.usage.completion_tokens_details?.rejected_prediction_tokens;
1545
1533
  }
1546
1534
  }
1547
1535
  const choice = value.choices[0];
1548
- if ((choice == null ? void 0 : choice.finish_reason) != null) {
1536
+ if (choice?.finish_reason != null) {
1549
1537
  finishReason = {
1550
1538
  unified: mapOpenAIFinishReason(choice.finish_reason),
1551
1539
  raw: choice.finish_reason
1552
1540
  };
1553
1541
  }
1554
- if (((_f = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _f.content) != null) {
1542
+ if (choice?.logprobs?.content != null) {
1555
1543
  providerMetadata.openai.logprobs = choice.logprobs.content;
1556
1544
  }
1557
- if ((choice == null ? void 0 : choice.delta) == null) {
1545
+ if (choice?.delta == null) {
1558
1546
  return;
1559
1547
  }
1560
1548
  const delta = choice.delta;
@@ -1612,7 +1600,7 @@ function isOpenAIChatOutputChunk(chunk) {
1612
1600
  }
1613
1601
  return chunk.choices.some((choice) => {
1614
1602
  const delta = choice.delta;
1615
- 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;
1603
+ return delta?.content != null && delta.content.length > 0 || delta?.tool_calls != null && delta.tool_calls.length > 0 || delta?.annotations != null && delta.annotations.length > 0;
1616
1604
  });
1617
1605
  }
1618
1606
 
@@ -1631,21 +1619,20 @@ import {
1631
1619
  // src/completion/convert-openai-completion-usage.ts
1632
1620
  import { createNullLanguageModelUsage as createNullLanguageModelUsage2 } from "@ai-sdk/provider-utils";
1633
1621
  function convertOpenAICompletionUsage(usage) {
1634
- var _a2, _b, _c, _d;
1635
1622
  if (usage == null) {
1636
1623
  return createNullLanguageModelUsage2();
1637
1624
  }
1638
- const promptTokens = (_a2 = usage.prompt_tokens) != null ? _a2 : 0;
1639
- const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
1625
+ const promptTokens = usage.prompt_tokens ?? 0;
1626
+ const completionTokens = usage.completion_tokens ?? 0;
1640
1627
  return {
1641
1628
  inputTokens: {
1642
- total: (_c = usage.prompt_tokens) != null ? _c : void 0,
1629
+ total: usage.prompt_tokens ?? void 0,
1643
1630
  noCache: promptTokens,
1644
1631
  cacheRead: void 0,
1645
1632
  cacheWrite: void 0
1646
1633
  },
1647
1634
  outputTokens: {
1648
- total: (_d = usage.completion_tokens) != null ? _d : void 0,
1635
+ total: usage.completion_tokens ?? void 0,
1649
1636
  text: completionTokens,
1650
1637
  reasoning: void 0
1651
1638
  },
@@ -1919,7 +1906,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
1919
1906
  if (topK != null) {
1920
1907
  warnings.push({ type: "unsupported", feature: "topK" });
1921
1908
  }
1922
- if (tools == null ? void 0 : tools.length) {
1909
+ if (tools?.length) {
1923
1910
  warnings.push({ type: "unsupported", feature: "tools" });
1924
1911
  }
1925
1912
  if (toolChoice != null) {
@@ -1933,7 +1920,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
1933
1920
  });
1934
1921
  }
1935
1922
  const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt });
1936
- const stop = [...stopSequences != null ? stopSequences : [], ...userStopSequences != null ? userStopSequences : []];
1923
+ const stop = [...stopSequences ?? [], ...userStopSequences ?? []];
1937
1924
  return {
1938
1925
  args: {
1939
1926
  // model id:
@@ -1941,7 +1928,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
1941
1928
  // model specific settings:
1942
1929
  echo: openaiOptions.echo,
1943
1930
  logit_bias: openaiOptions.logitBias,
1944
- logprobs: (openaiOptions == null ? void 0 : openaiOptions.logprobs) === true ? 0 : (openaiOptions == null ? void 0 : openaiOptions.logprobs) === false ? void 0 : openaiOptions == null ? void 0 : openaiOptions.logprobs,
1931
+ logprobs: openaiOptions?.logprobs === true ? 0 : openaiOptions?.logprobs === false ? void 0 : openaiOptions?.logprobs,
1945
1932
  suffix: openaiOptions.suffix,
1946
1933
  user: openaiOptions.user,
1947
1934
  // standardized settings:
@@ -1960,7 +1947,6 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
1960
1947
  };
1961
1948
  }
1962
1949
  async doGenerate(options) {
1963
- var _a2, _b, _c;
1964
1950
  const { args, warnings } = await this.getArgs(options);
1965
1951
  const {
1966
1952
  responseHeaders,
@@ -1971,7 +1957,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
1971
1957
  path: "/completions",
1972
1958
  modelId: this.modelId
1973
1959
  }),
1974
- headers: combineHeaders2((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
1960
+ headers: combineHeaders2(this.config.headers?.(), options.headers),
1975
1961
  body: args,
1976
1962
  failedResponseHandler: openaiFailedResponseHandler,
1977
1963
  successfulResponseHandler: createJsonResponseHandler2(
@@ -1990,7 +1976,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
1990
1976
  usage: convertOpenAICompletionUsage(response.usage),
1991
1977
  finishReason: {
1992
1978
  unified: mapOpenAIFinishReason2(choice.finish_reason),
1993
- raw: (_c = choice.finish_reason) != null ? _c : void 0
1979
+ raw: choice.finish_reason ?? void 0
1994
1980
  },
1995
1981
  request: { body: args },
1996
1982
  response: {
@@ -2003,7 +1989,6 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
2003
1989
  };
2004
1990
  }
2005
1991
  async doStream(options) {
2006
- var _a2, _b;
2007
1992
  const { args, warnings } = await this.getArgs(options);
2008
1993
  const body = {
2009
1994
  ...args,
@@ -2018,7 +2003,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
2018
2003
  });
2019
2004
  const { responseHeaders, value: response } = await postJsonToApi2({
2020
2005
  url,
2021
- headers: combineHeaders2((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
2006
+ headers: combineHeaders2(this.config.headers?.(), options.headers),
2022
2007
  body,
2023
2008
  failedResponseHandler: openaiFailedResponseHandler,
2024
2009
  successfulResponseHandler: createEventSourceResponseHandler2(
@@ -2049,7 +2034,6 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
2049
2034
  controller.enqueue({ type: "stream-start", warnings });
2050
2035
  },
2051
2036
  transform(chunk, controller) {
2052
- var _a3;
2053
2037
  if (options.includeRawChunks) {
2054
2038
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2055
2039
  }
@@ -2063,7 +2047,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
2063
2047
  finishReason = { unified: "error", raw: void 0 };
2064
2048
  controller.enqueue({
2065
2049
  type: "error",
2066
- error: (_a3 = createOpenAIProviderStreamError(value.error)) != null ? _a3 : value.error
2050
+ error: createOpenAIProviderStreamError(value.error) ?? value.error
2067
2051
  });
2068
2052
  return;
2069
2053
  }
@@ -2079,16 +2063,16 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
2079
2063
  usage = value.usage;
2080
2064
  }
2081
2065
  const choice = value.choices[0];
2082
- if ((choice == null ? void 0 : choice.finish_reason) != null) {
2066
+ if (choice?.finish_reason != null) {
2083
2067
  finishReason = {
2084
2068
  unified: mapOpenAIFinishReason2(choice.finish_reason),
2085
2069
  raw: choice.finish_reason
2086
2070
  };
2087
2071
  }
2088
- if ((choice == null ? void 0 : choice.logprobs) != null) {
2072
+ if (choice?.logprobs != null) {
2089
2073
  providerMetadata.openai.logprobs = choice.logprobs;
2090
2074
  }
2091
- if ((choice == null ? void 0 : choice.text) != null && choice.text.length > 0) {
2075
+ if (choice?.text != null && choice.text.length > 0) {
2092
2076
  controller.enqueue({
2093
2077
  type: "text-delta",
2094
2078
  id: "0",
@@ -2198,7 +2182,6 @@ var OpenAIEmbeddingModel = class _OpenAIEmbeddingModel {
2198
2182
  abortSignal,
2199
2183
  providerOptions
2200
2184
  }) {
2201
- var _a2, _b, _c;
2202
2185
  if (values.length > this.maxEmbeddingsPerCall) {
2203
2186
  throw new TooManyEmbeddingValuesForCallError({
2204
2187
  provider: this.provider,
@@ -2207,11 +2190,11 @@ var OpenAIEmbeddingModel = class _OpenAIEmbeddingModel {
2207
2190
  values
2208
2191
  });
2209
2192
  }
2210
- const openaiOptions = (_a2 = await parseProviderOptions3({
2193
+ const openaiOptions = await parseProviderOptions3({
2211
2194
  provider: "openai",
2212
2195
  providerOptions,
2213
2196
  schema: openaiEmbeddingModelOptions
2214
- })) != null ? _a2 : {};
2197
+ }) ?? {};
2215
2198
  const {
2216
2199
  responseHeaders,
2217
2200
  value: response,
@@ -2221,7 +2204,7 @@ var OpenAIEmbeddingModel = class _OpenAIEmbeddingModel {
2221
2204
  path: "/embeddings",
2222
2205
  modelId: this.modelId
2223
2206
  }),
2224
- headers: combineHeaders3((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), headers),
2207
+ headers: combineHeaders3(this.config.headers?.(), headers),
2225
2208
  body: {
2226
2209
  model: this.modelId,
2227
2210
  input: values,
@@ -2342,7 +2325,6 @@ var OpenAIFiles = class {
2342
2325
  headers,
2343
2326
  providerOptions
2344
2327
  }) {
2345
- var _a2, _b, _c;
2346
2328
  let openaiOptions;
2347
2329
  try {
2348
2330
  openaiOptions = await parseProviderOptions4({
@@ -2357,7 +2339,7 @@ var OpenAIFiles = class {
2357
2339
  }
2358
2340
  throw error;
2359
2341
  }
2360
- const purpose = (_a2 = openaiOptions == null ? void 0 : openaiOptions.purpose) != null ? _a2 : "assistants";
2342
+ const purpose = openaiOptions?.purpose ?? "assistants";
2361
2343
  const requestHeaders = this.getHeaders(headers);
2362
2344
  const url = `${this.config.baseURL}/files`;
2363
2345
  let response;
@@ -2365,7 +2347,7 @@ var OpenAIFiles = class {
2365
2347
  const parts = [
2366
2348
  { type: "field", name: "purpose", value: purpose }
2367
2349
  ];
2368
- if ((openaiOptions == null ? void 0 : openaiOptions.expiresAfter) != null) {
2350
+ if (openaiOptions?.expiresAfter != null) {
2369
2351
  parts.push(
2370
2352
  { type: "field", name: "expires_after[anchor]", value: "created_at" },
2371
2353
  {
@@ -2405,7 +2387,7 @@ var OpenAIFiles = class {
2405
2387
  formData.append("file", blob);
2406
2388
  }
2407
2389
  formData.append("purpose", purpose);
2408
- if ((openaiOptions == null ? void 0 : openaiOptions.expiresAfter) != null) {
2390
+ if (openaiOptions?.expiresAfter != null) {
2409
2391
  formData.append("expires_after[anchor]", "created_at");
2410
2392
  formData.append(
2411
2393
  "expires_after[seconds]",
@@ -2427,7 +2409,7 @@ var OpenAIFiles = class {
2427
2409
  return {
2428
2410
  warnings: [],
2429
2411
  providerReference: { openai: response.id },
2430
- ...((_b = response.filename) != null ? _b : filename) ? { filename: (_c = response.filename) != null ? _c : filename } : {},
2412
+ ...response.filename ?? filename ? { filename: response.filename ?? filename } : {},
2431
2413
  ...mediaType != null ? { mediaType } : {},
2432
2414
  ...response.bytes != null ? { byteSize: response.bytes } : {},
2433
2415
  ...response.created_at != null ? { createdAt: new Date(response.created_at * 1e3) } : {},
@@ -2471,7 +2453,6 @@ var OpenAIFiles = class {
2471
2453
  abortSignal,
2472
2454
  headers
2473
2455
  }) {
2474
- var _a2;
2475
2456
  const fileId = this.getFileId(file);
2476
2457
  const { value: content, responseHeaders } = await getFromApi({
2477
2458
  url: `${this.config.baseURL}/files/${encodePathSegment(fileId)}/content`,
@@ -2482,7 +2463,7 @@ var OpenAIFiles = class {
2482
2463
  fetch: this.config.fetch,
2483
2464
  validateUrl: false
2484
2465
  });
2485
- const mediaType = (_a2 = responseHeaders == null ? void 0 : responseHeaders["content-type"]) == null ? void 0 : _a2.split(";")[0].trim();
2466
+ const mediaType = responseHeaders?.["content-type"]?.split(";")[0].trim();
2486
2467
  return {
2487
2468
  warnings: [],
2488
2469
  content,
@@ -2594,8 +2575,7 @@ function hasDefaultResponseFormat(modelId) {
2594
2575
  );
2595
2576
  }
2596
2577
  function getMaxImagesPerCall(modelId) {
2597
- var _a2;
2598
- return (_a2 = modelMaxImagesPerCall[modelId]) != null ? _a2 : modelId.startsWith("gpt-image-") ? 10 : 1;
2578
+ return modelMaxImagesPerCall[modelId] ?? (modelId.startsWith("gpt-image-") ? 10 : 1);
2599
2579
  }
2600
2580
  var baseImageModelOptionsObject = z11.object({
2601
2581
  /**
@@ -2692,7 +2672,6 @@ var OpenAIImageModel = class _OpenAIImageModel {
2692
2672
  headers,
2693
2673
  abortSignal
2694
2674
  }) {
2695
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
2696
2675
  const warnings = [];
2697
2676
  if (aspectRatio != null) {
2698
2677
  warnings.push({
@@ -2704,19 +2683,19 @@ var OpenAIImageModel = class _OpenAIImageModel {
2704
2683
  if (seed != null) {
2705
2684
  warnings.push({ type: "unsupported", feature: "seed" });
2706
2685
  }
2707
- const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
2686
+ const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
2708
2687
  if (files != null) {
2709
- const openaiOptions2 = (_d = await parseProviderOptions5({
2688
+ const openaiOptions2 = await parseProviderOptions5({
2710
2689
  provider: "openai",
2711
2690
  providerOptions,
2712
2691
  schema: openaiImageModelEditOptions
2713
- })) != null ? _d : {};
2692
+ }) ?? {};
2714
2693
  const { value: response2, responseHeaders: responseHeaders2 } = await postFormDataToApi2({
2715
2694
  url: this.config.url({
2716
2695
  path: "/images/edits",
2717
2696
  modelId: this.modelId
2718
2697
  }),
2719
- headers: combineHeaders5((_f = (_e = this.config).headers) == null ? void 0 : _f.call(_e), headers),
2698
+ headers: combineHeaders5(this.config.headers?.(), headers),
2720
2699
  formData: convertToFormData({
2721
2700
  model: this.modelId,
2722
2701
  prompt,
@@ -2755,9 +2734,9 @@ var OpenAIImageModel = class _OpenAIImageModel {
2755
2734
  images: response2.data.map((item) => item.b64_json),
2756
2735
  warnings,
2757
2736
  usage: response2.usage != null ? {
2758
- inputTokens: (_g = response2.usage.input_tokens) != null ? _g : void 0,
2759
- outputTokens: (_h = response2.usage.output_tokens) != null ? _h : void 0,
2760
- totalTokens: (_i = response2.usage.total_tokens) != null ? _i : void 0
2737
+ inputTokens: response2.usage.input_tokens ?? void 0,
2738
+ outputTokens: response2.usage.output_tokens ?? void 0,
2739
+ totalTokens: response2.usage.total_tokens ?? void 0
2761
2740
  } : void 0,
2762
2741
  response: {
2763
2742
  timestamp: currentDate,
@@ -2766,37 +2745,34 @@ var OpenAIImageModel = class _OpenAIImageModel {
2766
2745
  },
2767
2746
  providerMetadata: {
2768
2747
  openai: {
2769
- images: response2.data.map((item, index) => {
2770
- var _a3, _b2, _c2, _d2, _e2, _f2;
2771
- return {
2772
- ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
2773
- created: (_a3 = response2.created) != null ? _a3 : void 0,
2774
- size: (_b2 = response2.size) != null ? _b2 : void 0,
2775
- quality: (_c2 = response2.quality) != null ? _c2 : void 0,
2776
- background: (_d2 = response2.background) != null ? _d2 : void 0,
2777
- outputFormat: (_e2 = response2.output_format) != null ? _e2 : void 0,
2778
- ...distributeTokenDetails(
2779
- (_f2 = response2.usage) == null ? void 0 : _f2.input_tokens_details,
2780
- index,
2781
- response2.data.length
2782
- )
2783
- };
2784
- })
2748
+ images: response2.data.map((item, index) => ({
2749
+ ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
2750
+ created: response2.created ?? void 0,
2751
+ size: response2.size ?? void 0,
2752
+ quality: response2.quality ?? void 0,
2753
+ background: response2.background ?? void 0,
2754
+ outputFormat: response2.output_format ?? void 0,
2755
+ ...distributeTokenDetails(
2756
+ response2.usage?.input_tokens_details,
2757
+ index,
2758
+ response2.data.length
2759
+ )
2760
+ }))
2785
2761
  }
2786
2762
  }
2787
2763
  };
2788
2764
  }
2789
- const openaiOptions = (_j = await parseProviderOptions5({
2765
+ const openaiOptions = await parseProviderOptions5({
2790
2766
  provider: "openai",
2791
2767
  providerOptions,
2792
2768
  schema: openaiImageModelGenerationOptions
2793
- })) != null ? _j : {};
2769
+ }) ?? {};
2794
2770
  const { value: response, responseHeaders } = await postJsonToApi4({
2795
2771
  url: this.config.url({
2796
2772
  path: "/images/generations",
2797
2773
  modelId: this.modelId
2798
2774
  }),
2799
- headers: combineHeaders5((_l = (_k = this.config).headers) == null ? void 0 : _l.call(_k), headers),
2775
+ headers: combineHeaders5(this.config.headers?.(), headers),
2800
2776
  body: {
2801
2777
  model: this.modelId,
2802
2778
  prompt,
@@ -2822,9 +2798,9 @@ var OpenAIImageModel = class _OpenAIImageModel {
2822
2798
  images: response.data.map((item) => item.b64_json),
2823
2799
  warnings,
2824
2800
  usage: response.usage != null ? {
2825
- inputTokens: (_m = response.usage.input_tokens) != null ? _m : void 0,
2826
- outputTokens: (_n = response.usage.output_tokens) != null ? _n : void 0,
2827
- totalTokens: (_o = response.usage.total_tokens) != null ? _o : void 0
2801
+ inputTokens: response.usage.input_tokens ?? void 0,
2802
+ outputTokens: response.usage.output_tokens ?? void 0,
2803
+ totalTokens: response.usage.total_tokens ?? void 0
2828
2804
  } : void 0,
2829
2805
  response: {
2830
2806
  timestamp: currentDate,
@@ -2833,22 +2809,19 @@ var OpenAIImageModel = class _OpenAIImageModel {
2833
2809
  },
2834
2810
  providerMetadata: {
2835
2811
  openai: {
2836
- images: response.data.map((item, index) => {
2837
- var _a3, _b2, _c2, _d2, _e2, _f2;
2838
- return {
2839
- ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
2840
- created: (_a3 = response.created) != null ? _a3 : void 0,
2841
- size: (_b2 = response.size) != null ? _b2 : void 0,
2842
- quality: (_c2 = response.quality) != null ? _c2 : void 0,
2843
- background: (_d2 = response.background) != null ? _d2 : void 0,
2844
- outputFormat: (_e2 = response.output_format) != null ? _e2 : void 0,
2845
- ...distributeTokenDetails(
2846
- (_f2 = response.usage) == null ? void 0 : _f2.input_tokens_details,
2847
- index,
2848
- response.data.length
2849
- )
2850
- };
2851
- })
2812
+ images: response.data.map((item, index) => ({
2813
+ ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
2814
+ created: response.created ?? void 0,
2815
+ size: response.size ?? void 0,
2816
+ quality: response.quality ?? void 0,
2817
+ background: response.background ?? void 0,
2818
+ outputFormat: response.output_format ?? void 0,
2819
+ ...distributeTokenDetails(
2820
+ response.usage?.input_tokens_details,
2821
+ index,
2822
+ response.data.length
2823
+ )
2824
+ }))
2852
2825
  }
2853
2826
  }
2854
2827
  };
@@ -3581,15 +3554,14 @@ var programmaticToolCallingFactory = createProviderExecutedToolFactory7({
3581
3554
  var programmaticToolCalling = () => experimental_toolCaller(programmaticToolCallingFactory({}), {
3582
3555
  type: "provider",
3583
3556
  prepareProviderOptions: (providerOptions) => {
3584
- var _a2;
3585
- const openaiOptions = providerOptions == null ? void 0 : providerOptions.openai;
3557
+ const openaiOptions = providerOptions?.openai;
3586
3558
  return {
3587
3559
  ...providerOptions,
3588
3560
  openai: {
3589
3561
  ...openaiOptions,
3590
3562
  allowedCallers: [
3591
3563
  .../* @__PURE__ */ new Set([
3592
- ...(_a2 = openaiOptions == null ? void 0 : openaiOptions.allowedCallers) != null ? _a2 : [],
3564
+ ...openaiOptions?.allowedCallers ?? [],
3593
3565
  "programmatic"
3594
3566
  ])
3595
3567
  ]
@@ -3755,19 +3727,18 @@ import { z as z28 } from "zod/v4";
3755
3727
  // src/responses/convert-openai-responses-usage.ts
3756
3728
  import { createNullLanguageModelUsage as createNullLanguageModelUsage3 } from "@ai-sdk/provider-utils";
3757
3729
  function convertOpenAIResponsesUsage(usage) {
3758
- var _a2, _b, _c, _d, _e, _f;
3759
3730
  if (usage == null) {
3760
3731
  return createNullLanguageModelUsage3();
3761
3732
  }
3762
3733
  const inputTokens = usage.input_tokens;
3763
3734
  const outputTokens = usage.output_tokens;
3764
- const cachedTokens = (_b = (_a2 = usage.input_tokens_details) == null ? void 0 : _a2.cached_tokens) != null ? _b : 0;
3765
- const cacheWriteTokens = (_d = (_c = usage.input_tokens_details) == null ? void 0 : _c.cache_write_tokens) != null ? _d : void 0;
3766
- const reasoningTokens = (_f = (_e = usage.output_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : 0;
3735
+ const cachedTokens = usage.input_tokens_details?.cached_tokens ?? 0;
3736
+ const cacheWriteTokens = usage.input_tokens_details?.cache_write_tokens ?? void 0;
3737
+ const reasoningTokens = usage.output_tokens_details?.reasoning_tokens ?? 0;
3767
3738
  return {
3768
3739
  inputTokens: {
3769
3740
  total: inputTokens,
3770
- noCache: inputTokens - cachedTokens - (cacheWriteTokens != null ? cacheWriteTokens : 0),
3741
+ noCache: inputTokens - cachedTokens - (cacheWriteTokens ?? 0),
3771
3742
  cacheRead: cachedTokens,
3772
3743
  cacheWrite: cacheWriteTokens
3773
3744
  },
@@ -5099,8 +5070,9 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema25(
5099
5070
  *
5100
5071
  * Only supported by GPT-6 and later models in standard, single-agent mode. Cannot be
5101
5072
  * combined with automatic compaction or automatic truncation.
5073
+ * Supported efforts vary by model; 'none' is supported by GPT-6 Sol and Luna.
5102
5074
  */
5103
- reasoningEffortUpdate: z26.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
5075
+ reasoningEffortUpdate: z26.enum(["none", "low", "medium", "high", "xhigh", "max"]).optional(),
5104
5076
  /**
5105
5077
  * Controls how much model work GPT-5.6 performs before returning a final answer.
5106
5078
  * `standard` is the default. `pro` increases quality, latency, and token usage.
@@ -5228,7 +5200,7 @@ var openaiResponsesSystemMessageOptionsSchema = lazySchema25(
5228
5200
  *
5229
5201
  * @see https://developers.openai.com/api/docs/guides/reasoning#change-reasoning-mid-conversation
5230
5202
  */
5231
- reasoningEffortUpdate: z26.enum(["low", "medium", "high", "xhigh", "max"]).optional()
5203
+ reasoningEffortUpdate: z26.enum(["none", "low", "medium", "high", "xhigh", "max"]).optional()
5232
5204
  })
5233
5205
  )
5234
5206
  );
@@ -5244,8 +5216,7 @@ function getParallelToolCallMetadata({
5244
5216
  providerOptions,
5245
5217
  providerOptionsName
5246
5218
  }) {
5247
- var _a2;
5248
- const metadata = (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.parallelToolCall;
5219
+ const metadata = providerOptions?.[providerOptionsName]?.parallelToolCall;
5249
5220
  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) {
5250
5221
  return void 0;
5251
5222
  }
@@ -5326,8 +5297,7 @@ async function convertFunctionToolResultOutput({
5326
5297
  providerOptionsName,
5327
5298
  warnings
5328
5299
  }) {
5329
- var _a2;
5330
- const hasOutputSchema = outputSchemaToolNames == null ? void 0 : outputSchemaToolNames.has(toolName);
5300
+ const hasOutputSchema = outputSchemaToolNames?.has(toolName);
5331
5301
  const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
5332
5302
  {
5333
5303
  type: "input_text",
@@ -5342,7 +5312,7 @@ async function convertFunctionToolResultOutput({
5342
5312
  hasOutputSchema ? JSON.stringify(output.value) : output.value
5343
5313
  );
5344
5314
  case "execution-denied": {
5345
- const reason = (_a2 = output.reason) != null ? _a2 : "Tool call execution denied.";
5315
+ const reason = output.reason ?? "Tool call execution denied.";
5346
5316
  return convertScalarOutput(
5347
5317
  hasOutputSchema ? JSON.stringify(reason) : reason
5348
5318
  );
@@ -5352,7 +5322,6 @@ async function convertFunctionToolResultOutput({
5352
5322
  return convertScalarOutput(JSON.stringify(output.value));
5353
5323
  case "content":
5354
5324
  return output.value.map((item) => {
5355
- var _a3, _b, _c;
5356
5325
  const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
5357
5326
  item.providerOptions,
5358
5327
  providerOptionsName
@@ -5369,7 +5338,7 @@ async function convertFunctionToolResultOutput({
5369
5338
  }
5370
5339
  case "file": {
5371
5340
  const topLevel = getTopLevelMediaType2(item.mediaType);
5372
- const imageDetail = (_b = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b.imageDetail;
5341
+ const imageDetail = item.providerOptions?.[providerOptionsName]?.imageDetail;
5373
5342
  if (item.data.type === "reference") {
5374
5343
  const fileId = resolveProviderReference2({
5375
5344
  reference: item.data.reference,
@@ -5407,7 +5376,7 @@ async function convertFunctionToolResultOutput({
5407
5376
  }
5408
5377
  return {
5409
5378
  type: "input_file",
5410
- filename: (_c = item.filename) != null ? _c : "data",
5379
+ filename: item.filename ?? "data",
5411
5380
  file_data: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
5412
5381
  ...promptCacheBreakpoint2 != null && {
5413
5382
  prompt_cache_breakpoint: promptCacheBreakpoint2
@@ -5508,16 +5477,14 @@ function collectCompleteParallelToolResultGroups({
5508
5477
  return completeGroups;
5509
5478
  }
5510
5479
  function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
5511
- var _a2;
5512
- return (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.promptCacheBreakpoint;
5480
+ return providerOptions?.[providerOptionsName]?.promptCacheBreakpoint;
5513
5481
  }
5514
5482
  function getScalarToolResultPromptCacheBreakpoint({
5515
5483
  output,
5516
5484
  toolResultProviderOptions,
5517
5485
  providerOptionsName
5518
5486
  }) {
5519
- var _a2;
5520
- return output.type === "content" ? void 0 : (_a2 = getPromptCacheBreakpoint2(output.providerOptions, providerOptionsName)) != null ? _a2 : getPromptCacheBreakpoint2(
5487
+ return output.type === "content" ? void 0 : getPromptCacheBreakpoint2(output.providerOptions, providerOptionsName) ?? getPromptCacheBreakpoint2(
5521
5488
  toolResultProviderOptions,
5522
5489
  providerOptionsName
5523
5490
  );
@@ -5546,7 +5513,6 @@ async function convertToOpenAIResponsesInput({
5546
5513
  outputSchemaToolNames,
5547
5514
  configurationUpdateUnsupportedReason
5548
5515
  }) {
5549
- 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;
5550
5516
  let input = [];
5551
5517
  const warnings = [];
5552
5518
  const processedApprovalIds = /* @__PURE__ */ new Set();
@@ -5572,7 +5538,7 @@ async function convertToOpenAIResponsesInput({
5572
5538
  schema: openaiResponsesSystemMessageOptionsSchema
5573
5539
  });
5574
5540
  }
5575
- const effort = options == null ? void 0 : options.reasoningEffortUpdate;
5541
+ const effort = options?.reasoningEffortUpdate;
5576
5542
  if (effort != null) {
5577
5543
  const unsupportedReason = content !== "" ? "Message-level reasoningEffortUpdate requires empty system message content." : configurationUpdateUnsupportedReason;
5578
5544
  if (unsupportedReason != null) {
@@ -5645,7 +5611,6 @@ async function convertToOpenAIResponsesInput({
5645
5611
  ...explicitMessageItemType && { type: "message" },
5646
5612
  role: "user",
5647
5613
  content: content.map((part, index) => {
5648
- var _a3, _b2, _c2, _d2, _e2;
5649
5614
  switch (part.type) {
5650
5615
  case "text": {
5651
5616
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(
@@ -5675,7 +5640,7 @@ async function convertToOpenAIResponsesInput({
5675
5640
  return {
5676
5641
  type: "input_image",
5677
5642
  file_id: fileId,
5678
- detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
5643
+ detail: part.providerOptions?.[providerOptionsName]?.imageDetail,
5679
5644
  ...promptCacheBreakpoint != null && {
5680
5645
  prompt_cache_breakpoint: promptCacheBreakpoint
5681
5646
  }
@@ -5703,7 +5668,7 @@ async function convertToOpenAIResponsesInput({
5703
5668
  ...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 } : {
5704
5669
  image_url: `data:${resolveFullMediaType2({ part })};base64,${convertToBase642(part.data.data)}`
5705
5670
  },
5706
- detail: (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail,
5671
+ detail: part.providerOptions?.[providerOptionsName]?.imageDetail,
5707
5672
  ...promptCacheBreakpoint != null && {
5708
5673
  prompt_cache_breakpoint: promptCacheBreakpoint
5709
5674
  }
@@ -5727,7 +5692,7 @@ async function convertToOpenAIResponsesInput({
5727
5692
  return {
5728
5693
  type: "input_file",
5729
5694
  ...typeof part.data.data === "string" && isFileId(part.data.data, fileIdPrefixes) ? { file_id: part.data.data } : {
5730
- filename: (_e2 = part.filename) != null ? _e2 : fullMediaType === "application/pdf" ? `part-${index}.pdf` : `part-${index}`,
5695
+ filename: part.filename ?? (fullMediaType === "application/pdf" ? `part-${index}.pdf` : `part-${index}`),
5731
5696
  file_data: `data:${fullMediaType};base64,${convertToBase642(part.data.data)}`
5732
5697
  },
5733
5698
  ...promptCacheBreakpoint != null && {
@@ -5748,9 +5713,9 @@ async function convertToOpenAIResponsesInput({
5748
5713
  for (const part of content) {
5749
5714
  switch (part.type) {
5750
5715
  case "text": {
5751
- const providerOptions2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName];
5752
- const id = providerOptions2 == null ? void 0 : providerOptions2.itemId;
5753
- const phase = providerOptions2 == null ? void 0 : providerOptions2.phase;
5716
+ const providerOptions2 = part.providerOptions?.[providerOptionsName];
5717
+ const id = providerOptions2?.itemId;
5718
+ const phase = providerOptions2?.phase;
5754
5719
  if (hasConversation && id != null) {
5755
5720
  break;
5756
5721
  }
@@ -5795,11 +5760,11 @@ async function convertToOpenAIResponsesInput({
5795
5760
  }
5796
5761
  break;
5797
5762
  }
5798
- 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;
5799
- 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;
5800
- 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;
5801
- const caller = (_r = (_q = part.providerOptions) == null ? void 0 : _q[providerOptionsName]) == null ? void 0 : _r.caller;
5802
- if ((caller == null ? void 0 : caller.type) === "program") {
5763
+ const id = part.providerOptions?.[providerOptionsName]?.itemId ?? part.providerMetadata?.[providerOptionsName]?.itemId;
5764
+ const namespace = part.providerOptions?.[providerOptionsName]?.namespace ?? part.providerMetadata?.[providerOptionsName]?.namespace;
5765
+ const isAsync = part.providerOptions?.[providerOptionsName]?.async ?? part.providerMetadata?.[providerOptionsName]?.async;
5766
+ const caller = part.providerOptions?.[providerOptionsName]?.caller;
5767
+ if (caller?.type === "program") {
5803
5768
  programmaticToolCallIds.add(part.toolCallId);
5804
5769
  }
5805
5770
  if (hasConversation && id != null) {
@@ -5823,9 +5788,9 @@ async function convertToOpenAIResponsesInput({
5823
5788
  const execution = parsedInput.call_id != null ? "client" : "server";
5824
5789
  input.push({
5825
5790
  type: "tool_search_call",
5826
- id: id != null ? id : part.toolCallId,
5791
+ id: id ?? part.toolCallId,
5827
5792
  execution,
5828
- call_id: (_s = parsedInput.call_id) != null ? _s : null,
5793
+ call_id: parsedInput.call_id ?? null,
5829
5794
  status: "completed",
5830
5795
  arguments: parsedInput.arguments
5831
5796
  });
@@ -5842,7 +5807,7 @@ async function convertToOpenAIResponsesInput({
5842
5807
  });
5843
5808
  input.push({
5844
5809
  type: "program",
5845
- id: id != null ? id : part.toolCallId,
5810
+ id: id ?? part.toolCallId,
5846
5811
  call_id: part.toolCallId,
5847
5812
  code: parsedInput.code,
5848
5813
  fingerprint: parsedInput.fingerprint
@@ -5857,7 +5822,7 @@ async function convertToOpenAIResponsesInput({
5857
5822
  break;
5858
5823
  }
5859
5824
  }
5860
- 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);
5825
+ const isProviderDefinedToolCall = hasLocalShellTool && resolvedToolName === "local_shell" || hasShellTool && resolvedToolName === "shell" || hasApplyPatchTool && resolvedToolName === "apply_patch" || hasComputerTool && resolvedToolName === "computer" || (customProviderToolNames?.has(resolvedToolName) ?? false);
5861
5826
  if (hasPreviousResponseId && store && id != null && isProviderDefinedToolCall) {
5862
5827
  break;
5863
5828
  }
@@ -5964,7 +5929,7 @@ async function convertToOpenAIResponsesInput({
5964
5929
  });
5965
5930
  break;
5966
5931
  }
5967
- if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
5932
+ if (customProviderToolNames?.has(resolvedToolName)) {
5968
5933
  input.push({
5969
5934
  type: "custom_tool_call",
5970
5935
  call_id: part.toolCallId,
@@ -6000,7 +5965,7 @@ async function convertToOpenAIResponsesInput({
6000
5965
  part.toolName
6001
5966
  );
6002
5967
  if (part.toolName === toolSearchToolName) {
6003
- 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;
5968
+ const itemId = part.providerOptions?.[providerOptionsName]?.itemId ?? part.providerMetadata?.[providerOptionsName]?.itemId ?? part.toolCallId;
6004
5969
  if (store) {
6005
5970
  input.push({ type: "item_reference", id: itemId });
6006
5971
  } else if (part.output.type === "json") {
@@ -6020,7 +5985,7 @@ async function convertToOpenAIResponsesInput({
6020
5985
  break;
6021
5986
  }
6022
5987
  if (resolvedResultToolName === "programmatic_tool_calling") {
6023
- 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;
5988
+ const itemId = part.providerOptions?.[providerOptionsName]?.itemId ?? part.providerMetadata?.[providerOptionsName]?.itemId ?? part.toolCallId;
6024
5989
  if (store) {
6025
5990
  input.push({ type: "item_reference", id: itemId });
6026
5991
  } else if (part.output.type === "json") {
@@ -6060,7 +6025,7 @@ async function convertToOpenAIResponsesInput({
6060
6025
  break;
6061
6026
  }
6062
6027
  if (store) {
6063
- const itemId = (_I = (_H = (_G = part.providerOptions) == null ? void 0 : _G[providerOptionsName]) == null ? void 0 : _H.itemId) != null ? _I : part.toolCallId;
6028
+ const itemId = part.providerOptions?.[providerOptionsName]?.itemId ?? part.toolCallId;
6064
6029
  input.push({ type: "item_reference", id: itemId });
6065
6030
  } else {
6066
6031
  warnings.push({
@@ -6076,7 +6041,7 @@ async function convertToOpenAIResponsesInput({
6076
6041
  providerOptions: part.providerOptions,
6077
6042
  schema: openaiResponsesReasoningProviderOptionsSchema
6078
6043
  });
6079
- const reasoningId = providerOptions2 == null ? void 0 : providerOptions2.itemId;
6044
+ const reasoningId = providerOptions2?.itemId;
6080
6045
  if ((hasConversation || hasPreviousResponseId) && reasoningId != null) {
6081
6046
  break;
6082
6047
  }
@@ -6108,19 +6073,19 @@ async function convertToOpenAIResponsesInput({
6108
6073
  reasoningMessages[reasoningId] = {
6109
6074
  type: "reasoning",
6110
6075
  id: reasoningId,
6111
- encrypted_content: providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent,
6076
+ encrypted_content: providerOptions2?.reasoningEncryptedContent,
6112
6077
  summary: summaryParts
6113
6078
  };
6114
6079
  input.push(reasoningMessages[reasoningId]);
6115
6080
  } else {
6116
6081
  reasoningMessage.summary.push(...summaryParts);
6117
- if ((providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent) != null) {
6082
+ if (providerOptions2?.reasoningEncryptedContent != null) {
6118
6083
  reasoningMessage.encrypted_content = providerOptions2.reasoningEncryptedContent;
6119
6084
  }
6120
6085
  }
6121
6086
  }
6122
6087
  } else {
6123
- const encryptedContent = providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent;
6088
+ const encryptedContent = providerOptions2?.reasoningEncryptedContent;
6124
6089
  if (encryptedContent != null) {
6125
6090
  const summaryParts = [];
6126
6091
  if (part.text.length > 0) {
@@ -6145,8 +6110,8 @@ async function convertToOpenAIResponsesInput({
6145
6110
  }
6146
6111
  case "custom": {
6147
6112
  if (part.kind === "openai.compaction") {
6148
- const providerOptions2 = (_J = part.providerOptions) == null ? void 0 : _J[providerOptionsName];
6149
- const id = providerOptions2 == null ? void 0 : providerOptions2.itemId;
6113
+ const providerOptions2 = part.providerOptions?.[providerOptionsName];
6114
+ const id = providerOptions2?.itemId;
6150
6115
  if (hasConversation && id != null) {
6151
6116
  break;
6152
6117
  }
@@ -6154,7 +6119,7 @@ async function convertToOpenAIResponsesInput({
6154
6119
  input.push({ type: "item_reference", id });
6155
6120
  break;
6156
6121
  }
6157
- const encryptedContent = providerOptions2 == null ? void 0 : providerOptions2.encryptedContent;
6122
+ const encryptedContent = providerOptions2?.encryptedContent;
6158
6123
  if (id != null) {
6159
6124
  input.push({
6160
6125
  type: "compaction",
@@ -6251,7 +6216,7 @@ ${text}`,
6251
6216
  }
6252
6217
  const output = part.output;
6253
6218
  if (output.type === "execution-denied") {
6254
- const approvalId = (_L = (_K = output.providerOptions) == null ? void 0 : _K.openai) == null ? void 0 : _L.approvalId;
6219
+ const approvalId = output.providerOptions?.openai?.approvalId;
6255
6220
  if (approvalId) {
6256
6221
  continue;
6257
6222
  }
@@ -6331,7 +6296,7 @@ ${text}`,
6331
6296
  file_id: parsedOutput.output.fileId,
6332
6297
  detail: parsedOutput.output.detail
6333
6298
  },
6334
- acknowledged_safety_checks: (_M = parsedOutput.acknowledgedSafetyChecks) == null ? void 0 : _M.map((safetyCheck) => ({
6299
+ acknowledged_safety_checks: parsedOutput.acknowledgedSafetyChecks?.map((safetyCheck) => ({
6335
6300
  id: safetyCheck.id,
6336
6301
  code: safetyCheck.code,
6337
6302
  message: safetyCheck.message
@@ -6339,7 +6304,7 @@ ${text}`,
6339
6304
  });
6340
6305
  continue;
6341
6306
  }
6342
- if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
6307
+ if (customProviderToolNames?.has(resolvedToolName)) {
6343
6308
  const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
6344
6309
  output,
6345
6310
  toolResultProviderOptions: part.providerOptions,
@@ -6360,7 +6325,7 @@ ${text}`,
6360
6325
  break;
6361
6326
  case "execution-denied":
6362
6327
  outputValue = convertScalarOutput(
6363
- (_N = output.reason) != null ? _N : "Tool call execution denied."
6328
+ output.reason ?? "Tool call execution denied."
6364
6329
  );
6365
6330
  break;
6366
6331
  case "json":
@@ -6369,7 +6334,6 @@ ${text}`,
6369
6334
  break;
6370
6335
  case "content":
6371
6336
  outputValue = output.value.map((item) => {
6372
- var _a3, _b2, _c2;
6373
6337
  const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
6374
6338
  item.providerOptions,
6375
6339
  providerOptionsName
@@ -6385,7 +6349,7 @@ ${text}`,
6385
6349
  };
6386
6350
  case "file": {
6387
6351
  const topLevel = getTopLevelMediaType2(item.mediaType);
6388
- const imageDetail = (_b2 = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail;
6352
+ const imageDetail = item.providerOptions?.[providerOptionsName]?.imageDetail;
6389
6353
  if (item.data.type === "data") {
6390
6354
  const fullMediaType = resolveFullMediaType2({
6391
6355
  part: item
@@ -6402,7 +6366,7 @@ ${text}`,
6402
6366
  }
6403
6367
  return {
6404
6368
  type: "input_file",
6405
- filename: (_c2 = item.filename) != null ? _c2 : "data",
6369
+ filename: item.filename ?? "data",
6406
6370
  file_data: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
6407
6371
  ...promptCacheBreakpoint2 != null && {
6408
6372
  prompt_cache_breakpoint: promptCacheBreakpoint2
@@ -6453,8 +6417,8 @@ ${text}`,
6453
6417
  });
6454
6418
  continue;
6455
6419
  }
6456
- const resultCaller = (_P = (_O = part.providerOptions) == null ? void 0 : _O[providerOptionsName]) == null ? void 0 : _P.caller;
6457
- if (output.type === "execution-denied" && ((resultCaller == null ? void 0 : resultCaller.type) === "program" || programmaticToolCallIds.has(part.toolCallId))) {
6420
+ const resultCaller = part.providerOptions?.[providerOptionsName]?.caller;
6421
+ if (output.type === "execution-denied" && (resultCaller?.type === "program" || programmaticToolCallIds.has(part.toolCallId))) {
6458
6422
  throw new UnsupportedFunctionalityError5({
6459
6423
  functionality: "execution-denied results for programmatic tool calls"
6460
6424
  });
@@ -6522,15 +6486,14 @@ async function prepareResponsesTools({
6522
6486
  outputSchemaToolNames,
6523
6487
  supportsAsyncToolCalling = true
6524
6488
  }) {
6525
- var _a2, _b, _c, _d;
6526
- tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
6489
+ tools = tools?.length ? tools : void 0;
6527
6490
  const toolWarnings = [];
6528
6491
  if (tools == null) {
6529
6492
  return { tools: void 0, toolChoice: void 0, toolWarnings };
6530
6493
  }
6531
6494
  const openaiTools2 = [];
6532
6495
  const namespaceTools = /* @__PURE__ */ new Map();
6533
- const resolvedCustomProviderToolNames = customProviderToolNames != null ? customProviderToolNames : /* @__PURE__ */ new Set();
6496
+ const resolvedCustomProviderToolNames = customProviderToolNames ?? /* @__PURE__ */ new Set();
6534
6497
  const allowedToolResolutions = /* @__PURE__ */ new Map();
6535
6498
  const allowedToolAliases = /* @__PURE__ */ new Map();
6536
6499
  const recordAllowedTool = (toolName, resolution, canonicalName) => {
@@ -6548,22 +6511,22 @@ async function prepareResponsesTools({
6548
6511
  for (const tool of tools) {
6549
6512
  switch (tool.type) {
6550
6513
  case "function": {
6551
- const openaiOptions = (_a2 = tool.providerOptions) == null ? void 0 : _a2.openai;
6552
- if ((openaiOptions == null ? void 0 : openaiOptions.outputSchema) != null) {
6553
- outputSchemaToolNames == null ? void 0 : outputSchemaToolNames.add(tool.name);
6514
+ const openaiOptions = tool.providerOptions?.openai;
6515
+ if (openaiOptions?.outputSchema != null) {
6516
+ outputSchemaToolNames?.add(tool.name);
6554
6517
  }
6555
6518
  const openaiFunctionTool = prepareFunctionTool({
6556
6519
  tool,
6557
6520
  options: openaiOptions,
6558
6521
  toolWarnings,
6559
6522
  async: resolveAsyncToolOption({
6560
- value: openaiOptions == null ? void 0 : openaiOptions.async,
6523
+ value: openaiOptions?.async,
6561
6524
  supportsAsyncToolCalling,
6562
6525
  toolName: tool.name,
6563
6526
  toolWarnings
6564
6527
  })
6565
6528
  });
6566
- const namespace = openaiOptions == null ? void 0 : openaiOptions.namespace;
6529
+ const namespace = openaiOptions?.namespace;
6567
6530
  if (namespace == null) {
6568
6531
  openaiTools2.push(openaiFunctionTool);
6569
6532
  } else {
@@ -6589,7 +6552,7 @@ async function prepareResponsesTools({
6589
6552
  namespace != null ? {
6590
6553
  supported: false,
6591
6554
  reason: "tools inside an OpenAI tool namespace are not visible to tool_choice.allowed_tools"
6592
- } : (openaiOptions == null ? void 0 : openaiOptions.deferLoading) === true ? {
6555
+ } : openaiOptions?.deferLoading === true ? {
6593
6556
  supported: false,
6594
6557
  reason: "deferred tools are not visible to tool_choice.allowed_tools"
6595
6558
  } : {
@@ -6735,7 +6698,7 @@ async function prepareResponsesTools({
6735
6698
  authorization: args.authorization,
6736
6699
  connector_id: args.connectorId,
6737
6700
  headers: args.headers,
6738
- require_approval: requireApprovalParam != null ? requireApprovalParam : "never",
6701
+ require_approval: requireApprovalParam ?? "never",
6739
6702
  server_description: args.serverDescription,
6740
6703
  server_url: args.serverUrl
6741
6704
  });
@@ -6786,7 +6749,7 @@ async function prepareResponsesTools({
6786
6749
  recordAllowedTool(
6787
6750
  tool.name,
6788
6751
  toAllowedToolResolution(openaiTool),
6789
- toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(tool.name)
6752
+ toolNameMapping?.toProviderToolName(tool.name)
6790
6753
  );
6791
6754
  }
6792
6755
  break;
@@ -6804,7 +6767,7 @@ async function prepareResponsesTools({
6804
6767
  const droppedToolNames = [];
6805
6768
  for (const name of allowedTools.toolNames) {
6806
6769
  const directResolution = allowedToolResolutions.get(name);
6807
- const resolution = directResolution != null ? directResolution : allowedToolAliases.get(name);
6770
+ const resolution = directResolution ?? allowedToolAliases.get(name);
6808
6771
  if (directResolution != null && allowedToolAliases.has(name)) {
6809
6772
  toolWarnings.push({
6810
6773
  type: "unsupported",
@@ -6829,7 +6792,7 @@ async function prepareResponsesTools({
6829
6792
  });
6830
6793
  allowedToolEntries.push({
6831
6794
  type: "function",
6832
- name: (_b = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(name)) != null ? _b : name
6795
+ name: toolNameMapping?.toProviderToolName(name) ?? name
6833
6796
  });
6834
6797
  continue;
6835
6798
  }
@@ -6855,7 +6818,7 @@ async function prepareResponsesTools({
6855
6818
  tools: openaiTools2,
6856
6819
  toolChoice: {
6857
6820
  type: "allowed_tools",
6858
- mode: (_c = allowedTools.mode) != null ? _c : "auto",
6821
+ mode: allowedTools.mode ?? "auto",
6859
6822
  tools: allowedToolEntries
6860
6823
  },
6861
6824
  toolWarnings
@@ -6871,7 +6834,7 @@ async function prepareResponsesTools({
6871
6834
  case "required":
6872
6835
  return { tools: openaiTools2, toolChoice: type, toolWarnings };
6873
6836
  case "tool": {
6874
- const resolvedToolName = (_d = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(toolChoice.toolName)) != null ? _d : toolChoice.toolName;
6837
+ const resolvedToolName = toolNameMapping?.toProviderToolName(toolChoice.toolName) ?? toolChoice.toolName;
6875
6838
  return {
6876
6839
  tools: openaiTools2,
6877
6840
  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 },
@@ -6939,13 +6902,12 @@ function prepareFunctionTool({
6939
6902
  toolWarnings,
6940
6903
  async
6941
6904
  }) {
6942
- var _a2;
6943
- const deferLoading = options == null ? void 0 : options.deferLoading;
6905
+ const deferLoading = options?.deferLoading;
6944
6906
  const normalizedInputSchema = normalizeOpenAIJsonSchema(tool.inputSchema);
6945
- const normalizedOutputSchema = (options == null ? void 0 : options.outputSchema) != null ? normalizeOpenAIJsonSchema(options.outputSchema) : void 0;
6907
+ const normalizedOutputSchema = options?.outputSchema != null ? normalizeOpenAIJsonSchema(options.outputSchema) : void 0;
6946
6908
  toolWarnings.push(
6947
6909
  ...normalizedInputSchema.warnings,
6948
- ...(_a2 = normalizedOutputSchema == null ? void 0 : normalizedOutputSchema.warnings) != null ? _a2 : []
6910
+ ...normalizedOutputSchema?.warnings ?? []
6949
6911
  );
6950
6912
  return {
6951
6913
  type: "function",
@@ -6953,10 +6915,10 @@ function prepareFunctionTool({
6953
6915
  description: tool.description,
6954
6916
  parameters: normalizedInputSchema.schema,
6955
6917
  ...async != null ? { async } : {},
6956
- ...tool.strict != null ? { strict: tool.strict } : {},
6918
+ strict: tool.strict ?? false,
6957
6919
  ...deferLoading != null ? { defer_loading: deferLoading } : {},
6958
- ...(options == null ? void 0 : options.allowedCallers) != null ? { allowed_callers: options.allowedCallers } : {},
6959
- ...(options == null ? void 0 : options.outputSchema) != null ? { output_schema: normalizedOutputSchema == null ? void 0 : normalizedOutputSchema.schema } : {}
6920
+ ...options?.allowedCallers != null ? { allowed_callers: options.allowedCallers } : {},
6921
+ ...options?.outputSchema != null ? { output_schema: normalizedOutputSchema?.schema } : {}
6960
6922
  };
6961
6923
  }
6962
6924
  function resolveAsyncToolOption({
@@ -7003,39 +6965,35 @@ function mapShellEnvironment(environment) {
7003
6965
  };
7004
6966
  }
7005
6967
  function mapShellSkills(skills) {
7006
- return skills == null ? void 0 : skills.map(
7007
- (skill) => {
7008
- var _a2, _b;
7009
- return skill.type === "skillReference" ? {
7010
- type: "skill_reference",
7011
- skill_id: resolveProviderReference3({
7012
- reference: (_a2 = skill.providerReference) != null ? _a2 : {},
7013
- provider: "openai"
7014
- }),
7015
- version: (_b = skill.version) != null ? _b : "latest"
7016
- } : {
7017
- type: "inline",
7018
- name: skill.name,
7019
- description: skill.description,
7020
- source: {
7021
- type: "base64",
7022
- media_type: skill.source.mediaType,
7023
- data: skill.source.data
7024
- }
7025
- };
6968
+ return skills?.map(
6969
+ (skill) => skill.type === "skillReference" ? {
6970
+ type: "skill_reference",
6971
+ skill_id: resolveProviderReference3({
6972
+ reference: skill.providerReference ?? {},
6973
+ provider: "openai"
6974
+ }),
6975
+ version: skill.version ?? "latest"
6976
+ } : {
6977
+ type: "inline",
6978
+ name: skill.name,
6979
+ description: skill.description,
6980
+ source: {
6981
+ type: "base64",
6982
+ media_type: skill.source.mediaType,
6983
+ data: skill.source.data
6984
+ }
7026
6985
  }
7027
6986
  );
7028
6987
  }
7029
6988
 
7030
6989
  // src/responses/openai-responses-language-model.ts
7031
6990
  function extractApprovalRequestIdToToolCallIdMapping(prompt) {
7032
- var _a2, _b;
7033
6991
  const mapping = {};
7034
6992
  for (const message of prompt) {
7035
6993
  if (message.role !== "assistant") continue;
7036
6994
  for (const part of message.content) {
7037
6995
  if (part.type !== "tool-call") continue;
7038
- const approvalRequestId = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.approvalRequestId;
6996
+ const approvalRequestId = part.providerOptions?.openai?.approvalRequestId;
7039
6997
  if (approvalRequestId != null) {
7040
6998
  mapping[approvalRequestId] = part.toolCallId;
7041
6999
  }
@@ -7098,16 +7056,15 @@ function mapComputerCallInput({
7098
7056
  pending_safety_checks,
7099
7057
  status
7100
7058
  }) {
7101
- var _a2;
7102
7059
  return {
7103
- actions: (actions != null ? actions : action != null ? [action] : []).map(
7060
+ actions: (actions ?? (action != null ? [action] : [])).map(
7104
7061
  mapComputerAction
7105
7062
  ),
7106
- pendingSafetyChecks: (_a2 = pending_safety_checks == null ? void 0 : pending_safety_checks.map((safetyCheck) => ({
7063
+ pendingSafetyChecks: pending_safety_checks?.map((safetyCheck) => ({
7107
7064
  id: safetyCheck.id,
7108
7065
  ...safetyCheck.code != null && { code: safetyCheck.code },
7109
7066
  ...safetyCheck.message != null && { message: safetyCheck.message }
7110
- }))) != null ? _a2 : [],
7067
+ })) ?? [],
7111
7068
  status
7112
7069
  };
7113
7070
  }
@@ -7122,7 +7079,7 @@ function getConfigurationUpdateUnsupportedReason({
7122
7079
  if (!modelCapabilities.supportsConfigurationUpdate) {
7123
7080
  return "reasoningEffortUpdate is only supported by GPT-6 and later models";
7124
7081
  }
7125
- if ((options == null ? void 0 : options.reasoningMode) === "pro" || (options == null ? void 0 : options.contextManagement) != null || (options == null ? void 0 : options.truncation) === "auto") {
7082
+ if (options?.reasoningMode === "pro" || options?.contextManagement != null || options?.truncation === "auto") {
7126
7083
  return "reasoningEffortUpdate requires standard reasoning mode without automatic compaction or automatic truncation";
7127
7084
  }
7128
7085
  return void 0;
@@ -7169,7 +7126,6 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7169
7126
  responseFormat
7170
7127
  }
7171
7128
  }) {
7172
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
7173
7129
  const warnings = [];
7174
7130
  const modelCapabilities = getOpenAILanguageModelCapabilities(modelId);
7175
7131
  if (topK != null) {
@@ -7200,7 +7156,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7200
7156
  schema: openaiLanguageModelResponsesOptionsSchema
7201
7157
  });
7202
7158
  }
7203
- let resolvedReasoningEffort = (_a2 = openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null ? _a2 : isCustomReasoning2(reasoning) ? reasoning : void 0;
7159
+ let resolvedReasoningEffort = openaiOptions?.reasoningEffort ?? (isCustomReasoning2(reasoning) ? reasoning : void 0);
7204
7160
  if (resolvedReasoningEffort != null && modelCapabilities.supportedReasoningEfforts != null && !modelCapabilities.supportedReasoningEfforts.includes(
7205
7161
  resolvedReasoningEffort
7206
7162
  )) {
@@ -7211,9 +7167,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7211
7167
  });
7212
7168
  resolvedReasoningEffort = void 0;
7213
7169
  }
7214
- const resolvedReasoningSummary = (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) !== void 0 ? openaiOptions.reasoningSummary : resolvedReasoningEffort != null && resolvedReasoningEffort !== "none" ? "detailed" : void 0;
7215
- const isReasoningModel = (_b = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _b : modelCapabilities.isReasoningModel;
7216
- if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) {
7170
+ const resolvedReasoningSummary = openaiOptions?.reasoningSummary !== void 0 ? openaiOptions.reasoningSummary : resolvedReasoningEffort != null && resolvedReasoningEffort !== "none" ? "detailed" : void 0;
7171
+ const isReasoningModel = openaiOptions?.forceReasoning ?? modelCapabilities.isReasoningModel;
7172
+ if (openaiOptions?.conversation && openaiOptions?.previousResponseId) {
7217
7173
  warnings.push({
7218
7174
  type: "unsupported",
7219
7175
  feature: "conversation",
@@ -7246,7 +7202,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7246
7202
  } = await prepareResponsesTools({
7247
7203
  tools,
7248
7204
  toolChoice,
7249
- allowedTools: (_c = openaiOptions == null ? void 0 : openaiOptions.allowedTools) != null ? _c : void 0,
7205
+ allowedTools: openaiOptions?.allowedTools ?? void 0,
7250
7206
  toolNameMapping,
7251
7207
  customProviderToolNames,
7252
7208
  outputSchemaToolNames,
@@ -7259,15 +7215,15 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7259
7215
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
7260
7216
  prompt,
7261
7217
  toolNameMapping,
7262
- systemMessageMode: (_d = openaiOptions == null ? void 0 : openaiOptions.systemMessageMode) != null ? _d : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode,
7218
+ systemMessageMode: openaiOptions?.systemMessageMode ?? (isReasoningModel ? "developer" : modelCapabilities.systemMessageMode),
7263
7219
  providerOptionsName,
7264
7220
  configurationUpdateUnsupportedReason,
7265
7221
  explicitMessageItemType: config.explicitMessageItemType,
7266
7222
  fileIdPrefixes: config.fileIdPrefixes,
7267
- passThroughUnsupportedFiles: (_e = openaiOptions == null ? void 0 : openaiOptions.passThroughUnsupportedFiles) != null ? _e : false,
7268
- store: (_f = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _f : true,
7269
- hasConversation: (openaiOptions == null ? void 0 : openaiOptions.conversation) != null,
7270
- hasPreviousResponseId: (openaiOptions == null ? void 0 : openaiOptions.previousResponseId) != null,
7223
+ passThroughUnsupportedFiles: openaiOptions?.passThroughUnsupportedFiles ?? false,
7224
+ store: openaiOptions?.store ?? true,
7225
+ hasConversation: openaiOptions?.conversation != null,
7226
+ hasPreviousResponseId: openaiOptions?.previousResponseId != null,
7271
7227
  hasLocalShellTool: hasOpenAITool("openai.local_shell"),
7272
7228
  hasShellTool: hasOpenAITool("openai.shell"),
7273
7229
  hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
@@ -7277,16 +7233,31 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7277
7233
  outputSchemaToolNames: outputSchemaToolNames.size > 0 ? outputSchemaToolNames : void 0
7278
7234
  });
7279
7235
  warnings.push(...inputWarnings);
7280
- const reasoningEffortUpdate = openaiOptions == null ? void 0 : openaiOptions.reasoningEffortUpdate;
7281
- if (reasoningEffortUpdate != null && configurationUpdateUnsupportedReason != null) {
7236
+ const getUpdateEffortUnsupportedReason = (effort) => effort != null && modelCapabilities.supportedReasoningEfforts?.includes(effort) === false ? `${modelId} only supports the following reasoning efforts: ${modelCapabilities.supportedReasoningEfforts.join(", ")}` : void 0;
7237
+ for (const item of input) {
7238
+ if (item.type === "configuration_update") {
7239
+ const unsupportedReason = getUpdateEffortUnsupportedReason(
7240
+ item.reasoning.effort
7241
+ );
7242
+ if (unsupportedReason != null) {
7243
+ throw new UnsupportedFunctionalityError7({
7244
+ functionality: "Message-level reasoningEffortUpdate",
7245
+ message: unsupportedReason
7246
+ });
7247
+ }
7248
+ }
7249
+ }
7250
+ const reasoningEffortUpdate = openaiOptions?.reasoningEffortUpdate;
7251
+ const requestUpdateUnsupportedReason = configurationUpdateUnsupportedReason ?? getUpdateEffortUnsupportedReason(reasoningEffortUpdate);
7252
+ if (reasoningEffortUpdate != null && requestUpdateUnsupportedReason != null) {
7282
7253
  warnings.push({
7283
7254
  type: "unsupported",
7284
7255
  feature: "reasoningEffortUpdate",
7285
- details: configurationUpdateUnsupportedReason
7256
+ details: requestUpdateUnsupportedReason
7286
7257
  });
7287
7258
  } else if (reasoningEffortUpdate != null) {
7288
7259
  const firstItem = input[0];
7289
- if ((firstItem == null ? void 0 : firstItem.type) !== "configuration_update" || firstItem.reasoning.effort !== reasoningEffortUpdate) {
7260
+ if (firstItem?.type !== "configuration_update" || firstItem.reasoning.effort !== reasoningEffortUpdate) {
7290
7261
  input.unshift({
7291
7262
  type: "configuration_update",
7292
7263
  reasoning: { effort: reasoningEffortUpdate }
@@ -7300,15 +7271,15 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7300
7271
  });
7301
7272
  }
7302
7273
  }
7303
- if (openaiOptions == null ? void 0 : openaiOptions.compactionTrigger) {
7274
+ if (openaiOptions?.compactionTrigger) {
7304
7275
  input.push({ type: "compaction_trigger" });
7305
7276
  }
7306
- const strictJsonSchema = (_g = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _g : true;
7307
- const normalizedResponseFormatSchema = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? normalizeOpenAIJsonSchema(responseFormat.schema) : void 0;
7277
+ const strictJsonSchema = openaiOptions?.strictJsonSchema ?? true;
7278
+ const normalizedResponseFormatSchema = responseFormat?.type === "json" && responseFormat.schema != null ? normalizeOpenAIJsonSchema(responseFormat.schema) : void 0;
7308
7279
  if (normalizedResponseFormatSchema != null) {
7309
7280
  warnings.push(...normalizedResponseFormatSchema.warnings);
7310
7281
  }
7311
- let include = openaiOptions == null ? void 0 : openaiOptions.include;
7282
+ let include = openaiOptions?.include;
7312
7283
  function addInclude(key) {
7313
7284
  if (include == null) {
7314
7285
  include = [key];
@@ -7317,26 +7288,25 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7317
7288
  }
7318
7289
  }
7319
7290
  function getOpenAIToolName(id) {
7320
- var _a3;
7321
- return (_a3 = tools == null ? void 0 : tools.find((tool) => tool.type === "provider" && tool.id === id)) == null ? void 0 : _a3.name;
7291
+ return tools?.find((tool) => tool.type === "provider" && tool.id === id)?.name;
7322
7292
  }
7323
7293
  function hasOpenAITool(id) {
7324
7294
  return getOpenAIToolName(id) != null;
7325
7295
  }
7326
- 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;
7296
+ const topLogprobs = typeof openaiOptions?.logprobs === "number" ? openaiOptions?.logprobs : openaiOptions?.logprobs === true ? TOP_LOGPROBS_MAX : void 0;
7327
7297
  if (topLogprobs) {
7328
7298
  addInclude("message.output_text.logprobs");
7329
7299
  }
7330
- const webSearchToolName = (_h = tools == null ? void 0 : tools.find(
7300
+ const webSearchToolName = tools?.find(
7331
7301
  (tool) => tool.type === "provider" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
7332
- )) == null ? void 0 : _h.name;
7333
- if (webSearchToolName && config.supportsWebSearchSourcesInclude !== false && (openaiOptions == null ? void 0 : openaiOptions.includeWebSearchSources) !== false) {
7302
+ )?.name;
7303
+ if (webSearchToolName && config.supportsWebSearchSourcesInclude !== false && openaiOptions?.includeWebSearchSources !== false) {
7334
7304
  addInclude("web_search_call.action.sources");
7335
7305
  }
7336
7306
  if (hasOpenAITool("openai.code_interpreter")) {
7337
7307
  addInclude("code_interpreter_call.outputs");
7338
7308
  }
7339
- const store = openaiOptions == null ? void 0 : openaiOptions.store;
7309
+ const store = openaiOptions?.store;
7340
7310
  if (store === false && isReasoningModel) {
7341
7311
  addInclude("reasoning.encrypted_content");
7342
7312
  }
@@ -7346,48 +7316,48 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7346
7316
  temperature,
7347
7317
  top_p: topP,
7348
7318
  max_output_tokens: maxOutputTokens,
7349
- ...((responseFormat == null ? void 0 : responseFormat.type) === "json" || (openaiOptions == null ? void 0 : openaiOptions.textVerbosity)) && {
7319
+ ...(responseFormat?.type === "json" || openaiOptions?.textVerbosity) && {
7350
7320
  text: {
7351
- ...(responseFormat == null ? void 0 : responseFormat.type) === "json" && {
7321
+ ...responseFormat?.type === "json" && {
7352
7322
  format: normalizedResponseFormatSchema != null ? {
7353
7323
  type: "json_schema",
7354
7324
  strict: strictJsonSchema,
7355
- name: (_i = responseFormat.name) != null ? _i : "response",
7325
+ name: responseFormat.name ?? "response",
7356
7326
  description: responseFormat.description,
7357
7327
  schema: normalizedResponseFormatSchema.schema
7358
7328
  } : { type: "json_object" }
7359
7329
  },
7360
- ...(openaiOptions == null ? void 0 : openaiOptions.textVerbosity) && {
7330
+ ...openaiOptions?.textVerbosity && {
7361
7331
  verbosity: openaiOptions.textVerbosity
7362
7332
  }
7363
7333
  }
7364
7334
  },
7365
7335
  // provider options:
7366
- conversation: openaiOptions == null ? void 0 : openaiOptions.conversation,
7367
- max_tool_calls: openaiOptions == null ? void 0 : openaiOptions.maxToolCalls,
7368
- metadata: openaiOptions == null ? void 0 : openaiOptions.metadata,
7369
- parallel_tool_calls: openaiOptions == null ? void 0 : openaiOptions.parallelToolCalls,
7370
- previous_response_id: openaiOptions == null ? void 0 : openaiOptions.previousResponseId,
7336
+ conversation: openaiOptions?.conversation,
7337
+ max_tool_calls: openaiOptions?.maxToolCalls,
7338
+ metadata: openaiOptions?.metadata,
7339
+ parallel_tool_calls: openaiOptions?.parallelToolCalls,
7340
+ previous_response_id: openaiOptions?.previousResponseId,
7371
7341
  store,
7372
- user: openaiOptions == null ? void 0 : openaiOptions.user,
7373
- instructions: openaiOptions == null ? void 0 : openaiOptions.instructions,
7374
- service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
7342
+ user: openaiOptions?.user,
7343
+ instructions: openaiOptions?.instructions,
7344
+ service_tier: openaiOptions?.serviceTier,
7375
7345
  include,
7376
- prompt_cache_key: openaiOptions == null ? void 0 : openaiOptions.promptCacheKey,
7377
- prompt_cache_options: openaiOptions == null ? void 0 : openaiOptions.promptCacheOptions,
7378
- prompt_cache_retention: openaiOptions == null ? void 0 : openaiOptions.promptCacheRetention,
7379
- safety_identifier: openaiOptions == null ? void 0 : openaiOptions.safetyIdentifier,
7346
+ prompt_cache_key: openaiOptions?.promptCacheKey,
7347
+ prompt_cache_options: openaiOptions?.promptCacheOptions,
7348
+ prompt_cache_retention: openaiOptions?.promptCacheRetention,
7349
+ safety_identifier: openaiOptions?.safetyIdentifier,
7380
7350
  top_logprobs: topLogprobs,
7381
- truncation: openaiOptions == null ? void 0 : openaiOptions.truncation,
7351
+ truncation: openaiOptions?.truncation,
7382
7352
  // context management (server-side compaction):
7383
- ...(openaiOptions == null ? void 0 : openaiOptions.contextManagement) && {
7353
+ ...openaiOptions?.contextManagement && {
7384
7354
  context_management: openaiOptions.contextManagement.map((cm) => ({
7385
7355
  type: cm.type,
7386
7356
  compact_threshold: cm.compactThreshold
7387
7357
  }))
7388
7358
  },
7389
7359
  // model-specific settings:
7390
- ...isReasoningModel && (resolvedReasoningEffort != null || resolvedReasoningSummary != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningMode) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningContext) != null) && {
7360
+ ...isReasoningModel && (resolvedReasoningEffort != null || resolvedReasoningSummary != null || openaiOptions?.reasoningMode != null || openaiOptions?.reasoningContext != null) && {
7391
7361
  reasoning: {
7392
7362
  ...resolvedReasoningEffort != null && {
7393
7363
  effort: resolvedReasoningEffort
@@ -7395,10 +7365,10 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7395
7365
  ...resolvedReasoningSummary != null && {
7396
7366
  summary: resolvedReasoningSummary
7397
7367
  },
7398
- ...(openaiOptions == null ? void 0 : openaiOptions.reasoningMode) != null && {
7368
+ ...openaiOptions?.reasoningMode != null && {
7399
7369
  mode: openaiOptions.reasoningMode
7400
7370
  },
7401
- ...(openaiOptions == null ? void 0 : openaiOptions.reasoningContext) != null && {
7371
+ ...openaiOptions?.reasoningContext != null && {
7402
7372
  context: openaiOptions.reasoningContext
7403
7373
  }
7404
7374
  }
@@ -7430,9 +7400,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7430
7400
  details: "topP is not supported for reasoning models"
7431
7401
  });
7432
7402
  }
7433
- if (modelCapabilities.supportedReasoningEfforts != null && (baseArgs.top_logprobs != null || ((_j = baseArgs.include) == null ? void 0 : _j.includes("message.output_text.logprobs")))) {
7403
+ if (modelCapabilities.supportedReasoningEfforts != null && (baseArgs.top_logprobs != null || baseArgs.include?.includes("message.output_text.logprobs"))) {
7434
7404
  baseArgs.top_logprobs = void 0;
7435
- const filteredInclude = (_k = baseArgs.include) == null ? void 0 : _k.filter(
7405
+ const filteredInclude = baseArgs.include?.filter(
7436
7406
  (value) => value !== "message.output_text.logprobs"
7437
7407
  );
7438
7408
  baseArgs.include = filteredInclude != null && filteredInclude.length > 0 ? filteredInclude : void 0;
@@ -7444,28 +7414,28 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7444
7414
  }
7445
7415
  }
7446
7416
  } else {
7447
- if ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null) {
7417
+ if (openaiOptions?.reasoningEffort != null) {
7448
7418
  warnings.push({
7449
7419
  type: "unsupported",
7450
7420
  feature: "reasoningEffort",
7451
7421
  details: "reasoningEffort is not supported for non-reasoning models"
7452
7422
  });
7453
7423
  }
7454
- if ((openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) {
7424
+ if (openaiOptions?.reasoningSummary != null) {
7455
7425
  warnings.push({
7456
7426
  type: "unsupported",
7457
7427
  feature: "reasoningSummary",
7458
7428
  details: "reasoningSummary is not supported for non-reasoning models"
7459
7429
  });
7460
7430
  }
7461
- if ((openaiOptions == null ? void 0 : openaiOptions.reasoningMode) != null) {
7431
+ if (openaiOptions?.reasoningMode != null) {
7462
7432
  warnings.push({
7463
7433
  type: "unsupported",
7464
7434
  feature: "reasoningMode",
7465
7435
  details: "reasoningMode is not supported for non-reasoning models"
7466
7436
  });
7467
7437
  }
7468
- if ((openaiOptions == null ? void 0 : openaiOptions.reasoningContext) != null) {
7438
+ if (openaiOptions?.reasoningContext != null) {
7469
7439
  warnings.push({
7470
7440
  type: "unsupported",
7471
7441
  feature: "reasoningContext",
@@ -7473,7 +7443,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7473
7443
  });
7474
7444
  }
7475
7445
  }
7476
- if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "flex" && !modelCapabilities.supportsFlexProcessing) {
7446
+ if (openaiOptions?.serviceTier === "flex" && !modelCapabilities.supportsFlexProcessing) {
7477
7447
  warnings.push({
7478
7448
  type: "unsupported",
7479
7449
  feature: "serviceTier",
@@ -7481,7 +7451,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7481
7451
  });
7482
7452
  delete baseArgs.service_tier;
7483
7453
  }
7484
- if (((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "priority" || (openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "fast") && !modelCapabilities.supportsPriorityProcessing) {
7454
+ if ((openaiOptions?.serviceTier === "priority" || openaiOptions?.serviceTier === "fast") && !modelCapabilities.supportsPriorityProcessing) {
7485
7455
  warnings.push({
7486
7456
  type: "unsupported",
7487
7457
  feature: "serviceTier",
@@ -7489,9 +7459,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7489
7459
  });
7490
7460
  delete baseArgs.service_tier;
7491
7461
  }
7492
- const shellToolEnvType = (_n = (_m = (_l = tools == null ? void 0 : tools.find(
7462
+ const shellToolEnvType = tools?.find(
7493
7463
  (tool) => tool.type === "provider" && tool.id === "openai.shell"
7494
- )) == null ? void 0 : _l.args) == null ? void 0 : _m.environment) == null ? void 0 : _n.type;
7464
+ )?.args?.environment?.type;
7495
7465
  const isShellProviderExecuted = shellToolEnvType === "containerAuto" || shellToolEnvType === "containerReference";
7496
7466
  return {
7497
7467
  webSearchToolName,
@@ -7515,7 +7485,6 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7515
7485
  });
7516
7486
  }
7517
7487
  async doGenerate(options) {
7518
- 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;
7519
7488
  const {
7520
7489
  args: body,
7521
7490
  warnings,
@@ -7535,7 +7504,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7535
7504
  rawValue: rawResponse
7536
7505
  } = await postJsonToApi5({
7537
7506
  url,
7538
- headers: combineHeaders6((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
7507
+ headers: combineHeaders6(this.config.headers?.(), options.headers),
7539
7508
  body,
7540
7509
  failedResponseHandler: openaiFailedResponseHandler,
7541
7510
  successfulResponseHandler: createJsonResponseHandler6(
@@ -7556,7 +7525,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7556
7525
  });
7557
7526
  }
7558
7527
  if (response.output == null) {
7559
- const detail = (_c = response.incomplete_details) == null ? void 0 : _c.reason;
7528
+ const detail = response.incomplete_details?.reason;
7560
7529
  throw new APICallError2({
7561
7530
  message: detail ? `Responses API returned no output (${detail})` : "Responses API returned no output",
7562
7531
  url,
@@ -7569,9 +7538,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7569
7538
  }
7570
7539
  const content = [];
7571
7540
  const logprobs = [];
7572
- const functionTools = (_e = (_d = options.tools) == null ? void 0 : _d.filter(
7541
+ const functionTools = options.tools?.filter(
7573
7542
  (tool) => tool.type === "function"
7574
- )) != null ? _e : [];
7543
+ ) ?? [];
7575
7544
  let hasFunctionCall = false;
7576
7545
  const hostedToolSearchCallIds = [];
7577
7546
  for (const part of response.output) {
@@ -7587,7 +7556,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7587
7556
  providerMetadata: {
7588
7557
  [providerOptionsName]: {
7589
7558
  itemId: part.id,
7590
- reasoningEncryptedContent: (_f = part.encrypted_content) != null ? _f : null
7559
+ reasoningEncryptedContent: part.encrypted_content ?? null
7591
7560
  }
7592
7561
  }
7593
7562
  });
@@ -7613,7 +7582,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7613
7582
  break;
7614
7583
  }
7615
7584
  case "tool_search_call": {
7616
- const toolCallId = (_g = part.call_id) != null ? _g : part.id;
7585
+ const toolCallId = part.call_id ?? part.id;
7617
7586
  const isHosted = part.execution === "server";
7618
7587
  if (isHosted) {
7619
7588
  hostedToolSearchCallIds.push(toolCallId);
@@ -7636,7 +7605,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7636
7605
  break;
7637
7606
  }
7638
7607
  case "tool_search_output": {
7639
- const toolCallId = (_i = (_h = part.call_id) != null ? _h : hostedToolSearchCallIds.shift()) != null ? _i : part.id;
7608
+ const toolCallId = part.call_id ?? hostedToolSearchCallIds.shift() ?? part.id;
7640
7609
  content.push({
7641
7610
  type: "tool-result",
7642
7611
  toolCallId,
@@ -7707,7 +7676,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7707
7676
  }
7708
7677
  case "message": {
7709
7678
  for (const contentPart of part.content) {
7710
- if (((_k = (_j = options.providerOptions) == null ? void 0 : _j[providerOptionsName]) == null ? void 0 : _k.logprobs) && contentPart.logprobs) {
7679
+ if (options.providerOptions?.[providerOptionsName]?.logprobs && contentPart.logprobs) {
7711
7680
  logprobs.push(contentPart.logprobs);
7712
7681
  }
7713
7682
  const providerMetadata2 = {
@@ -7729,7 +7698,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7729
7698
  content.push({
7730
7699
  type: "source",
7731
7700
  sourceType: "url",
7732
- id: (_n = (_m = (_l = this.config).generateId) == null ? void 0 : _m.call(_l)) != null ? _n : generateId2(),
7701
+ id: this.config.generateId?.() ?? generateId2(),
7733
7702
  url: annotation.url,
7734
7703
  title: annotation.title
7735
7704
  });
@@ -7737,7 +7706,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7737
7706
  content.push({
7738
7707
  type: "source",
7739
7708
  sourceType: "document",
7740
- id: (_q = (_p = (_o = this.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : generateId2(),
7709
+ id: this.config.generateId?.() ?? generateId2(),
7741
7710
  mediaType: "text/plain",
7742
7711
  title: annotation.filename,
7743
7712
  filename: annotation.filename,
@@ -7753,7 +7722,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7753
7722
  content.push({
7754
7723
  type: "source",
7755
7724
  sourceType: "document",
7756
- id: (_t = (_s = (_r = this.config).generateId) == null ? void 0 : _s.call(_r)) != null ? _t : generateId2(),
7725
+ id: this.config.generateId?.() ?? generateId2(),
7757
7726
  mediaType: "text/plain",
7758
7727
  title: annotation.filename,
7759
7728
  filename: annotation.filename,
@@ -7769,7 +7738,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7769
7738
  content.push({
7770
7739
  type: "source",
7771
7740
  sourceType: "document",
7772
- id: (_w = (_v = (_u = this.config).generateId) == null ? void 0 : _v.call(_u)) != null ? _w : generateId2(),
7741
+ id: this.config.generateId?.() ?? generateId2(),
7773
7742
  mediaType: "application/octet-stream",
7774
7743
  title: annotation.file_id,
7775
7744
  filename: annotation.file_id,
@@ -7884,7 +7853,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7884
7853
  type: "tool-call",
7885
7854
  toolCallId: part.id,
7886
7855
  toolName: toolNameMapping.toCustomToolName(
7887
- webSearchToolName != null ? webSearchToolName : "web_search"
7856
+ webSearchToolName ?? "web_search"
7888
7857
  ),
7889
7858
  input: JSON.stringify({}),
7890
7859
  providerExecuted: true
@@ -7893,14 +7862,14 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7893
7862
  type: "tool-result",
7894
7863
  toolCallId: part.id,
7895
7864
  toolName: toolNameMapping.toCustomToolName(
7896
- webSearchToolName != null ? webSearchToolName : "web_search"
7865
+ webSearchToolName ?? "web_search"
7897
7866
  ),
7898
7867
  result: mapWebSearchOutput(part.action)
7899
7868
  });
7900
7869
  break;
7901
7870
  }
7902
7871
  case "mcp_call": {
7903
- const toolCallId = part.approval_request_id != null ? (_x = approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id]) != null ? _x : part.id : part.id;
7872
+ const toolCallId = part.approval_request_id != null ? approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id] ?? part.id : part.id;
7904
7873
  const toolName = `mcp.${part.name}`;
7905
7874
  content.push({
7906
7875
  type: "tool-call",
@@ -7934,8 +7903,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7934
7903
  break;
7935
7904
  }
7936
7905
  case "mcp_approval_request": {
7937
- const approvalRequestId = (_y = part.approval_request_id) != null ? _y : part.id;
7938
- const dummyToolCallId = (_B = (_A = (_z = this.config).generateId) == null ? void 0 : _A.call(_z)) != null ? _B : generateId2();
7906
+ const approvalRequestId = part.approval_request_id ?? part.id;
7907
+ const dummyToolCallId = this.config.generateId?.() ?? generateId2();
7939
7908
  const toolName = `mcp.${part.name}`;
7940
7909
  content.push({
7941
7910
  type: "tool-call",
@@ -8001,13 +7970,13 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8001
7970
  toolName: toolNameMapping.toCustomToolName("file_search"),
8002
7971
  result: {
8003
7972
  queries: part.queries,
8004
- results: (_D = (_C = part.results) == null ? void 0 : _C.map((result) => ({
7973
+ results: part.results?.map((result) => ({
8005
7974
  attributes: result.attributes,
8006
7975
  fileId: result.file_id,
8007
7976
  filename: result.filename,
8008
7977
  score: result.score,
8009
7978
  text: result.text
8010
- }))) != null ? _D : null
7979
+ })) ?? null
8011
7980
  }
8012
7981
  });
8013
7982
  break;
@@ -8072,7 +8041,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8072
8041
  responseId: response.id,
8073
8042
  ...logprobs.length > 0 ? { logprobs } : {},
8074
8043
  ...typeof response.service_tier === "string" ? { serviceTier: response.service_tier } : {},
8075
- ...((_E = response.reasoning) == null ? void 0 : _E.context) != null ? { reasoningContext: response.reasoning.context } : {}
8044
+ ...response.reasoning?.context != null ? { reasoningContext: response.reasoning.context } : {}
8076
8045
  }
8077
8046
  };
8078
8047
  const usage = response.usage;
@@ -8080,10 +8049,10 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8080
8049
  content,
8081
8050
  finishReason: {
8082
8051
  unified: mapOpenAIResponseFinishReason({
8083
- finishReason: (_F = response.incomplete_details) == null ? void 0 : _F.reason,
8052
+ finishReason: response.incomplete_details?.reason,
8084
8053
  hasFunctionCall
8085
8054
  }),
8086
- raw: (_H = (_G = response.incomplete_details) == null ? void 0 : _G.reason) != null ? _H : void 0
8055
+ raw: response.incomplete_details?.reason ?? void 0
8087
8056
  },
8088
8057
  usage: convertOpenAIResponsesUsage(usage),
8089
8058
  request: { body },
@@ -8099,7 +8068,6 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8099
8068
  };
8100
8069
  }
8101
8070
  async doStream(options) {
8102
- var _a2, _b, _c, _d;
8103
8071
  const {
8104
8072
  args: body,
8105
8073
  warnings,
@@ -8115,7 +8083,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8115
8083
  });
8116
8084
  const { responseHeaders, value: response } = await postJsonToApi5({
8117
8085
  url,
8118
- headers: combineHeaders6((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
8086
+ headers: combineHeaders6(this.config.headers?.(), options.headers),
8119
8087
  body: {
8120
8088
  ...body,
8121
8089
  stream: true
@@ -8138,9 +8106,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8138
8106
  });
8139
8107
  const self = this;
8140
8108
  const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
8141
- const functionTools = (_d = (_c = options.tools) == null ? void 0 : _c.filter(
8109
+ const functionTools = options.tools?.filter(
8142
8110
  (tool) => tool.type === "function"
8143
- )) != null ? _d : [];
8111
+ ) ?? [];
8144
8112
  const approvalRequestIdToDummyToolCallIdFromStream = /* @__PURE__ */ new Map();
8145
8113
  let finishReason = {
8146
8114
  unified: "other",
@@ -8158,10 +8126,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8158
8126
  const resolveOutputItemId = ({
8159
8127
  itemId,
8160
8128
  outputIndex
8161
- }) => {
8162
- var _a3;
8163
- return outputIndex == null ? itemId : (_a3 = activeOutputItemIds[outputIndex]) != null ? _a3 : itemId;
8164
- };
8129
+ }) => outputIndex == null ? itemId : activeOutputItemIds[outputIndex] ?? itemId;
8165
8130
  let serviceTier;
8166
8131
  let reasoningContext;
8167
8132
  const hostedToolSearchCallIds = [];
@@ -8173,7 +8138,6 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8173
8138
  controller.enqueue({ type: "stream-start", warnings });
8174
8139
  },
8175
8140
  transform(chunk, controller) {
8176
- 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;
8177
8141
  if (options.includeRawChunks) {
8178
8142
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
8179
8143
  }
@@ -8228,7 +8192,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8228
8192
  } else if (value.item.type === "web_search_call") {
8229
8193
  ongoingToolCalls[value.output_index] = {
8230
8194
  toolName: toolNameMapping.toCustomToolName(
8231
- webSearchToolName != null ? webSearchToolName : "web_search"
8195
+ webSearchToolName ?? "web_search"
8232
8196
  ),
8233
8197
  toolCallId: value.item.id
8234
8198
  };
@@ -8236,7 +8200,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8236
8200
  type: "tool-input-start",
8237
8201
  id: value.item.id,
8238
8202
  toolName: toolNameMapping.toCustomToolName(
8239
- webSearchToolName != null ? webSearchToolName : "web_search"
8203
+ webSearchToolName ?? "web_search"
8240
8204
  ),
8241
8205
  providerExecuted: true
8242
8206
  });
@@ -8248,13 +8212,13 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8248
8212
  type: "tool-call",
8249
8213
  toolCallId: value.item.id,
8250
8214
  toolName: toolNameMapping.toCustomToolName(
8251
- webSearchToolName != null ? webSearchToolName : "web_search"
8215
+ webSearchToolName ?? "web_search"
8252
8216
  ),
8253
8217
  input: JSON.stringify({}),
8254
8218
  providerExecuted: true
8255
8219
  });
8256
8220
  } else if (value.item.type === "computer_call") {
8257
- const toolCallId = (_a3 = value.item.call_id) != null ? _a3 : value.item.id;
8221
+ const toolCallId = value.item.call_id ?? value.item.id;
8258
8222
  ongoingToolCalls[value.output_index] = {
8259
8223
  toolName: toolNameMapping.toCustomToolName("computer"),
8260
8224
  toolCallId
@@ -8306,7 +8270,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8306
8270
  ongoingToolCalls[value.output_index] = {
8307
8271
  toolName,
8308
8272
  toolCallId,
8309
- toolSearchExecution: (_b2 = value.item.execution) != null ? _b2 : "server"
8273
+ toolSearchExecution: value.item.execution ?? "server"
8310
8274
  };
8311
8275
  if (isHosted) {
8312
8276
  controller.enqueue({
@@ -8364,7 +8328,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8364
8328
  } else if (value.item.type === "message") {
8365
8329
  activeOutputItemIds[value.output_index] = value.item.id;
8366
8330
  ongoingAnnotations.splice(0);
8367
- activeMessagePhase = (_c2 = value.item.phase) != null ? _c2 : void 0;
8331
+ activeMessagePhase = value.item.phase ?? void 0;
8368
8332
  controller.enqueue({
8369
8333
  type: "text-start",
8370
8334
  id: value.item.id,
@@ -8389,7 +8353,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8389
8353
  providerMetadata: {
8390
8354
  [providerOptionsName]: {
8391
8355
  itemId: value.item.id,
8392
- reasoningEncryptedContent: (_d2 = value.item.encrypted_content) != null ? _d2 : null
8356
+ reasoningEncryptedContent: value.item.encrypted_content ?? null
8393
8357
  }
8394
8358
  }
8395
8359
  });
@@ -8400,7 +8364,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8400
8364
  itemId: value.item.id,
8401
8365
  outputIndex: value.output_index
8402
8366
  });
8403
- const phase = (_e = value.item.phase) != null ? _e : activeMessagePhase;
8367
+ const phase = value.item.phase ?? activeMessagePhase;
8404
8368
  activeMessagePhase = void 0;
8405
8369
  controller.enqueue({
8406
8370
  type: "text-end",
@@ -8421,19 +8385,18 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8421
8385
  const ongoingToolCall = ongoingToolCalls[value.output_index];
8422
8386
  ongoingToolCalls[value.output_index] = void 0;
8423
8387
  hasFunctionCall = true;
8424
- const suppressInputStreaming = (_f = ongoingToolCall == null ? void 0 : ongoingToolCall.suppressInputStreaming) != null ? _f : isUndeclaredParallelToolCall({
8388
+ const suppressInputStreaming = ongoingToolCall?.suppressInputStreaming ?? isUndeclaredParallelToolCall({
8425
8389
  toolName: item.name,
8426
8390
  tools: functionTools
8427
8391
  });
8428
8392
  const enqueueUnexpandedToolCall = () => {
8429
- var _a4;
8430
8393
  if (suppressInputStreaming) {
8431
8394
  controller.enqueue({
8432
8395
  type: "tool-input-start",
8433
8396
  id: item.call_id,
8434
8397
  toolName: item.name
8435
8398
  });
8436
- const bufferedInputDeltas = (_a4 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a4 : [];
8399
+ const bufferedInputDeltas = ongoingToolCall?.bufferedInputDeltas ?? [];
8437
8400
  if (bufferedInputDeltas.length > 0) {
8438
8401
  for (const delta of bufferedInputDeltas) {
8439
8402
  controller.enqueue({
@@ -8469,7 +8432,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8469
8432
  providerMetadata: {
8470
8433
  [providerOptionsName]: {
8471
8434
  itemId: item.id,
8472
- ...item.async != null ? { async: item.async } : (ongoingToolCall == null ? void 0 : ongoingToolCall.async) != null ? { async: ongoingToolCall.async } : {},
8435
+ ...item.async != null ? { async: item.async } : ongoingToolCall?.async != null ? { async: ongoingToolCall.async } : {},
8473
8436
  ...item.namespace != null && {
8474
8437
  namespace: item.namespace
8475
8438
  },
@@ -8573,7 +8536,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8573
8536
  providerMetadata: {
8574
8537
  [providerOptionsName]: {
8575
8538
  itemId: value.item.id,
8576
- ...value.item.async != null ? { async: value.item.async } : (ongoingToolCall == null ? void 0 : ongoingToolCall.async) != null ? { async: ongoingToolCall.async } : {}
8539
+ ...value.item.async != null ? { async: value.item.async } : ongoingToolCall?.async != null ? { async: ongoingToolCall.async } : {}
8577
8540
  }
8578
8541
  }
8579
8542
  });
@@ -8583,7 +8546,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8583
8546
  type: "tool-result",
8584
8547
  toolCallId: value.item.id,
8585
8548
  toolName: toolNameMapping.toCustomToolName(
8586
- webSearchToolName != null ? webSearchToolName : "web_search"
8549
+ webSearchToolName ?? "web_search"
8587
8550
  ),
8588
8551
  result: mapWebSearchOutput(value.item.action)
8589
8552
  });
@@ -8643,13 +8606,13 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8643
8606
  toolName: toolNameMapping.toCustomToolName("file_search"),
8644
8607
  result: {
8645
8608
  queries: value.item.queries,
8646
- results: (_h = (_g = value.item.results) == null ? void 0 : _g.map((result2) => ({
8609
+ results: value.item.results?.map((result2) => ({
8647
8610
  attributes: result2.attributes,
8648
8611
  fileId: result2.file_id,
8649
8612
  filename: result2.filename,
8650
8613
  score: result2.score,
8651
8614
  text: result2.text
8652
- }))) != null ? _h : null
8615
+ })) ?? null
8653
8616
  }
8654
8617
  });
8655
8618
  } else if (value.item.type === "code_interpreter_call") {
@@ -8675,7 +8638,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8675
8638
  const toolCall = ongoingToolCalls[value.output_index];
8676
8639
  const isHosted = value.item.execution === "server";
8677
8640
  if (toolCall != null) {
8678
- const toolCallId = isHosted ? toolCall.toolCallId : (_i = value.item.call_id) != null ? _i : value.item.id;
8641
+ const toolCallId = isHosted ? toolCall.toolCallId : value.item.call_id ?? value.item.id;
8679
8642
  if (isHosted) {
8680
8643
  hostedToolSearchCallIds.push(toolCallId);
8681
8644
  } else {
@@ -8707,7 +8670,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8707
8670
  }
8708
8671
  ongoingToolCalls[value.output_index] = void 0;
8709
8672
  } else if (value.item.type === "tool_search_output") {
8710
- const toolCallId = (_k = (_j = value.item.call_id) != null ? _j : hostedToolSearchCallIds.shift()) != null ? _k : value.item.id;
8673
+ const toolCallId = value.item.call_id ?? hostedToolSearchCallIds.shift() ?? value.item.id;
8711
8674
  controller.enqueue({
8712
8675
  type: "tool-result",
8713
8676
  toolCallId,
@@ -8723,10 +8686,10 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8723
8686
  });
8724
8687
  } else if (value.item.type === "mcp_call") {
8725
8688
  ongoingToolCalls[value.output_index] = void 0;
8726
- const approvalRequestId = (_l = value.item.approval_request_id) != null ? _l : void 0;
8727
- const aliasedToolCallId = approvalRequestId != null ? (_n = (_m = approvalRequestIdToDummyToolCallIdFromStream.get(
8689
+ const approvalRequestId = value.item.approval_request_id ?? void 0;
8690
+ const aliasedToolCallId = approvalRequestId != null ? approvalRequestIdToDummyToolCallIdFromStream.get(
8728
8691
  approvalRequestId
8729
- )) != null ? _m : approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId]) != null ? _n : value.item.id : value.item.id;
8692
+ ) ?? approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId] ?? value.item.id : value.item.id;
8730
8693
  const toolName = `mcp.${value.item.name}`;
8731
8694
  controller.enqueue({
8732
8695
  type: "tool-call",
@@ -8758,7 +8721,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8758
8721
  ongoingToolCalls[value.output_index] = void 0;
8759
8722
  } else if (value.item.type === "apply_patch_call") {
8760
8723
  const toolCall = ongoingToolCalls[value.output_index];
8761
- if ((toolCall == null ? void 0 : toolCall.applyPatch) && !toolCall.applyPatch.endEmitted && value.item.operation.type !== "delete_file") {
8724
+ if (toolCall?.applyPatch && !toolCall.applyPatch.endEmitted && value.item.operation.type !== "delete_file") {
8762
8725
  if (!toolCall.applyPatch.hasDiff) {
8763
8726
  controller.enqueue({
8764
8727
  type: "tool-input-delta",
@@ -8797,8 +8760,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8797
8760
  ongoingToolCalls[value.output_index] = void 0;
8798
8761
  } else if (value.item.type === "mcp_approval_request") {
8799
8762
  ongoingToolCalls[value.output_index] = void 0;
8800
- const dummyToolCallId = (_q = (_p = (_o = self.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : generateId2();
8801
- const approvalRequestId = (_r = value.item.approval_request_id) != null ? _r : value.item.id;
8763
+ const dummyToolCallId = self.config.generateId?.() ?? generateId2();
8764
+ const approvalRequestId = value.item.approval_request_id ?? value.item.id;
8802
8765
  approvalRequestIdToDummyToolCallIdFromStream.set(
8803
8766
  approvalRequestId,
8804
8767
  dummyToolCallId
@@ -8892,7 +8855,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8892
8855
  providerMetadata: {
8893
8856
  [providerOptionsName]: {
8894
8857
  itemId,
8895
- reasoningEncryptedContent: (_s = value.item.encrypted_content) != null ? _s : null
8858
+ reasoningEncryptedContent: value.item.encrypted_content ?? null
8896
8859
  }
8897
8860
  }
8898
8861
  });
@@ -8917,7 +8880,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8917
8880
  const toolCall = ongoingToolCalls[value.output_index];
8918
8881
  if (toolCall != null) {
8919
8882
  if (toolCall.suppressInputStreaming) {
8920
- (_t = toolCall.bufferedInputDeltas) == null ? void 0 : _t.push(value.delta);
8883
+ toolCall.bufferedInputDeltas?.push(value.delta);
8921
8884
  } else {
8922
8885
  controller.enqueue({
8923
8886
  type: "tool-input-delta",
@@ -8937,7 +8900,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8937
8900
  }
8938
8901
  } else if (isResponseApplyPatchCallOperationDiffDeltaChunk(value)) {
8939
8902
  const toolCall = ongoingToolCalls[value.output_index];
8940
- if (toolCall == null ? void 0 : toolCall.applyPatch) {
8903
+ if (toolCall?.applyPatch) {
8941
8904
  controller.enqueue({
8942
8905
  type: "tool-input-delta",
8943
8906
  id: toolCall.toolCallId,
@@ -8947,7 +8910,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8947
8910
  }
8948
8911
  } else if (isResponseApplyPatchCallOperationDiffDoneChunk(value)) {
8949
8912
  const toolCall = ongoingToolCalls[value.output_index];
8950
- if ((toolCall == null ? void 0 : toolCall.applyPatch) && !toolCall.applyPatch.endEmitted) {
8913
+ if (toolCall?.applyPatch && !toolCall.applyPatch.endEmitted) {
8951
8914
  if (!toolCall.applyPatch.hasDiff) {
8952
8915
  controller.enqueue({
8953
8916
  type: "tool-input-delta",
@@ -9027,7 +8990,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9027
8990
  id: itemId,
9028
8991
  delta: value.delta
9029
8992
  });
9030
- if (((_v = (_u = options.providerOptions) == null ? void 0 : _u[providerOptionsName]) == null ? void 0 : _v.logprobs) && value.logprobs) {
8993
+ if (options.providerOptions?.[providerOptionsName]?.logprobs && value.logprobs) {
9031
8994
  logprobs.push(value.logprobs);
9032
8995
  }
9033
8996
  } else if (value.type === "response.reasoning_summary_part.added") {
@@ -9061,7 +9024,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9061
9024
  providerMetadata: {
9062
9025
  [providerOptionsName]: {
9063
9026
  itemId,
9064
- reasoningEncryptedContent: (_w = activeReasoningPart.encryptedContent) != null ? _w : null
9027
+ reasoningEncryptedContent: activeReasoningPart.encryptedContent ?? null
9065
9028
  }
9066
9029
  }
9067
9030
  });
@@ -9108,30 +9071,30 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9108
9071
  if (!encounteredStreamError) {
9109
9072
  finishReason = {
9110
9073
  unified: mapOpenAIResponseFinishReason({
9111
- finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
9074
+ finishReason: value.response.incomplete_details?.reason,
9112
9075
  hasFunctionCall
9113
9076
  }),
9114
- raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
9077
+ raw: value.response.incomplete_details?.reason ?? void 0
9115
9078
  };
9116
9079
  }
9117
- usage = (_A = value.response.usage) != null ? _A : void 0;
9080
+ usage = value.response.usage ?? void 0;
9118
9081
  if (typeof value.response.service_tier === "string") {
9119
9082
  serviceTier = value.response.service_tier;
9120
9083
  }
9121
- if (((_B = value.response.reasoning) == null ? void 0 : _B.context) != null) {
9084
+ if (value.response.reasoning?.context != null) {
9122
9085
  reasoningContext = value.response.reasoning.context;
9123
9086
  }
9124
9087
  } else if (isResponseFailedChunk(value)) {
9125
- const incompleteReason = (_C = value.response.incomplete_details) == null ? void 0 : _C.reason;
9088
+ const incompleteReason = value.response.incomplete_details?.reason;
9126
9089
  finishReason = {
9127
9090
  unified: incompleteReason ? mapOpenAIResponseFinishReason({
9128
9091
  finishReason: incompleteReason,
9129
9092
  hasFunctionCall
9130
9093
  }) : "error",
9131
- raw: incompleteReason != null ? incompleteReason : "error"
9094
+ raw: incompleteReason ?? "error"
9132
9095
  };
9133
- usage = (_D = value.response.usage) != null ? _D : void 0;
9134
- if (((_E = value.response.reasoning) == null ? void 0 : _E.context) != null) {
9096
+ usage = value.response.usage ?? void 0;
9097
+ if (value.response.reasoning?.context != null) {
9135
9098
  reasoningContext = value.response.reasoning.context;
9136
9099
  }
9137
9100
  if (!encounteredStreamError && value.response.error != null) {
@@ -9147,7 +9110,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9147
9110
  };
9148
9111
  controller.enqueue({
9149
9112
  type: "error",
9150
- error: (_F = createOpenAIProviderStreamError(error)) != null ? _F : error
9113
+ error: createOpenAIProviderStreamError(error) ?? error
9151
9114
  });
9152
9115
  }
9153
9116
  } else if (isResponseAnnotationAddedChunk(value)) {
@@ -9156,7 +9119,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9156
9119
  controller.enqueue({
9157
9120
  type: "source",
9158
9121
  sourceType: "url",
9159
- id: (_I = (_H = (_G = self.config).generateId) == null ? void 0 : _H.call(_G)) != null ? _I : generateId2(),
9122
+ id: self.config.generateId?.() ?? generateId2(),
9160
9123
  url: value.annotation.url,
9161
9124
  title: value.annotation.title
9162
9125
  });
@@ -9164,7 +9127,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9164
9127
  controller.enqueue({
9165
9128
  type: "source",
9166
9129
  sourceType: "document",
9167
- id: (_L = (_K = (_J = self.config).generateId) == null ? void 0 : _K.call(_J)) != null ? _L : generateId2(),
9130
+ id: self.config.generateId?.() ?? generateId2(),
9168
9131
  mediaType: "text/plain",
9169
9132
  title: value.annotation.filename,
9170
9133
  filename: value.annotation.filename,
@@ -9180,7 +9143,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9180
9143
  controller.enqueue({
9181
9144
  type: "source",
9182
9145
  sourceType: "document",
9183
- id: (_O = (_N = (_M = self.config).generateId) == null ? void 0 : _N.call(_M)) != null ? _O : generateId2(),
9146
+ id: self.config.generateId?.() ?? generateId2(),
9184
9147
  mediaType: "text/plain",
9185
9148
  title: value.annotation.filename,
9186
9149
  filename: value.annotation.filename,
@@ -9196,7 +9159,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9196
9159
  controller.enqueue({
9197
9160
  type: "source",
9198
9161
  sourceType: "document",
9199
- id: (_R = (_Q = (_P = self.config).generateId) == null ? void 0 : _Q.call(_P)) != null ? _R : generateId2(),
9162
+ id: self.config.generateId?.() ?? generateId2(),
9200
9163
  mediaType: "application/octet-stream",
9201
9164
  title: value.annotation.file_id,
9202
9165
  filename: value.annotation.file_id,
@@ -9214,14 +9177,13 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9214
9177
  finishReason = { unified: "error", raw: "error" };
9215
9178
  controller.enqueue({
9216
9179
  type: "error",
9217
- error: (_S = createOpenAIProviderStreamError(value)) != null ? _S : value
9180
+ error: createOpenAIProviderStreamError(value) ?? value
9218
9181
  });
9219
9182
  }
9220
9183
  },
9221
9184
  flush(controller) {
9222
- var _a3;
9223
9185
  for (const toolCall of Object.values(ongoingToolCalls)) {
9224
- if (!(toolCall == null ? void 0 : toolCall.suppressInputStreaming)) {
9186
+ if (!toolCall?.suppressInputStreaming) {
9225
9187
  continue;
9226
9188
  }
9227
9189
  controller.enqueue({
@@ -9229,7 +9191,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
9229
9191
  id: toolCall.toolCallId,
9230
9192
  toolName: toolCall.toolName
9231
9193
  });
9232
- for (const delta of (_a3 = toolCall.bufferedInputDeltas) != null ? _a3 : []) {
9194
+ for (const delta of toolCall.bufferedInputDeltas ?? []) {
9233
9195
  controller.enqueue({
9234
9196
  type: "tool-input-delta",
9235
9197
  id: toolCall.toolCallId,
@@ -9337,7 +9299,6 @@ function isResponseOutputChunk(chunk) {
9337
9299
  return !(chunk.type === "response.created" || chunk.type === "response.in_progress" || chunk.type === "response.failed" || chunk.type === "error" || chunk.type === "unknown_chunk");
9338
9300
  }
9339
9301
  function mapWebSearchOutput(action) {
9340
- var _a2;
9341
9302
  if (action == null) {
9342
9303
  return {};
9343
9304
  }
@@ -9346,7 +9307,7 @@ function mapWebSearchOutput(action) {
9346
9307
  return {
9347
9308
  action: {
9348
9309
  type: "search",
9349
- query: (_a2 = action.query) != null ? _a2 : void 0,
9310
+ query: action.query ?? void 0,
9350
9311
  ...action.queries != null && { queries: action.queries }
9351
9312
  },
9352
9313
  // include sources when provided by the Responses API (behind include flag)
@@ -9451,7 +9412,6 @@ var OpenAIBatch = class {
9451
9412
  this.provider = options.provider;
9452
9413
  }
9453
9414
  async doStartBatch(options) {
9454
- var _a2, _b, _c, _d, _e, _f;
9455
9415
  assertTextBatchRequests(options.requests);
9456
9416
  validateSingleModel(options.requests);
9457
9417
  const fileParts = [];
@@ -9467,7 +9427,7 @@ var OpenAIBatch = class {
9467
9427
  const batchOptions = await this.parseBatchProviderOptions(
9468
9428
  options.providerOptions
9469
9429
  );
9470
- const inputFileExpiresAfterSeconds = (_a2 = batchOptions == null ? void 0 : batchOptions.inputFileExpiresAfter) != null ? _a2 : openaiBatchInputFileDefaultExpiresAfterSeconds;
9430
+ const inputFileExpiresAfterSeconds = batchOptions?.inputFileExpiresAfter ?? openaiBatchInputFileDefaultExpiresAfterSeconds;
9471
9431
  for (const request of options.requests) {
9472
9432
  const preparedRequest = await this.prepareRequest(request);
9473
9433
  fileParts.push(
@@ -9482,7 +9442,7 @@ var OpenAIBatch = class {
9482
9442
  for (const warning of preparedRequest.warnings) {
9483
9443
  warnings.push({ requestId: request.id, warning });
9484
9444
  }
9485
- for (const tool of (_b = request.options.tools) != null ? _b : []) {
9445
+ for (const tool of request.options.tools ?? []) {
9486
9446
  if (tool.type === "provider" && !openAIBatchConvertibleProviderToolIds.has(tool.id)) {
9487
9447
  warnings.push({
9488
9448
  requestId: request.id,
@@ -9510,7 +9470,7 @@ var OpenAIBatch = class {
9510
9470
  );
9511
9471
  const { value: uploadedFile } = await postToApi({
9512
9472
  url: this.getUrl("/files"),
9513
- headers: combineHeaders7((_d = (_c = this.options.config).headers) == null ? void 0 : _d.call(_c), options.headers),
9473
+ headers: combineHeaders7(this.options.config.headers?.(), options.headers),
9514
9474
  body: {
9515
9475
  content: formData,
9516
9476
  values: {
@@ -9533,7 +9493,7 @@ var OpenAIBatch = class {
9533
9493
  });
9534
9494
  const { value: batch } = await postJsonToApi6({
9535
9495
  url: this.getUrl("/batches"),
9536
- headers: combineHeaders7((_f = (_e = this.options.config).headers) == null ? void 0 : _f.call(_e), options.headers),
9496
+ headers: combineHeaders7(this.options.config.headers?.(), options.headers),
9537
9497
  body: {
9538
9498
  input_file_id: uploadedFile.id,
9539
9499
  endpoint: openaiBatchEndpoint,
@@ -9580,12 +9540,11 @@ var OpenAIBatch = class {
9580
9540
  return convertOpenAIBatchStatus(batch);
9581
9541
  }
9582
9542
  async doCancelBatch(options) {
9583
- var _a2, _b;
9584
9543
  await postJsonToApi6({
9585
9544
  url: this.getUrl(
9586
9545
  `/batches/${encodeURIComponent(options.batchId)}/cancel`
9587
9546
  ),
9588
- headers: combineHeaders7((_b = (_a2 = this.options.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
9547
+ headers: combineHeaders7(this.options.config.headers?.(), options.headers),
9589
9548
  body: {},
9590
9549
  failedResponseHandler: openaiFailedResponseHandler,
9591
9550
  successfulResponseHandler: createJsonResponseHandler7(
@@ -9597,7 +9556,6 @@ var OpenAIBatch = class {
9597
9556
  return {};
9598
9557
  }
9599
9558
  async doListBatches(options) {
9600
- var _a2, _b;
9601
9559
  const url = new URL(this.getUrl("/batches"));
9602
9560
  if (options.limit != null) {
9603
9561
  url.searchParams.set("limit", String(options.limit));
@@ -9607,7 +9565,7 @@ var OpenAIBatch = class {
9607
9565
  }
9608
9566
  const { value: page } = await getFromApi2({
9609
9567
  url: url.toString(),
9610
- headers: combineHeaders7((_b = (_a2 = this.options.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
9568
+ headers: combineHeaders7(this.options.config.headers?.(), options.headers),
9611
9569
  failedResponseHandler: openaiFailedResponseHandler,
9612
9570
  successfulResponseHandler: createJsonResponseHandler7(
9613
9571
  openaiBatchListResponseSchema
@@ -9646,10 +9604,9 @@ var OpenAIBatch = class {
9646
9604
  return convertAsyncIteratorToReadableStream(iterator);
9647
9605
  }
9648
9606
  async retrieveBatch(options) {
9649
- var _a2, _b;
9650
9607
  const { value: batch } = await getFromApi2({
9651
9608
  url: this.getUrl(`/batches/${encodeURIComponent(options.batchId)}`),
9652
- headers: combineHeaders7((_b = (_a2 = this.options.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
9609
+ headers: combineHeaders7(this.options.config.headers?.(), options.headers),
9653
9610
  failedResponseHandler: openaiFailedResponseHandler,
9654
9611
  successfulResponseHandler: createJsonResponseHandler7(
9655
9612
  openaiBatchResponseSchema
@@ -9664,12 +9621,11 @@ var OpenAIBatch = class {
9664
9621
  fileIds,
9665
9622
  options
9666
9623
  }) {
9667
- var _a2, _b;
9668
9624
  for (const fileId of fileIds) {
9669
9625
  const { value: lines } = await getFromApi2({
9670
9626
  url: this.getUrl(`/files/${encodeURIComponent(fileId)}/content`),
9671
9627
  headers: combineHeaders7(
9672
- (_b = (_a2 = this.options.config).headers) == null ? void 0 : _b.call(_a2),
9628
+ this.options.config.headers?.(),
9673
9629
  options.headers
9674
9630
  ),
9675
9631
  failedResponseHandler: openaiFailedResponseHandler,
@@ -9750,8 +9706,7 @@ var OpenAIBatch = class {
9750
9706
  }
9751
9707
  };
9752
9708
  function validateSingleModel(requests) {
9753
- var _a2;
9754
- const modelId = (_a2 = requests[0]) == null ? void 0 : _a2.modelId;
9709
+ const modelId = requests[0]?.modelId;
9755
9710
  for (const request of requests) {
9756
9711
  if (request.modelId !== modelId) {
9757
9712
  throw new InvalidArgumentError2({
@@ -9769,9 +9724,8 @@ var openAIBatchConvertibleProviderToolIds = /* @__PURE__ */ new Set([
9769
9724
  "openai.web_search_preview"
9770
9725
  ]);
9771
9726
  function convertOpenAIBatchStatus(batch) {
9772
- var _a2, _b, _c;
9773
9727
  const status = mapOpenAIBatchStatus(batch.status);
9774
- const firstError = (_b = (_a2 = batch.errors) == null ? void 0 : _a2.data) == null ? void 0 : _b[0];
9728
+ const firstError = batch.errors?.data?.[0];
9775
9729
  const requestCounts = convertOpenAIRequestCounts(batch.request_counts);
9776
9730
  const createdAt = convertUnixTimestamp(batch.created_at);
9777
9731
  const expiresAt = convertUnixTimestamp(batch.expires_at);
@@ -9781,7 +9735,7 @@ function convertOpenAIBatchStatus(batch) {
9781
9735
  ...requestCounts != null ? { requestCounts } : {},
9782
9736
  ...firstError != null ? {
9783
9737
  error: {
9784
- message: (_c = firstError.message) != null ? _c : "OpenAI batch failed.",
9738
+ message: firstError.message ?? "OpenAI batch failed.",
9785
9739
  ...firstError.code != null ? { code: firstError.code } : {}
9786
9740
  }
9787
9741
  } : {},
@@ -9806,9 +9760,9 @@ function mapOpenAIBatchStatus(rawStatus) {
9806
9760
  }
9807
9761
  }
9808
9762
  function convertOpenAIRequestCounts(counts) {
9809
- const total = counts == null ? void 0 : counts.total;
9810
- const completed = counts == null ? void 0 : counts.completed;
9811
- const failed = counts == null ? void 0 : counts.failed;
9763
+ const total = counts?.total;
9764
+ const completed = counts?.completed;
9765
+ const failed = counts?.failed;
9812
9766
  return normalizeBatchRequestCounts({
9813
9767
  total,
9814
9768
  pending: total != null && completed != null && failed != null ? total - completed - failed : void 0,
@@ -9827,7 +9781,6 @@ async function convertOpenAIErrorResponse({
9827
9781
  body,
9828
9782
  statusCode
9829
9783
  }) {
9830
- var _a2;
9831
9784
  const result = await safeValidateTypes({
9832
9785
  value: body,
9833
9786
  schema: openaiErrorDataSchema
@@ -9840,13 +9793,12 @@ async function convertOpenAIErrorResponse({
9840
9793
  }
9841
9794
  return {
9842
9795
  message: result.value.error.message,
9843
- type: (_a2 = result.value.error.type) != null ? _a2 : void 0,
9796
+ type: result.value.error.type ?? void 0,
9844
9797
  code: result.value.error.code != null ? String(result.value.error.code) : void 0,
9845
9798
  statusCode
9846
9799
  };
9847
9800
  }
9848
9801
  async function convertOpenAIBatchResult(body) {
9849
- var _a2, _b, _c, _d, _e, _f, _g, _h;
9850
9802
  const validation = await safeValidateTypes({
9851
9803
  value: body,
9852
9804
  schema: openaiResponsesResponseSchema
@@ -9872,7 +9824,7 @@ async function convertOpenAIBatchResult(body) {
9872
9824
  };
9873
9825
  }
9874
9826
  if (response.output == null) {
9875
- const detail = (_a2 = response.incomplete_details) == null ? void 0 : _a2.reason;
9827
+ const detail = response.incomplete_details?.reason;
9876
9828
  return {
9877
9829
  success: false,
9878
9830
  error: {
@@ -9895,7 +9847,7 @@ async function convertOpenAIBatchResult(body) {
9895
9847
  providerMetadata: {
9896
9848
  openai: {
9897
9849
  itemId: part.id,
9898
- reasoningEncryptedContent: (_b = part.encrypted_content) != null ? _b : null
9850
+ reasoningEncryptedContent: part.encrypted_content ?? null
9899
9851
  }
9900
9852
  }
9901
9853
  });
@@ -9971,13 +9923,13 @@ async function convertOpenAIBatchResult(body) {
9971
9923
  toolName: "file_search",
9972
9924
  result: {
9973
9925
  queries: part.queries,
9974
- results: (_d = (_c = part.results) == null ? void 0 : _c.map((result) => ({
9926
+ results: part.results?.map((result) => ({
9975
9927
  attributes: result.attributes,
9976
9928
  fileId: result.file_id,
9977
9929
  filename: result.filename,
9978
9930
  score: result.score,
9979
9931
  text: result.text
9980
- }))) != null ? _d : null
9932
+ })) ?? null
9981
9933
  },
9982
9934
  dynamic: true
9983
9935
  });
@@ -10017,7 +9969,7 @@ async function convertOpenAIBatchResult(body) {
10017
9969
  responseId: response.id,
10018
9970
  ...logprobs.length > 0 ? { logprobs } : {},
10019
9971
  ...typeof response.service_tier === "string" ? { serviceTier: response.service_tier } : {},
10020
- ...((_e = response.reasoning) == null ? void 0 : _e.context) != null ? { reasoningContext: response.reasoning.context } : {}
9972
+ ...response.reasoning?.context != null ? { reasoningContext: response.reasoning.context } : {}
10021
9973
  }
10022
9974
  };
10023
9975
  return {
@@ -10026,10 +9978,10 @@ async function convertOpenAIBatchResult(body) {
10026
9978
  content,
10027
9979
  finishReason: {
10028
9980
  unified: mapOpenAIResponseFinishReason({
10029
- finishReason: (_f = response.incomplete_details) == null ? void 0 : _f.reason,
9981
+ finishReason: response.incomplete_details?.reason,
10030
9982
  hasFunctionCall
10031
9983
  }),
10032
- raw: (_h = (_g = response.incomplete_details) == null ? void 0 : _g.reason) != null ? _h : void 0
9984
+ raw: response.incomplete_details?.reason ?? void 0
10033
9985
  },
10034
9986
  usage: convertOpenAIResponsesUsage(response.usage),
10035
9987
  response: {
@@ -10123,7 +10075,6 @@ var audioFormatSchema = z30.union([
10123
10075
  })
10124
10076
  ]);
10125
10077
  function buildOpenAILiveSessionConfig(config, modelId, transport = "websocket") {
10126
- var _a2, _b, _c, _d, _e, _f;
10127
10078
  for (const key of Object.keys(config)) {
10128
10079
  if (![
10129
10080
  "instructions",
@@ -10137,13 +10088,13 @@ function buildOpenAILiveSessionConfig(config, modelId, transport = "websocket")
10137
10088
  });
10138
10089
  }
10139
10090
  }
10140
- if (z30.object({ delegation: z30.object({ type: z30.literal("responses") }) }).safeParse((_a2 = config.providerOptions) == null ? void 0 : _a2.openai).success) {
10091
+ if (z30.object({ delegation: z30.object({ type: z30.literal("responses") }) }).safeParse(config.providerOptions?.openai).success) {
10141
10092
  throw new UnsupportedFunctionalityError9({
10142
10093
  functionality: "OpenAI Live Responses delegation; only client delegation is supported"
10143
10094
  });
10144
10095
  }
10145
10096
  const options = openaiRealtimeModelLiveOptionsSchema.parse(
10146
- (_c = (_b = config.providerOptions) == null ? void 0 : _b.openai) != null ? _c : {}
10097
+ config.providerOptions?.openai ?? {}
10147
10098
  );
10148
10099
  if (options.client !== void 0 && transport !== "webrtc") {
10149
10100
  throw new UnsupportedFunctionalityError9({
@@ -10174,9 +10125,9 @@ function buildOpenAILiveSessionConfig(config, modelId, transport = "websocket")
10174
10125
  ...config.instructions !== void 0 ? { instructions: config.instructions } : {},
10175
10126
  audio: {
10176
10127
  ...transport === "websocket" ? {
10177
- format: (_d = inputFormat != null ? inputFormat : outputFormat) != null ? _d : { type: "audio/pcm", rate: 24e3 }
10128
+ format: inputFormat ?? outputFormat ?? { type: "audio/pcm", rate: 24e3 }
10178
10129
  } : {},
10179
- output: { voice: (_f = (_e = options.voice) != null ? _e : config.voice) != null ? _f : "marin" }
10130
+ output: { voice: options.voice ?? config.voice ?? "marin" }
10180
10131
  },
10181
10132
  ...options.delegation !== void 0 ? { delegation: options.delegation } : {},
10182
10133
  ...options.client !== void 0 ? {
@@ -10300,7 +10251,6 @@ function parseOpenAILiveServerEvent(raw) {
10300
10251
  return [parseServerEvent(raw)];
10301
10252
  }
10302
10253
  function parseServerEvent(raw) {
10303
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
10304
10254
  const envelope = envelopeSchema.safeParse(raw);
10305
10255
  if (envelope.success && !knownTypes.has(envelope.data.type)) {
10306
10256
  return { type: "custom", rawType: envelope.data.type, raw };
@@ -10328,13 +10278,13 @@ function parseServerEvent(raw) {
10328
10278
  return {
10329
10279
  type: "session-started",
10330
10280
  sessionId: event.session.id,
10331
- delegationMode: ((_a2 = event.session.delegation) == null ? void 0 : _a2.type) === "responses" ? "provider" : "client",
10281
+ delegationMode: event.session.delegation?.type === "responses" ? "provider" : "client",
10332
10282
  raw
10333
10283
  };
10334
10284
  case "session.closed":
10335
10285
  return {
10336
10286
  type: "session-closed",
10337
- sessionId: (_b = event.session) == null ? void 0 : _b.id,
10287
+ sessionId: event.session?.id,
10338
10288
  usage: event.usage,
10339
10289
  reason: event.reason,
10340
10290
  raw
@@ -10343,7 +10293,7 @@ function parseServerEvent(raw) {
10343
10293
  return {
10344
10294
  type: "session-usage",
10345
10295
  usage: event.usage,
10346
- contextWindowUsageRatio: (_c = event.context_window) == null ? void 0 : _c.usage_ratio,
10296
+ contextWindowUsageRatio: event.context_window?.usage_ratio,
10347
10297
  raw
10348
10298
  };
10349
10299
  case "session.output_audio.delta":
@@ -10362,8 +10312,8 @@ function parseServerEvent(raw) {
10362
10312
  return {
10363
10313
  type: "delegation-created",
10364
10314
  delegationId: event.delegation.id,
10365
- target: event.delegation.target === "responses" ? "provider" : (_d = event.delegation.target) != null ? _d : void 0,
10366
- offsetMs: (_e = event.offset_ms) != null ? _e : void 0,
10315
+ target: event.delegation.target === "responses" ? "provider" : event.delegation.target ?? void 0,
10316
+ offsetMs: event.offset_ms ?? void 0,
10367
10317
  ...event.delegation.response_id != null ? { responseId: event.delegation.response_id } : {},
10368
10318
  raw
10369
10319
  };
@@ -10371,15 +10321,15 @@ function parseServerEvent(raw) {
10371
10321
  return {
10372
10322
  type: "error",
10373
10323
  message: event.error.message,
10374
- code: (_f = event.error.code) != null ? _f : void 0,
10375
- clientEventId: (_g = event.error.client_event_id) != null ? _g : void 0,
10324
+ code: event.error.code ?? void 0,
10325
+ clientEventId: event.error.client_event_id ?? void 0,
10376
10326
  raw
10377
10327
  };
10378
10328
  case "session.updated":
10379
10329
  return {
10380
10330
  type: "command-acknowledged",
10381
10331
  command: "session.update",
10382
- clientEventId: (_h = event.client_event_id) != null ? _h : void 0,
10332
+ clientEventId: event.client_event_id ?? void 0,
10383
10333
  raw
10384
10334
  };
10385
10335
  case "session.input_audio.muted":
@@ -10387,7 +10337,7 @@ function parseServerEvent(raw) {
10387
10337
  return {
10388
10338
  type: "command-acknowledged",
10389
10339
  command: event.type.slice(0, -1),
10390
- clientEventId: (_i = event.client_event_id) != null ? _i : void 0,
10340
+ clientEventId: event.client_event_id ?? void 0,
10391
10341
  raw
10392
10342
  };
10393
10343
  case "session.instructions.appended":
@@ -10396,13 +10346,12 @@ function parseServerEvent(raw) {
10396
10346
  return {
10397
10347
  type: "command-acknowledged",
10398
10348
  command: event.type.slice(0, -2),
10399
- clientEventId: (_j = event.client_event_id) != null ? _j : void 0,
10349
+ clientEventId: event.client_event_id ?? void 0,
10400
10350
  raw
10401
10351
  };
10402
10352
  }
10403
10353
  }
10404
10354
  function serializeOpenAILiveClientEvent(event, modelId) {
10405
- var _a2, _b, _c;
10406
10355
  const eventId = "eventId" in event && event.eventId !== void 0 ? { event_id: event.eventId } : {};
10407
10356
  switch (event.type) {
10408
10357
  case "session-start":
@@ -10434,9 +10383,9 @@ function serializeOpenAILiveClientEvent(event, modelId) {
10434
10383
  }).parse(event);
10435
10384
  const options = z31.strictObject({
10436
10385
  channel: z31.enum(["instructions", "thinking", "commentary"]).optional()
10437
- }).parse((_b = (_a2 = event.providerOptions) == null ? void 0 : _a2.openai) != null ? _b : {});
10386
+ }).parse(event.providerOptions?.openai ?? {});
10438
10387
  return {
10439
- type: `session.${(_c = options.channel) != null ? _c : "thinking"}.append`,
10388
+ type: `session.${options.channel ?? "thinking"}.append`,
10440
10389
  content: context.content,
10441
10390
  delegation_id: context.delegationId,
10442
10391
  ...eventId
@@ -10522,7 +10471,6 @@ var OpenAIRealtimeModelLive = class {
10522
10471
 
10523
10472
  // src/realtime/openai-realtime-event-mapper.ts
10524
10473
  function parseOpenAIRealtimeServerEvent(raw) {
10525
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
10526
10474
  const event = raw;
10527
10475
  const type = event.type;
10528
10476
  switch (type) {
@@ -10530,7 +10478,7 @@ function parseOpenAIRealtimeServerEvent(raw) {
10530
10478
  case "session.created":
10531
10479
  return {
10532
10480
  type: "session-created",
10533
- sessionId: (_a2 = event.session) == null ? void 0 : _a2.id,
10481
+ sessionId: event.session?.id,
10534
10482
  raw
10535
10483
  };
10536
10484
  case "session.updated":
@@ -10559,7 +10507,7 @@ function parseOpenAIRealtimeServerEvent(raw) {
10559
10507
  case "conversation.item.added":
10560
10508
  return {
10561
10509
  type: "conversation-item-added",
10562
- itemId: (_c = (_b = event.item) == null ? void 0 : _b.id) != null ? _c : event.item_id,
10510
+ itemId: event.item?.id ?? event.item_id,
10563
10511
  item: event.item,
10564
10512
  raw
10565
10513
  };
@@ -10567,21 +10515,21 @@ function parseOpenAIRealtimeServerEvent(raw) {
10567
10515
  return {
10568
10516
  type: "input-transcription-completed",
10569
10517
  itemId: event.item_id,
10570
- transcript: (_d = event.transcript) != null ? _d : "",
10518
+ transcript: event.transcript ?? "",
10571
10519
  raw
10572
10520
  };
10573
10521
  // ── Response lifecycle ──────────────────────────────────────────
10574
10522
  case "response.created":
10575
10523
  return {
10576
10524
  type: "response-created",
10577
- responseId: (_f = (_e = event.response) == null ? void 0 : _e.id) != null ? _f : event.response_id,
10525
+ responseId: event.response?.id ?? event.response_id,
10578
10526
  raw
10579
10527
  };
10580
10528
  case "response.done":
10581
10529
  return {
10582
10530
  type: "response-done",
10583
- responseId: (_h = (_g = event.response) == null ? void 0 : _g.id) != null ? _h : event.response_id,
10584
- status: (_j = (_i = event.response) == null ? void 0 : _i.status) != null ? _j : "completed",
10531
+ responseId: event.response?.id ?? event.response_id,
10532
+ status: event.response?.status ?? "completed",
10585
10533
  raw
10586
10534
  };
10587
10535
  // ── Output item lifecycle ───────────────────────────────────────
@@ -10589,14 +10537,14 @@ function parseOpenAIRealtimeServerEvent(raw) {
10589
10537
  return {
10590
10538
  type: "output-item-added",
10591
10539
  responseId: event.response_id,
10592
- itemId: (_l = (_k = event.item) == null ? void 0 : _k.id) != null ? _l : event.item_id,
10540
+ itemId: event.item?.id ?? event.item_id,
10593
10541
  raw
10594
10542
  };
10595
10543
  case "response.output_item.done":
10596
10544
  return {
10597
10545
  type: "output-item-done",
10598
10546
  responseId: event.response_id,
10599
- itemId: (_n = (_m = event.item) == null ? void 0 : _m.id) != null ? _n : event.item_id,
10547
+ itemId: event.item?.id ?? event.item_id,
10600
10548
  raw
10601
10549
  };
10602
10550
  case "response.content_part.added":
@@ -10687,9 +10635,9 @@ function parseOpenAIRealtimeServerEvent(raw) {
10687
10635
  case "error":
10688
10636
  return {
10689
10637
  type: "error",
10690
- message: (_q = (_p = (_o = event.error) == null ? void 0 : _o.message) != null ? _p : event.message) != null ? _q : "Unknown error",
10691
- code: (_s = (_r = event.error) == null ? void 0 : _r.code) != null ? _s : event.code,
10692
- clientEventId: (_u = (_t = event.error) == null ? void 0 : _t.event_id) != null ? _u : void 0,
10638
+ message: event.error?.message ?? event.message ?? "Unknown error",
10639
+ code: event.error?.code ?? event.code,
10640
+ clientEventId: event.error?.event_id ?? void 0,
10693
10641
  raw
10694
10642
  };
10695
10643
  // ── Pass-through ────────────────────────────────────────────────
@@ -10771,7 +10719,6 @@ function serializeOpenAIRealtimeClientEvent(event, modelId) {
10771
10719
  }
10772
10720
  }
10773
10721
  function buildOpenAISessionConfig(config, modelId) {
10774
- var _a2;
10775
10722
  const session = {
10776
10723
  type: "realtime",
10777
10724
  model: modelId
@@ -10812,7 +10759,7 @@ function buildOpenAISessionConfig(config, modelId) {
10812
10759
  }
10813
10760
  if (config.inputAudioTranscription != null) {
10814
10761
  input.transcription = {
10815
- model: (_a2 = config.inputAudioTranscription.model) != null ? _a2 : "gpt-realtime-whisper",
10762
+ model: config.inputAudioTranscription.model ?? "gpt-realtime-whisper",
10816
10763
  ...config.inputAudioTranscription.language != null ? { language: config.inputAudioTranscription.language } : {},
10817
10764
  ...config.inputAudioTranscription.prompt != null ? { prompt: config.inputAudioTranscription.prompt } : {}
10818
10765
  };
@@ -10859,8 +10806,7 @@ var OpenAIRealtimeModel = class {
10859
10806
  this.config = config;
10860
10807
  }
10861
10808
  async doCreateClientSecret(options) {
10862
- var _a2;
10863
- const fetchFn = (_a2 = this.config.fetch) != null ? _a2 : fetch;
10809
+ const fetchFn = this.config.fetch ?? fetch;
10864
10810
  const url = `${this.config.baseURL}/realtime/client_secrets`;
10865
10811
  const session = options.sessionConfig != null ? buildOpenAISessionConfig(options.sessionConfig, this.modelId) : { type: "realtime", model: this.modelId };
10866
10812
  const response = await fetchFn(url, {
@@ -11007,7 +10953,6 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
11007
10953
  language,
11008
10954
  providerOptions
11009
10955
  }) {
11010
- var _a2, _b;
11011
10956
  const warnings = [];
11012
10957
  const openAIOptions = await parseProviderOptions9({
11013
10958
  provider: "openai",
@@ -11035,8 +10980,8 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
11035
10980
  }
11036
10981
  if (openAIOptions) {
11037
10982
  const speechModelOptions = {
11038
- speed: (_a2 = openAIOptions.speed) != null ? _a2 : void 0,
11039
- instructions: (_b = openAIOptions.instructions) != null ? _b : void 0
10983
+ speed: openAIOptions.speed ?? void 0,
10984
+ instructions: openAIOptions.instructions ?? void 0
11040
10985
  };
11041
10986
  for (const key in speechModelOptions) {
11042
10987
  const value = speechModelOptions[key];
@@ -11058,8 +11003,7 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
11058
11003
  };
11059
11004
  }
11060
11005
  async doGenerate(options) {
11061
- var _a2, _b, _c, _d, _e;
11062
- const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
11006
+ const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
11063
11007
  const { requestBody, warnings } = await this.getArgs(options);
11064
11008
  const {
11065
11009
  value: audio,
@@ -11070,7 +11014,7 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
11070
11014
  path: "/audio/speech",
11071
11015
  modelId: this.modelId
11072
11016
  }),
11073
- headers: combineHeaders8((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), options.headers),
11017
+ headers: combineHeaders8(this.config.headers?.(), options.headers),
11074
11018
  body: requestBody,
11075
11019
  failedResponseHandler: openaiFailedResponseHandler,
11076
11020
  successfulResponseHandler: createBinaryResponseHandler(),
@@ -11308,7 +11252,6 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
11308
11252
  mediaType,
11309
11253
  providerOptions
11310
11254
  }) {
11311
- var _a2, _b;
11312
11255
  const warnings = [];
11313
11256
  const openAIOptions = await parseProviderOptions10({
11314
11257
  provider: "openai",
@@ -11328,7 +11271,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
11328
11271
  formData.append("response_format", "verbose_json");
11329
11272
  }
11330
11273
  const isDiarizationModel = this.modelId === "gpt-4o-transcribe-diarize";
11331
- const chunkingStrategy = (_a2 = openAIOptions == null ? void 0 : openAIOptions.chunkingStrategy) != null ? _a2 : isDiarizationModel ? "auto" : void 0;
11274
+ const chunkingStrategy = openAIOptions?.chunkingStrategy ?? (isDiarizationModel ? "auto" : void 0);
11332
11275
  if (openAIOptions) {
11333
11276
  const isGpt4oTranscribeModel = [
11334
11277
  "gpt-4o-transcribe",
@@ -11341,7 +11284,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
11341
11284
  // https://platform.openai.com/docs/api-reference/audio/createTranscription#audio_createtranscription-response_format
11342
11285
  // prefer verbose_json to get segments for models that support it
11343
11286
  ...this.modelId !== "whisper-1" && {
11344
- response_format: (_b = openAIOptions.responseFormat) != null ? _b : isDiarizationModel ? "diarized_json" : isGpt4oTranscribeModel ? "json" : "verbose_json"
11287
+ response_format: openAIOptions.responseFormat ?? (isDiarizationModel ? "diarized_json" : isGpt4oTranscribeModel ? "json" : "verbose_json")
11345
11288
  },
11346
11289
  temperature: openAIOptions.temperature,
11347
11290
  timestamp_granularities: openAIOptions.timestampGranularities
@@ -11383,13 +11326,12 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
11383
11326
  };
11384
11327
  }
11385
11328
  async doGenerate(options) {
11386
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
11387
11329
  if (isRealtimeTranscriptionModelId(this.modelId)) {
11388
11330
  throw new UnsupportedFunctionalityError12({
11389
11331
  functionality: `non-streaming transcription with ${this.modelId}`
11390
11332
  });
11391
11333
  }
11392
- const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
11334
+ const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
11393
11335
  const { formData, warnings } = await this.getArgs(options);
11394
11336
  const {
11395
11337
  value: response,
@@ -11400,7 +11342,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
11400
11342
  path: "/audio/transcriptions",
11401
11343
  modelId: this.modelId
11402
11344
  }),
11403
- headers: combineHeaders9((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), options.headers),
11345
+ headers: combineHeaders9(this.config.headers?.(), options.headers),
11404
11346
  formData,
11405
11347
  failedResponseHandler: openaiFailedResponseHandler,
11406
11348
  successfulResponseHandler: createJsonResponseHandler9(
@@ -11410,7 +11352,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
11410
11352
  fetch: this.config.fetch
11411
11353
  });
11412
11354
  const language = response.language != null && response.language in languageMap ? languageMap[response.language] : void 0;
11413
- const diarizedSegments = (_f = response.segments) == null ? void 0 : _f.flatMap(
11355
+ const diarizedSegments = response.segments?.flatMap(
11414
11356
  (segment) => "speaker" in segment ? [
11415
11357
  {
11416
11358
  text: segment.text,
@@ -11422,17 +11364,17 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
11422
11364
  );
11423
11365
  return {
11424
11366
  text: response.text,
11425
- segments: (_j = (_i = (_g = response.segments) == null ? void 0 : _g.map((segment) => ({
11367
+ segments: response.segments?.map((segment) => ({
11426
11368
  text: segment.text,
11427
11369
  startSecond: segment.start,
11428
11370
  endSecond: segment.end
11429
- }))) != null ? _i : (_h = response.words) == null ? void 0 : _h.map((word) => ({
11371
+ })) ?? response.words?.map((word) => ({
11430
11372
  text: word.word,
11431
11373
  startSecond: word.start,
11432
11374
  endSecond: word.end
11433
- }))) != null ? _j : [],
11375
+ })) ?? [],
11434
11376
  language,
11435
- durationInSeconds: (_k = response.duration) != null ? _k : void 0,
11377
+ durationInSeconds: response.duration ?? void 0,
11436
11378
  warnings,
11437
11379
  response: {
11438
11380
  timestamp: currentDate,
@@ -11450,20 +11392,19 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
11450
11392
  };
11451
11393
  }
11452
11394
  async doStream(options) {
11453
- var _a2, _b, _c, _d, _e, _f, _g;
11454
11395
  if (!isRealtimeTranscriptionModelId(this.modelId)) {
11455
11396
  throw new UnsupportedFunctionalityError12({
11456
11397
  functionality: `streaming transcription with ${this.modelId}`
11457
11398
  });
11458
11399
  }
11459
- const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
11400
+ const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
11460
11401
  const openAIOptions = await parseProviderOptions10({
11461
11402
  provider: "openai",
11462
11403
  providerOptions: options.providerOptions,
11463
11404
  schema: openAITranscriptionModelOptions
11464
11405
  });
11465
11406
  const warnings = [];
11466
- const rawOpenAIOptions = (_e = (_d = options.providerOptions) == null ? void 0 : _d.openai) != null ? _e : {};
11407
+ const rawOpenAIOptions = options.providerOptions?.openai ?? {};
11467
11408
  for (const option of [
11468
11409
  "include",
11469
11410
  "prompt",
@@ -11478,7 +11419,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
11478
11419
  });
11479
11420
  }
11480
11421
  }
11481
- const headers = combineHeaders9((_g = (_f = this.config).headers) == null ? void 0 : _g.call(_f), options.headers);
11422
+ const headers = combineHeaders9(this.config.headers?.(), options.headers);
11482
11423
  const sessionUpdate = buildOpenAIRealtimeTranscriptionSession({
11483
11424
  modelId: this.modelId,
11484
11425
  inputAudioFormat: options.inputAudioFormat,
@@ -11500,7 +11441,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
11500
11441
  ),
11501
11442
  headers,
11502
11443
  sessionUpdate,
11503
- language: openAIOptions == null ? void 0 : openAIOptions.language,
11444
+ language: openAIOptions?.language,
11504
11445
  warnings,
11505
11446
  audio: options.audio,
11506
11447
  abortSignal: options.abortSignal,
@@ -11536,7 +11477,7 @@ function createOpenAIRealtimeTranscriptionStream({
11536
11477
  void audio.cancel().catch(() => {
11537
11478
  });
11538
11479
  }
11539
- connection == null ? void 0 : connection.close(closeCode);
11480
+ connection?.close(closeCode);
11540
11481
  };
11541
11482
  const finishWithError = (error) => {
11542
11483
  if (finished) return;
@@ -11595,7 +11536,6 @@ function createOpenAIRealtimeTranscriptionStream({
11595
11536
  void sendAudio(socket).catch(finishWithError);
11596
11537
  },
11597
11538
  onMessageText: async (text) => {
11598
- var _a2, _b, _c, _d;
11599
11539
  const parsed = await safeParseJSON2({ text });
11600
11540
  if (!parsed.success) return;
11601
11541
  const raw = parsed.value;
@@ -11607,17 +11547,17 @@ function createOpenAIRealtimeTranscriptionStream({
11607
11547
  controller.enqueue({
11608
11548
  type: "transcript-delta",
11609
11549
  id: raw.item_id,
11610
- delta: (_a2 = raw.delta) != null ? _a2 : ""
11550
+ delta: raw.delta ?? ""
11611
11551
  });
11612
11552
  break;
11613
11553
  }
11614
11554
  case "conversation.item.input_audio_transcription.completed": {
11615
- finish((_b = raw.transcript) != null ? _b : "", raw.item_id);
11555
+ finish(raw.transcript ?? "", raw.item_id);
11616
11556
  break;
11617
11557
  }
11618
11558
  case "error": {
11619
11559
  finishWithError(
11620
- new Error((_d = (_c = raw.error) == null ? void 0 : _c.message) != null ? _d : "OpenAI realtime error")
11560
+ new Error(raw.error?.message ?? "OpenAI realtime error")
11621
11561
  );
11622
11562
  break;
11623
11563
  }
@@ -11646,7 +11586,6 @@ function buildOpenAIRealtimeTranscriptionSession({
11646
11586
  inputAudioFormat,
11647
11587
  providerOptions
11648
11588
  }) {
11649
- var _a2, _b;
11650
11589
  return {
11651
11590
  type: "session.update",
11652
11591
  session: {
@@ -11659,25 +11598,24 @@ function buildOpenAIRealtimeTranscriptionSession({
11659
11598
  },
11660
11599
  transcription: {
11661
11600
  model: modelId,
11662
- ...(providerOptions == null ? void 0 : providerOptions.language) != null ? { language: providerOptions.language } : {},
11663
- ...((_a2 = providerOptions == null ? void 0 : providerOptions.streaming) == null ? void 0 : _a2.delay) != null ? { delay: providerOptions.streaming.delay } : {}
11601
+ ...providerOptions?.language != null ? { language: providerOptions.language } : {},
11602
+ ...providerOptions?.streaming?.delay != null ? { delay: providerOptions.streaming.delay } : {}
11664
11603
  },
11665
11604
  turn_detection: null
11666
11605
  }
11667
11606
  },
11668
- ...((_b = providerOptions == null ? void 0 : providerOptions.streaming) == null ? void 0 : _b.include) != null ? { include: providerOptions.streaming.include } : {}
11607
+ ...providerOptions?.streaming?.include != null ? { include: providerOptions.streaming.include } : {}
11669
11608
  }
11670
11609
  };
11671
11610
  }
11672
11611
  function getOpenAIRealtimeConnection(headers) {
11673
- var _a2;
11674
11612
  let authorization;
11675
11613
  for (const [key, value] of Object.entries(headers)) {
11676
11614
  if (key.toLowerCase() === "authorization" && value != null) {
11677
11615
  authorization = value;
11678
11616
  }
11679
11617
  }
11680
- const token = (_a2 = authorization == null ? void 0 : authorization.match(/^bearer\s+(.+)$/i)) == null ? void 0 : _a2[1];
11618
+ const token = authorization?.match(/^bearer\s+(.+)$/i)?.[1];
11681
11619
  if (token == null) {
11682
11620
  return { protocols: ["realtime"], headers };
11683
11621
  }
@@ -11738,14 +11676,13 @@ var OpenAISpeechTranslationModel = class _OpenAISpeechTranslationModel {
11738
11676
  return this.config.provider;
11739
11677
  }
11740
11678
  async doStream(options) {
11741
- var _a2, _b, _c, _d, _e;
11742
11679
  if (options.targetLanguage == null) {
11743
11680
  throw new InvalidArgumentError5({
11744
11681
  argument: "targetLanguage",
11745
11682
  message: `targetLanguage is required for translation model '${this.modelId}'.`
11746
11683
  });
11747
11684
  }
11748
- const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
11685
+ const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
11749
11686
  await parseProviderOptions11({
11750
11687
  provider: "openai",
11751
11688
  providerOptions: options.providerOptions,
@@ -11767,7 +11704,7 @@ var OpenAISpeechTranslationModel = class _OpenAISpeechTranslationModel {
11767
11704
  details: "The OpenAI Realtime translation API always outputs 24kHz 16-bit PCM audio and does not accept an output audio format."
11768
11705
  });
11769
11706
  }
11770
- const headers = combineHeaders10((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), options.headers);
11707
+ const headers = combineHeaders10(this.config.headers?.(), options.headers);
11771
11708
  const sessionUpdate = buildOpenAIRealtimeSpeechTranslationSession({
11772
11709
  targetLanguage: options.targetLanguage
11773
11710
  });
@@ -11823,7 +11760,7 @@ function createOpenAIRealtimeSpeechTranslationStream({
11823
11760
  void audio.cancel().catch(() => {
11824
11761
  });
11825
11762
  }
11826
- connection == null ? void 0 : connection.close(closeCode);
11763
+ connection?.close(closeCode);
11827
11764
  };
11828
11765
  const finishWithError = (error) => {
11829
11766
  if (finished) return;
@@ -11891,7 +11828,6 @@ function createOpenAIRealtimeSpeechTranslationStream({
11891
11828
  void sendAudio(socket).catch(finishWithError);
11892
11829
  },
11893
11830
  onMessageText: async (text) => {
11894
- var _a2, _b, _c, _d, _e, _f;
11895
11831
  if (finished) return;
11896
11832
  const parsed = await safeParseJSON3({ text });
11897
11833
  if (!parsed.success) return;
@@ -11910,18 +11846,18 @@ function createOpenAIRealtimeSpeechTranslationStream({
11910
11846
  break;
11911
11847
  }
11912
11848
  case "session.output_transcript.delta": {
11913
- translationText += (_a2 = raw.delta) != null ? _a2 : "";
11849
+ translationText += raw.delta ?? "";
11914
11850
  controller.enqueue({
11915
11851
  type: "output-text-delta",
11916
- delta: (_b = raw.delta) != null ? _b : ""
11852
+ delta: raw.delta ?? ""
11917
11853
  });
11918
11854
  break;
11919
11855
  }
11920
11856
  case "session.input_transcript.delta": {
11921
- sourceText += (_c = raw.delta) != null ? _c : "";
11857
+ sourceText += raw.delta ?? "";
11922
11858
  controller.enqueue({
11923
11859
  type: "source-transcript-delta",
11924
- delta: (_d = raw.delta) != null ? _d : ""
11860
+ delta: raw.delta ?? ""
11925
11861
  });
11926
11862
  break;
11927
11863
  }
@@ -11932,7 +11868,7 @@ function createOpenAIRealtimeSpeechTranslationStream({
11932
11868
  case "error": {
11933
11869
  controller.enqueue({
11934
11870
  type: "error",
11935
- error: new Error((_f = (_e = raw.error) == null ? void 0 : _e.message) != null ? _f : "OpenAI realtime error")
11871
+ error: new Error(raw.error?.message ?? "OpenAI realtime error")
11936
11872
  });
11937
11873
  break;
11938
11874
  }
@@ -11945,7 +11881,7 @@ function createOpenAIRealtimeSpeechTranslationStream({
11945
11881
  if (finished) return;
11946
11882
  finishWithError(
11947
11883
  new Error(
11948
- `OpenAI realtime translation WebSocket closed unexpectedly before finishing (code ${code != null ? code : "unknown"}${reason ? `, reason: ${reason}` : ""}).`
11884
+ `OpenAI realtime translation WebSocket closed unexpectedly before finishing (code ${code ?? "unknown"}${reason ? `, reason: ${reason}` : ""}).`
11949
11885
  )
11950
11886
  );
11951
11887
  }
@@ -11987,14 +11923,13 @@ function validateOpenAISpeechTranslationInputAudioFormat(inputAudioFormat) {
11987
11923
  }
11988
11924
  }
11989
11925
  function getOpenAIRealtimeConnection2(headers) {
11990
- var _a2;
11991
11926
  let authorization;
11992
11927
  for (const [key, value] of Object.entries(headers)) {
11993
11928
  if (key.toLowerCase() === "authorization" && value != null) {
11994
11929
  authorization = value;
11995
11930
  }
11996
11931
  }
11997
- const token = (_a2 = authorization == null ? void 0 : authorization.match(/^bearer\s+(.+)$/i)) == null ? void 0 : _a2[1];
11932
+ const token = authorization?.match(/^bearer\s+(.+)$/i)?.[1];
11998
11933
  if (token == null) {
11999
11934
  return { protocols: ["realtime"], headers };
12000
11935
  }
@@ -12093,20 +12028,19 @@ var OpenAISkills = class {
12093
12028
  };
12094
12029
 
12095
12030
  // src/version.ts
12096
- var VERSION = true ? "4.0.75" : "0.0.0-test";
12031
+ var VERSION = true ? "4.0.78" : "0.0.0-test";
12097
12032
 
12098
12033
  // src/openai-provider.ts
12099
12034
  function createOpenAI(options = {}) {
12100
- var _a2, _b;
12101
- const baseURL = (_a2 = withoutTrailingSlash(
12035
+ const baseURL = withoutTrailingSlash(
12102
12036
  validateBaseURL(
12103
12037
  loadOptionalSetting({
12104
12038
  settingValue: options.baseURL,
12105
12039
  environmentVariableName: "OPENAI_BASE_URL"
12106
12040
  })
12107
12041
  )
12108
- )) != null ? _a2 : "https://api.openai.com/v1";
12109
- const providerName = (_b = options.name) != null ? _b : "openai";
12042
+ ) ?? "https://api.openai.com/v1";
12043
+ const providerName = options.name ?? "openai";
12110
12044
  const getHeaders = () => withUserAgentSuffix(
12111
12045
  {
12112
12046
  Authorization: `Bearer ${loadApiKey({