import{r as e}from"./chunk-CMxvf4Kt.js";import{t}from"./preload-helper-zJ_50EbN.js";import{r as n}from"./api-base-B9gtivQY.js";var r=/;[ \t]*base64[ \t]*$/i,i=/%([0-9a-f]{2})/gi,a=`text/plain;charset=US-ASCII`,o=37,s=/[\t\n\r]/g,c=/[\t\n\r]/,l=`data:`;function u(e){return e===9||e===10||e===13}function d(e){let t=0,n=e.length;for(;t<n&&e.charCodeAt(t)<=32;)t+=1;for(;n>t&&e.charCodeAt(n-1)<=32;)--n;return t===0&&n===e.length?e:e.slice(t,n)}function f(e){let t=d(e);return c.test(t)?t.replace(s,``):t}function p(e){let t=0;for(;t<e.length&&e.charCodeAt(t)<=32;)t+=1;for(let n of l){for(;t<e.length&&u(e.charCodeAt(t));)t+=1;if(t>=e.length||e[t].toLowerCase()!==n)return!1;t+=1}return!0}function m(e){return e>=48&&e<=57?e-48:e>=97&&e<=102?e-87:e>=65&&e<=70?e-55:-1}function h(e,t){if(e.charCodeAt(t)!==o)return-1;let n=m(e.charCodeAt(t+1)),r=m(e.charCodeAt(t+2));return n<0||r<0?-1:n*16+r}function g(e){let t=new TextEncoder;if(!e.includes(`%`))return t.encode(e);let n=new Uint8Array(e.length),r=0,i=e=>{if(r+e<=n.length)return;let t=Math.max(n.length,1);for(;t<r+e;)t*=2;let i=new Uint8Array(t);i.set(n.subarray(0,r)),n=i},a=0,o=o=>{if(o<=a)return;let s=e.slice(a,o);i(s.length*3),r+=t.encodeInto(s,n.subarray(r)).written},s=0;for(;s<e.length;){if(h(e,s)<0){s+=1;continue}o(s);let t=h(e,s);for(;t>=0;)i(1),n[r]=t,r+=1,s+=3,t=h(e,s);a=s}return o(e.length),n.slice(0,r)}function _(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e+=1)n[e]=t.charCodeAt(e);return n}function v(e){let t=f(e),n=t.indexOf(`,`);if(!p(t)||n<0)throw Error(`Invalid data URI.`);let o=t.slice(5,n),s=t.indexOf(`#`,n+1),c=t.slice(n+1,s<0?void 0:s),l=r.test(o),u=(l?o.replace(r,``):o).split(`;`,1)[0].trim(),d=u.includes(`/`)?u:a;return l?{bytes:_(c.includes(`%`)?c.replace(i,(e,t)=>String.fromCharCode(Number.parseInt(t,16))):c),mimeType:d}:{bytes:g(c),mimeType:d}}var y=e({DownloadCancelledError:()=>x,downloadFile:()=>O,downloadUrl:()=>j,downloadUrlStreaming:()=>A,isDownloadCancelled:()=>S,pickNativeChatImport:()=>M,pickNativeTrainingConfig:()=>N,readNativeChatImportChunk:()=>w,urlToBlob:()=>k}),b=`x-unsloth-default-name`,x=class extends Error{constructor(){super(`Save cancelled.`),this.name=`DownloadCancelledError`}};function S(e){return e instanceof x}function C(e){let t=new TextEncoder().encode(e),n=``;for(let e of t)n+=String.fromCharCode(e);return btoa(n)}async function w(e,n,r){let{invoke:i}=await t(async()=>{let{invoke:e}=await import(`./core-SwWLTXZB.js`);return{invoke:e}},[]),a=await i(`read_native_chat_import_chunk`,{token:e,offset:n,length:r});return a instanceof ArrayBuffer,new Uint8Array(a)}function T(e,t){let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)}function E(e,t){let n=document.createElement(`a`);n.href=e,n.download=t,n.rel=`noopener`,document.body.appendChild(n),n.click(),n.remove()}async function D(e){let t=await fetch(e);if(!t.ok)throw Error(`Download failed with status ${t.status}.`);return t}async function O(e,r,i=`application/octet-stream`){if(n){let{invoke:n}=await t(async()=>{let{invoke:e}=await import(`./core-SwWLTXZB.js`);return{invoke:e}},[]);if(await n(`save_native_file`,typeof e==`string`?new TextEncoder().encode(e):e instanceof Blob?new Uint8Array(await e.arrayBuffer()):e,{headers:{[b]:C(r)}})===null)throw new x;return}let a=e instanceof Uint8Array?Uint8Array.from(e).buffer:e;T(a instanceof Blob?a:new Blob([a],{type:i}),r)}async function k(e){if(p(e)){let{bytes:t,mimeType:n}=v(e);return new Blob([Uint8Array.from(t).buffer],{type:n})}return(await D(e)).blob()}async function A(e,r){if(!n){E(e,r);return}let{invoke:i}=await t(async()=>{let{invoke:e}=await import(`./core-SwWLTXZB.js`);return{invoke:e}},[]);if(await i(`save_native_file_from_url`,{url:e,fileName:r})===null)throw new x}async function j(e,t){if(p(e)){let{bytes:n,mimeType:r}=v(e);await O(n,t,r);return}if(!n){E(e,t);return}let r=await D(e);await O(new Uint8Array(await r.arrayBuffer()),t,r.headers.get(`content-type`)||`application/octet-stream`)}async function M(){if(!n)return null;let{invoke:e}=await t(async()=>{let{invoke:e}=await import(`./core-SwWLTXZB.js`);return{invoke:e}},[]);return e(`pick_native_chat_import`)}async function N(){if(!n)return null;let{invoke:e}=await t(async()=>{let{invoke:e}=await import(`./core-SwWLTXZB.js`);return{invoke:e}},[]);return e(`pick_native_training_config`)}export{y as a,k as c,S as i,j as n,M as o,A as r,N as s,O as t};