@sentientui/core 0.16.3 → 0.16.5

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.
@@ -1,2 +1,2 @@
1
- "use strict";var Ze=Object.create;var oe=Object.defineProperty,et=Object.defineProperties,tt=Object.getOwnPropertyDescriptor,nt=Object.getOwnPropertyDescriptors,ot=Object.getOwnPropertyNames,Re=Object.getOwnPropertySymbols,rt=Object.getPrototypeOf,Oe=Object.prototype.hasOwnProperty,st=Object.prototype.propertyIsEnumerable;var ke=(e,t,n)=>t in e?oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,v=(e,t)=>{for(var n in t||(t={}))Oe.call(t,n)&&ke(e,n,t[n]);if(Re)for(var n of Re(t))st.call(t,n)&&ke(e,n,t[n]);return e},F=(e,t)=>et(e,nt(t));var it=(e,t)=>{for(var n in t)oe(e,n,{get:t[n],enumerable:!0})},De=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let d of ot(t))!Oe.call(e,d)&&d!==n&&oe(e,d,{get:()=>t[d],enumerable:!(a=tt(t,d))||a.enumerable});return e};var at=(e,t,n)=>(n=e!=null?Ze(rt(e)):{},De(t||!e||!e.__esModule?oe(n,"default",{value:e,enumerable:!0}):n,e)),ct=e=>De(oe({},"__esModule",{value:!0}),e);var nn={};it(nn,{deriveSessionSegment:()=>he,detectDeviceClass:()=>W,detectTimeOfDay:()=>z,detectTrafficSource:()=>q,init:()=>tn,referrerDomainFromReferer:()=>J});module.exports=ct(nn);var dt="_snt_uid";var j="_snt_uid";function lt(){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 ut(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function gt(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(a){}}function pt(e){try{return localStorage.getItem(e)}catch(t){return null}}function ft(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function mt(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function yt(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function ht(e){try{sessionStorage.removeItem(e)}catch(t){}}function St(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 bt(e){try{localStorage.removeItem(e)}catch(t){}}function vt(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var Et={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function ie(e){var c,l,g,y,f,m;if(typeof window=="undefined")return Et;let t=(c=e==null?void 0:e.cookieName)!=null?c:dt,a=((l=e==null?void 0:e.cookieTTLDays)!=null?l:365)*24*60*60,d=(m=(f=(y=(g=ut(t))!=null?g:pt(j))!=null?y:mt(j))!=null?f:e==null?void 0:e.ssrSessionId)!=null?m:lt();gt(t,d,a);let s=ft(j,d),o=St(t),r=s?!1:yt(j,d),i=!s&&!o&&!r;return{getSessionId:()=>d,isEphemeral:()=>i,destroy:()=>{d=null,vt(t),bt(j),ht(j)}}}function fe(e){return`_snt_retry_${e.slice(0,12)}`}var wt={push:()=>{},flush:()=>{},destroy:()=>{}};function It(e,t){try{let n=localStorage.getItem(t);if(!n)return[];let a=JSON.parse(n);return Array.isArray(a)?(localStorage.removeItem(t),a.slice(-e)):[]}catch(n){return[]}}function pe(e,t,n){try{let d=[...(()=>{try{let s=localStorage.getItem(n);if(!s)return[];let o=JSON.parse(s);return Array.isArray(o)?o:[]}catch(s){return[]}})(),...e].slice(-t);localStorage.setItem(n,JSON.stringify(d))}catch(a){}}function Ne(e){var X,Z,ee;if(typeof window=="undefined")return wt;let t=(X=e.flushIntervalMs)!=null?X:5e3,n=(Z=e.maxBatchSize)!=null?Z:20,a=(ee=e.maxRetrySize)!=null?ee:100,d=e.ingestUrl,s=e.apiKey,o=fe(s),r=[],i=new Set,c=[],l=h=>{for(let b of h)g.delete(b),!i.has(b)&&(i.add(b),c.push(b));for(;c.length>500;){let b=c.shift();b&&i.delete(b)}},g=new Set,y=h=>{i.has(h.id)||g.has(h.id)||(g.add(h.id),r.push(h))},f=It(a,o);for(let h of f)y(h);let m=0,E=0,I=h=>{if(h.length===0)return;let b=JSON.stringify(h),A=h.map(u=>u.id),k;try{k=fetch(d,{method:"POST",keepalive:!0,body:b,headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`}})}catch(u){pe(h,a,o);for(let p of A)g.delete(p);E++,m=Date.now()+Math.min(6e4,1e3*2**Math.min(E,6));return}let L=u=>{if(u.ok||u.status>=400&&u.status<500&&u.status!==429){l(A),E=0,m=0;return}pe(h,a,o);for(let p of A)g.delete(p);E++,m=Date.now()+Math.min(6e4,1e3*2**Math.min(E,6))};k instanceof Promise?k.then(L).catch(()=>{pe(h,a,o);for(let u of A)g.delete(u);E++,m=Date.now()+Math.min(6e4,1e3*2**Math.min(E,6))}):L(k)},w=typeof TextEncoder!="undefined"?new TextEncoder:null,se=h=>w?w.encode(h).length:h.length,G=h=>{let b=[],A=2;for(let k of h){let L=se(JSON.stringify(k))+1;if(b.length>0&&A+L>57344||b.length>=n)break;b.push(k),A+=L}return b},N=()=>{try{if(Date.now()<m)return;for(;r.length>0;){let h=r.filter(A=>!i.has(A.id));if(r.length=0,h.length===0)break;let b=G(h);if(b.length===0)break;b.length<h.length&&r.push(...h.slice(b.length)),I(b)}}catch(h){}},R=!0,K=null;K=setInterval(()=>{R&&N()},t);let H=()=>{document.visibilityState==="hidden"&&N()},V=()=>{N()};return document.addEventListener("visibilitychange",H),window.addEventListener("pagehide",V),{push(h){y(h),r.length>=n&&N()},flush:N,destroy(){R=!1,K!==null&&(clearInterval(K),K=null),document.removeEventListener("visibilitychange",H),window.removeEventListener("pagehide",V),N()}}}var ye="_snt_asgn_";function ae(e,t){return`${e}:${t}`}function Ct(e,t){return`${ye}${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function Pe(e){let t=e.slice(ye.length),n=t.indexOf(":");if(n<0)return null;try{return{componentId:decodeURIComponent(t.slice(0,n)),segment:decodeURIComponent(t.slice(n+1))}}catch(a){return null}}function me(){try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n!=null&&n.startsWith(ye)&&e.push(n)}return e}catch(e){return[]}}function Le(e=18e5){let t=new Map,n=d=>d.assignedAt+e<Date.now();return typeof window!="undefined"&&(()=>{for(let d of me())try{let s=localStorage.getItem(d);if(!s)continue;let o=JSON.parse(s);if(n(o)){localStorage.removeItem(d);continue}let r=Pe(d);if(!r)continue;t.set(ae(r.componentId,r.segment),o)}catch(s){}})(),{get(d,s){let o=t.get(ae(d,s));return o?n(o)?(t.delete(ae(d,s)),null):o:null},set(d,s,o){let r=ae(d,s);t.set(r,o);try{localStorage.setItem(Ct(d,s),JSON.stringify(o))}catch(i){}},invalidate(d){let s=`${d}:`;for(let o of[...t.keys()])o.startsWith(s)&&t.delete(o);for(let o of me()){let r=Pe(o);if((r==null?void 0:r.componentId)===d)try{localStorage.removeItem(o)}catch(i){}}},clear(){t.clear();for(let d of me())try{localStorage.removeItem(d)}catch(s){}}}}var Me=["GPTBot","ChatGPT-User","OAI-SearchBot","ClaudeBot","Claude-User","Claude-SearchBot","PerplexityBot","Perplexity-User","Google-Extended","Applebot-Extended","Meta-ExternalAgent","Bytespider","CCBot","Amazonbot","cohere-ai","Diffbot"];function ce(e){return Ue(e)!==null}function Ue(e){var n;if(!e)return null;let t=e.toLowerCase();return(n=Me.find(a=>t.includes(a.toLowerCase())))!=null?n:null}function W(e){let t=e.toLowerCase();return/ipad|tablet|playbook|kindle|silk/.test(t)?"tablet":/mobi|iphone|ipod|android.*mobile|phone/.test(t)?"mobile":"desktop"}function q(e,t){if(!e)return"direct";try{let n=new URL(e);if(t)try{if(new URL(t).host===n.host)return"direct"}catch(d){}let a=n.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(a)?"search":/(^|\.)(twitter\.com|x\.com|facebook\.com|linkedin\.com|reddit\.com|t\.co)$/.test(a)?"social":"referral"}catch(n){return"direct"}}function J(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function z(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function he(e){let t=xt("__segment__",e);return`${t.deviceClass}:${t.trafficSource}`}function xt(e,t){var s,o,r,i,c,l,g;let n=(o=(s=t==null?void 0:t.userAgent)==null?void 0:s.trim())!=null?o:"",a=(i=(r=t==null?void 0:t.referer)==null?void 0:r.trim())!=null?i:"",d=(c=t==null?void 0:t.now)!=null?c:new Date;return{sessionId:e,ephemeral:!1,utmParams:(l=t==null?void 0:t.utmParams)!=null?l:{},deviceClass:n?W(n):"desktop",trafficSource:a?q(a,t==null?void 0:t.appOrigin):"direct",referrerDomain:J(a),timeOfDay:z(d),dayOfWeek:(g=["sun","mon","tue","wed","thu","fri","sat"][d.getDay()])!=null?g:"sun",automation:(t==null?void 0:t.webdriver)===!0||ce(n)}}var Y=require("@sentientui/policy");function Se(e){return v(v(v({id:e.id},e.arms?{arms:[...e.arms]}:{}),e.dims?{dims:Object.fromEntries(Object.entries(e.dims).map(([t,n])=>[t,[...n]]))}:{}),e.baseline!==void 0?{baseline:e.baseline}:{})}function be(e){let t=Se(e);return(0,Y.slotResultFor)(t,(0,Y.slotBaselineArm)(t))}function Ge(e){return typeof e=="string"?e:(0,Y.canonicalArm)(e)}var de="_snt_snap:",At=["low","medium","high"];function Ke(e){try{let t=localStorage.getItem(de+e);if(!t)return null;let n=JSON.parse(t);return!n||typeof n!="object"||n.v!==1||typeof n.persona!="string"||typeof n.band!="string"||!At.includes(n.band)||typeof n.slots!="object"||n.slots===null||Array.isArray(n.slots)||!(n.layoutOrder===null||Array.isArray(n.layoutOrder))||typeof n.savedAt!="number"||!(n.slotConfig===void 0||typeof n.slotConfig=="object"&&n.slotConfig!==null&&!Array.isArray(n.slotConfig))?null:n}catch(t){return null}}function le(e,t){try{localStorage.setItem(de+e,JSON.stringify(t))}catch(n){}}var Ee=require("@sentientui/policy");var ge=require("@sentientui/policy");var $e="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",Tt="[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.",Be=!1,ue=!1;function _t(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(t){return}}function Fe(e){var r;let t=ie({ssrSessionId:e.ssrSessionId}),n=(r=t.getSessionId())!=null?r:"local",a=_t(),d=import("@sentientui/core/local").then(i=>{let c=i;return c.LOCAL_ENGINE_AVAILABLE?(Be||(Be=!0,console.info(Tt)),c):(ue||(ue=!0,console.error($e)),null)}).catch(()=>(ue||(ue=!0,console.error($e)),null)),s=null;function o(i){let c=document.documentElement;c.dataset.sentientPersona===void 0&&(c.dataset.sentientPersona=i.persona,c.dataset.sentientConfidence=(0,ge.confidenceBand)(i.confidence))}return{isLocal:!0,async decide(i){var g,y,f;let c=await d;if(!c)return null;let l=c.createLocalEngine({sessionId:n,forcedPersona:a}).decide(i);return s=F(v({},l),{layoutOrder:(y=(g=l.layoutOrder)!=null?g:s==null?void 0:s.layoutOrder)!=null?y:null,slots:v(v({},(f=s==null?void 0:s.slots)!=null?f:{}),l.slots)}),le(e.apiKey||"local",{v:1,persona:s.persona,band:(0,ge.confidenceBand)(s.confidence),slots:s.slots,layoutOrder:s.layoutOrder,savedAt:Date.now()}),o(l),l},getSlotResult(i){var c,l,g;return(g=(l=s==null?void 0:s.slots[i])!=null?l:(c=e.initialSlots)==null?void 0:c[i])!=null?g:null},getPersona(){return s?{persona:s.persona,confidence:s.confidence,band:(0,ge.confidenceBand)(s.confidence)}:null},async assign(i,c){var y;let l=await d;return!l||!c||c.length===0?c!=null&&c[0]?{variantId:c[0],assignmentTtlMs:0}:null:{variantId:(y=l.createLocalEngine({sessionId:n,forcedPersona:a}).decide({components:[{id:i,variantIds:c}]}).assignments[i])!=null?y:c[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>t.destroy()}}var je="https://api.sentient-ui.com/v1/events",re=new Map,Rt=null;function ve(){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 kt(){try{let e={},t=new URLSearchParams(window.location.search);for(let[n,a]of t)n.startsWith("utm_")&&(e[n]=a);return e}catch(e){return{}}}function We(e){return e.replace(/\/events\/?$/,"")}function we(){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 Ot(e){var o;let t=We((o=e.ingestUrl)!=null?o:je),n={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},a={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),async assign(r,i,c){try{let l=new URLSearchParams({componentId:r});for(let f of i!=null?i:[])l.append("variantIds[]",f);let g=await fetch(`${t}/winner?${l.toString()}`,{headers:n});return g.ok?{variantId:(await g.json()).variantId,assignmentTtlMs:0}:i!=null&&i[0]?{variantId:i[0],assignmentTtlMs:0}:null}catch(l){return i!=null&&i[0]?{variantId:i[0],assignmentTtlMs:0}:null}},decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}},d={track:r=>a.track(r),goal:(r,i,c,l)=>a.goal(r,i,c,l),componentGoal:(r,i,c)=>a.componentGoal(r,i,c),identify:r=>a.identify(r),getAssignment:(r,i)=>a.getAssignment(r,i),assign:(r,i,c,l)=>a.assign(r,i,c,l),decide:r=>a.decide(r),getSlotResult:r=>a.getSlotResult(r),getPersona:()=>a.getPersona(),fetchWeights:()=>a.fetchWeights(),getGraph:()=>a.getGraph(),dispose:()=>a.dispose(),destroy:()=>a.destroy()};function s(r){a=r}return{proxy:d,setInner:s}}function qe(e){var V,X,Z,ee,h,b,A,k,L;if(typeof window=="undefined")return Q;Rt=e.apiKey;let t=e.respectDoNotTrack!==!1&&we(),n=e.consent===!1||t,a=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!a&&e.localMode!==!1)return n?(re.set(e.apiKey||"local",{config:e,upgrade:null}),Q):(re.set(e.apiKey||"local",{config:e,upgrade:null}),Fe(e));if(n){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:u,setInner:p}=Ot(e);return re.set(e.apiKey,{config:e,upgrade:t?null:p}),u}return re.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 d=(V=e.ingestUrl)!=null?V:je,s=Date.now(),o=ie({ssrSessionId:e.ssrSessionId}),r=Le(),i=Ne({ingestUrl:d,apiKey:e.apiKey}),c=We(d),l={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},g=W((X=navigator.userAgent)!=null?X:""),y=typeof window!="undefined"?window.location.origin:void 0,f=q((Z=document.referrer)!=null?Z:"",y),m=(ee=e.sessionSegment)!=null?ee:`${g}:${f}`,E=new Map,I=new Map,w=null,se=u=>{for(let p of u)I.has(p.id)||I.set(p.id,be(p))};if(e.initialSlots)for(let[u,p]of Object.entries(e.initialSlots))I.set(u,p);let G=Ke(e.apiKey);if(G)for(let[u,p]of Object.entries(G.slots))I.has(u)||I.set(u,p);let N={low:.15,medium:.5,high:.85};if(e.initialPersona)w=v({},e.initialPersona);else{let u=document.documentElement.dataset;u.sentientPersona?w={persona:u.sentientPersona,confidence:(b=N[(h=u.sentientConfidence)!=null?h:"low"])!=null?b:.15}:G&&(w={persona:G.persona,confidence:(A=N[G.band])!=null?A:.15})}if(e.initialAssignments)for(let[u,p]of Object.entries(e.initialAssignments))r.set(u,m,{variantId:p,assignedAt:Date.now(),segment:m,confidence:1});let R=Promise.resolve(),K=o.getSessionId();if(K){let u=J((k=document.referrer)!=null?k:""),p=v(v({sessionId:K,deviceClass:g,trafficSource:f,referrerDomain:u,utmParams:kt(),timeOfDay:z(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:o.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||ce((L=navigator.userAgent)!=null?L:"")},e.userId?{userId:e.userId}:{}),e.country?{country:e.country}:{});try{R=fetch(`${c}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(p),headers:l}).then(S=>{S.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(S){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:i});let H={goal(u,p={},S=1,O=0){let x=o.getSessionId();if(!x)return;let T=ve();R.then(()=>{fetch(`${c}/goals`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:x,name:u,metadata:p,weight:S,stepIndex:O,goalId:T}),headers:l}).catch(()=>{})})},componentGoal(u,p,S){var D,U,P;let O=o.getSessionId();if(!O)return;let x=r.get(u,m),T=x?null:(D=I.get(u))!=null?D:null;if(!x&&T===null){e.debug&&console.warn(`[sentient] componentGoal("${u}"): no assignment or slot decision yet \u2014 render its <Adaptive>/adaptive hook or call assign()/decide() before recording a goal.`);return}let $=x?x.variantId:Ge(T),M={id:ve(),sessionId:O,projectId:e.apiKey,componentId:u,variantId:$,eventType:"goal_achieved",goalType:p,payload:v({reward:(U=S==null?void 0:S.reward)!=null?U:1},(P=S==null?void 0:S.metadata)!=null?P:{}),timestamp:Date.now(),timeInSession:Date.now()-s};e.debug&&console.log("[sentient] componentGoal",M),R.then(()=>i.push(M))},identify(u){let p=o.getSessionId();p&&R.then(()=>{fetch(`${c}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:p,userId:u,ephemeral:o.isEphemeral()}),headers:l}).catch(()=>{})})},track(u){let p=o.getSessionId();if(!p)return;let S=F(v({},u),{id:ve(),sessionId:p,timestamp:Date.now(),timeInSession:Date.now()-s});e.debug&&console.log("[sentient] track",S),R.then(()=>i.push(S))},getAssignment(u,p){return r.get(u,p)},async assign(u,p,S,O){let x=o.getSessionId();if(!x)return null;let T=r.get(u,m);if(T&&(p!=null&&p.length||T.content!==void 0))return{variantId:T.variantId,assignmentTtlMs:0,content:T.content};let $=E.get(u);if($)return $;let M=(async()=>{await R;try{let D={sessionId:x,componentId:u,variantIds:p};O!==void 0?D.agentDataByVariant=O:S!==void 0&&(D.agentData=S);let U=await fetch(`${c}/assign`,{method:"POST",body:JSON.stringify(D),headers:l});if(!U.ok)return null;let P=await U.json();return r.set(u,m,{variantId:P.variantId,assignedAt:Date.now(),segment:m,confidence:1,content:P.content}),P}catch(D){return null}finally{E.delete(u)}})();return E.set(u,M),M},async decide(u){var O,x,T,$,M,D,U,P,Ae,Te;let p=o.getSessionId();if(!p)return null;let S=(O=u.slots)!=null?O:[];await R;try{let B={sessionId:p};u.sections&&u.sections.length>0&&(B.sections=u.sections.map(_=>({id:_}))),B.components=(x=u.components)!=null?x:[],S.length>0&&(B.slots=S.map(Se)),u.slotsFrom==="registry"&&(B.slotsFrom="registry"),u.v&&(B.v=u.v);let _e=await fetch(`${c}/decide`,{method:"POST",body:JSON.stringify(B),headers:l});if(!_e.ok)return se(S),null;let C=await _e.json(),te={};for(let _ of S)te[_.id]=($=(T=C.slots)==null?void 0:T[_.id])!=null?$:be(_);if(C.slots)for(let[_,ne]of Object.entries(C.slots))_ in te||(te[_]=ne);for(let[_,ne]of Object.entries(te))I.set(_,ne);w={persona:(M=C.persona)!=null?M:"unknown",confidence:(D=C.confidence)!=null?D:0};for(let[_,ne]of Object.entries((U=C.assignments)!=null?U:{}))r.set(_,m,{variantId:ne,assignedAt:Date.now(),segment:m,confidence:1});return le(e.apiKey,v({v:1,persona:w.persona,band:(0,Ee.confidenceBand)(w.confidence),slots:Object.fromEntries(I),layoutOrder:(P=C.layoutOrder)!=null?P:null,savedAt:Date.now()},C.slotConfig?{slotConfig:C.slotConfig}:{})),v(v({layoutOrder:(Ae=C.layoutOrder)!=null?Ae:null,assignments:(Te=C.assignments)!=null?Te:{},slots:te,persona:w.persona,confidence:w.confidence},C.slotConfig?{slotConfig:C.slotConfig}:{}),C.goals?{goals:C.goals}:{})}catch(B){return se(S),null}},getSlotResult(u){var p;return(p=I.get(u))!=null?p:null},getPersona(){return w?{persona:w.persona,confidence:w.confidence,band:(0,Ee.confidenceBand)(w.confidence)}:null},async fetchWeights(){var u;try{let p=await fetch(`${c}/weights`,{headers:l});return p.ok?(u=(await p.json()).components)!=null?u:[]:[]}catch(p){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){i.destroy(),e.debug&&console.log("[sentient] disposed")},destroy(){i.destroy(),o.destroy();try{localStorage.removeItem(de+e.apiKey),localStorage.removeItem(fe(e.apiKey))}catch(u){}e.debug&&console.log("[sentient] destroyed")}};if(re.set(e.apiKey,{config:e,upgrade:null}),e.debug){let u=window;u.__sentient&&(u.__sentient.client=H)}return H}var Je=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Dt=[["pricing",/\b(pricing|price|plans?|subscriptions?|per month|\/mo|tier)\b/i],["faq",/\b(faq|frequently asked|common questions?)\b/i],["comparison",/\b(compare|comparison|versus|vs\.)\b/i],["social_proof",/\b(testimonial|reviews?|trusted by|loved by|customers?|logos|rated|case stud)\b/i],["trust",/\b(security|guarantee|privacy|compliance|secure|gdpr|soc ?2|encrypt)\b/i],["features",/\b(features?|how it works|benefits?|capabilit|what you get)\b/i]],Nt=[["pricing",/(?:[$€£]\s?\d[\d,.]*\s*(?:\/|per\s)\s*(?:mo|month|yr|year|seat|user))|(?:\b(?:starter|basic|pro|growth|premium|enterprise)\b[^.]{0,60}[$€£]\s?\d)/i],["social_proof",/(?:★{2,})|(?:\b\d(?:\.\d)?\s*(?:out of|\/)\s*5\b)|(?:\brated\b)|(?:["“][^"”]{20,160}["”]\s*[—–-]\s*[A-Z][a-z]+)/],["trust",/\b(?:money[- ]back guarantee|refund(?:s)? within|encrypted|soc ?2|iso ?27001|gdpr[- ]compliant|cancel anytime)\b/i],["comparison",/\b(?:vs|versus)\b\.?[^.!?]{0,80}\b(?:compare|comparison|plans?|features?|alternative)\b|\bhow (?:we|it) compares?\b/i]];function Pt(e){var n;let t=e.querySelector("h1, h2, h3");return((n=t==null?void 0:t.textContent)!=null?n:"").slice(0,160)}function Lt(e){if(e.tag==="nav"||e.tag==="footer")return{type:"navigation",strength:"weak"};let t=`${e.idClass} ${e.headingText}`.toLowerCase();for(let[n,a]of Dt)if(a.test(t))return{type:n,strength:"strong"};for(let[n,a]of Nt)if(a.test(e.bodyText))return{type:n,strength:"strong"};return e.actionCount>=1&&e.textLength>0&&e.textLength<200?{type:"cta",strength:"weak"}:e.tag==="header"?{type:"hero",strength:"weak"}:/\b(hero|headline|banner)\b/i.test(t)?{type:"hero",strength:"weak"}:{type:"generic",strength:"weak"}}function Mt(e){var n,a;let t=((n=e.textContent)!=null?n:"").replace(/\s+/g," ").trim();return{tag:e.tagName.toLowerCase(),idClass:`${e.id} ${String((a=e.className)!=null?a:"")}`,headingText:Pt(e),bodyText:t.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:t.length}}function ze(e){return Lt(Mt(e)).type}var Ut=new Set(["SECTION","ARTICLE","MAIN","DIV"]),Gt="h1, h2, h3",Kt={scan:async()=>({nodes:[],edges:[],scannedAt:0}),observe:()=>{},getProminenceScore:()=>0,destroy:()=>{}};function Ie(e,t,n){return n<=t?0:Math.max(0,Math.min(1,(e-t)/(n-t)))}function $t(e){var t,n,a;try{let d=e;for(let s of Object.keys(d)){if(!s.startsWith("__reactFiber")&&!s.startsWith("__reactInternalInstance"))continue;let o=d[s],r=(a=(t=o==null?void 0:o.type)==null?void 0:t.displayName)!=null?a:(n=o==null?void 0:o.type)==null?void 0:n.name;if(r&&r.length>1)return r}}catch(d){}}function Bt(e){let t={};for(let n of Array.from(e.attributes))n.name.startsWith("data-")&&(t[n.name]=n.value);return t}var Ye=new Set(Je);function Ft(e){let t=e.getAttribute("data-sentient-type");if(t&&Ye.has(t))return t;let n=e.getAttribute("role");return n&&Ye.has(n)?n:ze(e)}function jt(e){var t,n;return(n=(t=e.getAttribute("data-sentient-id"))!=null?t:e.getAttribute("id"))!=null?n:e.tagName.toLowerCase()}function Wt(e){let t=0,n=e.parentElement;for(;n;)t++,n=n.parentElement;return t}function Ce(e,t){var a,d,s;let n=e.querySelector(Gt);return{componentId:jt(e),semanticType:Ft(e),ariaLabel:(a=e.getAttribute("aria-label"))!=null?a:void 0,headingText:(s=(d=n==null?void 0:n.textContent)==null?void 0:d.trim())!=null?s:void 0,isAboveFold:e.getBoundingClientRect().top<window.innerHeight,prominenceScore:t(e),depth:Wt(e),reactComponentName:$t(e),dataAttributes:Bt(e)}}function Qe(e){var s;let t=[],n=new Set,a="__root__",d=new Map;for(let[o,r]of e){let i=o.parentElement,c=a;for(;i;){if(e.has(i)){c=e.get(i);let g=e.get(o),y=`${c}->${g}`;!n.has(y)&&c!==g&&(n.add(y),t.push({fromComponentId:c,toComponentId:g,weight:.6}));break}i=i.parentElement}let l=(s=d.get(c))!=null?s:[];l.push(o),d.set(c,l)}for(let o of d.values())if(!(o.length<2))for(let r=0;r<o.length;r++)for(let i=r+1;i<o.length;i++){let c=e.get(o[r]),l=e.get(o[i]);if(c===l)continue;let g=`${c}->${l}::sib`,y=`${l}->${c}::sib`;n.has(g)||(n.add(g),t.push({fromComponentId:c,toComponentId:l,weight:.3})),n.has(y)||(n.add(y),t.push({fromComponentId:l,toComponentId:c,weight:.3}))}return t}function qt(e){let t=[],n=new Set,a=new Map;return document.querySelectorAll("[data-sentient-id]").forEach(o=>{if(o instanceof Element&&!n.has(o)){n.add(o);let r=Ce(o,e);t.push(r),a.set(o,r.componentId)}}),document.querySelectorAll("section, article, main, aside").forEach(o=>{if(!(o instanceof Element)||n.has(o))return;let r=o.hasAttribute("aria-label"),i=o.hasAttribute("data-sentient-id");if(!r&&!i)return;n.add(o);let c=Ce(o,e);t.push(c),a.set(o,c.componentId)}),{nodes:t,edges:Qe(a)}}function He(){if(typeof window=="undefined")return Kt;let e=null,t=0,n=null,a=r=>{try{let i=window.getComputedStyle(r),c=parseFloat(i.fontSize)||12,l=parseFloat(i.zIndex)||0,g=r.getBoundingClientRect(),y=Math.max(g.top,0),f=window.innerHeight||1,m=1/(y/f+1),E=Ie(c,12,48)*.4+Ie(m,0,1)*.4+Ie(l,0,100)*.2;return Math.max(0,Math.min(1,E))}catch(i){return .5}};return{scan:()=>new Promise(r=>{let i=()=>{let{nodes:c,edges:l}=qt(a);r({nodes:c,edges:l,scannedAt:Date.now()})};try{typeof requestIdleCallback=="function"?t=requestIdleCallback(i,{timeout:100}):i()}catch(c){i()}}),observe:r=>{n=r;try{e=new MutationObserver(i=>{let c=[],l=new Map;for(let g of i)g.type==="childList"&&g.addedNodes.forEach(y=>{if(!(y instanceof Element)||!Ut.has(y.tagName))return;let f=y.hasAttribute("data-sentient-id"),m=y.hasAttribute("aria-label");if(!f&&!m)return;let E=Ce(y,a);c.push(E),l.set(y,E.componentId)});c.length>0&&n&&n({nodes:c,edges:Qe(l),addedAt:Date.now()})}),e.observe(document.body,{childList:!0,subtree:!0})}catch(i){}},getProminenceScore:a,destroy:()=>{if(e&&(e.disconnect(),e=null),t&&typeof cancelIdleCallback=="function")try{cancelIdleCallback(t)}catch(r){}t=0,n=null}}}var xe="_snt_graph_nodes",Ve="_snt_graph_edges",Jt={pricing:["features","faq"],features:["pricing"],faq:["pricing"],social_proof:["cta"],cta:["social_proof","hero","trust"],hero:["cta"],comparison:["pricing"],trust:["cta"]};function zt(e){var t;return(t=Jt[e])!=null?t:[]}function Yt(e,t){try{let n=localStorage.getItem(e);return n?JSON.parse(n):t}catch(n){return t}}function Qt(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch(n){}}var Ht=new Set(["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"]);function Vt(e){return Ht.has(e)?e:"generic"}function Xt(e,t,n){let a=`${e}:${t}:${n.join(",")}`,d=5381;for(let s=0;s<a.length;s++)d=(d<<5)+d+a.charCodeAt(s)&4294967295;return(d>>>0).toString(16).padStart(8,"0")}function Xe(e){let t=new Map,n=new Map,a=()=>{typeof window!="undefined"&&Qt(xe,[...t.values()])},d=s=>{var o;try{let r=JSON.parse(s);t.clear();for(let i of(o=r.pageNodes)!=null?o:[])t.set(i.componentId,i)}catch(r){}};if(typeof window!="undefined"){let s=Yt(xe,[]);for(let o of s)t.set(o.componentId,o);try{localStorage.removeItem(Ve)}catch(o){}}return{addPageNode(s){t.set(s.componentId,s),a()},addStructuralEdge(s){let o=`${s.fromComponentId}->${s.toComponentId}`;n.set(o,s)},syncOnce(){var o,r;if(!(e!=null&&e.syncUrl)||typeof window=="undefined")return;let s=[...t.values()];if(s.length!==0)try{let i=new Map;for(let f of s){let m=(o=i.get(f.semanticType))!=null?o:[];m.push(f),i.set(f.semanticType,m)}let c=[],l=new Set;for(let f of s)for(let m of zt(f.semanticType)){let E=(r=i.get(m))!=null?r:[];for(let I of E){if(I.componentId===f.componentId)continue;let w=`semantic:${f.componentId}->${I.componentId}`;l.has(w)||(l.add(w),c.push({fromComponentId:f.componentId,toComponentId:I.componentId,type:"semantic",weight:.4,confidence:.9}))}}let g=new Set(s.map(f=>f.componentId));for(let f of n.values()){if(!g.has(f.fromComponentId)||!g.has(f.toComponentId))continue;let m=`structural:${f.fromComponentId}->${f.toComponentId}`;l.has(m)||(l.add(m),c.push({fromComponentId:f.fromComponentId,toComponentId:f.toComponentId,type:"structural",weight:f.weight,confidence:1}))}let y={pageUrl:window.location.href,nodes:s.map(f=>{let m=Vt(f.semanticType);return{componentId:f.componentId,semanticType:m,answers:f.answers,contentHash:Xt(f.componentId,m,f.answers),prominenceScore:f.prominenceScore,depthInPage:f.depth}}),edges:c};fetch(e.syncUrl,{method:"POST",keepalive:!0,headers:v({"Content-Type":"application/json"},e.apiKey?{Authorization:`Bearer ${e.apiKey}`}:{}),body:JSON.stringify(y)}).catch(()=>{})}catch(i){}},snapshot(){return{pageNodes:[...t.values()],capturedAt:Date.now()}},serialize(){return JSON.stringify({pageNodes:[...t.values()]})},restore:d,destroy(){if(typeof window!="undefined")try{localStorage.removeItem(xe),localStorage.removeItem(Ve)}catch(s){}}}}var Zt="https://api.sentient-ui.com/v1/events";function en(){try{let e=document.cookie.match(/(?:^|; )_snt_uid=([^;]*)/);return e?decodeURIComponent(e[1]):void 0}catch(e){return}}function tn(e){var c;let t=qe(e),n=e.respectDoNotTrack!==!1&&we(),a=e.consent===!1||n;if(!e.graph||!e.apiKey||a||typeof window=="undefined")return t;let d=He(),s=(c=e.ingestUrl)!=null?c:Zt,o=Xe({syncUrl:s.replace(/\/events\/?$/,"/graph/sync"),apiKey:e.apiKey,projectId:e.apiKey,sessionId:en()});try{let l=localStorage.getItem("_snt_graph_nodes");l&&o.restore(JSON.stringify({pageNodes:JSON.parse(l)}))}catch(l){}d.scan().then(l=>{for(let g of l.nodes)o.addPageNode({id:g.componentId,componentId:g.componentId,semanticType:g.semanticType,answers:g.headingText?[g.headingText]:[],prominenceScore:g.prominenceScore,depth:g.depth});for(let g of l.edges)o.addStructuralEdge(g);o.syncOnce()});let r=null,i=()=>{r!==null&&clearTimeout(r),r=setTimeout(()=>{r=null,o.syncOnce()},500)};return d.observe(l=>{for(let g of l.nodes)o.addPageNode({id:g.componentId,componentId:g.componentId,semanticType:g.semanticType,answers:g.headingText?[g.headingText]:[],prominenceScore:g.prominenceScore,depth:g.depth});for(let g of l.edges)o.addStructuralEdge(g);i()}),F(v({},t),{getGraph:()=>o.snapshot(),dispose:()=>{r!==null&&clearTimeout(r),d.destroy(),o.destroy(),t.dispose()},destroy:()=>{r!==null&&clearTimeout(r),d.destroy(),o.destroy(),t.destroy()}})}0&&(module.exports={deriveSessionSegment,detectDeviceClass,detectTimeOfDay,detectTrafficSource,init,referrerDomainFromReferer});
1
+ "use strict";var et=Object.create;var se=Object.defineProperty,tt=Object.defineProperties,nt=Object.getOwnPropertyDescriptor,ot=Object.getOwnPropertyDescriptors,rt=Object.getOwnPropertyNames,Re=Object.getOwnPropertySymbols,st=Object.getPrototypeOf,De=Object.prototype.hasOwnProperty,it=Object.prototype.propertyIsEnumerable;var ke=(e,t,n)=>t in e?se(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,b=(e,t)=>{for(var n in t||(t={}))De.call(t,n)&&ke(e,n,t[n]);if(Re)for(var n of Re(t))it.call(t,n)&&ke(e,n,t[n]);return e},q=(e,t)=>tt(e,ot(t));var at=(e,t)=>{for(var n in t)se(e,n,{get:t[n],enumerable:!0})},Oe=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let d of rt(t))!De.call(e,d)&&d!==n&&se(e,d,{get:()=>t[d],enumerable:!(a=nt(t,d))||a.enumerable});return e};var ct=(e,t,n)=>(n=e!=null?et(st(e)):{},Oe(t||!e||!e.__esModule?se(n,"default",{value:e,enumerable:!0}):n,e)),dt=e=>Oe(se({},"__esModule",{value:!0}),e);var on={};at(on,{deriveSessionSegment:()=>Se,detectDeviceClass:()=>z,detectTimeOfDay:()=>H,detectTrafficSource:()=>Y,init:()=>nn,referrerDomainFromReferer:()=>Q});module.exports=dt(on);var lt="_snt_uid";var J="_snt_uid";function ut(){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 gt(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function pt(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(a){}}function mt(e){try{return localStorage.getItem(e)}catch(t){return null}}function ft(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function yt(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function ht(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function St(e){try{sessionStorage.removeItem(e)}catch(t){}}function bt(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 vt(e){try{localStorage.removeItem(e)}catch(t){}}function wt(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var Et={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function ae(e){var c,u,g,y,p,v;if(typeof window=="undefined")return Et;let t=(c=e==null?void 0:e.cookieName)!=null?c:lt,a=((u=e==null?void 0:e.cookieTTLDays)!=null?u:365)*24*60*60,d=(v=(p=(y=(g=gt(t))!=null?g:mt(J))!=null?y:yt(J))!=null?p:e==null?void 0:e.ssrSessionId)!=null?v:ut();pt(t,d,a);let i=ft(J,d),r=bt(t),o=i?!1:ht(J,d),s=!i&&!r&&!o;return{getSessionId:()=>d,isEphemeral:()=>s,destroy:()=>{d=null,wt(t),vt(J),St(J)}}}function fe(e){return`_snt_retry_${e.slice(0,12)}`}var It={push:()=>{},flush:()=>{},destroy:()=>{}};function Ct(e,t){try{let n=localStorage.getItem(t);if(!n)return[];let a=JSON.parse(n);return Array.isArray(a)?(localStorage.removeItem(t),a.slice(-e)):[]}catch(n){return[]}}function me(e,t,n){try{let d=[...(()=>{try{let i=localStorage.getItem(n);if(!i)return[];let r=JSON.parse(i);return Array.isArray(r)?r:[]}catch(i){return[]}})(),...e].slice(-t);localStorage.setItem(n,JSON.stringify(d))}catch(a){}}function Ne(e){var ee,te,ne;if(typeof window=="undefined")return It;let t=(ee=e.flushIntervalMs)!=null?ee:5e3,n=(te=e.maxBatchSize)!=null?te:20,a=(ne=e.maxRetrySize)!=null?ne:100,d=e.ingestUrl,i=e.apiKey,r=fe(i),o=[],s=new Set,c=[],u=f=>{for(let h of f)g.delete(h),!s.has(h)&&(s.add(h),c.push(h));for(;c.length>500;){let h=c.shift();h&&s.delete(h)}},g=new Set,y=f=>{s.has(f.id)||g.has(f.id)||(g.add(f.id),o.push(f))},p=f=>{for(let h of f)s.has(h.id)||(g.add(h.id),o.push(h))},v=Ct(a,r);for(let f of v)y(f);let w=0,x=0,A=f=>{if(f.length===0)return;let h=JSON.stringify(f),L=f.map(l=>l.id),O;try{O=fetch(d,{method:"POST",keepalive:!0,body:h,headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`}})}catch(l){me(f,a,r),p(f),x++,w=Date.now()+Math.min(6e4,1e3*2**Math.min(x,6));return}let K=l=>{if(l.ok||l.status>=400&&l.status<500&&l.status!==429){u(L),x=0,w=0;return}me(f,a,r),p(f),x++,w=Date.now()+Math.min(6e4,1e3*2**Math.min(x,6))};O instanceof Promise?O.then(K).catch(()=>{me(f,a,r),p(f),x++,w=Date.now()+Math.min(6e4,1e3*2**Math.min(x,6))}):K(O)},E=typeof TextEncoder!="undefined"?new TextEncoder:null,ie=f=>E?E.encode(f).length:f.length,B=f=>{let h=[],L=2;for(let O of f){let K=ie(JSON.stringify(O))+1;if(h.length>0&&L+K>57344||h.length>=n)break;h.push(O),L+=K}return h},M=()=>{try{if(Date.now()<w)return;for(;o.length>0&&!(Date.now()<w);){let f=o.filter(L=>!s.has(L.id));if(o.length=0,f.length===0)break;let h=B(f);if(h.length===0)break;h.length<f.length&&o.push(...f.slice(h.length)),A(h)}}catch(f){}},D=!0,F=null;F=setInterval(()=>{D&&M()},t);let U=()=>{document.visibilityState==="hidden"&&M()},Z=()=>{M()};return document.addEventListener("visibilitychange",U),window.addEventListener("pagehide",Z),{push(f){y(f),o.length>=n&&M()},flush:M,destroy(){D=!1,F!==null&&(clearInterval(F),F=null),document.removeEventListener("visibilitychange",U),window.removeEventListener("pagehide",Z),M()}}}var he="_snt_asgn_";function ce(e,t){return`${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function xt(e,t){return`${he}${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function Pe(e){let t=e.slice(he.length),n=t.indexOf(":");if(n<0)return null;try{return{componentId:decodeURIComponent(t.slice(0,n)),segment:decodeURIComponent(t.slice(n+1))}}catch(a){return null}}function ye(){try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n!=null&&n.startsWith(he)&&e.push(n)}return e}catch(e){return[]}}function Me(e=18e5){let t=new Map,n=d=>d.assignedAt+(d.ttlMs&&d.ttlMs>0?d.ttlMs:e)<Date.now();return typeof window!="undefined"&&(()=>{for(let d of ye())try{let i=localStorage.getItem(d);if(!i)continue;let r=JSON.parse(i);if(n(r)){localStorage.removeItem(d);continue}let o=Pe(d);if(!o)continue;t.set(ce(o.componentId,o.segment),r)}catch(i){}})(),{get(d,i){let r=t.get(ce(d,i));return r?n(r)?(t.delete(ce(d,i)),null):r:null},set(d,i,r){let o=ce(d,i);t.set(o,r);try{localStorage.setItem(xt(d,i),JSON.stringify(r))}catch(s){}},invalidate(d){let i=`${encodeURIComponent(d)}:`;for(let r of[...t.keys()])r.startsWith(i)&&t.delete(r);for(let r of ye()){let o=Pe(r);if((o==null?void 0:o.componentId)===d)try{localStorage.removeItem(r)}catch(s){}}},clear(){t.clear();for(let d of ye())try{localStorage.removeItem(d)}catch(i){}}}}var Le=["GPTBot","ChatGPT-User","OAI-SearchBot","ClaudeBot","Claude-User","Claude-SearchBot","PerplexityBot","Perplexity-User","Google-Extended","Applebot-Extended","Meta-ExternalAgent","Bytespider","CCBot","Amazonbot","cohere-ai","Diffbot"];function de(e){return Ue(e)!==null}function Ue(e){var n;if(!e)return null;let t=e.toLowerCase();return(n=Le.find(a=>t.includes(a.toLowerCase())))!=null?n:null}function z(e){let t=e.toLowerCase();return/ipad|tablet|playbook|kindle|silk/.test(t)?"tablet":/mobi|iphone|ipod|android.*mobile|phone/.test(t)?"mobile":"desktop"}function Y(e,t){if(!e)return"direct";try{let n=new URL(e);if(t)try{if(new URL(t).host===n.host)return"direct"}catch(d){}let a=n.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(a)?"search":/(^|\.)(twitter\.com|x\.com|facebook\.com|linkedin\.com|reddit\.com|t\.co)$/.test(a)?"social":"referral"}catch(n){return"direct"}}function Q(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function H(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function Se(e){let t=At("__segment__",e);return`${t.deviceClass}:${t.trafficSource}`}function At(e,t){var i,r,o,s,c,u,g;let n=(r=(i=t==null?void 0:t.userAgent)==null?void 0:i.trim())!=null?r:"",a=(s=(o=t==null?void 0:t.referer)==null?void 0:o.trim())!=null?s:"",d=(c=t==null?void 0:t.now)!=null?c:new Date;return{sessionId:e,ephemeral:!1,utmParams:(u=t==null?void 0:t.utmParams)!=null?u:{},deviceClass:n?z(n):"desktop",trafficSource:a?Y(a,t==null?void 0:t.appOrigin):"direct",referrerDomain:Q(a),timeOfDay:H(d),dayOfWeek:(g=["sun","mon","tue","wed","thu","fri","sat"][d.getDay()])!=null?g:"sun",automation:(t==null?void 0:t.webdriver)===!0||de(n)}}var V=require("@sentientui/policy");function be(e){return b(b(b({id:e.id},e.arms?{arms:[...e.arms]}:{}),e.dims?{dims:Object.fromEntries(Object.entries(e.dims).map(([t,n])=>[t,[...n]]))}:{}),e.baseline!==void 0?{baseline:e.baseline}:{})}function ve(e){let t=be(e);return(0,V.slotResultFor)(t,(0,V.slotBaselineArm)(t))}function Ke(e){return typeof e=="string"?e:(0,V.canonicalArm)(e)}var le="_snt_snap:",Tt=["low","medium","high"];function Ge(e){try{let t=localStorage.getItem(le+e);if(!t)return null;let n=JSON.parse(t);return!n||typeof n!="object"||n.v!==1||typeof n.persona!="string"||typeof n.band!="string"||!Tt.includes(n.band)||typeof n.slots!="object"||n.slots===null||Array.isArray(n.slots)||!(n.layoutOrder===null||Array.isArray(n.layoutOrder))||typeof n.savedAt!="number"||!(n.slotConfig===void 0||typeof n.slotConfig=="object"&&n.slotConfig!==null&&!Array.isArray(n.slotConfig))?null:n}catch(t){return null}}function ue(e,t){try{localStorage.setItem(le+e,JSON.stringify(t))}catch(n){}}var Ee=require("@sentientui/policy");var pe=require("@sentientui/policy");var $e="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",_t="[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.",Be=!1,ge=!1;function Rt(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(t){return}}function Fe(e){var o;let t=ae({ssrSessionId:e.ssrSessionId}),n=(o=t.getSessionId())!=null?o:"local",a=Rt(),d=import("@sentientui/core/local").then(s=>{let c=s;return c.LOCAL_ENGINE_AVAILABLE?(Be||(Be=!0,console.info(_t)),c):(ge||(ge=!0,console.error($e)),null)}).catch(()=>(ge||(ge=!0,console.error($e)),null)),i=null;function r(s){let c=document.documentElement;c.dataset.sentientPersona===void 0&&(c.dataset.sentientPersona=s.persona,c.dataset.sentientConfidence=(0,pe.confidenceBand)(s.confidence))}return{isLocal:!0,async decide(s){var g,y,p;let c=await d;if(!c)return null;let u=c.createLocalEngine({sessionId:n,forcedPersona:a}).decide(s);return i=q(b({},u),{layoutOrder:(y=(g=u.layoutOrder)!=null?g:i==null?void 0:i.layoutOrder)!=null?y:null,slots:b(b({},(p=i==null?void 0:i.slots)!=null?p:{}),u.slots)}),ue(e.apiKey||"local",{v:1,persona:i.persona,band:(0,pe.confidenceBand)(i.confidence),slots:i.slots,layoutOrder:i.layoutOrder,savedAt:Date.now()}),r(u),u},getSlotResult(s){var c,u,g;return(g=(u=i==null?void 0:i.slots[s])!=null?u:(c=e.initialSlots)==null?void 0:c[s])!=null?g:null},getPersona(){return i?{persona:i.persona,confidence:i.confidence,band:(0,pe.confidenceBand)(i.confidence)}:null},async assign(s,c){var y;let u=await d;return!u||!c||c.length===0?c!=null&&c[0]?{variantId:c[0],assignmentTtlMs:0}:null:{variantId:(y=u.createLocalEngine({sessionId:n,forcedPersona:a}).decide({components:[{id:s,variantIds:c}]}).assignments[s])!=null?y:c[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>t.destroy()}}var je="https://api.sentient-ui.com/v1/events",P=new Map,kt=null;function we(){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 X={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 Dt(){try{let e={},t=new URLSearchParams(window.location.search);for(let[n,a]of t)n.startsWith("utm_")&&(e[n]=a);return e}catch(e){return{}}}function We(e){return e.replace(/\/events\/?$/,"")}function Ie(){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 Ot(e){var r;let t=We((r=e.ingestUrl)!=null?r:je),n={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},a={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),async assign(o,s,c){try{let u=new URLSearchParams({componentId:o});for(let p of s!=null?s:[])u.append("variantIds[]",p);let g=await fetch(`${t}/winner?${u.toString()}`,{headers:n});return g.ok?{variantId:(await g.json()).variantId,assignmentTtlMs:0}:s!=null&&s[0]?{variantId:s[0],assignmentTtlMs:0}:null}catch(u){return s!=null&&s[0]?{variantId:s[0],assignmentTtlMs:0}:null}},decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}},d={track:o=>a.track(o),goal:(o,s,c,u)=>a.goal(o,s,c,u),componentGoal:(o,s,c)=>a.componentGoal(o,s,c),identify:o=>a.identify(o),getAssignment:(o,s)=>a.getAssignment(o,s),assign:(o,s,c,u)=>a.assign(o,s,c,u),decide:o=>a.decide(o),getSlotResult:o=>a.getSlotResult(o),getPersona:()=>a.getPersona(),fetchWeights:()=>a.fetchWeights(),getGraph:()=>a.getGraph(),dispose:()=>a.dispose(),destroy:()=>a.destroy()};function i(o){a=o}return{proxy:d,setInner:i}}function qe(e){var Z,ee,te,ne,f,h,L,O,K;if(typeof window=="undefined")return X;kt=e.apiKey;let t=P.get(e.apiKey||"local");if(t!=null&&t.dispose)try{t.dispose()}catch(l){}let n=e.respectDoNotTrack!==!1&&Ie(),a=e.consent===!1||n,d=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!d&&e.localMode!==!1)return a?(P.set(e.apiKey||"local",{config:e,upgrade:null}),X):(P.set(e.apiKey||"local",{config:e,upgrade:null}),Fe(e));if(a){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."),X;let{proxy:l,setInner:m}=Ot(e);return P.set(e.apiKey,{config:e,upgrade:n?null:m}),l}return P.set(e.apiKey,{config:e,upgrade:null}),X}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."),X;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),X;let i=(Z=e.ingestUrl)!=null?Z:je,r=Date.now(),o=ae({ssrSessionId:e.ssrSessionId}),s=Me(),c=Ne({ingestUrl:i,apiKey:e.apiKey}),u=We(i),g={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},y=z((ee=navigator.userAgent)!=null?ee:""),p=typeof window!="undefined"?window.location.origin:void 0,v=Y((te=document.referrer)!=null?te:"",p),w=(ne=e.sessionSegment)!=null?ne:`${y}:${v}`,x=new Map,A=new Map,E=null,ie=l=>{for(let m of l)A.has(m.id)||A.set(m.id,ve(m))};if(e.initialSlots)for(let[l,m]of Object.entries(e.initialSlots))A.set(l,m);let B=Ge(e.apiKey);if(B)for(let[l,m]of Object.entries(B.slots))A.has(l)||A.set(l,m);let M={low:.15,medium:.5,high:.85};if(e.initialPersona)E=b({},e.initialPersona);else{let l=document.documentElement.dataset;l.sentientPersona?E={persona:l.sentientPersona,confidence:(h=M[(f=l.sentientConfidence)!=null?f:"low"])!=null?h:.15}:B&&(E={persona:B.persona,confidence:(L=M[B.band])!=null?L:.15})}if(e.initialAssignments)for(let[l,m]of Object.entries(e.initialAssignments))s.set(l,w,{variantId:m,assignedAt:Date.now(),segment:w,confidence:1});let D=Promise.resolve(),F=o.getSessionId();if(F){let l=Q((O=document.referrer)!=null?O:""),m=b(b({sessionId:F,deviceClass:y,trafficSource:v,referrerDomain:l,utmParams:Dt(),timeOfDay:H(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:o.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||de((K=navigator.userAgent)!=null?K:"")},e.userId?{userId:e.userId}:{}),e.country?{country:e.country}:{});try{D=fetch(`${u}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(m),headers:g}).then(S=>{S.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(S){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:c});let U={goal(l,m={},S=1,N=0){let T=o.getSessionId();if(!T)return;let C=we();D.then(()=>{fetch(`${u}/goals`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:T,name:l,metadata:m,weight:S,stepIndex:N,goalId:C}),headers:g}).catch(()=>{})})},componentGoal(l,m,S){var _,$,R;let N=o.getSessionId();if(!N)return;let T=s.get(l,w),C=T?null:(_=A.get(l))!=null?_:null;if(!T&&C===null){e.debug&&console.warn(`[sentient] componentGoal("${l}"): no assignment or slot decision yet \u2014 render its <Adaptive>/adaptive hook or call assign()/decide() before recording a goal.`);return}let j=T?T.variantId:Ke(C),G={id:we(),sessionId:N,projectId:e.apiKey,componentId:l,variantId:j,eventType:"goal_achieved",goalType:m,payload:b({reward:($=S==null?void 0:S.reward)!=null?$:1},(R=S==null?void 0:S.metadata)!=null?R:{}),timestamp:Date.now(),timeInSession:Date.now()-r};e.debug&&console.log("[sentient] componentGoal",G),D.then(()=>c.push(G))},identify(l){let m=o.getSessionId();m&&D.then(()=>{fetch(`${u}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:m,userId:l,ephemeral:o.isEphemeral()}),headers:g}).catch(()=>{})})},track(l){let m=o.getSessionId();if(!m)return;let S=q(b({},l),{id:we(),sessionId:m,timestamp:Date.now(),timeInSession:Date.now()-r});e.debug&&console.log("[sentient] track",S),D.then(()=>c.push(S))},getAssignment(l,m){return s.get(l,m)},async assign(l,m,S,N){let T=o.getSessionId();if(!T)return null;let C=s.get(l,w);if(C&&(m!=null&&m.length||C.content!==void 0)){let _=C.ttlMs&&C.ttlMs>0?Math.max(0,C.assignedAt+C.ttlMs-Date.now()):0;return{variantId:C.variantId,assignmentTtlMs:_,content:C.content}}let j=x.get(l);if(j)return j;let G=(async()=>{await D;try{let _={sessionId:T,componentId:l,variantIds:m};N!==void 0?_.agentDataByVariant=N:S!==void 0&&(_.agentData=S);let $=await fetch(`${u}/assign`,{method:"POST",body:JSON.stringify(_),headers:g});if(!$.ok)return null;let R=await $.json();return s.set(l,w,b({variantId:R.variantId,assignedAt:Date.now(),segment:w,confidence:1,content:R.content},R.assignmentTtlMs&&R.assignmentTtlMs>0?{ttlMs:R.assignmentTtlMs}:{})),R}catch(_){return null}finally{x.delete(l)}})();return x.set(l,G),G},async decide(l){var N,T,C,j,G,_,$,R,Te;let m=o.getSessionId();if(!m)return null;let S=(N=l.slots)!=null?N:[];await D;try{let W={sessionId:m};l.sections&&l.sections.length>0&&(W.sections=l.sections.map(k=>({id:k}))),W.components=(T=l.components)!=null?T:[],S.length>0&&(W.slots=S.map(be)),l.slotsFrom==="registry"&&(W.slotsFrom="registry"),l.v&&(W.v=l.v);let _e=await fetch(`${u}/decide`,{method:"POST",body:JSON.stringify(W),headers:g});if(!_e.ok)return ie(S),null;let I=await _e.json(),oe={};for(let k of S)oe[k.id]=(j=(C=I.slots)==null?void 0:C[k.id])!=null?j:ve(k);if(I.slots)for(let[k,re]of Object.entries(I.slots))k in oe||(oe[k]=re);for(let[k,re]of Object.entries(oe))A.set(k,re);let Ze=E!=null&&E.persona!=="unknown";I.persona&&!(I.persona==="unknown"&&Ze)?E={persona:I.persona,confidence:(G=I.confidence)!=null?G:0}:E||(E={persona:"unknown",confidence:0});for(let[k,re]of Object.entries((_=I.assignments)!=null?_:{}))s.set(k,w,{variantId:re,assignedAt:Date.now(),segment:w,confidence:1});return ue(e.apiKey,b({v:1,persona:E.persona,band:(0,Ee.confidenceBand)(E.confidence),slots:Object.fromEntries(A),layoutOrder:($=I.layoutOrder)!=null?$:null,savedAt:Date.now()},I.slotConfig?{slotConfig:I.slotConfig}:{})),b(b(b({layoutOrder:(R=I.layoutOrder)!=null?R:null,assignments:(Te=I.assignments)!=null?Te:{},slots:oe,persona:E.persona,confidence:E.confidence},I.slotConfig?{slotConfig:I.slotConfig}:{}),I.goals?{goals:I.goals}:{}),I.sectionMap?{sectionMap:I.sectionMap}:{})}catch(W){return ie(S),null}},getSlotResult(l){var m;return(m=A.get(l))!=null?m:null},getPersona(){return E?{persona:E.persona,confidence:E.confidence,band:(0,Ee.confidenceBand)(E.confidence)}:null},async fetchWeights(){var l;try{let m=await fetch(`${u}/weights`,{headers:g});return m.ok?(l=(await m.json()).components)!=null?l:[]:[]}catch(m){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){var l;c.destroy(),((l=P.get(e.apiKey))==null?void 0:l.dispose)===U.dispose&&P.delete(e.apiKey),e.debug&&console.log("[sentient] disposed")},destroy(){var l;c.destroy(),o.destroy(),((l=P.get(e.apiKey))==null?void 0:l.dispose)===U.dispose&&P.delete(e.apiKey);try{localStorage.removeItem(le+e.apiKey),localStorage.removeItem(fe(e.apiKey))}catch(m){}e.debug&&console.log("[sentient] destroyed")}};if(P.set(e.apiKey,{config:e,upgrade:null,dispose:U.dispose}),e.debug){let l=window;l.__sentient&&(l.__sentient.client=U)}return U}var Je=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Nt=[["pricing",/\b(pricing|price|plans?|subscriptions?|per month|\/mo|tier)\b/i],["faq",/\b(faq|frequently asked|common questions?)\b/i],["comparison",/\b(compare|comparison|versus|vs\.)\b/i],["social_proof",/\b(testimonial|reviews?|trusted by|loved by|customers?|logos|rated|case stud)\b/i],["trust",/\b(security|guarantee|privacy|compliance|secure|gdpr|soc ?2|encrypt)\b/i],["features",/\b(features?|how it works|benefits?|capabilit|what you get)\b/i]],Pt=[["pricing",/(?:[$€£]\s?\d[\d,.]*\s*(?:\/|per\s)\s*(?:mo|month|yr|year|seat|user))|(?:\b(?:starter|basic|pro|growth|premium|enterprise)\b[^.]{0,60}[$€£]\s?\d)/i],["social_proof",/(?:★{2,})|(?:\b\d(?:\.\d)?\s*(?:out of|\/)\s*5\b)|(?:\brated\b)|(?:["“][^"”]{20,160}["”]\s*[—–-]\s*[A-Z][a-z]+)/],["trust",/\b(?:money[- ]back guarantee|refund(?:s)? within|encrypted|soc ?2|iso ?27001|gdpr[- ]compliant|cancel anytime)\b/i],["comparison",/\b(?:vs|versus)\b\.?[^.!?]{0,80}\b(?:compare|comparison|plans?|features?|alternative)\b|\bhow (?:we|it) compares?\b/i]];function Mt(e){var n;let t=e.querySelector("h1, h2, h3");return((n=t==null?void 0:t.textContent)!=null?n:"").slice(0,160)}function Lt(e){if(e.tag==="nav"||e.tag==="footer")return{type:"navigation",strength:"weak"};let t=`${e.idClass} ${e.headingText}`.toLowerCase();for(let[n,a]of Nt)if(a.test(t))return{type:n,strength:"strong"};for(let[n,a]of Pt)if(a.test(e.bodyText))return{type:n,strength:"strong"};return e.actionCount>=1&&e.textLength>0&&e.textLength<200?{type:"cta",strength:"weak"}:e.tag==="header"?{type:"hero",strength:"weak"}:/\b(hero|headline|banner)\b/i.test(t)?{type:"hero",strength:"weak"}:{type:"generic",strength:"weak"}}function Ut(e){var n,a;let t=((n=e.textContent)!=null?n:"").replace(/\s+/g," ").trim();return{tag:e.tagName.toLowerCase(),idClass:`${e.id} ${String((a=e.className)!=null?a:"")}`,headingText:Mt(e),bodyText:t.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:t.length}}function ze(e){return Lt(Ut(e)).type}var Kt=new Set(["SECTION","ARTICLE","MAIN","DIV"]),Gt="h1, h2, h3",$t={scan:async()=>({nodes:[],edges:[],scannedAt:0}),observe:()=>{},getProminenceScore:()=>0,destroy:()=>{}};function Ce(e,t,n){return n<=t?0:Math.max(0,Math.min(1,(e-t)/(n-t)))}function Bt(e){var t,n,a;try{let d=e;for(let i of Object.keys(d)){if(!i.startsWith("__reactFiber")&&!i.startsWith("__reactInternalInstance"))continue;let r=d[i],o=(a=(t=r==null?void 0:r.type)==null?void 0:t.displayName)!=null?a:(n=r==null?void 0:r.type)==null?void 0:n.name;if(o&&o.length>1)return o}}catch(d){}}function Ft(e){let t={};for(let n of Array.from(e.attributes))n.name.startsWith("data-")&&(t[n.name]=n.value);return t}var Ye=new Set(Je);function jt(e){let t=e.getAttribute("data-sentient-type");if(t&&Ye.has(t))return t;let n=e.getAttribute("role");return n&&Ye.has(n)?n:ze(e)}function Wt(e){var t,n;return(n=(t=e.getAttribute("data-sentient-id"))!=null?t:e.getAttribute("id"))!=null?n:e.tagName.toLowerCase()}function qt(e){let t=0,n=e.parentElement;for(;n;)t++,n=n.parentElement;return t}function xe(e,t){var a,d,i;let n=e.querySelector(Gt);return{componentId:Wt(e),semanticType:jt(e),ariaLabel:(a=e.getAttribute("aria-label"))!=null?a:void 0,headingText:(i=(d=n==null?void 0:n.textContent)==null?void 0:d.trim())!=null?i:void 0,isAboveFold:e.getBoundingClientRect().top<window.innerHeight,prominenceScore:t(e),depth:qt(e),reactComponentName:Bt(e),dataAttributes:Ft(e)}}function Qe(e){var i;let t=[],n=new Set,a="__root__",d=new Map;for(let[r,o]of e){let s=r.parentElement,c=a;for(;s;){if(e.has(s)){c=e.get(s);let g=e.get(r),y=`${c}->${g}`;!n.has(y)&&c!==g&&(n.add(y),t.push({fromComponentId:c,toComponentId:g,weight:.6}));break}s=s.parentElement}let u=(i=d.get(c))!=null?i:[];u.push(r),d.set(c,u)}for(let r of d.values())if(!(r.length<2))for(let o=0;o<r.length;o++)for(let s=o+1;s<r.length;s++){let c=e.get(r[o]),u=e.get(r[s]);if(c===u)continue;let g=`${c}->${u}::sib`,y=`${u}->${c}::sib`;n.has(g)||(n.add(g),t.push({fromComponentId:c,toComponentId:u,weight:.3})),n.has(y)||(n.add(y),t.push({fromComponentId:u,toComponentId:c,weight:.3}))}return t}function Jt(e){let t=[],n=new Set,a=new Map;return document.querySelectorAll("[data-sentient-id]").forEach(r=>{if(r instanceof Element&&!n.has(r)){n.add(r);let o=xe(r,e);t.push(o),a.set(r,o.componentId)}}),document.querySelectorAll("section, article, main, aside").forEach(r=>{if(!(r instanceof Element)||n.has(r))return;let o=r.hasAttribute("aria-label"),s=r.hasAttribute("data-sentient-id");if(!o&&!s)return;n.add(r);let c=xe(r,e);t.push(c),a.set(r,c.componentId)}),{nodes:t,edges:Qe(a)}}function He(){if(typeof window=="undefined")return $t;let e=null,t=0,n=null,a=o=>{try{let s=window.getComputedStyle(o),c=parseFloat(s.fontSize)||12,u=parseFloat(s.zIndex)||0,g=o.getBoundingClientRect(),y=Math.max(g.top,0),p=window.innerHeight||1,v=1/(y/p+1),w=Ce(c,12,48)*.4+Ce(v,0,1)*.4+Ce(u,0,100)*.2;return Math.max(0,Math.min(1,w))}catch(s){return .5}};return{scan:()=>new Promise(o=>{let s=()=>{let{nodes:c,edges:u}=Jt(a);o({nodes:c,edges:u,scannedAt:Date.now()})};try{typeof requestIdleCallback=="function"?t=requestIdleCallback(s,{timeout:100}):s()}catch(c){s()}}),observe:o=>{n=o;try{e=new MutationObserver(s=>{let c=[],u=new Map;for(let g of s)g.type==="childList"&&g.addedNodes.forEach(y=>{if(!(y instanceof Element)||!Kt.has(y.tagName))return;let p=y.hasAttribute("data-sentient-id"),v=y.hasAttribute("aria-label");if(!p&&!v)return;let w=xe(y,a);c.push(w),u.set(y,w.componentId)});c.length>0&&n&&n({nodes:c,edges:Qe(u),addedAt:Date.now()})}),e.observe(document.body,{childList:!0,subtree:!0})}catch(s){}},getProminenceScore:a,destroy:()=>{if(e&&(e.disconnect(),e=null),t&&typeof cancelIdleCallback=="function")try{cancelIdleCallback(t)}catch(o){}t=0,n=null}}}var Ae="_snt_graph_nodes",Ve="_snt_graph_edges",zt={pricing:["features","faq"],features:["pricing"],faq:["pricing"],social_proof:["cta"],cta:["social_proof","hero","trust"],hero:["cta"],comparison:["pricing"],trust:["cta"]};function Yt(e){var t;return(t=zt[e])!=null?t:[]}function Qt(e,t){try{let n=localStorage.getItem(e);return n?JSON.parse(n):t}catch(n){return t}}function Ht(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch(n){}}var Vt=new Set(["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"]);function Xt(e){return Vt.has(e)?e:"generic"}function Zt(e,t,n){let a=`${e}:${t}:${n.join(",")}`,d=5381;for(let i=0;i<a.length;i++)d=(d<<5)+d+a.charCodeAt(i)&4294967295;return(d>>>0).toString(16).padStart(8,"0")}function Xe(e){let t=new Map,n=new Map,a=()=>{typeof window!="undefined"&&Ht(Ae,[...t.values()])},d=i=>{var r;try{let o=JSON.parse(i);t.clear();for(let s of(r=o.pageNodes)!=null?r:[])t.set(s.componentId,s)}catch(o){}};if(typeof window!="undefined"){let i=Qt(Ae,[]);for(let r of i)t.set(r.componentId,r);try{localStorage.removeItem(Ve)}catch(r){}}return{addPageNode(i){t.set(i.componentId,i),a()},addStructuralEdge(i){let r=`${i.fromComponentId}->${i.toComponentId}`;n.set(r,i)},syncOnce(){var r,o;if(!(e!=null&&e.syncUrl)||typeof window=="undefined")return;let i=[...t.values()];if(i.length!==0)try{let s=new Map;for(let p of i){let v=(r=s.get(p.semanticType))!=null?r:[];v.push(p),s.set(p.semanticType,v)}let c=[],u=new Set;for(let p of i)for(let v of Yt(p.semanticType)){let w=(o=s.get(v))!=null?o:[];for(let x of w){if(x.componentId===p.componentId)continue;let A=`semantic:${p.componentId}->${x.componentId}`;u.has(A)||(u.add(A),c.push({fromComponentId:p.componentId,toComponentId:x.componentId,type:"semantic",weight:.4,confidence:.9}))}}let g=new Set(i.map(p=>p.componentId));for(let p of n.values()){if(!g.has(p.fromComponentId)||!g.has(p.toComponentId))continue;let v=`structural:${p.fromComponentId}->${p.toComponentId}`;u.has(v)||(u.add(v),c.push({fromComponentId:p.fromComponentId,toComponentId:p.toComponentId,type:"structural",weight:p.weight,confidence:1}))}let y={pageUrl:window.location.href,nodes:i.map(p=>{let v=Xt(p.semanticType);return{componentId:p.componentId,semanticType:v,answers:p.answers,contentHash:Zt(p.componentId,v,p.answers),prominenceScore:p.prominenceScore,depthInPage:p.depth}}),edges:c};fetch(e.syncUrl,{method:"POST",keepalive:!0,headers:b({"Content-Type":"application/json"},e.apiKey?{Authorization:`Bearer ${e.apiKey}`}:{}),body:JSON.stringify(y)}).catch(()=>{})}catch(s){}},snapshot(){return{pageNodes:[...t.values()],capturedAt:Date.now()}},serialize(){return JSON.stringify({pageNodes:[...t.values()]})},restore:d,destroy(){if(typeof window!="undefined")try{localStorage.removeItem(Ae),localStorage.removeItem(Ve)}catch(i){}}}}var en="https://api.sentient-ui.com/v1/events";function tn(){try{let e=document.cookie.match(/(?:^|; )_snt_uid=([^;]*)/);return e?decodeURIComponent(e[1]):void 0}catch(e){return}}function nn(e){var c;let t=qe(e),n=e.respectDoNotTrack!==!1&&Ie(),a=e.consent===!1||n;if(!e.graph||!e.apiKey||a||typeof window=="undefined")return t;let d=He(),i=(c=e.ingestUrl)!=null?c:en,r=Xe({syncUrl:i.replace(/\/events\/?$/,"/graph/sync"),apiKey:e.apiKey,projectId:e.apiKey,sessionId:tn()});try{let u=localStorage.getItem("_snt_graph_nodes");u&&r.restore(JSON.stringify({pageNodes:JSON.parse(u)}))}catch(u){}d.scan().then(u=>{for(let g of u.nodes)r.addPageNode({id:g.componentId,componentId:g.componentId,semanticType:g.semanticType,answers:g.headingText?[g.headingText]:[],prominenceScore:g.prominenceScore,depth:g.depth});for(let g of u.edges)r.addStructuralEdge(g);r.syncOnce()});let o=null,s=()=>{o!==null&&clearTimeout(o),o=setTimeout(()=>{o=null,r.syncOnce()},500)};return d.observe(u=>{for(let g of u.nodes)r.addPageNode({id:g.componentId,componentId:g.componentId,semanticType:g.semanticType,answers:g.headingText?[g.headingText]:[],prominenceScore:g.prominenceScore,depth:g.depth});for(let g of u.edges)r.addStructuralEdge(g);s()}),q(b({},t),{getGraph:()=>r.snapshot(),dispose:()=>{o!==null&&clearTimeout(o),d.destroy(),r.destroy(),t.dispose()},destroy:()=>{o!==null&&clearTimeout(o),d.destroy(),r.destroy(),t.destroy()}})}0&&(module.exports={deriveSessionSegment,detectDeviceClass,detectTimeOfDay,detectTrafficSource,init,referrerDomainFromReferer});
2
2
  //# sourceMappingURL=index-graph.js.map