@sentientui/core 0.16.2 → 0.16.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-SHGSYP75.mjs +2 -0
- package/dist/{chunk-I2QGVQI6.mjs.map → chunk-SHGSYP75.mjs.map} +1 -1
- package/dist/{index-C247KMBw.d.ts → index-CTs3AM9E.d.ts} +3 -1
- package/dist/{index-CZLjrtM4.d.cts → index-DqbtJfra.d.cts} +3 -1
- package/dist/index-engagement.js +1 -1
- package/dist/index-engagement.js.map +1 -1
- package/dist/index-engagement.mjs +1 -1
- package/dist/index-engagement.mjs.map +1 -1
- package/dist/index-graph.d.cts +2 -2
- package/dist/index-graph.d.ts +2 -2
- package/dist/index-graph.mjs +1 -1
- package/dist/index-local.d.cts +1 -1
- package/dist/index-local.d.ts +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-I2QGVQI6.mjs +0 -2
package/dist/chunk-I2QGVQI6.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{b as ie,d as ae,e as le,f as ce,g as de,j as ue,k as ne,m as ge}from"./chunk-L5TA3FAB.mjs";import{a as w,b as j}from"./chunk-TMCGHANO.mjs";var Ne="_snt_uid";var F="_snt_uid";function Me(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(t){}let e=()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0");return`${e()}-${e()}-${e()}-${e()}`}function Ke(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function Ue(e,t,s){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${s}; SameSite=strict; path=/`}catch(d){}}function Ge(e){try{return localStorage.getItem(e)}catch(t){return null}}function $e(e,t){try{return localStorage.setItem(e,t),!0}catch(s){return!1}}function Be(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function We(e,t){try{return sessionStorage.setItem(e,t),!0}catch(s){return!1}}function je(e){try{sessionStorage.removeItem(e)}catch(t){}}function Fe(e){try{return document.cookie=`${e}_probe=1; max-age=1; SameSite=strict; path=/`,/(?:^|; )_snt_uid_probe=1/.test(document.cookie)||document.cookie.indexOf(`${e}_probe=1`)!==-1}catch(t){return!1}}function Je(e){try{localStorage.removeItem(e)}catch(t){}}function Qe(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var Ye={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function oe(e){var c,g,f,h,b,S;if(typeof window=="undefined")return Ye;let t=(c=e==null?void 0:e.cookieName)!=null?c:Ne,d=((g=e==null?void 0:e.cookieTTLDays)!=null?g:365)*24*60*60,l=(S=(b=(h=(f=Ke(t))!=null?f:Ge(F))!=null?h:Be(F))!=null?b:e==null?void 0:e.ssrSessionId)!=null?S:Me();Ue(t,l,d);let r=$e(F,l),i=Fe(t),n=r?!1:We(F,l),a=!r&&!i&&!n;return{getSessionId:()=>l,isEphemeral:()=>a,destroy:()=>{l=null,Qe(t),Je(F),je(F)}}}function fe(e){return`_snt_retry_${e.slice(0,12)}`}var He={push:()=>{},flush:()=>{},destroy:()=>{}};function ze(e,t){try{let s=localStorage.getItem(t);if(!s)return[];let d=JSON.parse(s);return Array.isArray(d)?(localStorage.removeItem(t),d.slice(-e)):[]}catch(s){return[]}}function pe(e,t,s){try{let l=[...(()=>{try{let r=localStorage.getItem(s);if(!r)return[];let i=JSON.parse(r);return Array.isArray(i)?i:[]}catch(r){return[]}})(),...e].slice(-t);localStorage.setItem(s,JSON.stringify(l))}catch(d){}}function xe(e){var z,V,q;if(typeof window=="undefined")return He;let t=(z=e.flushIntervalMs)!=null?z:5e3,s=(V=e.maxBatchSize)!=null?V:20,d=(q=e.maxRetrySize)!=null?q:100,l=e.ingestUrl,r=e.apiKey,i=fe(r),n=[],a=new Set,c=[],g=p=>{for(let y of p)f.delete(y),!a.has(y)&&(a.add(y),c.push(y));for(;c.length>500;){let y=c.shift();y&&a.delete(y)}},f=new Set,h=p=>{a.has(p.id)||f.has(p.id)||(f.add(p.id),n.push(p))},b=ze(d,i);for(let p of b)h(p);let S=0,A=0,k=p=>{if(p.length===0)return;let y=JSON.stringify(p),x=p.map(o=>o.id),O;try{O=fetch(l,{method:"POST",keepalive:!0,body:y,headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`}})}catch(o){pe(p,d,i);for(let u of x)f.delete(u);A++,S=Date.now()+Math.min(6e4,1e3*2**Math.min(A,6));return}let N=o=>{if(o.ok||o.status>=400&&o.status<500&&o.status!==429){g(x),A=0,S=0;return}pe(p,d,i);for(let u of x)f.delete(u);A++,S=Date.now()+Math.min(6e4,1e3*2**Math.min(A,6))};O instanceof Promise?O.then(N).catch(()=>{pe(p,d,i);for(let o of x)f.delete(o);A++,S=Date.now()+Math.min(6e4,1e3*2**Math.min(A,6))}):N(O)},v=typeof TextEncoder!="undefined"?new TextEncoder:null,te=p=>v?v.encode(p).length:p.length,U=p=>{let y=[],x=2;for(let O of p){let N=te(JSON.stringify(O))+1;if(y.length>0&&x+N>57344||y.length>=s)break;y.push(O),x+=N}return y},L=()=>{try{if(Date.now()<S)return;for(;n.length>0;){let p=n.filter(x=>!a.has(x.id));if(n.length=0,p.length===0)break;let y=U(p);if(y.length===0)break;y.length<p.length&&n.push(...p.slice(y.length)),k(y)}}catch(p){}},R=!0,G=null;G=setInterval(()=>{R&&L()},t);let Y=()=>{document.visibilityState==="hidden"&&L()},H=()=>{L()};return document.addEventListener("visibilitychange",Y),window.addEventListener("pagehide",H),{push(p){h(p),n.length>=s&&L()},flush:L,destroy(){R=!1,G!==null&&(clearInterval(G),G=null),document.removeEventListener("visibilitychange",Y),window.removeEventListener("pagehide",H),L()}}}var ye="_snt_asgn_";function se(e,t){return`${e}:${t}`}function Ve(e,t){return`${ye}${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function _e(e){let t=e.slice(ye.length),s=t.indexOf(":");if(s<0)return null;try{return{componentId:decodeURIComponent(t.slice(0,s)),segment:decodeURIComponent(t.slice(s+1))}}catch(d){return null}}function me(){try{let e=[];for(let t=0;t<localStorage.length;t++){let s=localStorage.key(t);s!=null&&s.startsWith(ye)&&e.push(s)}return e}catch(e){return[]}}function Ce(e=18e5){let t=new Map,s=l=>l.assignedAt+e<Date.now();return typeof window!="undefined"&&(()=>{for(let l of me())try{let r=localStorage.getItem(l);if(!r)continue;let i=JSON.parse(r);if(s(i)){localStorage.removeItem(l);continue}let n=_e(l);if(!n)continue;t.set(se(n.componentId,n.segment),i)}catch(r){}})(),{get(l,r){let i=t.get(se(l,r));return i?s(i)?(t.delete(se(l,r)),null):i:null},set(l,r,i){let n=se(l,r);t.set(n,i);try{localStorage.setItem(Ve(l,r),JSON.stringify(i))}catch(a){}},invalidate(l){let r=`${l}:`;for(let i of[...t.keys()])i.startsWith(r)&&t.delete(i);for(let i of me()){let n=_e(i);if((n==null?void 0:n.componentId)===l)try{localStorage.removeItem(i)}catch(a){}}},clear(){t.clear();for(let l of me())try{localStorage.removeItem(l)}catch(r){}}}}var J="_snt_snap:",qe=["low","medium","high"];function Se(e){try{let t=localStorage.getItem(J+e);if(!t)return null;let s=JSON.parse(t);return!s||typeof s!="object"||s.v!==1||typeof s.persona!="string"||typeof s.band!="string"||!qe.includes(s.band)||typeof s.slots!="object"||s.slots===null||Array.isArray(s.slots)||!(s.layoutOrder===null||Array.isArray(s.layoutOrder))||typeof s.savedAt!="number"||!(s.slotConfig===void 0||typeof s.slotConfig=="object"&&s.slotConfig!==null&&!Array.isArray(s.slotConfig))?null:s}catch(t){return null}}function ee(e,t){try{localStorage.setItem(J+e,JSON.stringify(t))}catch(s){}}function Xe(e){return"(function(){try{var r=localStorage.getItem("+JSON.stringify(J+e).replace(/</g,"\\u003c")+');if(!r)return;var s=JSON.parse(r);if(!s||s.v!==1||typeof s.persona!=="string"||typeof s.band!=="string")return;var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",s.persona);d.setAttribute("data-sentient-confidence",s.band);}catch(e){}})();'}import{confidenceBand as Oe}from"@sentientui/policy";import{confidenceBand as he}from"@sentientui/policy";var ve="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",ke="[sentient] Local mode \u2014 decisions are simulated on-device and nothing is sent over the network. Add an API key to learn from real traffic.",Ae=!1,re=!1;function Ze(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(t){return}}function Re(e){var n;let t=oe({ssrSessionId:e.ssrSessionId}),s=(n=t.getSessionId())!=null?n:"local",d=Ze(),l=import("@sentientui/core/local").then(a=>{let c=a;return c.LOCAL_ENGINE_AVAILABLE?(Ae||(Ae=!0,console.info(ke)),c):(re||(re=!0,console.error(ve)),null)}).catch(()=>(re||(re=!0,console.error(ve)),null)),r=null;function i(a){let c=document.documentElement;c.dataset.sentientPersona===void 0&&(c.dataset.sentientPersona=a.persona,c.dataset.sentientConfidence=he(a.confidence))}return{isLocal:!0,async decide(a){var f,h,b;let c=await l;if(!c)return null;let g=c.createLocalEngine({sessionId:s,forcedPersona:d}).decide(a);return r=j(w({},g),{layoutOrder:(h=(f=g.layoutOrder)!=null?f:r==null?void 0:r.layoutOrder)!=null?h:null,slots:w(w({},(b=r==null?void 0:r.slots)!=null?b:{}),g.slots)}),ee(e.apiKey||"local",{v:1,persona:r.persona,band:he(r.confidence),slots:r.slots,layoutOrder:r.layoutOrder,savedAt:Date.now()}),i(g),g},getSlotResult(a){var c,g,f;return(f=(g=r==null?void 0:r.slots[a])!=null?g:(c=e.initialSlots)==null?void 0:c[a])!=null?f:null},getPersona(){return r?{persona:r.persona,confidence:r.confidence,band:he(r.confidence)}:null},async assign(a,c){var h;let g=await l;return!g||!c||c.length===0?c!=null&&c[0]?{variantId:c[0],assignmentTtlMs:0}:null:{variantId:(h=g.createLocalEngine({sessionId:s,forcedPersona:d}).decide({components:[{id:a,variantIds:c}]}).assignments[a])!=null?h:c[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>t.destroy()}}function et(e,t,s){let d=[];{let i=!1,n=[],a=()=>{if(i)return;let c=Date.now();for(n.push(c);n.length>0&&c-n[0]>500;)n.shift();n.length>=3&&(i=!0,e("rage_click"))};t.addEventListener("click",a),d.push(()=>t.removeEventListener("click",a))}{let l=!1,r=i=>{if(l||!(i.target instanceof Node)||!t.contains(i.target)&&t!==i.target)return;l=!0;let n=typeof window!="undefined"?window.getSelection():null,a=n?n.toString().length:0;e("text_copy",{selectionLength:a})};document.addEventListener("copy",r),d.push(()=>document.removeEventListener("copy",r))}{let l=!1,r=!1,i=null,n=()=>{i!==null&&(clearTimeout(i),i=null)},a=()=>{l||!r||(n(),i=setTimeout(()=>{!l&&r&&(l=!0,e("scroll_hesitation"))},3e3))},c=()=>{n(),a()},g=h=>{for(let b of h)r=b.intersectionRatio>.3,r?a():n()},f=new IntersectionObserver(g,{threshold:[.3]});f.observe(t),window.addEventListener("scroll",c,{passive:!0}),d.push(()=>{f.disconnect(),window.removeEventListener("scroll",c),n()})}{let l=!1,r=s!=null?s:Date.now(),i=()=>{if(l||document.visibilityState!=="hidden")return;let n=Date.now()-r;n<15e3&&(l=!0,e("tab_loss",{timeOnPage:n}))};document.addEventListener("visibilitychange",i),d.push(()=>document.removeEventListener("visibilitychange",i))}return()=>{for(let l of d)l()}}var De="https://api.sentient-ui.com/v1/events",W=new Map,Te=null;function Ee(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(e){}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}var Q={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,assign:()=>Promise.resolve(null),decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}};function tt(){try{let e={},t=new URLSearchParams(window.location.search);for(let[s,d]of t)s.startsWith("utm_")&&(e[s]=d);return e}catch(e){return{}}}function Le(e){return e.replace(/\/events\/?$/,"")}function Pe(){return typeof navigator!="undefined"&&navigator.globalPrivacyControl===!0?!0:[typeof navigator!="undefined"?navigator.doNotTrack:void 0,typeof window!="undefined"?window.doNotTrack:void 0,typeof navigator!="undefined"?navigator.msDoNotTrack:void 0].some(t=>t==="1"||t==="yes")}function Ct(e){if(typeof window=="undefined")return;let t=e!=null?e:Te;if(!t){console.warn("[sentient] grantConsent() called before init()");return}let s=W.get(t);if(!s){console.warn("[sentient] grantConsent() called before init()");return}let{config:d,upgrade:l}=s;if(!l||d.respectDoNotTrack!==!1&&Pe())return;let r=ot(j(w({},d),{consent:!0}));l(r),W.set(t,{config:j(w({},d),{consent:!0}),upgrade:null})}function nt(e){var i;let t=Le((i=e.ingestUrl)!=null?i:De),s={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},d={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),async assign(n,a,c){try{let g=new URLSearchParams({componentId:n});for(let b of a!=null?a:[])g.append("variantIds[]",b);let f=await fetch(`${t}/winner?${g.toString()}`,{headers:s});return f.ok?{variantId:(await f.json()).variantId,assignmentTtlMs:0}:a!=null&&a[0]?{variantId:a[0],assignmentTtlMs:0}:null}catch(g){return a!=null&&a[0]?{variantId:a[0],assignmentTtlMs:0}:null}},decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}},l={track:n=>d.track(n),goal:(n,a,c,g)=>d.goal(n,a,c,g),componentGoal:(n,a,c)=>d.componentGoal(n,a,c),identify:n=>d.identify(n),getAssignment:(n,a)=>d.getAssignment(n,a),assign:(n,a,c,g)=>d.assign(n,a,c,g),decide:n=>d.decide(n),getSlotResult:n=>d.getSlotResult(n),getPersona:()=>d.getPersona(),fetchWeights:()=>d.fetchWeights(),getGraph:()=>d.getGraph(),dispose:()=>d.dispose(),destroy:()=>d.destroy()};function r(n){d=n}return{proxy:l,setInner:r}}function ot(e){var H,z,V,q,p,y,x,O,N;if(typeof window=="undefined")return Q;Te=e.apiKey;let t=e.respectDoNotTrack!==!1&&Pe(),s=e.consent===!1||t,d=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!d&&e.localMode!==!1)return s?(W.set(e.apiKey||"local",{config:e,upgrade:null}),Q):(W.set(e.apiKey||"local",{config:e,upgrade:null}),Re(e));if(s){if(e.preConsentBehavior==="statistical_winner"){if(!e.apiKey||!e.apiKey.startsWith("pk_"))return console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),Q;let{proxy:o,setInner:u}=nt(e);return W.set(e.apiKey,{config:e,upgrade:t?null:u}),o}return W.set(e.apiKey,{config:e,upgrade:null}),Q}if(!e.apiKey||!e.apiKey.startsWith("pk_"))return console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),Q;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),Q;let l=(H=e.ingestUrl)!=null?H:De,r=Date.now(),i=oe({ssrSessionId:e.ssrSessionId}),n=Ce(),a=xe({ingestUrl:l,apiKey:e.apiKey}),c=Le(l),g={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},f=ae((z=navigator.userAgent)!=null?z:""),h=typeof window!="undefined"?window.location.origin:void 0,b=le((V=document.referrer)!=null?V:"",h),S=(q=e.sessionSegment)!=null?q:`${f}:${b}`,A=new Map,k=new Map,v=null,te=o=>{for(let u of o)k.has(u.id)||k.set(u.id,ne(u))};if(e.initialSlots)for(let[o,u]of Object.entries(e.initialSlots))k.set(o,u);let U=Se(e.apiKey);if(U)for(let[o,u]of Object.entries(U.slots))k.has(o)||k.set(o,u);let L={low:.15,medium:.5,high:.85};if(e.initialPersona)v=w({},e.initialPersona);else{let o=document.documentElement.dataset;o.sentientPersona?v={persona:o.sentientPersona,confidence:(y=L[(p=o.sentientConfidence)!=null?p:"low"])!=null?y:.15}:U&&(v={persona:U.persona,confidence:(x=L[U.band])!=null?x:.15})}if(e.initialAssignments)for(let[o,u]of Object.entries(e.initialAssignments))n.set(o,S,{variantId:u,assignedAt:Date.now(),segment:S,confidence:1});let R=Promise.resolve(),G=i.getSessionId();if(G){let o=ce((O=document.referrer)!=null?O:""),u=w(w({sessionId:G,deviceClass:f,trafficSource:b,referrerDomain:o,utmParams:tt(),timeOfDay:de(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:i.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||ie((N=navigator.userAgent)!=null?N:"")},e.userId?{userId:e.userId}:{}),e.country?{country:e.country}:{});try{R=fetch(`${c}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(u),headers:g}).then(m=>{m.status===402&&console.warn("[SentientUI] Session limit exceeded for this project. The bandit will stop learning until the limit resets. Upgrade at sentient-ui.com/pricing")}).catch(()=>{})}catch(m){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:a});let Y={goal(o,u={},m=1,D=0){let I=i.getSessionId();if(!I)return;let _=Ee();R.then(()=>{fetch(`${c}/goals`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:I,name:o,metadata:u,weight:m,stepIndex:D,goalId:_}),headers:g}).catch(()=>{})})},componentGoal(o,u,m){var T,K,P;let D=i.getSessionId();if(!D)return;let I=n.get(o,S),_=I?null:(T=k.get(o))!=null?T:null;if(!I&&_===null){e.debug&&console.warn(`[sentient] componentGoal("${o}"): no assignment or slot decision yet \u2014 render its <Adaptive>/adaptive hook or call assign()/decide() before recording a goal.`);return}let $=I?I.variantId:ge(_),M={id:Ee(),sessionId:D,projectId:e.apiKey,componentId:o,variantId:$,eventType:"goal_achieved",goalType:u,payload:w({reward:(K=m==null?void 0:m.reward)!=null?K:1},(P=m==null?void 0:m.metadata)!=null?P:{}),timestamp:Date.now(),timeInSession:Date.now()-r};e.debug&&console.log("[sentient] componentGoal",M),R.then(()=>a.push(M))},identify(o){let u=i.getSessionId();u&&R.then(()=>{fetch(`${c}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:u,userId:o,ephemeral:i.isEphemeral()}),headers:g}).catch(()=>{})})},track(o){let u=i.getSessionId();if(!u)return;let m=j(w({},o),{id:Ee(),sessionId:u,timestamp:Date.now(),timeInSession:Date.now()-r});e.debug&&console.log("[sentient] track",m),R.then(()=>a.push(m))},getAssignment(o,u){return n.get(o,u)},async assign(o,u,m,D){let I=i.getSessionId();if(!I)return null;let _=n.get(o,S);if(_&&(u!=null&&u.length||_.content!==void 0))return{variantId:_.variantId,assignmentTtlMs:0,content:_.content};let $=A.get(o);if($)return $;let M=(async()=>{await R;try{let T={sessionId:I,componentId:o,variantIds:u};D!==void 0?T.agentDataByVariant=D:m!==void 0&&(T.agentData=m);let K=await fetch(`${c}/assign`,{method:"POST",body:JSON.stringify(T),headers:g});if(!K.ok)return null;let P=await K.json();return n.set(o,S,{variantId:P.variantId,assignedAt:Date.now(),segment:S,confidence:1,content:P.content}),P}catch(T){return null}finally{A.delete(o)}})();return A.set(o,M),M},async decide(o){var D,I,_,$,M,T,K,P,we,be;let u=i.getSessionId();if(!u)return null;let m=(D=o.slots)!=null?D:[];await R;try{let B={sessionId:u};o.sections&&o.sections.length>0&&(B.sections=o.sections.map(C=>({id:C}))),B.components=(I=o.components)!=null?I:[],m.length>0&&(B.slots=m.map(ue)),o.slotsFrom==="registry"&&(B.slotsFrom="registry"),o.v&&(B.v=o.v);let Ie=await fetch(`${c}/decide`,{method:"POST",body:JSON.stringify(B),headers:g});if(!Ie.ok)return te(m),null;let E=await Ie.json(),X={};for(let C of m)X[C.id]=($=(_=E.slots)==null?void 0:_[C.id])!=null?$:ne(C);if(E.slots)for(let[C,Z]of Object.entries(E.slots))C in X||(X[C]=Z);for(let[C,Z]of Object.entries(X))k.set(C,Z);v={persona:(M=E.persona)!=null?M:"unknown",confidence:(T=E.confidence)!=null?T:0};for(let[C,Z]of Object.entries((K=E.assignments)!=null?K:{}))n.set(C,S,{variantId:Z,assignedAt:Date.now(),segment:S,confidence:1});return ee(e.apiKey,w({v:1,persona:v.persona,band:Oe(v.confidence),slots:Object.fromEntries(k),layoutOrder:(P=E.layoutOrder)!=null?P:null,savedAt:Date.now()},E.slotConfig?{slotConfig:E.slotConfig}:{})),w(w({layoutOrder:(we=E.layoutOrder)!=null?we:null,assignments:(be=E.assignments)!=null?be:{},slots:X,persona:v.persona,confidence:v.confidence},E.slotConfig?{slotConfig:E.slotConfig}:{}),E.goals?{goals:E.goals}:{})}catch(B){return te(m),null}},getSlotResult(o){var u;return(u=k.get(o))!=null?u:null},getPersona(){return v?{persona:v.persona,confidence:v.confidence,band:Oe(v.confidence)}:null},async fetchWeights(){var o;try{let u=await fetch(`${c}/weights`,{headers:g});return u.ok?(o=(await u.json()).components)!=null?o:[]:[]}catch(u){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){a.destroy(),e.debug&&console.log("[sentient] disposed")},destroy(){a.destroy(),i.destroy();try{localStorage.removeItem(J+e.apiKey),localStorage.removeItem(fe(e.apiKey))}catch(o){}e.debug&&console.log("[sentient] destroyed")}};if(W.set(e.apiKey,{config:e,upgrade:null}),e.debug){let o=window;o.__sentient&&(o.__sentient.client=Y)}return Y}export{J as a,Se as b,ee as c,Xe as d,ve as e,ke as f,et as g,Pe as h,Ct as i,ot as j};
|
|
2
|
-
//# sourceMappingURL=chunk-I2QGVQI6.mjs.map
|