@sentientui/core 0.19.0 → 0.19.1
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-FJOZXSCS.mjs +2 -0
- package/dist/chunk-FJOZXSCS.mjs.map +1 -0
- 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-graph.js +1 -1
- package/dist/index-graph.js.map +1 -1
- package/dist/index-graph.mjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-RQXFTO7P.mjs +0 -2
- package/dist/chunk-RQXFTO7P.mjs.map +0 -1
package/dist/index-graph.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as b,d as v}from"./chunk-CD2A55US.mjs";import{a as T,i as N,k as A}from"./chunk-
|
|
1
|
+
import{a as b,d as v}from"./chunk-CD2A55US.mjs";import{a as T,i as N,k as A}from"./chunk-FJOZXSCS.mjs";import{g as $,h as k,i as U,j as L,k as j}from"./chunk-MYT7OJBV.mjs";import{a as y,b as I}from"./chunk-TMCGHANO.mjs";var x="_snt_graph_edges",K={pricing:["features","faq"],features:["pricing"],faq:["pricing"],social_proof:["cta"],cta:["social_proof","hero","trust"],hero:["cta"],comparison:["pricing"],trust:["cta"]};function z(e){var t;return(t=K[e])!=null?t:[]}function F(e,t){try{let n=localStorage.getItem(e);return n?JSON.parse(n):t}catch(n){return t}}function q(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch(n){}}var B=new Set(["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"]);function H(e){return B.has(e)?e:"generic"}function _(e){try{let t=new URL(e);return`${t.origin}${t.pathname}`}catch(t){return"/"}}function J(e,t,n){let d=`${e}:${t}:${n.join(",")}`,p=5381;for(let m=0;m<d.length;m++)p=(p<<5)+p+d.charCodeAt(m)&4294967295;return(p>>>0).toString(16).padStart(8,"0")}function M(e){let t=new Map,n=new Map,d=`_snt_graph_nodes${T(e==null?void 0:e.apiKey)}`,p=()=>{typeof window!="undefined"&&q(d,[...t.values()])},m=o=>{var a;try{let i=JSON.parse(o);t.clear();for(let c of(a=i.pageNodes)!=null?a:[])t.set(c.componentId,c)}catch(i){}};if(typeof window!="undefined"){let o=F(d,[]);for(let a of o)t.set(a.componentId,a);try{localStorage.removeItem(x)}catch(a){}}return{addPageNode(o){t.set(o.componentId,o),p()},addStructuralEdge(o){let a=`${o.fromComponentId}->${o.toComponentId}`;n.set(a,o)},syncOnce(){var a,i;if(!(e!=null&&e.syncUrl)||typeof window=="undefined")return;let o=[...t.values()];if(o.length!==0)try{let c=new Map;for(let s of o){let f=(a=c.get(s.semanticType))!=null?a:[];f.push(s),c.set(s.semanticType,f)}let u=[],l=new Set;for(let s of o)for(let f of z(s.semanticType)){let S=(i=c.get(f))!=null?i:[];for(let h of S){if(h.componentId===s.componentId)continue;let w=`semantic:${s.componentId}->${h.componentId}`;l.has(w)||(l.add(w),u.push({fromComponentId:s.componentId,toComponentId:h.componentId,type:"semantic",weight:.4,confidence:.9}))}}let g=new Set(o.map(s=>s.componentId));for(let s of n.values()){if(!g.has(s.fromComponentId)||!g.has(s.toComponentId))continue;let f=`structural:${s.fromComponentId}->${s.toComponentId}`;l.has(f)||(l.add(f),u.push({fromComponentId:s.fromComponentId,toComponentId:s.toComponentId,type:"structural",weight:s.weight,confidence:1}))}let r=I(y(y({pageUrl:_(window.location.href)},e.sessionId?{sessionId:e.sessionId}:{}),e.projectId?{projectId:e.projectId}:{}),{nodes:o.map(s=>{let f=H(s.semanticType);return{componentId:s.componentId,semanticType:f,answers:s.answers,contentHash:J(s.componentId,f,s.answers),prominenceScore:s.prominenceScore,depthInPage:s.depth}}),edges:u});fetch(e.syncUrl,{method:"POST",keepalive:!0,headers:y({"Content-Type":"application/json"},e.apiKey?{Authorization:`Bearer ${e.apiKey}`}:{}),body:JSON.stringify(r)}).catch(()=>{})}catch(c){}},snapshot(){return{pageNodes:[...t.values()],capturedAt:Date.now()}},serialize(){return JSON.stringify({pageNodes:[...t.values()]})},restore:m,destroy(){if(typeof window!="undefined")try{localStorage.removeItem(d),localStorage.removeItem(x)}catch(o){}}}}var V=new Set(["SECTION","ARTICLE","MAIN","DIV"]),W="h1, h2, h3",O=30,Y=1500,Q={scan:async()=>({nodes:[],edges:[],scannedAt:0}),observe:()=>{},getProminenceScore:()=>0,destroy:()=>{}};function R(e,t,n){return n<=t?0:Math.max(0,Math.min(1,(e-t)/(n-t)))}function X(e){var t,n,d;try{let p=e;for(let m of Object.keys(p)){if(!m.startsWith("__reactFiber")&&!m.startsWith("__reactInternalInstance"))continue;let o=p[m],a=(d=(t=o==null?void 0:o.type)==null?void 0:t.displayName)!=null?d:(n=o==null?void 0:o.type)==null?void 0:n.name;if(a&&a.length>1)return a}}catch(p){}}function Z(e){let t={};for(let n of Array.from(e.attributes))n.name.startsWith("data-")&&(t[n.name]=n.value);return t}var P=new Set(b);function ee(e){let t=e.getAttribute("data-sentient-type");if(t&&P.has(t))return t;let n=e.getAttribute("role");return n&&P.has(n)?n:v(e)}function te(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 ne(e){let t=[],n=e;for(;n;){let d=n.parentElement;if(!d){t.push(n.tagName.toLowerCase());break}let p=Array.prototype.indexOf.call(d.children,n);t.push(`${n.tagName.toLowerCase()}[${p}]`),n=d}return t.reverse().join("/")}function oe(e){var n;let t=(n=e.getAttribute("data-sentient-id"))!=null?n:e.getAttribute("id");return t||`${e.tagName.toLowerCase()}-${te(ne(e))}`}function re(e){let t=0,n=e.parentElement;for(;n;)t++,n=n.parentElement;return t}function C(e,t){var d,p,m;let n=e.querySelector(W);return{componentId:oe(e),semanticType:ee(e),ariaLabel:(d=e.getAttribute("aria-label"))!=null?d:void 0,headingText:(m=(p=n==null?void 0:n.textContent)==null?void 0:p.trim())!=null?m:void 0,isAboveFold:e.getBoundingClientRect().top<window.innerHeight,prominenceScore:t(e),depth:re(e),reactComponentName:X(e),dataAttributes:Z(e)}}function D(e){var m;let t=[],n=new Set,d="__root__",p=new Map;for(let[o,a]of e){let i=o.parentElement,c=d;for(;i;){if(e.has(i)){c=e.get(i);let l=e.get(o),g=`${c}->${l}`;!n.has(g)&&c!==l&&(n.add(g),t.push({fromComponentId:c,toComponentId:l,weight:.6}));break}i=i.parentElement}let u=(m=p.get(c))!=null?m:[];u.push(o),p.set(c,u)}for(let o of p.values()){if(o.length<2)continue;let a=o.length>O?o.slice(0,O):o;for(let i=0;i<a.length;i++)for(let c=i+1;c<a.length;c++){if(t.length>=Y)return t;let u=e.get(a[i]),l=e.get(a[c]);if(u===l)continue;let g=`${u}->${l}::sib`,r=`${l}->${u}::sib`;n.has(g)||(n.add(g),t.push({fromComponentId:u,toComponentId:l,weight:.3})),n.has(r)||(n.add(r),t.push({fromComponentId:l,toComponentId:u,weight:.3}))}}return t}function se(e){let t=[],n=new Set,d=new Map;return document.querySelectorAll("[data-sentient-id]").forEach(o=>{if(o instanceof Element&&!n.has(o)){n.add(o);let a=C(o,e);t.push(a),d.set(o,a.componentId)}}),document.querySelectorAll("section, article, main, aside").forEach(o=>{if(!(o instanceof Element)||n.has(o))return;let a=o.hasAttribute("aria-label"),i=o.hasAttribute("data-sentient-id");if(!a&&!i)return;n.add(o);let c=C(o,e);t.push(c),d.set(o,c.componentId)}),{nodes:t,edges:D(d),elementToId:d}}function G(){if(typeof window=="undefined")return Q;let e=null,t=0,n=null,d=new Map,p=i=>{try{let c=window.getComputedStyle(i),u=parseFloat(c.fontSize)||12,l=parseFloat(c.zIndex)||0,g=i.getBoundingClientRect(),r=Math.max(g.top,0),s=window.innerHeight||1,f=1/(r/s+1),S=R(u,12,48)*.4+f*.4+R(l,0,100)*.2;return Math.max(0,Math.min(1,S))}catch(c){return .5}};return{scan:()=>new Promise(i=>{let c=()=>{let{nodes:u,edges:l,elementToId:g}=se(p);d.clear();for(let[r,s]of g)d.set(r,s);i({nodes:u,edges:l,scannedAt:Date.now()})};try{typeof requestIdleCallback=="function"?t=requestIdleCallback(c,{timeout:100}):c()}catch(u){c()}}),observe:i=>{n=i;try{e=new MutationObserver(c=>{let u=[],l=new Set;for(let r of c)r.type==="childList"&&r.addedNodes.forEach(s=>{if(!(s instanceof Element)||!V.has(s.tagName))return;let f=s.hasAttribute("data-sentient-id"),S=s.hasAttribute("aria-label");if(!f&&!S)return;let h=C(s,p);u.push(h),l.add(h.componentId),d.set(s,h.componentId)});if(u.length===0||!n)return;for(let r of[...d.keys()])r.isConnected||d.delete(r);let g=D(d).filter(r=>l.has(r.fromComponentId)||l.has(r.toComponentId));n({nodes:u,edges:g,addedAt:Date.now()})}),e.observe(document.body,{childList:!0,subtree:!0})}catch(c){}},getProminenceScore:p,destroy:()=>{if(e&&(e.disconnect(),e=null),t&&typeof cancelIdleCallback=="function")try{cancelIdleCallback(t)}catch(i){}t=0,n=null,d.clear()}}}var ae="https://api.sentient-ui.com/v1/events";function ie(){try{let e=document.cookie.match(/(?:^|; )_snt_uid=([^;]*)/);return e?decodeURIComponent(e[1]):void 0}catch(e){return}}var E=new Map;function he(e){var l;let t=A(e),n=e.respectDoNotTrack!==!1&&N(),d=e.consent===!1||n;if(!e.graph||!e.apiKey||d||typeof window=="undefined")return t;let p=E.get(e.apiKey);if(p)try{p()}catch(g){}let m=G(),o=(l=e.ingestUrl)!=null?l:ae,a=M({syncUrl:o.replace(/\/events\/?$/,"/graph/sync"),apiKey:e.apiKey,projectId:e.apiKey,sessionId:ie()});m.scan().then(g=>{for(let r of g.nodes)a.addPageNode({id:r.componentId,componentId:r.componentId,semanticType:r.semanticType,answers:e.captureDomText&&r.headingText?[r.headingText]:[],prominenceScore:r.prominenceScore,depth:r.depth});for(let r of g.edges)a.addStructuralEdge(r);a.syncOnce()});let i=null,c=()=>{i!==null&&clearTimeout(i),i=setTimeout(()=>{i=null,a.syncOnce()},500)};m.observe(g=>{for(let r of g.nodes)a.addPageNode({id:r.componentId,componentId:r.componentId,semanticType:r.semanticType,answers:e.captureDomText&&r.headingText?[r.headingText]:[],prominenceScore:r.prominenceScore,depth:r.depth});for(let r of g.edges)a.addStructuralEdge(r);c()});let u=()=>{i!==null&&(clearTimeout(i),i=null),m.destroy(),a.destroy(),E.get(e.apiKey)===u&&E.delete(e.apiKey)};return E.set(e.apiKey,u),I(y({},t),{getGraph:()=>a.snapshot(),dispose:()=>{u(),t.dispose()},destroy:()=>{u(),t.destroy()}})}export{j as deriveSessionSegment,$ as detectDeviceClass,L as detectTimeOfDay,k as detectTrafficSource,he as init,U as referrerDomainFromReferer,_ as sanitizePageUrl};
|
|
2
2
|
//# sourceMappingURL=index-graph.mjs.map
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var st=Object.create;var le=Object.defineProperty,it=Object.defineProperties,at=Object.getOwnPropertyDescriptor,lt=Object.getOwnPropertyDescriptors,ct=Object.getOwnPropertyNames,Ue=Object.getOwnPropertySymbols,dt=Object.getPrototypeOf,$e=Object.prototype.hasOwnProperty,ut=Object.prototype.propertyIsEnumerable;var Be=(e,t,n)=>t in e?le(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,E=(e,t)=>{for(var n in t||(t={}))$e.call(t,n)&&Be(e,n,t[n]);if(Ue)for(var n of Ue(t))ut.call(t,n)&&Be(e,n,t[n]);return e},X=(e,t)=>it(e,lt(t));var gt=(e,t)=>{for(var n in t)le(e,n,{get:t[n],enumerable:!0})},Fe=(e,t,n,d)=>{if(t&&typeof t=="object"||typeof t=="function")for(let u of ct(t))!$e.call(e,u)&&u!==n&&le(e,u,{get:()=>t[u],enumerable:!(d=at(t,u))||d.enumerable});return e};var pt=(e,t,n)=>(n=e!=null?st(dt(e)):{},Fe(t||!e||!e.__esModule?le(n,"default",{value:e,enumerable:!0}):n,e)),ft=e=>Fe(le({},"__esModule",{value:!0}),e);var jt={};gt(jt,{AGENT_INTENTS:()=>Ee,LOCAL_MODE_BANNER:()=>Pe,PROD_KEYLESS_ERROR:()=>_e,SNAPSHOT_STORAGE_KEY_PREFIX:()=>Y,agentIntent:()=>Je,agentUaList:()=>ce,armOfResult:()=>ke,attachMicroSignalDetectors:()=>Ze,baselineResultFor:()=>te,baselineSlots:()=>Ve,classifiedAgents:()=>ze,deriveSessionSegment:()=>He,detectDeviceClass:()=>ue,detectTimeOfDay:()=>fe,detectTrafficSource:()=>ge,grantConsent:()=>Ft,init:()=>rt,isDoNotTrackEnabled:()=>Ge,matchedAgentToken:()=>Oe,readSnapshot:()=>Ce,referrerDomainFromReferer:()=>pe,renderPrePaintScript:()=>Ye,toWireSlot:()=>me,uaTokenMatch:()=>de,writeSnapshot:()=>ne});module.exports=ft(jt);function he(){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)})}function Se(e){return e?`_${e.slice(0,12)}`:""}var mt="_snt_uid",yt=365,ht="_snt_uid";function St(){return he()}function vt(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function wt(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(d){}}function bt(e){try{return localStorage.getItem(e)}catch(t){return null}}function xt(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function It(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function Et(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function kt(e){try{sessionStorage.removeItem(e)}catch(t){}}function Ct(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 Rt(e){try{localStorage.removeItem(e)}catch(t){}}function At(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var _t={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function ve(e){var y,b,D,R,x,N;if(typeof window=="undefined")return _t;let t=Se(e==null?void 0:e.apiKey),n=(y=e==null?void 0:e.cookieName)!=null?y:`${mt}${t}`,d=`${ht}${t}`,o=((b=e==null?void 0:e.cookieTTLDays)!=null?b:yt)*24*60*60,g=k=>k&&k.length>0?k:null,l=(N=(x=(R=(D=g(vt(n)))!=null?D:g(bt(d)))!=null?R:g(It(d)))!=null?x:g(e==null?void 0:e.ssrSessionId))!=null?N:St();wt(n,l,o);let s=xt(d,l),r=Ct(n),i=s?!1:Et(d,l),c=!s&&!r&&!i;return{getSessionId:()=>l,isEphemeral:()=>c,destroy:()=>{l=null,At(n),Rt(d),kt(d)}}}function q(e){return Math.min(6e4,1e3*2**Math.min(e,6))}function we(e){if(e.ok===!0)return"delivered";let{status:t}=e;return typeof t!="number"?"retry":t>=200&&t<300?"delivered":t>=400&&t<500&&t!==429?"dropped":"retry"}function be(e,t){try{let n=localStorage.getItem(e);if(!n)return[];let d=JSON.parse(n);return Array.isArray(d)?(localStorage.removeItem(e),d.slice(-t)):[]}catch(n){return[]}}function Z(e,t,n){try{let d=(()=>{try{let o=localStorage.getItem(n);if(!o)return[];let g=JSON.parse(o);return Array.isArray(g)?g:[]}catch(o){return[]}})(),u=new Map;for(let o of d)u.set(o.id,o);for(let o of e)u.set(o.id,o);localStorage.setItem(n,JSON.stringify([...u.values()].slice(-t)))}catch(d){}}function xe(e,t){try{let n=localStorage.getItem(t);if(!n)return;let d=JSON.parse(n);if(!Array.isArray(d))return;let u=new Set(e),o=d.filter(g=>!u.has(g.id));if(o.length===d.length)return;o.length===0?localStorage.removeItem(t):localStorage.setItem(t,JSON.stringify(o))}catch(n){}}var Tt=500,Dt=56*1024;function Te(e){return`_snt_retry_${e.slice(0,12)}`}var Ot={push:()=>{},flush:()=>{},destroy:()=>{}};function We(e){var L,J,re;if(typeof window=="undefined")return Ot;let t=(L=e.flushIntervalMs)!=null?L:5e3,n=(J=e.maxBatchSize)!=null?J:20,d=(re=e.maxRetrySize)!=null?re:100,u=e.ingestUrl,o=e.apiKey,g=Te(o),l=[],s=new Set,r=[],i=m=>{for(let S of m)c.delete(S),!s.has(S)&&(s.add(S),r.push(S));for(;r.length>Tt;){let S=r.shift();S&&s.delete(S)}xe(m,g)},c=new Set,y=m=>{s.has(m.id)||c.has(m.id)||(c.add(m.id),l.push(m))},b=m=>{for(let S of m)s.has(S.id)||(c.add(S.id),l.push(S))},D=be(g,d);for(let m of D)y(m);let R=0,x=0,N=m=>{if(m.length===0)return;let S=JSON.stringify(m),j=m.map(V=>V.id),U;try{U=fetch(u,{method:"POST",keepalive:!0,body:S,headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`}})}catch(V){Z(m,d,g),b(m),x++,R=Date.now()+q(x);return}let z=V=>{if(we(V)!=="retry"){i(j),x=0,R=0;return}Z(m,d,g),b(m),x++,R=Date.now()+q(x)};U instanceof Promise?U.then(z).catch(()=>{Z(m,d,g),b(m),x++,R=Date.now()+q(x)}):z(U)},k=typeof TextEncoder!="undefined"?new TextEncoder:null,I=m=>k?k.encode(m).length:m.length,H=m=>{let S=[],j=2;for(let U of m){let z=I(JSON.stringify(U))+1;if(S.length>0&&j+z>Dt||S.length>=n)break;S.push(U),j+=z}return S},A=()=>{try{if(Date.now()<R)return;for(;l.length>0&&!(Date.now()<R);){let m=l.filter(j=>!s.has(j.id));if(l.length=0,m.length===0)break;let S=H(m);if(S.length===0)break;S.length<m.length&&l.push(...m.slice(S.length)),N(S)}}catch(m){}},f=!0,v=null;v=setInterval(()=>{f&&A()},t);let Q=()=>{document.visibilityState==="hidden"&&A()},G=()=>{A()};return document.addEventListener("visibilitychange",Q),window.addEventListener("pagehide",G),{push(m){y(m),l.length>=n&&A()},flush:A,destroy(){f=!1,v!==null&&(clearInterval(v),v=null),document.removeEventListener("visibilitychange",Q),window.removeEventListener("pagehide",G),A()}}}var Pt=200;function De(e){return`_snt_goal_retry_${e.slice(0,12)}`}var Lt={send:()=>{},flush:()=>{},destroy:()=>{}};function je(e){var I,H,A;if(typeof window=="undefined")return Lt;let t=(I=e.flushIntervalMs)!=null?I:5e3,n=(H=e.maxRetrySize)!=null?H:100,d=(A=e.maxPerFlush)!=null?A:5,u=De(e.apiKey),o=[],g=new Set,l=new Set,s=[],r=0,i=0,c=!1,y=f=>{for(g.delete(f.id),l.has(f.id)||(l.add(f.id),s.push(f.id));s.length>Pt;){let v=s.shift();v&&l.delete(v)}xe([f.id],u)},b=f=>{Z([f],n,u),!l.has(f.id)&&!g.has(f.id)&&(g.add(f.id),o.push(f)),i++,r=Date.now()+q(i)},D=f=>{let v;try{v=fetch(e.url,{method:"POST",keepalive:!0,body:f.body,headers:e.headers})}catch(G){b(f);return}let Q=G=>{var J;let L=we(G);if(L==="retry"){b(f);return}L==="dropped"&&((J=e.onDrop)==null||J.call(e,f,G.status)),y(f),i=0,r=0};v instanceof Promise?v.then(Q).catch(()=>b(f)):Q(v)},R=()=>{try{if(c||Date.now()<r)return;let f=0;for(;o.length>0&&f<d&&!(Date.now()<r);){let v=o.shift();g.delete(v.id),!l.has(v.id)&&(f++,D(v))}}catch(f){}};for(let f of be(u,n))g.has(f.id)||(g.add(f.id),o.push(f));let x=setInterval(R,t),N=()=>{document.visibilityState==="hidden"&&R()},k=()=>R();return document.addEventListener("visibilitychange",N),window.addEventListener("pagehide",k),{send(f){if(!c&&!(l.has(f.id)||g.has(f.id))){if(Date.now()<r){g.add(f.id),o.push(f);return}D(f)}},flush:R,destroy(){clearInterval(x),document.removeEventListener("visibilitychange",N),window.removeEventListener("pagehide",k),R(),c=!0}}}var Mt=1800*1e3;function Ie(e,t){return`${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function Qe(e=Mt,t){let n=new Map,d=`_snt_asgn${Se(t)}_`,u=(r,i)=>`${d}${encodeURIComponent(r)}:${encodeURIComponent(i)}`,o=r=>{let i=r.slice(d.length),c=i.indexOf(":");if(c<0)return null;try{return{componentId:decodeURIComponent(i.slice(0,c)),segment:decodeURIComponent(i.slice(c+1))}}catch(y){return null}},g=()=>{try{let r=[];for(let i=0;i<localStorage.length;i++){let c=localStorage.key(i);c!=null&&c.startsWith(d)&&r.push(c)}return r}catch(r){return[]}},l=r=>r.assignedAt+(r.ttlMs&&r.ttlMs>0?r.ttlMs:e)<Date.now();return typeof window!="undefined"&&(()=>{for(let r of g())try{let i=localStorage.getItem(r);if(!i)continue;let c=JSON.parse(i);if(l(c)){localStorage.removeItem(r);continue}let y=o(r);if(!y)continue;n.set(Ie(y.componentId,y.segment),c)}catch(i){}})(),{get(r,i){let c=n.get(Ie(r,i));return c?l(c)?(n.delete(Ie(r,i)),null):c:null},set(r,i,c){let y=Ie(r,i);n.set(y,c);try{localStorage.setItem(u(r,i),JSON.stringify(c))}catch(b){}},invalidate(r){let i=`${encodeURIComponent(r)}:`;for(let c of[...n.keys()])c.startsWith(i)&&n.delete(c);for(let c of g()){let y=o(c);if((y==null?void 0:y.componentId)===r)try{localStorage.removeItem(c)}catch(b){}}},clear(){n.clear();for(let r of g())try{localStorage.removeItem(r)}catch(i){}}}}var ce=["GPTBot","ChatGPT-User","OAI-SearchBot","ClaudeBot","Claude-User","Claude-SearchBot","PerplexityBot","Perplexity-User","Google-Extended","Applebot-Extended","Meta-ExternalAgent","Bytespider","CCBot","Amazonbot","cohere-ai","Diffbot"];function de(e){return Oe(e)!==null}function Oe(e){var n;if(!e)return null;let t=e.toLowerCase();return(n=ce.find(d=>t.includes(d.toLowerCase())))!=null?n:null}var Ee={GPTBot:"training","ChatGPT-User":"user","OAI-SearchBot":"search",ClaudeBot:"training","Claude-User":"user","Claude-SearchBot":"search",PerplexityBot:"search","Perplexity-User":"user","Google-Extended":"training","Applebot-Extended":"training","Meta-ExternalAgent":"training",Bytespider:"training",CCBot:"training",Amazonbot:"other","cohere-ai":"training",Diffbot:"other"};function Je(e){if(!e)return"other";let t=ce.find(n=>n.toLowerCase()===e.toLowerCase());return t&&Ee[t]||"other"}function ze(){var t;let e={user:[],search:[],training:[],other:[]};for(let n of ce)e[(t=Ee[n])!=null?t:"other"].push(n);return e}function ue(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 ge(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(u){}let d=n.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(d)?"search":/(^|\.)(twitter\.com|x\.com|facebook\.com|linkedin\.com|reddit\.com|t\.co)$/.test(d)?"social":"referral"}catch(n){return"direct"}}function pe(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function fe(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function He(e){let t=Nt("__segment__",e);return`${t.deviceClass}:${t.trafficSource}`}function Nt(e,t){var o,g,l,s,r,i,c;let n=(g=(o=t==null?void 0:t.userAgent)==null?void 0:o.trim())!=null?g:"",d=(s=(l=t==null?void 0:t.referer)==null?void 0:l.trim())!=null?s:"",u=(r=t==null?void 0:t.now)!=null?r:new Date;return{sessionId:e,ephemeral:!1,utmParams:(i=t==null?void 0:t.utmParams)!=null?i:{},deviceClass:n?ue(n):"desktop",trafficSource:d?ge(d,t==null?void 0:t.appOrigin):"direct",referrerDomain:pe(d),timeOfDay:fe(u),dayOfWeek:(c=["sun","mon","tue","wed","thu","fri","sat"][u.getDay()])!=null?c:"sun",automation:(t==null?void 0:t.webdriver)===!0||de(n)}}var ee=require("@sentientui/policy");function me(e){return E(E(E({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 te(e){let t=me(e);return(0,ee.slotResultFor)(t,(0,ee.slotBaselineArm)(t))}function Ve(e){let t={};for(let n of e)t[n.id]=te(n);return t}function ke(e){return typeof e=="string"?e:(0,ee.canonicalArm)(e)}var Y="_snt_snap:",Gt=["low","medium","high"];function Ce(e){try{let t=localStorage.getItem(Y+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"||!Gt.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 ne(e,t){try{localStorage.setItem(Y+e,JSON.stringify(t))}catch(n){}}function Ye(e){return"(function(){try{var r=localStorage.getItem("+JSON.stringify(Y+e).replace(/</g,"\\u003c")+');if(!r)return;var s=JSON.parse(r);if(!s||s.v!==1||typeof s.persona!=="string"||typeof s.band!=="string")return;var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",s.persona);d.setAttribute("data-sentient-confidence",s.band);}catch(e){}})();'}var Me=require("@sentientui/policy");var Ae=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.",Pe="[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.",Xe=!1,Re=!1;function Kt(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(t){return}}function qe(e){var l;let t=ve({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),n=(l=t.getSessionId())!=null?l:"local",d=Kt(),u=import("@sentientui/core/local").then(s=>{let r=s;return r.LOCAL_ENGINE_AVAILABLE?(Xe||(Xe=!0,console.info(Pe)),r):(Re||(Re=!0,console.error(_e)),null)}).catch(()=>(Re||(Re=!0,console.error(_e)),null)),o=null;function g(s){let r=document.documentElement;r.dataset.sentientPersona===void 0&&(r.dataset.sentientPersona=s.persona,r.dataset.sentientConfidence=(0,Ae.confidenceBand)(s.confidence))}return{isLocal:!0,async decide(s){var c,y,b;let r=await u;if(!r)return null;let i=r.createLocalEngine({sessionId:n,forcedPersona:d}).decide(s);return o=X(E({},i),{layoutOrder:(y=(c=i.layoutOrder)!=null?c:o==null?void 0:o.layoutOrder)!=null?y:null,slots:E(E({},(b=o==null?void 0:o.slots)!=null?b:{}),i.slots)}),ne(e.apiKey||"local",{v:1,persona:o.persona,band:(0,Ae.confidenceBand)(o.confidence),slots:o.slots,layoutOrder:o.layoutOrder,savedAt:Date.now()}),g(i),i},getSlotResult(s){var r,i,c;return(c=(i=o==null?void 0:o.slots[s])!=null?i:(r=e.initialSlots)==null?void 0:r[s])!=null?c:null},getPersona(){return o?{persona:o.persona,confidence:o.confidence,band:(0,Ae.confidenceBand)(o.confidence)}:null},async assign(s,r){var y;let i=await u;return!i||!r||r.length===0?r!=null&&r[0]?{variantId:r[0],assignmentTtlMs:0}:null:{variantId:(y=i.createLocalEngine({sessionId:n,forcedPersona:d}).decide({components:[{id:s,variantIds:r}]}).assignments[s])!=null?y:r[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>t.destroy()}}function Ze(e,t,n,d){let u=[];{let l=!1,s=[],r=()=>{if(l)return;let i=Date.now();for(s.push(i);s.length>0&&i-s[0]>500;)s.shift();s.length>=3&&(l=!0,e("rage_click"))};t.addEventListener("click",r),u.push(()=>t.removeEventListener("click",r))}{let o=!1,g=l=>{if(o||!(l.target instanceof Node)||!t.contains(l.target)&&t!==l.target)return;o=!0;let s=typeof window!="undefined"?window.getSelection():null,r=s?s.toString().length:0;e("text_copy",{selectionLength:r})};document.addEventListener("copy",g),u.push(()=>document.removeEventListener("copy",g))}{let o=!1,g=!1,l=null,s=()=>{l!==null&&(clearTimeout(l),l=null)},r=()=>{o||!g||(s(),l=setTimeout(()=>{!o&&g&&(o=!0,e("scroll_hesitation"))},3e3))},i=()=>{s(),r()},c=b=>{for(let D of b)g=D.intersectionRatio>.3,g?r():s()},y=new IntersectionObserver(c,{threshold:[.3]});y.observe(t),window.addEventListener("scroll",i,{passive:!0}),u.push(()=>{y.disconnect(),window.removeEventListener("scroll",i),s()})}if((d==null?void 0:d.tabLoss)!==!1){let o=!1,g=n!=null?n:Date.now(),l=()=>{if(o||document.visibilityState!=="hidden")return;let s=Date.now()-g;s<15e3&&(o=!0,e("tab_loss",{timeOnPage:s}))};document.addEventListener("visibilitychange",l),u.push(()=>document.removeEventListener("visibilitychange",l))}return()=>{for(let o of u)o()}}var et="https://api.sentient-ui.com/v1/events",P=new Map,tt=null;function Ut(e){return"value"in e||"currency"in e||"externalId"in e||"metadata"in e||"weight"in e||"stepIndex"in e}function Le(){return he()}function Ne(){var e;if(typeof window!="undefined")return((e=window.location)==null?void 0:e.pathname)||void 0}function Bt(e,t){let n=typeof window=="undefined"?null:window.history;if(!n)return;let d,u=()=>{let o=Ne();!o||o===d||(d=o,e.track({projectId:t,componentId:"__page__",eventType:"pageview",payload:{}}))};for(let o of["pushState","replaceState"]){let g=n[o];n[o]=function(...l){let s=g.apply(this,l);return u(),s}}window.addEventListener("popstate",u),u()}var ye={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 $t(){try{let e={},t=new URLSearchParams(window.location.search);for(let[n,d]of t)n.startsWith("utm_")&&(e[n]=d);return e}catch(e){return{}}}function nt(e){return e.replace(/\/events\/?$/,"")}function Ge(){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 Ft(e){var l;if(typeof window=="undefined")return;let t=e!=null?e:tt;if(!t){console.warn("[sentient] grantConsent() called before init()");return}let n=P.get(t);if(!n){console.warn("[sentient] grantConsent() called before init()");return}let{config:d,upgrade:u}=n;if(!u||d.respectDoNotTrack!==!1&&Ge())return;let o=rt(X(E({},d),{consent:!0}));u(o);let g=(l=P.get(t))==null?void 0:l.dispose;P.set(t,{config:X(E({},d),{consent:!0}),upgrade:null,dispose:g})}function Wt(e){var l;let t=e.preConsentBehavior==="statistical_winner",n=nt((l=e.ingestUrl)!=null?l:et),d={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},u={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),async assign(s,r,i){if(!t)return null;try{let c=new URLSearchParams({componentId:s});for(let D of r!=null?r:[])c.append("variantIds[]",D);let y=await fetch(`${n}/winner?${c.toString()}`,{headers:d});return y.ok?{variantId:(await y.json()).variantId,assignmentTtlMs:0}:r!=null&&r[0]?{variantId:r[0],assignmentTtlMs:0}:null}catch(c){return r!=null&&r[0]?{variantId:r[0],assignmentTtlMs:0}:null}},decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}},o={track:s=>u.track(s),goal:((s,r,i,c)=>u.goal(s,r,i,c)),componentGoal:(s,r,i)=>u.componentGoal(s,r,i),identify:s=>u.identify(s),getAssignment:(s,r)=>u.getAssignment(s,r),assign:(s,r,i,c)=>u.assign(s,r,i,c),decide:s=>u.decide(s),getSlotResult:s=>u.getSlotResult(s),getPersona:()=>u.getPersona(),fetchWeights:()=>u.fetchWeights(),getGraph:()=>u.getGraph(),dispose:()=>u.dispose(),destroy:()=>u.destroy()};function g(s){u=s}return{proxy:o,setInner:g}}function rt(e){var J,re,m,S,j,U,z,V,Ke;if(typeof window=="undefined")return ye;tt=e.apiKey;let t=P.get(e.apiKey||"local");if(t!=null&&t.dispose)try{t.dispose()}catch(a){}let n=e.respectDoNotTrack!==!1&&Ge(),d=e.consent===!1||n,u=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!u&&e.localMode!==!1)return d?(P.set(e.apiKey||"local",{config:e,upgrade:null}),ye):(P.set(e.apiKey||"local",{config:e,upgrade:null}),qe(e));if(d){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."),P.set(e.apiKey,{config:e,upgrade:null}),ye;let{proxy:a,setInner:p}=Wt(e);return P.set(e.apiKey,{config:e,upgrade:n?null:p}),a}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."),ye;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),ye;let o=(J=e.ingestUrl)!=null?J:et,g=Date.now(),l=ve({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),s=Qe(void 0,e.apiKey),r=We({ingestUrl:o,apiKey:e.apiKey}),i=nt(o),c={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},y=je({url:`${i}/goals`,apiKey:e.apiKey,headers:c,onDrop:(a,p)=>{e.debug&&console.warn(`[sentient] goal dropped (HTTP ${p}) \u2014 this will not be retried. `+(p===400?"The session was not found: call init() and let the session upsert complete before firing goals.":p===401||p===403?"Check the API key and that this origin is on the project allowlist.":"See the response status for the cause."),a)}}),b=ue((re=navigator.userAgent)!=null?re:""),D=typeof window!="undefined"?window.location.origin:void 0,R=ge((m=document.referrer)!=null?m:"",D),x=(S=e.sessionSegment)!=null?S:`${b}:${R}`,N=new Map,k=new Map,I=null,H=a=>{for(let p of a)k.has(p.id)||k.set(p.id,te(p))};if(e.initialSlots)for(let[a,p]of Object.entries(e.initialSlots))k.set(a,p);let A=Ce(e.apiKey);if(A)for(let[a,p]of Object.entries(A.slots))k.has(a)||k.set(a,p);let f={low:.15,medium:.5,high:.85};if(e.initialPersona)I=E({},e.initialPersona);else{let a=document.documentElement.dataset;a.sentientPersona?I={persona:a.sentientPersona,confidence:(U=f[(j=a.sentientConfidence)!=null?j:"low"])!=null?U:.15}:A&&(I={persona:A.persona,confidence:(z=f[A.band])!=null?z:.15})}if(e.initialAssignments)for(let[a,p]of Object.entries(e.initialAssignments))s.set(a,x,{variantId:p,assignedAt:Date.now(),segment:x,confidence:1});let v=Promise.resolve(),Q=l.getSessionId();if(Q){let a=pe((V=document.referrer)!=null?V:""),p=E(E({sessionId:Q,deviceClass:b,trafficSource:R,referrerDomain:a,utmParams:$t(),timeOfDay:fe(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:l.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||de((Ke=navigator.userAgent)!=null?Ke:"")},e.userId?{userId:e.userId}:{}),e.country?{country:e.country}:{});try{v=fetch(`${i}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(p),headers:c}).then(h=>{h.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(h){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:r});let G=new Set,L={goal(a,p={},h=1,B=0){var T,oe,W,se;let O=l.getSessionId();if(!O)return;let w=Ut(p)?p:{metadata:p},$=`${a}\0${(T=w.externalId)!=null?T:""}`;if(G.has($)){e.debug&&console.log(`[sentient] goal("${a}") already recorded for this action \u2014 not sent twice`);return}G.add($),G.size===1&&setTimeout(()=>G.clear(),0);let K=Le(),_={sessionId:O,name:a,metadata:(oe=w.metadata)!=null?oe:{},weight:(W=w.weight)!=null?W:h,stepIndex:(se=w.stepIndex)!=null?se:B,goalId:K,value:w.value,currency:w.currency,externalId:w.externalId};e.debug&&console.log("[sentient] goal",_);let F={id:K,body:JSON.stringify(_)};v.then(()=>y.send(F))},componentGoal(a,p,h){var _,F,T;let B=l.getSessionId();if(!B)return;let O=s.get(a,x),w=O?null:(_=k.get(a))!=null?_:null;if(!O&&w===null){e.debug&&console.warn(`[sentient] componentGoal("${a}"): no assignment or slot decision yet \u2014 render its <Adaptive>/adaptive hook or call assign()/decide() before recording a goal.`);return}let $=O?O.variantId:ke(w),K={id:Le(),sessionId:B,projectId:e.apiKey,componentId:a,variantId:$,eventType:"goal_achieved",goalType:p,payload:E({reward:(F=h==null?void 0:h.reward)!=null?F:1,goalValue:h==null?void 0:h.value,currency:h==null?void 0:h.currency},(T=h==null?void 0:h.metadata)!=null?T:{}),timestamp:Date.now(),timeInSession:Date.now()-g,path:Ne()};e.debug&&console.log("[sentient] componentGoal",K),v.then(()=>r.push(K))},identify(a){let p=l.getSessionId();p&&v.then(()=>{fetch(`${i}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:p,userId:a,ephemeral:l.isEphemeral()}),headers:c}).catch(()=>{})})},track(a){let p=l.getSessionId();if(!p)return;let h=X(E({path:Ne()},a),{id:Le(),sessionId:p,timestamp:Date.now(),timeInSession:Date.now()-g});e.debug&&console.log("[sentient] track",h),v.then(()=>r.push(h))},getAssignment(a,p){return s.get(a,p)},async assign(a,p,h,B){let O=l.getSessionId();if(!O)return null;let w=s.get(a,x);if(w&&(p!=null&&p.length||w.content!==void 0)){let _=w.ttlMs&&w.ttlMs>0?Math.max(0,w.assignedAt+w.ttlMs-Date.now()):0;return{variantId:w.variantId,assignmentTtlMs:_,content:w.content}}let $=N.get(a);if($)return $;let K=(async()=>{await v;try{let _={sessionId:O,componentId:a,variantIds:p};B!==void 0?_.agentDataByVariant=B:h!==void 0&&(_.agentData=h);let F=await fetch(`${i}/assign`,{method:"POST",body:JSON.stringify(_),headers:c});if(!F.ok)return null;let T=await F.json();return s.set(a,x,E({variantId:T.variantId,assignedAt:Date.now(),segment:x,confidence:1,content:T.content},T.assignmentTtlMs&&T.assignmentTtlMs>0?{ttlMs:T.assignmentTtlMs}:{})),T}catch(_){return null}finally{N.delete(a)}})();return N.set(a,K),K},async decide(a){var B,O,w,$,K,_,F,T,oe;let p=l.getSessionId();if(!p)return null;let h=(B=a.slots)!=null?B:[];await v;try{let W={sessionId:p};a.sections&&a.sections.length>0&&(W.sections=a.sections.map(M=>({id:M}))),W.components=(O=a.components)!=null?O:[],h.length>0&&(W.slots=h.map(me)),a.slotsFrom==="registry"&&(W.slotsFrom="registry"),a.v&&(W.v=a.v);let se=await fetch(`${i}/decide`,{method:"POST",body:JSON.stringify(W),headers:c});if(!se.ok)return H(h),null;let C=await se.json(),ie={};for(let M of h)ie[M.id]=($=(w=C.slots)==null?void 0:w[M.id])!=null?$:te(M);if(C.slots)for(let[M,ae]of Object.entries(C.slots))M in ie||(ie[M]=ae);for(let[M,ae]of Object.entries(ie))k.set(M,ae);let ot=I!=null&&I.persona!=="unknown";C.persona&&!(C.persona==="unknown"&&ot)?I={persona:C.persona,confidence:(K=C.confidence)!=null?K:0}:I||(I={persona:"unknown",confidence:0});for(let[M,ae]of Object.entries((_=C.assignments)!=null?_:{}))s.set(M,x,{variantId:ae,assignedAt:Date.now(),segment:x,confidence:1});return ne(e.apiKey,E({v:1,persona:I.persona,band:(0,Me.confidenceBand)(I.confidence),slots:Object.fromEntries(k),layoutOrder:(F=C.layoutOrder)!=null?F:null,savedAt:Date.now()},C.slotConfig?{slotConfig:C.slotConfig}:{})),E(E(E({layoutOrder:(T=C.layoutOrder)!=null?T:null,assignments:(oe=C.assignments)!=null?oe:{},slots:ie,persona:I.persona,confidence:I.confidence},C.slotConfig?{slotConfig:C.slotConfig}:{}),C.goals?{goals:C.goals}:{}),C.sectionMap?{sectionMap:C.sectionMap}:{})}catch(W){return H(h),null}},getSlotResult(a){var p;return(p=k.get(a))!=null?p:null},getPersona(){return I?{persona:I.persona,confidence:I.confidence,band:(0,Me.confidenceBand)(I.confidence)}:null},async fetchWeights(){var a;try{let p=await fetch(`${i}/weights`,{headers:c});return p.ok?(a=(await p.json()).components)!=null?a:[]:[]}catch(p){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){var a;r.destroy(),y.destroy(),((a=P.get(e.apiKey))==null?void 0:a.dispose)===L.dispose&&P.delete(e.apiKey),e.debug&&console.log("[sentient] disposed")},destroy(){var a;r.destroy(),y.destroy(),l.destroy(),((a=P.get(e.apiKey))==null?void 0:a.dispose)===L.dispose&&P.delete(e.apiKey);try{localStorage.removeItem(Y+e.apiKey),localStorage.removeItem(Te(e.apiKey)),localStorage.removeItem(De(e.apiKey))}catch(p){}e.debug&&console.log("[sentient] destroyed")}};if(P.set(e.apiKey,{config:e,upgrade:null,dispose:L.dispose}),Bt(L,e.apiKey),e.debug){let a=window;a.__sentient&&(a.__sentient.client=L)}return L}0&&(module.exports={AGENT_INTENTS,LOCAL_MODE_BANNER,PROD_KEYLESS_ERROR,SNAPSHOT_STORAGE_KEY_PREFIX,agentIntent,agentUaList,armOfResult,attachMicroSignalDetectors,baselineResultFor,baselineSlots,classifiedAgents,deriveSessionSegment,detectDeviceClass,detectTimeOfDay,detectTrafficSource,grantConsent,init,isDoNotTrackEnabled,matchedAgentToken,readSnapshot,referrerDomainFromReferer,renderPrePaintScript,toWireSlot,uaTokenMatch,writeSnapshot});
|
|
1
|
+
"use strict";var lt=Object.create;var ue=Object.defineProperty,ct=Object.defineProperties,dt=Object.getOwnPropertyDescriptor,ut=Object.getOwnPropertyDescriptors,gt=Object.getOwnPropertyNames,$e=Object.getOwnPropertySymbols,pt=Object.getPrototypeOf,We=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable;var Fe=(e,t,n)=>t in e?ue(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,k=(e,t)=>{for(var n in t||(t={}))We.call(t,n)&&Fe(e,n,t[n]);if($e)for(var n of $e(t))ft.call(t,n)&&Fe(e,n,t[n]);return e},te=(e,t)=>ct(e,ut(t));var mt=(e,t)=>{for(var n in t)ue(e,n,{get:t[n],enumerable:!0})},je=(e,t,n,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let u of gt(t))!We.call(e,u)&&u!==n&&ue(e,u,{get:()=>t[u],enumerable:!(c=dt(t,u))||c.enumerable});return e};var yt=(e,t,n)=>(n=e!=null?lt(pt(e)):{},je(t||!e||!e.__esModule?ue(n,"default",{value:e,enumerable:!0}):n,e)),ht=e=>je(ue({},"__esModule",{value:!0}),e);var zt={};mt(zt,{AGENT_INTENTS:()=>Re,LOCAL_MODE_BANNER:()=>Ge,PROD_KEYLESS_ERROR:()=>Oe,SNAPSHOT_STORAGE_KEY_PREFIX:()=>Z,agentIntent:()=>ze,agentUaList:()=>ge,armOfResult:()=>Ae,attachMicroSignalDetectors:()=>tt,baselineResultFor:()=>se,baselineSlots:()=>Xe,classifiedAgents:()=>Ve,deriveSessionSegment:()=>Ye,detectDeviceClass:()=>fe,detectTimeOfDay:()=>he,detectTrafficSource:()=>me,grantConsent:()=>Ht,init:()=>it,isDoNotTrackEnabled:()=>Be,matchedAgentToken:()=>Ne,readSnapshot:()=>_e,referrerDomainFromReferer:()=>ye,renderPrePaintScript:()=>qe,toWireSlot:()=>Se,uaTokenMatch:()=>pe,writeSnapshot:()=>ie});module.exports=ht(zt);function we(){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)})}function be(e){return e?`_${e.slice(0,12)}`:""}var St="_snt_uid",vt=365,wt="_snt_uid";function bt(){return we()}function xt(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function It(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(c){}}function Et(e){try{return localStorage.getItem(e)}catch(t){return null}}function kt(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function Ct(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function Rt(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function At(e){try{sessionStorage.removeItem(e)}catch(t){}}function _t(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 Tt(e){try{localStorage.removeItem(e)}catch(t){}}function Dt(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var Ot={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function xe(e){var y,b,D,R,I,M;if(typeof window=="undefined")return Ot;let t=be(e==null?void 0:e.apiKey),n=(y=e==null?void 0:e.cookieName)!=null?y:`${St}${t}`,c=`${wt}${t}`,s=((b=e==null?void 0:e.cookieTTLDays)!=null?b:vt)*24*60*60,g=C=>C&&C.length>0?C:null,d=(M=(I=(R=(D=g(xt(n)))!=null?D:g(Et(c)))!=null?R:g(Ct(c)))!=null?I:g(e==null?void 0:e.ssrSessionId))!=null?M:bt();It(n,d,s);let o=kt(c,d),r=_t(n),i=o?!1:Rt(c,d),a=!o&&!r&&!i;return{getSessionId:()=>d,isEphemeral:()=>a,destroy:()=>{d=null,Dt(n),Tt(c),At(c)}}}function ne(e){return Math.min(6e4,1e3*2**Math.min(e,6))}function Ie(e){if(e.ok===!0)return"delivered";let{status:t}=e;return typeof t!="number"?"retry":t>=200&&t<300?"delivered":t>=400&&t<500&&t!==429?"dropped":"retry"}function Ee(e,t){try{let n=localStorage.getItem(e);if(!n)return[];let c=JSON.parse(n);return Array.isArray(c)?(localStorage.removeItem(e),c.slice(-t)):[]}catch(n){return[]}}function re(e,t,n){try{let c=(()=>{try{let s=localStorage.getItem(n);if(!s)return[];let g=JSON.parse(s);return Array.isArray(g)?g:[]}catch(s){return[]}})(),u=new Map;for(let s of c)u.set(s.id,s);for(let s of e)u.set(s.id,s);localStorage.setItem(n,JSON.stringify([...u.values()].slice(-t)))}catch(c){}}function ke(e,t){try{let n=localStorage.getItem(t);if(!n)return;let c=JSON.parse(n);if(!Array.isArray(c))return;let u=new Set(e),s=c.filter(g=>!u.has(g.id));if(s.length===c.length)return;s.length===0?localStorage.removeItem(t):localStorage.setItem(t,JSON.stringify(s))}catch(n){}}var Pt=500,Lt=56*1024;function Le(e){return`_snt_retry_${e.slice(0,12)}`}var Mt={push:()=>{},flush:()=>{},destroy:()=>{}};function Qe(e){var O,j,Q;if(typeof window=="undefined")return Mt;let t=(O=e.flushIntervalMs)!=null?O:5e3,n=(j=e.maxBatchSize)!=null?j:20,c=(Q=e.maxRetrySize)!=null?Q:100,u=e.ingestUrl,s=e.apiKey,g=Le(s),d=[],o=new Set,r=[],i=f=>{for(let S of f)a.delete(S),!o.has(S)&&(o.add(S),r.push(S));for(;r.length>Pt;){let S=r.shift();S&&o.delete(S)}ke(f,g)},a=new Set,y=f=>{o.has(f.id)||a.has(f.id)||(a.add(f.id),d.push(f))},b=f=>{for(let S of f)o.has(S.id)||(a.add(S.id),d.push(S))},D=Ee(g,c);for(let f of D)y(f);let R=0,I=0,M=(f,S=!0)=>{if(f.length===0)return;let H=JSON.stringify(f),q=f.map(z=>z.id),B;try{B=fetch(u,{method:"POST",keepalive:!0,body:H,headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`}})}catch(z){re(f,c,g),b(f),I++,R=Date.now()+ne(I);return}let ae=z=>{if(Ie(z)!=="retry"){if(!z.ok&&S){let ee=f.filter(V=>V.eventType!=="pageview");if(ee.length>0&&ee.length<f.length){i(f.filter(V=>V.eventType==="pageview").map(V=>V.id)),M(ee,!1);return}}i(q),I=0,R=0;return}re(f,c,g),b(f),I++,R=Date.now()+ne(I)};B instanceof Promise?B.then(ae).catch(()=>{re(f,c,g),b(f),I++,R=Date.now()+ne(I)}):ae(B)},C=typeof TextEncoder!="undefined"?new TextEncoder:null,E=f=>C?C.encode(f).length:f.length,X=f=>{let S=[],H=2;for(let q of f){let B=E(JSON.stringify(q))+1;if(S.length>0&&H+B>Lt||S.length>=n)break;S.push(q),H+=B}return S},A=()=>{try{if(Date.now()<R)return;for(;d.length>0&&!(Date.now()<R);){let f=d.filter(H=>!o.has(H.id));if(d.length=0,f.length===0)break;let S=X(f);if(S.length===0)break;S.length<f.length&&d.push(...f.slice(S.length)),M(S)}}catch(f){}},m=!0,v=null;v=setInterval(()=>{m&&A()},t);let J=()=>{document.visibilityState==="hidden"&&A()},G=()=>{A()};return document.addEventListener("visibilitychange",J),window.addEventListener("pagehide",G),{push(f){y(f),d.length>=n&&A()},flush:A,destroy(){m=!1,v!==null&&(clearInterval(v),v=null),document.removeEventListener("visibilitychange",J),window.removeEventListener("pagehide",G),A()}}}var Nt=200;function Me(e){return`_snt_goal_retry_${e.slice(0,12)}`}var Gt={send:()=>{},flush:()=>{},destroy:()=>{}};function He(e){var E,X,A;if(typeof window=="undefined")return Gt;let t=(E=e.flushIntervalMs)!=null?E:5e3,n=(X=e.maxRetrySize)!=null?X:100,c=(A=e.maxPerFlush)!=null?A:5,u=Me(e.apiKey),s=[],g=new Set,d=new Set,o=[],r=0,i=0,a=!1,y=m=>{for(g.delete(m.id),d.has(m.id)||(d.add(m.id),o.push(m.id));o.length>Nt;){let v=o.shift();v&&d.delete(v)}ke([m.id],u)},b=m=>{re([m],n,u),!d.has(m.id)&&!g.has(m.id)&&(g.add(m.id),s.push(m)),i++,r=Date.now()+ne(i)},D=m=>{let v;try{v=fetch(e.url,{method:"POST",keepalive:!0,body:m.body,headers:e.headers})}catch(G){b(m);return}let J=G=>{var j;let O=Ie(G);if(O==="retry"){b(m);return}O==="dropped"&&((j=e.onDrop)==null||j.call(e,m,G.status)),y(m),i=0,r=0};v instanceof Promise?v.then(J).catch(()=>b(m)):J(v)},R=()=>{try{if(a||Date.now()<r)return;let m=0;for(;s.length>0&&m<c&&!(Date.now()<r);){let v=s.shift();g.delete(v.id),!d.has(v.id)&&(m++,D(v))}}catch(m){}};for(let m of Ee(u,n))g.has(m.id)||(g.add(m.id),s.push(m));let I=setInterval(R,t),M=()=>{document.visibilityState==="hidden"&&R()},C=()=>R();return document.addEventListener("visibilitychange",M),window.addEventListener("pagehide",C),{send(m){if(!a&&!(d.has(m.id)||g.has(m.id))){if(Date.now()<r){g.add(m.id),s.push(m);return}D(m)}},flush:R,destroy(){clearInterval(I),document.removeEventListener("visibilitychange",M),window.removeEventListener("pagehide",C),R(),a=!0}}}var Kt=1800*1e3;function Ce(e,t){return`${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function Je(e=Kt,t){let n=new Map,c=`_snt_asgn${be(t)}_`,u=(r,i)=>`${c}${encodeURIComponent(r)}:${encodeURIComponent(i)}`,s=r=>{let i=r.slice(c.length),a=i.indexOf(":");if(a<0)return null;try{return{componentId:decodeURIComponent(i.slice(0,a)),segment:decodeURIComponent(i.slice(a+1))}}catch(y){return null}},g=()=>{try{let r=[];for(let i=0;i<localStorage.length;i++){let a=localStorage.key(i);a!=null&&a.startsWith(c)&&r.push(a)}return r}catch(r){return[]}},d=r=>r.assignedAt+(r.ttlMs&&r.ttlMs>0?r.ttlMs:e)<Date.now();return typeof window!="undefined"&&(()=>{for(let r of g())try{let i=localStorage.getItem(r);if(!i)continue;let a=JSON.parse(i);if(d(a)){localStorage.removeItem(r);continue}let y=s(r);if(!y)continue;n.set(Ce(y.componentId,y.segment),a)}catch(i){}})(),{get(r,i){let a=n.get(Ce(r,i));return a?d(a)?(n.delete(Ce(r,i)),null):a:null},set(r,i,a){let y=Ce(r,i);n.set(y,a);try{localStorage.setItem(u(r,i),JSON.stringify(a))}catch(b){}},invalidate(r){let i=`${encodeURIComponent(r)}:`;for(let a of[...n.keys()])a.startsWith(i)&&n.delete(a);for(let a of g()){let y=s(a);if((y==null?void 0:y.componentId)===r)try{localStorage.removeItem(a)}catch(b){}}},clear(){n.clear();for(let r of g())try{localStorage.removeItem(r)}catch(i){}}}}var ge=["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 pe(e){return Ne(e)!==null}function Ne(e){var n;if(!e)return null;let t=e.toLowerCase();return(n=ge.find(c=>t.includes(c.toLowerCase())))!=null?n:null}var Re={GPTBot:"training","ChatGPT-User":"user","OAI-SearchBot":"search",ClaudeBot:"training","Claude-User":"user","Claude-SearchBot":"search",PerplexityBot:"search","Perplexity-User":"user","Google-Extended":"training","Applebot-Extended":"training","Meta-ExternalAgent":"training",Bytespider:"training",CCBot:"training",Amazonbot:"other","cohere-ai":"training",Diffbot:"other"};function ze(e){if(!e)return"other";let t=ge.find(n=>n.toLowerCase()===e.toLowerCase());return t&&Re[t]||"other"}function Ve(){var t;let e={user:[],search:[],training:[],other:[]};for(let n of ge)e[(t=Re[n])!=null?t:"other"].push(n);return e}function fe(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 me(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(u){}let c=n.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(c)?"search":/(^|\.)(twitter\.com|x\.com|facebook\.com|linkedin\.com|reddit\.com|t\.co)$/.test(c)?"social":"referral"}catch(n){return"direct"}}function ye(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function he(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function Ye(e){let t=Ut("__segment__",e);return`${t.deviceClass}:${t.trafficSource}`}function Ut(e,t){var s,g,d,o,r,i,a;let n=(g=(s=t==null?void 0:t.userAgent)==null?void 0:s.trim())!=null?g:"",c=(o=(d=t==null?void 0:t.referer)==null?void 0:d.trim())!=null?o:"",u=(r=t==null?void 0:t.now)!=null?r:new Date;return{sessionId:e,ephemeral:!1,utmParams:(i=t==null?void 0:t.utmParams)!=null?i:{},deviceClass:n?fe(n):"desktop",trafficSource:c?me(c,t==null?void 0:t.appOrigin):"direct",referrerDomain:ye(c),timeOfDay:he(u),dayOfWeek:(a=["sun","mon","tue","wed","thu","fri","sat"][u.getDay()])!=null?a:"sun",automation:(t==null?void 0:t.webdriver)===!0||pe(n)}}var oe=require("@sentientui/policy");function Se(e){return k(k(k({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 se(e){let t=Se(e);return(0,oe.slotResultFor)(t,(0,oe.slotBaselineArm)(t))}function Xe(e){let t={};for(let n of e)t[n.id]=se(n);return t}function Ae(e){return typeof e=="string"?e:(0,oe.canonicalArm)(e)}var Z="_snt_snap:",Bt=["low","medium","high"];function _e(e){try{let t=localStorage.getItem(Z+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"||!Bt.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 ie(e,t){try{localStorage.setItem(Z+e,JSON.stringify(t))}catch(n){}}function qe(e){return"(function(){try{var r=localStorage.getItem("+JSON.stringify(Z+e).replace(/</g,"\\u003c")+');if(!r)return;var s=JSON.parse(r);if(!s||s.v!==1||typeof s.persona!=="string"||typeof s.band!=="string")return;var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",s.persona);d.setAttribute("data-sentient-confidence",s.band);}catch(e){}})();'}var Ue=require("@sentientui/policy");var De=require("@sentientui/policy");var Oe="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",Ge="[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.",Ze=!1,Te=!1;function $t(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(t){return}}function et(e){var d;let t=xe({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),n=(d=t.getSessionId())!=null?d:"local",c=$t(),u=import("@sentientui/core/local").then(o=>{let r=o;return r.LOCAL_ENGINE_AVAILABLE?(Ze||(Ze=!0,console.info(Ge)),r):(Te||(Te=!0,console.error(Oe)),null)}).catch(()=>(Te||(Te=!0,console.error(Oe)),null)),s=null;function g(o){let r=document.documentElement;r.dataset.sentientPersona===void 0&&(r.dataset.sentientPersona=o.persona,r.dataset.sentientConfidence=(0,De.confidenceBand)(o.confidence))}return{isLocal:!0,async decide(o){var a,y,b;let r=await u;if(!r)return null;let i=r.createLocalEngine({sessionId:n,forcedPersona:c}).decide(o);return s=te(k({},i),{layoutOrder:(y=(a=i.layoutOrder)!=null?a:s==null?void 0:s.layoutOrder)!=null?y:null,slots:k(k({},(b=s==null?void 0:s.slots)!=null?b:{}),i.slots)}),ie(e.apiKey||"local",{v:1,persona:s.persona,band:(0,De.confidenceBand)(s.confidence),slots:s.slots,layoutOrder:s.layoutOrder,savedAt:Date.now()}),g(i),i},getSlotResult(o){var r,i,a;return(a=(i=s==null?void 0:s.slots[o])!=null?i:(r=e.initialSlots)==null?void 0:r[o])!=null?a:null},getPersona(){return s?{persona:s.persona,confidence:s.confidence,band:(0,De.confidenceBand)(s.confidence)}:null},async assign(o,r){var y;let i=await u;return!i||!r||r.length===0?r!=null&&r[0]?{variantId:r[0],assignmentTtlMs:0}:null:{variantId:(y=i.createLocalEngine({sessionId:n,forcedPersona:c}).decide({components:[{id:o,variantIds:r}]}).assignments[o])!=null?y:r[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>t.destroy()}}function tt(e,t,n,c){let u=[];{let d=!1,o=[],r=()=>{if(d)return;let i=Date.now();for(o.push(i);o.length>0&&i-o[0]>500;)o.shift();o.length>=3&&(d=!0,e("rage_click"))};t.addEventListener("click",r),u.push(()=>t.removeEventListener("click",r))}{let s=!1,g=d=>{if(s||!(d.target instanceof Node)||!t.contains(d.target)&&t!==d.target)return;s=!0;let o=typeof window!="undefined"?window.getSelection():null,r=o?o.toString().length:0;e("text_copy",{selectionLength:r})};document.addEventListener("copy",g),u.push(()=>document.removeEventListener("copy",g))}{let s=!1,g=!1,d=null,o=()=>{d!==null&&(clearTimeout(d),d=null)},r=()=>{s||!g||(o(),d=setTimeout(()=>{!s&&g&&(s=!0,e("scroll_hesitation"))},3e3))},i=()=>{o(),r()},a=b=>{for(let D of b)g=D.intersectionRatio>.3,g?r():o()},y=new IntersectionObserver(a,{threshold:[.3]});y.observe(t),window.addEventListener("scroll",i,{passive:!0}),u.push(()=>{y.disconnect(),window.removeEventListener("scroll",i),o()})}if((c==null?void 0:c.tabLoss)!==!1){let s=!1,g=n!=null?n:Date.now(),d=()=>{if(s||document.visibilityState!=="hidden")return;let o=Date.now()-g;o<15e3&&(s=!0,e("tab_loss",{timeOnPage:o}))};document.addEventListener("visibilitychange",d),u.push(()=>document.removeEventListener("visibilitychange",d))}return()=>{for(let s of u)s()}}var nt="https://api.sentient-ui.com/v1/events",L=new Map,rt=null;function Ft(e){return"value"in e||"currency"in e||"externalId"in e||"metadata"in e||"weight"in e||"stepIndex"in e}function Ke(){return we()}function Pe(){var e;if(typeof window!="undefined")return((e=window.location)==null?void 0:e.pathname)||void 0}function Wt(e){if(typeof MessageChannel=="function"){let t=new MessageChannel;t.port1.onmessage=()=>{e.clear(),t.port1.close(),t.port2.close()},t.port2.postMessage(0)}else setTimeout(()=>e.clear(),0)}var ot=new Set;function jt(e,t,n){let c=typeof window=="undefined"?null:window.history;if(!c)return()=>{};let u=!1,s,g=()=>{if(u)return;let r=Pe();!r||r===s||(s=r,e.track({projectId:t,componentId:"__page__",eventType:"pageview",payload:{}}),n(`${t}:${r}`))},d=[];for(let r of["pushState","replaceState"]){let i=c[r],a=function(...y){let b=i.apply(this,y);return g(),b};c[r]=a,d.push([r,i,a])}window.addEventListener("popstate",g);let o=Pe();return o&&ot.has(`${t}:${o}`)?s=o:g(),()=>{if(!u){u=!0,window.removeEventListener("popstate",g);for(let[r,i,a]of d)c[r]===a&&(c[r]=i)}}}var ve={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 Qt(){try{let e={},t=new URLSearchParams(window.location.search);for(let[n,c]of t)n.startsWith("utm_")&&(e[n]=c);return e}catch(e){return{}}}function st(e){return e.replace(/\/events\/?$/,"")}function Be(){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 Ht(e){var d;if(typeof window=="undefined")return;let t=e!=null?e:rt;if(!t){console.warn("[sentient] grantConsent() called before init()");return}let n=L.get(t);if(!n){console.warn("[sentient] grantConsent() called before init()");return}let{config:c,upgrade:u}=n;if(!u||c.respectDoNotTrack!==!1&&Be())return;let s=it(te(k({},c),{consent:!0}));u(s);let g=(d=L.get(t))==null?void 0:d.dispose;L.set(t,{config:te(k({},c),{consent:!0}),upgrade:null,dispose:g})}function Jt(e){var d;let t=e.preConsentBehavior==="statistical_winner",n=st((d=e.ingestUrl)!=null?d:nt),c={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},u={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),async assign(o,r,i){if(!t)return null;try{let a=new URLSearchParams({componentId:o});for(let D of r!=null?r:[])a.append("variantIds[]",D);let y=await fetch(`${n}/winner?${a.toString()}`,{headers:c});return y.ok?{variantId:(await y.json()).variantId,assignmentTtlMs:0}:r!=null&&r[0]?{variantId:r[0],assignmentTtlMs:0}:null}catch(a){return r!=null&&r[0]?{variantId:r[0],assignmentTtlMs:0}:null}},decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}},s={track:o=>u.track(o),goal:((o,r,i,a)=>u.goal(o,r,i,a)),componentGoal:(o,r,i)=>u.componentGoal(o,r,i),identify:o=>u.identify(o),getAssignment:(o,r)=>u.getAssignment(o,r),assign:(o,r,i,a)=>u.assign(o,r,i,a),decide:o=>u.decide(o),getSlotResult:o=>u.getSlotResult(o),getPersona:()=>u.getPersona(),fetchWeights:()=>u.fetchWeights(),getGraph:()=>u.getGraph(),dispose:()=>u.dispose(),destroy:()=>u.destroy()};function g(o){u=o}return{proxy:s,setInner:g}}function it(e){var f,S,H,q,B,ae,z,ee,V;if(typeof window=="undefined")return ve;rt=e.apiKey;let t=L.get(e.apiKey||"local");if(t!=null&&t.dispose)try{t.dispose()}catch(l){}let n=e.respectDoNotTrack!==!1&&Be(),c=e.consent===!1||n,u=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!u&&e.localMode!==!1)return c?(L.set(e.apiKey||"local",{config:e,upgrade:null}),ve):(L.set(e.apiKey||"local",{config:e,upgrade:null}),et(e));if(c){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."),L.set(e.apiKey,{config:e,upgrade:null}),ve;let{proxy:l,setInner:p}=Jt(e);return L.set(e.apiKey,{config:e,upgrade:n?null:p}),l}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."),ve;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),ve;let s=(f=e.ingestUrl)!=null?f:nt,g=Date.now(),d=xe({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),o=Je(void 0,e.apiKey),r=Qe({ingestUrl:s,apiKey:e.apiKey}),i=st(s),a={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},y=He({url:`${i}/goals`,apiKey:e.apiKey,headers:a,onDrop:(l,p)=>{e.debug&&console.warn(`[sentient] goal dropped (HTTP ${p}) \u2014 this will not be retried. `+(p===400?"The session was not found: call init() and let the session upsert complete before firing goals.":p===401||p===403?"Check the API key and that this origin is on the project allowlist.":"See the response status for the cause."),l)}}),b=fe((S=navigator.userAgent)!=null?S:""),D=typeof window!="undefined"?window.location.origin:void 0,R=me((H=document.referrer)!=null?H:"",D),I=(q=e.sessionSegment)!=null?q:`${b}:${R}`,M=new Map,C=new Map,E=null,X=l=>{for(let p of l)C.has(p.id)||C.set(p.id,se(p))};if(e.initialSlots)for(let[l,p]of Object.entries(e.initialSlots))C.set(l,p);let A=_e(e.apiKey);if(A)for(let[l,p]of Object.entries(A.slots))C.has(l)||C.set(l,p);let m={low:.15,medium:.5,high:.85};if(e.initialPersona)E=k({},e.initialPersona);else{let l=document.documentElement.dataset;l.sentientPersona?E={persona:l.sentientPersona,confidence:(ae=m[(B=l.sentientConfidence)!=null?B:"low"])!=null?ae:.15}:A&&(E={persona:A.persona,confidence:(z=m[A.band])!=null?z:.15})}if(e.initialAssignments)for(let[l,p]of Object.entries(e.initialAssignments))o.set(l,I,{variantId:p,assignedAt:Date.now(),segment:I,confidence:1});let v=Promise.resolve(),J=d.getSessionId();if(J){let l=ye((ee=document.referrer)!=null?ee:""),p=k(k({sessionId:J,deviceClass:b,trafficSource:R,referrerDomain:l,utmParams:Qt(),timeOfDay:he(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:d.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||pe((V=navigator.userAgent)!=null?V:"")},e.userId?{userId:e.userId}:{}),e.country?{country:e.country}:{});try{v=fetch(`${i}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(p),headers:a}).then(h=>{h.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(h){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:r});let G=new Set,O=null,j=!1,Q={goal(l,p={},h=1,K=0){var T,le,W,ce,x,Y;let P=d.getSessionId();if(!P)return;let w=Ft(p)?p:{metadata:p},$=`${l}\0${(T=w.externalId)!=null?T:""}\0${(le=w.stepIndex)!=null?le:K}\0${(W=w.weight)!=null?W:h}`;if(G.has($)){e.debug&&console.log(`[sentient] goal("${l}") already recorded for this action \u2014 not sent twice`);return}G.add($),G.size===1&&Wt(G);let U=Ke(),_={sessionId:P,name:l,metadata:(ce=w.metadata)!=null?ce:{},weight:(x=w.weight)!=null?x:h,stepIndex:(Y=w.stepIndex)!=null?Y:K,goalId:U,value:w.value,currency:w.currency,externalId:w.externalId};e.debug&&console.log("[sentient] goal",_);let F={id:U,body:JSON.stringify(_)};v.then(()=>y.send(F))},componentGoal(l,p,h){var _,F,T;let K=d.getSessionId();if(!K)return;let P=o.get(l,I),w=P?null:(_=C.get(l))!=null?_:null;if(!P&&w===null){e.debug&&console.warn(`[sentient] componentGoal("${l}"): no assignment or slot decision yet \u2014 render its <Adaptive>/adaptive hook or call assign()/decide() before recording a goal.`);return}let $=P?P.variantId:Ae(w),U={id:Ke(),sessionId:K,projectId:e.apiKey,componentId:l,variantId:$,eventType:"goal_achieved",goalType:p,payload:k({reward:(F=h==null?void 0:h.reward)!=null?F:1,goalValue:h==null?void 0:h.value,currency:h==null?void 0:h.currency},(T=h==null?void 0:h.metadata)!=null?T:{}),timestamp:Date.now(),timeInSession:Date.now()-g,path:Pe()};e.debug&&console.log("[sentient] componentGoal",U),v.then(()=>r.push(U))},identify(l){let p=d.getSessionId();p&&v.then(()=>{fetch(`${i}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:p,userId:l,ephemeral:d.isEphemeral()}),headers:a}).catch(()=>{})})},track(l){let p=d.getSessionId();if(!p)return;let h=te(k({path:Pe()},l),{id:Ke(),sessionId:p,timestamp:Date.now(),timeInSession:Date.now()-g});e.debug&&console.log("[sentient] track",h),v.then(()=>r.push(h))},getAssignment(l,p){return o.get(l,p)},async assign(l,p,h,K){let P=d.getSessionId();if(!P)return null;let w=o.get(l,I);if(w&&(p!=null&&p.length||w.content!==void 0)){let _=w.ttlMs&&w.ttlMs>0?Math.max(0,w.assignedAt+w.ttlMs-Date.now()):0;return{variantId:w.variantId,assignmentTtlMs:_,content:w.content}}let $=M.get(l);if($)return $;let U=(async()=>{await v;try{let _={sessionId:P,componentId:l,variantIds:p};K!==void 0?_.agentDataByVariant=K:h!==void 0&&(_.agentData=h);let F=await fetch(`${i}/assign`,{method:"POST",body:JSON.stringify(_),headers:a});if(!F.ok)return null;let T=await F.json();return o.set(l,I,k({variantId:T.variantId,assignedAt:Date.now(),segment:I,confidence:1,content:T.content},T.assignmentTtlMs&&T.assignmentTtlMs>0?{ttlMs:T.assignmentTtlMs}:{})),T}catch(_){return null}finally{M.delete(l)}})();return M.set(l,U),U},async decide(l){var K,P,w,$,U,_,F,T,le;let p=d.getSessionId();if(!p)return null;let h=(K=l.slots)!=null?K:[];await v;try{let W={sessionId:p};l.sections&&l.sections.length>0&&(W.sections=l.sections.map(N=>({id:N}))),W.components=(P=l.components)!=null?P:[],h.length>0&&(W.slots=h.map(Se)),l.slotsFrom==="registry"&&(W.slotsFrom="registry"),l.v&&(W.v=l.v);let ce=await fetch(`${i}/decide`,{method:"POST",body:JSON.stringify(W),headers:a});if(!ce.ok)return X(h),null;let x=await ce.json(),Y={};for(let N of h)Y[N.id]=($=(w=x.slots)==null?void 0:w[N.id])!=null?$:se(N);if(x.slots)for(let[N,de]of Object.entries(x.slots))N in Y||(Y[N]=de);for(let[N,de]of Object.entries(Y))C.set(N,de);let at=E!=null&&E.persona!=="unknown";x.persona&&!(x.persona==="unknown"&&at)?E={persona:x.persona,confidence:(U=x.confidence)!=null?U:0}:E||(E={persona:"unknown",confidence:0});for(let[N,de]of Object.entries((_=x.assignments)!=null?_:{}))o.set(N,I,{variantId:de,assignedAt:Date.now(),segment:I,confidence:1});return ie(e.apiKey,k({v:1,persona:E.persona,band:(0,Ue.confidenceBand)(E.confidence),slots:Object.fromEntries(C),layoutOrder:(F=x.layoutOrder)!=null?F:null,savedAt:Date.now()},x.slotConfig?{slotConfig:x.slotConfig}:{})),k(k(k({layoutOrder:(T=x.layoutOrder)!=null?T:null,assignments:(le=x.assignments)!=null?le:{},slots:Y,persona:E.persona,confidence:E.confidence},x.slotConfig?{slotConfig:x.slotConfig}:{}),x.goals?{goals:x.goals}:{}),x.sectionMap?{sectionMap:x.sectionMap}:{})}catch(W){return X(h),null}},getSlotResult(l){var p;return(p=C.get(l))!=null?p:null},getPersona(){return E?{persona:E.persona,confidence:E.confidence,band:(0,Ue.confidenceBand)(E.confidence)}:null},async fetchWeights(){var l;try{let p=await fetch(`${i}/weights`,{headers:a});return p.ok?(l=(await p.json()).components)!=null?l:[]:[]}catch(p){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){var l;O==null||O(),j=!0,r.destroy(),y.destroy(),((l=L.get(e.apiKey))==null?void 0:l.dispose)===Q.dispose&&L.delete(e.apiKey),e.debug&&console.log("[sentient] disposed")},destroy(){var l;O==null||O(),j=!0,r.destroy(),y.destroy(),d.destroy(),((l=L.get(e.apiKey))==null?void 0:l.dispose)===Q.dispose&&L.delete(e.apiKey);try{localStorage.removeItem(Z+e.apiKey),localStorage.removeItem(Le(e.apiKey)),localStorage.removeItem(Me(e.apiKey))}catch(p){}e.debug&&console.log("[sentient] destroyed")}};if(L.set(e.apiKey,{config:e,upgrade:null,dispose:Q.dispose}),O=jt(Q,e.apiKey,l=>{v.then(()=>{j||ot.add(l)})}),e.debug){let l=window;l.__sentient&&(l.__sentient.client=Q)}return Q}0&&(module.exports={AGENT_INTENTS,LOCAL_MODE_BANNER,PROD_KEYLESS_ERROR,SNAPSHOT_STORAGE_KEY_PREFIX,agentIntent,agentUaList,armOfResult,attachMicroSignalDetectors,baselineResultFor,baselineSlots,classifiedAgents,deriveSessionSegment,detectDeviceClass,detectTimeOfDay,detectTrafficSource,grantConsent,init,isDoNotTrackEnabled,matchedAgentToken,readSnapshot,referrerDomainFromReferer,renderPrePaintScript,toWireSlot,uaTokenMatch,writeSnapshot});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|