Loading
function(l,t,d){let i,c;d.d(t,{a:()=>R,i:()=>C,l:()=>G,o:()=>x,r:()=>g,t:()=>S});var e=d(976886),a=d(133237),s=d(257300),Z=d(209688),n=d(588233),b=d(171251),m=d(886421);let o=["wasmPath","wasmSimdPath","glueCodePath","glueCodeSimdPath","modelsBasePath"];function u(l){let t=l.trim();if(""===t)return!1;if(function(l){for(let t=0;t<l.length;t+=1){let d=l.charCodeAt(t);if(d<32||127===d)return!0}return!1}(t))return!0;if(/^https?:\/\//i.test(t))try{new URL(t)}catch{return!0}return!1}function h(l,t){"empty"===t?console.warn(`[Incode SDK] wasm.${l} is empty. Falling back to CDN default.`):console.warn(`[Incode SDK] wasm.${l} appears malformed. Falling back to CDN default.`)}function W(l,t,d){if(!t||!(l in t))return d;let i=t[l];return void 0===i||"string"!=typeof i?d:""===i.trim()?(h(l,"empty"),d):u(i)?(h(l,"malformed"),d):i.trim()}function G(l){let t,d,i=(t="https://cdn.incodesmile.com/ml-wasm-kit-release/v2.13.21",{wasmPath:`${t}/webLib.wasm`,wasmSimdPath:`${t}/webLibSimd.wasm`,glueCodePath:`${t}/webLib.js`,glueCodeSimdPath:`${t}/webLibSimd.js`,modelsBasePath:`${t}/models`});if(!l)return i;let c=i.wasmSimdPath??i.wasmPath,e=i.modelsBasePath??(-1===(d=i.wasmPath.lastIndexOf("/"))?"models":`${i.wasmPath.substring(0,d)}/models`),a=W("wasmSimdPath",l,c),s=a.replace(/\.wasm($|\?)/,".js$1"),Z={wasmPath:W("wasmPath",l,i.wasmPath),wasmSimdPath:a,glueCodePath:W("glueCodePath",l,i.glueCodePath),glueCodeSimdPath:W("glueCodeSimdPath",l,s),modelsBasePath:W("modelsBasePath",l,e),useSimd:l.useSimd,pipelines:l.pipelines,pipelineModels:l.pipelineModels};for(let l of o){let t=Z[l];"string"==typeof t&&u(t)&&console.warn(`[Incode SDK] wasm.${l} appears malformed. Check the URL or path.`)}return Z}var p=class{sendBeacon(l,t,d="application/json"){if("u"<typeof navigator||"function"!=typeof navigator.sendBeacon)return!1;let i=new Blob([t],{type:d});return navigator.sendBeacon(l,i)}onPageHide(l){let t=()=>{"hidden"===document.visibilityState&&l()};return document.addEventListener("visibilitychange",t),window.addEventListener("pagehide",l),window.addEventListener("beforeunload",l),()=>{document.removeEventListener("visibilitychange",t),window.removeEventListener("pagehide",l),window.removeEventListener("beforeunload",l)}}},N=class extends Error{constructor(l,t,d,i,c,e){super(`HTTP ${l} ${t}`),this.ok=!1,this.status=l,this.statusText=t,this.url=d,this.method=i,this.headers=c,this.data=e,this.name="FetchHttpError"}};let M=async(l,t)=>{if("response"===t)return l;if("blob"===t)return await l.blob();if("arrayBuffer"===t)return await l.arrayBuffer();if("text"===t)return await l.text();let d=l.headers.get("content-type")??"";if("json"===t||d.includes("application/json"))try{return await l.json()}catch{}return await l.text()};var X=class extends Error{constructor(l,t,d,i,c,e){super(`HTTP ${l} ${t}`),this.ok=!1,this.status=l,this.statusText=t,this.url=d,this.method=i,this.headers=c,this.data=e,this.name="WasmHttpError"}};let y=new Set(["GET","POST","PUT","PATCH","DELETE"]),Y=async(l,t,d)=>{if(!t)return await l;if(t.aborted)throw d;return await new Promise((i,c)=>{let e=()=>c(d);t.addEventListener("abort",e,{once:!0}),l.then(i,c).finally(()=>{t.removeEventListener("abort",e)})})},r=async l=>{let t={"Content-Type":"application/json",Accept:"application/json","api-version":"1.0",...l.customHeaders??{}},d=l.isEncryptionEnabled??(()=>!1),i="sha256"===l.mgf1;await (0,e.o)(l.wasm.wasmPath,l.wasm.wasmSimdPath??l.wasm.wasmPath,l.wasm.glueCodePath,l.wasm.glueCodeSimdPath??"",l.wasm.useSimd??!0),await (0,e.c)(l.apiURL,"",l.encryptionEnabled??!1,t,i);let c={baseURL:l.apiURL,headers:t},a={defaults:c,async request(t){var a;let s,{method:Z="GET",url:n,headers:b={},query:m,params:o,body:u,signal:h,timeout:W=l.timeout??3e4,onUploadProgress:G,ie:p=!1}=t,N=(l=>{let t=l.toUpperCase();if(!y.has(t))throw Error(`Unsupported HTTP method for WASM client: ${l}`);return t})(Z),M=o??m,r=(a=c.baseURL,s=(l=>{if(!l)return"";let t=new URLSearchParams;Object.entries(l).forEach(([l,d])=>{null!=d&&t.append(l,String(d))});let d=t.toString();return d?`?${d}`:""})(M),n.startsWith("http://")||n.startsWith("https://")?`${n}${s}`:`${a.endsWith("/")?a.slice(0,-1):a}${n.startsWith("/")?n:`/${n}`}${s}`),T=p||i&&d(),V={...c.headers,...T?{"X-RSA-Encryption-Scheme":"RSA/NONE/OAEPWITHSHA-256ANDMGF1PADDING"}:{},...b},L=(l=>{if(null!=l)return l instanceof FormData||l instanceof Blob||l instanceof ArrayBuffer||l instanceof Uint8Array||"string"==typeof l||"object"==typeof l?l:String(l)})(u),I=G?l=>{l.total>0&&G(Math.round(l.loaded/l.total*100))}:void 0,z=new X(0,"Request aborted",r,N,{},null);if(h?.aborted)throw z;try{let l=await Y((0,e.a)(N,n,L,V,M,W,I,p),h,z);if(l.status<200||l.status>=300)throw new X(l.status,"",r,N,{},l.data);return{ok:!0,status:l.status,statusText:"",url:r,headers:{},data:l.data}}catch(l){if(l instanceof X)throw l;throw new X((l=>{if(l instanceof e.i)return l.statusCode;if("object"==typeof l&&null!==l){if("number"==typeof l.statusCode)return l.statusCode;if("number"==typeof l.status)return l.status}return 0})(l),l instanceof Error?l.message:"WasmWebClient request failed",r,N,{},l instanceof e.i?l.response?.data??null:null)}},get:(l,t)=>a.request({...t,url:l,method:"GET"}),post:(l,t,d)=>a.request({...d,url:l,body:t,method:"POST"}),put:(l,t,d)=>a.request({...d,url:l,body:t,method:"PUT"}),patch:(l,t,d)=>a.request({...d,url:l,body:t,method:"PATCH"}),delete:(l,t)=>a.request({...t,url:l,method:"DELETE"}),head:()=>Promise.reject(Error("HEAD is not supported by the WASM HTTP client")),options:()=>Promise.reject(Error("OPTIONS is not supported by the WASM HTTP client")),setHeader(l,t){c.headers[l]=t}};return a};function T(l){(0,Z.o)(l),(0,e.s)(async(t,d,i)=>{let c=await l.request({method:"POST",url:t,body:d,headers:i.headers,params:i.params,timeout:i.timeout,ie:i.ie});return{data:c.data,status:c.status}})}function V(){return i?.encryption.enabled??!1}async function L(l,t,d,c){var e;let a,s,Z;T(d?await z(c.enabled,()=>r({apiURL:l,customHeaders:t.customHeaders,timeout:t.timeout,wasm:d,encryptionEnabled:c.enabled,mgf1:c.mgf1,isEncryptionEnabled:V})):(a={"Content-Type":"application/json",Accept:"application/json","api-version":"1.0",...(e={apiURL:l,customHeaders:t.customHeaders,timeout:t.timeout}).customHeaders??{}},Z={defaults:s={baseURL:e.apiURL,headers:a},async request(l){var t;let d,{method:i="GET",url:c,headers:a={},query:Z,params:n,body:b,signal:m,timeout:o=e.timeout??3e4,parse:u,onUploadProgress:h,keepalive:W}=l,G=(t=s.baseURL,d=(l=>{if(!l)return"";let t=new URLSearchParams;Object.entries(l).forEach(([l,d])=>{null!=d&&t.append(l,String(d))});let d=t.toString();return d?`?${d}`:""})(n??Z),c.startsWith("http://")||c.startsWith("https://")?`${c}${d}`:`${t.endsWith("/")?t.slice(0,-1):t}${c.startsWith("/")?c:`/${c}`}${d}`),p={...s.headers,...a},X=null==b?null:b instanceof FormData||b instanceof Blob||b instanceof ArrayBuffer?b:"object"==typeof b?JSON.stringify(b):String(b),y=p;if(null===X&&("POST"===i||"PUT"===i||"PATCH"===i)){let{"Content-Type":l,...t}=p;y=t}if(h){let l;if(null!==X&&"u">typeof ReadableStream&&X instanceof ReadableStream)throw Error("Upload progress tracking is not supported for ReadableStream bodies");return l=y,new Promise((t,d)=>{let c=new XMLHttpRequest;c.open(i,G,!0),Object.entries(l).forEach(([l,t])=>{c.setRequestHeader(l,t)}),c.timeout=o,c.upload.onprogress=l=>{l.lengthComputable&&h(Math.round(l.loaded/l.total*100))},c.onload=()=>{let l,e={};c.getAllResponseHeaders().split("\r\n").forEach(l=>{let t=l.split(": ");2===t.length&&(e[t[0].toLowerCase()]=t[1])});try{l=(c.getResponseHeader("content-type")??"").includes("application/json")?JSON.parse(c.responseText):c.responseText}catch{l=c.responseText}c.status>=200&&c.status<300?t({ok:!0,status:c.status,statusText:c.statusText,url:G,headers:e,data:l}):d(new N(c.status,c.statusText,G,i,e,l))},c.onerror=()=>{d(new N(0,"Network Error",G,i,{},null))},c.ontimeout=()=>{d(new N(0,"Request timeout",G,i,{},null))},m&&m.addEventListener("abort",()=>{c.abort(),d(new N(0,"Request aborted",G,i,{},null))}),c.send(X)})}let Y=new AbortController,r=m??Y.signal,T=setTimeout(()=>Y.abort(),o);try{let l=await fetch(G,{method:i,headers:y,body:X,signal:r,keepalive:W});T&&clearTimeout(T);let t={};l.headers.forEach((l,d)=>{t[d]=l});let d=await M(l,u);if(!l.ok)throw new N(l.status,l.statusText,G,i,t,d);return{ok:!0,status:l.status,statusText:l.statusText,url:G,headers:t,data:d}}catch(l){if(T&&clearTimeout(T),l instanceof N)throw l;if(l instanceof Error&&"AbortError"===l.name)throw new N(0,"Request timeout",G,i,{},null);throw l}},get:(l,t)=>Z.request({...t,url:l,method:"GET"}),post:(l,t,d)=>Z.request({...d,url:l,body:t,method:"POST"}),put:(l,t,d)=>Z.request({...d,url:l,body:t,method:"PUT"}),patch:(l,t,d)=>Z.request({...d,url:l,body:t,method:"PATCH"}),delete:(l,t)=>Z.request({...t,url:l,method:"DELETE"}),head:(l,t)=>Z.request({...t,url:l,method:"HEAD"}),options:(l,t)=>Z.request({...t,url:l,method:"OPTIONS"}),setHeader(l,t){s.headers[l]=t}})),i={apiURL:l,customHeaders:t.customHeaders,timeout:t.timeout,isWasm:!!d,encryption:c}}async function I(l){let t=i;t&&!t.isWasm&&(T(await r({apiURL:t.apiURL,customHeaders:t.customHeaders,timeout:t.timeout,wasm:l,encryptionEnabled:t.encryption.enabled,mgf1:t.encryption.mgf1,isEncryptionEnabled:V})),i={...t,isWasm:!0})}async function z(l,t){if(!l)return t();try{return await t()}catch(t){let l=Error("Failed to establish encrypted transport. The /e2ee/key handshake did not complete. Verify the apiURL is reachable and that the environment supports E2EE.");throw l.cause=t,l}}let w="sha1";async function R(l){(0,n.g)()||(0,n.v)((0,n.m)({endpoint:b.t.events,authToken:()=>(0,Z.r)(),apiBaseUrl:()=>(0,Z.n)().defaults.baseURL,apiClient:Z.t,pageLifecycle:new p,timer:s.t.getInstance()}));let t=function(l){if(void 0!==l)return!1===l?{enabled:!1,mgf1:w}:!0===l?{enabled:!0,mgf1:w}:{enabled:!0,mgf1:l.mgf1??w}}(l.encryption),d=i;if(t&&d&&(t.enabled!==d.encryption.enabled||t.enabled&&t.mgf1!==d.encryption.mgf1))throw Error("Encryption is locked at the first setup() call and cannot be changed at runtime. Call reset() to fully reinitialize the SDK if you need a different encryption configuration.");if(t?.enabled&&!1===l.wasm)throw Error("Encryption is incompatible with `wasm: false`. Either remove `wasm: false` or omit `encryption`.");let c=t??d?.encryption??{enabled:!1,mgf1:"sha1"},o=l.wasm||t?.enabled?G(l.wasm||{}):void 0;l.apiURL&&await L(l.apiURL,l,o,c),l.token&&(0,Z.i)()&&(0,m.r)({token:l.token,hostingApp:l.hostingApp}).catch(l=>{console.warn("Session initialization failed:",l)}),o&&(await (0,e.n)(o),await (await a.t.getInstance()).initialize({...o,pipelines:o.pipelines?[...o.pipelines]:void 0}))}function C(l){c=l}async function S(l){let t=l??c;if(!t)throw Error("WASM config is required. Provide config parameter or call setWasmConfig() first.");let d=G(t);await (await a.t.getInstance()).initialize({...d,pipelines:d.pipelines?[...d.pipelines]:void 0})}async function x(l){let t=l??c;t&&await I(G(t))}function g(){(0,Z.a)(),(0,m.i)(),(0,n._)(),i=void 0,(0,e.s)(null),c=void 0,a.t.resetInstance()}}