@prexo/ai-chat-sdk
Version:
AI Chat SDK for building AI chat applications with Context and History
3 lines • 3.05 kB
JavaScript
;var f=Object.defineProperty;var l=(i,e,n)=>e in i?f(i,e,{enumerable:true,configurable:true,writable:true,value:n}):i[e]=n;var o=(i,e,n)=>l(i,typeof e!="symbol"?e+"":e,n);var s="1.0.1-beta.1";var a={};function u(){try{return typeof process<"u"&&process.env?.PREXO_SDK_VERSION?process.env.PREXO_SDK_VERSION:typeof window<"u"&&window.__PREXO_SDK_VERSION__?window.__PREXO_SDK_VERSION__:typeof globalThis<"u"&&globalThis.__PREXO_SDK_VERSION__?globalThis.__PREXO_SDK_VERSION__:s}catch{return s}}function h(i,e){return `${i}::${e}`}var d=class{constructor(e){o(this,"enabled");o(this,"endpoint");o(this,"ingestionKey");o(this,"sdkVersion");o(this,"ingestionKeyPromise");let n=typeof process<"u"&&process.env?.DISABLE_TELEMETRY==="1";this.enabled=e.enabled??!n,this.endpoint=(typeof process<"u"&&process.env,"https://api.prexoai.xyz/v1/telementry"),this.sdkVersion=u(),e.ingestionKey&&(this.ingestionKey=e.ingestionKey);}async fetchIngestionKeyCached(){let e="";typeof window<"u"&&window.location&&window.location.origin&&(typeof process<"u"&&process.env,e=window.location.origin);let n=h(this.endpoint,e);return a[n]||(a[n]=this.fetchIngestionKey(e)),a[n]}async fetchIngestionKey(e){let n=this.endpoint?this.endpoint.replace(/\/?$/,"/key"):"https://api.prexoai.xyz/v1/telementry/key";try{let t=await fetch(n,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({domain:e})});if(!t.ok)throw new Error("Failed to fetch ingestion key");return (await t.json()).key||"prexoai-ingest-key"}catch{return "prexoai-ingest-key"}}detectBrowser(){if(typeof window<"u"&&typeof navigator<"u"){let e=navigator.userAgent||"unknown",n=navigator.appVersion||"unknown",t=navigator.vendor||"unknown",r=navigator.language||"unknown",c=navigator.platform||"unknown",p=navigator.cookieEnabled!==void 0?String(navigator.cookieEnabled):"unknown",y=navigator.hardwareConcurrency!==void 0?String(navigator.hardwareConcurrency):"unknown",g=navigator.deviceMemory!==void 0?String(navigator.deviceMemory):"unknown";return [`UserAgent: ${e}`,`AppVersion: ${n}`,`Vendor: ${t}`,`Language: ${r}`,`Platform: ${c}`,`CookieEnabled: ${p}`,`HardwareConcurrency: ${y}`,`DeviceMemory: ${g}`].join("; ")}return "not-browser"}detectPlatform(){return typeof navigator<"u"&&typeof navigator.platform=="string"?navigator.platform||"unknown":typeof process<"u"&&typeof process.platform=="string"?process.platform:"unknown"}async send(e,n){if(!this.enabled)return;let t=this.ingestionKey;t||(this.ingestionKeyPromise||(this.ingestionKeyPromise=this.fetchIngestionKeyCached()),t=await this.ingestionKeyPromise,this.ingestionKey=t);let r={event:e,properties:{...n,sdkVersion:this.sdkVersion,browser:this.detectBrowser(),platform:this.detectPlatform(),timestamp:new Date().toISOString()}};try{await fetch(this.endpoint,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json","x-ingest-key":t},body:JSON.stringify(r)});}catch{}}};
exports.Telementry=d;//# sourceMappingURL=telemetry.cjs.map
//# sourceMappingURL=telemetry.cjs.map