@oramacloud/client
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -1,2 +0,2 @@ | ||
"use strict";var OramaClient=(()=>{var xt=Object.create;var L=Object.defineProperty;var wt=Object.getOwnPropertyDescriptor;var It=Object.getOwnPropertyNames;var Ct=Object.getPrototypeOf,Tt=Object.prototype.hasOwnProperty;var C=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),vt=(t,e)=>{for(var n in e)L(t,n,{get:e[n],enumerable:!0})},de=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of It(e))!Tt.call(t,s)&&s!==n&&L(t,s,{get:()=>e[s],enumerable:!(r=wt(e,s))||r.enumerable});return t};var Q=(t,e,n)=>(n=t!=null?xt(Ct(t)):{},de(e||!t||!t.__esModule?L(n,"default",{value:t,enumerable:!0}):n,t)),Et=t=>de(L({},"__esModule",{value:!0}),t);var G=C(g=>{"use strict";Object.defineProperty(g,"__esModule",{value:!0});g.isBytes=pe;g.number=N;g.bool=he;g.bytes=Y;g.hash=fe;g.exists=me;g.output=ye;function N(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`positive integer expected, not ${t}`)}function he(t){if(typeof t!="boolean")throw new Error(`boolean expected, not ${t}`)}function pe(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function Y(t,...e){if(!pe(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${t.length}`)}function fe(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");N(t.outputLen),N(t.blockLen)}function me(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function ye(t,e){Y(t);let n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}var At={number:N,bool:he,bytes:Y,hash:fe,exists:me,output:ye};g.default=At});var Ue=C(a=>{"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.add5L=a.add5H=a.add4H=a.add4L=a.add3H=a.add3L=a.rotlBL=a.rotlBH=a.rotlSL=a.rotlSH=a.rotr32L=a.rotr32H=a.rotrBL=a.rotrBH=a.rotrSL=a.rotrSH=a.shrSL=a.shrSH=a.toBig=void 0;a.fromBig=X;a.split=ge;a.add=_e;var D=BigInt(2**32-1),J=BigInt(32);function X(t,e=!1){return e?{h:Number(t&D),l:Number(t>>J&D)}:{h:Number(t>>J&D)|0,l:Number(t&D)|0}}function ge(t,e=!1){let n=new Uint32Array(t.length),r=new Uint32Array(t.length);for(let s=0;s<t.length;s++){let{h:o,l:i}=X(t[s],e);[n[s],r[s]]=[o,i]}return[n,r]}var be=(t,e)=>BigInt(t>>>0)<<J|BigInt(e>>>0);a.toBig=be;var Se=(t,e,n)=>t>>>n;a.shrSH=Se;var xe=(t,e,n)=>t<<32-n|e>>>n;a.shrSL=xe;var we=(t,e,n)=>t>>>n|e<<32-n;a.rotrSH=we;var Ie=(t,e,n)=>t<<32-n|e>>>n;a.rotrSL=Ie;var Ce=(t,e,n)=>t<<64-n|e>>>n-32;a.rotrBH=Ce;var Te=(t,e,n)=>t>>>n-32|e<<64-n;a.rotrBL=Te;var ve=(t,e)=>e;a.rotr32H=ve;var Ee=(t,e)=>t;a.rotr32L=Ee;var Ae=(t,e,n)=>t<<n|e>>>32-n;a.rotlSH=Ae;var Pe=(t,e,n)=>e<<n|t>>>32-n;a.rotlSL=Pe;var Oe=(t,e,n)=>e<<n-32|t>>>64-n;a.rotlBH=Oe;var ke=(t,e,n)=>t<<n-32|e>>>64-n;a.rotlBL=ke;function _e(t,e,n,r){let s=(e>>>0)+(r>>>0);return{h:t+n+(s/2**32|0)|0,l:s|0}}var Me=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0);a.add3L=Me;var Le=(t,e,n,r)=>e+n+r+(t/2**32|0)|0;a.add3H=Le;var Ne=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0);a.add4L=Ne;var De=(t,e,n,r,s)=>e+n+r+s+(t/2**32|0)|0;a.add4H=De;var Re=(t,e,n,r,s)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(s>>>0);a.add5L=Re;var Be=(t,e,n,r,s,o)=>e+n+r+s+o+(t/2**32|0)|0;a.add5H=Be;var Pt={fromBig:X,split:ge,toBig:be,shrSH:Se,shrSL:xe,rotrSH:we,rotrSL:Ie,rotrBH:Ce,rotrBL:Te,rotr32H:ve,rotr32L:Ee,rotlSH:Ae,rotlSL:Pe,rotlBH:Oe,rotlBL:ke,add:_e,add3L:Me,add3H:Le,add4L:Ne,add4H:De,add5H:Be,add5L:Re};a.default=Pt});var He=C(R=>{"use strict";Object.defineProperty(R,"__esModule",{value:!0});R.crypto=void 0;R.crypto=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0});var Fe=C(c=>{"use strict";Object.defineProperty(c,"__esModule",{value:!0});c.Hash=c.nextTick=c.byteSwapIfBE=c.byteSwap=c.isLE=c.rotl=c.rotr=c.createView=c.u32=c.u8=void 0;c.isBytes=Ot;c.byteSwap32=Rt;c.bytesToHex=Ut;c.hexToBytes=Ht;c.asyncLoop=$t;c.utf8ToBytes=$e;c.toBytes=B;c.concatBytes=Ft;c.checkOpts=Vt;c.wrapConstructor=Wt;c.wrapConstructorWithOpts=Kt;c.wrapXOFConstructorWithOpts=zt;c.randomBytes=Qt;var v=He(),ee=G();function Ot(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}var kt=t=>new Uint8Array(t.buffer,t.byteOffset,t.byteLength);c.u8=kt;var _t=t=>new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4));c.u32=_t;var Mt=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);c.createView=Mt;var Lt=(t,e)=>t<<32-e|t>>>e;c.rotr=Lt;var Nt=(t,e)=>t<<e|t>>>32-e>>>0;c.rotl=Nt;c.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var Dt=t=>t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255;c.byteSwap=Dt;c.byteSwapIfBE=c.isLE?t=>t:t=>(0,c.byteSwap)(t);function Rt(t){for(let e=0;e<t.length;e++)t[e]=(0,c.byteSwap)(t[e])}var Bt=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Ut(t){(0,ee.bytes)(t);let e="";for(let n=0;n<t.length;n++)e+=Bt[t[n]];return e}var b={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function je(t){if(t>=b._0&&t<=b._9)return t-b._0;if(t>=b._A&&t<=b._F)return t-(b._A-10);if(t>=b._a&&t<=b._f)return t-(b._a-10)}function Ht(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);let e=t.length,n=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let r=new Uint8Array(n);for(let s=0,o=0;s<n;s++,o+=2){let i=je(t.charCodeAt(o)),l=je(t.charCodeAt(o+1));if(i===void 0||l===void 0){let p=t[o]+t[o+1];throw new Error('hex string expected, got non-hex character "'+p+'" at index '+o)}r[s]=i*16+l}return r}var jt=async()=>{};c.nextTick=jt;async function $t(t,e,n){let r=Date.now();for(let s=0;s<t;s++){n(s);let o=Date.now()-r;o>=0&&o<e||(await(0,c.nextTick)(),r+=o)}}function $e(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function B(t){return typeof t=="string"&&(t=$e(t)),(0,ee.bytes)(t),t}function Ft(...t){let e=0;for(let r=0;r<t.length;r++){let s=t[r];(0,ee.bytes)(s),e+=s.length}let n=new Uint8Array(e);for(let r=0,s=0;r<t.length;r++){let o=t[r];n.set(o,s),s+=o.length}return n}var Z=class{clone(){return this._cloneInto()}};c.Hash=Z;var qt={}.toString;function Vt(t,e){if(e!==void 0&&qt.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(t,e)}function Wt(t){let e=r=>t().update(B(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function Kt(t){let e=(r,s)=>t(s).update(B(r)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}function zt(t){let e=(r,s)=>t(s).update(B(r)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}function Qt(t=32){if(v.crypto&&typeof v.crypto.getRandomValues=="function")return v.crypto.getRandomValues(new Uint8Array(t));if(v.crypto&&typeof v.crypto.randomBytes=="function")return v.crypto.randomBytes(t);throw new Error("crypto.getRandomValues must be defined")}});var Ge=C(d=>{"use strict";Object.defineProperty(d,"__esModule",{value:!0});d.shake256=d.shake128=d.keccak_512=d.keccak_384=d.keccak_256=d.keccak_224=d.sha3_512=d.sha3_384=d.sha3_256=d.sha3_224=d.Keccak=void 0;d.keccakP=Qe;var E=G(),P=Ue(),S=Fe(),We=[],Ke=[],ze=[],Yt=BigInt(0),A=BigInt(1),Gt=BigInt(2),Jt=BigInt(7),Xt=BigInt(256),Zt=BigInt(113);for(let t=0,e=A,n=1,r=0;t<24;t++){[n,r]=[r,(2*n+3*r)%5],We.push(2*(5*r+n)),Ke.push((t+1)*(t+2)/2%64);let s=Yt;for(let o=0;o<7;o++)e=(e<<A^(e>>Jt)*Zt)%Xt,e&Gt&&(s^=A<<(A<<BigInt(o))-A);ze.push(s)}var[en,tn]=(0,P.split)(ze,!0),qe=(t,e,n)=>n>32?(0,P.rotlBH)(t,e,n):(0,P.rotlSH)(t,e,n),Ve=(t,e,n)=>n>32?(0,P.rotlBL)(t,e,n):(0,P.rotlSL)(t,e,n);function Qe(t,e=24){let n=new Uint32Array(10);for(let r=24-e;r<24;r++){for(let i=0;i<10;i++)n[i]=t[i]^t[i+10]^t[i+20]^t[i+30]^t[i+40];for(let i=0;i<10;i+=2){let l=(i+8)%10,p=(i+2)%10,h=n[p],u=n[p+1],f=qe(h,u,1)^n[l],m=Ve(h,u,1)^n[l+1];for(let x=0;x<50;x+=10)t[i+x]^=f,t[i+x+1]^=m}let s=t[2],o=t[3];for(let i=0;i<24;i++){let l=Ke[i],p=qe(s,o,l),h=Ve(s,o,l),u=We[i];s=t[u],o=t[u+1],t[u]=p,t[u+1]=h}for(let i=0;i<50;i+=10){for(let l=0;l<10;l++)n[l]=t[i+l];for(let l=0;l<10;l++)t[i+l]^=~n[(l+2)%10]&n[(l+4)%10]}t[0]^=en[r],t[1]^=tn[r]}n.fill(0)}var O=class t extends S.Hash{constructor(e,n,r,s=!1,o=24){if(super(),this.blockLen=e,this.suffix=n,this.outputLen=r,this.enableXOF=s,this.rounds=o,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,(0,E.number)(r),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=(0,S.u32)(this.state)}keccak(){S.isLE||(0,S.byteSwap32)(this.state32),Qe(this.state32,this.rounds),S.isLE||(0,S.byteSwap32)(this.state32),this.posOut=0,this.pos=0}update(e){(0,E.exists)(this);let{blockLen:n,state:r}=this;e=(0,S.toBytes)(e);let s=e.length;for(let o=0;o<s;){let i=Math.min(n-this.pos,s-o);for(let l=0;l<i;l++)r[this.pos++]^=e[o++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:n,pos:r,blockLen:s}=this;e[r]^=n,n&128&&r===s-1&&this.keccak(),e[s-1]^=128,this.keccak()}writeInto(e){(0,E.exists)(this,!1),(0,E.bytes)(e),this.finish();let n=this.state,{blockLen:r}=this;for(let s=0,o=e.length;s<o;){this.posOut>=r&&this.keccak();let i=Math.min(r-this.posOut,o-s);e.set(n.subarray(this.posOut,this.posOut+i),s),this.posOut+=i,s+=i}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return(0,E.number)(e),this.xofInto(new Uint8Array(e))}digestInto(e){if((0,E.output)(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){let{blockLen:n,suffix:r,outputLen:s,rounds:o,enableXOF:i}=this;return e||(e=new t(n,r,s,i,o)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=o,e.suffix=r,e.outputLen=s,e.enableXOF=i,e.destroyed=this.destroyed,e}};d.Keccak=O;var w=(t,e,n)=>(0,S.wrapConstructor)(()=>new O(e,t,n));d.sha3_224=w(6,144,224/8);d.sha3_256=w(6,136,256/8);d.sha3_384=w(6,104,384/8);d.sha3_512=w(6,72,512/8);d.keccak_224=w(1,144,224/8);d.keccak_256=w(1,136,256/8);d.keccak_384=w(1,104,384/8);d.keccak_512=w(1,72,512/8);var Ye=(t,e,n)=>(0,S.wrapXOFConstructorWithOpts)((r={})=>new O(e,t,r.dkLen===void 0?n:r.dkLen,!0));d.shake128=Ye(31,168,128/8);d.shake256=Ye(31,136,256/8)});var st=C((In,I)=>{"use strict";var{sha3_512:nn}=Ge(),Xe=24,k=32,te=(t=4,e=Math.random)=>{let n="";for(;n.length<t;)n=n+Math.floor(e()*36).toString(36);return n};function Ze(t){let e=BigInt(8),n=BigInt(0);for(let r of t.values()){let s=BigInt(r);n=(n<<e)+s}return n}var et=(t="")=>Ze(nn(t)).toString(36).slice(1),Je=Array.from({length:26},(t,e)=>String.fromCharCode(e+97)),rn=t=>Je[Math.floor(t()*Je.length)],tt=({globalObj:t=typeof global<"u"?global:typeof window<"u"?window:{},random:e=Math.random}={})=>{let n=Object.keys(t).toString(),r=n.length?n+te(k,e):te(k,e);return et(r).substring(0,k)},nt=t=>()=>t++,sn=476782367,rt=({random:t=Math.random,counter:e=nt(Math.floor(t()*sn)),length:n=Xe,fingerprint:r=tt({random:t})}={})=>function(){let o=rn(t),i=Date.now().toString(36),l=e().toString(36),p=te(n,t),h=`${i+p+l+r}`;return`${o+et(h).substring(1,n)}`},on=rt(),an=(t,{minLength:e=2,maxLength:n=k}={})=>{let r=t.length,s=/^[a-z][0-9a-z]+$/;try{if(typeof t=="string"&&r>=e&&r<=n&&s.test(t))return!0}finally{}return!1};I.exports.getConstants=()=>({defaultLength:Xe,bigLength:k});I.exports.init=rt;I.exports.createId=on;I.exports.bufToBigInt=Ze;I.exports.createCounter=nt;I.exports.createFingerprint=tt;I.exports.isCuid=an});var U=C((Cn,_)=>{"use strict";var{createId:cn,init:ln,getConstants:un,isCuid:dn}=st();_.exports.createId=cn;_.exports.init=ln;_.exports.getConstants=un;_.exports.isCuid=dn});var mn={};vt(mn,{AnswerSession:()=>M,CloudManager:()=>le,OramaClient:()=>ae});var mt=Q(U(),1);var Tn=Date.now().toString().slice(5);var ot=BigInt(1e3),it=BigInt(1e6),at=BigInt(1e9);async function ct(t){return typeof t=="number"&&(t=BigInt(t)),t<ot?`${t}ns`:t<it?`${t/ot}\u03BCs`:t<at?`${t/it}ms`:`${t/at}s`}async function ne(t){return{raw:Number(t),formatted:await ct(t)}}var ut="2.0.0";var dt={name:"@oramacloud/client",version:ut,description:"Orama SDK client for Node.js, Deno, and Browsers",type:"module",sideEffects:!1,main:"./dist/index.cjs",module:"./dist/index.js",types:"./dist/index.d.ts",runkitExampleFilename:"./example/runkit.js",exports:{".":{types:"./dist/index.d.ts",browser:"./dist/index.global.js",require:"./dist/index.cjs",import:"./dist/index.js"}},scripts:{watch:"tsup --config tsup.lib.js --watch src",build:"tsup --config tsup.lib.js",test:'glob -c "node --import tsx --no-warnings --test" "./tests/**/*.test.ts"',"serve:example":"esbuild src/index.ts --bundle --outfile=example/out.js --format=esm --watch --servedir=example"},keywords:["orama","search engine","sdk"],files:["dist","example/runkit.js"],author:{name:"Michele Riva",email:"michele.riva@oramasearch.com",url:"https://github.com/MicheleRiva"},license:"ISC",dependencies:{"@orama/cuid2":"^2.2.3","@orama/orama":"^2.0.16",lodash:"^4.17.21"},devDependencies:{"@fastify/formbody":"^7.4.0","@types/lodash":"^4.14.202","@types/node":"^20.3.1",dotenv:"^16.3.1",esbuild:"0.18.5",fastify:"^4.19.2",glob:"^11.0.0",husky:"^8.0.3","npm-run-all":"^4.1.5","ts-standard":"^12.0.2",tsup:"^8.3.0",tsx:"^4.7.0",typescript:"^5.1.3"},publishConfig:{access:"public"},"ts-standard":{ignore:["dist","node_modules"]}};var oe=Q(U(),1);var ht="https://answer.api.orama.com",pt="/v1/indexes",re="orama_user_id";function ft(t){let[e,...n]=t.split(` | ||
"use strict";var OramaClient=(()=>{var xt=Object.create;var L=Object.defineProperty;var wt=Object.getOwnPropertyDescriptor;var It=Object.getOwnPropertyNames;var Ct=Object.getPrototypeOf,Tt=Object.prototype.hasOwnProperty;var C=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),vt=(t,e)=>{for(var n in e)L(t,n,{get:e[n],enumerable:!0})},de=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of It(e))!Tt.call(t,s)&&s!==n&&L(t,s,{get:()=>e[s],enumerable:!(r=wt(e,s))||r.enumerable});return t};var Q=(t,e,n)=>(n=t!=null?xt(Ct(t)):{},de(e||!t||!t.__esModule?L(n,"default",{value:t,enumerable:!0}):n,t)),Et=t=>de(L({},"__esModule",{value:!0}),t);var G=C(g=>{"use strict";Object.defineProperty(g,"__esModule",{value:!0});g.isBytes=pe;g.number=N;g.bool=he;g.bytes=Y;g.hash=fe;g.exists=me;g.output=ye;function N(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`positive integer expected, not ${t}`)}function he(t){if(typeof t!="boolean")throw new Error(`boolean expected, not ${t}`)}function pe(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function Y(t,...e){if(!pe(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${t.length}`)}function fe(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");N(t.outputLen),N(t.blockLen)}function me(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function ye(t,e){Y(t);let n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}var At={number:N,bool:he,bytes:Y,hash:fe,exists:me,output:ye};g.default=At});var Ue=C(a=>{"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.add5L=a.add5H=a.add4H=a.add4L=a.add3H=a.add3L=a.rotlBL=a.rotlBH=a.rotlSL=a.rotlSH=a.rotr32L=a.rotr32H=a.rotrBL=a.rotrBH=a.rotrSL=a.rotrSH=a.shrSL=a.shrSH=a.toBig=void 0;a.fromBig=X;a.split=ge;a.add=_e;var D=BigInt(2**32-1),J=BigInt(32);function X(t,e=!1){return e?{h:Number(t&D),l:Number(t>>J&D)}:{h:Number(t>>J&D)|0,l:Number(t&D)|0}}function ge(t,e=!1){let n=new Uint32Array(t.length),r=new Uint32Array(t.length);for(let s=0;s<t.length;s++){let{h:o,l:i}=X(t[s],e);[n[s],r[s]]=[o,i]}return[n,r]}var be=(t,e)=>BigInt(t>>>0)<<J|BigInt(e>>>0);a.toBig=be;var Se=(t,e,n)=>t>>>n;a.shrSH=Se;var xe=(t,e,n)=>t<<32-n|e>>>n;a.shrSL=xe;var we=(t,e,n)=>t>>>n|e<<32-n;a.rotrSH=we;var Ie=(t,e,n)=>t<<32-n|e>>>n;a.rotrSL=Ie;var Ce=(t,e,n)=>t<<64-n|e>>>n-32;a.rotrBH=Ce;var Te=(t,e,n)=>t>>>n-32|e<<64-n;a.rotrBL=Te;var ve=(t,e)=>e;a.rotr32H=ve;var Ee=(t,e)=>t;a.rotr32L=Ee;var Ae=(t,e,n)=>t<<n|e>>>32-n;a.rotlSH=Ae;var Pe=(t,e,n)=>e<<n|t>>>32-n;a.rotlSL=Pe;var Oe=(t,e,n)=>e<<n-32|t>>>64-n;a.rotlBH=Oe;var ke=(t,e,n)=>t<<n-32|e>>>64-n;a.rotlBL=ke;function _e(t,e,n,r){let s=(e>>>0)+(r>>>0);return{h:t+n+(s/2**32|0)|0,l:s|0}}var Me=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0);a.add3L=Me;var Le=(t,e,n,r)=>e+n+r+(t/2**32|0)|0;a.add3H=Le;var Ne=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0);a.add4L=Ne;var De=(t,e,n,r,s)=>e+n+r+s+(t/2**32|0)|0;a.add4H=De;var Re=(t,e,n,r,s)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(s>>>0);a.add5L=Re;var Be=(t,e,n,r,s,o)=>e+n+r+s+o+(t/2**32|0)|0;a.add5H=Be;var Pt={fromBig:X,split:ge,toBig:be,shrSH:Se,shrSL:xe,rotrSH:we,rotrSL:Ie,rotrBH:Ce,rotrBL:Te,rotr32H:ve,rotr32L:Ee,rotlSH:Ae,rotlSL:Pe,rotlBH:Oe,rotlBL:ke,add:_e,add3L:Me,add3H:Le,add4L:Ne,add4H:De,add5H:Be,add5L:Re};a.default=Pt});var He=C(R=>{"use strict";Object.defineProperty(R,"__esModule",{value:!0});R.crypto=void 0;R.crypto=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0});var Fe=C(c=>{"use strict";Object.defineProperty(c,"__esModule",{value:!0});c.Hash=c.nextTick=c.byteSwapIfBE=c.byteSwap=c.isLE=c.rotl=c.rotr=c.createView=c.u32=c.u8=void 0;c.isBytes=Ot;c.byteSwap32=Rt;c.bytesToHex=Ut;c.hexToBytes=Ht;c.asyncLoop=$t;c.utf8ToBytes=$e;c.toBytes=B;c.concatBytes=Ft;c.checkOpts=Vt;c.wrapConstructor=Wt;c.wrapConstructorWithOpts=Kt;c.wrapXOFConstructorWithOpts=zt;c.randomBytes=Qt;var v=He(),ee=G();function Ot(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}var kt=t=>new Uint8Array(t.buffer,t.byteOffset,t.byteLength);c.u8=kt;var _t=t=>new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4));c.u32=_t;var Mt=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);c.createView=Mt;var Lt=(t,e)=>t<<32-e|t>>>e;c.rotr=Lt;var Nt=(t,e)=>t<<e|t>>>32-e>>>0;c.rotl=Nt;c.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var Dt=t=>t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255;c.byteSwap=Dt;c.byteSwapIfBE=c.isLE?t=>t:t=>(0,c.byteSwap)(t);function Rt(t){for(let e=0;e<t.length;e++)t[e]=(0,c.byteSwap)(t[e])}var Bt=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Ut(t){(0,ee.bytes)(t);let e="";for(let n=0;n<t.length;n++)e+=Bt[t[n]];return e}var b={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function je(t){if(t>=b._0&&t<=b._9)return t-b._0;if(t>=b._A&&t<=b._F)return t-(b._A-10);if(t>=b._a&&t<=b._f)return t-(b._a-10)}function Ht(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);let e=t.length,n=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let r=new Uint8Array(n);for(let s=0,o=0;s<n;s++,o+=2){let i=je(t.charCodeAt(o)),l=je(t.charCodeAt(o+1));if(i===void 0||l===void 0){let p=t[o]+t[o+1];throw new Error('hex string expected, got non-hex character "'+p+'" at index '+o)}r[s]=i*16+l}return r}var jt=async()=>{};c.nextTick=jt;async function $t(t,e,n){let r=Date.now();for(let s=0;s<t;s++){n(s);let o=Date.now()-r;o>=0&&o<e||(await(0,c.nextTick)(),r+=o)}}function $e(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function B(t){return typeof t=="string"&&(t=$e(t)),(0,ee.bytes)(t),t}function Ft(...t){let e=0;for(let r=0;r<t.length;r++){let s=t[r];(0,ee.bytes)(s),e+=s.length}let n=new Uint8Array(e);for(let r=0,s=0;r<t.length;r++){let o=t[r];n.set(o,s),s+=o.length}return n}var Z=class{clone(){return this._cloneInto()}};c.Hash=Z;var qt={}.toString;function Vt(t,e){if(e!==void 0&&qt.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(t,e)}function Wt(t){let e=r=>t().update(B(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function Kt(t){let e=(r,s)=>t(s).update(B(r)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}function zt(t){let e=(r,s)=>t(s).update(B(r)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}function Qt(t=32){if(v.crypto&&typeof v.crypto.getRandomValues=="function")return v.crypto.getRandomValues(new Uint8Array(t));if(v.crypto&&typeof v.crypto.randomBytes=="function")return v.crypto.randomBytes(t);throw new Error("crypto.getRandomValues must be defined")}});var Ge=C(d=>{"use strict";Object.defineProperty(d,"__esModule",{value:!0});d.shake256=d.shake128=d.keccak_512=d.keccak_384=d.keccak_256=d.keccak_224=d.sha3_512=d.sha3_384=d.sha3_256=d.sha3_224=d.Keccak=void 0;d.keccakP=Qe;var E=G(),P=Ue(),S=Fe(),We=[],Ke=[],ze=[],Yt=BigInt(0),A=BigInt(1),Gt=BigInt(2),Jt=BigInt(7),Xt=BigInt(256),Zt=BigInt(113);for(let t=0,e=A,n=1,r=0;t<24;t++){[n,r]=[r,(2*n+3*r)%5],We.push(2*(5*r+n)),Ke.push((t+1)*(t+2)/2%64);let s=Yt;for(let o=0;o<7;o++)e=(e<<A^(e>>Jt)*Zt)%Xt,e&Gt&&(s^=A<<(A<<BigInt(o))-A);ze.push(s)}var[en,tn]=(0,P.split)(ze,!0),qe=(t,e,n)=>n>32?(0,P.rotlBH)(t,e,n):(0,P.rotlSH)(t,e,n),Ve=(t,e,n)=>n>32?(0,P.rotlBL)(t,e,n):(0,P.rotlSL)(t,e,n);function Qe(t,e=24){let n=new Uint32Array(10);for(let r=24-e;r<24;r++){for(let i=0;i<10;i++)n[i]=t[i]^t[i+10]^t[i+20]^t[i+30]^t[i+40];for(let i=0;i<10;i+=2){let l=(i+8)%10,p=(i+2)%10,h=n[p],u=n[p+1],f=qe(h,u,1)^n[l],m=Ve(h,u,1)^n[l+1];for(let x=0;x<50;x+=10)t[i+x]^=f,t[i+x+1]^=m}let s=t[2],o=t[3];for(let i=0;i<24;i++){let l=Ke[i],p=qe(s,o,l),h=Ve(s,o,l),u=We[i];s=t[u],o=t[u+1],t[u]=p,t[u+1]=h}for(let i=0;i<50;i+=10){for(let l=0;l<10;l++)n[l]=t[i+l];for(let l=0;l<10;l++)t[i+l]^=~n[(l+2)%10]&n[(l+4)%10]}t[0]^=en[r],t[1]^=tn[r]}n.fill(0)}var O=class t extends S.Hash{constructor(e,n,r,s=!1,o=24){if(super(),this.blockLen=e,this.suffix=n,this.outputLen=r,this.enableXOF=s,this.rounds=o,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,(0,E.number)(r),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=(0,S.u32)(this.state)}keccak(){S.isLE||(0,S.byteSwap32)(this.state32),Qe(this.state32,this.rounds),S.isLE||(0,S.byteSwap32)(this.state32),this.posOut=0,this.pos=0}update(e){(0,E.exists)(this);let{blockLen:n,state:r}=this;e=(0,S.toBytes)(e);let s=e.length;for(let o=0;o<s;){let i=Math.min(n-this.pos,s-o);for(let l=0;l<i;l++)r[this.pos++]^=e[o++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:n,pos:r,blockLen:s}=this;e[r]^=n,n&128&&r===s-1&&this.keccak(),e[s-1]^=128,this.keccak()}writeInto(e){(0,E.exists)(this,!1),(0,E.bytes)(e),this.finish();let n=this.state,{blockLen:r}=this;for(let s=0,o=e.length;s<o;){this.posOut>=r&&this.keccak();let i=Math.min(r-this.posOut,o-s);e.set(n.subarray(this.posOut,this.posOut+i),s),this.posOut+=i,s+=i}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return(0,E.number)(e),this.xofInto(new Uint8Array(e))}digestInto(e){if((0,E.output)(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){let{blockLen:n,suffix:r,outputLen:s,rounds:o,enableXOF:i}=this;return e||(e=new t(n,r,s,i,o)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=o,e.suffix=r,e.outputLen=s,e.enableXOF=i,e.destroyed=this.destroyed,e}};d.Keccak=O;var w=(t,e,n)=>(0,S.wrapConstructor)(()=>new O(e,t,n));d.sha3_224=w(6,144,224/8);d.sha3_256=w(6,136,256/8);d.sha3_384=w(6,104,384/8);d.sha3_512=w(6,72,512/8);d.keccak_224=w(1,144,224/8);d.keccak_256=w(1,136,256/8);d.keccak_384=w(1,104,384/8);d.keccak_512=w(1,72,512/8);var Ye=(t,e,n)=>(0,S.wrapXOFConstructorWithOpts)((r={})=>new O(e,t,r.dkLen===void 0?n:r.dkLen,!0));d.shake128=Ye(31,168,128/8);d.shake256=Ye(31,136,256/8)});var st=C((In,I)=>{"use strict";var{sha3_512:nn}=Ge(),Xe=24,k=32,te=(t=4,e=Math.random)=>{let n="";for(;n.length<t;)n=n+Math.floor(e()*36).toString(36);return n};function Ze(t){let e=BigInt(8),n=BigInt(0);for(let r of t.values()){let s=BigInt(r);n=(n<<e)+s}return n}var et=(t="")=>Ze(nn(t)).toString(36).slice(1),Je=Array.from({length:26},(t,e)=>String.fromCharCode(e+97)),rn=t=>Je[Math.floor(t()*Je.length)],tt=({globalObj:t=typeof global<"u"?global:typeof window<"u"?window:{},random:e=Math.random}={})=>{let n=Object.keys(t).toString(),r=n.length?n+te(k,e):te(k,e);return et(r).substring(0,k)},nt=t=>()=>t++,sn=476782367,rt=({random:t=Math.random,counter:e=nt(Math.floor(t()*sn)),length:n=Xe,fingerprint:r=tt({random:t})}={})=>function(){let o=rn(t),i=Date.now().toString(36),l=e().toString(36),p=te(n,t),h=`${i+p+l+r}`;return`${o+et(h).substring(1,n)}`},on=rt(),an=(t,{minLength:e=2,maxLength:n=k}={})=>{let r=t.length,s=/^[a-z][0-9a-z]+$/;try{if(typeof t=="string"&&r>=e&&r<=n&&s.test(t))return!0}finally{}return!1};I.exports.getConstants=()=>({defaultLength:Xe,bigLength:k});I.exports.init=rt;I.exports.createId=on;I.exports.bufToBigInt=Ze;I.exports.createCounter=nt;I.exports.createFingerprint=tt;I.exports.isCuid=an});var U=C((Cn,_)=>{"use strict";var{createId:cn,init:ln,getConstants:un,isCuid:dn}=st();_.exports.createId=cn;_.exports.init=ln;_.exports.getConstants=un;_.exports.isCuid=dn});var mn={};vt(mn,{AnswerSession:()=>M,CloudManager:()=>le,OramaClient:()=>ae});var mt=Q(U(),1);var Tn=Date.now().toString().slice(5);var ot=BigInt(1e3),it=BigInt(1e6),at=BigInt(1e9);async function ct(t){return typeof t=="number"&&(t=BigInt(t)),t<ot?`${t}ns`:t<it?`${t/ot}\u03BCs`:t<at?`${t/it}ms`:`${t/at}s`}async function ne(t){return{raw:Number(t),formatted:await ct(t)}}var ut="2.0.1";var dt={name:"@oramacloud/client",version:ut,description:"Orama SDK client for Node.js, Deno, and Browsers",type:"module",sideEffects:!1,main:"./dist/index.cjs",module:"./dist/index.js",types:"./dist/index.d.ts",runkitExampleFilename:"./example/runkit.js",exports:{".":{types:"./dist/index.d.ts",browser:"./dist/index.global.js",require:"./dist/index.cjs",import:"./dist/index.js"}},scripts:{watch:"tsup --config tsup.lib.js --watch src",build:"tsup --config tsup.lib.js",test:'glob -c "node --import tsx --no-warnings --test" "./tests/**/*.test.ts"',"serve:example":"esbuild src/index.ts --bundle --outfile=example/out.js --format=esm --watch --servedir=example"},keywords:["orama","search engine","sdk"],files:["dist","example/runkit.js"],author:{name:"Michele Riva",email:"michele.riva@oramasearch.com",url:"https://github.com/MicheleRiva"},license:"ISC",dependencies:{"@orama/cuid2":"^2.2.3","@orama/orama":"^2.0.16",lodash:"^4.17.21"},devDependencies:{"@fastify/formbody":"^7.4.0","@types/lodash":"^4.14.202","@types/node":"^20.3.1",dotenv:"^16.3.1",esbuild:"0.18.5",fastify:"^4.19.2",glob:"^11.0.0",husky:"^8.0.3","npm-run-all":"^4.1.5","ts-standard":"^12.0.2",tsup:"^8.3.0",tsx:"^4.7.0",typescript:"^5.1.3"},publishConfig:{access:"public"},"ts-standard":{ignore:["dist","node_modules"]}};var oe=Q(U(),1);var ht="https://answer.api.orama.com",pt="/v1/indexes",re="orama_user_id";function ft(t){let[e,...n]=t.split(` | ||
`),r=n.join(` | ||
@@ -3,0 +3,0 @@ `).replace("data: ","");return{event:e.replace("event: ",""),data:r}}function se(t){return typeof t=="object"?JSON.stringify(t):`${t}`}var M=class{messages;inferenceType;oramaClient;endpoint;abortController;events;userContext;conversationID;lastInteractionParams;state=[];systemPrompts;constructor(e){let n=e.oramaClient.answersApiBaseURL||ht;this.messages=e.initialMessages||[],this.inferenceType=e.inferenceType,this.oramaClient=e.oramaClient,this.endpoint=`${n}/v1/answer?api-key=${this.oramaClient.api_key}`,this.events=e.events,this.conversationID=(0,oe.createId)(),this.userContext=e.userContext}async askStream(e){return this.messages.push({role:"user",content:e.term??""}),this.fetchAnswer(e)}async ask(e){let n=await this.askStream(e),r="";for await(let s of n)r=s;return this.events?.onMessageChange&&this.events.onMessageChange(this.messages),r}getMessages(){return this.messages}clearSession(){this.messages=[],this.state=[],this.events?.onMessageChange&&this.events.onMessageChange(this.messages),this.events?.onStateChange&&this.events.onStateChange(this.state)}abortAnswer(){if(!this.abortController)throw new Error("AbortController is not ready");this.abortController.abort(),this.abortController=void 0,this.state[this.state.length-1].aborted=!0}async regenerateLast({stream:e=!0}={}){if(this.state.length===0||this.messages.length===0)throw new Error("No messages to regenerate");if(!(this.messages.at(-1)?.role==="assistant"))throw new Error("Last message is not an assistant message");return this.messages.pop(),this.state.pop(),e?this.askStream(this.lastInteractionParams):this.ask(this.lastInteractionParams)}addNewEmptyAssistantMessage(){this.messages.push({role:"assistant",content:""})}async*fetchAnswer(e){this.abortController=new AbortController,this.lastInteractionParams=e;let n=(0,oe.createId)(),r=null,s=this.state.length;this.state.push({interactionId:n,query:e.term??"",response:"",relatedQueries:null,sources:null,translatedQuery:null,aborted:!1,loading:!0,error:!1,errorMessage:null});try{this.events?.onNewInteractionStarted&&this.events.onNewInteractionStarted(n),this.events?.onStateChange&&this.events.onStateChange(this.state);let o=new URLSearchParams;o.append("type",this.inferenceType),o.append("messages",JSON.stringify(this.messages)),o.append("query",e.term??""),o.append("conversationId",this.conversationID),o.append("userId",this.oramaClient.getUserId()),o.append("endpoint",this.oramaClient.endpoint),o.append("searchParams",JSON.stringify(e)),o.append("identity",this.oramaClient.getIdentity()??""),o.append("interactionId",n),o.append("alias",this.oramaClient.getAlias()??"");let i=this.getSystemPromptConfiguration();if(i&&o.append("systemPrompts",JSON.stringify(i)),this.userContext&&o.append("userContext",se(this.userContext)),e.userData&&o.append("userData",se(e.userData)),e.related){if(e.related?.howMany&&e.related?.howMany>5)throw new Error("Can generate at most 5 related queries");o.append("related",JSON.stringify({enabled:!0,howMany:e.related.howMany??3,format:e.related.format??"question"}))}let l=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:o.toString(),signal:this.abortController.signal});if(!l.ok||!l.body)throw new Error(l.statusText);r=l.body.getReader();let p=new TextDecoder,h=[],u="";this.events?.onMessageLoading&&this.events.onMessageLoading(!0),this.addNewEmptyAssistantMessage();let f=this.messages.at(-1);for(;;){let{value:m,done:x}=await r.read();if(x)break;u+=p.decode(m,{stream:!0});let K;for(;(K=u.indexOf(` |
@@ -1,2 +0,2 @@ | ||
var St=Object.create;var ce=Object.defineProperty;var xt=Object.getOwnPropertyDescriptor;var wt=Object.getOwnPropertyNames;var It=Object.getPrototypeOf,Ct=Object.prototype.hasOwnProperty;var C=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Tt=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of wt(e))!Ct.call(t,s)&&s!==n&&ce(t,s,{get:()=>e[s],enumerable:!(r=xt(e,s))||r.enumerable});return t};var z=(t,e,n)=>(n=t!=null?St(It(t)):{},Tt(e||!t||!t.__esModule?ce(n,"default",{value:t,enumerable:!0}):n,t));var Y=C(g=>{"use strict";Object.defineProperty(g,"__esModule",{value:!0});g.isBytes=ue;g.number=M;g.bool=le;g.bytes=Q;g.hash=de;g.exists=he;g.output=pe;function M(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`positive integer expected, not ${t}`)}function le(t){if(typeof t!="boolean")throw new Error(`boolean expected, not ${t}`)}function ue(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function Q(t,...e){if(!ue(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${t.length}`)}function de(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");M(t.outputLen),M(t.blockLen)}function he(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function pe(t,e){Q(t);let n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}var vt={number:M,bool:le,bytes:Q,hash:de,exists:he,output:pe};g.default=vt});var De=C(a=>{"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.add5L=a.add5H=a.add4H=a.add4L=a.add3H=a.add3L=a.rotlBL=a.rotlBH=a.rotlSL=a.rotlSH=a.rotr32L=a.rotr32H=a.rotrBL=a.rotrBH=a.rotrSL=a.rotrSH=a.shrSL=a.shrSH=a.toBig=void 0;a.fromBig=J;a.split=fe;a.add=Pe;var L=BigInt(2**32-1),G=BigInt(32);function J(t,e=!1){return e?{h:Number(t&L),l:Number(t>>G&L)}:{h:Number(t>>G&L)|0,l:Number(t&L)|0}}function fe(t,e=!1){let n=new Uint32Array(t.length),r=new Uint32Array(t.length);for(let s=0;s<t.length;s++){let{h:o,l:i}=J(t[s],e);[n[s],r[s]]=[o,i]}return[n,r]}var me=(t,e)=>BigInt(t>>>0)<<G|BigInt(e>>>0);a.toBig=me;var ye=(t,e,n)=>t>>>n;a.shrSH=ye;var ge=(t,e,n)=>t<<32-n|e>>>n;a.shrSL=ge;var be=(t,e,n)=>t>>>n|e<<32-n;a.rotrSH=be;var Se=(t,e,n)=>t<<32-n|e>>>n;a.rotrSL=Se;var xe=(t,e,n)=>t<<64-n|e>>>n-32;a.rotrBH=xe;var we=(t,e,n)=>t>>>n-32|e<<64-n;a.rotrBL=we;var Ie=(t,e)=>e;a.rotr32H=Ie;var Ce=(t,e)=>t;a.rotr32L=Ce;var Te=(t,e,n)=>t<<n|e>>>32-n;a.rotlSH=Te;var ve=(t,e,n)=>e<<n|t>>>32-n;a.rotlSL=ve;var Ee=(t,e,n)=>e<<n-32|t>>>64-n;a.rotlBH=Ee;var Ae=(t,e,n)=>t<<n-32|e>>>64-n;a.rotlBL=Ae;function Pe(t,e,n,r){let s=(e>>>0)+(r>>>0);return{h:t+n+(s/2**32|0)|0,l:s|0}}var Oe=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0);a.add3L=Oe;var ke=(t,e,n,r)=>e+n+r+(t/2**32|0)|0;a.add3H=ke;var _e=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0);a.add4L=_e;var Me=(t,e,n,r,s)=>e+n+r+s+(t/2**32|0)|0;a.add4H=Me;var Le=(t,e,n,r,s)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(s>>>0);a.add5L=Le;var Ne=(t,e,n,r,s,o)=>e+n+r+s+o+(t/2**32|0)|0;a.add5H=Ne;var Et={fromBig:J,split:fe,toBig:me,shrSH:ye,shrSL:ge,rotrSH:be,rotrSL:Se,rotrBH:xe,rotrBL:we,rotr32H:Ie,rotr32L:Ce,rotlSH:Te,rotlSL:ve,rotlBH:Ee,rotlBL:Ae,add:Pe,add3L:Oe,add3H:ke,add4L:_e,add4H:Me,add5H:Ne,add5L:Le};a.default=Et});var Re=C(N=>{"use strict";Object.defineProperty(N,"__esModule",{value:!0});N.crypto=void 0;N.crypto=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0});var He=C(c=>{"use strict";Object.defineProperty(c,"__esModule",{value:!0});c.Hash=c.nextTick=c.byteSwapIfBE=c.byteSwap=c.isLE=c.rotl=c.rotr=c.createView=c.u32=c.u8=void 0;c.isBytes=At;c.byteSwap32=Nt;c.bytesToHex=Rt;c.hexToBytes=Bt;c.asyncLoop=Ht;c.utf8ToBytes=Ue;c.toBytes=D;c.concatBytes=jt;c.checkOpts=Ft;c.wrapConstructor=qt;c.wrapConstructorWithOpts=Vt;c.wrapXOFConstructorWithOpts=Wt;c.randomBytes=Kt;var v=Re(),Z=Y();function At(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}var Pt=t=>new Uint8Array(t.buffer,t.byteOffset,t.byteLength);c.u8=Pt;var Ot=t=>new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4));c.u32=Ot;var kt=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);c.createView=kt;var _t=(t,e)=>t<<32-e|t>>>e;c.rotr=_t;var Mt=(t,e)=>t<<e|t>>>32-e>>>0;c.rotl=Mt;c.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var Lt=t=>t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255;c.byteSwap=Lt;c.byteSwapIfBE=c.isLE?t=>t:t=>(0,c.byteSwap)(t);function Nt(t){for(let e=0;e<t.length;e++)t[e]=(0,c.byteSwap)(t[e])}var Dt=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Rt(t){(0,Z.bytes)(t);let e="";for(let n=0;n<t.length;n++)e+=Dt[t[n]];return e}var b={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Be(t){if(t>=b._0&&t<=b._9)return t-b._0;if(t>=b._A&&t<=b._F)return t-(b._A-10);if(t>=b._a&&t<=b._f)return t-(b._a-10)}function Bt(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);let e=t.length,n=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let r=new Uint8Array(n);for(let s=0,o=0;s<n;s++,o+=2){let i=Be(t.charCodeAt(o)),l=Be(t.charCodeAt(o+1));if(i===void 0||l===void 0){let p=t[o]+t[o+1];throw new Error('hex string expected, got non-hex character "'+p+'" at index '+o)}r[s]=i*16+l}return r}var Ut=async()=>{};c.nextTick=Ut;async function Ht(t,e,n){let r=Date.now();for(let s=0;s<t;s++){n(s);let o=Date.now()-r;o>=0&&o<e||(await(0,c.nextTick)(),r+=o)}}function Ue(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function D(t){return typeof t=="string"&&(t=Ue(t)),(0,Z.bytes)(t),t}function jt(...t){let e=0;for(let r=0;r<t.length;r++){let s=t[r];(0,Z.bytes)(s),e+=s.length}let n=new Uint8Array(e);for(let r=0,s=0;r<t.length;r++){let o=t[r];n.set(o,s),s+=o.length}return n}var X=class{clone(){return this._cloneInto()}};c.Hash=X;var $t={}.toString;function Ft(t,e){if(e!==void 0&&$t.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(t,e)}function qt(t){let e=r=>t().update(D(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function Vt(t){let e=(r,s)=>t(s).update(D(r)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}function Wt(t){let e=(r,s)=>t(s).update(D(r)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}function Kt(t=32){if(v.crypto&&typeof v.crypto.getRandomValues=="function")return v.crypto.getRandomValues(new Uint8Array(t));if(v.crypto&&typeof v.crypto.randomBytes=="function")return v.crypto.randomBytes(t);throw new Error("crypto.getRandomValues must be defined")}});var ze=C(d=>{"use strict";Object.defineProperty(d,"__esModule",{value:!0});d.shake256=d.shake128=d.keccak_512=d.keccak_384=d.keccak_256=d.keccak_224=d.sha3_512=d.sha3_384=d.sha3_256=d.sha3_224=d.Keccak=void 0;d.keccakP=We;var E=Y(),P=De(),S=He(),Fe=[],qe=[],Ve=[],zt=BigInt(0),A=BigInt(1),Qt=BigInt(2),Yt=BigInt(7),Gt=BigInt(256),Jt=BigInt(113);for(let t=0,e=A,n=1,r=0;t<24;t++){[n,r]=[r,(2*n+3*r)%5],Fe.push(2*(5*r+n)),qe.push((t+1)*(t+2)/2%64);let s=zt;for(let o=0;o<7;o++)e=(e<<A^(e>>Yt)*Jt)%Gt,e&Qt&&(s^=A<<(A<<BigInt(o))-A);Ve.push(s)}var[Xt,Zt]=(0,P.split)(Ve,!0),je=(t,e,n)=>n>32?(0,P.rotlBH)(t,e,n):(0,P.rotlSH)(t,e,n),$e=(t,e,n)=>n>32?(0,P.rotlBL)(t,e,n):(0,P.rotlSL)(t,e,n);function We(t,e=24){let n=new Uint32Array(10);for(let r=24-e;r<24;r++){for(let i=0;i<10;i++)n[i]=t[i]^t[i+10]^t[i+20]^t[i+30]^t[i+40];for(let i=0;i<10;i+=2){let l=(i+8)%10,p=(i+2)%10,h=n[p],u=n[p+1],f=je(h,u,1)^n[l],m=$e(h,u,1)^n[l+1];for(let x=0;x<50;x+=10)t[i+x]^=f,t[i+x+1]^=m}let s=t[2],o=t[3];for(let i=0;i<24;i++){let l=qe[i],p=je(s,o,l),h=$e(s,o,l),u=Fe[i];s=t[u],o=t[u+1],t[u]=p,t[u+1]=h}for(let i=0;i<50;i+=10){for(let l=0;l<10;l++)n[l]=t[i+l];for(let l=0;l<10;l++)t[i+l]^=~n[(l+2)%10]&n[(l+4)%10]}t[0]^=Xt[r],t[1]^=Zt[r]}n.fill(0)}var O=class t extends S.Hash{constructor(e,n,r,s=!1,o=24){if(super(),this.blockLen=e,this.suffix=n,this.outputLen=r,this.enableXOF=s,this.rounds=o,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,(0,E.number)(r),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=(0,S.u32)(this.state)}keccak(){S.isLE||(0,S.byteSwap32)(this.state32),We(this.state32,this.rounds),S.isLE||(0,S.byteSwap32)(this.state32),this.posOut=0,this.pos=0}update(e){(0,E.exists)(this);let{blockLen:n,state:r}=this;e=(0,S.toBytes)(e);let s=e.length;for(let o=0;o<s;){let i=Math.min(n-this.pos,s-o);for(let l=0;l<i;l++)r[this.pos++]^=e[o++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:n,pos:r,blockLen:s}=this;e[r]^=n,n&128&&r===s-1&&this.keccak(),e[s-1]^=128,this.keccak()}writeInto(e){(0,E.exists)(this,!1),(0,E.bytes)(e),this.finish();let n=this.state,{blockLen:r}=this;for(let s=0,o=e.length;s<o;){this.posOut>=r&&this.keccak();let i=Math.min(r-this.posOut,o-s);e.set(n.subarray(this.posOut,this.posOut+i),s),this.posOut+=i,s+=i}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return(0,E.number)(e),this.xofInto(new Uint8Array(e))}digestInto(e){if((0,E.output)(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){let{blockLen:n,suffix:r,outputLen:s,rounds:o,enableXOF:i}=this;return e||(e=new t(n,r,s,i,o)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=o,e.suffix=r,e.outputLen=s,e.enableXOF=i,e.destroyed=this.destroyed,e}};d.Keccak=O;var w=(t,e,n)=>(0,S.wrapConstructor)(()=>new O(e,t,n));d.sha3_224=w(6,144,224/8);d.sha3_256=w(6,136,256/8);d.sha3_384=w(6,104,384/8);d.sha3_512=w(6,72,512/8);d.keccak_224=w(1,144,224/8);d.keccak_256=w(1,136,256/8);d.keccak_384=w(1,104,384/8);d.keccak_512=w(1,72,512/8);var Ke=(t,e,n)=>(0,S.wrapXOFConstructorWithOpts)((r={})=>new O(e,t,r.dkLen===void 0?n:r.dkLen,!0));d.shake128=Ke(31,168,128/8);d.shake256=Ke(31,136,256/8)});var tt=C((Sn,I)=>{"use strict";var{sha3_512:en}=ze(),Ye=24,k=32,ee=(t=4,e=Math.random)=>{let n="";for(;n.length<t;)n=n+Math.floor(e()*36).toString(36);return n};function Ge(t){let e=BigInt(8),n=BigInt(0);for(let r of t.values()){let s=BigInt(r);n=(n<<e)+s}return n}var Je=(t="")=>Ge(en(t)).toString(36).slice(1),Qe=Array.from({length:26},(t,e)=>String.fromCharCode(e+97)),tn=t=>Qe[Math.floor(t()*Qe.length)],Xe=({globalObj:t=typeof global<"u"?global:typeof window<"u"?window:{},random:e=Math.random}={})=>{let n=Object.keys(t).toString(),r=n.length?n+ee(k,e):ee(k,e);return Je(r).substring(0,k)},Ze=t=>()=>t++,nn=476782367,et=({random:t=Math.random,counter:e=Ze(Math.floor(t()*nn)),length:n=Ye,fingerprint:r=Xe({random:t})}={})=>function(){let o=tn(t),i=Date.now().toString(36),l=e().toString(36),p=ee(n,t),h=`${i+p+l+r}`;return`${o+Je(h).substring(1,n)}`},rn=et(),sn=(t,{minLength:e=2,maxLength:n=k}={})=>{let r=t.length,s=/^[a-z][0-9a-z]+$/;try{if(typeof t=="string"&&r>=e&&r<=n&&s.test(t))return!0}finally{}return!1};I.exports.getConstants=()=>({defaultLength:Ye,bigLength:k});I.exports.init=et;I.exports.createId=rn;I.exports.bufToBigInt=Ge;I.exports.createCounter=Ze;I.exports.createFingerprint=Xe;I.exports.isCuid=sn});var R=C((xn,_)=>{"use strict";var{createId:on,init:an,getConstants:cn,isCuid:ln}=tt();_.exports.createId=on;_.exports.init=an;_.exports.getConstants=cn;_.exports.isCuid=ln});var pt=z(R(),1);var wn=Date.now().toString().slice(5);var nt=BigInt(1e3),rt=BigInt(1e6),st=BigInt(1e9);async function ot(t){return typeof t=="number"&&(t=BigInt(t)),t<nt?`${t}ns`:t<rt?`${t/nt}\u03BCs`:t<st?`${t/rt}ms`:`${t/st}s`}async function te(t){return{raw:Number(t),formatted:await ot(t)}}var at="2.0.0";var ct={name:"@oramacloud/client",version:at,description:"Orama SDK client for Node.js, Deno, and Browsers",type:"module",sideEffects:!1,main:"./dist/index.cjs",module:"./dist/index.js",types:"./dist/index.d.ts",runkitExampleFilename:"./example/runkit.js",exports:{".":{types:"./dist/index.d.ts",browser:"./dist/index.global.js",require:"./dist/index.cjs",import:"./dist/index.js"}},scripts:{watch:"tsup --config tsup.lib.js --watch src",build:"tsup --config tsup.lib.js",test:'glob -c "node --import tsx --no-warnings --test" "./tests/**/*.test.ts"',"serve:example":"esbuild src/index.ts --bundle --outfile=example/out.js --format=esm --watch --servedir=example"},keywords:["orama","search engine","sdk"],files:["dist","example/runkit.js"],author:{name:"Michele Riva",email:"michele.riva@oramasearch.com",url:"https://github.com/MicheleRiva"},license:"ISC",dependencies:{"@orama/cuid2":"^2.2.3","@orama/orama":"^2.0.16",lodash:"^4.17.21"},devDependencies:{"@fastify/formbody":"^7.4.0","@types/lodash":"^4.14.202","@types/node":"^20.3.1",dotenv:"^16.3.1",esbuild:"0.18.5",fastify:"^4.19.2",glob:"^11.0.0",husky:"^8.0.3","npm-run-all":"^4.1.5","ts-standard":"^12.0.2",tsup:"^8.3.0",tsx:"^4.7.0",typescript:"^5.1.3"},publishConfig:{access:"public"},"ts-standard":{ignore:["dist","node_modules"]}};var se=z(R(),1);var lt="https://answer.api.orama.com",ut="/v1/indexes",ne="orama_user_id";function dt(t){let[e,...n]=t.split(` | ||
var St=Object.create;var ce=Object.defineProperty;var xt=Object.getOwnPropertyDescriptor;var wt=Object.getOwnPropertyNames;var It=Object.getPrototypeOf,Ct=Object.prototype.hasOwnProperty;var C=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Tt=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of wt(e))!Ct.call(t,s)&&s!==n&&ce(t,s,{get:()=>e[s],enumerable:!(r=xt(e,s))||r.enumerable});return t};var z=(t,e,n)=>(n=t!=null?St(It(t)):{},Tt(e||!t||!t.__esModule?ce(n,"default",{value:t,enumerable:!0}):n,t));var Y=C(g=>{"use strict";Object.defineProperty(g,"__esModule",{value:!0});g.isBytes=ue;g.number=M;g.bool=le;g.bytes=Q;g.hash=de;g.exists=he;g.output=pe;function M(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`positive integer expected, not ${t}`)}function le(t){if(typeof t!="boolean")throw new Error(`boolean expected, not ${t}`)}function ue(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function Q(t,...e){if(!ue(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${t.length}`)}function de(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");M(t.outputLen),M(t.blockLen)}function he(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function pe(t,e){Q(t);let n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}var vt={number:M,bool:le,bytes:Q,hash:de,exists:he,output:pe};g.default=vt});var De=C(a=>{"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.add5L=a.add5H=a.add4H=a.add4L=a.add3H=a.add3L=a.rotlBL=a.rotlBH=a.rotlSL=a.rotlSH=a.rotr32L=a.rotr32H=a.rotrBL=a.rotrBH=a.rotrSL=a.rotrSH=a.shrSL=a.shrSH=a.toBig=void 0;a.fromBig=J;a.split=fe;a.add=Pe;var L=BigInt(2**32-1),G=BigInt(32);function J(t,e=!1){return e?{h:Number(t&L),l:Number(t>>G&L)}:{h:Number(t>>G&L)|0,l:Number(t&L)|0}}function fe(t,e=!1){let n=new Uint32Array(t.length),r=new Uint32Array(t.length);for(let s=0;s<t.length;s++){let{h:o,l:i}=J(t[s],e);[n[s],r[s]]=[o,i]}return[n,r]}var me=(t,e)=>BigInt(t>>>0)<<G|BigInt(e>>>0);a.toBig=me;var ye=(t,e,n)=>t>>>n;a.shrSH=ye;var ge=(t,e,n)=>t<<32-n|e>>>n;a.shrSL=ge;var be=(t,e,n)=>t>>>n|e<<32-n;a.rotrSH=be;var Se=(t,e,n)=>t<<32-n|e>>>n;a.rotrSL=Se;var xe=(t,e,n)=>t<<64-n|e>>>n-32;a.rotrBH=xe;var we=(t,e,n)=>t>>>n-32|e<<64-n;a.rotrBL=we;var Ie=(t,e)=>e;a.rotr32H=Ie;var Ce=(t,e)=>t;a.rotr32L=Ce;var Te=(t,e,n)=>t<<n|e>>>32-n;a.rotlSH=Te;var ve=(t,e,n)=>e<<n|t>>>32-n;a.rotlSL=ve;var Ee=(t,e,n)=>e<<n-32|t>>>64-n;a.rotlBH=Ee;var Ae=(t,e,n)=>t<<n-32|e>>>64-n;a.rotlBL=Ae;function Pe(t,e,n,r){let s=(e>>>0)+(r>>>0);return{h:t+n+(s/2**32|0)|0,l:s|0}}var Oe=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0);a.add3L=Oe;var ke=(t,e,n,r)=>e+n+r+(t/2**32|0)|0;a.add3H=ke;var _e=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0);a.add4L=_e;var Me=(t,e,n,r,s)=>e+n+r+s+(t/2**32|0)|0;a.add4H=Me;var Le=(t,e,n,r,s)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(s>>>0);a.add5L=Le;var Ne=(t,e,n,r,s,o)=>e+n+r+s+o+(t/2**32|0)|0;a.add5H=Ne;var Et={fromBig:J,split:fe,toBig:me,shrSH:ye,shrSL:ge,rotrSH:be,rotrSL:Se,rotrBH:xe,rotrBL:we,rotr32H:Ie,rotr32L:Ce,rotlSH:Te,rotlSL:ve,rotlBH:Ee,rotlBL:Ae,add:Pe,add3L:Oe,add3H:ke,add4L:_e,add4H:Me,add5H:Ne,add5L:Le};a.default=Et});var Re=C(N=>{"use strict";Object.defineProperty(N,"__esModule",{value:!0});N.crypto=void 0;N.crypto=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0});var He=C(c=>{"use strict";Object.defineProperty(c,"__esModule",{value:!0});c.Hash=c.nextTick=c.byteSwapIfBE=c.byteSwap=c.isLE=c.rotl=c.rotr=c.createView=c.u32=c.u8=void 0;c.isBytes=At;c.byteSwap32=Nt;c.bytesToHex=Rt;c.hexToBytes=Bt;c.asyncLoop=Ht;c.utf8ToBytes=Ue;c.toBytes=D;c.concatBytes=jt;c.checkOpts=Ft;c.wrapConstructor=qt;c.wrapConstructorWithOpts=Vt;c.wrapXOFConstructorWithOpts=Wt;c.randomBytes=Kt;var v=Re(),Z=Y();function At(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}var Pt=t=>new Uint8Array(t.buffer,t.byteOffset,t.byteLength);c.u8=Pt;var Ot=t=>new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4));c.u32=Ot;var kt=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);c.createView=kt;var _t=(t,e)=>t<<32-e|t>>>e;c.rotr=_t;var Mt=(t,e)=>t<<e|t>>>32-e>>>0;c.rotl=Mt;c.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var Lt=t=>t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255;c.byteSwap=Lt;c.byteSwapIfBE=c.isLE?t=>t:t=>(0,c.byteSwap)(t);function Nt(t){for(let e=0;e<t.length;e++)t[e]=(0,c.byteSwap)(t[e])}var Dt=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Rt(t){(0,Z.bytes)(t);let e="";for(let n=0;n<t.length;n++)e+=Dt[t[n]];return e}var b={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Be(t){if(t>=b._0&&t<=b._9)return t-b._0;if(t>=b._A&&t<=b._F)return t-(b._A-10);if(t>=b._a&&t<=b._f)return t-(b._a-10)}function Bt(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);let e=t.length,n=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let r=new Uint8Array(n);for(let s=0,o=0;s<n;s++,o+=2){let i=Be(t.charCodeAt(o)),l=Be(t.charCodeAt(o+1));if(i===void 0||l===void 0){let p=t[o]+t[o+1];throw new Error('hex string expected, got non-hex character "'+p+'" at index '+o)}r[s]=i*16+l}return r}var Ut=async()=>{};c.nextTick=Ut;async function Ht(t,e,n){let r=Date.now();for(let s=0;s<t;s++){n(s);let o=Date.now()-r;o>=0&&o<e||(await(0,c.nextTick)(),r+=o)}}function Ue(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function D(t){return typeof t=="string"&&(t=Ue(t)),(0,Z.bytes)(t),t}function jt(...t){let e=0;for(let r=0;r<t.length;r++){let s=t[r];(0,Z.bytes)(s),e+=s.length}let n=new Uint8Array(e);for(let r=0,s=0;r<t.length;r++){let o=t[r];n.set(o,s),s+=o.length}return n}var X=class{clone(){return this._cloneInto()}};c.Hash=X;var $t={}.toString;function Ft(t,e){if(e!==void 0&&$t.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(t,e)}function qt(t){let e=r=>t().update(D(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function Vt(t){let e=(r,s)=>t(s).update(D(r)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}function Wt(t){let e=(r,s)=>t(s).update(D(r)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}function Kt(t=32){if(v.crypto&&typeof v.crypto.getRandomValues=="function")return v.crypto.getRandomValues(new Uint8Array(t));if(v.crypto&&typeof v.crypto.randomBytes=="function")return v.crypto.randomBytes(t);throw new Error("crypto.getRandomValues must be defined")}});var ze=C(d=>{"use strict";Object.defineProperty(d,"__esModule",{value:!0});d.shake256=d.shake128=d.keccak_512=d.keccak_384=d.keccak_256=d.keccak_224=d.sha3_512=d.sha3_384=d.sha3_256=d.sha3_224=d.Keccak=void 0;d.keccakP=We;var E=Y(),P=De(),S=He(),Fe=[],qe=[],Ve=[],zt=BigInt(0),A=BigInt(1),Qt=BigInt(2),Yt=BigInt(7),Gt=BigInt(256),Jt=BigInt(113);for(let t=0,e=A,n=1,r=0;t<24;t++){[n,r]=[r,(2*n+3*r)%5],Fe.push(2*(5*r+n)),qe.push((t+1)*(t+2)/2%64);let s=zt;for(let o=0;o<7;o++)e=(e<<A^(e>>Yt)*Jt)%Gt,e&Qt&&(s^=A<<(A<<BigInt(o))-A);Ve.push(s)}var[Xt,Zt]=(0,P.split)(Ve,!0),je=(t,e,n)=>n>32?(0,P.rotlBH)(t,e,n):(0,P.rotlSH)(t,e,n),$e=(t,e,n)=>n>32?(0,P.rotlBL)(t,e,n):(0,P.rotlSL)(t,e,n);function We(t,e=24){let n=new Uint32Array(10);for(let r=24-e;r<24;r++){for(let i=0;i<10;i++)n[i]=t[i]^t[i+10]^t[i+20]^t[i+30]^t[i+40];for(let i=0;i<10;i+=2){let l=(i+8)%10,p=(i+2)%10,h=n[p],u=n[p+1],f=je(h,u,1)^n[l],m=$e(h,u,1)^n[l+1];for(let x=0;x<50;x+=10)t[i+x]^=f,t[i+x+1]^=m}let s=t[2],o=t[3];for(let i=0;i<24;i++){let l=qe[i],p=je(s,o,l),h=$e(s,o,l),u=Fe[i];s=t[u],o=t[u+1],t[u]=p,t[u+1]=h}for(let i=0;i<50;i+=10){for(let l=0;l<10;l++)n[l]=t[i+l];for(let l=0;l<10;l++)t[i+l]^=~n[(l+2)%10]&n[(l+4)%10]}t[0]^=Xt[r],t[1]^=Zt[r]}n.fill(0)}var O=class t extends S.Hash{constructor(e,n,r,s=!1,o=24){if(super(),this.blockLen=e,this.suffix=n,this.outputLen=r,this.enableXOF=s,this.rounds=o,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,(0,E.number)(r),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=(0,S.u32)(this.state)}keccak(){S.isLE||(0,S.byteSwap32)(this.state32),We(this.state32,this.rounds),S.isLE||(0,S.byteSwap32)(this.state32),this.posOut=0,this.pos=0}update(e){(0,E.exists)(this);let{blockLen:n,state:r}=this;e=(0,S.toBytes)(e);let s=e.length;for(let o=0;o<s;){let i=Math.min(n-this.pos,s-o);for(let l=0;l<i;l++)r[this.pos++]^=e[o++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:n,pos:r,blockLen:s}=this;e[r]^=n,n&128&&r===s-1&&this.keccak(),e[s-1]^=128,this.keccak()}writeInto(e){(0,E.exists)(this,!1),(0,E.bytes)(e),this.finish();let n=this.state,{blockLen:r}=this;for(let s=0,o=e.length;s<o;){this.posOut>=r&&this.keccak();let i=Math.min(r-this.posOut,o-s);e.set(n.subarray(this.posOut,this.posOut+i),s),this.posOut+=i,s+=i}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return(0,E.number)(e),this.xofInto(new Uint8Array(e))}digestInto(e){if((0,E.output)(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){let{blockLen:n,suffix:r,outputLen:s,rounds:o,enableXOF:i}=this;return e||(e=new t(n,r,s,i,o)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=o,e.suffix=r,e.outputLen=s,e.enableXOF=i,e.destroyed=this.destroyed,e}};d.Keccak=O;var w=(t,e,n)=>(0,S.wrapConstructor)(()=>new O(e,t,n));d.sha3_224=w(6,144,224/8);d.sha3_256=w(6,136,256/8);d.sha3_384=w(6,104,384/8);d.sha3_512=w(6,72,512/8);d.keccak_224=w(1,144,224/8);d.keccak_256=w(1,136,256/8);d.keccak_384=w(1,104,384/8);d.keccak_512=w(1,72,512/8);var Ke=(t,e,n)=>(0,S.wrapXOFConstructorWithOpts)((r={})=>new O(e,t,r.dkLen===void 0?n:r.dkLen,!0));d.shake128=Ke(31,168,128/8);d.shake256=Ke(31,136,256/8)});var tt=C((Sn,I)=>{"use strict";var{sha3_512:en}=ze(),Ye=24,k=32,ee=(t=4,e=Math.random)=>{let n="";for(;n.length<t;)n=n+Math.floor(e()*36).toString(36);return n};function Ge(t){let e=BigInt(8),n=BigInt(0);for(let r of t.values()){let s=BigInt(r);n=(n<<e)+s}return n}var Je=(t="")=>Ge(en(t)).toString(36).slice(1),Qe=Array.from({length:26},(t,e)=>String.fromCharCode(e+97)),tn=t=>Qe[Math.floor(t()*Qe.length)],Xe=({globalObj:t=typeof global<"u"?global:typeof window<"u"?window:{},random:e=Math.random}={})=>{let n=Object.keys(t).toString(),r=n.length?n+ee(k,e):ee(k,e);return Je(r).substring(0,k)},Ze=t=>()=>t++,nn=476782367,et=({random:t=Math.random,counter:e=Ze(Math.floor(t()*nn)),length:n=Ye,fingerprint:r=Xe({random:t})}={})=>function(){let o=tn(t),i=Date.now().toString(36),l=e().toString(36),p=ee(n,t),h=`${i+p+l+r}`;return`${o+Je(h).substring(1,n)}`},rn=et(),sn=(t,{minLength:e=2,maxLength:n=k}={})=>{let r=t.length,s=/^[a-z][0-9a-z]+$/;try{if(typeof t=="string"&&r>=e&&r<=n&&s.test(t))return!0}finally{}return!1};I.exports.getConstants=()=>({defaultLength:Ye,bigLength:k});I.exports.init=et;I.exports.createId=rn;I.exports.bufToBigInt=Ge;I.exports.createCounter=Ze;I.exports.createFingerprint=Xe;I.exports.isCuid=sn});var R=C((xn,_)=>{"use strict";var{createId:on,init:an,getConstants:cn,isCuid:ln}=tt();_.exports.createId=on;_.exports.init=an;_.exports.getConstants=cn;_.exports.isCuid=ln});var pt=z(R(),1);var wn=Date.now().toString().slice(5);var nt=BigInt(1e3),rt=BigInt(1e6),st=BigInt(1e9);async function ot(t){return typeof t=="number"&&(t=BigInt(t)),t<nt?`${t}ns`:t<rt?`${t/nt}\u03BCs`:t<st?`${t/rt}ms`:`${t/st}s`}async function te(t){return{raw:Number(t),formatted:await ot(t)}}var at="2.0.1";var ct={name:"@oramacloud/client",version:at,description:"Orama SDK client for Node.js, Deno, and Browsers",type:"module",sideEffects:!1,main:"./dist/index.cjs",module:"./dist/index.js",types:"./dist/index.d.ts",runkitExampleFilename:"./example/runkit.js",exports:{".":{types:"./dist/index.d.ts",browser:"./dist/index.global.js",require:"./dist/index.cjs",import:"./dist/index.js"}},scripts:{watch:"tsup --config tsup.lib.js --watch src",build:"tsup --config tsup.lib.js",test:'glob -c "node --import tsx --no-warnings --test" "./tests/**/*.test.ts"',"serve:example":"esbuild src/index.ts --bundle --outfile=example/out.js --format=esm --watch --servedir=example"},keywords:["orama","search engine","sdk"],files:["dist","example/runkit.js"],author:{name:"Michele Riva",email:"michele.riva@oramasearch.com",url:"https://github.com/MicheleRiva"},license:"ISC",dependencies:{"@orama/cuid2":"^2.2.3","@orama/orama":"^2.0.16",lodash:"^4.17.21"},devDependencies:{"@fastify/formbody":"^7.4.0","@types/lodash":"^4.14.202","@types/node":"^20.3.1",dotenv:"^16.3.1",esbuild:"0.18.5",fastify:"^4.19.2",glob:"^11.0.0",husky:"^8.0.3","npm-run-all":"^4.1.5","ts-standard":"^12.0.2",tsup:"^8.3.0",tsx:"^4.7.0",typescript:"^5.1.3"},publishConfig:{access:"public"},"ts-standard":{ignore:["dist","node_modules"]}};var se=z(R(),1);var lt="https://answer.api.orama.com",ut="/v1/indexes",ne="orama_user_id";function dt(t){let[e,...n]=t.split(` | ||
`),r=n.join(` | ||
@@ -3,0 +3,0 @@ `).replace("data: ","");return{event:e.replace("event: ",""),data:r}}function re(t){return typeof t=="object"?JSON.stringify(t):`${t}`}var B=class{messages;inferenceType;oramaClient;endpoint;abortController;events;userContext;conversationID;lastInteractionParams;state=[];systemPrompts;constructor(e){let n=e.oramaClient.answersApiBaseURL||lt;this.messages=e.initialMessages||[],this.inferenceType=e.inferenceType,this.oramaClient=e.oramaClient,this.endpoint=`${n}/v1/answer?api-key=${this.oramaClient.api_key}`,this.events=e.events,this.conversationID=(0,se.createId)(),this.userContext=e.userContext}async askStream(e){return this.messages.push({role:"user",content:e.term??""}),this.fetchAnswer(e)}async ask(e){let n=await this.askStream(e),r="";for await(let s of n)r=s;return this.events?.onMessageChange&&this.events.onMessageChange(this.messages),r}getMessages(){return this.messages}clearSession(){this.messages=[],this.state=[],this.events?.onMessageChange&&this.events.onMessageChange(this.messages),this.events?.onStateChange&&this.events.onStateChange(this.state)}abortAnswer(){if(!this.abortController)throw new Error("AbortController is not ready");this.abortController.abort(),this.abortController=void 0,this.state[this.state.length-1].aborted=!0}async regenerateLast({stream:e=!0}={}){if(this.state.length===0||this.messages.length===0)throw new Error("No messages to regenerate");if(!(this.messages.at(-1)?.role==="assistant"))throw new Error("Last message is not an assistant message");return this.messages.pop(),this.state.pop(),e?this.askStream(this.lastInteractionParams):this.ask(this.lastInteractionParams)}addNewEmptyAssistantMessage(){this.messages.push({role:"assistant",content:""})}async*fetchAnswer(e){this.abortController=new AbortController,this.lastInteractionParams=e;let n=(0,se.createId)(),r=null,s=this.state.length;this.state.push({interactionId:n,query:e.term??"",response:"",relatedQueries:null,sources:null,translatedQuery:null,aborted:!1,loading:!0,error:!1,errorMessage:null});try{this.events?.onNewInteractionStarted&&this.events.onNewInteractionStarted(n),this.events?.onStateChange&&this.events.onStateChange(this.state);let o=new URLSearchParams;o.append("type",this.inferenceType),o.append("messages",JSON.stringify(this.messages)),o.append("query",e.term??""),o.append("conversationId",this.conversationID),o.append("userId",this.oramaClient.getUserId()),o.append("endpoint",this.oramaClient.endpoint),o.append("searchParams",JSON.stringify(e)),o.append("identity",this.oramaClient.getIdentity()??""),o.append("interactionId",n),o.append("alias",this.oramaClient.getAlias()??"");let i=this.getSystemPromptConfiguration();if(i&&o.append("systemPrompts",JSON.stringify(i)),this.userContext&&o.append("userContext",re(this.userContext)),e.userData&&o.append("userData",re(e.userData)),e.related){if(e.related?.howMany&&e.related?.howMany>5)throw new Error("Can generate at most 5 related queries");o.append("related",JSON.stringify({enabled:!0,howMany:e.related.howMany??3,format:e.related.format??"question"}))}let l=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:o.toString(),signal:this.abortController.signal});if(!l.ok||!l.body)throw new Error(l.statusText);r=l.body.getReader();let p=new TextDecoder,h=[],u="";this.events?.onMessageLoading&&this.events.onMessageLoading(!0),this.addNewEmptyAssistantMessage();let f=this.messages.at(-1);for(;;){let{value:m,done:x}=await r.read();if(x)break;u+=p.decode(m,{stream:!0});let W;for(;(W=u.indexOf(` |
{ | ||
"name": "@oramacloud/client", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Orama SDK client for Node.js, Deno, and Browsers", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12