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

@oramacloud/client

Package Overview
Dependencies
Maintainers
4
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 1.0.0-beta.23 to 1.0.0

22

dist/index.d.ts
import { SearchParams, AnyOrama, Results, AnyDocument } from '@orama/orama';
import { OpenAI } from 'openai';

@@ -44,2 +45,15 @@ interface IOramaClient {

type EmbeddingModel = keyof typeof embeddingsModels;
type ChatModel = keyof typeof chatModels;
type ChatMessage = OpenAI.ChatCompletionMessageParam;
type ChatParams = {
messages: ChatMessage[];
model: ChatModel;
};
declare const embeddingsModels: {
[x: string]: string;
};
declare const chatModels: {
[x: string]: string;
};
declare class OramaProxy {

@@ -50,9 +64,11 @@ private CSRFToken;

constructor(params: IOramaProxy);
generateEmbeddings(text: string): Promise<number[]>;
chat<T = unknown>(messages: T[], onChunk: (chunk: string) => any): Promise<void>;
generateEmbeddings(text: string, model: EmbeddingModel): Promise<number[]>;
chat(params: ChatParams): Promise<string>;
chatStream(params: ChatParams): AsyncGenerator<string>;
private init;
private isServer;
private getHeaders;
private getReferrer;
}
export { OramaClient, OramaProxy, SearchConfig };
export { ChatMessage, ChatModel, ChatParams, EmbeddingModel, OramaClient, OramaProxy, SearchConfig };

2

dist/index.global.js

@@ -1,2 +0,2 @@

"use strict";var OramaClient=(()=>{var Dt=Object.create;var E=Object.defineProperty;var Mt=Object.getOwnPropertyDescriptor;var jt=Object.getOwnPropertyNames;var Ut=Object.getPrototypeOf,Ht=Object.prototype.hasOwnProperty;var $t=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+e+'" is not supported')});var g=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Ft=(e,t)=>{for(var n in t)E(e,n,{get:t[n],enumerable:!0})},K=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of jt(t))!Ht.call(e,o)&&o!==n&&E(e,o,{get:()=>t[o],enumerable:!(r=Mt(t,o))||r.enumerable});return e};var Vt=(e,t,n)=>(n=e!=null?Dt(Ut(e)):{},K(t||!e||!e.__esModule?E(n,"default",{value:e,enumerable:!0}):n,e)),Xt=e=>K(E({},"__esModule",{value:!0}),e);var rt=g(f=>{"use strict";Object.defineProperty(f,"__esModule",{value:!0});f.output=f.exists=f.hash=f.bytes=f.bool=f.number=void 0;function A(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}f.number=A;function Q(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}f.bool=Q;function j(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}f.bytes=j;function tt(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");A(e.outputLen),A(e.blockLen)}f.hash=tt;function et(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}f.exists=et;function nt(e,t){j(e);let n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}f.output=nt;var Yt={number:A,bool:Q,bytes:j,hash:tt,exists:et,output:nt};f.default=Yt});var st=g(h=>{"use strict";Object.defineProperty(h,"__esModule",{value:!0});h.add=h.toBig=h.split=h.fromBig=void 0;var k=BigInt(2**32-1),U=BigInt(32);function H(e,t=!1){return t?{h:Number(e&k),l:Number(e>>U&k)}:{h:Number(e>>U&k)|0,l:Number(e&k)|0}}h.fromBig=H;function ot(e,t=!1){let n=new Uint32Array(e.length),r=new Uint32Array(e.length);for(let o=0;o<e.length;o++){let{h:s,l:i}=H(e[o],t);[n[o],r[o]]=[s,i]}return[n,r]}h.split=ot;var qt=(e,t)=>BigInt(e>>>0)<<U|BigInt(t>>>0);h.toBig=qt;var zt=(e,t,n)=>e>>>n,Kt=(e,t,n)=>e<<32-n|t>>>n,Wt=(e,t,n)=>e>>>n|t<<32-n,Gt=(e,t,n)=>e<<32-n|t>>>n,Jt=(e,t,n)=>e<<64-n|t>>>n-32,Zt=(e,t,n)=>e>>>n-32|t<<64-n,Qt=(e,t)=>t,te=(e,t)=>e,ee=(e,t,n)=>e<<n|t>>>32-n,ne=(e,t,n)=>t<<n|e>>>32-n,re=(e,t,n)=>t<<n-32|e>>>64-n,oe=(e,t,n)=>e<<n-32|t>>>64-n;function it(e,t,n,r){let o=(t>>>0)+(r>>>0);return{h:e+n+(o/2**32|0)|0,l:o|0}}h.add=it;var ie=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),se=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,ce=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),ae=(e,t,n,r,o)=>t+n+r+o+(e/2**32|0)|0,ue=(e,t,n,r,o)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(o>>>0),le=(e,t,n,r,o,s)=>t+n+r+o+s+(e/2**32|0)|0,pe={fromBig:H,split:ot,toBig:h.toBig,shrSH:zt,shrSL:Kt,rotrSH:Wt,rotrSL:Gt,rotrBH:Jt,rotrBL:Zt,rotr32H:Qt,rotr32L:te,rotlSH:ee,rotlSL:ne,rotlBH:re,rotlBL:oe,add:it,add3L:ie,add3H:se,add4L:ce,add4H:ae,add5H:le,add5L:ue};h.default=pe});var ct=g(R=>{"use strict";Object.defineProperty(R,"__esModule",{value:!0});R.crypto=void 0;var v=$t("node:crypto");R.crypto=v&&typeof v=="object"&&"webcrypto"in v?v.webcrypto:void 0});var ut=g(c=>{"use strict";Object.defineProperty(c,"__esModule",{value:!0});c.randomBytes=c.wrapXOFConstructorWithOpts=c.wrapConstructorWithOpts=c.wrapConstructor=c.checkOpts=c.Hash=c.concatBytes=c.toBytes=c.utf8ToBytes=c.asyncLoop=c.nextTick=c.hexToBytes=c.bytesToHex=c.isLE=c.rotr=c.createView=c.u32=c.u8=void 0;var $=ct(),V=e=>e instanceof Uint8Array,fe=e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength);c.u8=fe;var he=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4));c.u32=he;var de=e=>new DataView(e.buffer,e.byteOffset,e.byteLength);c.createView=de;var ye=(e,t)=>e<<32-t|e>>>t;c.rotr=ye;c.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!c.isLE)throw new Error("Non little-endian hardware is not supported");var me=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function ge(e){if(!V(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=me[e[n]];return t}c.bytesToHex=ge;function be(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);let t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(t/2);for(let r=0;r<n.length;r++){let o=r*2,s=e.slice(o,o+2),i=Number.parseInt(s,16);if(Number.isNaN(i)||i<0)throw new Error("Invalid byte sequence");n[r]=i}return n}c.hexToBytes=be;var we=async()=>{};c.nextTick=we;async function xe(e,t,n){let r=Date.now();for(let o=0;o<e;o++){n(o);let s=Date.now()-r;s>=0&&s<t||(await(0,c.nextTick)(),r+=s)}}c.asyncLoop=xe;function at(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}c.utf8ToBytes=at;function B(e){if(typeof e=="string"&&(e=at(e)),!V(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}c.toBytes=B;function Oe(...e){let t=new Uint8Array(e.reduce((r,o)=>r+o.length,0)),n=0;return e.forEach(r=>{if(!V(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}c.concatBytes=Oe;var F=class{clone(){return this._cloneInto()}};c.Hash=F;var _e=e=>Object.prototype.toString.call(e)==="[object Object]"&&e.constructor===Object;function Te(e,t){if(t!==void 0&&(typeof t!="object"||!_e(t)))throw new Error("Options should be object or undefined");return Object.assign(e,t)}c.checkOpts=Te;function Se(e){let t=r=>e().update(B(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}c.wrapConstructor=Se;function Ie(e){let t=(r,o)=>e(o).update(B(r)).digest(),n=e({});return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=r=>e(r),t}c.wrapConstructorWithOpts=Ie;function Ce(e){let t=(r,o)=>e(o).update(B(r)).digest(),n=e({});return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=r=>e(r),t}c.wrapXOFConstructorWithOpts=Ce;function Ee(e=32){if($.crypto&&typeof $.crypto.getRandomValues=="function")return $.crypto.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}c.randomBytes=Ee});var gt=g(u=>{"use strict";Object.defineProperty(u,"__esModule",{value:!0});u.shake256=u.shake128=u.keccak_512=u.keccak_384=u.keccak_256=u.keccak_224=u.sha3_512=u.sha3_384=u.sha3_256=u.sha3_224=u.Keccak=u.keccakP=void 0;var b=rt(),O=st(),x=ut(),[ft,ht,dt]=[[],[],[]],Ae=BigInt(0),w=BigInt(1),ke=BigInt(2),ve=BigInt(7),Re=BigInt(256),Be=BigInt(113);for(let e=0,t=w,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],ft.push(2*(5*r+n)),ht.push((e+1)*(e+2)/2%64);let o=Ae;for(let s=0;s<7;s++)t=(t<<w^(t>>ve)*Be)%Re,t&ke&&(o^=w<<(w<<BigInt(s))-w);dt.push(o)}var[Le,Ne]=O.default.split(dt,!0),lt=(e,t,n)=>n>32?O.default.rotlBH(e,t,n):O.default.rotlSH(e,t,n),pt=(e,t,n)=>n>32?O.default.rotlBL(e,t,n):O.default.rotlSL(e,t,n);function yt(e,t=24){let n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let i=0;i<10;i++)n[i]=e[i]^e[i+10]^e[i+20]^e[i+30]^e[i+40];for(let i=0;i<10;i+=2){let a=(i+8)%10,l=(i+2)%10,p=n[l],d=n[l+1],Nt=lt(p,d,1)^n[a],Pt=pt(p,d,1)^n[a+1];for(let C=0;C<50;C+=10)e[i+C]^=Nt,e[i+C+1]^=Pt}let o=e[2],s=e[3];for(let i=0;i<24;i++){let a=ht[i],l=lt(o,s,a),p=pt(o,s,a),d=ft[i];o=e[d],s=e[d+1],e[d]=l,e[d+1]=p}for(let i=0;i<50;i+=10){for(let a=0;a<10;a++)n[a]=e[i+a];for(let a=0;a<10;a++)e[i+a]^=~n[(a+2)%10]&n[(a+4)%10]}e[0]^=Le[r],e[1]^=Ne[r]}n.fill(0)}u.keccakP=yt;var _=class e extends x.Hash{constructor(t,n,r,o=!1,s=24){if(super(),this.blockLen=t,this.suffix=n,this.outputLen=r,this.enableXOF=o,this.rounds=s,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,b.default.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,x.u32)(this.state)}keccak(){yt(this.state32,this.rounds),this.posOut=0,this.pos=0}update(t){b.default.exists(this);let{blockLen:n,state:r}=this;t=(0,x.toBytes)(t);let o=t.length;for(let s=0;s<o;){let i=Math.min(n-this.pos,o-s);for(let a=0;a<i;a++)r[this.pos++]^=t[s++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:t,suffix:n,pos:r,blockLen:o}=this;t[r]^=n,n&128&&r===o-1&&this.keccak(),t[o-1]^=128,this.keccak()}writeInto(t){b.default.exists(this,!1),b.default.bytes(t),this.finish();let n=this.state,{blockLen:r}=this;for(let o=0,s=t.length;o<s;){this.posOut>=r&&this.keccak();let i=Math.min(r-this.posOut,s-o);t.set(n.subarray(this.posOut,this.posOut+i),o),this.posOut+=i,o+=i}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return b.default.number(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(b.default.output(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(t){let{blockLen:n,suffix:r,outputLen:o,rounds:s,enableXOF:i}=this;return t||(t=new e(n,r,o,i,s)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=s,t.suffix=r,t.outputLen=o,t.enableXOF=i,t.destroyed=this.destroyed,t}};u.Keccak=_;var y=(e,t,n)=>(0,x.wrapConstructor)(()=>new _(t,e,n));u.sha3_224=y(6,144,224/8);u.sha3_256=y(6,136,256/8);u.sha3_384=y(6,104,384/8);u.sha3_512=y(6,72,512/8);u.keccak_224=y(1,144,224/8);u.keccak_256=y(1,136,256/8);u.keccak_384=y(1,104,384/8);u.keccak_512=y(1,72,512/8);var mt=(e,t,n)=>(0,x.wrapXOFConstructorWithOpts)((r={})=>new _(t,e,r.dkLen===void 0?n:r.dkLen,!0));u.shake128=mt(31,168,128/8);u.shake256=mt(31,136,256/8)});var It=g((rn,m)=>{"use strict";var{sha3_512:Pe}=gt(),wt=24,T=32,X=(e=4,t=Math.random)=>{let n="";for(;n.length<e;)n=n+Math.floor(t()*36).toString(36);return n};function xt(e){let t=8n,n=0n;for(let r of e.values()){let o=BigInt(r);n=(n<<t)+o}return n}var Ot=(e="")=>xt(Pe(e)).toString(36).slice(1),bt=Array.from({length:26},(e,t)=>String.fromCharCode(t+97)),De=e=>bt[Math.floor(e()*bt.length)],_t=({globalObj:e=typeof global<"u"?global:typeof window<"u"?window:{},random:t=Math.random}={})=>{let n=Object.keys(e).toString(),r=n.length?n+X(T,t):X(T,t);return Ot(r).substring(0,T)},Tt=e=>()=>e++,Me=476782367,St=({random:e=Math.random,counter:t=Tt(Math.floor(e()*Me)),length:n=wt,fingerprint:r=_t({random:e})}={})=>function(){let s=De(e),i=Date.now().toString(36),a=t().toString(36),l=X(n,e),p=`${i+l+a+r}`;return`${s+Ot(p).substring(1,n)}`},je=St(),Ue=(e,{minLength:t=2,maxLength:n=T}={})=>{let r=e.length,o=/^[0-9a-z]+$/;try{if(typeof e=="string"&&r>=t&&r<=n&&o.test(e))return!0}finally{}return!1};m.exports.getConstants=()=>({defaultLength:wt,bigLength:T});m.exports.init=St;m.exports.createId=je;m.exports.bufToBigInt=xt;m.exports.createCounter=Tt;m.exports.createFingerprint=_t;m.exports.isCuid=Ue});var Ct=g((on,S)=>{"use strict";var{createId:He,init:$e,getConstants:Fe,isCuid:Ve}=It();S.exports.createId=He;S.exports.init=$e;S.exports.getConstants=Fe;S.exports.isCuid=Ve});var Ye={};Ft(Ye,{OramaClient:()=>q,OramaProxy:()=>z});var ze=Date.now().toString().slice(5);var W=BigInt(1e3),G=BigInt(1e6),J=BigInt(1e9);async function Z(e){return typeof e=="number"&&(e=BigInt(e)),e<W?`${e}ns`:e<G?`${e/W}\u03BCs`:e<J?`${e/G}ms`:`${e/J}s`}async function M(e){return{raw:Number(e),formatted:await Z(e)}}var Lt=Vt(Ct(),1);var L=class{cache;config;constructor(t){this.cache=new Map,this.config=t}set(t,n){this.cache.set(t,n)}get(t){return this.cache.get(t)}has(t){return this.cache.has(t)}delete(t){return this.cache.delete(t)}clear(){this.cache.clear()}size(){return this.cache.size}};var N="https://secure-proxy.orama.run",Et="/init",At="/chat",kt="/query";var Rt="1.0.0-beta.22";var Bt={name:"@oramacloud/client",version:Rt,description:"Orama SDK 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:{".":{require:"./dist/index.cjs",import:"./dist/index.js",types:"./dist/index.d.ts",browser:"./dist/index.global.js"},"./react":{require:"./dist/react/index.cjs",import:"./dist/react/index.js",types:"./dist/react/index.d.ts"},"./vue":{require:"./dist/vue/index.cjs",import:"./dist/vue/index.js",types:"./dist/vue/index.d.ts"}},scripts:{format:"bunx @biomejs/biome format src --write",build:"npm run build:lib && npm run build:react","build:lib":"tsup --config tsup.lib.js","build:react":"tsup --config tsup.react.js","build:vue":"tsup --config tsup.vue.js",test:"tsx tests/index.test.ts","serve:example":"esbuild src/index.ts --bundle --outfile=example/out.js --format=esm --watch --servedir=example",prepare:"husky install"},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/orama":"^2.0.0-beta.9","@paralleldrive/cuid2":"^2.2.1",react:"^18.2.0",vue:"^3.3.4"},devDependencies:{"@biomejs/biome":"^1.4.1","@fastify/formbody":"^7.4.0","@types/node":"^20.3.1","@types/react":"^18.2.14",esbuild:"0.18.5",fastify:"^4.19.2",husky:"^8.0.3","ts-standard":"^12.0.2",tsup:"^7.1.0",tsx:"^3.12.7",typescript:"^5.1.3"},"ts-standard":{ignore:["dist","node_modules"]}};function I(e,t){if(typeof navigator<"u"){navigator.sendBeacon(e,t);return}fetch(e,{method:"POST",body:t,headers:{"Content-Type":"application/json"}}).then(()=>{},n=>console.log(n))}var P=class e{data;params;config;constructor(t){this.data=[],this.config=t}setParams(t){this.params=t}static create(t){let n=new e(t);return n.start(),n}add(t){this.data.push({rawSearchString:t.rawSearchString,query:t.query,resultsCount:t.resultsCount,roundTripTime:t.roundTripTime,searchedAt:t.searchedAt,referer:typeof location<"u"?location.toString():void 0}),this.params!=null&&this.data.length>=this.config.flushSize&&this.flush()}flush(){if(this.params==null||this.data.length===0)return;let t=this.data;this.data=[];let n={source:"fe",deploymentID:this.params.deploymentID,index:this.params.index,oramaId:this.config.id,oramaVersion:Bt.version,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,events:t};I(this.params.endpoint+`?api-key=${this.config.api_key}`,JSON.stringify(n))?.catch(r=>console.log(r))}start(){let t=setInterval(this.flush.bind(this),this.config.flushInterval);t.unref!=null&&t.unref()}};var D=class{constructor(t){this.params=t}intervalId;start(){this.stop(),this.intervalId=setInterval(this.beat.bind(this),this.params.frequency)}stop(){this.intervalId!==void 0&&clearInterval(this.intervalId)}beat(){I(this.params.endpoint)?.catch(t=>console.log(t))}};var q=class{id=(0,Lt.createId)();api_key;endpoint;collector;cache;heartbeat;initPromise;constructor(t){if(this.api_key=t.api_key,this.endpoint=t.endpoint,t.telemetry!==!1){let n={id:this.id,api_key:this.api_key,flushInterval:t.telemetry?.flushInterval??5e3,flushSize:t.telemetry?.flushSize??25};this.collector=P.create(n)}if(t.cache!==!1){let n={};this.cache=new L(n)}this.init()}async search(t,n){await this.initPromise;let r="search-"+JSON.stringify(t),o,s,i=!1;if((n?.fresh!==!0&&this.cache?.has(r))===!0&&this.cache!=null)o=0,s=this.cache.get(r),i=!0;else{let l=Date.now();s=await this.fetch("search","POST",{q:t},n?.abortController);let p=Date.now();s.elapsed=await M(BigInt(p*1e6-l*1e6)),o=p-l,this.cache?.set(r,s)}return this.collector!=null&&this.collector.add({rawSearchString:t.term,resultsCount:s.hits.length,roundTripTime:o,query:t,cached:i,searchedAt:new Date}),s}async vectorSearch(t,n){await this.initPromise;let r="vectorSearch-"+JSON.stringify(t),o,s,i=!1;if((n?.fresh!==!0&&this.cache?.has(r))===!0&&this.cache!=null)o=0,s=this.cache.get(r),i=!0;else{let l=Date.now();s=await this.fetch("vector-search2","POST",{q:t},n?.abortController);let p=Date.now();s.elapsed=await M(BigInt(p*1e6-l*1e6)),o=p-l,this.cache?.set(r,s)}return this.collector!=null&&this.collector.add({rawSearchString:t.term,resultsCount:s.hits.length,roundTripTime:o,query:t,cached:i,searchedAt:new Date}),s}startHeartBeat(t){this.heartbeat?.stop(),this.heartbeat=new D({...t,endpoint:this.endpoint+`/health?api-key=${this.api_key}`}),this.heartbeat.start()}stopHeartBeat(){this.heartbeat?.stop()}async getPop(){return(await this.initPromise)?.pop??""}init(){this.initPromise=this.fetch("init","GET").then(t=>(this.collector?.setParams({endpoint:t.collectUrl,deploymentID:t.deploymentID,index:t.index}),t)).catch(t=>(console.log(t),null))}async fetch(t,n,r,o){if(o?.signal.aborted===!0)throw new Error("Request aborted");let s={method:n,headers:{"Content-Type":"application/x-www-form-urlencoded"},signal:o?.signal};if(n==="POST"&&r!==void 0){let a=r;a.version=Rt,a.id=this.id,s.body=Object.entries(a).map(([l,p])=>`${l}=${encodeURIComponent(JSON.stringify(p))}`).join("&")}let i=await fetch(`${this.endpoint}/${t}?api-key=${this.api_key}`,s);if(!i.ok){let a=new Error;throw a.httpResponse=i,a}return await i.json()}};var z=class{CSRFToken="";ready;api_key;constructor(t){this.api_key=t.api_key,this.ready=this.init().then(()=>!0).catch(n=>(console.log(n),!1))}async generateEmbeddings(t){if(!await this.ready)return console.log("OramaProxy had an error during the initialization"),[];let r=`${N}${kt}?apiKey=${this.api_key}`;return(await fetch(r,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},referrer:this.getReferrer(),body:new URLSearchParams({query:t,csrf:this.CSRFToken}).toString()})).json()}async chat(t,n){if(!await this.ready){console.log("OramaProxy had an error during the initialization");return}let o=`${N}${At}?apiKey=${this.api_key}`,s=await fetch(o,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},referrer:this.getReferrer(),body:new URLSearchParams({messages:JSON.stringify(t),csrf:this.CSRFToken}).toString()});if(!s.ok||s.body==null)throw s.statusText;let i=s.body.getReader(),a=new TextDecoder;for(;;){let{value:l,done:p}=await i.read();if(p)break;let d=a.decode(l,{stream:!0});n(d)}}async init(){let t=`${N}${Et}?apiKey=${this.api_key}`,r=await(await fetch(t,{referrer:this.getReferrer()})).json();console.log({data:r}),this.CSRFToken=r.csrfToken}isServer(){return typeof window>"u"}getReferrer(){return this.isServer()?"http://localhost":window.location.href}};return Xt(Ye);})();
"use strict";var OramaClient=(()=>{var $t=Object.create;var I=Object.defineProperty;var Ft=Object.getOwnPropertyDescriptor;var Vt=Object.getOwnPropertyNames;var Xt=Object.getPrototypeOf,Yt=Object.prototype.hasOwnProperty;var qt=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+e+'" is not supported')});var g=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Gt=(e,t)=>{for(var n in t)I(e,n,{get:t[n],enumerable:!0})},K=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Vt(t))!Yt.call(e,o)&&o!==n&&I(e,o,{get:()=>t[o],enumerable:!(r=Ft(t,o))||r.enumerable});return e};var Kt=(e,t,n)=>(n=e!=null?$t(Xt(e)):{},K(t||!e||!e.__esModule?I(n,"default",{value:e,enumerable:!0}):n,e)),zt=e=>K(I({},"__esModule",{value:!0}),e);var rt=g(p=>{"use strict";Object.defineProperty(p,"__esModule",{value:!0});p.output=p.exists=p.hash=p.bytes=p.bool=p.number=void 0;function C(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}p.number=C;function Q(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}p.bool=Q;function j(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}p.bytes=j;function tt(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");C(e.outputLen),C(e.blockLen)}p.hash=tt;function et(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}p.exists=et;function nt(e,t){j(e);let n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}p.output=nt;var Wt={number:C,bool:Q,bytes:j,hash:tt,exists:et,output:nt};p.default=Wt});var it=g(h=>{"use strict";Object.defineProperty(h,"__esModule",{value:!0});h.add=h.toBig=h.split=h.fromBig=void 0;var k=BigInt(2**32-1),H=BigInt(32);function U(e,t=!1){return t?{h:Number(e&k),l:Number(e>>H&k)}:{h:Number(e>>H&k)|0,l:Number(e&k)|0}}h.fromBig=U;function ot(e,t=!1){let n=new Uint32Array(e.length),r=new Uint32Array(e.length);for(let o=0;o<e.length;o++){let{h:i,l:s}=U(e[o],t);[n[o],r[o]]=[i,s]}return[n,r]}h.split=ot;var Jt=(e,t)=>BigInt(e>>>0)<<H|BigInt(t>>>0);h.toBig=Jt;var Zt=(e,t,n)=>e>>>n,Qt=(e,t,n)=>e<<32-n|t>>>n,te=(e,t,n)=>e>>>n|t<<32-n,ee=(e,t,n)=>e<<32-n|t>>>n,ne=(e,t,n)=>e<<64-n|t>>>n-32,re=(e,t,n)=>e>>>n-32|t<<64-n,oe=(e,t)=>t,se=(e,t)=>e,ie=(e,t,n)=>e<<n|t>>>32-n,ae=(e,t,n)=>t<<n|e>>>32-n,ce=(e,t,n)=>t<<n-32|e>>>64-n,ue=(e,t,n)=>e<<n-32|t>>>64-n;function st(e,t,n,r){let o=(t>>>0)+(r>>>0);return{h:e+n+(o/2**32|0)|0,l:o|0}}h.add=st;var le=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),pe=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,fe=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),he=(e,t,n,r,o)=>t+n+r+o+(e/2**32|0)|0,de=(e,t,n,r,o)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(o>>>0),ye=(e,t,n,r,o,i)=>t+n+r+o+i+(e/2**32|0)|0,me={fromBig:U,split:ot,toBig:h.toBig,shrSH:Zt,shrSL:Qt,rotrSH:te,rotrSL:ee,rotrBH:ne,rotrBL:re,rotr32H:oe,rotr32L:se,rotlSH:ie,rotlSL:ae,rotlBH:ce,rotlBL:ue,add:st,add3L:le,add3H:pe,add4L:fe,add4H:he,add5H:ye,add5L:de};h.default=me});var at=g(v=>{"use strict";Object.defineProperty(v,"__esModule",{value:!0});v.crypto=void 0;var L=qt("node:crypto");v.crypto=L&&typeof L=="object"&&"webcrypto"in L?L.webcrypto:void 0});var ut=g(a=>{"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.randomBytes=a.wrapXOFConstructorWithOpts=a.wrapConstructorWithOpts=a.wrapConstructor=a.checkOpts=a.Hash=a.concatBytes=a.toBytes=a.utf8ToBytes=a.asyncLoop=a.nextTick=a.hexToBytes=a.bytesToHex=a.isLE=a.rotr=a.createView=a.u32=a.u8=void 0;var $=at(),V=e=>e instanceof Uint8Array,ge=e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength);a.u8=ge;var be=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4));a.u32=be;var _e=e=>new DataView(e.buffer,e.byteOffset,e.byteLength);a.createView=_e;var we=(e,t)=>e<<32-t|e>>>t;a.rotr=we;a.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!a.isLE)throw new Error("Non little-endian hardware is not supported");var xe=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Oe(e){if(!V(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=xe[e[n]];return t}a.bytesToHex=Oe;function Ee(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);let t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(t/2);for(let r=0;r<n.length;r++){let o=r*2,i=e.slice(o,o+2),s=Number.parseInt(i,16);if(Number.isNaN(s)||s<0)throw new Error("Invalid byte sequence");n[r]=s}return n}a.hexToBytes=Ee;var Te=async()=>{};a.nextTick=Te;async function Se(e,t,n){let r=Date.now();for(let o=0;o<e;o++){n(o);let i=Date.now()-r;i>=0&&i<t||(await(0,a.nextTick)(),r+=i)}}a.asyncLoop=Se;function ct(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}a.utf8ToBytes=ct;function B(e){if(typeof e=="string"&&(e=ct(e)),!V(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}a.toBytes=B;function Ae(...e){let t=new Uint8Array(e.reduce((r,o)=>r+o.length,0)),n=0;return e.forEach(r=>{if(!V(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}a.concatBytes=Ae;var F=class{clone(){return this._cloneInto()}};a.Hash=F;var Ie=e=>Object.prototype.toString.call(e)==="[object Object]"&&e.constructor===Object;function Ce(e,t){if(t!==void 0&&(typeof t!="object"||!Ie(t)))throw new Error("Options should be object or undefined");return Object.assign(e,t)}a.checkOpts=Ce;function ke(e){let t=r=>e().update(B(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}a.wrapConstructor=ke;function Le(e){let t=(r,o)=>e(o).update(B(r)).digest(),n=e({});return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=r=>e(r),t}a.wrapConstructorWithOpts=Le;function ve(e){let t=(r,o)=>e(o).update(B(r)).digest(),n=e({});return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=r=>e(r),t}a.wrapXOFConstructorWithOpts=ve;function Be(e=32){if($.crypto&&typeof $.crypto.getRandomValues=="function")return $.crypto.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}a.randomBytes=Be});var gt=g(u=>{"use strict";Object.defineProperty(u,"__esModule",{value:!0});u.shake256=u.shake128=u.keccak_512=u.keccak_384=u.keccak_256=u.keccak_224=u.sha3_512=u.sha3_384=u.sha3_256=u.sha3_224=u.Keccak=u.keccakP=void 0;var b=rt(),x=it(),w=ut(),[ft,ht,dt]=[[],[],[]],Ne=BigInt(0),_=BigInt(1),Re=BigInt(2),Me=BigInt(7),Pe=BigInt(256),De=BigInt(113);for(let e=0,t=_,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],ft.push(2*(5*r+n)),ht.push((e+1)*(e+2)/2%64);let o=Ne;for(let i=0;i<7;i++)t=(t<<_^(t>>Me)*De)%Pe,t&Re&&(o^=_<<(_<<BigInt(i))-_);dt.push(o)}var[je,He]=x.default.split(dt,!0),lt=(e,t,n)=>n>32?x.default.rotlBH(e,t,n):x.default.rotlSH(e,t,n),pt=(e,t,n)=>n>32?x.default.rotlBL(e,t,n):x.default.rotlSL(e,t,n);function yt(e,t=24){let n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let s=0;s<10;s++)n[s]=e[s]^e[s+10]^e[s+20]^e[s+30]^e[s+40];for(let s=0;s<10;s+=2){let c=(s+8)%10,l=(s+2)%10,f=n[l],m=n[l+1],Ht=lt(f,m,1)^n[c],Ut=pt(f,m,1)^n[c+1];for(let A=0;A<50;A+=10)e[s+A]^=Ht,e[s+A+1]^=Ut}let o=e[2],i=e[3];for(let s=0;s<24;s++){let c=ht[s],l=lt(o,i,c),f=pt(o,i,c),m=ft[s];o=e[m],i=e[m+1],e[m]=l,e[m+1]=f}for(let s=0;s<50;s+=10){for(let c=0;c<10;c++)n[c]=e[s+c];for(let c=0;c<10;c++)e[s+c]^=~n[(c+2)%10]&n[(c+4)%10]}e[0]^=je[r],e[1]^=He[r]}n.fill(0)}u.keccakP=yt;var O=class e extends w.Hash{constructor(t,n,r,o=!1,i=24){if(super(),this.blockLen=t,this.suffix=n,this.outputLen=r,this.enableXOF=o,this.rounds=i,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,b.default.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,w.u32)(this.state)}keccak(){yt(this.state32,this.rounds),this.posOut=0,this.pos=0}update(t){b.default.exists(this);let{blockLen:n,state:r}=this;t=(0,w.toBytes)(t);let o=t.length;for(let i=0;i<o;){let s=Math.min(n-this.pos,o-i);for(let c=0;c<s;c++)r[this.pos++]^=t[i++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:t,suffix:n,pos:r,blockLen:o}=this;t[r]^=n,n&128&&r===o-1&&this.keccak(),t[o-1]^=128,this.keccak()}writeInto(t){b.default.exists(this,!1),b.default.bytes(t),this.finish();let n=this.state,{blockLen:r}=this;for(let o=0,i=t.length;o<i;){this.posOut>=r&&this.keccak();let s=Math.min(r-this.posOut,i-o);t.set(n.subarray(this.posOut,this.posOut+s),o),this.posOut+=s,o+=s}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return b.default.number(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(b.default.output(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(t){let{blockLen:n,suffix:r,outputLen:o,rounds:i,enableXOF:s}=this;return t||(t=new e(n,r,o,s,i)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=i,t.suffix=r,t.outputLen=o,t.enableXOF=s,t.destroyed=this.destroyed,t}};u.Keccak=O;var d=(e,t,n)=>(0,w.wrapConstructor)(()=>new O(t,e,n));u.sha3_224=d(6,144,224/8);u.sha3_256=d(6,136,256/8);u.sha3_384=d(6,104,384/8);u.sha3_512=d(6,72,512/8);u.keccak_224=d(1,144,224/8);u.keccak_256=d(1,136,256/8);u.keccak_384=d(1,104,384/8);u.keccak_512=d(1,72,512/8);var mt=(e,t,n)=>(0,w.wrapXOFConstructorWithOpts)((r={})=>new O(t,e,r.dkLen===void 0?n:r.dkLen,!0));u.shake128=mt(31,168,128/8);u.shake256=mt(31,136,256/8)});var St=g((pn,y)=>{"use strict";var{sha3_512:Ue}=gt(),_t=24,E=32,X=(e=4,t=Math.random)=>{let n="";for(;n.length<e;)n=n+Math.floor(t()*36).toString(36);return n};function wt(e){let t=8n,n=0n;for(let r of e.values()){let o=BigInt(r);n=(n<<t)+o}return n}var xt=(e="")=>wt(Ue(e)).toString(36).slice(1),bt=Array.from({length:26},(e,t)=>String.fromCharCode(t+97)),$e=e=>bt[Math.floor(e()*bt.length)],Ot=({globalObj:e=typeof global<"u"?global:typeof window<"u"?window:{},random:t=Math.random}={})=>{let n=Object.keys(e).toString(),r=n.length?n+X(E,t):X(E,t);return xt(r).substring(0,E)},Et=e=>()=>e++,Fe=476782367,Tt=({random:e=Math.random,counter:t=Et(Math.floor(e()*Fe)),length:n=_t,fingerprint:r=Ot({random:e})}={})=>function(){let i=$e(e),s=Date.now().toString(36),c=t().toString(36),l=X(n,e),f=`${s+l+c+r}`;return`${i+xt(f).substring(1,n)}`},Ve=Tt(),Xe=(e,{minLength:t=2,maxLength:n=E}={})=>{let r=e.length,o=/^[0-9a-z]+$/;try{if(typeof e=="string"&&r>=t&&r<=n&&o.test(e))return!0}finally{}return!1};y.exports.getConstants=()=>({defaultLength:_t,bigLength:E});y.exports.init=Tt;y.exports.createId=Ve;y.exports.bufToBigInt=wt;y.exports.createCounter=Et;y.exports.createFingerprint=Ot;y.exports.isCuid=Xe});var At=g((fn,T)=>{"use strict";var{createId:Ye,init:qe,getConstants:Ge,isCuid:Ke}=St();T.exports.createId=Ye;T.exports.init=qe;T.exports.getConstants=Ge;T.exports.isCuid=Ke});var Ze={};Gt(Ze,{OramaClient:()=>q,OramaProxy:()=>G});var tn=Date.now().toString().slice(5);var z=BigInt(1e3),W=BigInt(1e6),J=BigInt(1e9);async function Z(e){return typeof e=="number"&&(e=BigInt(e)),e<z?`${e}ns`:e<W?`${e/z}\u03BCs`:e<J?`${e/W}ms`:`${e/J}s`}async function D(e){return{raw:Number(e),formatted:await Z(e)}}var Nt=Kt(At(),1);var N=class{cache;config;constructor(t){this.cache=new Map,this.config=t}set(t,n){this.cache.set(t,n)}get(t){return this.cache.get(t)}has(t){return this.cache.has(t)}delete(t){return this.cache.delete(t)}clear(){this.cache.clear()}size(){return this.cache.size}};var R="https://secure-proxy.orama.foo",It="/init",Ct="/chat",kt="/query";var vt="1.0.0-beta.23";var Bt={name:"@oramacloud/client",version:vt,description:"Orama SDK 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:{".":{require:"./dist/index.cjs",import:"./dist/index.js",types:"./dist/index.d.ts",browser:"./dist/index.global.js"},"./react":{require:"./dist/react/index.cjs",import:"./dist/react/index.js",types:"./dist/react/index.d.ts"},"./vue":{require:"./dist/vue/index.cjs",import:"./dist/vue/index.js",types:"./dist/vue/index.d.ts"}},scripts:{format:"bunx @biomejs/biome format src --write",build:"npm run build:lib && npm run build:react","build:lib":"tsup --config tsup.lib.js","build:react":"tsup --config tsup.react.js","build:vue":"tsup --config tsup.vue.js",test:"tsx tests/proxy.e2e.test","serve:example":"esbuild src/index.ts --bundle --outfile=example/out.js --format=esm --watch --servedir=example",prepare:"husky install"},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/orama":"^2.0.0-beta.9","@paralleldrive/cuid2":"^2.2.1",react:"^18.2.0",vue:"^3.3.4"},devDependencies:{"@biomejs/biome":"^1.4.1","@fastify/formbody":"^7.4.0","@types/node":"^20.3.1","@types/react":"^18.2.14",dotenv:"^16.3.1",esbuild:"0.18.5",fastify:"^4.19.2",husky:"^8.0.3",openai:"^4.24.1","ts-standard":"^12.0.2",tsup:"^7.1.0",tsx:"^3.12.7",typescript:"^5.1.3"},"ts-standard":{ignore:["dist","node_modules"]}};function S(e,t){if(typeof navigator<"u"){navigator.sendBeacon(e,t);return}fetch(e,{method:"POST",body:t,headers:{"Content-Type":"application/json"}}).then(()=>{},n=>console.log(n))}var M=class e{data;params;config;constructor(t){this.data=[],this.config=t}setParams(t){this.params=t}static create(t){let n=new e(t);return n.start(),n}add(t){this.data.push({rawSearchString:t.rawSearchString,query:t.query,resultsCount:t.resultsCount,roundTripTime:t.roundTripTime,searchedAt:t.searchedAt,referer:typeof location<"u"?location.toString():void 0}),this.params!=null&&this.data.length>=this.config.flushSize&&this.flush()}flush(){if(this.params==null||this.data.length===0)return;let t=this.data;this.data=[];let n={source:"fe",deploymentID:this.params.deploymentID,index:this.params.index,oramaId:this.config.id,oramaVersion:Bt.version,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,events:t};S(this.params.endpoint+`?api-key=${this.config.api_key}`,JSON.stringify(n))?.catch(r=>console.log(r))}start(){let t=setInterval(this.flush.bind(this),this.config.flushInterval);t.unref!=null&&t.unref()}};var P=class{constructor(t){this.params=t}intervalId;start(){this.stop(),this.intervalId=setInterval(this.beat.bind(this),this.params.frequency)}stop(){this.intervalId!==void 0&&clearInterval(this.intervalId)}beat(){S(this.params.endpoint)?.catch(t=>console.log(t))}};var q=class{id=(0,Nt.createId)();api_key;endpoint;collector;cache;heartbeat;initPromise;constructor(t){if(this.api_key=t.api_key,this.endpoint=t.endpoint,t.telemetry!==!1){let n={id:this.id,api_key:this.api_key,flushInterval:t.telemetry?.flushInterval??5e3,flushSize:t.telemetry?.flushSize??25};this.collector=M.create(n)}if(t.cache!==!1){let n={};this.cache=new N(n)}this.init()}async search(t,n){await this.initPromise;let r="search-"+JSON.stringify(t),o,i,s=!1;if((n?.fresh!==!0&&this.cache?.has(r))===!0&&this.cache!=null)o=0,i=this.cache.get(r),s=!0;else{let l=Date.now();i=await this.fetch("search","POST",{q:t},n?.abortController);let f=Date.now();i.elapsed=await D(BigInt(f*1e6-l*1e6)),o=f-l,this.cache?.set(r,i)}return this.collector!=null&&this.collector.add({rawSearchString:t.term,resultsCount:i.hits.length,roundTripTime:o,query:t,cached:s,searchedAt:new Date}),i}async vectorSearch(t,n){await this.initPromise;let r="vectorSearch-"+JSON.stringify(t),o,i,s=!1;if((n?.fresh!==!0&&this.cache?.has(r))===!0&&this.cache!=null)o=0,i=this.cache.get(r),s=!0;else{let l=Date.now();i=await this.fetch("vector-search2","POST",{q:t},n?.abortController);let f=Date.now();i.elapsed=await D(BigInt(f*1e6-l*1e6)),o=f-l,this.cache?.set(r,i)}return this.collector!=null&&this.collector.add({rawSearchString:t.term,resultsCount:i.hits.length,roundTripTime:o,query:t,cached:s,searchedAt:new Date}),i}startHeartBeat(t){this.heartbeat?.stop(),this.heartbeat=new P({...t,endpoint:this.endpoint+`/health?api-key=${this.api_key}`}),this.heartbeat.start()}stopHeartBeat(){this.heartbeat?.stop()}async getPop(){return(await this.initPromise)?.pop??""}init(){this.initPromise=this.fetch("init","GET").then(t=>(this.collector?.setParams({endpoint:t.collectUrl,deploymentID:t.deploymentID,index:t.index}),t)).catch(t=>(console.log(t),null))}async fetch(t,n,r,o){if(o?.signal.aborted===!0)throw new Error("Request aborted");let i={method:n,headers:{"Content-Type":"application/x-www-form-urlencoded"},signal:o?.signal};if(n==="POST"&&r!==void 0){let c=r;c.version=vt,c.id=this.id,i.body=Object.entries(c).map(([l,f])=>`${l}=${encodeURIComponent(JSON.stringify(f))}`).join("&")}let s=await fetch(`${this.endpoint}/${t}?api-key=${this.api_key}`,i);if(!s.ok){let c=new Error;throw c.httpResponse=s,c}return await s.json()}};var Rt="text-embedding-ada-002";var Mt="gpt-4-1106-preview",Pt="gpt-4",Dt="gpt-3.5-turbo",jt="gpt-3.5-turbo-16k",We={[`openai/${Rt}`]:Rt},Je={[`openai/${Dt}`]:Dt,[`openai/${Pt}`]:Pt,[`openai/${jt}`]:jt,[`openai/${Mt}`]:Mt},G=class{CSRFToken="";ready;api_key;constructor(t){this.api_key=t.api_key,this.ready=this.init().then(()=>!0).catch(n=>(console.log(n),!1))}async generateEmbeddings(t,n){if(!await this.ready)return console.log("OramaProxy had an error during the initialization"),[];let o=`${R}${kt}?apiKey=${this.api_key}`;return(await fetch(o,{method:"POST",headers:this.getHeaders(),body:new URLSearchParams({query:t,csrf:this.CSRFToken,model:We[n]}).toString()})).json()}async chat(t){if(!await this.ready)return console.log("OramaProxy had an error during the initialization"),"";let r="";for await(let o of this.chatStream(t))r+=o;return r}async*chatStream(t){let n=`${R}${Ct}?apiKey=${this.api_key}`,r=await fetch(n,{method:"POST",headers:this.getHeaders(),body:new URLSearchParams({messages:JSON.stringify(t.messages),csrf:this.CSRFToken,model:Je[t.model]}).toString()});if(!r.ok||r.body==null)throw r.statusText;let o=r.body.getReader(),i=new TextDecoder;for(;;){let{value:s,done:c}=await o.read();if(c)break;yield i.decode(s,{stream:!0})}}async init(){let t=`${R}${It}?apiKey=${this.api_key}`,r=await(await fetch(t,{headers:{referer:this.getReferrer()}})).json();this.CSRFToken=r.csrfToken}isServer(){return typeof window>"u"}getHeaders(){return{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",referer:this.getReferrer()}}getReferrer(){return this.isServer()?"http://localhost":window.location.href}};return zt(Ze);})();
/*! Bundled license information:

@@ -3,0 +3,0 @@

@@ -1,2 +0,2 @@

import{formatElapsedTime as v}from"@orama/orama/components";import{createId as A}from"@paralleldrive/cuid2";var d=class{cache;config;constructor(e){this.cache=new Map,this.config=e}set(e,t){this.cache.set(e,t)}get(e){return this.cache.get(e)}has(e){return this.cache.has(e)}delete(e){return this.cache.delete(e)}clear(){this.cache.clear()}size(){return this.cache.size}};var p="https://secure-proxy.orama.run",y="/init",C="/chat",g="/query";var S="1.0.0-beta.22";var O={name:"@oramacloud/client",version:S,description:"Orama SDK 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:{".":{require:"./dist/index.cjs",import:"./dist/index.js",types:"./dist/index.d.ts",browser:"./dist/index.global.js"},"./react":{require:"./dist/react/index.cjs",import:"./dist/react/index.js",types:"./dist/react/index.d.ts"},"./vue":{require:"./dist/vue/index.cjs",import:"./dist/vue/index.js",types:"./dist/vue/index.d.ts"}},scripts:{format:"bunx @biomejs/biome format src --write",build:"npm run build:lib && npm run build:react","build:lib":"tsup --config tsup.lib.js","build:react":"tsup --config tsup.react.js","build:vue":"tsup --config tsup.vue.js",test:"tsx tests/index.test.ts","serve:example":"esbuild src/index.ts --bundle --outfile=example/out.js --format=esm --watch --servedir=example",prepare:"husky install"},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/orama":"^2.0.0-beta.9","@paralleldrive/cuid2":"^2.2.1",react:"^18.2.0",vue:"^3.3.4"},devDependencies:{"@biomejs/biome":"^1.4.1","@fastify/formbody":"^7.4.0","@types/node":"^20.3.1","@types/react":"^18.2.14",esbuild:"0.18.5",fastify:"^4.19.2",husky:"^8.0.3","ts-standard":"^12.0.2",tsup:"^7.1.0",tsx:"^3.12.7",typescript:"^5.1.3"},"ts-standard":{ignore:["dist","node_modules"]}};function h(l,e){if(typeof navigator<"u"){navigator.sendBeacon(l,e);return}fetch(l,{method:"POST",body:e,headers:{"Content-Type":"application/json"}}).then(()=>{},t=>console.log(t))}var u=class l{data;params;config;constructor(e){this.data=[],this.config=e}setParams(e){this.params=e}static create(e){let t=new l(e);return t.start(),t}add(e){this.data.push({rawSearchString:e.rawSearchString,query:e.query,resultsCount:e.resultsCount,roundTripTime:e.roundTripTime,searchedAt:e.searchedAt,referer:typeof location<"u"?location.toString():void 0}),this.params!=null&&this.data.length>=this.config.flushSize&&this.flush()}flush(){if(this.params==null||this.data.length===0)return;let e=this.data;this.data=[];let t={source:"fe",deploymentID:this.params.deploymentID,index:this.params.index,oramaId:this.config.id,oramaVersion:O.version,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,events:e};h(this.params.endpoint+`?api-key=${this.config.api_key}`,JSON.stringify(t))?.catch(i=>console.log(i))}start(){let e=setInterval(this.flush.bind(this),this.config.flushInterval);e.unref!=null&&e.unref()}};var m=class{constructor(e){this.params=e}intervalId;start(){this.stop(),this.intervalId=setInterval(this.beat.bind(this),this.params.frequency)}stop(){this.intervalId!==void 0&&clearInterval(this.intervalId)}beat(){h(this.params.endpoint)?.catch(e=>console.log(e))}};var _=class{id=A();api_key;endpoint;collector;cache;heartbeat;initPromise;constructor(e){if(this.api_key=e.api_key,this.endpoint=e.endpoint,e.telemetry!==!1){let t={id:this.id,api_key:this.api_key,flushInterval:e.telemetry?.flushInterval??5e3,flushSize:e.telemetry?.flushSize??25};this.collector=u.create(t)}if(e.cache!==!1){let t={};this.cache=new d(t)}this.init()}async search(e,t){await this.initPromise;let i="search-"+JSON.stringify(e),s,r,o=!1;if((t?.fresh!==!0&&this.cache?.has(i))===!0&&this.cache!=null)s=0,r=this.cache.get(i),o=!0;else{let n=Date.now();r=await this.fetch("search","POST",{q:e},t?.abortController);let c=Date.now();r.elapsed=await v(BigInt(c*1e6-n*1e6)),s=c-n,this.cache?.set(i,r)}return this.collector!=null&&this.collector.add({rawSearchString:e.term,resultsCount:r.hits.length,roundTripTime:s,query:e,cached:o,searchedAt:new Date}),r}async vectorSearch(e,t){await this.initPromise;let i="vectorSearch-"+JSON.stringify(e),s,r,o=!1;if((t?.fresh!==!0&&this.cache?.has(i))===!0&&this.cache!=null)s=0,r=this.cache.get(i),o=!0;else{let n=Date.now();r=await this.fetch("vector-search2","POST",{q:e},t?.abortController);let c=Date.now();r.elapsed=await v(BigInt(c*1e6-n*1e6)),s=c-n,this.cache?.set(i,r)}return this.collector!=null&&this.collector.add({rawSearchString:e.term,resultsCount:r.hits.length,roundTripTime:s,query:e,cached:o,searchedAt:new Date}),r}startHeartBeat(e){this.heartbeat?.stop(),this.heartbeat=new m({...e,endpoint:this.endpoint+`/health?api-key=${this.api_key}`}),this.heartbeat.start()}stopHeartBeat(){this.heartbeat?.stop()}async getPop(){return(await this.initPromise)?.pop??""}init(){this.initPromise=this.fetch("init","GET").then(e=>(this.collector?.setParams({endpoint:e.collectUrl,deploymentID:e.deploymentID,index:e.index}),e)).catch(e=>(console.log(e),null))}async fetch(e,t,i,s){if(s?.signal.aborted===!0)throw new Error("Request aborted");let r={method:t,headers:{"Content-Type":"application/x-www-form-urlencoded"},signal:s?.signal};if(t==="POST"&&i!==void 0){let a=i;a.version=S,a.id=this.id,r.body=Object.entries(a).map(([n,c])=>`${n}=${encodeURIComponent(JSON.stringify(c))}`).join("&")}let o=await fetch(`${this.endpoint}/${e}?api-key=${this.api_key}`,r);if(!o.ok){let a=new Error;throw a.httpResponse=o,a}return await o.json()}};var R=class{CSRFToken="";ready;api_key;constructor(e){this.api_key=e.api_key,this.ready=this.init().then(()=>!0).catch(t=>(console.log(t),!1))}async generateEmbeddings(e){if(!await this.ready)return console.log("OramaProxy had an error during the initialization"),[];let i=`${p}${g}?apiKey=${this.api_key}`;return(await fetch(i,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},referrer:this.getReferrer(),body:new URLSearchParams({query:e,csrf:this.CSRFToken}).toString()})).json()}async chat(e,t){if(!await this.ready){console.log("OramaProxy had an error during the initialization");return}let s=`${p}${C}?apiKey=${this.api_key}`,r=await fetch(s,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},referrer:this.getReferrer(),body:new URLSearchParams({messages:JSON.stringify(e),csrf:this.CSRFToken}).toString()});if(!r.ok||r.body==null)throw r.statusText;let o=r.body.getReader(),a=new TextDecoder;for(;;){let{value:n,done:c}=await o.read();if(c)break;let E=a.decode(n,{stream:!0});t(E)}}async init(){let e=`${p}${y}?apiKey=${this.api_key}`,i=await(await fetch(e,{referrer:this.getReferrer()})).json();console.log({data:i}),this.CSRFToken=i.csrfToken}isServer(){return typeof window>"u"}getReferrer(){return this.isServer()?"http://localhost":window.location.href}};export{_ as OramaClient,R as OramaProxy};
import{formatElapsedTime as T}from"@orama/orama/components";import{createId as x}from"@paralleldrive/cuid2";var p=class{cache;config;constructor(e){this.cache=new Map,this.config=e}set(e,t){this.cache.set(e,t)}get(e){return this.cache.get(e)}has(e){return this.cache.has(e)}delete(e){return this.cache.delete(e)}clear(){this.cache.clear()}size(){return this.cache.size}};var h="https://secure-proxy.orama.foo",y="/init",_="/chat",g="/query";var O="1.0.0-beta.23";var E={name:"@oramacloud/client",version:O,description:"Orama SDK 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:{".":{require:"./dist/index.cjs",import:"./dist/index.js",types:"./dist/index.d.ts",browser:"./dist/index.global.js"},"./react":{require:"./dist/react/index.cjs",import:"./dist/react/index.js",types:"./dist/react/index.d.ts"},"./vue":{require:"./dist/vue/index.cjs",import:"./dist/vue/index.js",types:"./dist/vue/index.d.ts"}},scripts:{format:"bunx @biomejs/biome format src --write",build:"npm run build:lib && npm run build:react","build:lib":"tsup --config tsup.lib.js","build:react":"tsup --config tsup.react.js","build:vue":"tsup --config tsup.vue.js",test:"tsx tests/proxy.e2e.test","serve:example":"esbuild src/index.ts --bundle --outfile=example/out.js --format=esm --watch --servedir=example",prepare:"husky install"},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/orama":"^2.0.0-beta.9","@paralleldrive/cuid2":"^2.2.1",react:"^18.2.0",vue:"^3.3.4"},devDependencies:{"@biomejs/biome":"^1.4.1","@fastify/formbody":"^7.4.0","@types/node":"^20.3.1","@types/react":"^18.2.14",dotenv:"^16.3.1",esbuild:"0.18.5",fastify:"^4.19.2",husky:"^8.0.3",openai:"^4.24.1","ts-standard":"^12.0.2",tsup:"^7.1.0",tsx:"^3.12.7",typescript:"^5.1.3"},"ts-standard":{ignore:["dist","node_modules"]}};function d(n,e){if(typeof navigator<"u"){navigator.sendBeacon(n,e);return}fetch(n,{method:"POST",body:e,headers:{"Content-Type":"application/json"}}).then(()=>{},t=>console.log(t))}var u=class n{data;params;config;constructor(e){this.data=[],this.config=e}setParams(e){this.params=e}static create(e){let t=new n(e);return t.start(),t}add(e){this.data.push({rawSearchString:e.rawSearchString,query:e.query,resultsCount:e.resultsCount,roundTripTime:e.roundTripTime,searchedAt:e.searchedAt,referer:typeof location<"u"?location.toString():void 0}),this.params!=null&&this.data.length>=this.config.flushSize&&this.flush()}flush(){if(this.params==null||this.data.length===0)return;let e=this.data;this.data=[];let t={source:"fe",deploymentID:this.params.deploymentID,index:this.params.index,oramaId:this.config.id,oramaVersion:E.version,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,events:e};d(this.params.endpoint+`?api-key=${this.config.api_key}`,JSON.stringify(t))?.catch(r=>console.log(r))}start(){let e=setInterval(this.flush.bind(this),this.config.flushInterval);e.unref!=null&&e.unref()}};var m=class{constructor(e){this.params=e}intervalId;start(){this.stop(),this.intervalId=setInterval(this.beat.bind(this),this.params.frequency)}stop(){this.intervalId!==void 0&&clearInterval(this.intervalId)}beat(){d(this.params.endpoint)?.catch(e=>console.log(e))}};var S=class{id=x();api_key;endpoint;collector;cache;heartbeat;initPromise;constructor(e){if(this.api_key=e.api_key,this.endpoint=e.endpoint,e.telemetry!==!1){let t={id:this.id,api_key:this.api_key,flushInterval:e.telemetry?.flushInterval??5e3,flushSize:e.telemetry?.flushSize??25};this.collector=u.create(t)}if(e.cache!==!1){let t={};this.cache=new p(t)}this.init()}async search(e,t){await this.initPromise;let r="search-"+JSON.stringify(e),i,s,o=!1;if((t?.fresh!==!0&&this.cache?.has(r))===!0&&this.cache!=null)i=0,s=this.cache.get(r),o=!0;else{let c=Date.now();s=await this.fetch("search","POST",{q:e},t?.abortController);let l=Date.now();s.elapsed=await T(BigInt(l*1e6-c*1e6)),i=l-c,this.cache?.set(r,s)}return this.collector!=null&&this.collector.add({rawSearchString:e.term,resultsCount:s.hits.length,roundTripTime:i,query:e,cached:o,searchedAt:new Date}),s}async vectorSearch(e,t){await this.initPromise;let r="vectorSearch-"+JSON.stringify(e),i,s,o=!1;if((t?.fresh!==!0&&this.cache?.has(r))===!0&&this.cache!=null)i=0,s=this.cache.get(r),o=!0;else{let c=Date.now();s=await this.fetch("vector-search2","POST",{q:e},t?.abortController);let l=Date.now();s.elapsed=await T(BigInt(l*1e6-c*1e6)),i=l-c,this.cache?.set(r,s)}return this.collector!=null&&this.collector.add({rawSearchString:e.term,resultsCount:s.hits.length,roundTripTime:i,query:e,cached:o,searchedAt:new Date}),s}startHeartBeat(e){this.heartbeat?.stop(),this.heartbeat=new m({...e,endpoint:this.endpoint+`/health?api-key=${this.api_key}`}),this.heartbeat.start()}stopHeartBeat(){this.heartbeat?.stop()}async getPop(){return(await this.initPromise)?.pop??""}init(){this.initPromise=this.fetch("init","GET").then(e=>(this.collector?.setParams({endpoint:e.collectUrl,deploymentID:e.deploymentID,index:e.index}),e)).catch(e=>(console.log(e),null))}async fetch(e,t,r,i){if(i?.signal.aborted===!0)throw new Error("Request aborted");let s={method:t,headers:{"Content-Type":"application/x-www-form-urlencoded"},signal:i?.signal};if(t==="POST"&&r!==void 0){let a=r;a.version=O,a.id=this.id,s.body=Object.entries(a).map(([c,l])=>`${c}=${encodeURIComponent(JSON.stringify(l))}`).join("&")}let o=await fetch(`${this.endpoint}/${e}?api-key=${this.api_key}`,s);if(!o.ok){let a=new Error;throw a.httpResponse=o,a}return await o.json()}};var A="text-embedding-ada-002";var v="gpt-4-1106-preview",R="gpt-4",b="gpt-3.5-turbo",I="gpt-3.5-turbo-16k",M={[`openai/${A}`]:A},N={[`openai/${b}`]:b,[`openai/${R}`]:R,[`openai/${I}`]:I,[`openai/${v}`]:v},D=class{CSRFToken="";ready;api_key;constructor(e){this.api_key=e.api_key,this.ready=this.init().then(()=>!0).catch(t=>(console.log(t),!1))}async generateEmbeddings(e,t){if(!await this.ready)return console.log("OramaProxy had an error during the initialization"),[];let i=`${h}${g}?apiKey=${this.api_key}`;return(await fetch(i,{method:"POST",headers:this.getHeaders(),body:new URLSearchParams({query:e,csrf:this.CSRFToken,model:M[t]}).toString()})).json()}async chat(e){if(!await this.ready)return console.log("OramaProxy had an error during the initialization"),"";let r="";for await(let i of this.chatStream(e))r+=i;return r}async*chatStream(e){let t=`${h}${_}?apiKey=${this.api_key}`,r=await fetch(t,{method:"POST",headers:this.getHeaders(),body:new URLSearchParams({messages:JSON.stringify(e.messages),csrf:this.CSRFToken,model:N[e.model]}).toString()});if(!r.ok||r.body==null)throw r.statusText;let i=r.body.getReader(),s=new TextDecoder;for(;;){let{value:o,done:a}=await i.read();if(a)break;yield s.decode(o,{stream:!0})}}async init(){let e=`${h}${y}?apiKey=${this.api_key}`,r=await(await fetch(e,{headers:{referer:this.getReferrer()}})).json();this.CSRFToken=r.csrfToken}isServer(){return typeof window>"u"}getHeaders(){return{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",referer:this.getReferrer()}}getReferrer(){return this.isServer()?"http://localhost":window.location.href}};export{S as OramaClient,D as OramaProxy};
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import R,{useState as f,useEffect as S,createContext as E,useContext as I}from"react";import{formatElapsedTime as b}from"@orama/orama/components";import{createId as w}from"@paralleldrive/cuid2";var h=class{cache;config;constructor(e){this.cache=new Map,this.config=e}set(e,t){this.cache.set(e,t)}get(e){return this.cache.get(e)}has(e){return this.cache.has(e)}delete(e){return this.cache.delete(e)}clear(){this.cache.clear()}size(){return this.cache.size}};var g="1.0.0-beta.22";var v={name:"@oramacloud/client",version:g,description:"Orama SDK 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:{".":{require:"./dist/index.cjs",import:"./dist/index.js",types:"./dist/index.d.ts",browser:"./dist/index.global.js"},"./react":{require:"./dist/react/index.cjs",import:"./dist/react/index.js",types:"./dist/react/index.d.ts"},"./vue":{require:"./dist/vue/index.cjs",import:"./dist/vue/index.js",types:"./dist/vue/index.d.ts"}},scripts:{format:"bunx @biomejs/biome format src --write",build:"npm run build:lib && npm run build:react","build:lib":"tsup --config tsup.lib.js","build:react":"tsup --config tsup.react.js","build:vue":"tsup --config tsup.vue.js",test:"tsx tests/index.test.ts","serve:example":"esbuild src/index.ts --bundle --outfile=example/out.js --format=esm --watch --servedir=example",prepare:"husky install"},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/orama":"^2.0.0-beta.9","@paralleldrive/cuid2":"^2.2.1",react:"^18.2.0",vue:"^3.3.4"},devDependencies:{"@biomejs/biome":"^1.4.1","@fastify/formbody":"^7.4.0","@types/node":"^20.3.1","@types/react":"^18.2.14",esbuild:"0.18.5",fastify:"^4.19.2",husky:"^8.0.3","ts-standard":"^12.0.2",tsup:"^7.1.0",tsx:"^3.12.7",typescript:"^5.1.3"},"ts-standard":{ignore:["dist","node_modules"]}};function u(s,e){if(typeof navigator<"u"){navigator.sendBeacon(s,e);return}fetch(s,{method:"POST",body:e,headers:{"Content-Type":"application/json"}}).then(()=>{},t=>console.log(t))}var d=class s{data;params;config;constructor(e){this.data=[],this.config=e}setParams(e){this.params=e}static create(e){let t=new s(e);return t.start(),t}add(e){this.data.push({rawSearchString:e.rawSearchString,query:e.query,resultsCount:e.resultsCount,roundTripTime:e.roundTripTime,searchedAt:e.searchedAt,referer:typeof location<"u"?location.toString():void 0}),this.params!=null&&this.data.length>=this.config.flushSize&&this.flush()}flush(){if(this.params==null||this.data.length===0)return;let e=this.data;this.data=[];let t={source:"fe",deploymentID:this.params.deploymentID,index:this.params.index,oramaId:this.config.id,oramaVersion:v.version,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,events:e};u(this.params.endpoint+`?api-key=${this.config.api_key}`,JSON.stringify(t))?.catch(i=>console.log(i))}start(){let e=setInterval(this.flush.bind(this),this.config.flushInterval);e.unref!=null&&e.unref()}};var p=class{constructor(e){this.params=e}intervalId;start(){this.stop(),this.intervalId=setInterval(this.beat.bind(this),this.params.frequency)}stop(){this.intervalId!==void 0&&clearInterval(this.intervalId)}beat(){u(this.params.endpoint)?.catch(e=>console.log(e))}};var m=class{id=w();api_key;endpoint;collector;cache;heartbeat;initPromise;constructor(e){if(this.api_key=e.api_key,this.endpoint=e.endpoint,e.telemetry!==!1){let t={id:this.id,api_key:this.api_key,flushInterval:e.telemetry?.flushInterval??5e3,flushSize:e.telemetry?.flushSize??25};this.collector=d.create(t)}if(e.cache!==!1){let t={};this.cache=new h(t)}this.init()}async search(e,t){await this.initPromise;let i="search-"+JSON.stringify(e),a,r,n=!1;if((t?.fresh!==!0&&this.cache?.has(i))===!0&&this.cache!=null)a=0,r=this.cache.get(i),n=!0;else{let c=Date.now();r=await this.fetch("search","POST",{q:e},t?.abortController);let l=Date.now();r.elapsed=await b(BigInt(l*1e6-c*1e6)),a=l-c,this.cache?.set(i,r)}return this.collector!=null&&this.collector.add({rawSearchString:e.term,resultsCount:r.hits.length,roundTripTime:a,query:e,cached:n,searchedAt:new Date}),r}async vectorSearch(e,t){await this.initPromise;let i="vectorSearch-"+JSON.stringify(e),a,r,n=!1;if((t?.fresh!==!0&&this.cache?.has(i))===!0&&this.cache!=null)a=0,r=this.cache.get(i),n=!0;else{let c=Date.now();r=await this.fetch("vector-search2","POST",{q:e},t?.abortController);let l=Date.now();r.elapsed=await b(BigInt(l*1e6-c*1e6)),a=l-c,this.cache?.set(i,r)}return this.collector!=null&&this.collector.add({rawSearchString:e.term,resultsCount:r.hits.length,roundTripTime:a,query:e,cached:n,searchedAt:new Date}),r}startHeartBeat(e){this.heartbeat?.stop(),this.heartbeat=new p({...e,endpoint:this.endpoint+`/health?api-key=${this.api_key}`}),this.heartbeat.start()}stopHeartBeat(){this.heartbeat?.stop()}async getPop(){return(await this.initPromise)?.pop??""}init(){this.initPromise=this.fetch("init","GET").then(e=>(this.collector?.setParams({endpoint:e.collectUrl,deploymentID:e.deploymentID,index:e.index}),e)).catch(e=>(console.log(e),null))}async fetch(e,t,i,a){if(a?.signal.aborted===!0)throw new Error("Request aborted");let r={method:t,headers:{"Content-Type":"application/x-www-form-urlencoded"},signal:a?.signal};if(t==="POST"&&i!==void 0){let o=i;o.version=g,o.id=this.id,r.body=Object.entries(o).map(([c,l])=>`${c}=${encodeURIComponent(JSON.stringify(l))}`).join("&")}let n=await fetch(`${this.endpoint}/${e}?api-key=${this.api_key}`,r);if(!n.ok){let o=new Error;throw o.httpResponse=n,o}return await n.json()}};var x=E({endpoint:"",apiKey:""}),q=({children:s,endpoint:e,apiKey:t})=>R.createElement(x.Provider,{value:{endpoint:e,apiKey:t}},s);function Y(s){let{apiKey:e,endpoint:t}=I(x),[i,a]=f(!1),[r,n]=f(null),[o,c]=f(null),[l,O]=f(null);return S(()=>{n(new m({api_key:e,endpoint:t})),a(!0)},[]),S(()=>{r!==null&&r.search(s).then(c).catch(O)},[r,s]),{ready:i,results:o,error:l}}export{q as OramaCloud,Y as useSearch};
import R,{useState as f,useEffect as S,createContext as E,useContext as I}from"react";import{formatElapsedTime as b}from"@orama/orama/components";import{createId as w}from"@paralleldrive/cuid2";var h=class{cache;config;constructor(e){this.cache=new Map,this.config=e}set(e,t){this.cache.set(e,t)}get(e){return this.cache.get(e)}has(e){return this.cache.has(e)}delete(e){return this.cache.delete(e)}clear(){this.cache.clear()}size(){return this.cache.size}};var g="1.0.0-beta.23";var v={name:"@oramacloud/client",version:g,description:"Orama SDK 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:{".":{require:"./dist/index.cjs",import:"./dist/index.js",types:"./dist/index.d.ts",browser:"./dist/index.global.js"},"./react":{require:"./dist/react/index.cjs",import:"./dist/react/index.js",types:"./dist/react/index.d.ts"},"./vue":{require:"./dist/vue/index.cjs",import:"./dist/vue/index.js",types:"./dist/vue/index.d.ts"}},scripts:{format:"bunx @biomejs/biome format src --write",build:"npm run build:lib && npm run build:react","build:lib":"tsup --config tsup.lib.js","build:react":"tsup --config tsup.react.js","build:vue":"tsup --config tsup.vue.js",test:"tsx tests/proxy.e2e.test","serve:example":"esbuild src/index.ts --bundle --outfile=example/out.js --format=esm --watch --servedir=example",prepare:"husky install"},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/orama":"^2.0.0-beta.9","@paralleldrive/cuid2":"^2.2.1",react:"^18.2.0",vue:"^3.3.4"},devDependencies:{"@biomejs/biome":"^1.4.1","@fastify/formbody":"^7.4.0","@types/node":"^20.3.1","@types/react":"^18.2.14",dotenv:"^16.3.1",esbuild:"0.18.5",fastify:"^4.19.2",husky:"^8.0.3",openai:"^4.24.1","ts-standard":"^12.0.2",tsup:"^7.1.0",tsx:"^3.12.7",typescript:"^5.1.3"},"ts-standard":{ignore:["dist","node_modules"]}};function u(s,e){if(typeof navigator<"u"){navigator.sendBeacon(s,e);return}fetch(s,{method:"POST",body:e,headers:{"Content-Type":"application/json"}}).then(()=>{},t=>console.log(t))}var d=class s{data;params;config;constructor(e){this.data=[],this.config=e}setParams(e){this.params=e}static create(e){let t=new s(e);return t.start(),t}add(e){this.data.push({rawSearchString:e.rawSearchString,query:e.query,resultsCount:e.resultsCount,roundTripTime:e.roundTripTime,searchedAt:e.searchedAt,referer:typeof location<"u"?location.toString():void 0}),this.params!=null&&this.data.length>=this.config.flushSize&&this.flush()}flush(){if(this.params==null||this.data.length===0)return;let e=this.data;this.data=[];let t={source:"fe",deploymentID:this.params.deploymentID,index:this.params.index,oramaId:this.config.id,oramaVersion:v.version,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,events:e};u(this.params.endpoint+`?api-key=${this.config.api_key}`,JSON.stringify(t))?.catch(i=>console.log(i))}start(){let e=setInterval(this.flush.bind(this),this.config.flushInterval);e.unref!=null&&e.unref()}};var p=class{constructor(e){this.params=e}intervalId;start(){this.stop(),this.intervalId=setInterval(this.beat.bind(this),this.params.frequency)}stop(){this.intervalId!==void 0&&clearInterval(this.intervalId)}beat(){u(this.params.endpoint)?.catch(e=>console.log(e))}};var m=class{id=w();api_key;endpoint;collector;cache;heartbeat;initPromise;constructor(e){if(this.api_key=e.api_key,this.endpoint=e.endpoint,e.telemetry!==!1){let t={id:this.id,api_key:this.api_key,flushInterval:e.telemetry?.flushInterval??5e3,flushSize:e.telemetry?.flushSize??25};this.collector=d.create(t)}if(e.cache!==!1){let t={};this.cache=new h(t)}this.init()}async search(e,t){await this.initPromise;let i="search-"+JSON.stringify(e),a,r,n=!1;if((t?.fresh!==!0&&this.cache?.has(i))===!0&&this.cache!=null)a=0,r=this.cache.get(i),n=!0;else{let c=Date.now();r=await this.fetch("search","POST",{q:e},t?.abortController);let l=Date.now();r.elapsed=await b(BigInt(l*1e6-c*1e6)),a=l-c,this.cache?.set(i,r)}return this.collector!=null&&this.collector.add({rawSearchString:e.term,resultsCount:r.hits.length,roundTripTime:a,query:e,cached:n,searchedAt:new Date}),r}async vectorSearch(e,t){await this.initPromise;let i="vectorSearch-"+JSON.stringify(e),a,r,n=!1;if((t?.fresh!==!0&&this.cache?.has(i))===!0&&this.cache!=null)a=0,r=this.cache.get(i),n=!0;else{let c=Date.now();r=await this.fetch("vector-search2","POST",{q:e},t?.abortController);let l=Date.now();r.elapsed=await b(BigInt(l*1e6-c*1e6)),a=l-c,this.cache?.set(i,r)}return this.collector!=null&&this.collector.add({rawSearchString:e.term,resultsCount:r.hits.length,roundTripTime:a,query:e,cached:n,searchedAt:new Date}),r}startHeartBeat(e){this.heartbeat?.stop(),this.heartbeat=new p({...e,endpoint:this.endpoint+`/health?api-key=${this.api_key}`}),this.heartbeat.start()}stopHeartBeat(){this.heartbeat?.stop()}async getPop(){return(await this.initPromise)?.pop??""}init(){this.initPromise=this.fetch("init","GET").then(e=>(this.collector?.setParams({endpoint:e.collectUrl,deploymentID:e.deploymentID,index:e.index}),e)).catch(e=>(console.log(e),null))}async fetch(e,t,i,a){if(a?.signal.aborted===!0)throw new Error("Request aborted");let r={method:t,headers:{"Content-Type":"application/x-www-form-urlencoded"},signal:a?.signal};if(t==="POST"&&i!==void 0){let o=i;o.version=g,o.id=this.id,r.body=Object.entries(o).map(([c,l])=>`${c}=${encodeURIComponent(JSON.stringify(l))}`).join("&")}let n=await fetch(`${this.endpoint}/${e}?api-key=${this.api_key}`,r);if(!n.ok){let o=new Error;throw o.httpResponse=n,o}return await n.json()}};var x=E({endpoint:"",apiKey:""}),q=({children:s,endpoint:e,apiKey:t})=>R.createElement(x.Provider,{value:{endpoint:e,apiKey:t}},s);function Y(s){let{apiKey:e,endpoint:t}=I(x),[i,a]=f(!1),[r,n]=f(null),[o,c]=f(null),[l,O]=f(null);return S(()=>{n(new m({api_key:e,endpoint:t})),a(!0)},[]),S(()=>{r!==null&&r.search(s).then(c).catch(O)},[r,s]),{ready:i,results:o,error:l}}export{q as OramaCloud,Y as useSearch};
//# sourceMappingURL=index.js.map
{
"name": "@oramacloud/client",
"version": "1.0.0-beta.23",
"version": "1.0.0",
"description": "Orama SDK for Node.js, Deno, and Browsers",

@@ -55,5 +55,7 @@ "type": "module",

"@types/react": "^18.2.14",
"dotenv": "^16.3.1",
"esbuild": "0.18.5",
"fastify": "^4.19.2",
"husky": "^8.0.3",
"openai": "^4.24.1",
"ts-standard": "^12.0.2",

@@ -60,0 +62,0 @@ "tsup": "^7.1.0",

@@ -40,3 +40,3 @@ # Orama Cloud Client

## Integrating with Orama Secure Proxy
## Generating embeddings via the Secure Proxy

@@ -50,10 +50,59 @@ ```js

const embeddings = await proxy.generateEmbeddings({
query: 'red leather shoes',
const embeddings = await proxy.generateEmbeddings('red leather shoes', 'openai/text-embedding-ada-002')
console.log(embeddings)
// [-0.019633075, -0.00820422, -0.013555876, -0.011825735, 0.006641511, -0.012948156, ...]
```
## Generating chat completions via the Secure Proxy
You can generate chat completions via the Secure Proxy in two different ways:
### Returning a single string
```js
import { OramaProxy } from '@oramacloud/client'
const proxy = new OramaClient({
api_key: '<Your Orama Secure Proxy API Key>'
})
await proxy.chat({
messages: [{ role: 'user', content: 'Say "hello world" in Italian' }],
onChunk: (chunk) => console.log(chunk)
const chatParams = {
model 'gpt-4',
messages: [{ role: 'user', content: 'Who is Michael Scott?' }]
}
const response = await proxy.chat(chatParams)
console.log(response)
// "Michael Scott is a fictional character from the television show "The Office" (US version) ..."
```
### Returning a stream (via async iterators)
```js
import { OramaProxy } from '@oramacloud/client'
const proxy = new OramaClient({
api_key: '<Your Orama Secure Proxy API Key>'
})
const chatParams = {
model 'gpt-4',
messages: [{ role: 'user', content: 'Who is Michael Scott?' }]
}
for await (const message of proxy.chatStream(chatParams)) {
console.log(message)
}
// Michael
// Scott is
// a fictional
// character from the
// television show
// "The
// Office" (US
// version)
// ...
```

@@ -60,0 +109,0 @@

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

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