@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.
@@ -2767,12 +2767,126 @@ function getToolResultContent(input) {
2767
2767
  return input.output.value;
2768
2768
  case "json":
2769
2769
  case "error-json":
2770
- case "content":
2771
2770
  return JSON.stringify(input.output.value);
2771
+ case "content":
2772
+ return mapToolResultContentParts(input.output.value);
2772
2773
  case "execution-denied":
2773
2774
  return (_a16 = input.output.reason) != null ? _a16 : "Tool execution denied";
2774
2775
  }
2775
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
+ }
2776
2890
  function findFirstReasoningDetails(content) {
2777
2891
  var _a16, _b16, _c;
2778
2892
  for (const part of content) {