@openrouter/ai-sdk-provider 2.3.1 → 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.
@@ -2801,12 +2801,126 @@ function getToolResultContent(input) {
2801
2801
  return input.output.value;
2802
2802
  case "json":
2803
2803
  case "error-json":
2804
- case "content":
2805
2804
  return JSON.stringify(input.output.value);
2805
+ case "content":
2806
+ return mapToolResultContentParts(input.output.value);
2806
2807
  case "execution-denied":
2807
2808
  return (_a16 = input.output.reason) != null ? _a16 : "Tool execution denied";
2808
2809
  }
2809
2810
  }
2811
+ function mapToolResultContentParts(parts) {
2812
+ return parts.map((part) => {
2813
+ var _a16, _b16, _c;
2814
+ switch (part.type) {
2815
+ case "text":
2816
+ return { type: "text", text: part.text };
2817
+ case "image-data":
2818
+ return {
2819
+ type: "image_url",
2820
+ image_url: {
2821
+ url: buildFileDataUrl({
2822
+ data: part.data,
2823
+ mediaType: part.mediaType,
2824
+ defaultMediaType: "image/jpeg"
2825
+ })
2826
+ }
2827
+ };
2828
+ case "image-url":
2829
+ return {
2830
+ type: "image_url",
2831
+ image_url: { url: part.url }
2832
+ };
2833
+ case "file-data": {
2834
+ const dataUrl = buildFileDataUrl({
2835
+ data: part.data,
2836
+ mediaType: part.mediaType,
2837
+ defaultMediaType: "application/octet-stream"
2838
+ });
2839
+ if ((_a16 = part.mediaType) == null ? void 0 : _a16.startsWith("image/")) {
2840
+ return {
2841
+ type: "image_url",
2842
+ image_url: { url: dataUrl }
2843
+ };
2844
+ }
2845
+ if ((_b16 = part.mediaType) == null ? void 0 : _b16.startsWith("audio/")) {
2846
+ const rawFormat = part.mediaType.replace("audio/", "");
2847
+ const format = MIME_TO_FORMAT[rawFormat];
2848
+ if (format !== void 0) {
2849
+ return {
2850
+ type: "input_audio",
2851
+ input_audio: {
2852
+ data: getBase64FromDataUrl(dataUrl),
2853
+ format
2854
+ }
2855
+ };
2856
+ }
2857
+ }
2858
+ return {
2859
+ type: "file",
2860
+ file: {
2861
+ filename: (_c = part.filename) != null ? _c : "",
2862
+ file_data: dataUrl
2863
+ }
2864
+ };
2865
+ }
2866
+ case "file-url": {
2867
+ if (looksLikeImageUrl(part.url)) {
2868
+ return {
2869
+ type: "image_url",
2870
+ image_url: { url: part.url }
2871
+ };
2872
+ }
2873
+ return {
2874
+ type: "file",
2875
+ file: {
2876
+ filename: filenameFromUrl(part.url),
2877
+ file_data: part.url
2878
+ }
2879
+ };
2880
+ }
2881
+ case "file-id":
2882
+ case "image-file-id":
2883
+ case "custom":
2884
+ return { type: "text", text: JSON.stringify(part) };
2885
+ default: {
2886
+ const _exhaustiveCheck = part;
2887
+ return { type: "text", text: JSON.stringify(_exhaustiveCheck) };
2888
+ }
2889
+ }
2890
+ });
2891
+ }
2892
+ var IMAGE_EXTENSIONS = /* @__PURE__ */ new Set([
2893
+ "jpg",
2894
+ "jpeg",
2895
+ "png",
2896
+ "gif",
2897
+ "webp",
2898
+ "svg",
2899
+ "bmp",
2900
+ "ico",
2901
+ "tif",
2902
+ "tiff",
2903
+ "avif"
2904
+ ]);
2905
+ function looksLikeImageUrl(url) {
2906
+ var _a16;
2907
+ try {
2908
+ const pathname = new URL(url).pathname;
2909
+ const ext = (_a16 = pathname.split(".").pop()) == null ? void 0 : _a16.toLowerCase();
2910
+ return ext !== void 0 && IMAGE_EXTENSIONS.has(ext);
2911
+ } catch (e) {
2912
+ return false;
2913
+ }
2914
+ }
2915
+ function filenameFromUrl(url) {
2916
+ try {
2917
+ const pathname = new URL(url).pathname;
2918
+ const last = pathname.split("/").pop();
2919
+ return (last == null ? void 0 : last.includes(".")) ? last : "";
2920
+ } catch (e) {
2921
+ return "";
2922
+ }
2923
+ }
2810
2924
  function findFirstReasoningDetails(content) {
2811
2925
  var _a16, _b16, _c;
2812
2926
  for (const part of content) {