@ai-sdk/open-responses 2.0.52 → 2.0.54

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
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var VERSION = true ? "2.0.52" : "0.0.0-test";
2
+ var VERSION = true ? "2.0.54" : "0.0.0-test";
3
3
 
4
4
  // src/open-responses-provider.ts
5
5
  import {
@@ -19,7 +19,7 @@ function createOpenResponsesExtensionRegistry(extensions) {
19
19
  byProviderToolId: /* @__PURE__ */ new Map(),
20
20
  byToolType: /* @__PURE__ */ new Map()
21
21
  };
22
- for (const extension of extensions != null ? extensions : []) {
22
+ for (const extension of extensions ?? []) {
23
23
  const namespaceSeparatorIndex = extension.id.indexOf(".");
24
24
  if (namespaceSeparatorIndex <= 0) {
25
25
  throw new Error(
@@ -251,7 +251,6 @@ async function convertToOpenResponsesInput({
251
251
  strictResponseInput = false,
252
252
  customToolId
253
253
  }) {
254
- var _a, _b, _c, _d;
255
254
  const input = [];
256
255
  const warnings = [];
257
256
  const systemMessages = [];
@@ -302,7 +301,7 @@ async function convertToOpenResponsesInput({
302
301
  const fullMediaType = resolveFullMediaType({ part });
303
302
  userContent.push({
304
303
  type: "input_file",
305
- filename: (_a = part.filename) != null ? _a : "data",
304
+ filename: part.filename ?? "data",
306
305
  file_data: `data:${fullMediaType};base64,${convertToBase64(part.data.data)}`
307
306
  });
308
307
  }
@@ -338,14 +337,11 @@ async function convertToOpenResponsesInput({
338
337
  status: "completed",
339
338
  role: "assistant",
340
339
  content: assistantContent.map(
341
- (part) => {
342
- var _a2, _b2;
343
- return part.type === "output_text" ? {
344
- ...part,
345
- annotations: (_a2 = part.annotations) != null ? _a2 : [],
346
- logprobs: (_b2 = part.logprobs) != null ? _b2 : []
347
- } : part;
348
- }
340
+ (part) => part.type === "output_text" ? {
341
+ ...part,
342
+ annotations: part.annotations ?? [],
343
+ logprobs: part.logprobs ?? []
344
+ } : part
349
345
  )
350
346
  });
351
347
  } else {
@@ -379,7 +375,7 @@ async function convertToOpenResponsesInput({
379
375
  }
380
376
  if (part.type === "tool-call" || part.type === "tool-result") {
381
377
  const providerTool = providerToolsByName.get(part.toolName);
382
- const extension = providerTool == null ? void 0 : extensionRegistry == null ? void 0 : extensionRegistry.byProviderToolId.get(providerTool.id);
378
+ const extension = providerTool == null ? void 0 : extensionRegistry?.byProviderToolId.get(providerTool.id);
383
379
  if (providerTool != null && extension != null) {
384
380
  flushAssistantContent();
385
381
  const encoded = await encodeExtensionInputPart({
@@ -402,18 +398,18 @@ async function convertToOpenResponsesInput({
402
398
  case "reasoning": {
403
399
  flushAssistantContent();
404
400
  const providerData = getProviderData(part, providerOptionsName);
405
- const itemId = typeof (providerData == null ? void 0 : providerData.itemId) === "string" ? providerData.itemId : void 0;
401
+ const itemId = typeof providerData?.itemId === "string" ? providerData.itemId : void 0;
406
402
  const summary = parseReasoningSummary(
407
- providerData == null ? void 0 : providerData.reasoningSummary
403
+ providerData?.reasoningSummary
408
404
  );
409
405
  const reasoningContent = parseReasoningContent(
410
- providerData == null ? void 0 : providerData.reasoningContent
406
+ providerData?.reasoningContent
411
407
  );
412
408
  const hasReasoningContent = providerData != null && "reasoningContent" in providerData;
413
- const encryptedContent = typeof (providerData == null ? void 0 : providerData.reasoningEncryptedContent) === "string" ? providerData.reasoningEncryptedContent : void 0;
409
+ const encryptedContent = typeof providerData?.reasoningEncryptedContent === "string" ? providerData.reasoningEncryptedContent : void 0;
414
410
  const reasoningItem = {
415
411
  type: "reasoning",
416
- summary: summary != null ? summary : [],
412
+ summary: summary ?? [],
417
413
  ...itemId != null && { id: itemId },
418
414
  ...reasoningContent != null ? { content: reasoningContent } : !hasReasoningContent && part.text.length > 0 ? {
419
415
  content: [
@@ -428,10 +424,10 @@ async function convertToOpenResponsesInput({
428
424
  }
429
425
  };
430
426
  const previousItem = input[input.length - 1];
431
- if (reasoningItem.id != null && (previousItem == null ? void 0 : previousItem.type) === "reasoning" && previousItem.id === reasoningItem.id) {
427
+ if (reasoningItem.id != null && previousItem?.type === "reasoning" && previousItem.id === reasoningItem.id) {
432
428
  if (reasoningItem.content != null) {
433
429
  previousItem.content = [
434
- ...(_b = previousItem.content) != null ? _b : [],
430
+ ...previousItem.content ?? [],
435
431
  ...reasoningItem.content
436
432
  ];
437
433
  }
@@ -442,9 +438,9 @@ async function convertToOpenResponsesInput({
442
438
  }
443
439
  case "text": {
444
440
  const providerData = getProviderData(part, providerOptionsName);
445
- const itemId = typeof (providerData == null ? void 0 : providerData.itemId) === "string" ? providerData.itemId : void 0;
441
+ const itemId = typeof providerData?.itemId === "string" ? providerData.itemId : void 0;
446
442
  const annotations = parseOutputTextAnnotations(
447
- providerData == null ? void 0 : providerData.annotations
443
+ providerData?.annotations
448
444
  );
449
445
  if (assistantContent.length > 0 && assistantMessageId !== itemId) {
450
446
  flushAssistantContent();
@@ -461,9 +457,9 @@ async function convertToOpenResponsesInput({
461
457
  flushAssistantContent();
462
458
  const argumentsValue = typeof part.input === "string" ? part.input : JSON.stringify(part.input);
463
459
  const providerData = getProviderData(part, providerOptionsName);
464
- const itemId = typeof (providerData == null ? void 0 : providerData.itemId) === "string" ? providerData.itemId : void 0;
460
+ const itemId = typeof providerData?.itemId === "string" ? providerData.itemId : void 0;
465
461
  const providerTool = providerToolsByName.get(part.toolName);
466
- if (customToolId != null && (providerTool == null ? void 0 : providerTool.id) === customToolId) {
462
+ if (customToolId != null && providerTool?.id === customToolId) {
467
463
  input.push({
468
464
  type: "custom_tool_call",
469
465
  ...itemId != null && { id: itemId },
@@ -507,7 +503,7 @@ async function convertToOpenResponsesInput({
507
503
  continue;
508
504
  }
509
505
  const providerTool = providerToolsByName.get(part.toolName);
510
- const extension = providerTool == null ? void 0 : extensionRegistry == null ? void 0 : extensionRegistry.byProviderToolId.get(providerTool.id);
506
+ const extension = providerTool == null ? void 0 : extensionRegistry?.byProviderToolId.get(providerTool.id);
511
507
  if (providerTool != null && extension != null) {
512
508
  const encoded = await encodeExtensionInputPart({
513
509
  extensionRegistry,
@@ -532,7 +528,7 @@ async function convertToOpenResponsesInput({
532
528
  contentValue = output.value;
533
529
  break;
534
530
  case "execution-denied":
535
- contentValue = (_c = output.reason) != null ? _c : "Tool call execution denied.";
531
+ contentValue = output.reason ?? "Tool call execution denied.";
536
532
  break;
537
533
  case "json":
538
534
  case "error-json":
@@ -564,7 +560,7 @@ async function convertToOpenResponsesInput({
564
560
  } else {
565
561
  contentParts.push({
566
562
  type: "input_file",
567
- filename: (_d = item.filename) != null ? _d : "data",
563
+ filename: item.filename ?? "data",
568
564
  file_data: `data:${fullMediaType};base64,${convertToBase64(item.data.data)}`
569
565
  });
570
566
  }
@@ -603,7 +599,7 @@ async function convertToOpenResponsesInput({
603
599
  }
604
600
  }
605
601
  input.push({
606
- type: customToolId != null && (providerTool == null ? void 0 : providerTool.id) === customToolId ? "custom_tool_call_output" : "function_call_output",
602
+ type: customToolId != null && providerTool?.id === customToolId ? "custom_tool_call_output" : "function_call_output",
607
603
  call_id: part.toolCallId,
608
604
  output: contentValue
609
605
  });
@@ -624,9 +620,9 @@ async function encodeExtensionInputPart({
624
620
  part,
625
621
  providerTool
626
622
  }) {
627
- const extension = extensionRegistry == null ? void 0 : extensionRegistry.byProviderToolId.get(providerTool.id);
628
- const encodeInputItem = extension == null ? void 0 : extension.encodeInputItem;
629
- const itemTypes = extension == null ? void 0 : extension.itemTypes;
623
+ const extension = extensionRegistry?.byProviderToolId.get(providerTool.id);
624
+ const encodeInputItem = extension?.encodeInputItem;
625
+ const itemTypes = extension?.itemTypes;
630
626
  if (encodeInputItem == null || itemTypes == null) {
631
627
  return void 0;
632
628
  }
@@ -642,7 +638,7 @@ async function encodeExtensionInputPart({
642
638
  return void 0;
643
639
  }
644
640
  return items;
645
- } catch (e) {
641
+ } catch {
646
642
  return void 0;
647
643
  }
648
644
  }
@@ -651,11 +647,10 @@ function getExtensionReplay({
651
647
  providerOptionsName,
652
648
  extensionRegistry
653
649
  }) {
654
- var _a, _b;
655
- const extensionData = (_a = getProviderData(
650
+ const extensionData = getProviderData(
656
651
  part,
657
652
  providerOptionsName
658
- )) == null ? void 0 : _a.openResponsesExtension;
653
+ )?.openResponsesExtension;
659
654
  if (extensionData == null || typeof extensionData !== "object" || Array.isArray(extensionData)) {
660
655
  return void 0;
661
656
  }
@@ -663,25 +658,23 @@ function getExtensionReplay({
663
658
  if (typeof id !== "string") {
664
659
  return void 0;
665
660
  }
666
- const extension = extensionRegistry == null ? void 0 : extensionRegistry.byExtensionId.get(
661
+ const extension = extensionRegistry?.byExtensionId.get(
667
662
  id
668
663
  );
669
664
  if (extension == null) {
670
665
  return void 0;
671
666
  }
672
- if (isOpenResponsesExtensionItem(item) && ((_b = extension.itemTypes) == null ? void 0 : _b.includes(item.type))) {
667
+ if (isOpenResponsesExtensionItem(item) && extension.itemTypes?.includes(item.type)) {
673
668
  return { item };
674
669
  }
675
670
  return typeof itemId === "string" ? {} : void 0;
676
671
  }
677
672
  function getProviderData(part, providerOptionsName) {
678
- var _a, _b, _c;
679
- const providerData = (_c = (_a = part.providerOptions) == null ? void 0 : _a[providerOptionsName]) != null ? _c : (_b = part.providerMetadata) == null ? void 0 : _b[providerOptionsName];
673
+ const providerData = part.providerOptions?.[providerOptionsName] ?? part.providerMetadata?.[providerOptionsName];
680
674
  return providerData != null && typeof providerData === "object" && !Array.isArray(providerData) ? providerData : void 0;
681
675
  }
682
676
  function getImageDetail(part, providerOptionsName) {
683
- var _a;
684
- const imageDetail = (_a = getProviderData(part, providerOptionsName)) == null ? void 0 : _a.imageDetail;
677
+ const imageDetail = getProviderData(part, providerOptionsName)?.imageDetail;
685
678
  return imageDetail === "low" || imageDetail === "high" || imageDetail === "auto" ? imageDetail : "auto";
686
679
  }
687
680
  function parseReasoningSummary(value) {
@@ -789,10 +782,9 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
789
782
  this.supportedUrls = {
790
783
  "image/*": [/^https?:\/\/.*$/]
791
784
  };
792
- var _a;
793
785
  this.modelId = modelId;
794
786
  this.config = config;
795
- this.extensionRegistry = (_a = config.extensionRegistry) != null ? _a : createOpenResponsesExtensionRegistry();
787
+ this.extensionRegistry = config.extensionRegistry ?? createOpenResponsesExtensionRegistry();
796
788
  }
797
789
  static [WORKFLOW_SERIALIZE](model) {
798
790
  if (model.extensionRegistry.byExtensionId.size > 0) {
@@ -827,7 +819,6 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
827
819
  toolChoice,
828
820
  responseFormat
829
821
  }) {
830
- var _a, _b, _c;
831
822
  const warnings = [];
832
823
  if (stopSequences != null) {
833
824
  warnings.push({ type: "unsupported", feature: "stopSequences" });
@@ -839,7 +830,7 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
839
830
  warnings.push({ type: "unsupported", feature: "seed" });
840
831
  }
841
832
  const providerToolsByName = new Map(
842
- (tools != null ? tools : []).filter((tool) => tool.type === "provider").map((tool) => [tool.name, tool])
833
+ (tools ?? []).filter((tool) => tool.type === "provider").map((tool) => [tool.name, tool])
843
834
  );
844
835
  const {
845
836
  input,
@@ -856,7 +847,7 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
856
847
  warnings.push(...inputWarnings);
857
848
  const convertedTools = [];
858
849
  const encodedProviderToolsByName = /* @__PURE__ */ new Map();
859
- for (const tool of tools != null ? tools : []) {
850
+ for (const tool of tools ?? []) {
860
851
  if (tool.type === "provider") {
861
852
  if (this.config.customToolId != null && tool.id === this.config.customToolId) {
862
853
  const format = tool.args.format != null && typeof tool.args.format === "object" && !Array.isArray(tool.args.format) ? tool.args.format : void 0;
@@ -886,7 +877,7 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
886
877
  type: extension.toolType
887
878
  };
888
879
  }
889
- } catch (e) {
880
+ } catch {
890
881
  }
891
882
  }
892
883
  if (encoded == null) {
@@ -913,12 +904,12 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
913
904
  }
914
905
  }
915
906
  let convertedToolChoice;
916
- if ((toolChoice == null ? void 0 : toolChoice.type) === "tool") {
907
+ if (toolChoice?.type === "tool") {
917
908
  const registeredTool = encodedProviderToolsByName.get(
918
909
  toolChoice.toolName
919
910
  );
920
911
  if (registeredTool == null) {
921
- if (this.config.customToolId != null && ((_a = providerToolsByName.get(toolChoice.toolName)) == null ? void 0 : _a.id) === this.config.customToolId) {
912
+ if (this.config.customToolId != null && providerToolsByName.get(toolChoice.toolName)?.id === this.config.customToolId) {
922
913
  convertedToolChoice = {
923
914
  type: "custom",
924
915
  name: toolChoice.toolName
@@ -933,11 +924,11 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
933
924
  const { encodeToolChoice, tool, toolType } = registeredTool;
934
925
  let fields = {};
935
926
  try {
936
- fields = await (encodeToolChoice == null ? void 0 : encodeToolChoice({
927
+ fields = await encodeToolChoice?.({
937
928
  name: tool.name,
938
929
  args: tool.args
939
- }));
940
- } catch (e) {
930
+ });
931
+ } catch {
941
932
  fields = void 0;
942
933
  }
943
934
  if (encodeToolChoice != null && !isOpenResponsesJSONObject(fields)) {
@@ -953,16 +944,16 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
953
944
  }
954
945
  }
955
946
  } else {
956
- convertedToolChoice = toolChoice == null ? void 0 : toolChoice.type;
947
+ convertedToolChoice = toolChoice?.type;
957
948
  }
958
- const textFormat = (responseFormat == null ? void 0 : responseFormat.type) === "json" && this.config.structuredOutputs !== false ? responseFormat.schema != null ? {
949
+ const textFormat = responseFormat?.type === "json" && this.config.structuredOutputs !== false ? responseFormat.schema != null ? {
959
950
  type: "json_schema",
960
- name: (_b = responseFormat.name) != null ? _b : "response",
951
+ name: responseFormat.name ?? "response",
961
952
  description: responseFormat.description,
962
953
  schema: responseFormat.schema,
963
954
  strict: true
964
955
  } : { type: "json_object" } : void 0;
965
- if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && this.config.structuredOutputs === false) {
956
+ if (responseFormat?.type === "json" && this.config.structuredOutputs === false) {
966
957
  warnings.push({ type: "unsupported", feature: "responseFormat" });
967
958
  }
968
959
  const openResponsesOptions = await parseProviderOptions({
@@ -970,7 +961,7 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
970
961
  providerOptions,
971
962
  schema: openResponsesLanguageModelOptions
972
963
  });
973
- const resolvedReasoningEffort = (_c = openResponsesOptions == null ? void 0 : openResponsesOptions.reasoningEffort) != null ? _c : isCustomReasoning(reasoning) ? reasoning === "none" ? "none" : mapReasoningToProviderEffort({
964
+ const resolvedReasoningEffort = openResponsesOptions?.reasoningEffort ?? (isCustomReasoning(reasoning) ? reasoning === "none" ? "none" : mapReasoningToProviderEffort({
974
965
  reasoning,
975
966
  effortMap: {
976
967
  minimal: "low",
@@ -980,7 +971,7 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
980
971
  xhigh: "xhigh"
981
972
  },
982
973
  warnings
983
- }) : void 0;
974
+ }) : void 0);
984
975
  return {
985
976
  body: {
986
977
  model: this.modelId,
@@ -991,11 +982,11 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
991
982
  top_p: topP,
992
983
  presence_penalty: presencePenalty,
993
984
  frequency_penalty: frequencyPenalty,
994
- reasoning: resolvedReasoningEffort != null || (openResponsesOptions == null ? void 0 : openResponsesOptions.reasoningSummary) != null ? {
985
+ reasoning: resolvedReasoningEffort != null || openResponsesOptions?.reasoningSummary != null ? {
995
986
  ...resolvedReasoningEffort != null && {
996
987
  effort: resolvedReasoningEffort
997
988
  },
998
- ...(openResponsesOptions == null ? void 0 : openResponsesOptions.reasoningSummary) != null && {
989
+ ...openResponsesOptions?.reasoningSummary != null && {
999
990
  summary: openResponsesOptions.reasoningSummary
1000
991
  }
1001
992
  } : void 0,
@@ -1007,7 +998,6 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
1007
998
  };
1008
999
  }
1009
1000
  async doGenerate(options) {
1010
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1011
1001
  const { body, warnings } = await this.getArgs(options);
1012
1002
  const {
1013
1003
  responseHeaders,
@@ -1015,9 +1005,9 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
1015
1005
  rawValue: rawResponse
1016
1006
  } = await postJsonToApi({
1017
1007
  url: this.config.url,
1018
- headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
1008
+ headers: combineHeaders(this.config.headers?.(), options.headers),
1019
1009
  body,
1020
- failedResponseHandler: (_c = this.config.failedResponseHandler) != null ? _c : defaultFailedResponseHandler,
1010
+ failedResponseHandler: this.config.failedResponseHandler ?? defaultFailedResponseHandler,
1021
1011
  successfulResponseHandler: createJsonResponseHandler(
1022
1012
  // do not validate the response body, only apply types to the response body
1023
1013
  jsonSchema(() => {
@@ -1028,23 +1018,22 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
1028
1018
  fetch: this.config.fetch
1029
1019
  });
1030
1020
  if (response.error) {
1031
- const errorMetadata = (_e = (_d = this.config).getResponseErrorMetadata) == null ? void 0 : _e.call(
1032
- _d,
1021
+ const errorMetadata = this.config.getResponseErrorMetadata?.(
1033
1022
  response.error
1034
1023
  );
1035
1024
  throw new APICallError({
1036
1025
  message: response.error.message,
1037
1026
  url: this.config.url,
1038
1027
  requestBodyValues: body,
1039
- statusCode: (_f = errorMetadata == null ? void 0 : errorMetadata.statusCode) != null ? _f : 400,
1040
- isRetryable: errorMetadata == null ? void 0 : errorMetadata.isRetryable,
1028
+ statusCode: errorMetadata?.statusCode ?? 400,
1029
+ isRetryable: errorMetadata?.isRetryable,
1041
1030
  responseHeaders,
1042
1031
  responseBody: rawResponse,
1043
1032
  data: response.error
1044
1033
  });
1045
1034
  }
1046
1035
  if (response.output == null) {
1047
- const detail = (_h = (_g = response.incomplete_details) == null ? void 0 : _g.reason) != null ? _h : response.status;
1036
+ const detail = response.incomplete_details?.reason ?? response.status;
1048
1037
  throw new APICallError({
1049
1038
  message: detail ? `Responses API returned no output (${detail})` : "Responses API returned no output",
1050
1039
  url: this.config.url,
@@ -1061,7 +1050,7 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
1061
1050
  switch (part.type) {
1062
1051
  // TODO AI SDK 7 adjust reasoning in the specification to better support the reasoning structure from open responses.
1063
1052
  case "reasoning": {
1064
- if (((_j = (_i = part.content) == null ? void 0 : _i.length) != null ? _j : 0) > 0) {
1053
+ if ((part.content?.length ?? 0) > 0) {
1065
1054
  for (const contentPart of part.content) {
1066
1055
  content.push({
1067
1056
  type: "reasoning",
@@ -1139,37 +1128,37 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
1139
1128
  });
1140
1129
  if (decoded != null) {
1141
1130
  content.push(...decoded);
1142
- hasToolCalls || (hasToolCalls = decoded.some((part2) => part2.type === "tool-call"));
1131
+ hasToolCalls ||= decoded.some((part2) => part2.type === "tool-call");
1143
1132
  }
1144
1133
  break;
1145
1134
  }
1146
1135
  }
1147
1136
  }
1148
1137
  const usage = response.usage;
1149
- const inputTokens = usage == null ? void 0 : usage.input_tokens;
1150
- const cachedInputTokens = (_k = usage == null ? void 0 : usage.input_tokens_details) == null ? void 0 : _k.cached_tokens;
1151
- const cacheWriteTokens = (_l = usage == null ? void 0 : usage.input_tokens_details) == null ? void 0 : _l.cache_write_tokens;
1152
- const outputTokens = usage == null ? void 0 : usage.output_tokens;
1153
- const reasoningTokens = (_m = usage == null ? void 0 : usage.output_tokens_details) == null ? void 0 : _m.reasoning_tokens;
1138
+ const inputTokens = usage?.input_tokens;
1139
+ const cachedInputTokens = usage?.input_tokens_details?.cached_tokens;
1140
+ const cacheWriteTokens = usage?.input_tokens_details?.cache_write_tokens;
1141
+ const outputTokens = usage?.output_tokens;
1142
+ const reasoningTokens = usage?.output_tokens_details?.reasoning_tokens;
1154
1143
  return {
1155
1144
  content,
1156
1145
  finishReason: {
1157
1146
  unified: mapOpenResponsesFinishReason({
1158
- finishReason: (_n = response.incomplete_details) == null ? void 0 : _n.reason,
1147
+ finishReason: response.incomplete_details?.reason,
1159
1148
  hasToolCalls
1160
1149
  }),
1161
- raw: (_p = (_o = response.incomplete_details) == null ? void 0 : _o.reason) != null ? _p : void 0
1150
+ raw: response.incomplete_details?.reason ?? void 0
1162
1151
  },
1163
1152
  usage: {
1164
1153
  inputTokens: {
1165
1154
  total: inputTokens,
1166
- noCache: (inputTokens != null ? inputTokens : 0) - (cachedInputTokens != null ? cachedInputTokens : 0) - (cacheWriteTokens != null ? cacheWriteTokens : 0),
1155
+ noCache: (inputTokens ?? 0) - (cachedInputTokens ?? 0) - (cacheWriteTokens ?? 0),
1167
1156
  cacheRead: cachedInputTokens,
1168
1157
  cacheWrite: cacheWriteTokens
1169
1158
  },
1170
1159
  outputTokens: {
1171
1160
  total: outputTokens,
1172
- text: (outputTokens != null ? outputTokens : 0) - (reasoningTokens != null ? reasoningTokens : 0),
1161
+ text: (outputTokens ?? 0) - (reasoningTokens ?? 0),
1173
1162
  reasoning: reasoningTokens
1174
1163
  },
1175
1164
  raw: response.usage
@@ -1187,16 +1176,15 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
1187
1176
  };
1188
1177
  }
1189
1178
  async doStream(options) {
1190
- var _a, _b, _c;
1191
1179
  const { body, warnings } = await this.getArgs(options);
1192
1180
  const { responseHeaders, value: response } = await postJsonToApi({
1193
1181
  url: this.config.url,
1194
- headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
1182
+ headers: combineHeaders(this.config.headers?.(), options.headers),
1195
1183
  body: {
1196
1184
  ...body,
1197
1185
  stream: true
1198
1186
  },
1199
- failedResponseHandler: (_c = this.config.failedResponseHandler) != null ? _c : defaultFailedResponseHandler,
1187
+ failedResponseHandler: this.config.failedResponseHandler ?? defaultFailedResponseHandler,
1200
1188
  successfulResponseHandler: createEventSourceResponseHandler(z4.any()),
1201
1189
  abortSignal: options.abortSignal,
1202
1190
  fetch: this.config.fetch
@@ -1215,24 +1203,23 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
1215
1203
  }
1216
1204
  };
1217
1205
  const updateUsage = (responseUsage) => {
1218
- var _a2, _b2, _c2;
1219
1206
  if (!responseUsage) {
1220
1207
  return;
1221
1208
  }
1222
1209
  const inputTokens = responseUsage.input_tokens;
1223
- const cachedInputTokens = (_a2 = responseUsage.input_tokens_details) == null ? void 0 : _a2.cached_tokens;
1224
- const cacheWriteTokens = (_b2 = responseUsage.input_tokens_details) == null ? void 0 : _b2.cache_write_tokens;
1210
+ const cachedInputTokens = responseUsage.input_tokens_details?.cached_tokens;
1211
+ const cacheWriteTokens = responseUsage.input_tokens_details?.cache_write_tokens;
1225
1212
  const outputTokens = responseUsage.output_tokens;
1226
- const reasoningTokens = (_c2 = responseUsage.output_tokens_details) == null ? void 0 : _c2.reasoning_tokens;
1213
+ const reasoningTokens = responseUsage.output_tokens_details?.reasoning_tokens;
1227
1214
  usage.inputTokens = {
1228
1215
  total: inputTokens,
1229
- noCache: (inputTokens != null ? inputTokens : 0) - (cachedInputTokens != null ? cachedInputTokens : 0) - (cacheWriteTokens != null ? cacheWriteTokens : 0),
1216
+ noCache: (inputTokens ?? 0) - (cachedInputTokens ?? 0) - (cacheWriteTokens ?? 0),
1230
1217
  cacheRead: cachedInputTokens,
1231
1218
  cacheWrite: cacheWriteTokens
1232
1219
  };
1233
1220
  usage.outputTokens = {
1234
1221
  total: outputTokens,
1235
- text: (outputTokens != null ? outputTokens : 0) - (reasoningTokens != null ? reasoningTokens : 0),
1222
+ text: (outputTokens ?? 0) - (reasoningTokens ?? 0),
1236
1223
  reasoning: reasoningTokens
1237
1224
  };
1238
1225
  usage.raw = responseUsage;
@@ -1256,7 +1243,6 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
1256
1243
  controller.enqueue({ type: "stream-start", warnings });
1257
1244
  },
1258
1245
  async transform(parseResult, controller) {
1259
- var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1260
1246
  if (options.includeRawChunks) {
1261
1247
  controller.enqueue({
1262
1248
  type: "raw",
@@ -1270,15 +1256,15 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
1270
1256
  const chunk = parseResult.value;
1271
1257
  if (isOpenResponsesExtensionEvent(chunk)) {
1272
1258
  const extension = extensionRegistry.byEventType.get(chunk.type);
1273
- if ((extension == null ? void 0 : extension.decodeEvent) != null) {
1259
+ if (extension?.decodeEvent != null) {
1274
1260
  try {
1275
1261
  const decoded = await extension.decodeEvent({
1276
1262
  event: chunk,
1277
1263
  state: extensionStreamState
1278
1264
  });
1279
- for (const part of decoded != null ? decoded : []) {
1265
+ for (const part of decoded ?? []) {
1280
1266
  controller.enqueue(part);
1281
- hasToolCalls || (hasToolCalls = part.type === "tool-call" || part.type === "tool-input-start");
1267
+ hasToolCalls ||= part.type === "tool-call" || part.type === "tool-input-start";
1282
1268
  }
1283
1269
  } catch (error) {
1284
1270
  controller.enqueue({ type: "error", error });
@@ -1301,7 +1287,7 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
1301
1287
  });
1302
1288
  return;
1303
1289
  }
1304
- toolCall.arguments = ((_a2 = toolCall.arguments) != null ? _a2 : "") + functionCallChunk.delta;
1290
+ toolCall.arguments = (toolCall.arguments ?? "") + functionCallChunk.delta;
1305
1291
  } else if (chunk.type === "response.function_call_arguments.done") {
1306
1292
  const functionCallChunk = chunk;
1307
1293
  const toolCall = toolCallsByItemId.get(functionCallChunk.item_id);
@@ -1314,9 +1300,9 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
1314
1300
  toolCall.arguments = functionCallChunk.arguments;
1315
1301
  } else if (chunk.type === "response.output_item.done" && chunk.item.type === "function_call") {
1316
1302
  const toolCall = toolCallsByItemId.get(chunk.item.id);
1317
- const toolName = (_b2 = toolCall == null ? void 0 : toolCall.toolName) != null ? _b2 : chunk.item.name;
1318
- const toolCallId = (_c2 = toolCall == null ? void 0 : toolCall.toolCallId) != null ? _c2 : chunk.item.call_id;
1319
- const input = chunk.item.arguments !== "" ? chunk.item.arguments : (_d = toolCall == null ? void 0 : toolCall.arguments) != null ? _d : "";
1303
+ const toolName = toolCall?.toolName ?? chunk.item.name;
1304
+ const toolCallId = toolCall?.toolCallId ?? chunk.item.call_id;
1305
+ const input = chunk.item.arguments !== "" ? chunk.item.arguments : toolCall?.arguments ?? "";
1320
1306
  controller.enqueue({
1321
1307
  type: "tool-call",
1322
1308
  toolCallId,
@@ -1348,11 +1334,11 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
1348
1334
  input: chunk.delta
1349
1335
  });
1350
1336
  } else {
1351
- toolCall.input = ((_e = toolCall.input) != null ? _e : "") + chunk.delta;
1337
+ toolCall.input = (toolCall.input ?? "") + chunk.delta;
1352
1338
  }
1353
1339
  controller.enqueue({
1354
1340
  type: "tool-input-delta",
1355
- id: (_g = (_f = customToolCallsByItemId.get(chunk.item_id)) == null ? void 0 : _f.toolCallId) != null ? _g : chunk.item_id,
1341
+ id: customToolCallsByItemId.get(chunk.item_id)?.toolCallId ?? chunk.item_id,
1356
1342
  delta: chunk.delta
1357
1343
  });
1358
1344
  } else if (chunk.type === "response.custom_tool_call_input.done") {
@@ -1366,13 +1352,13 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
1366
1352
  }
1367
1353
  } else if (chunk.type === "response.output_item.done" && chunk.item.type === "custom_tool_call") {
1368
1354
  const toolCall = customToolCallsByItemId.get(chunk.item.id);
1369
- const toolCallId = (_h = toolCall == null ? void 0 : toolCall.toolCallId) != null ? _h : chunk.item.call_id;
1370
- const input = chunk.item.input !== "" ? chunk.item.input : (_i = toolCall == null ? void 0 : toolCall.input) != null ? _i : "";
1355
+ const toolCallId = toolCall?.toolCallId ?? chunk.item.call_id;
1356
+ const input = chunk.item.input !== "" ? chunk.item.input : toolCall?.input ?? "";
1371
1357
  controller.enqueue({ type: "tool-input-end", id: toolCallId });
1372
1358
  controller.enqueue({
1373
1359
  type: "tool-call",
1374
1360
  toolCallId,
1375
- toolName: (_j = toolCall == null ? void 0 : toolCall.toolName) != null ? _j : chunk.item.name,
1361
+ toolName: toolCall?.toolName ?? chunk.item.name,
1376
1362
  input: JSON.stringify(input),
1377
1363
  providerMetadata: {
1378
1364
  [providerOptionsName]: { itemId: chunk.item.id }
@@ -1388,9 +1374,9 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
1388
1374
  mode: "stream",
1389
1375
  providerOptionsName
1390
1376
  });
1391
- for (const part of decoded != null ? decoded : []) {
1377
+ for (const part of decoded ?? []) {
1392
1378
  controller.enqueue(part);
1393
- hasToolCalls || (hasToolCalls = part.type === "tool-call");
1379
+ hasToolCalls ||= part.type === "tool-call";
1394
1380
  }
1395
1381
  } catch (error) {
1396
1382
  controller.enqueue({ type: "error", error });
@@ -1443,19 +1429,19 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
1443
1429
  }
1444
1430
  });
1445
1431
  } else if (chunk.type === "response.completed" || chunk.type === "response.incomplete") {
1446
- const reason = (_k = chunk.response.incomplete_details) == null ? void 0 : _k.reason;
1432
+ const reason = chunk.response.incomplete_details?.reason;
1447
1433
  finishReason = {
1448
1434
  unified: mapOpenResponsesFinishReason({
1449
1435
  finishReason: reason,
1450
1436
  hasToolCalls
1451
1437
  }),
1452
- raw: reason != null ? reason : void 0
1438
+ raw: reason ?? void 0
1453
1439
  };
1454
1440
  updateUsage(chunk.response.usage);
1455
1441
  } else if (chunk.type === "response.failed") {
1456
1442
  finishReason = {
1457
1443
  unified: "error",
1458
- raw: (_m = (_l = chunk.response.error) == null ? void 0 : _l.code) != null ? _m : chunk.response.status
1444
+ raw: chunk.response.error?.code ?? chunk.response.status
1459
1445
  };
1460
1446
  updateUsage(chunk.response.usage);
1461
1447
  if (chunk.response.error != null) {
@@ -1516,7 +1502,7 @@ function createOpenResponsesStreamError({
1516
1502
  message: error.message,
1517
1503
  type,
1518
1504
  code: error.code,
1519
- ...getResponseErrorMetadata == null ? void 0 : getResponseErrorMetadata(error),
1505
+ ...getResponseErrorMetadata?.(error),
1520
1506
  data
1521
1507
  });
1522
1508
  }
@@ -1596,8 +1582,7 @@ function addExtensionItemReferenceMetadata({
1596
1582
  part,
1597
1583
  providerOptionsName
1598
1584
  }) {
1599
- var _a;
1600
- const providerMetadata = (_a = part.providerMetadata) != null ? _a : {};
1585
+ const providerMetadata = part.providerMetadata ?? {};
1601
1586
  return {
1602
1587
  ...part,
1603
1588
  providerMetadata: {
@@ -1629,24 +1614,20 @@ function getOutputTextAnnotations(value) {
1629
1614
 
1630
1615
  // src/open-responses-provider.ts
1631
1616
  function createOpenResponses(options) {
1632
- var _a;
1633
1617
  const providerName = options.name;
1634
- const customToolId = (_a = options.customToolId) != null ? _a : "open-responses.custom";
1618
+ const customToolId = options.customToolId ?? "open-responses.custom";
1635
1619
  const extensionRegistry = createOpenResponsesExtensionRegistry(
1636
1620
  options.experimental_extensions
1637
1621
  );
1638
- const getHeaders = () => {
1639
- var _a2;
1640
- return withUserAgentSuffix(
1641
- {
1642
- ...options.apiKey ? {
1643
- Authorization: `Bearer ${options.apiKey}`
1644
- } : {},
1645
- ...typeof options.headers === "function" ? options.headers() : options.headers
1646
- },
1647
- (_a2 = options.userAgentSuffix) != null ? _a2 : `ai-sdk/open-responses/${VERSION}`
1648
- );
1649
- };
1622
+ const getHeaders = () => withUserAgentSuffix(
1623
+ {
1624
+ ...options.apiKey ? {
1625
+ Authorization: `Bearer ${options.apiKey}`
1626
+ } : {},
1627
+ ...typeof options.headers === "function" ? options.headers() : options.headers
1628
+ },
1629
+ options.userAgentSuffix ?? `ai-sdk/open-responses/${VERSION}`
1630
+ );
1650
1631
  const createResponsesModel = (modelId) => {
1651
1632
  return new OpenResponsesLanguageModel(modelId, {
1652
1633
  provider: `${providerName}.responses`,