Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@oramacloud/client

Package Overview
Dependencies
Maintainers
0
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@oramacloud/client - npm Package Compare versions

Comparing version 2.1.0 to 2.1.1

2

dist/index.global.js

@@ -11,3 +11,3 @@ "use strict";var OramaClient=(()=>{var vt=Object.create;var M=Object.defineProperty;var Ct=Object.getOwnPropertyDescriptor;var _t=Object.getOwnPropertyNames;var Nt=Object.getPrototypeOf,Dt=Object.prototype.hasOwnProperty;var A=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),kt=(t,e)=>{for(var n in e)M(t,n,{get:e[n],enumerable:!0})},ye=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of _t(e))!Dt.call(t,s)&&s!==n&&M(t,s,{get:()=>e[s],enumerable:!(r=Ct(e,s))||r.enumerable});return t};var X=(t,e,n)=>(n=t!=null?vt(Nt(t)):{},ye(e||!t||!t.__esModule?M(n,"default",{value:t,enumerable:!0}):n,t)),Lt=t=>ye(M({},"__esModule",{value:!0}),t);var Z=A(y=>{"use strict";Object.defineProperty(y,"__esModule",{value:!0});y.isBytes=be;y.number=B;y.bool=Se;y.bytes=Q;y.hash=Ie;y.exists=Te;y.output=we;function B(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`positive integer expected, not ${t}`)}function Se(t){if(typeof t!="boolean")throw new Error(`boolean expected, not ${t}`)}function be(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function Q(t,...e){if(!be(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 Ie(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");B(t.outputLen),B(t.blockLen)}function Te(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 we(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 Rt={number:B,bool:Se,bytes:Q,hash:Ie,exists:Te,output:we};y.default=Rt});var $e=A(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=te;a.split=xe;a.add=Be;var U=BigInt(2**32-1),ee=BigInt(32);function te(t,e=!1){return e?{h:Number(t&U),l:Number(t>>ee&U)}:{h:Number(t>>ee&U)|0,l:Number(t&U)|0}}function xe(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}=te(t[s],e);[n[s],r[s]]=[o,i]}return[n,r]}var Ae=(t,e)=>BigInt(t>>>0)<<ee|BigInt(e>>>0);a.toBig=Ae;var Oe=(t,e,n)=>t>>>n;a.shrSH=Oe;var Ee=(t,e,n)=>t<<32-n|e>>>n;a.shrSL=Ee;var Pe=(t,e,n)=>t>>>n|e<<32-n;a.rotrSH=Pe;var ve=(t,e,n)=>t<<32-n|e>>>n;a.rotrSL=ve;var Ce=(t,e,n)=>t<<64-n|e>>>n-32;a.rotrBH=Ce;var _e=(t,e,n)=>t>>>n-32|e<<64-n;a.rotrBL=_e;var Ne=(t,e)=>e;a.rotr32H=Ne;var De=(t,e)=>t;a.rotr32L=De;var ke=(t,e,n)=>t<<n|e>>>32-n;a.rotlSH=ke;var Le=(t,e,n)=>e<<n|t>>>32-n;a.rotlSL=Le;var Re=(t,e,n)=>e<<n-32|t>>>64-n;a.rotlBH=Re;var Me=(t,e,n)=>t<<n-32|e>>>64-n;a.rotlBL=Me;function Be(t,e,n,r){let s=(e>>>0)+(r>>>0);return{h:t+n+(s/2**32|0)|0,l:s|0}}var Ue=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0);a.add3L=Ue;var ze=(t,e,n,r)=>e+n+r+(t/2**32|0)|0;a.add3H=ze;var He=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0);a.add4L=He;var Fe=(t,e,n,r,s)=>e+n+r+s+(t/2**32|0)|0;a.add4H=Fe;var We=(t,e,n,r,s)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(s>>>0);a.add5L=We;var Ve=(t,e,n,r,s,o)=>e+n+r+s+o+(t/2**32|0)|0;a.add5H=Ve;var Mt={fromBig:te,split:xe,toBig:Ae,shrSH:Oe,shrSL:Ee,rotrSH:Pe,rotrSL:ve,rotrBH:Ce,rotrBL:_e,rotr32H:Ne,rotr32L:De,rotlSH:ke,rotlSL:Le,rotlBH:Re,rotlBL:Me,add:Be,add3L:Ue,add3H:ze,add4L:He,add4H:Fe,add5H:Ve,add5L:We};a.default=Mt});var je=A(z=>{"use strict";Object.defineProperty(z,"__esModule",{value:!0});z.crypto=void 0;z.crypto=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0});var qe=A(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=Bt;c.byteSwap32=$t;c.bytesToHex=Jt;c.hexToBytes=Kt;c.asyncLoop=Gt;c.utf8ToBytes=Ke;c.toBytes=H;c.concatBytes=Yt;c.checkOpts=Qt;c.wrapConstructor=Zt;c.wrapConstructorWithOpts=en;c.wrapXOFConstructorWithOpts=tn;c.randomBytes=nn;var E=je(),re=Z();function Bt(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}var Ut=t=>new Uint8Array(t.buffer,t.byteOffset,t.byteLength);c.u8=Ut;var zt=t=>new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4));c.u32=zt;var Ht=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);c.createView=Ht;var Ft=(t,e)=>t<<32-e|t>>>e;c.rotr=Ft;var Wt=(t,e)=>t<<e|t>>>32-e>>>0;c.rotl=Wt;c.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var Vt=t=>t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255;c.byteSwap=Vt;c.byteSwapIfBE=c.isLE?t=>t:t=>(0,c.byteSwap)(t);function $t(t){for(let e=0;e<t.length;e++)t[e]=(0,c.byteSwap)(t[e])}var jt=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Jt(t){(0,re.bytes)(t);let e="";for(let n=0;n<t.length;n++)e+=jt[t[n]];return e}var S={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Je(t){if(t>=S._0&&t<=S._9)return t-S._0;if(t>=S._A&&t<=S._F)return t-(S._A-10);if(t>=S._a&&t<=S._f)return t-(S._a-10)}function Kt(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 f=t[o]+t[o+1];throw new Error('hex string expected, got non-hex character "'+f+'" at index '+o)}r[s]=i*16+l}return r}var qt=async()=>{};c.nextTick=qt;async function Gt(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 Ke(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function H(t){return typeof t=="string"&&(t=Ke(t)),(0,re.bytes)(t),t}function Yt(...t){let e=0;for(let r=0;r<t.length;r++){let s=t[r];(0,re.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 ne=class{clone(){return this._cloneInto()}};c.Hash=ne;var Xt={}.toString;function Qt(t,e){if(e!==void 0&&Xt.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(t,e)}function Zt(t){let e=r=>t().update(H(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function en(t){let e=(r,s)=>t(s).update(H(r)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}function tn(t){let e=(r,s)=>t(s).update(H(r)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}function nn(t=32){if(E.crypto&&typeof E.crypto.getRandomValues=="function")return E.crypto.getRandomValues(new Uint8Array(t));if(E.crypto&&typeof E.crypto.randomBytes=="function")return E.crypto.randomBytes(t);throw new Error("crypto.getRandomValues must be defined")}});var nt=A(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=et;var P=Z(),C=$e(),b=qe(),Xe=[],Qe=[],Ze=[],rn=BigInt(0),v=BigInt(1),sn=BigInt(2),on=BigInt(7),an=BigInt(256),cn=BigInt(113);for(let t=0,e=v,n=1,r=0;t<24;t++){[n,r]=[r,(2*n+3*r)%5],Xe.push(2*(5*r+n)),Qe.push((t+1)*(t+2)/2%64);let s=rn;for(let o=0;o<7;o++)e=(e<<v^(e>>on)*cn)%an,e&sn&&(s^=v<<(v<<BigInt(o))-v);Ze.push(s)}var[ln,un]=(0,C.split)(Ze,!0),Ge=(t,e,n)=>n>32?(0,C.rotlBH)(t,e,n):(0,C.rotlSH)(t,e,n),Ye=(t,e,n)=>n>32?(0,C.rotlBL)(t,e,n):(0,C.rotlSL)(t,e,n);function et(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,f=(i+2)%10,h=n[f],u=n[f+1],p=Ge(h,u,1)^n[l],m=Ye(h,u,1)^n[l+1];for(let I=0;I<50;I+=10)t[i+I]^=p,t[i+I+1]^=m}let s=t[2],o=t[3];for(let i=0;i<24;i++){let l=Qe[i],f=Ge(s,o,l),h=Ye(s,o,l),u=Xe[i];s=t[u],o=t[u+1],t[u]=f,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]^=ln[r],t[1]^=un[r]}n.fill(0)}var _=class t extends b.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,P.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,b.u32)(this.state)}keccak(){b.isLE||(0,b.byteSwap32)(this.state32),et(this.state32,this.rounds),b.isLE||(0,b.byteSwap32)(this.state32),this.posOut=0,this.pos=0}update(e){(0,P.exists)(this);let{blockLen:n,state:r}=this;e=(0,b.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,P.exists)(this,!1),(0,P.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,P.number)(e),this.xofInto(new Uint8Array(e))}digestInto(e){if((0,P.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=_;var T=(t,e,n)=>(0,b.wrapConstructor)(()=>new _(e,t,n));d.sha3_224=T(6,144,224/8);d.sha3_256=T(6,136,256/8);d.sha3_384=T(6,104,384/8);d.sha3_512=T(6,72,512/8);d.keccak_224=T(1,144,224/8);d.keccak_256=T(1,136,256/8);d.keccak_384=T(1,104,384/8);d.keccak_512=T(1,72,512/8);var tt=(t,e,n)=>(0,b.wrapXOFConstructorWithOpts)((r={})=>new _(e,t,r.dkLen===void 0?n:r.dkLen,!0));d.shake128=tt(31,168,128/8);d.shake256=tt(31,136,256/8)});var ut=A((Hn,w)=>{"use strict";var{sha3_512:dn}=nt(),st=24,N=32,se=(t=4,e=Math.random)=>{let n="";for(;n.length<t;)n=n+Math.floor(e()*36).toString(36);return n};function ot(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 it=(t="")=>ot(dn(t)).toString(36).slice(1),rt=Array.from({length:26},(t,e)=>String.fromCharCode(e+97)),hn=t=>rt[Math.floor(t()*rt.length)],at=({globalObj:t=typeof global<"u"?global:typeof window<"u"?window:{},random:e=Math.random}={})=>{let n=Object.keys(t).toString(),r=n.length?n+se(N,e):se(N,e);return it(r).substring(0,N)},ct=t=>()=>t++,fn=476782367,lt=({random:t=Math.random,counter:e=ct(Math.floor(t()*fn)),length:n=st,fingerprint:r=at({random:t})}={})=>function(){let o=hn(t),i=Date.now().toString(36),l=e().toString(36),f=se(n,t),h=`${i+f+l+r}`;return`${o+it(h).substring(1,n)}`},pn=lt(),mn=(t,{minLength:e=2,maxLength:n=N}={})=>{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};w.exports.getConstants=()=>({defaultLength:st,bigLength:N});w.exports.init=lt;w.exports.createId=pn;w.exports.bufToBigInt=ot;w.exports.createCounter=ct;w.exports.createFingerprint=at;w.exports.isCuid=mn});var F=A((Fn,D)=>{"use strict";var{createId:gn,init:yn,getConstants:Sn,isCuid:bn}=ut();D.exports.createId=gn;D.exports.init=yn;D.exports.getConstants=Sn;D.exports.isCuid=bn});var kn={};kt(kn,{AnswerSession:()=>R,CloudManager:()=>fe,OramaClient:()=>de});var xt=X(F(),1);var In={arabic:"ar",armenian:"am",bulgarian:"bg",danish:"dk",dutch:"nl",english:"en",finnish:"fi",french:"fr",german:"de",greek:"gr",hungarian:"hu",indian:"in",indonesian:"id",irish:"ie",italian:"it",lithuanian:"lt",nepali:"np",norwegian:"no",portuguese:"pt",romanian:"ro",russian:"ru",serbian:"rs",slovenian:"ru",spanish:"es",swedish:"se",tamil:"ta",turkish:"tr",ukrainian:"uk",sanskrit:"sk"};var oe=Object.keys(In);var $n=Date.now().toString().slice(5);var dt=BigInt(1e3),ht=BigInt(1e6),ft=BigInt(1e9);function pt(t){return typeof t=="number"&&(t=BigInt(t)),t<dt?`${t}ns`:t<ht?`${t/dt}\u03BCs`:t<ft?`${t/ht}ms`:`${t/ft}s`}var jn="intersection"in new Set;var Jn="union"in new Set;var Tn=oe.join(`

Read more at https://docs.orama.com/open-source/plugins/plugin-secure-proxy
`,ANSWER_SESSION_LAST_MESSAGE_IS_NOT_ASSISTANT:"The last message in the session is not an assistant message. Cannot regenerate non-assistant messages.",PLUGIN_COMPONENT_CONFLICT:'The component "%s" is already defined. The plugin "%s" is trying to redefine it.'};function ie(t){return{raw:Number(t),formatted:pt(t)}}var Pn="[^aeiou]",gt="[aeiouy]",x=Pn+"[^aeiouy]*",L=gt+"[aeiou]*",$r="^("+x+")?"+L+x,jr="^("+x+")?"+L+x+"("+L+")?$",Jr="^("+x+")?"+L+x+L+x,Kr="^("+x+")?"+gt;var St="2.1.0";var bt={name:"@oramacloud/client",version:St,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":"^3.0.0",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 le=X(F(),1);var It="https://answer.api.orama.com",Tt="/v1/indexes",ae="orama_user_id";function wt(t){let[e,...n]=t.split(`
`,ANSWER_SESSION_LAST_MESSAGE_IS_NOT_ASSISTANT:"The last message in the session is not an assistant message. Cannot regenerate non-assistant messages.",PLUGIN_COMPONENT_CONFLICT:'The component "%s" is already defined. The plugin "%s" is trying to redefine it.'};function ie(t){return{raw:Number(t),formatted:pt(t)}}var Pn="[^aeiou]",gt="[aeiouy]",x=Pn+"[^aeiouy]*",L=gt+"[aeiou]*",$r="^("+x+")?"+L+x,jr="^("+x+")?"+L+x+"("+L+")?$",Jr="^("+x+")?"+L+x+L+x,Kr="^("+x+")?"+gt;var St="2.1.1";var bt={name:"@oramacloud/client",version:St,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":"^3.0.0",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 le=X(F(),1);var It="https://answer.api.orama.com",Tt="/v1/indexes",ae="orama_user_id";function wt(t){let[e,...n]=t.split(`
`),r=n.join(`

@@ -14,0 +14,0 @@ `).replace("data: ","");return{event:e.replace("event: ",""),data:r}}function ce(t){return typeof t=="object"?JSON.stringify(t):`${t}`}var R=class{messages;inferenceType;oramaClient;endpoint;abortController;events;userContext;conversationID;lastInteractionParams;state=[];systemPrompts;constructor(e){let n=e.oramaClient.answersApiBaseURL||It;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,le.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,le.createId)(),r=null,s=this.state.length;this.state.push({interactionId:n,query:e.term??"",response:"",relatedQueries:null,sources:null,translatedQuery:null,segment:null,trigger: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",ce(this.userContext)),e.userData&&o.append("userData",ce(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 f=new TextDecoder,h=[],u="";this.events?.onMessageLoading&&this.events.onMessageLoading(!0),this.addNewEmptyAssistantMessage();let p=this.messages.at(-1);for(;;){let{value:m,done:I}=await r.read();if(I)break;u+=f.decode(m,{stream:!0});let G;for(;(G=u.indexOf(`

@@ -11,3 +11,3 @@ var Pt=Object.create;var pe=Object.defineProperty;var vt=Object.getOwnPropertyDescriptor;var Ct=Object.getOwnPropertyNames;var _t=Object.getPrototypeOf,Nt=Object.prototype.hasOwnProperty;var A=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Dt=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Ct(e))!Nt.call(t,s)&&s!==n&&pe(t,s,{get:()=>e[s],enumerable:!(r=vt(e,s))||r.enumerable});return t};var Y=(t,e,n)=>(n=t!=null?Pt(_t(t)):{},Dt(e||!t||!t.__esModule?pe(n,"default",{value:t,enumerable:!0}):n,t));var Q=A(y=>{"use strict";Object.defineProperty(y,"__esModule",{value:!0});y.isBytes=ge;y.number=R;y.bool=me;y.bytes=X;y.hash=ye;y.exists=Se;y.output=be;function R(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`positive integer expected, not ${t}`)}function me(t){if(typeof t!="boolean")throw new Error(`boolean expected, not ${t}`)}function ge(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function X(t,...e){if(!ge(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 ye(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");R(t.outputLen),R(t.blockLen)}function Se(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 be(t,e){X(t);let n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}var kt={number:R,bool:me,bytes:X,hash:ye,exists:Se,output:be};y.default=kt});var Fe=A(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=ee;a.split=Ie;a.add=Le;var M=BigInt(2**32-1),Z=BigInt(32);function ee(t,e=!1){return e?{h:Number(t&M),l:Number(t>>Z&M)}:{h:Number(t>>Z&M)|0,l:Number(t&M)|0}}function Ie(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}=ee(t[s],e);[n[s],r[s]]=[o,i]}return[n,r]}var Te=(t,e)=>BigInt(t>>>0)<<Z|BigInt(e>>>0);a.toBig=Te;var we=(t,e,n)=>t>>>n;a.shrSH=we;var xe=(t,e,n)=>t<<32-n|e>>>n;a.shrSL=xe;var Ae=(t,e,n)=>t>>>n|e<<32-n;a.rotrSH=Ae;var Oe=(t,e,n)=>t<<32-n|e>>>n;a.rotrSL=Oe;var Ee=(t,e,n)=>t<<64-n|e>>>n-32;a.rotrBH=Ee;var Pe=(t,e,n)=>t>>>n-32|e<<64-n;a.rotrBL=Pe;var ve=(t,e)=>e;a.rotr32H=ve;var Ce=(t,e)=>t;a.rotr32L=Ce;var _e=(t,e,n)=>t<<n|e>>>32-n;a.rotlSH=_e;var Ne=(t,e,n)=>e<<n|t>>>32-n;a.rotlSL=Ne;var De=(t,e,n)=>e<<n-32|t>>>64-n;a.rotlBH=De;var ke=(t,e,n)=>t<<n-32|e>>>64-n;a.rotlBL=ke;function Le(t,e,n,r){let s=(e>>>0)+(r>>>0);return{h:t+n+(s/2**32|0)|0,l:s|0}}var Re=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0);a.add3L=Re;var Me=(t,e,n,r)=>e+n+r+(t/2**32|0)|0;a.add3H=Me;var Be=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0);a.add4L=Be;var Ue=(t,e,n,r,s)=>e+n+r+s+(t/2**32|0)|0;a.add4H=Ue;var ze=(t,e,n,r,s)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(s>>>0);a.add5L=ze;var He=(t,e,n,r,s,o)=>e+n+r+s+o+(t/2**32|0)|0;a.add5H=He;var Lt={fromBig:ee,split:Ie,toBig:Te,shrSH:we,shrSL:xe,rotrSH:Ae,rotrSL:Oe,rotrBH:Ee,rotrBL:Pe,rotr32H:ve,rotr32L:Ce,rotlSH:_e,rotlSL:Ne,rotlBH:De,rotlBL:ke,add:Le,add3L:Re,add3H:Me,add4L:Be,add4H:Ue,add5H:He,add5L:ze};a.default=Lt});var We=A(B=>{"use strict";Object.defineProperty(B,"__esModule",{value:!0});B.crypto=void 0;B.crypto=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0});var je=A(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=Rt;c.byteSwap32=Wt;c.bytesToHex=$t;c.hexToBytes=jt;c.asyncLoop=Kt;c.utf8ToBytes=$e;c.toBytes=U;c.concatBytes=qt;c.checkOpts=Yt;c.wrapConstructor=Xt;c.wrapConstructorWithOpts=Qt;c.wrapXOFConstructorWithOpts=Zt;c.randomBytes=en;var E=We(),ne=Q();function Rt(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}var Mt=t=>new Uint8Array(t.buffer,t.byteOffset,t.byteLength);c.u8=Mt;var Bt=t=>new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4));c.u32=Bt;var Ut=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);c.createView=Ut;var zt=(t,e)=>t<<32-e|t>>>e;c.rotr=zt;var Ht=(t,e)=>t<<e|t>>>32-e>>>0;c.rotl=Ht;c.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var Ft=t=>t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255;c.byteSwap=Ft;c.byteSwapIfBE=c.isLE?t=>t:t=>(0,c.byteSwap)(t);function Wt(t){for(let e=0;e<t.length;e++)t[e]=(0,c.byteSwap)(t[e])}var Vt=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function $t(t){(0,ne.bytes)(t);let e="";for(let n=0;n<t.length;n++)e+=Vt[t[n]];return e}var S={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Ve(t){if(t>=S._0&&t<=S._9)return t-S._0;if(t>=S._A&&t<=S._F)return t-(S._A-10);if(t>=S._a&&t<=S._f)return t-(S._a-10)}function jt(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=Ve(t.charCodeAt(o)),l=Ve(t.charCodeAt(o+1));if(i===void 0||l===void 0){let f=t[o]+t[o+1];throw new Error('hex string expected, got non-hex character "'+f+'" at index '+o)}r[s]=i*16+l}return r}var Jt=async()=>{};c.nextTick=Jt;async function Kt(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 U(t){return typeof t=="string"&&(t=$e(t)),(0,ne.bytes)(t),t}function qt(...t){let e=0;for(let r=0;r<t.length;r++){let s=t[r];(0,ne.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 te=class{clone(){return this._cloneInto()}};c.Hash=te;var Gt={}.toString;function Yt(t,e){if(e!==void 0&&Gt.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(t,e)}function Xt(t){let e=r=>t().update(U(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function Qt(t){let e=(r,s)=>t(s).update(U(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(U(r)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}function en(t=32){if(E.crypto&&typeof E.crypto.getRandomValues=="function")return E.crypto.getRandomValues(new Uint8Array(t));if(E.crypto&&typeof E.crypto.randomBytes=="function")return E.crypto.randomBytes(t);throw new Error("crypto.getRandomValues must be defined")}});var Ze=A(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=Xe;var P=Q(),C=Fe(),b=je(),qe=[],Ge=[],Ye=[],tn=BigInt(0),v=BigInt(1),nn=BigInt(2),rn=BigInt(7),sn=BigInt(256),on=BigInt(113);for(let t=0,e=v,n=1,r=0;t<24;t++){[n,r]=[r,(2*n+3*r)%5],qe.push(2*(5*r+n)),Ge.push((t+1)*(t+2)/2%64);let s=tn;for(let o=0;o<7;o++)e=(e<<v^(e>>rn)*on)%sn,e&nn&&(s^=v<<(v<<BigInt(o))-v);Ye.push(s)}var[an,cn]=(0,C.split)(Ye,!0),Je=(t,e,n)=>n>32?(0,C.rotlBH)(t,e,n):(0,C.rotlSH)(t,e,n),Ke=(t,e,n)=>n>32?(0,C.rotlBL)(t,e,n):(0,C.rotlSL)(t,e,n);function Xe(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,f=(i+2)%10,h=n[f],u=n[f+1],p=Je(h,u,1)^n[l],m=Ke(h,u,1)^n[l+1];for(let I=0;I<50;I+=10)t[i+I]^=p,t[i+I+1]^=m}let s=t[2],o=t[3];for(let i=0;i<24;i++){let l=Ge[i],f=Je(s,o,l),h=Ke(s,o,l),u=qe[i];s=t[u],o=t[u+1],t[u]=f,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]^=an[r],t[1]^=cn[r]}n.fill(0)}var _=class t extends b.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,P.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,b.u32)(this.state)}keccak(){b.isLE||(0,b.byteSwap32)(this.state32),Xe(this.state32,this.rounds),b.isLE||(0,b.byteSwap32)(this.state32),this.posOut=0,this.pos=0}update(e){(0,P.exists)(this);let{blockLen:n,state:r}=this;e=(0,b.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,P.exists)(this,!1),(0,P.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,P.number)(e),this.xofInto(new Uint8Array(e))}digestInto(e){if((0,P.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=_;var T=(t,e,n)=>(0,b.wrapConstructor)(()=>new _(e,t,n));d.sha3_224=T(6,144,224/8);d.sha3_256=T(6,136,256/8);d.sha3_384=T(6,104,384/8);d.sha3_512=T(6,72,512/8);d.keccak_224=T(1,144,224/8);d.keccak_256=T(1,136,256/8);d.keccak_384=T(1,104,384/8);d.keccak_512=T(1,72,512/8);var Qe=(t,e,n)=>(0,b.wrapXOFConstructorWithOpts)((r={})=>new _(e,t,r.dkLen===void 0?n:r.dkLen,!0));d.shake128=Qe(31,168,128/8);d.shake256=Qe(31,136,256/8)});var at=A((Bn,w)=>{"use strict";var{sha3_512:ln}=Ze(),tt=24,N=32,re=(t=4,e=Math.random)=>{let n="";for(;n.length<t;)n=n+Math.floor(e()*36).toString(36);return n};function nt(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 rt=(t="")=>nt(ln(t)).toString(36).slice(1),et=Array.from({length:26},(t,e)=>String.fromCharCode(e+97)),un=t=>et[Math.floor(t()*et.length)],st=({globalObj:t=typeof global<"u"?global:typeof window<"u"?window:{},random:e=Math.random}={})=>{let n=Object.keys(t).toString(),r=n.length?n+re(N,e):re(N,e);return rt(r).substring(0,N)},ot=t=>()=>t++,dn=476782367,it=({random:t=Math.random,counter:e=ot(Math.floor(t()*dn)),length:n=tt,fingerprint:r=st({random:t})}={})=>function(){let o=un(t),i=Date.now().toString(36),l=e().toString(36),f=re(n,t),h=`${i+f+l+r}`;return`${o+rt(h).substring(1,n)}`},hn=it(),fn=(t,{minLength:e=2,maxLength:n=N}={})=>{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};w.exports.getConstants=()=>({defaultLength:tt,bigLength:N});w.exports.init=it;w.exports.createId=hn;w.exports.bufToBigInt=nt;w.exports.createCounter=ot;w.exports.createFingerprint=st;w.exports.isCuid=fn});var z=A((Un,D)=>{"use strict";var{createId:pn,init:mn,getConstants:gn,isCuid:yn}=at();D.exports.createId=pn;D.exports.init=mn;D.exports.getConstants=gn;D.exports.isCuid=yn});var Tt=Y(z(),1);var Sn={arabic:"ar",armenian:"am",bulgarian:"bg",danish:"dk",dutch:"nl",english:"en",finnish:"fi",french:"fr",german:"de",greek:"gr",hungarian:"hu",indian:"in",indonesian:"id",irish:"ie",italian:"it",lithuanian:"lt",nepali:"np",norwegian:"no",portuguese:"pt",romanian:"ro",russian:"ru",serbian:"rs",slovenian:"ru",spanish:"es",swedish:"se",tamil:"ta",turkish:"tr",ukrainian:"uk",sanskrit:"sk"};var se=Object.keys(Sn);var Fn=Date.now().toString().slice(5);var ct=BigInt(1e3),lt=BigInt(1e6),ut=BigInt(1e9);function dt(t){return typeof t=="number"&&(t=BigInt(t)),t<ct?`${t}ns`:t<lt?`${t/ct}\u03BCs`:t<ut?`${t/lt}ms`:`${t/ut}s`}var Wn="intersection"in new Set;var Vn="union"in new Set;var bn=se.join(`

Read more at https://docs.orama.com/open-source/plugins/plugin-secure-proxy
`,ANSWER_SESSION_LAST_MESSAGE_IS_NOT_ASSISTANT:"The last message in the session is not an assistant message. Cannot regenerate non-assistant messages.",PLUGIN_COMPONENT_CONFLICT:'The component "%s" is already defined. The plugin "%s" is trying to redefine it.'};function oe(t){return{raw:Number(t),formatted:dt(t)}}var On="[^aeiou]",ft="[aeiouy]",x=On+"[^aeiouy]*",L=ft+"[aeiou]*",Fr="^("+x+")?"+L+x,Wr="^("+x+")?"+L+x+"("+L+")?$",Vr="^("+x+")?"+L+x+L+x,$r="^("+x+")?"+ft;var mt="2.1.0";var gt={name:"@oramacloud/client",version:mt,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":"^3.0.0",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 ce=Y(z(),1);var yt="https://answer.api.orama.com",St="/v1/indexes",ie="orama_user_id";function bt(t){let[e,...n]=t.split(`
`,ANSWER_SESSION_LAST_MESSAGE_IS_NOT_ASSISTANT:"The last message in the session is not an assistant message. Cannot regenerate non-assistant messages.",PLUGIN_COMPONENT_CONFLICT:'The component "%s" is already defined. The plugin "%s" is trying to redefine it.'};function oe(t){return{raw:Number(t),formatted:dt(t)}}var On="[^aeiou]",ft="[aeiouy]",x=On+"[^aeiouy]*",L=ft+"[aeiou]*",Fr="^("+x+")?"+L+x,Wr="^("+x+")?"+L+x+"("+L+")?$",Vr="^("+x+")?"+L+x+L+x,$r="^("+x+")?"+ft;var mt="2.1.1";var gt={name:"@oramacloud/client",version:mt,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":"^3.0.0",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 ce=Y(z(),1);var yt="https://answer.api.orama.com",St="/v1/indexes",ie="orama_user_id";function bt(t){let[e,...n]=t.split(`
`),r=n.join(`

@@ -14,0 +14,0 @@ `).replace("data: ","");return{event:e.replace("event: ",""),data:r}}function ae(t){return typeof t=="object"?JSON.stringify(t):`${t}`}var H=class{messages;inferenceType;oramaClient;endpoint;abortController;events;userContext;conversationID;lastInteractionParams;state=[];systemPrompts;constructor(e){let n=e.oramaClient.answersApiBaseURL||yt;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,ce.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,ce.createId)(),r=null,s=this.state.length;this.state.push({interactionId:n,query:e.term??"",response:"",relatedQueries:null,sources:null,translatedQuery:null,segment:null,trigger: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",ae(this.userContext)),e.userData&&o.append("userData",ae(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 f=new TextDecoder,h=[],u="";this.events?.onMessageLoading&&this.events.onMessageLoading(!0),this.addNewEmptyAssistantMessage();let p=this.messages.at(-1);for(;;){let{value:m,done:I}=await r.read();if(I)break;u+=f.decode(m,{stream:!0});let q;for(;(q=u.indexOf(`

{
"name": "@oramacloud/client",
"version": "2.1.0",
"version": "2.1.1",
"description": "Orama SDK client for Node.js, Deno, and Browsers",

@@ -12,8 +12,6 @@ "type": "module",

"exports": {
".": {
"types": "./dist/index.d.ts",
"browser": "./dist/index.global.js",
"require": "./dist/index.cjs",
"import": "./dist/index.js"
}
"types": "./dist/index.d.ts",
"browser": "./dist/index.global.js",
"require": "./dist/index.cjs",
"import": "./dist/index.js"
},

@@ -20,0 +18,0 @@ "keywords": [

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc