@sentientui/core 0.42.0 → 0.43.0
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/README.md +1 -1
- package/dist/{chunk-QPJ6TL6L.mjs → chunk-5VIREVXA.mjs} +2 -2
- package/dist/chunk-5VIREVXA.mjs.map +1 -0
- package/dist/{index-Bz4QCRmF.d.cts → index-CWHTKETi.d.cts} +9 -1
- package/dist/{index-C36TXfry.d.ts → index-cqfRT6LZ.d.ts} +9 -1
- package/dist/index-engagement.js.map +1 -1
- package/dist/index-engagement.mjs +1 -1
- package/dist/index-graph.d.cts +2 -2
- package/dist/index-graph.d.ts +2 -2
- 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-local.d.cts +1 -1
- package/dist/index-local.d.ts +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-QPJ6TL6L.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ Reading a consent platform yourself: `import { consentWatcher } from '@sentientu
|
|
|
51
51
|
| `sessionSegment` | `string` | Segment from SSR (`device:source`). Must match the value used in `preloadAssignments`. |
|
|
52
52
|
| `ssrSessionId` | `string` | Session ID minted during SSR (from `readSessionCookie`) so server and client share one session. |
|
|
53
53
|
| `userId` | `string` | Optional cross-session identity. Persists portraits across sessions for the same user. |
|
|
54
|
-
| `persona` | `string` | Declared persona — the role your app already knows for this visitor (e.g. `'admin'`, `'evaluator'`). Must be a key in the project's persona vocabulary (dashboard →
|
|
54
|
+
| `persona` | `string` | Declared persona — the role your app already knows for this visitor (e.g. `'admin'`, `'evaluator'`). Must be a key in the project's persona vocabulary (dashboard → Audiences); unrecognized values are ignored server-side and surfaced in the dashboard so you can add them. Served at full confidence, overriding the inferred persona. Keep it a low-cardinality role label — never a user id or email. |
|
|
55
55
|
| `country` | `string` | ISO 3166-1 alpha-2 country code, if you already know it server-side. |
|
|
56
56
|
| `internal` | `boolean \| () => boolean` | Your own team or a test site: served normally, left out of reports and learning. A function is called once, at init. See [Excluding your team and test sites](#excluding-your-team-and-test-sites). |
|
|
57
57
|
| `debug` | `boolean` | Logs events to the console and exposes `window.__sentient`. |
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as Ke,b as pe,c as ge,e as ie,f as Ee,g as Ne,h as Dt,i as Pt,j as Bt,k as Lt,l as Mt,m as Ge}from"./chunk-JNQY3XNF.mjs";import{a as Kt,e as Ce}from"./chunk-LCYGZNFI.mjs";import{b as $e,i as je,j as Ue,k as We,m as Fe,n as Ve,q as He,r as xe,t as ze}from"./chunk-3HMJERH4.mjs";import{a as ve,d as Ot,e as we}from"./chunk-WUFFNQHQ.mjs";import{a as v,b as te}from"./chunk-TMCGHANO.mjs";var qe;function Je(e){qe=typeof e=="string"&&e!==""?e:void 0}function Nt(e=document){if(qe)return qe;try{let s=e.querySelector("script[nonce]");return(s==null?void 0:s.nonce)||(s==null?void 0:s.getAttribute("nonce"))||void 0}catch(s){return}}function Xe(e,s=document){let g=Nt(s);return g&&e.setAttribute("nonce",g),e}var on=1800*1e3;function Ie(e,s){return`${encodeURIComponent(e)}:${encodeURIComponent(s)}`}function Gt(e=on,s){let g=new Map,b=`_snt_asgn${ve(s)}_`,x=(a,i)=>`${b}${encodeURIComponent(a)}:${encodeURIComponent(i)}`,m=a=>{let i=a.slice(b.length),l=i.indexOf(":");if(l<0)return null;try{return{componentId:decodeURIComponent(i.slice(0,l)),segment:decodeURIComponent(i.slice(l+1))}}catch(w){return null}},_=()=>{try{let a=[];for(let i=0;i<localStorage.length;i++){let l=localStorage.key(i);l!=null&&l.startsWith(b)&&a.push(l)}return a}catch(a){return[]}},n=a=>a.assignedAt+(a.ttlMs&&a.ttlMs>0?a.ttlMs:e)<Date.now();return typeof window!="undefined"&&(()=>{for(let a of _())try{let i=localStorage.getItem(a);if(!i)continue;let l=JSON.parse(i);if(n(l)){localStorage.removeItem(a);continue}let w=m(a);if(!w)continue;g.set(Ie(w.componentId,w.segment),l)}catch(i){}})(),{get(a,i){let l=g.get(Ie(a,i));return l?n(l)?(g.delete(Ie(a,i)),null):l:null},set(a,i,l){let w=Ie(a,i);g.set(w,l);try{localStorage.setItem(x(a,i),JSON.stringify(l))}catch(A){}},clear(){g.clear();for(let a of _())try{localStorage.removeItem(a)}catch(i){}}}}import{STAGE_KEYS as sn}from"@sentientui/policy";var Ye="data-sentient-stage";function Qe(e,s){return!s||typeof e!="string"||!(e==="returning"||sn.includes(e))?null:s!=="detailed"&&(e==="customer"||e==="lapsed")?"returning":e}function Ze(e,s=document){try{e?s.documentElement.setAttribute(Ye,e):s.documentElement.removeAttribute(Ye)}catch(g){}}import{confidenceBand as Ht}from"@sentientui/policy";import{confidenceBand as et}from"@sentientui/policy";var tt="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",jt="[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.",$t=!1,_e=!1;function rn(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(s){return}}function Ut(e){var a;let s=Ce({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),g=(a=s.getSessionId())!=null?a:"local",b=rn(),x=import("@sentientui/core/local").then(i=>{let l=i;return l.LOCAL_ENGINE_AVAILABLE?($t||($t=!0,console.info(jt)),l):(_e||(_e=!0,console.error(tt)),null)}).catch(()=>(_e||(_e=!0,console.error(tt)),null)),m=null,_={low:.15,medium:.5,high:.85},n=(()=>{var l;if(e.initialPersona)return v({},e.initialPersona);let i=pe(e.apiKey||"local");return i?{persona:i.persona,confidence:(l=_[i.band])!=null?l:.15}:null})();function u(i){let l=document.documentElement;l.dataset.sentientPersona===void 0&&(l.dataset.sentientPersona=i.persona,l.dataset.sentientConfidence=et(i.confidence))}return{isLocal:!0,async decide(i){var A,L,K;let l=await x;if(!l)return null;let w=l.createLocalEngine({sessionId:g,forcedPersona:b}).decide(i);return m=te(v({},w),{layoutOrder:(L=(A=w.layoutOrder)!=null?A:m==null?void 0:m.layoutOrder)!=null?L:null,slots:v(v({},(K=m==null?void 0:m.slots)!=null?K:{}),w.slots)}),ge(e.apiKey||"local",{v:1,persona:m.persona,band:et(m.confidence),slots:m.slots,layoutOrder:m.layoutOrder,savedAt:Date.now()}),u(w),w},getSlotResult(i){var l,w,A;return(A=(w=m==null?void 0:m.slots[i])!=null?w:(l=e.initialSlots)==null?void 0:l[i])!=null?A:null},getSlotConfig(i){var l,w;return(w=(l=e.initialSlotConfig)==null?void 0:l[i])!=null?w:null},getSitePalette(){var i;return(i=e.initialPalette)!=null?i:null},reportSlots(){},getVisitorId:()=>null,getPersona(){let i=m!=null?m:n;return i?{persona:i.persona,confidence:i.confidence,band:et(i.confidence)}:null},async assign(i,l){var L;let w=await x;return!w||!l||l.length===0?l!=null&&l[0]?{variantId:l[0],assignmentTtlMs:0}:null:{variantId:(L=w.createLocalEngine({sessionId:g,forcedPersona:b}).decide({components:[{id:i,variantIds:l}]}).assignments[i])!=null?L:l[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),flush:()=>{},dispose:()=>{},destroy:()=>s.destroy()}}var Wt=/^(\*|\/[^\s?#*]*(\/\*)?)$/;function nt(e){let s=e.split(/[?#]/)[0]||"/";return s.length>1?s.replace(/\/+$/,"")||"/":s}function an(e,s){if(e===void 0||!Wt.test(e))return!1;if(e==="*")return!0;let g=nt(s);if(e.endsWith("/*")){let b=nt(e.slice(0,-2));return g.startsWith(b==="/"?"/":`${b}/`)&&g!==b}return g===nt(e)}function ln(e,s){if(!e)return!1;if(e==="/")return s==="/";let g=e.endsWith("/")?e.slice(0,-1):e;return s===g||s.startsWith(`${g}/`)}function cn(e){if(!/^https?:\/\//i.test(e))return e;try{return new URL(e).pathname||"/"}catch(s){return e}}var Ln=["none","sm","md","lg"],Mn=["start","center","end","stretch"],Kn=["start","center","end","between"],Nn=["sm","md","lg"],Gn=["normal","medium","bold"],$n=["default","muted","accent"],jn=["primary","secondary","ghost"],Un=["left","center","right"],Wn=["auto","square","landscape","wide"],Fn=["cover","contain"],Vn=[2,3,4],Hn=[1,2,3,4],zn=["default","raised"],qn=["none","sm","md","lg"],Jn=["measure"],Xn=["input","textarea","select"],Yn=["text","email","number","tel"],Qn=5,Zn=8,eo=64,to=5,no=12,oo=4,so=500;function dn(e){if(e==null||typeof e!="object"||Array.isArray(e))return!1;let s=e;return s.type==="form"?!0:Array.isArray(s.children)?s.children.some(dn):!1}var ot="sentient-reveal",ae="sentient-revealed",Ft=240,Re=!1;function un(){var e;Re=!1,typeof document!="undefined"&&((e=document.getElementById(ot))==null||e.remove())}function pn(e){if(Re||e.getElementById(ot)){Re=!0;return}let s=Xe(e.createElement("style"),e);s.id=ot,s.textContent=`@media (prefers-reduced-motion: no-preference){@keyframes ${ae}{from{opacity:.55;transform:translateY(2px)}to{opacity:1;transform:none}}.${ae}{animation:${ae} ${Ft}ms cubic-bezier(.2,.6,.2,1) both}}`,e.head.appendChild(s),Re=!0}function gn(e,s={}){var x;let g=(x=s.doc)!=null?x:typeof document!="undefined"?document:void 0;if(!g||!(e instanceof Element)||(s.arm!==void 0&&e.setAttribute("data-sentient-arm",s.arm),s.persona!==void 0&&e.setAttribute("data-sentient-persona",s.persona),s.previous!==void 0&&s.previous===e.textContent))return!1;pn(g),e.classList.remove(ae),e.offsetWidth,e.classList.add(ae);let b=()=>{e.classList.remove(ae),e.removeEventListener("animationend",b)};return e.addEventListener("animationend",b),!0}function fn(e,s,g,b){let x=[];{let n=!1,u=[],a=()=>{if(n)return;let i=Date.now();for(u.push(i);u.length>0&&i-u[0]>500;)u.shift();u.length>=3&&(n=!0,e("rage_click"))};s.addEventListener("click",a),x.push(()=>s.removeEventListener("click",a))}{let m=!1,_=n=>{if(m||!(n.target instanceof Node)||!s.contains(n.target)&&s!==n.target)return;m=!0;let u=typeof window!="undefined"?window.getSelection():null,a=u?u.toString().length:0;e("text_copy",{selectionLength:a})};document.addEventListener("copy",_),x.push(()=>document.removeEventListener("copy",_))}{let m=!1,_=!1,n=null,u=()=>{n!==null&&(clearTimeout(n),n=null)},a=()=>{m||!_||(u(),n=setTimeout(()=>{!m&&_&&(m=!0,e("scroll_hesitation"))},3e3))},i=()=>{u(),a()},l=A=>{for(let L of A)_=L.intersectionRatio>.3,_?a():u()},w=new IntersectionObserver(l,{threshold:[.3]});w.observe(s),window.addEventListener("scroll",i,{passive:!0}),x.push(()=>{w.disconnect(),window.removeEventListener("scroll",i),u()})}if((b==null?void 0:b.tabLoss)!==!1){let m=!1,_=g!=null?g:Date.now(),n=()=>{if(m||document.visibilityState!=="hidden")return;let u=Date.now()-_;u<15e3&&(m=!0,e("tab_loss",{timeOnPage:u}))};document.addEventListener("visibilitychange",n),x.push(()=>document.removeEventListener("visibilitychange",n))}return()=>{for(let m of x)m()}}function mn(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}var Jt="https://api.sentient-ui.com/v1/events",zt=()=>import("@sentientui/core/internal-traffic"),F=new Map,Xt=null;function Go(e,s){let g=F.get(e);g&&g.upgrade&&(g.reinit=s)}function yn(e){return"value"in e||"currency"in e||"externalId"in e||"metadata"in e||"weight"in e||"stepIndex"in e}var Sn=3;function rt(){return Kt()}function Ae(){var e;if(typeof window!="undefined")return((e=window.location)==null?void 0:e.pathname)||void 0}function hn(){let e=new WeakMap,s=new Map,g=!1,b=(n,u,a)=>{let i=n.get(u);return a===null?i?!0:(n.set(u,new Set),!1):i?i.has(a)?!0:(i.add(a),!1):(n.set(u,new Set([a])),!1)},x=typeof window!="undefined"&&"event"in window,m=()=>{if(!x)return;let n=window.event;return typeof Event=="function"&&n instanceof Event?n:void 0},_=()=>{if(x){Promise.resolve().then(()=>{g=!1,s.clear()});return}let n=!1,u=()=>{n||(n=!0,g=!1,s.clear())};if(setTimeout(u,0),typeof MessageChannel=="function"){let a=new MessageChannel;a.port1.onmessage=()=>{a.port1.close(),a.port2.close(),u()},a.port2.postMessage(0)}};return{firedBefore(n,u){let a=m();if(a){let l=e.get(a);return l||(l=new Map,e.set(a,l)),b(l,n,u)}let i=b(s,n,u);return!i&&!g&&(g=!0,_()),i}}}var Yt=new Set;function kn(e,s,g){let b=typeof window=="undefined"?null:window.history;if(!b)return()=>{};let x=!1,m,_=()=>{if(x)return;let a=Ae();!a||a===m||(m=a,e.track({projectId:s,componentId:"__page__",eventType:"pageview",payload:{}}),g(`${s}:${a}`))},n=[];for(let a of["pushState","replaceState"]){let i=b[a],l=function(...w){let A=i.apply(this,w);return _(),A};b[a]=l,n.push([a,i,l])}window.addEventListener("popstate",_);let u=Ae();return u&&Yt.has(`${s}:${u}`)?m=u:_(),()=>{if(!x){x=!0,window.removeEventListener("popstate",_);for(let[a,i,l]of n)b[a]===l&&(b[a]=i)}}}var fe={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,assign:()=>Promise.resolve(null),decide:()=>Promise.resolve(null),getSlotResult:()=>null,getSlotConfig:()=>null,getSitePalette:()=>null,reportSlots:()=>{},getPersona:()=>null,getVisitorId:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),flush:()=>{},dispose:()=>{},destroy:()=>{}};function bn(){try{return Fe(window.location.search)}catch(e){return{utmParams:{},clickIds:{}}}}function Qt(e){return e.replace(/\/events\/?$/,"")}function Zt(){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(s=>s==="1"||s==="yes")}function $o(e){var u;if(typeof window=="undefined")return;let s=e!=null?e:Xt;if(!s){console.warn("[sentient] grantConsent() called before init()");return}let g=F.get(s);if(!g){console.warn("[sentient] grantConsent() called before init()");return}let{config:b,upgrade:x,reinit:m}=g;if(!x){g.upgradeBlockedReason&&console.warn(g.upgradeBlockedReason);return}if(b.respectDoNotTrack!==!1&&Zt())return;let _=(m!=null?m:wn)(te(v({},b),{consent:!0}));x(_);let n=(u=F.get(s))==null?void 0:u.dispose;F.set(s,{config:te(v({},b),{consent:!0}),upgrade:null,dispose:n})}function vn(e,s){var ye;let g=e.preConsentBehavior==="statistical_winner",b=Qt((ye=e.ingestUrl)!=null?ye:Jt),x={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},m=new Map,_=new Map,n={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),assign(r,c,E){if(!g)return Promise.resolve(null);let T=m.get(r);return T?Promise.resolve(T):at(_,r,async()=>{try{let I=new URLSearchParams({componentId:r});for(let q of c!=null?c:[])I.append("variantIds[]",q);let G=ie(5e3),W;try{let q=await fetch(`${b}/winner?${I.toString()}`,{headers:x,signal:G.signal});if(!q.ok)return c!=null&&c[0]?{variantId:c[0],assignmentTtlMs:0}:null;W=await q.json()}finally{G.clear()}let $={variantId:W.variantId,assignmentTtlMs:0};return m.set(r,$),$}catch(I){return c!=null&&c[0]?{variantId:c[0],assignmentTtlMs:0}:null}})},decide:()=>Promise.resolve(null),getSlotResult:()=>null,getSlotConfig:()=>null,getSitePalette:()=>null,reportSlots:()=>{},getPersona:()=>null,getVisitorId:()=>null,getGraph:()=>({pageNodes:[],capturedAt:0}),flush:()=>{},dispose:()=>{},destroy:()=>{}},u=!1,a=new Set,i=[],l=[],w=[],A=()=>{for(let[,,r]of w.splice(0))r(null);L.length=0},L=[],K=!1,ee=()=>{if(u)return;K=!0;let r=F.get(e.apiKey);(r==null?void 0:r.upgrade)===le&&F.set(e.apiKey,{config:e,upgrade:null,upgradeBlockedReason:"[sentient] grantConsent(): client released before consent; call init() again"})},N=[],V=()=>{setTimeout(()=>{var r;try{(r=N.shift())==null||r(n)}catch(c){}N.length&&V()})},me=r=>{u?N.length?N.push(r):r(n):!s&&!K&&L.length<100?L.push(r):K&&e.debug&&console.warn("[sentient] goal dropped: client released")},se={get gated(){return!u&&!s},get released(){return K&&!u},takeHeld:()=>L.splice(0),track:r=>n.track(r),goal:((r,c,E,T)=>me(I=>I.goal(r,c,E,T))),componentGoal:(r,c,E)=>n.componentGoal(r,c,E),identify:(r,c)=>n.identify(r,c),getAssignment:(r,c)=>n.getAssignment(r,c),isUnified:r=>{var c,E;return(E=(c=n.isUnified)==null?void 0:c.call(n,r))!=null?E:!1},assign:(r,c,E,T,I)=>n.assign(r,c,E,T,I),decide:r=>u?n.decide(r):K||s?Promise.resolve(null):new Promise(c=>w.push([r,qt(),c])),getSlotResult:r=>n.getSlotResult(r),isSlotDecided:r=>{var c,E;return(E=(c=n.isSlotDecided)==null?void 0:c.call(n,r))!=null?E:!0},getSlotConfig:r=>n.getSlotConfig(r),getSitePalette:()=>n.getSitePalette(),getStyleVocabulary:()=>{var r,c;return(c=(r=n.getStyleVocabulary)==null?void 0:r.call(n))!=null?c:null},reportSlots:(r,c,E,T)=>n.reportSlots(r,c,E,T),reportSkeleton:(r,c)=>{var E;return(E=n.reportSkeleton)==null?void 0:E.call(n,r,c)},reportAgentData:(r,c,E)=>{var T;return(T=n.reportAgentData)==null?void 0:T.call(n,r,c,E)},reportDrift:(r,c,E,T)=>{var I;return(I=n.reportDrift)==null?void 0:I.call(n,r,c,E,T)},requestSlots:(r,c,E)=>{var T;return u?(T=n.requestSlots)==null?void 0:T.call(n,r,c,E):i.push([r,c,E])},decideSlots:r=>{var c;return u?(c=n.decideSlots)==null?void 0:c.call(n,r):l.push(...r)},cancelSlots:r=>{var E;if(u)return(E=n.cancelSlots)==null?void 0:E.call(n,r);let c=new Set(r);for(let T of i)T[0]=T[0].filter(I=>!c.has(I));l=l.filter(T=>!c.has(T.id))},onSlotsChanged:r=>(a.add(r),()=>{a.delete(r)}),getPersona:()=>n.getPersona(),getVisitorId:()=>{var r,c;return(c=(r=n.getVisitorId)==null?void 0:r.call(n))!=null?c:null},fetchWeights:()=>n.fetchWeights(),getGraph:()=>n.getGraph(),flush:()=>n.flush(),dispose:()=>(ee(),A(),n.dispose()),destroy:()=>(ee(),A(),u?n.destroy():Ge(e.apiKey))};function le(r){var E,T,I;n=r,u=!0,L.length&&(N.push(...L.splice(0)),V());let c=qt();for(let[G,W,$]of w.splice(0))W!==c?$(null):r.decide(G).then($,()=>$(null));(E=r.onSlotsChanged)==null||E.call(r,()=>a.forEach(G=>G()));for(let[G,W,$]of i.splice(0))G.length>0&&((T=r.requestSlots)==null||T.call(r,G,W,$));l.length>0&&((I=r.decideSlots)==null||I.call(r,l.splice(0)))}return{proxy:se,setInner:le}}function qt(){return typeof location=="undefined"?"":location.pathname+(/^#!?\//.test(location.hash)?location.hash:"")}function at(e,s,g){let b=e.get(s);if(b)return b;let x=(async()=>{try{return await g()}finally{e.delete(s)}})();return e.set(s,x),x}function wn(e){var ht,kt,bt,vt,wt,Et,Ct,xt,It,_t,Rt;if(typeof window=="undefined")return fe;e.nonce&&Je(e.nonce),Xt=e.apiKey||"local";let s=F.get(e.apiKey||"local");if(s!=null&&s.dispose)try{s.dispose()}catch(t){}let g=e.respectDoNotTrack!==!1&&Zt(),b=e.consent===!1||g,x=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!x&&e.localMode!==!1)return F.set(e.apiKey||"local",{config:e,upgrade:null,upgradeBlockedReason:"[sentient] grantConsent(): this client is keyless/local \u2014 there is no hosted client to upgrade to. Configure a pk_ API key to enable tracking."}),b?fe:Ut(e);if(b){if(!e.apiKey||!e.apiKey.startsWith("pk_"))return e.preConsentBehavior==="statistical_winner"&&console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),F.set(e.apiKey||"local",{config:e,upgrade:null,upgradeBlockedReason:"[sentient] grantConsent(): the client was initialized with an invalid apiKey (expected a pk_ public key) \u2014 consent cannot enable tracking."}),fe;let{proxy:t,setInner:o}=vn(e,g);return F.set(e.apiKey,{config:e,upgrade:g?null:o}),t}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."),fe;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),fe;let m=(ht=e.ingestUrl)!=null?ht:Jt,_=Date.now(),n=Ce({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey,cookieDomain:e.cookieDomain}),u={},a;try{/sentient_internal=/.test(location.search+document.cookie)&&(a=zt().then(async t=>{u.internalToken=await t.takeInternalToken(n.domain)||void 0}).catch(()=>{})),(typeof e.internal=="function"?e.internal():e.internal)===!0&&(u.internal=!0)}catch(t){}let i=Gt(void 0,e.apiKey),l=!1,w=we(e.apiKey),A=()=>!l&&we(e.apiKey)===w,L=new Set((kt=e.initialUnified)!=null?kt:[]),K=te(v({},i),{get:(t,o)=>L.has(t)?null:i.get(t,o),set:(...t)=>{A()&&i.set(...t)}}),ee=Bt({ingestUrl:m,apiKey:e.apiKey}),N=Qt(m),V={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},me=new Set,se=Mt({url:`${N}/goals`,apiKey:e.apiKey,headers:V,onDrop:(t,o)=>{if(!e.debug){if(me.has(o))return;me.add(o)}console.warn(`[sentient] goal dropped (HTTP ${o}) \u2014 this will not be retried. `+(o===400?"The session was not found: call init() and let the session upsert complete before firing goals.":o===401||o===403?"Check the API key and that this origin is on the project allowlist.":"See the response status for the cause."),t)}}),le=je((bt=navigator.userAgent)!=null?bt:""),ye=window.location.origin,r=Ue((vt=document.referrer)!=null?vt:"",ye,n.domain),c=(wt=e.sessionSegment)!=null?wt:`${le}:${r}`,E=new Map,T=new Map,I=new Map,G=new Set,W=new Map,$=null,q=null,j=null,lt=new Set,Se=new Set,Te=new Map,Oe=new Map,ct=new Set,dt=new Set,ut=new Set,pt=new Set,De=null,ce=/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/,gt=new Set,he=new Set,ke=new Set,de=new Map,Pe=null,be=new Set,ue=new Map,Be=null,en=2,ft=new Map,X=!1,mt=(t,o,d)=>{var p;let S=new Set,k=1;for(let f of t){o.delete(f);let y=((p=ft.get(f))!=null?p:0)+1;ft.set(f,y),y<=en&&(S.add(f),y>k&&(k=y))}S.size>0&&setTimeout(()=>{X||d(S)},Ne(k))},Le=t=>{for(let o of t)I.has(o.id)||I.set(o.id,xe(o))};if(e.initialSlots)for(let[t,o]of Object.entries(e.initialSlots))I.set(t,o),G.add(t);if(e.initialSlotConfig)for(let[t,o]of Object.entries(e.initialSlotConfig))W.set(t,o);e.initialPalette&&($=e.initialPalette),e.initialVocabulary&&(q=e.initialVocabulary);let Y=pe(e.apiKey);if(Y){for(let[t,o]of Object.entries(Y.slots))I.has(t)||I.set(t,o);for(let[t,o]of Object.entries((Et=Y.slotConfig)!=null?Et:{}))W.has(t)||W.set(t,o);!$&&Y.palette&&($=Y.palette),!q&&Y.vocabulary&&(q=Y.vocabulary)}let yt={low:.15,medium:.5,high:.85};if(e.initialPersona)j=v({},e.initialPersona);else{let t=document.documentElement.dataset;t.sentientPersona?j={persona:t.sentientPersona,confidence:(xt=yt[(Ct=t.sentientConfidence)!=null?Ct:"low"])!=null?xt:.15}:Y&&(j={persona:Y.persona,confidence:(It=yt[Y.band])!=null?It:.15})}if(e.initialAssignments)for(let[t,o]of Object.entries(e.initialAssignments))K.set(t,c,{variantId:o,assignedAt:Date.now(),segment:c,confidence:1});let ne=Promise.resolve(),St=n.getSessionId();if(St){let t=We((_t=document.referrer)!=null?_t:""),{utmParams:o,clickIds:d}=bn(),S=v(v(v(v({sessionId:St,deviceClass:le,trafficSource:r,referrerDomain:t,utmParams:o,clickIds:d,landingPath:typeof location!="undefined"?location.pathname:void 0,timeOfDay:Ve(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:n.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||$e((Rt=navigator.userAgent)!=null?Rt:"")},e.userId?{userId:e.userId}:{}),e.persona?{persona:e.persona}:{}),e.country?{country:e.country}:{}),e.sdk?{sdk:e.sdk.name,sdkVersion:e.sdk.version}:{}),k=async()=>{a&&await Ee(a,2500);for(let p=0;;p++){if(X||!A())return;let f=ie(5e3);try{let y=await fetch(`${N}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(Object.assign(S,u)),headers:V,signal:f.signal});if(y.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");return}if(y.ok||Dt(y)==="dropped")return}catch(y){}finally{f.clear()}if(p>=Sn){console.warn("[SentientUI] Could not register the session after retries. Conversions in this visit may not be recorded.");return}await new Promise(y=>setTimeout(y,Ne(p+1)))}};try{ne=k()}catch(p){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:ee});let tn=hn(),oe=null,Me=!1,M={goal(t,o={},d=1,S=0){var B,R,H,J,z,U,h;let k=n.getSessionId();if(!k||X||!A())return;let p=yn(o)?o:{metadata:o},f=[t,(B=p.externalId)!=null?B:"",(R=p.stepIndex)!=null?R:S,(H=p.weight)!=null?H:d].join("\0"),y=p.value!==void 0?`${p.value}\0${(J=p.currency)!=null?J:""}`:null;if(tn.firedBefore(f,y)){e.debug&&console.log(`[sentient] goal("${t}") already recorded for this action \u2014 not sent twice`);return}let O=rt(),C={sessionId:k,name:t,metadata:(z=p.metadata)!=null?z:{},weight:(U=p.weight)!=null?U:d,stepIndex:(h=p.stepIndex)!=null?h:S,goalId:O,value:p.value,currency:p.currency,externalId:p.externalId};e.debug&&console.log("[sentient] goal",C);let D={id:O,body:JSON.stringify(C)};ne.then(()=>se.send(D))},componentGoal(t,o,d){var O,C,D;let S=n.getSessionId();if(!S||X||!A())return;let k=K.get(t,c),p=k?null:(O=I.get(t))!=null?O:null;if(!k&&p===null){e.debug&&console.warn(`[sentient] componentGoal("${t}"): no assignment or slot decision yet \u2014 render its <Adaptive>/adaptive hook or call assign()/decide() before recording a goal.`);return}if(!k&&!G.has(t)){e.debug&&console.warn(`[sentient] componentGoal("${t}"): slot not decided this session \u2014 not attributed`);return}let f=k?k.variantId:ze(p),y={id:rt(),sessionId:S,projectId:e.apiKey,componentId:t,variantId:f,eventType:"goal_achieved",goalType:o,payload:v({reward:(C=d==null?void 0:d.reward)!=null?C:1,goalValue:d==null?void 0:d.value,currency:d==null?void 0:d.currency},(D=d==null?void 0:d.metadata)!=null?D:{}),timestamp:Date.now(),timeInSession:Date.now()-_,path:Ae()};e.debug&&console.log("[sentient] componentGoal",y),ne.then(()=>{!X&&A()&&ee.push(y)})},identify(t,o){let d=n.getSessionId();if(!d||X||!A())return;let S=(o==null?void 0:o.email)!==void 0?zt().then(k=>k.emailFields(o.email)).catch(()=>({})):{};Promise.all([ne,S]).then(([,k])=>{fetch(`${N}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(te(v(v({sessionId:d,userId:t,userHash:o==null?void 0:o.userHash},k),u),{ephemeral:n.isEphemeral()})),headers:V}).catch(()=>{})})},track(t){let o=n.getSessionId();if(!o||X||!A()||t.eventType==="variant_assigned"&&I.get(t.componentId)!==void 0&&!G.has(t.componentId)&&!K.get(t.componentId,c))return;let d=te(v({path:Ae()},t),{id:rt(),sessionId:o,timestamp:Date.now(),timeInSession:Date.now()-_});e.debug&&console.log("[sentient] track",d),ne.then(()=>ee.push(d))},getAssignment(t,o){return K.get(t,o)},isUnified:t=>L.has(t),async assign(t,o,d,S,k){var O;let p=n.getSessionId();if(!p)return null;let f=(k==null?void 0:k.unified)===!0;if(f&&L.has(t))return{variantId:(O=o==null?void 0:o[0])!=null?O:"",assignmentTtlMs:0,unified:!0};let y=K.get(t,c);if(y&&(o!=null&&o.length||y.content!==void 0)){let C=y.ttlMs&&y.ttlMs>0?Math.max(0,y.assignedAt+y.ttlMs-Date.now()):0;return{variantId:y.variantId,assignmentTtlMs:C,content:y.content}}return at(E,f?`${t}\0unified`:t,async()=>{if(!await Ee(ne,2500)||X||!A())return null;let C=ie(3e4);try{let D={sessionId:p,componentId:t,variantIds:o};S!==void 0?D.agentDataByVariant=S:d!==void 0&&(D.agentData=d),f&&(D.caps={unified:!0});let B=await fetch(`${N}/assign`,{method:"POST",body:JSON.stringify(D),headers:V,signal:C.signal});if(!B.ok)return null;let R=await B.json();return R.unified===!0?f?(L.add(t),{variantId:R.variantId,assignmentTtlMs:0,unified:!0}):null:(K.set(t,c,v({variantId:R.variantId,assignedAt:Date.now(),segment:c,confidence:1,content:R.content},R.assignmentTtlMs&&R.assignmentTtlMs>0?{ttlMs:R.assignmentTtlMs}:{})),R)}catch(D){return null}finally{C.clear()}})},async decide(t){var p,f;let o=n.getSessionId();if(!o)return null;let d=(p=t.slots)!=null?p:[],S={sessionId:o};t.sections&&t.sections.length>0&&(S.sections=t.sections.map(y=>({id:y}))),S.components=(f=t.components)!=null?f:[],d.length>0&&(S.slots=d.map(He)),t.slotsFrom==="registry"&&(S.slotsFrom="registry",t.registrySlotIds&&(S.registrySlotIds=t.registrySlotIds),t.bootstrap===!1&&(S.bootstrap=!1),t.render&&Object.keys(t.render).length>0&&(S.render=t.render)),t.v&&(S.v=t.v),typeof t.pp=="number"&&(S.pp=t.pp),e.persona&&(S.persona=e.persona),Object.assign(S,u);let k=JSON.stringify(S);return at(T,k,async()=>{var O,C,D,B,R,H,J,z;if(!await Ee(ne,2500)||X||!A())return Le(d),null;let y=ie(3e4);try{let U=await fetch(`${N}/decide`,{method:"POST",body:k,headers:V,signal:y.signal});if(!U.ok)return Le(d),null;let h=await U.json(),Q=Qe(h.stage,e.stageAttributes);e.stageAttributes&&Ze(Q);let re={};for(let P of d){let Z=(O=h.slots)==null?void 0:O[P.id];if(Z!==void 0){re[P.id]=Z,I.set(P.id,Z),G.add(P.id);continue}let At=I.get(P.id);if(At!==void 0)re[P.id]=At;else{let Tt=xe(P);re[P.id]=Tt,I.set(P.id,Tt)}}if(h.slots)for(let[P,Z]of Object.entries(h.slots))P in re||(re[P]=Z,I.set(P,Z),G.add(P));let nn=j!=null&&j.persona!=="unknown";h.persona&&!(h.persona==="unknown"&&nn)?j={persona:h.persona,confidence:(C=h.confidence)!=null?C:0}:j||(j={persona:"unknown",confidence:0});for(let[P,Z]of Object.entries((D=h.assignments)!=null?D:{}))K.set(P,c,{variantId:Z,assignedAt:Date.now(),segment:c,confidence:1});if(h.slotConfig)for(let[P,Z]of Object.entries(h.slotConfig))W.set(P,Z);h.palette&&($=h.palette),h.vocabulary&&(q=h.vocabulary);for(let P of(B=t.registrySlotIds)!=null?B:[])(R=h.slotConfig)!=null&&R[P]||(W.delete(P),I.delete(P),G.delete(P));return A()&&ge(e.apiKey,v(v(v(v({v:1,persona:j.persona,band:Ht(j.confidence),slots:Object.fromEntries(I),layoutOrder:(H=h.layoutOrder)!=null?H:null,savedAt:Date.now()},W.size>0?{slotConfig:Object.fromEntries(W)}:{}),$?{palette:$}:{}),q?{vocabulary:q}:{}),Q?{stage:Q}:{})),v(v(v(v(v(v(v({layoutOrder:(J=h.layoutOrder)!=null?J:null,assignments:(z=h.assignments)!=null?z:{},slots:re,persona:j.persona,confidence:j.confidence},h.slotConfig?{slotConfig:h.slotConfig}:{}),h.goals?{goals:h.goals}:{}),h.sectionMap?{sectionMap:h.sectionMap}:{}),h.palette?{palette:h.palette}:{}),h.vocabulary?{vocabulary:h.vocabulary}:{}),h.stage?{stage:h.stage}:{}),h.context?{context:h.context}:{})}catch(U){return Le(d),null}finally{y.clear()}})},getSlotResult(t){var o;return(o=I.get(t))!=null?o:null},isSlotDecided(t){return G.has(t)},getSlotConfig(t){var o;return(o=W.get(t))!=null?o:null},reportSlots(t,o,d,S){var p;let k={};for(let[f,y]of Object.entries(S!=null?S:{}))for(let O of y){let C=`${f}|${O.key}`;!ce.test(f)||ut.has(C)||(ut.add(C),((p=k[f])!=null?p:k[f]=[]).push(O))}Object.keys(k).length>0&&fetch(`${N}/slots/observed`,{method:"POST",headers:V,body:JSON.stringify({slotIds:Object.keys(k),authoredArms:k})}).catch(()=>{});for(let f of t)if(!(typeof f!="string"||f.length===0)){if(!ce.test(f)){mn()&&!gt.has(f)&&(gt.add(f),console.warn(`[sentient] reportSlots: slot id ${JSON.stringify(f)} will not register \u2014 ids must start with a letter or digit and contain only letters, digits, '_' or '-' (max 128 chars): /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/.`));continue}if(!lt.has(f)){lt.add(f),Se.add(f);let y=o==null?void 0:o[f];if(typeof y=="string"){let C=y.replace(/\s+/g," ").trim().slice(0,400);C!==""&&Te.set(f,C)}let O=d==null?void 0:d[f];O!==void 0&&Oe.set(f,O)}}Se.size===0||De!=null||(De=setTimeout(()=>{De=null;let f=[...Se];Se.clear();for(let y=0;y<f.length;y+=20){let O=f.slice(y,y+20),C={},D={};for(let B of O){let R=Te.get(B);R!==void 0&&(C[B]=R,Te.delete(B));let H=Oe.get(B);H!==void 0&&(D[B]=H,Oe.delete(B))}fetch(`${N}/slots/observed`,{method:"POST",headers:V,body:JSON.stringify(v(te(v(v({slotIds:O},Object.keys(C).length>0?{baselineTexts:C}:{}),Object.keys(D).length>0?{baselineSkeletons:D}:{}),{pagePaths:Object.fromEntries(O.map(B=>[B,location.pathname]))}),Object.keys(C).length>0&&n.getSessionId()?{sessionId:n.getSessionId()}:{}))}).catch(()=>{})}},1e3))},reportSkeleton(t,o){!ce.test(t)||ct.has(t)||(ct.add(t),fetch(`${N}/slots/observed`,{method:"POST",headers:V,body:JSON.stringify({slotIds:[t],baselineSkeletons:{[t]:o}})}).catch(()=>{}))},reportAgentData(t,o,d){let S=`${t}|${o}`;!ce.test(t)||pt.has(S)||(pt.add(S),fetch(`${N}/slots/observed`,{method:"POST",headers:V,body:JSON.stringify(v(v({slotIds:[t],agentData:{[t]:{[o]:d}}},o.startsWith("authored.")?{authoredArms:{[t]:[{key:o.slice(9)}]}}:{}),n.getSessionId()?{sessionId:n.getSessionId()}:{}))}).catch(()=>{}))},reportDrift(t,o,d,S){let k=`${t}|${o}`,p=n.getSessionId();!p||dt.has(k)||(dt.add(k),fetch(`${N}/slots/drift`,{method:"POST",headers:V,body:JSON.stringify({sessionId:p,reports:[{slotId:t,expectedFp:o,observedFp:d,reason:S}]})}).catch(()=>{}))},requestSlots(t,o,d){var S,k;for(let p of t)ke.has(p)||(ke.add(p),ce.test(p)?de.set(p,{text:o==null?void 0:o[p],render:(S=d==null?void 0:d.render)==null?void 0:S[p],skeleton:(k=d==null?void 0:d.skeletons)==null?void 0:k[p]}):M.reportSlots([p]));de.size===0||Pe!=null||(Pe=setTimeout(()=>{Pe=null;let p=[...de];de.clear();for(let f=0;f<p.length;f+=50){let y=p.slice(f,f+50),O={};for(let[C,D]of y)D.render&&(O[C]=D.render);M.decide({slotsFrom:"registry",registrySlotIds:y.map(([C])=>C),bootstrap:!1,render:O}).then(C=>{var D,B;if(C){let R={},H={},J=[];for(let[z,U]of y){let h=(D=C.slotConfig)==null?void 0:D[z];if(h){h.needsSkeleton&&U.skeleton&&((B=M.reportSkeleton)==null||B.call(M,z,U.skeleton));continue}J.push(z),U.text&&(R[z]=U.text),U.skeleton&&(H[z]=U.skeleton)}J.length>0&&M.reportSlots(J,R,H)}else mt(y.map(([R])=>R),ke,R=>{var U;let H={},J={},z={};for(let[h,Q]of y)R.has(h)&&(Q.text&&(H[h]=Q.text),Q.render&&(J[h]=Q.render),Q.skeleton&&(z[h]=Q.skeleton));(U=M.requestSlots)==null||U.call(M,[...R],H,{render:J,skeletons:z})});he.forEach(R=>R())})}},0))},decideSlots(t){for(let o of t)be.has(o.id)||(be.add(o.id),ue.set(o.id,o));ue.size===0||Be!=null||(Be=setTimeout(()=>{Be=null;let o=[...ue.values()];ue.clear();for(let d=0;d<o.length;d+=30){let S=o.slice(d,d+30);M.decide({slots:S}).then(k=>{k||mt(S.map(p=>p.id),be,p=>{var f;return(f=M.decideSlots)==null?void 0:f.call(M,S.filter(y=>p.has(y.id)))}),he.forEach(p=>p())})}},0))},cancelSlots(t){for(let o of t)de.delete(o)&&ke.delete(o),ue.delete(o)&&be.delete(o)},onSlotsChanged(t){return he.add(t),()=>{he.delete(t)}},getStyleVocabulary(){return q},getSitePalette(){return $},getVisitorId:()=>A()?n.getSessionId():null,getPersona(){return j?{persona:j.persona,confidence:j.confidence,band:Ht(j.confidence)}:null},async fetchWeights(){var o;let t=ie(5e3);try{let d=await fetch(`${N}/weights`,{headers:V,signal:t.signal});return d.ok?(o=(await d.json()).components)!=null?o:[]:[]}catch(d){return[]}finally{t.clear()}},getGraph(){return{pageNodes:[],capturedAt:0}},flush(){ee.flush(),se.flush()},dispose(){var t;oe==null||oe(),Me=!0,X=!0,ee.destroy(),se.destroy(),((t=F.get(e.apiKey))==null?void 0:t.dispose)===M.dispose&&F.delete(e.apiKey),e.debug&&console.log("[sentient] disposed")},destroy(){var t;oe==null||oe(),Me=!0,X=!0,l=!0,Ot(e.apiKey),ee.destroy({forget:!0}),se.destroy({forget:!0}),n.destroy(),K.clear(),((t=F.get(e.apiKey))==null?void 0:t.dispose)===M.dispose&&F.delete(e.apiKey);try{localStorage.removeItem(Ke+e.apiKey),localStorage.removeItem(Pt(e.apiKey)),localStorage.removeItem(Lt(e.apiKey)),localStorage.removeItem(`_snt_graph_nodes${ve(e.apiKey)}`),localStorage.removeItem("_snt_graph_edges")}catch(o){}e.debug&&console.log("[sentient] destroyed")}};if(F.set(e.apiKey,{config:e,upgrade:null,dispose:M.dispose}),oe=kn(M,e.apiKey,t=>{ne.then(()=>{Me||Yt.add(t)})}),e.debug){let t=window;t.__sentient&&(t.__sentient.client=M)}return M}export{Je as a,Nt as b,Xe as c,Ye as d,Qe as e,Ze as f,tt as g,jt as h,Wt as i,an as j,ln as k,cn as l,Ln as m,Mn as n,Kn as o,Nn as p,Gn as q,$n as r,jn as s,Un as t,Wn as u,Fn as v,Vn as w,Hn as x,zn as y,qn as z,Jn as A,Xn as B,Yn as C,Qn as D,Zn as E,eo as F,to as G,no as H,oo as I,so as J,dn as K,Ft as L,un as M,gn as N,fn as O,Go as P,Zt as Q,$o as R,qt as S,wn as T};
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{a as Ke,b as pe,c as ge,e as ie,f as Ee,g as Ne,h as Dt,i as Pt,j as Bt,k as Lt,l as Mt,m as Ge}from"./chunk-JNQY3XNF.mjs";import{a as Kt,e as Ce}from"./chunk-LCYGZNFI.mjs";import{b as $e,i as je,j as Ue,k as We,m as Fe,n as He,q as Ve,r as xe,t as ze}from"./chunk-3HMJERH4.mjs";import{a as ve,d as Ot,e as we}from"./chunk-WUFFNQHQ.mjs";import{a as v,b as te}from"./chunk-TMCGHANO.mjs";var qe;function Je(e){qe=typeof e=="string"&&e!==""?e:void 0}function Nt(e=document){if(qe)return qe;try{let s=e.querySelector("script[nonce]");return(s==null?void 0:s.nonce)||(s==null?void 0:s.getAttribute("nonce"))||void 0}catch(s){return}}function Xe(e,s=document){let g=Nt(s);return g&&e.setAttribute("nonce",g),e}var on=1800*1e3;function Ie(e,s){return`${encodeURIComponent(e)}:${encodeURIComponent(s)}`}function Gt(e=on,s){let g=new Map,b=`_snt_asgn${ve(s)}_`,x=(a,i)=>`${b}${encodeURIComponent(a)}:${encodeURIComponent(i)}`,m=a=>{let i=a.slice(b.length),l=i.indexOf(":");if(l<0)return null;try{return{componentId:decodeURIComponent(i.slice(0,l)),segment:decodeURIComponent(i.slice(l+1))}}catch(w){return null}},_=()=>{try{let a=[];for(let i=0;i<localStorage.length;i++){let l=localStorage.key(i);l!=null&&l.startsWith(b)&&a.push(l)}return a}catch(a){return[]}},n=a=>a.assignedAt+(a.ttlMs&&a.ttlMs>0?a.ttlMs:e)<Date.now();return typeof window!="undefined"&&(()=>{for(let a of _())try{let i=localStorage.getItem(a);if(!i)continue;let l=JSON.parse(i);if(n(l)){localStorage.removeItem(a);continue}let w=m(a);if(!w)continue;g.set(Ie(w.componentId,w.segment),l)}catch(i){}})(),{get(a,i){let l=g.get(Ie(a,i));return l?n(l)?(g.delete(Ie(a,i)),null):l:null},set(a,i,l){let w=Ie(a,i);g.set(w,l);try{localStorage.setItem(x(a,i),JSON.stringify(l))}catch(A){}},clear(){g.clear();for(let a of _())try{localStorage.removeItem(a)}catch(i){}}}}import{STAGE_KEYS as sn}from"@sentientui/policy";var Ye="data-sentient-stage";function Qe(e,s){return!s||typeof e!="string"||!(e==="returning"||sn.includes(e))?null:s!=="detailed"&&(e==="customer"||e==="lapsed")?"returning":e}function Ze(e,s=document){try{e?s.documentElement.setAttribute(Ye,e):s.documentElement.removeAttribute(Ye)}catch(g){}}import{confidenceBand as Vt}from"@sentientui/policy";import{confidenceBand as et}from"@sentientui/policy";var tt="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",jt="[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.",$t=!1,_e=!1;function rn(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(s){return}}function Ut(e){var a;let s=Ce({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),g=(a=s.getSessionId())!=null?a:"local",b=rn(),x=import("@sentientui/core/local").then(i=>{let l=i;return l.LOCAL_ENGINE_AVAILABLE?($t||($t=!0,console.info(jt)),l):(_e||(_e=!0,console.error(tt)),null)}).catch(()=>(_e||(_e=!0,console.error(tt)),null)),m=null,_={low:.15,medium:.5,high:.85},n=(()=>{var l;if(e.initialPersona)return v({},e.initialPersona);let i=pe(e.apiKey||"local");return i?{persona:i.persona,confidence:(l=_[i.band])!=null?l:.15}:null})();function u(i){let l=document.documentElement;l.dataset.sentientPersona===void 0&&(l.dataset.sentientPersona=i.persona,l.dataset.sentientConfidence=et(i.confidence))}return{isLocal:!0,async decide(i){var A,L,K;let l=await x;if(!l)return null;let w=l.createLocalEngine({sessionId:g,forcedPersona:b}).decide(i);return m=te(v({},w),{layoutOrder:(L=(A=w.layoutOrder)!=null?A:m==null?void 0:m.layoutOrder)!=null?L:null,slots:v(v({},(K=m==null?void 0:m.slots)!=null?K:{}),w.slots)}),ge(e.apiKey||"local",{v:1,persona:m.persona,band:et(m.confidence),slots:m.slots,layoutOrder:m.layoutOrder,savedAt:Date.now()}),u(w),w},getSlotResult(i){var l,w,A;return(A=(w=m==null?void 0:m.slots[i])!=null?w:(l=e.initialSlots)==null?void 0:l[i])!=null?A:null},getSlotConfig(i){var l,w;return(w=(l=e.initialSlotConfig)==null?void 0:l[i])!=null?w:null},getSitePalette(){var i;return(i=e.initialPalette)!=null?i:null},reportSlots(){},getVisitorId:()=>null,getPersona(){let i=m!=null?m:n;return i?{persona:i.persona,confidence:i.confidence,band:et(i.confidence)}:null},async assign(i,l){var L;let w=await x;return!w||!l||l.length===0?l!=null&&l[0]?{variantId:l[0],assignmentTtlMs:0}:null:{variantId:(L=w.createLocalEngine({sessionId:g,forcedPersona:b}).decide({components:[{id:i,variantIds:l}]}).assignments[i])!=null?L:l[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),flush:()=>{},dispose:()=>{},destroy:()=>s.destroy()}}var Wt=/^(\*|\/[^\s?#*]*(\/\*)?)$/;function nt(e){let s=e.split(/[?#]/)[0]||"/";return s.length>1?s.replace(/\/+$/,"")||"/":s}function an(e,s){if(e===void 0||!Wt.test(e))return!1;if(e==="*")return!0;let g=nt(s);if(e.endsWith("/*")){let b=nt(e.slice(0,-2));return g.startsWith(b==="/"?"/":`${b}/`)&&g!==b}return g===nt(e)}function ln(e,s){if(!e)return!1;if(e==="/")return s==="/";let g=e.endsWith("/")?e.slice(0,-1):e;return s===g||s.startsWith(`${g}/`)}function cn(e){if(!/^https?:\/\//i.test(e))return e;try{return new URL(e).pathname||"/"}catch(s){return e}}var Ln=["none","sm","md","lg"],Mn=["start","center","end","stretch"],Kn=["start","center","end","between"],Nn=["sm","md","lg"],Gn=["normal","medium","bold"],$n=["default","muted","accent"],jn=["primary","secondary","ghost"],Un=["left","center","right"],Wn=["auto","square","landscape","wide"],Fn=["cover","contain"],Hn=[2,3,4],Vn=[1,2,3,4],zn=["default","raised"],qn=["none","sm","md","lg"],Jn=["measure"],Xn=["input","textarea","select"],Yn=["text","email","number","tel"],Qn=5,Zn=8,eo=64,to=5,no=12,oo=4,so=500;function dn(e){if(e==null||typeof e!="object"||Array.isArray(e))return!1;let s=e;return s.type==="form"?!0:Array.isArray(s.children)?s.children.some(dn):!1}var ot="sentient-reveal",ae="sentient-revealed",Ft=240,Re=!1;function un(){var e;Re=!1,typeof document!="undefined"&&((e=document.getElementById(ot))==null||e.remove())}function pn(e){if(Re||e.getElementById(ot)){Re=!0;return}let s=Xe(e.createElement("style"),e);s.id=ot,s.textContent=`@media (prefers-reduced-motion: no-preference){@keyframes ${ae}{from{opacity:.55;transform:translateY(2px)}to{opacity:1;transform:none}}.${ae}{animation:${ae} ${Ft}ms cubic-bezier(.2,.6,.2,1) both}}`,e.head.appendChild(s),Re=!0}function gn(e,s={}){var x;let g=(x=s.doc)!=null?x:typeof document!="undefined"?document:void 0;if(!g||!(e instanceof Element)||(s.arm!==void 0&&e.setAttribute("data-sentient-arm",s.arm),s.persona!==void 0&&e.setAttribute("data-sentient-persona",s.persona),s.previous!==void 0&&s.previous===e.textContent))return!1;pn(g),e.classList.remove(ae),e.offsetWidth,e.classList.add(ae);let b=()=>{e.classList.remove(ae),e.removeEventListener("animationend",b)};return e.addEventListener("animationend",b),!0}function fn(e,s,g,b){let x=[];{let n=!1,u=[],a=()=>{if(n)return;let i=Date.now();for(u.push(i);u.length>0&&i-u[0]>500;)u.shift();u.length>=3&&(n=!0,e("rage_click"))};s.addEventListener("click",a),x.push(()=>s.removeEventListener("click",a))}{let m=!1,_=n=>{if(m||!(n.target instanceof Node)||!s.contains(n.target)&&s!==n.target)return;m=!0;let u=typeof window!="undefined"?window.getSelection():null,a=u?u.toString().length:0;e("text_copy",{selectionLength:a})};document.addEventListener("copy",_),x.push(()=>document.removeEventListener("copy",_))}{let m=!1,_=!1,n=null,u=()=>{n!==null&&(clearTimeout(n),n=null)},a=()=>{m||!_||(u(),n=setTimeout(()=>{!m&&_&&(m=!0,e("scroll_hesitation"))},3e3))},i=()=>{u(),a()},l=A=>{for(let L of A)_=L.intersectionRatio>.3,_?a():u()},w=new IntersectionObserver(l,{threshold:[.3]});w.observe(s),window.addEventListener("scroll",i,{passive:!0}),x.push(()=>{w.disconnect(),window.removeEventListener("scroll",i),u()})}if((b==null?void 0:b.tabLoss)!==!1){let m=!1,_=g!=null?g:Date.now(),n=()=>{if(m||document.visibilityState!=="hidden")return;let u=Date.now()-_;u<15e3&&(m=!0,e("tab_loss",{timeOnPage:u}))};document.addEventListener("visibilitychange",n),x.push(()=>document.removeEventListener("visibilitychange",n))}return()=>{for(let m of x)m()}}function mn(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}var Jt="https://api.sentient-ui.com/v1/events",zt=()=>import("@sentientui/core/internal-traffic"),F=new Map,Xt=null;function Go(e,s){let g=F.get(e);g&&g.upgrade&&(g.reinit=s)}function yn(e){return"value"in e||"currency"in e||"externalId"in e||"metadata"in e||"weight"in e||"stepIndex"in e}var Sn=3;function rt(){return Kt()}function Ae(){var e;if(typeof window!="undefined")return((e=window.location)==null?void 0:e.pathname)||void 0}function hn(){let e=new WeakMap,s=new Map,g=!1,b=(n,u,a)=>{let i=n.get(u);return a===null?i?!0:(n.set(u,new Set),!1):i?i.has(a)?!0:(i.add(a),!1):(n.set(u,new Set([a])),!1)},x=typeof window!="undefined"&&"event"in window,m=()=>{if(!x)return;let n=window.event;return typeof Event=="function"&&n instanceof Event?n:void 0},_=()=>{if(x){Promise.resolve().then(()=>{g=!1,s.clear()});return}let n=!1,u=()=>{n||(n=!0,g=!1,s.clear())};if(setTimeout(u,0),typeof MessageChannel=="function"){let a=new MessageChannel;a.port1.onmessage=()=>{a.port1.close(),a.port2.close(),u()},a.port2.postMessage(0)}};return{firedBefore(n,u){let a=m();if(a){let l=e.get(a);return l||(l=new Map,e.set(a,l)),b(l,n,u)}let i=b(s,n,u);return!i&&!g&&(g=!0,_()),i}}}var Yt=new Set;function kn(e,s,g){let b=typeof window=="undefined"?null:window.history;if(!b)return()=>{};let x=!1,m,_=()=>{if(x)return;let a=Ae();!a||a===m||(m=a,e.track({projectId:s,componentId:"__page__",eventType:"pageview",payload:{}}),g(`${s}:${a}`))},n=[];for(let a of["pushState","replaceState"]){let i=b[a],l=function(...w){let A=i.apply(this,w);return _(),A};b[a]=l,n.push([a,i,l])}window.addEventListener("popstate",_);let u=Ae();return u&&Yt.has(`${s}:${u}`)?m=u:_(),()=>{if(!x){x=!0,window.removeEventListener("popstate",_);for(let[a,i,l]of n)b[a]===l&&(b[a]=i)}}}var fe={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,assign:()=>Promise.resolve(null),decide:()=>Promise.resolve(null),getSlotResult:()=>null,getSlotConfig:()=>null,getSitePalette:()=>null,reportSlots:()=>{},getPersona:()=>null,getVisitorId:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),flush:()=>{},dispose:()=>{},destroy:()=>{}};function bn(){try{return Fe(window.location.search)}catch(e){return{utmParams:{},clickIds:{}}}}function Qt(e){return e.replace(/\/events\/?$/,"")}function Zt(){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(s=>s==="1"||s==="yes")}function $o(e){var u;if(typeof window=="undefined")return;let s=e!=null?e:Xt;if(!s){console.warn("[sentient] grantConsent() called before init()");return}let g=F.get(s);if(!g){console.warn("[sentient] grantConsent() called before init()");return}let{config:b,upgrade:x,reinit:m}=g;if(!x){g.upgradeBlockedReason&&console.warn(g.upgradeBlockedReason);return}if(b.respectDoNotTrack!==!1&&Zt())return;let _=(m!=null?m:wn)(te(v({},b),{consent:!0}));x(_);let n=(u=F.get(s))==null?void 0:u.dispose;F.set(s,{config:te(v({},b),{consent:!0}),upgrade:null,dispose:n})}function vn(e,s){var ye;let g=e.preConsentBehavior==="statistical_winner",b=Qt((ye=e.ingestUrl)!=null?ye:Jt),x={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},m=new Map,_=new Map,n={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),assign(r,c,E){if(!g)return Promise.resolve(null);let T=m.get(r);return T?Promise.resolve(T):at(_,r,async()=>{try{let I=new URLSearchParams({componentId:r});for(let q of c!=null?c:[])I.append("variantIds[]",q);let G=ie(5e3),W;try{let q=await fetch(`${b}/winner?${I.toString()}`,{headers:x,signal:G.signal});if(!q.ok)return c!=null&&c[0]?{variantId:c[0],assignmentTtlMs:0}:null;W=await q.json()}finally{G.clear()}let $={variantId:W.variantId,assignmentTtlMs:0};return m.set(r,$),$}catch(I){return c!=null&&c[0]?{variantId:c[0],assignmentTtlMs:0}:null}})},decide:()=>Promise.resolve(null),getSlotResult:()=>null,getSlotConfig:()=>null,getSitePalette:()=>null,reportSlots:()=>{},getPersona:()=>null,getVisitorId:()=>null,getGraph:()=>({pageNodes:[],capturedAt:0}),flush:()=>{},dispose:()=>{},destroy:()=>{}},u=!1,a=new Set,i=[],l=[],w=[],A=()=>{for(let[,,r]of w.splice(0))r(null);L.length=0},L=[],K=!1,ee=()=>{if(u)return;K=!0;let r=F.get(e.apiKey);(r==null?void 0:r.upgrade)===le&&F.set(e.apiKey,{config:e,upgrade:null,upgradeBlockedReason:"[sentient] grantConsent(): client released before consent; call init() again"})},N=[],H=()=>{setTimeout(()=>{var r;try{(r=N.shift())==null||r(n)}catch(c){}N.length&&H()})},me=r=>{u?N.length?N.push(r):r(n):!s&&!K&&L.length<100?L.push(r):K&&e.debug&&console.warn("[sentient] goal dropped: client released")},se={get gated(){return!u&&!s},get released(){return K&&!u},takeHeld:()=>L.splice(0),track:r=>n.track(r),goal:((r,c,E,T)=>me(I=>I.goal(r,c,E,T))),componentGoal:(r,c,E)=>n.componentGoal(r,c,E),identify:(r,c)=>n.identify(r,c),getAssignment:(r,c)=>n.getAssignment(r,c),isUnified:r=>{var c,E;return(E=(c=n.isUnified)==null?void 0:c.call(n,r))!=null?E:!1},assign:(r,c,E,T,I)=>n.assign(r,c,E,T,I),decide:r=>u?n.decide(r):K||s?Promise.resolve(null):new Promise(c=>w.push([r,qt(),c])),getSlotResult:r=>n.getSlotResult(r),isSlotDecided:r=>{var c,E;return(E=(c=n.isSlotDecided)==null?void 0:c.call(n,r))!=null?E:!0},getSlotConfig:r=>n.getSlotConfig(r),getSitePalette:()=>n.getSitePalette(),getStyleVocabulary:()=>{var r,c;return(c=(r=n.getStyleVocabulary)==null?void 0:r.call(n))!=null?c:null},reportSlots:(r,c,E,T)=>n.reportSlots(r,c,E,T),reportSkeleton:(r,c)=>{var E;return(E=n.reportSkeleton)==null?void 0:E.call(n,r,c)},reportAgentData:(r,c,E)=>{var T;return(T=n.reportAgentData)==null?void 0:T.call(n,r,c,E)},reportDrift:(r,c,E,T)=>{var I;return(I=n.reportDrift)==null?void 0:I.call(n,r,c,E,T)},requestSlots:(r,c,E)=>{var T;return u?(T=n.requestSlots)==null?void 0:T.call(n,r,c,E):i.push([r,c,E])},decideSlots:r=>{var c;return u?(c=n.decideSlots)==null?void 0:c.call(n,r):l.push(...r)},cancelSlots:r=>{var E;if(u)return(E=n.cancelSlots)==null?void 0:E.call(n,r);let c=new Set(r);for(let T of i)T[0]=T[0].filter(I=>!c.has(I));l=l.filter(T=>!c.has(T.id))},onSlotsChanged:r=>(a.add(r),()=>{a.delete(r)}),getPersona:()=>n.getPersona(),getVisitorId:()=>{var r,c;return(c=(r=n.getVisitorId)==null?void 0:r.call(n))!=null?c:null},fetchWeights:()=>n.fetchWeights(),getGraph:()=>n.getGraph(),flush:()=>n.flush(),dispose:()=>(ee(),A(),n.dispose()),destroy:()=>(ee(),A(),u?n.destroy():Ge(e.apiKey))};function le(r){var E,T,I;n=r,u=!0,L.length&&(N.push(...L.splice(0)),H());let c=qt();for(let[G,W,$]of w.splice(0))W!==c?$(null):r.decide(G).then($,()=>$(null));(E=r.onSlotsChanged)==null||E.call(r,()=>a.forEach(G=>G()));for(let[G,W,$]of i.splice(0))G.length>0&&((T=r.requestSlots)==null||T.call(r,G,W,$));l.length>0&&((I=r.decideSlots)==null||I.call(r,l.splice(0)))}return{proxy:se,setInner:le}}function qt(){return typeof location=="undefined"?"":location.pathname+(/^#!?\//.test(location.hash)?location.hash:"")}function at(e,s,g){let b=e.get(s);if(b)return b;let x=(async()=>{try{return await g()}finally{e.delete(s)}})();return e.set(s,x),x}function wn(e){var ht,kt,bt,vt,wt,Et,Ct,xt,It,_t,Rt;if(typeof window=="undefined")return fe;e.nonce&&Je(e.nonce),Xt=e.apiKey||"local";let s=F.get(e.apiKey||"local");if(s!=null&&s.dispose)try{s.dispose()}catch(t){}let g=e.respectDoNotTrack!==!1&&Zt(),b=e.consent===!1||g,x=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!x&&e.localMode!==!1)return F.set(e.apiKey||"local",{config:e,upgrade:null,upgradeBlockedReason:"[sentient] grantConsent(): this client is keyless/local \u2014 there is no hosted client to upgrade to. Configure a pk_ API key to enable tracking."}),b?fe:Ut(e);if(b){if(!e.apiKey||!e.apiKey.startsWith("pk_"))return e.preConsentBehavior==="statistical_winner"&&console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),F.set(e.apiKey||"local",{config:e,upgrade:null,upgradeBlockedReason:"[sentient] grantConsent(): the client was initialized with an invalid apiKey (expected a pk_ public key) \u2014 consent cannot enable tracking."}),fe;let{proxy:t,setInner:o}=vn(e,g);return F.set(e.apiKey,{config:e,upgrade:g?null:o}),t}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."),fe;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),fe;let m=(ht=e.ingestUrl)!=null?ht:Jt,_=Date.now(),n=Ce({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey,cookieDomain:e.cookieDomain}),u={},a;try{/sentient_internal=/.test(location.search+document.cookie)&&(a=zt().then(async t=>{u.internalToken=await t.takeInternalToken(n.domain)||void 0}).catch(()=>{})),(typeof e.internal=="function"?e.internal():e.internal)===!0&&(u.internal=!0)}catch(t){}let i=Gt(void 0,e.apiKey),l=!1,w=we(e.apiKey),A=()=>!l&&we(e.apiKey)===w,L=new Set((kt=e.initialUnified)!=null?kt:[]),K=te(v({},i),{get:(t,o)=>L.has(t)?null:i.get(t,o),set:(...t)=>{A()&&i.set(...t)}}),ee=Bt({ingestUrl:m,apiKey:e.apiKey}),N=Qt(m),H={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},me=new Set,se=Mt({url:`${N}/goals`,apiKey:e.apiKey,headers:H,onDrop:(t,o)=>{if(!e.debug){if(me.has(o))return;me.add(o)}console.warn(`[sentient] goal dropped (HTTP ${o}) \u2014 this will not be retried. `+(o===400?"The session was not found: call init() and let the session upsert complete before firing goals.":o===401||o===403?"Check the API key and that this origin is on the project allowlist.":"See the response status for the cause."),t)}}),le=je((bt=navigator.userAgent)!=null?bt:""),ye=window.location.origin,r=Ue((vt=document.referrer)!=null?vt:"",ye,n.domain),c=(wt=e.sessionSegment)!=null?wt:`${le}:${r}`,E=new Map,T=new Map,I=new Map,G=new Set,W=new Map,$=null,q=null,j=null,lt=new Set,Se=new Set,Te=new Map,Oe=new Map,ct=new Set,dt=new Set,ut=new Set,pt=new Set,De=null,ce=/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/,gt=new Set,he=new Set,ke=new Set,de=new Map,Pe=null,be=new Set,ue=new Map,Be=null,en=2,ft=new Map,X=!1,mt=(t,o,d)=>{var p;let S=new Set,k=1;for(let f of t){o.delete(f);let y=((p=ft.get(f))!=null?p:0)+1;ft.set(f,y),y<=en&&(S.add(f),y>k&&(k=y))}S.size>0&&setTimeout(()=>{X||d(S)},Ne(k))},Le=t=>{for(let o of t)I.has(o.id)||I.set(o.id,xe(o))};if(e.initialSlots)for(let[t,o]of Object.entries(e.initialSlots))I.set(t,o),G.add(t);if(e.initialSlotConfig)for(let[t,o]of Object.entries(e.initialSlotConfig))W.set(t,o);e.initialPalette&&($=e.initialPalette),e.initialVocabulary&&(q=e.initialVocabulary);let Y=pe(e.apiKey);if(Y){for(let[t,o]of Object.entries(Y.slots))I.has(t)||I.set(t,o);for(let[t,o]of Object.entries((Et=Y.slotConfig)!=null?Et:{}))W.has(t)||W.set(t,o);!$&&Y.palette&&($=Y.palette),!q&&Y.vocabulary&&(q=Y.vocabulary)}let yt={low:.15,medium:.5,high:.85};if(e.initialPersona)j=v({},e.initialPersona);else{let t=document.documentElement.dataset;t.sentientPersona?j={persona:t.sentientPersona,confidence:(xt=yt[(Ct=t.sentientConfidence)!=null?Ct:"low"])!=null?xt:.15}:Y&&(j={persona:Y.persona,confidence:(It=yt[Y.band])!=null?It:.15})}if(e.initialAssignments)for(let[t,o]of Object.entries(e.initialAssignments))K.set(t,c,{variantId:o,assignedAt:Date.now(),segment:c,confidence:1});let ne=Promise.resolve(),St=n.getSessionId();if(St){let t=We((_t=document.referrer)!=null?_t:""),{utmParams:o,clickIds:d}=bn(),S=v(v(v(v({sessionId:St,deviceClass:le,trafficSource:r,referrerDomain:t,utmParams:o,clickIds:d,landingPath:typeof location!="undefined"?location.pathname:void 0,timeOfDay:He(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:n.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||$e((Rt=navigator.userAgent)!=null?Rt:"")},e.userId?{userId:e.userId,userHash:e.userHash}:{}),e.persona?{persona:e.persona}:{}),e.country?{country:e.country}:{}),e.sdk?{sdk:e.sdk.name,sdkVersion:e.sdk.version}:{}),k=async()=>{a&&await Ee(a,2500);for(let p=0;;p++){if(X||!A())return;let f=ie(5e3);try{let y=await fetch(`${N}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(Object.assign(S,u)),headers:H,signal:f.signal});if(y.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");return}if(y.ok||Dt(y)==="dropped")return}catch(y){}finally{f.clear()}if(p>=Sn){console.warn("[SentientUI] Could not register the session after retries. Conversions in this visit may not be recorded.");return}await new Promise(y=>setTimeout(y,Ne(p+1)))}};try{ne=k()}catch(p){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:ee});let tn=hn(),oe=null,Me=!1,M={goal(t,o={},d=1,S=0){var B,R,V,J,z,U,h;let k=n.getSessionId();if(!k||X||!A())return;let p=yn(o)?o:{metadata:o},f=[t,(B=p.externalId)!=null?B:"",(R=p.stepIndex)!=null?R:S,(V=p.weight)!=null?V:d].join("\0"),y=p.value!==void 0?`${p.value}\0${(J=p.currency)!=null?J:""}`:null;if(tn.firedBefore(f,y)){e.debug&&console.log(`[sentient] goal("${t}") already recorded for this action \u2014 not sent twice`);return}let O=rt(),C={sessionId:k,name:t,metadata:(z=p.metadata)!=null?z:{},weight:(U=p.weight)!=null?U:d,stepIndex:(h=p.stepIndex)!=null?h:S,goalId:O,value:p.value,currency:p.currency,externalId:p.externalId};e.debug&&console.log("[sentient] goal",C);let D={id:O,body:JSON.stringify(C)};ne.then(()=>se.send(D))},componentGoal(t,o,d){var O,C,D;let S=n.getSessionId();if(!S||X||!A())return;let k=K.get(t,c),p=k?null:(O=I.get(t))!=null?O:null;if(!k&&p===null){e.debug&&console.warn(`[sentient] componentGoal("${t}"): no assignment or slot decision yet \u2014 render its <Adaptive>/adaptive hook or call assign()/decide() before recording a goal.`);return}if(!k&&!G.has(t)){e.debug&&console.warn(`[sentient] componentGoal("${t}"): slot not decided this session \u2014 not attributed`);return}let f=k?k.variantId:ze(p),y={id:rt(),sessionId:S,projectId:e.apiKey,componentId:t,variantId:f,eventType:"goal_achieved",goalType:o,payload:v({reward:(C=d==null?void 0:d.reward)!=null?C:1,goalValue:d==null?void 0:d.value,currency:d==null?void 0:d.currency},(D=d==null?void 0:d.metadata)!=null?D:{}),timestamp:Date.now(),timeInSession:Date.now()-_,path:Ae()};e.debug&&console.log("[sentient] componentGoal",y),ne.then(()=>{!X&&A()&&ee.push(y)})},identify(t,o){let d=n.getSessionId();if(!d||X||!A())return;let S=(o==null?void 0:o.email)!==void 0?zt().then(k=>k.emailFields(o.email)).catch(()=>({})):{};Promise.all([ne,S]).then(([,k])=>{fetch(`${N}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(te(v(v({sessionId:d,userId:t,userHash:o==null?void 0:o.userHash},k),u),{ephemeral:n.isEphemeral()})),headers:H}).catch(()=>{})})},track(t){let o=n.getSessionId();if(!o||X||!A()||t.eventType==="variant_assigned"&&I.get(t.componentId)!==void 0&&!G.has(t.componentId)&&!K.get(t.componentId,c))return;let d=te(v({path:Ae()},t),{id:rt(),sessionId:o,timestamp:Date.now(),timeInSession:Date.now()-_});e.debug&&console.log("[sentient] track",d),ne.then(()=>ee.push(d))},getAssignment(t,o){return K.get(t,o)},isUnified:t=>L.has(t),async assign(t,o,d,S,k){var O;let p=n.getSessionId();if(!p)return null;let f=(k==null?void 0:k.unified)===!0;if(f&&L.has(t))return{variantId:(O=o==null?void 0:o[0])!=null?O:"",assignmentTtlMs:0,unified:!0};let y=K.get(t,c);if(y&&(o!=null&&o.length||y.content!==void 0)){let C=y.ttlMs&&y.ttlMs>0?Math.max(0,y.assignedAt+y.ttlMs-Date.now()):0;return{variantId:y.variantId,assignmentTtlMs:C,content:y.content}}return at(E,f?`${t}\0unified`:t,async()=>{if(!await Ee(ne,2500)||X||!A())return null;let C=ie(3e4);try{let D={sessionId:p,componentId:t,variantIds:o};S!==void 0?D.agentDataByVariant=S:d!==void 0&&(D.agentData=d),f&&(D.caps={unified:!0});let B=await fetch(`${N}/assign`,{method:"POST",body:JSON.stringify(D),headers:H,signal:C.signal});if(!B.ok)return null;let R=await B.json();return R.unified===!0?f?(L.add(t),{variantId:R.variantId,assignmentTtlMs:0,unified:!0}):null:(K.set(t,c,v({variantId:R.variantId,assignedAt:Date.now(),segment:c,confidence:1,content:R.content},R.assignmentTtlMs&&R.assignmentTtlMs>0?{ttlMs:R.assignmentTtlMs}:{})),R)}catch(D){return null}finally{C.clear()}})},async decide(t){var p,f;let o=n.getSessionId();if(!o)return null;let d=(p=t.slots)!=null?p:[],S={sessionId:o};t.sections&&t.sections.length>0&&(S.sections=t.sections.map(y=>({id:y}))),S.components=(f=t.components)!=null?f:[],d.length>0&&(S.slots=d.map(Ve)),t.slotsFrom==="registry"&&(S.slotsFrom="registry",t.registrySlotIds&&(S.registrySlotIds=t.registrySlotIds),t.bootstrap===!1&&(S.bootstrap=!1),t.render&&Object.keys(t.render).length>0&&(S.render=t.render)),t.v&&(S.v=t.v),typeof t.pp=="number"&&(S.pp=t.pp),e.persona&&(S.persona=e.persona),Object.assign(S,u);let k=JSON.stringify(S);return at(T,k,async()=>{var O,C,D,B,R,V,J,z;if(!await Ee(ne,2500)||X||!A())return Le(d),null;let y=ie(3e4);try{let U=await fetch(`${N}/decide`,{method:"POST",body:k,headers:H,signal:y.signal});if(!U.ok)return Le(d),null;let h=await U.json(),Q=Qe(h.stage,e.stageAttributes);e.stageAttributes&&Ze(Q);let re={};for(let P of d){let Z=(O=h.slots)==null?void 0:O[P.id];if(Z!==void 0){re[P.id]=Z,I.set(P.id,Z),G.add(P.id);continue}let At=I.get(P.id);if(At!==void 0)re[P.id]=At;else{let Tt=xe(P);re[P.id]=Tt,I.set(P.id,Tt)}}if(h.slots)for(let[P,Z]of Object.entries(h.slots))P in re||(re[P]=Z,I.set(P,Z),G.add(P));let nn=j!=null&&j.persona!=="unknown";h.persona&&!(h.persona==="unknown"&&nn)?j={persona:h.persona,confidence:(C=h.confidence)!=null?C:0}:j||(j={persona:"unknown",confidence:0});for(let[P,Z]of Object.entries((D=h.assignments)!=null?D:{}))K.set(P,c,{variantId:Z,assignedAt:Date.now(),segment:c,confidence:1});if(h.slotConfig)for(let[P,Z]of Object.entries(h.slotConfig))W.set(P,Z);h.palette&&($=h.palette),h.vocabulary&&(q=h.vocabulary);for(let P of(B=t.registrySlotIds)!=null?B:[])(R=h.slotConfig)!=null&&R[P]||(W.delete(P),I.delete(P),G.delete(P));return A()&&ge(e.apiKey,v(v(v(v({v:1,persona:j.persona,band:Vt(j.confidence),slots:Object.fromEntries(I),layoutOrder:(V=h.layoutOrder)!=null?V:null,savedAt:Date.now()},W.size>0?{slotConfig:Object.fromEntries(W)}:{}),$?{palette:$}:{}),q?{vocabulary:q}:{}),Q?{stage:Q}:{})),v(v(v(v(v(v(v({layoutOrder:(J=h.layoutOrder)!=null?J:null,assignments:(z=h.assignments)!=null?z:{},slots:re,persona:j.persona,confidence:j.confidence},h.slotConfig?{slotConfig:h.slotConfig}:{}),h.goals?{goals:h.goals}:{}),h.sectionMap?{sectionMap:h.sectionMap}:{}),h.palette?{palette:h.palette}:{}),h.vocabulary?{vocabulary:h.vocabulary}:{}),h.stage?{stage:h.stage}:{}),h.context?{context:h.context}:{})}catch(U){return Le(d),null}finally{y.clear()}})},getSlotResult(t){var o;return(o=I.get(t))!=null?o:null},isSlotDecided(t){return G.has(t)},getSlotConfig(t){var o;return(o=W.get(t))!=null?o:null},reportSlots(t,o,d,S){var p;let k={};for(let[f,y]of Object.entries(S!=null?S:{}))for(let O of y){let C=`${f}|${O.key}`;!ce.test(f)||ut.has(C)||(ut.add(C),((p=k[f])!=null?p:k[f]=[]).push(O))}Object.keys(k).length>0&&fetch(`${N}/slots/observed`,{method:"POST",headers:H,body:JSON.stringify({slotIds:Object.keys(k),authoredArms:k})}).catch(()=>{});for(let f of t)if(!(typeof f!="string"||f.length===0)){if(!ce.test(f)){mn()&&!gt.has(f)&&(gt.add(f),console.warn(`[sentient] reportSlots: slot id ${JSON.stringify(f)} will not register \u2014 ids must start with a letter or digit and contain only letters, digits, '_' or '-' (max 128 chars): /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/.`));continue}if(!lt.has(f)){lt.add(f),Se.add(f);let y=o==null?void 0:o[f];if(typeof y=="string"){let C=y.replace(/\s+/g," ").trim().slice(0,400);C!==""&&Te.set(f,C)}let O=d==null?void 0:d[f];O!==void 0&&Oe.set(f,O)}}Se.size===0||De!=null||(De=setTimeout(()=>{De=null;let f=[...Se];Se.clear();for(let y=0;y<f.length;y+=20){let O=f.slice(y,y+20),C={},D={};for(let B of O){let R=Te.get(B);R!==void 0&&(C[B]=R,Te.delete(B));let V=Oe.get(B);V!==void 0&&(D[B]=V,Oe.delete(B))}fetch(`${N}/slots/observed`,{method:"POST",headers:H,body:JSON.stringify(v(te(v(v({slotIds:O},Object.keys(C).length>0?{baselineTexts:C}:{}),Object.keys(D).length>0?{baselineSkeletons:D}:{}),{pagePaths:Object.fromEntries(O.map(B=>[B,location.pathname]))}),Object.keys(C).length>0&&n.getSessionId()?{sessionId:n.getSessionId()}:{}))}).catch(()=>{})}},1e3))},reportSkeleton(t,o){!ce.test(t)||ct.has(t)||(ct.add(t),fetch(`${N}/slots/observed`,{method:"POST",headers:H,body:JSON.stringify({slotIds:[t],baselineSkeletons:{[t]:o}})}).catch(()=>{}))},reportAgentData(t,o,d){let S=`${t}|${o}`;!ce.test(t)||pt.has(S)||(pt.add(S),fetch(`${N}/slots/observed`,{method:"POST",headers:H,body:JSON.stringify(v(v({slotIds:[t],agentData:{[t]:{[o]:d}}},o.startsWith("authored.")?{authoredArms:{[t]:[{key:o.slice(9)}]}}:{}),n.getSessionId()?{sessionId:n.getSessionId()}:{}))}).catch(()=>{}))},reportDrift(t,o,d,S){let k=`${t}|${o}`,p=n.getSessionId();!p||dt.has(k)||(dt.add(k),fetch(`${N}/slots/drift`,{method:"POST",headers:H,body:JSON.stringify({sessionId:p,reports:[{slotId:t,expectedFp:o,observedFp:d,reason:S}]})}).catch(()=>{}))},requestSlots(t,o,d){var S,k;for(let p of t)ke.has(p)||(ke.add(p),ce.test(p)?de.set(p,{text:o==null?void 0:o[p],render:(S=d==null?void 0:d.render)==null?void 0:S[p],skeleton:(k=d==null?void 0:d.skeletons)==null?void 0:k[p]}):M.reportSlots([p]));de.size===0||Pe!=null||(Pe=setTimeout(()=>{Pe=null;let p=[...de];de.clear();for(let f=0;f<p.length;f+=50){let y=p.slice(f,f+50),O={};for(let[C,D]of y)D.render&&(O[C]=D.render);M.decide({slotsFrom:"registry",registrySlotIds:y.map(([C])=>C),bootstrap:!1,render:O}).then(C=>{var D,B;if(C){let R={},V={},J=[];for(let[z,U]of y){let h=(D=C.slotConfig)==null?void 0:D[z];if(h){h.needsSkeleton&&U.skeleton&&((B=M.reportSkeleton)==null||B.call(M,z,U.skeleton));continue}J.push(z),U.text&&(R[z]=U.text),U.skeleton&&(V[z]=U.skeleton)}J.length>0&&M.reportSlots(J,R,V)}else mt(y.map(([R])=>R),ke,R=>{var U;let V={},J={},z={};for(let[h,Q]of y)R.has(h)&&(Q.text&&(V[h]=Q.text),Q.render&&(J[h]=Q.render),Q.skeleton&&(z[h]=Q.skeleton));(U=M.requestSlots)==null||U.call(M,[...R],V,{render:J,skeletons:z})});he.forEach(R=>R())})}},0))},decideSlots(t){for(let o of t)be.has(o.id)||(be.add(o.id),ue.set(o.id,o));ue.size===0||Be!=null||(Be=setTimeout(()=>{Be=null;let o=[...ue.values()];ue.clear();for(let d=0;d<o.length;d+=30){let S=o.slice(d,d+30);M.decide({slots:S}).then(k=>{k||mt(S.map(p=>p.id),be,p=>{var f;return(f=M.decideSlots)==null?void 0:f.call(M,S.filter(y=>p.has(y.id)))}),he.forEach(p=>p())})}},0))},cancelSlots(t){for(let o of t)de.delete(o)&&ke.delete(o),ue.delete(o)&&be.delete(o)},onSlotsChanged(t){return he.add(t),()=>{he.delete(t)}},getStyleVocabulary(){return q},getSitePalette(){return $},getVisitorId:()=>A()?n.getSessionId():null,getPersona(){return j?{persona:j.persona,confidence:j.confidence,band:Vt(j.confidence)}:null},async fetchWeights(){var o;let t=ie(5e3);try{let d=await fetch(`${N}/weights`,{headers:H,signal:t.signal});return d.ok?(o=(await d.json()).components)!=null?o:[]:[]}catch(d){return[]}finally{t.clear()}},getGraph(){return{pageNodes:[],capturedAt:0}},flush(){ee.flush(),se.flush()},dispose(){var t;oe==null||oe(),Me=!0,X=!0,ee.destroy(),se.destroy(),((t=F.get(e.apiKey))==null?void 0:t.dispose)===M.dispose&&F.delete(e.apiKey),e.debug&&console.log("[sentient] disposed")},destroy(){var t;oe==null||oe(),Me=!0,X=!0,l=!0,Ot(e.apiKey),ee.destroy({forget:!0}),se.destroy({forget:!0}),n.destroy(),K.clear(),((t=F.get(e.apiKey))==null?void 0:t.dispose)===M.dispose&&F.delete(e.apiKey);try{localStorage.removeItem(Ke+e.apiKey),localStorage.removeItem(Pt(e.apiKey)),localStorage.removeItem(Lt(e.apiKey)),localStorage.removeItem(`_snt_graph_nodes${ve(e.apiKey)}`),localStorage.removeItem("_snt_graph_edges")}catch(o){}e.debug&&console.log("[sentient] destroyed")}};if(F.set(e.apiKey,{config:e,upgrade:null,dispose:M.dispose}),oe=kn(M,e.apiKey,t=>{ne.then(()=>{Me||Yt.add(t)})}),e.debug){let t=window;t.__sentient&&(t.__sentient.client=M)}return M}export{Je as a,Nt as b,Xe as c,Ye as d,Qe as e,Ze as f,tt as g,jt as h,Wt as i,an as j,ln as k,cn as l,Ln as m,Mn as n,Kn as o,Nn as p,Gn as q,$n as r,jn as s,Un as t,Wn as u,Fn as v,Hn as w,Vn as x,zn as y,qn as z,Jn as A,Xn as B,Yn as C,Qn as D,Zn as E,eo as F,to as G,no as H,oo as I,so as J,dn as K,Ft as L,un as M,gn as N,fn as O,Go as P,Zt as Q,$o as R,qt as S,wn as T};
|
|
2
|
+
//# sourceMappingURL=chunk-5VIREVXA.mjs.map
|