@sentientui/core 0.16.4 → 0.16.6
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-C5CJIBEL.mjs +2 -0
- package/dist/chunk-C5CJIBEL.mjs.map +1 -0
- package/dist/{index-CTs3AM9E.d.ts → index-BpGkrzI3.d.ts} +16 -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 -10
- package/dist/index-graph.d.ts +2 -10
- package/dist/index-graph.js +1 -1
- package/dist/index-graph.js.map +1 -1
- package/dist/index-graph.mjs +1 -1
- package/dist/index-graph.mjs.map +1 -1
- package/dist/index-local.d.cts +1 -1
- package/dist/index-local.d.ts +1 -1
- package/dist/{index-DqbtJfra.d.cts → index-oQoVHiWq.d.cts} +16 -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 +2 -2
- package/dist/chunk-SHGSYP75.mjs +0 -2
- package/dist/chunk-SHGSYP75.mjs.map +0 -1
package/dist/index-graph.js
CHANGED
|
@@ -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 ot=Object.create;var se=Object.defineProperty,rt=Object.defineProperties,st=Object.getOwnPropertyDescriptor,it=Object.getOwnPropertyDescriptors,at=Object.getOwnPropertyNames,ke=Object.getOwnPropertySymbols,ct=Object.getPrototypeOf,De=Object.prototype.hasOwnProperty,dt=Object.prototype.propertyIsEnumerable;var Oe=(e,t,n)=>t in e?se(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,v=(e,t)=>{for(var n in t||(t={}))De.call(t,n)&&Oe(e,n,t[n]);if(ke)for(var n of ke(t))dt.call(t,n)&&Oe(e,n,t[n]);return e},B=(e,t)=>rt(e,it(t));var lt=(e,t)=>{for(var n in t)se(e,n,{get:t[n],enumerable:!0})},Ne=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let c of at(t))!De.call(e,c)&&c!==n&&se(e,c,{get:()=>t[c],enumerable:!(o=st(t,c))||o.enumerable});return e};var ut=(e,t,n)=>(n=e!=null?ot(ct(e)):{},Ne(t||!e||!e.__esModule?se(n,"default",{value:e,enumerable:!0}):n,e)),gt=e=>Ne(se({},"__esModule",{value:!0}),e);var gn={};lt(gn,{deriveSessionSegment:()=>be,detectDeviceClass:()=>z,detectTimeOfDay:()=>V,detectTrafficSource:()=>Y,init:()=>un,referrerDomainFromReferer:()=>Q});module.exports=gt(gn);function ae(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(e){}try{if(typeof crypto!="undefined"&&typeof crypto.getRandomValues=="function"){let e=new Uint8Array(16);crypto.getRandomValues(e),e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t="";for(let n=0;n<16;n++)t+=e[n].toString(16).padStart(2,"0"),(n===3||n===5||n===7||n===9)&&(t+="-");return t}}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 pt="_snt_uid",mt=365,J="_snt_uid";function ft(){return ae()}function yt(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function ht(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(o){}}function St(e){try{return localStorage.getItem(e)}catch(t){return null}}function vt(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function bt(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function wt(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function Et(e){try{sessionStorage.removeItem(e)}catch(t){}}function It(e){try{return document.cookie=`${e}_probe=1; max-age=1; SameSite=strict; path=/`,document.cookie.indexOf(`${e}_probe=1`)!==-1}catch(t){return!1}}function Ct(e){try{localStorage.removeItem(e)}catch(t){}}function xt(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var At={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function ce(e){var g,p,y,d,h,b;if(typeof window=="undefined")return At;let t=(g=e==null?void 0:e.cookieName)!=null?g:pt,o=((p=e==null?void 0:e.cookieTTLDays)!=null?p:mt)*24*60*60,c=E=>E&&E.length>0?E:null,r=(b=(h=(d=(y=c(yt(t)))!=null?y:c(St(J)))!=null?d:c(bt(J)))!=null?h:c(e==null?void 0:e.ssrSessionId))!=null?b:ft();ht(t,r,o);let s=vt(J,r),i=It(t),a=s?!1:wt(J,r),l=!s&&!i&&!a;return{getSessionId:()=>r,isEphemeral:()=>l,destroy:()=>{r=null,xt(t),Ct(J),Et(J)}}}function he(e){return`_snt_retry_${e.slice(0,12)}`}var Tt={push:()=>{},flush:()=>{},destroy:()=>{}};function Rt(e,t){try{let n=localStorage.getItem(t);if(!n)return[];let o=JSON.parse(n);return Array.isArray(o)?(localStorage.removeItem(t),o.slice(-e)):[]}catch(n){return[]}}function ye(e,t,n){try{let o=(()=>{try{let s=localStorage.getItem(n);if(!s)return[];let i=JSON.parse(s);return Array.isArray(i)?i:[]}catch(s){return[]}})(),c=new Map;for(let s of o)c.set(s.id,s);for(let s of e)c.set(s.id,s);let r=[...c.values()].slice(-t);localStorage.setItem(n,JSON.stringify(r))}catch(o){}}function _t(e,t){try{let n=localStorage.getItem(t);if(!n)return;let o=JSON.parse(n);if(!Array.isArray(o))return;let c=new Set(e),r=o.filter(s=>!c.has(s.id));if(r.length===o.length)return;r.length===0?localStorage.removeItem(t):localStorage.setItem(t,JSON.stringify(r))}catch(n){}}function Pe(e){var ee,te,ne;if(typeof window=="undefined")return Tt;let t=(ee=e.flushIntervalMs)!=null?ee:5e3,n=(te=e.maxBatchSize)!=null?te:20,o=(ne=e.maxRetrySize)!=null?ne:100,c=e.ingestUrl,r=e.apiKey,s=he(r),i=[],a=new Set,l=[],g=f=>{for(let S of f)p.delete(S),!a.has(S)&&(a.add(S),l.push(S));for(;l.length>500;){let S=l.shift();S&&a.delete(S)}_t(f,s)},p=new Set,y=f=>{a.has(f.id)||p.has(f.id)||(p.add(f.id),i.push(f))},d=f=>{for(let S of f)a.has(S.id)||(p.add(S.id),i.push(S))},h=Rt(o,s);for(let f of h)y(f);let b=0,E=0,x=f=>{if(f.length===0)return;let S=JSON.stringify(f),L=f.map(u=>u.id),D;try{D=fetch(c,{method:"POST",keepalive:!0,body:S,headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`}})}catch(u){ye(f,o,s),d(f),E++,b=Date.now()+Math.min(6e4,1e3*2**Math.min(E,6));return}let K=u=>{if(u.ok||u.status>=400&&u.status<500&&u.status!==429){g(L),E=0,b=0;return}ye(f,o,s),d(f),E++,b=Date.now()+Math.min(6e4,1e3*2**Math.min(E,6))};D instanceof Promise?D.then(K).catch(()=>{ye(f,o,s),d(f),E++,b=Date.now()+Math.min(6e4,1e3*2**Math.min(E,6))}):K(D)},I=typeof TextEncoder!="undefined"?new TextEncoder:null,ie=f=>I?I.encode(f).length:f.length,j=f=>{let S=[],L=2;for(let D of f){let K=ie(JSON.stringify(D))+1;if(S.length>0&&L+K>57344||S.length>=n)break;S.push(D),L+=K}return S},M=()=>{try{if(Date.now()<b)return;for(;i.length>0&&!(Date.now()<b);){let f=i.filter(L=>!a.has(L.id));if(i.length=0,f.length===0)break;let S=j(f);if(S.length===0)break;S.length<f.length&&i.push(...f.slice(S.length)),x(S)}}catch(f){}},O=!0,F=null;F=setInterval(()=>{O&&M()},t);let U=()=>{document.visibilityState==="hidden"&&M()},Z=()=>{M()};return document.addEventListener("visibilitychange",U),window.addEventListener("pagehide",Z),{push(f){y(f),i.length>=n&&M()},flush:M,destroy(){O=!1,F!==null&&(clearInterval(F),F=null),document.removeEventListener("visibilitychange",U),window.removeEventListener("pagehide",Z),M()}}}var ve="_snt_asgn_";function de(e,t){return`${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function kt(e,t){return`${ve}${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function Me(e){let t=e.slice(ve.length),n=t.indexOf(":");if(n<0)return null;try{return{componentId:decodeURIComponent(t.slice(0,n)),segment:decodeURIComponent(t.slice(n+1))}}catch(o){return null}}function Se(){try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n!=null&&n.startsWith(ve)&&e.push(n)}return e}catch(e){return[]}}function Le(e=18e5){let t=new Map,n=c=>c.assignedAt+(c.ttlMs&&c.ttlMs>0?c.ttlMs:e)<Date.now();return typeof window!="undefined"&&(()=>{for(let c of Se())try{let r=localStorage.getItem(c);if(!r)continue;let s=JSON.parse(r);if(n(s)){localStorage.removeItem(c);continue}let i=Me(c);if(!i)continue;t.set(de(i.componentId,i.segment),s)}catch(r){}})(),{get(c,r){let s=t.get(de(c,r));return s?n(s)?(t.delete(de(c,r)),null):s:null},set(c,r,s){let i=de(c,r);t.set(i,s);try{localStorage.setItem(kt(c,r),JSON.stringify(s))}catch(a){}},invalidate(c){let r=`${encodeURIComponent(c)}:`;for(let s of[...t.keys()])s.startsWith(r)&&t.delete(s);for(let s of Se()){let i=Me(s);if((i==null?void 0:i.componentId)===c)try{localStorage.removeItem(s)}catch(a){}}},clear(){t.clear();for(let c of Se())try{localStorage.removeItem(c)}catch(r){}}}}var Ue=["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 le(e){return Ke(e)!==null}function Ke(e){var n;if(!e)return null;let t=e.toLowerCase();return(n=Ue.find(o=>t.includes(o.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(c){}let o=n.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(o)?"search":/(^|\.)(twitter\.com|x\.com|facebook\.com|linkedin\.com|reddit\.com|t\.co)$/.test(o)?"social":"referral"}catch(n){return"direct"}}function Q(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function V(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function be(e){let t=Ot("__segment__",e);return`${t.deviceClass}:${t.trafficSource}`}function Ot(e,t){var r,s,i,a,l,g,p;let n=(s=(r=t==null?void 0:t.userAgent)==null?void 0:r.trim())!=null?s:"",o=(a=(i=t==null?void 0:t.referer)==null?void 0:i.trim())!=null?a:"",c=(l=t==null?void 0:t.now)!=null?l:new Date;return{sessionId:e,ephemeral:!1,utmParams:(g=t==null?void 0:t.utmParams)!=null?g:{},deviceClass:n?z(n):"desktop",trafficSource:o?Y(o,t==null?void 0:t.appOrigin):"direct",referrerDomain:Q(o),timeOfDay:V(c),dayOfWeek:(p=["sun","mon","tue","wed","thu","fri","sat"][c.getDay()])!=null?p:"sun",automation:(t==null?void 0:t.webdriver)===!0||le(n)}}var H=require("@sentientui/policy");function we(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 Ee(e){let t=we(e);return(0,H.slotResultFor)(t,(0,H.slotBaselineArm)(t))}function Ge(e){return typeof e=="string"?e:(0,H.canonicalArm)(e)}var ue="_snt_snap:",Dt=["low","medium","high"];function $e(e){try{let t=localStorage.getItem(ue+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"||!Dt.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 ge(e,t){try{localStorage.setItem(ue+e,JSON.stringify(t))}catch(n){}}var Ce=require("@sentientui/policy");var me=require("@sentientui/policy");var Be="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",Nt="[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.",je=!1,pe=!1;function Pt(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(t){return}}function Fe(e){var i;let t=ce({ssrSessionId:e.ssrSessionId}),n=(i=t.getSessionId())!=null?i:"local",o=Pt(),c=import("@sentientui/core/local").then(a=>{let l=a;return l.LOCAL_ENGINE_AVAILABLE?(je||(je=!0,console.info(Nt)),l):(pe||(pe=!0,console.error(Be)),null)}).catch(()=>(pe||(pe=!0,console.error(Be)),null)),r=null;function s(a){let l=document.documentElement;l.dataset.sentientPersona===void 0&&(l.dataset.sentientPersona=a.persona,l.dataset.sentientConfidence=(0,me.confidenceBand)(a.confidence))}return{isLocal:!0,async decide(a){var p,y,d;let l=await c;if(!l)return null;let g=l.createLocalEngine({sessionId:n,forcedPersona:o}).decide(a);return r=B(v({},g),{layoutOrder:(y=(p=g.layoutOrder)!=null?p:r==null?void 0:r.layoutOrder)!=null?y:null,slots:v(v({},(d=r==null?void 0:r.slots)!=null?d:{}),g.slots)}),ge(e.apiKey||"local",{v:1,persona:r.persona,band:(0,me.confidenceBand)(r.confidence),slots:r.slots,layoutOrder:r.layoutOrder,savedAt:Date.now()}),s(g),g},getSlotResult(a){var l,g,p;return(p=(g=r==null?void 0:r.slots[a])!=null?g:(l=e.initialSlots)==null?void 0:l[a])!=null?p:null},getPersona(){return r?{persona:r.persona,confidence:r.confidence,band:(0,me.confidenceBand)(r.confidence)}:null},async assign(a,l){var y;let g=await c;return!g||!l||l.length===0?l!=null&&l[0]?{variantId:l[0],assignmentTtlMs:0}:null:{variantId:(y=g.createLocalEngine({sessionId:n,forcedPersona:o}).decide({components:[{id:a,variantIds:l}]}).assignments[a])!=null?y:l[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>t.destroy()}}var We="https://api.sentient-ui.com/v1/events",P=new Map,Mt=null;function Ie(){return ae()}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 Lt(){try{let e={},t=new URLSearchParams(window.location.search);for(let[n,o]of t)n.startsWith("utm_")&&(e[n]=o);return e}catch(e){return{}}}function qe(e){return e.replace(/\/events\/?$/,"")}function xe(){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 Ut(e){var s;let t=qe((s=e.ingestUrl)!=null?s:We),n={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},o={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),async assign(i,a,l){try{let g=new URLSearchParams({componentId:i});for(let d of a!=null?a:[])g.append("variantIds[]",d);let p=await fetch(`${t}/winner?${g.toString()}`,{headers:n});return p.ok?{variantId:(await p.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:()=>{}},c={track:i=>o.track(i),goal:(i,a,l,g)=>o.goal(i,a,l,g),componentGoal:(i,a,l)=>o.componentGoal(i,a,l),identify:i=>o.identify(i),getAssignment:(i,a)=>o.getAssignment(i,a),assign:(i,a,l,g)=>o.assign(i,a,l,g),decide:i=>o.decide(i),getSlotResult:i=>o.getSlotResult(i),getPersona:()=>o.getPersona(),fetchWeights:()=>o.fetchWeights(),getGraph:()=>o.getGraph(),dispose:()=>o.dispose(),destroy:()=>o.destroy()};function r(i){o=i}return{proxy:c,setInner:r}}function Je(e){var Z,ee,te,ne,f,S,L,D,K;if(typeof window=="undefined")return X;Mt=e.apiKey;let t=P.get(e.apiKey||"local");if(t!=null&&t.dispose)try{t.dispose()}catch(u){}let n=e.respectDoNotTrack!==!1&&xe(),o=e.consent===!1||n,c=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!c&&e.localMode!==!1)return o?(P.set(e.apiKey||"local",{config:e,upgrade:null}),X):(P.set(e.apiKey||"local",{config:e,upgrade:null}),Fe(e));if(o){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:u,setInner:m}=Ut(e);return P.set(e.apiKey,{config:e,upgrade:n?null:m}),u}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 r=(Z=e.ingestUrl)!=null?Z:We,s=Date.now(),i=ce({ssrSessionId:e.ssrSessionId}),a=Le(),l=Pe({ingestUrl:r,apiKey:e.apiKey}),g=qe(r),p={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},y=z((ee=navigator.userAgent)!=null?ee:""),d=typeof window!="undefined"?window.location.origin:void 0,h=Y((te=document.referrer)!=null?te:"",d),b=(ne=e.sessionSegment)!=null?ne:`${y}:${h}`,E=new Map,x=new Map,I=null,ie=u=>{for(let m of u)x.has(m.id)||x.set(m.id,Ee(m))};if(e.initialSlots)for(let[u,m]of Object.entries(e.initialSlots))x.set(u,m);let j=$e(e.apiKey);if(j)for(let[u,m]of Object.entries(j.slots))x.has(u)||x.set(u,m);let M={low:.15,medium:.5,high:.85};if(e.initialPersona)I=v({},e.initialPersona);else{let u=document.documentElement.dataset;u.sentientPersona?I={persona:u.sentientPersona,confidence:(S=M[(f=u.sentientConfidence)!=null?f:"low"])!=null?S:.15}:j&&(I={persona:j.persona,confidence:(L=M[j.band])!=null?L:.15})}if(e.initialAssignments)for(let[u,m]of Object.entries(e.initialAssignments))a.set(u,b,{variantId:m,assignedAt:Date.now(),segment:b,confidence:1});let O=Promise.resolve(),F=i.getSessionId();if(F){let u=Q((D=document.referrer)!=null?D:""),m=v(v({sessionId:F,deviceClass:y,trafficSource:h,referrerDomain:u,utmParams:Lt(),timeOfDay:V(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:i.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||le((K=navigator.userAgent)!=null?K:"")},e.userId?{userId:e.userId}:{}),e.country?{country:e.country}:{});try{O=fetch(`${g}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(m),headers:p}).then(w=>{w.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(w){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:l});let U={goal(u,m={},w=1,N=0){let T=i.getSessionId();if(!T)return;let A=Ie();O.then(()=>{fetch(`${g}/goals`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:T,name:u,metadata:m,weight:w,stepIndex:N,goalId:A}),headers:p}).catch(()=>{})})},componentGoal(u,m,w){var R,$,_;let N=i.getSessionId();if(!N)return;let T=a.get(u,b),A=T?null:(R=x.get(u))!=null?R:null;if(!T&&A===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 W=T?T.variantId:Ge(A),G={id:Ie(),sessionId:N,projectId:e.apiKey,componentId:u,variantId:W,eventType:"goal_achieved",goalType:m,payload:v({reward:($=w==null?void 0:w.reward)!=null?$:1},(_=w==null?void 0:w.metadata)!=null?_:{}),timestamp:Date.now(),timeInSession:Date.now()-s};e.debug&&console.log("[sentient] componentGoal",G),O.then(()=>l.push(G))},identify(u){let m=i.getSessionId();m&&O.then(()=>{fetch(`${g}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:m,userId:u,ephemeral:i.isEphemeral()}),headers:p}).catch(()=>{})})},track(u){let m=i.getSessionId();if(!m)return;let w=B(v({},u),{id:Ie(),sessionId:m,timestamp:Date.now(),timeInSession:Date.now()-s});e.debug&&console.log("[sentient] track",w),O.then(()=>l.push(w))},getAssignment(u,m){return a.get(u,m)},async assign(u,m,w,N){let T=i.getSessionId();if(!T)return null;let A=a.get(u,b);if(A&&(m!=null&&m.length||A.content!==void 0)){let R=A.ttlMs&&A.ttlMs>0?Math.max(0,A.assignedAt+A.ttlMs-Date.now()):0;return{variantId:A.variantId,assignmentTtlMs:R,content:A.content}}let W=E.get(u);if(W)return W;let G=(async()=>{await O;try{let R={sessionId:T,componentId:u,variantIds:m};N!==void 0?R.agentDataByVariant=N:w!==void 0&&(R.agentData=w);let $=await fetch(`${g}/assign`,{method:"POST",body:JSON.stringify(R),headers:p});if(!$.ok)return null;let _=await $.json();return a.set(u,b,v({variantId:_.variantId,assignedAt:Date.now(),segment:b,confidence:1,content:_.content},_.assignmentTtlMs&&_.assignmentTtlMs>0?{ttlMs:_.assignmentTtlMs}:{})),_}catch(R){return null}finally{E.delete(u)}})();return E.set(u,G),G},async decide(u){var N,T,A,W,G,R,$,_,Re;let m=i.getSessionId();if(!m)return null;let w=(N=u.slots)!=null?N:[];await O;try{let q={sessionId:m};u.sections&&u.sections.length>0&&(q.sections=u.sections.map(k=>({id:k}))),q.components=(T=u.components)!=null?T:[],w.length>0&&(q.slots=w.map(we)),u.slotsFrom==="registry"&&(q.slotsFrom="registry"),u.v&&(q.v=u.v);let _e=await fetch(`${g}/decide`,{method:"POST",body:JSON.stringify(q),headers:p});if(!_e.ok)return ie(w),null;let C=await _e.json(),oe={};for(let k of w)oe[k.id]=(W=(A=C.slots)==null?void 0:A[k.id])!=null?W:Ee(k);if(C.slots)for(let[k,re]of Object.entries(C.slots))k in oe||(oe[k]=re);for(let[k,re]of Object.entries(oe))x.set(k,re);let nt=I!=null&&I.persona!=="unknown";C.persona&&!(C.persona==="unknown"&&nt)?I={persona:C.persona,confidence:(G=C.confidence)!=null?G:0}:I||(I={persona:"unknown",confidence:0});for(let[k,re]of Object.entries((R=C.assignments)!=null?R:{}))a.set(k,b,{variantId:re,assignedAt:Date.now(),segment:b,confidence:1});return ge(e.apiKey,v({v:1,persona:I.persona,band:(0,Ce.confidenceBand)(I.confidence),slots:Object.fromEntries(x),layoutOrder:($=C.layoutOrder)!=null?$:null,savedAt:Date.now()},C.slotConfig?{slotConfig:C.slotConfig}:{})),v(v(v({layoutOrder:(_=C.layoutOrder)!=null?_:null,assignments:(Re=C.assignments)!=null?Re:{},slots:oe,persona:I.persona,confidence:I.confidence},C.slotConfig?{slotConfig:C.slotConfig}:{}),C.goals?{goals:C.goals}:{}),C.sectionMap?{sectionMap:C.sectionMap}:{})}catch(q){return ie(w),null}},getSlotResult(u){var m;return(m=x.get(u))!=null?m:null},getPersona(){return I?{persona:I.persona,confidence:I.confidence,band:(0,Ce.confidenceBand)(I.confidence)}:null},async fetchWeights(){var u;try{let m=await fetch(`${g}/weights`,{headers:p});return m.ok?(u=(await m.json()).components)!=null?u:[]:[]}catch(m){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){var u;l.destroy(),((u=P.get(e.apiKey))==null?void 0:u.dispose)===U.dispose&&P.delete(e.apiKey),e.debug&&console.log("[sentient] disposed")},destroy(){var u;l.destroy(),i.destroy(),((u=P.get(e.apiKey))==null?void 0:u.dispose)===U.dispose&&P.delete(e.apiKey);try{localStorage.removeItem(ue+e.apiKey),localStorage.removeItem(he(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 u=window;u.__sentient&&(u.__sentient.client=U)}return U}var ze=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Kt=[["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]],Gt=[["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 $t(e){var n;let t=e.querySelector("h1, h2, h3");return((n=t==null?void 0:t.textContent)!=null?n:"").slice(0,160)}function Bt(e){if(e.tag==="nav"||e.tag==="footer")return{type:"navigation",strength:"weak"};let t=`${e.idClass} ${e.headingText}`.toLowerCase();for(let[n,o]of Kt)if(o.test(t))return{type:n,strength:"strong"};for(let[n,o]of Gt)if(o.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 jt(e){var n,o;let t=((n=e.textContent)!=null?n:"").replace(/\s+/g," ").trim();return{tag:e.tagName.toLowerCase(),idClass:`${e.id} ${String((o=e.className)!=null?o:"")}`,headingText:$t(e),bodyText:t.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:t.length}}function Ye(e){return Bt(jt(e)).type}var Ft=new Set(["SECTION","ARTICLE","MAIN","DIV"]),Wt="h1, h2, h3",Qe=30,qt=1500,Jt={scan:async()=>({nodes:[],edges:[],scannedAt:0}),observe:()=>{},getProminenceScore:()=>0,destroy:()=>{}};function Ve(e,t,n){return n<=t?0:Math.max(0,Math.min(1,(e-t)/(n-t)))}function zt(e){var t,n,o;try{let c=e;for(let r of Object.keys(c)){if(!r.startsWith("__reactFiber")&&!r.startsWith("__reactInternalInstance"))continue;let s=c[r],i=(o=(t=s==null?void 0:s.type)==null?void 0:t.displayName)!=null?o:(n=s==null?void 0:s.type)==null?void 0:n.name;if(i&&i.length>1)return i}}catch(c){}}function Yt(e){let t={};for(let n of Array.from(e.attributes))n.name.startsWith("data-")&&(t[n.name]=n.value);return t}var He=new Set(ze);function Qt(e){let t=e.getAttribute("data-sentient-type");if(t&&He.has(t))return t;let n=e.getAttribute("role");return n&&He.has(n)?n:Ye(e)}function Vt(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e.charCodeAt(n)&4294967295;return(t>>>0).toString(16).padStart(8,"0")}function Ht(e){let t=[],n=e;for(;n;){let o=n.parentElement;if(!o){t.push(n.tagName.toLowerCase());break}let c=Array.prototype.indexOf.call(o.children,n);t.push(`${n.tagName.toLowerCase()}[${c}]`),n=o}return t.reverse().join("/")}function Xt(e){var n;let t=(n=e.getAttribute("data-sentient-id"))!=null?n:e.getAttribute("id");return t||`${e.tagName.toLowerCase()}-${Vt(Ht(e))}`}function Zt(e){let t=0,n=e.parentElement;for(;n;)t++,n=n.parentElement;return t}function Ae(e,t){var o,c,r;let n=e.querySelector(Wt);return{componentId:Xt(e),semanticType:Qt(e),ariaLabel:(o=e.getAttribute("aria-label"))!=null?o:void 0,headingText:(r=(c=n==null?void 0:n.textContent)==null?void 0:c.trim())!=null?r:void 0,isAboveFold:e.getBoundingClientRect().top<window.innerHeight,prominenceScore:t(e),depth:Zt(e),reactComponentName:zt(e),dataAttributes:Yt(e)}}function Xe(e){var r;let t=[],n=new Set,o="__root__",c=new Map;for(let[s,i]of e){let a=s.parentElement,l=o;for(;a;){if(e.has(a)){l=e.get(a);let p=e.get(s),y=`${l}->${p}`;!n.has(y)&&l!==p&&(n.add(y),t.push({fromComponentId:l,toComponentId:p,weight:.6}));break}a=a.parentElement}let g=(r=c.get(l))!=null?r:[];g.push(s),c.set(l,g)}for(let s of c.values()){if(s.length<2)continue;let i=s.length>Qe?s.slice(0,Qe):s;for(let a=0;a<i.length;a++)for(let l=a+1;l<i.length;l++){if(t.length>=qt)return t;let g=e.get(i[a]),p=e.get(i[l]);if(g===p)continue;let y=`${g}->${p}::sib`,d=`${p}->${g}::sib`;n.has(y)||(n.add(y),t.push({fromComponentId:g,toComponentId:p,weight:.3})),n.has(d)||(n.add(d),t.push({fromComponentId:p,toComponentId:g,weight:.3}))}}return t}function en(e){let t=[],n=new Set,o=new Map;return document.querySelectorAll("[data-sentient-id]").forEach(s=>{if(s instanceof Element&&!n.has(s)){n.add(s);let i=Ae(s,e);t.push(i),o.set(s,i.componentId)}}),document.querySelectorAll("section, article, main, aside").forEach(s=>{if(!(s instanceof Element)||n.has(s))return;let i=s.hasAttribute("aria-label"),a=s.hasAttribute("data-sentient-id");if(!i&&!a)return;n.add(s);let l=Ae(s,e);t.push(l),o.set(s,l.componentId)}),{nodes:t,edges:Xe(o),elementToId:o}}function Ze(){if(typeof window=="undefined")return Jt;let e=null,t=0,n=null,o=new Map,c=a=>{try{let l=window.getComputedStyle(a),g=parseFloat(l.fontSize)||12,p=parseFloat(l.zIndex)||0,y=a.getBoundingClientRect(),d=Math.max(y.top,0),h=window.innerHeight||1,b=1/(d/h+1),E=Ve(g,12,48)*.4+b*.4+Ve(p,0,100)*.2;return Math.max(0,Math.min(1,E))}catch(l){return .5}};return{scan:()=>new Promise(a=>{let l=()=>{let{nodes:g,edges:p,elementToId:y}=en(c);o.clear();for(let[d,h]of y)o.set(d,h);a({nodes:g,edges:p,scannedAt:Date.now()})};try{typeof requestIdleCallback=="function"?t=requestIdleCallback(l,{timeout:100}):l()}catch(g){l()}}),observe:a=>{n=a;try{e=new MutationObserver(l=>{let g=[],p=new Set;for(let d of l)d.type==="childList"&&d.addedNodes.forEach(h=>{if(!(h instanceof Element)||!Ft.has(h.tagName))return;let b=h.hasAttribute("data-sentient-id"),E=h.hasAttribute("aria-label");if(!b&&!E)return;let x=Ae(h,c);g.push(x),p.add(x.componentId),o.set(h,x.componentId)});if(g.length===0||!n)return;for(let d of[...o.keys()])d.isConnected||o.delete(d);let y=Xe(o).filter(d=>p.has(d.fromComponentId)||p.has(d.toComponentId));n({nodes:g,edges:y,addedAt:Date.now()})}),e.observe(document.body,{childList:!0,subtree:!0})}catch(l){}},getProminenceScore:c,destroy:()=>{if(e&&(e.disconnect(),e=null),t&&typeof cancelIdleCallback=="function")try{cancelIdleCallback(t)}catch(a){}t=0,n=null,o.clear()}}}var Te="_snt_graph_nodes",et="_snt_graph_edges",tn={pricing:["features","faq"],features:["pricing"],faq:["pricing"],social_proof:["cta"],cta:["social_proof","hero","trust"],hero:["cta"],comparison:["pricing"],trust:["cta"]};function nn(e){var t;return(t=tn[e])!=null?t:[]}function on(e,t){try{let n=localStorage.getItem(e);return n?JSON.parse(n):t}catch(n){return t}}function rn(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch(n){}}var sn=new Set(["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"]);function an(e){return sn.has(e)?e:"generic"}function cn(e,t,n){let o=`${e}:${t}:${n.join(",")}`,c=5381;for(let r=0;r<o.length;r++)c=(c<<5)+c+o.charCodeAt(r)&4294967295;return(c>>>0).toString(16).padStart(8,"0")}function tt(e){let t=new Map,n=new Map,o=()=>{typeof window!="undefined"&&rn(Te,[...t.values()])},c=r=>{var s;try{let i=JSON.parse(r);t.clear();for(let a of(s=i.pageNodes)!=null?s:[])t.set(a.componentId,a)}catch(i){}};if(typeof window!="undefined"){let r=on(Te,[]);for(let s of r)t.set(s.componentId,s);try{localStorage.removeItem(et)}catch(s){}}return{addPageNode(r){t.set(r.componentId,r),o()},addStructuralEdge(r){let s=`${r.fromComponentId}->${r.toComponentId}`;n.set(s,r)},syncOnce(){var s,i;if(!(e!=null&&e.syncUrl)||typeof window=="undefined")return;let r=[...t.values()];if(r.length!==0)try{let a=new Map;for(let d of r){let h=(s=a.get(d.semanticType))!=null?s:[];h.push(d),a.set(d.semanticType,h)}let l=[],g=new Set;for(let d of r)for(let h of nn(d.semanticType)){let b=(i=a.get(h))!=null?i:[];for(let E of b){if(E.componentId===d.componentId)continue;let x=`semantic:${d.componentId}->${E.componentId}`;g.has(x)||(g.add(x),l.push({fromComponentId:d.componentId,toComponentId:E.componentId,type:"semantic",weight:.4,confidence:.9}))}}let p=new Set(r.map(d=>d.componentId));for(let d of n.values()){if(!p.has(d.fromComponentId)||!p.has(d.toComponentId))continue;let h=`structural:${d.fromComponentId}->${d.toComponentId}`;g.has(h)||(g.add(h),l.push({fromComponentId:d.fromComponentId,toComponentId:d.toComponentId,type:"structural",weight:d.weight,confidence:1}))}let y=B(v(v({pageUrl:window.location.href},e.sessionId?{sessionId:e.sessionId}:{}),e.projectId?{projectId:e.projectId}:{}),{nodes:r.map(d=>{let h=an(d.semanticType);return{componentId:d.componentId,semanticType:h,answers:d.answers,contentHash:cn(d.componentId,h,d.answers),prominenceScore:d.prominenceScore,depthInPage:d.depth}}),edges:l});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(a){}},snapshot(){return{pageNodes:[...t.values()],capturedAt:Date.now()}},serialize(){return JSON.stringify({pageNodes:[...t.values()]})},restore:c,destroy(){if(typeof window!="undefined")try{localStorage.removeItem(Te),localStorage.removeItem(et)}catch(r){}}}}var dn="https://api.sentient-ui.com/v1/events";function ln(){try{let e=document.cookie.match(/(?:^|; )_snt_uid=([^;]*)/);return e?decodeURIComponent(e[1]):void 0}catch(e){return}}var fe=new Map;function un(e){var p;let t=Je(e),n=e.respectDoNotTrack!==!1&&xe(),o=e.consent===!1||n;if(!e.graph||!e.apiKey||o||typeof window=="undefined")return t;let c=fe.get(e.apiKey);if(c)try{c()}catch(y){}let r=Ze(),s=(p=e.ingestUrl)!=null?p:dn,i=tt({syncUrl:s.replace(/\/events\/?$/,"/graph/sync"),apiKey:e.apiKey,projectId:e.apiKey,sessionId:ln()});r.scan().then(y=>{for(let d of y.nodes)i.addPageNode({id:d.componentId,componentId:d.componentId,semanticType:d.semanticType,answers:d.headingText?[d.headingText]:[],prominenceScore:d.prominenceScore,depth:d.depth});for(let d of y.edges)i.addStructuralEdge(d);i.syncOnce()});let a=null,l=()=>{a!==null&&clearTimeout(a),a=setTimeout(()=>{a=null,i.syncOnce()},500)};r.observe(y=>{for(let d of y.nodes)i.addPageNode({id:d.componentId,componentId:d.componentId,semanticType:d.semanticType,answers:d.headingText?[d.headingText]:[],prominenceScore:d.prominenceScore,depth:d.depth});for(let d of y.edges)i.addStructuralEdge(d);l()});let g=()=>{a!==null&&(clearTimeout(a),a=null),r.destroy(),i.destroy(),fe.get(e.apiKey)===g&&fe.delete(e.apiKey)};return fe.set(e.apiKey,g),B(v({},t),{getGraph:()=>i.snapshot(),dispose:()=>{g(),t.dispose()},destroy:()=>{g(),t.destroy()}})}0&&(module.exports={deriveSessionSegment,detectDeviceClass,detectTimeOfDay,detectTrafficSource,init,referrerDomainFromReferer});
|
|
2
2
|
//# sourceMappingURL=index-graph.js.map
|