@openrouter/ai-sdk-provider 2.3.0 → 2.3.2

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.
@@ -2725,11 +2725,12 @@ function convertToOpenRouterChatMessages(prompt) {
2725
2725
  }
2726
2726
  finalReasoningDetails = uniqueDetails.length > 0 ? uniqueDetails : void 0;
2727
2727
  }
2728
+ const effectiveReasoning = reasoning && finalReasoningDetails ? reasoning : void 0;
2728
2729
  messages.push({
2729
2730
  role: "assistant",
2730
2731
  content: text,
2731
2732
  tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
2732
- reasoning: reasoning || void 0,
2733
+ reasoning: effectiveReasoning,
2733
2734
  reasoning_details: finalReasoningDetails,
2734
2735
  annotations: messageAnnotations,
2735
2736
  cache_control: getCacheControl(providerOptions)
@@ -2766,12 +2767,126 @@ function getToolResultContent(input) {
2766
2767
  return input.output.value;
2767
2768
  case "json":
2768
2769
  case "error-json":
2769
- case "content":
2770
2770
  return JSON.stringify(input.output.value);
2771
+ case "content":
2772
+ return mapToolResultContentParts(input.output.value);
2771
2773
  case "execution-denied":
2772
2774
  return (_a16 = input.output.reason) != null ? _a16 : "Tool execution denied";
2773
2775
  }
2774
2776
  }
2777
+ function mapToolResultContentParts(parts) {
2778
+ return parts.map((part) => {
2779
+ var _a16, _b16, _c;
2780
+ switch (part.type) {
2781
+ case "text":
2782
+ return { type: "text", text: part.text };
2783
+ case "image-data":
2784
+ return {
2785
+ type: "image_url",
2786
+ image_url: {
2787
+ url: buildFileDataUrl({
2788
+ data: part.data,
2789
+ mediaType: part.mediaType,
2790
+ defaultMediaType: "image/jpeg"
2791
+ })
2792
+ }
2793
+ };
2794
+ case "image-url":
2795
+ return {
2796
+ type: "image_url",
2797
+ image_url: { url: part.url }
2798
+ };
2799
+ case "file-data": {
2800
+ const dataUrl = buildFileDataUrl({
2801
+ data: part.data,
2802
+ mediaType: part.mediaType,
2803
+ defaultMediaType: "application/octet-stream"
2804
+ });
2805
+ if ((_a16 = part.mediaType) == null ? void 0 : _a16.startsWith("image/")) {
2806
+ return {
2807
+ type: "image_url",
2808
+ image_url: { url: dataUrl }
2809
+ };
2810
+ }
2811
+ if ((_b16 = part.mediaType) == null ? void 0 : _b16.startsWith("audio/")) {
2812
+ const rawFormat = part.mediaType.replace("audio/", "");
2813
+ const format = MIME_TO_FORMAT[rawFormat];
2814
+ if (format !== void 0) {
2815
+ return {
2816
+ type: "input_audio",
2817
+ input_audio: {
2818
+ data: getBase64FromDataUrl(dataUrl),
2819
+ format
2820
+ }
2821
+ };
2822
+ }
2823
+ }
2824
+ return {
2825
+ type: "file",
2826
+ file: {
2827
+ filename: (_c = part.filename) != null ? _c : "",
2828
+ file_data: dataUrl
2829
+ }
2830
+ };
2831
+ }
2832
+ case "file-url": {
2833
+ if (looksLikeImageUrl(part.url)) {
2834
+ return {
2835
+ type: "image_url",
2836
+ image_url: { url: part.url }
2837
+ };
2838
+ }
2839
+ return {
2840
+ type: "file",
2841
+ file: {
2842
+ filename: filenameFromUrl(part.url),
2843
+ file_data: part.url
2844
+ }
2845
+ };
2846
+ }
2847
+ case "file-id":
2848
+ case "image-file-id":
2849
+ case "custom":
2850
+ return { type: "text", text: JSON.stringify(part) };
2851
+ default: {
2852
+ const _exhaustiveCheck = part;
2853
+ return { type: "text", text: JSON.stringify(_exhaustiveCheck) };
2854
+ }
2855
+ }
2856
+ });
2857
+ }
2858
+ var IMAGE_EXTENSIONS = /* @__PURE__ */ new Set([
2859
+ "jpg",
2860
+ "jpeg",
2861
+ "png",
2862
+ "gif",
2863
+ "webp",
2864
+ "svg",
2865
+ "bmp",
2866
+ "ico",
2867
+ "tif",
2868
+ "tiff",
2869
+ "avif"
2870
+ ]);
2871
+ function looksLikeImageUrl(url) {
2872
+ var _a16;
2873
+ try {
2874
+ const pathname = new URL(url).pathname;
2875
+ const ext = (_a16 = pathname.split(".").pop()) == null ? void 0 : _a16.toLowerCase();
2876
+ return ext !== void 0 && IMAGE_EXTENSIONS.has(ext);
2877
+ } catch (e) {
2878
+ return false;
2879
+ }
2880
+ }
2881
+ function filenameFromUrl(url) {
2882
+ try {
2883
+ const pathname = new URL(url).pathname;
2884
+ const last = pathname.split("/").pop();
2885
+ return (last == null ? void 0 : last.includes(".")) ? last : "";
2886
+ } catch (e) {
2887
+ return "";
2888
+ }
2889
+ }
2775
2890
  function findFirstReasoningDetails(content) {
2776
2891
  var _a16, _b16, _c;
2777
2892
  for (const part of content) {