@sentientui/react 0.23.0 → 0.24.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/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- var ct=Object.defineProperty,dt=Object.defineProperties;var ft=Object.getOwnPropertyDescriptors;var X=Object.getOwnPropertySymbols;var Ge=Object.prototype.hasOwnProperty,_e=Object.prototype.propertyIsEnumerable;var Ce=(e,t,n)=>t in e?ct(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,A=(e,t)=>{for(var n in t||(t={}))Ge.call(t,n)&&Ce(e,n,t[n]);if(X)for(var n of X(t))_e.call(t,n)&&Ce(e,n,t[n]);return e},q=(e,t)=>dt(e,ft(t));var Re=(e,t)=>{var n={};for(var r in e)Ge.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&X)for(var r of X(e))t.indexOf(r)<0&&_e.call(e,r)&&(n[r]=e[r]);return n};import{createContext as vt,useContext as L,useEffect as W,useMemo as We,useRef as $e,useState as ee,useSyncExternalStore as yt}from"react";import{detectDeviceClass as St,detectTrafficSource as ht,init as bt}from"@sentientui/core";var Oe=new Map,Q=new Map;function Ee(e,t){let n=Q.get(e);return n||(n=new Set,Q.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&Q.delete(e)}}function Ie(e,t){Oe.set(e,t);let n=Q.get(e);if(n)for(let r of n)try{r(t)}catch(o){}}function Le(e){var t;return(t=Oe.get(e))!=null?t:null}var gt={on:!1,listeners:new Set};function Pe(){if(typeof window=="undefined")return gt;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function de(){return Pe().on}function De(e){let t=Pe().listeners;return t.add(e),()=>{t.delete(e)}}function Te(e){return{isLocal:e.isLocal,track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},fetchWeights:()=>Promise.resolve([]),getAssignment:(t,n)=>e.getAssignment(t,n),assign:(t,n,r,o)=>e.assign(t,n,r,o),decide:()=>Promise.resolve(null),getSlotResult:t=>e.getSlotResult(t),getPersona:()=>e.getPersona(),getGraph:()=>e.getGraph(),dispose:()=>e.dispose(),destroy:()=>e.destroy()}}var Fe="sentient:overrides-changed";function fe(){var e;return typeof window=="undefined"?0:(e=window.__sentient_overrides_version)!=null?e:0}function F(e){return typeof window=="undefined"?()=>{}:(window.addEventListener(Fe,e),()=>window.removeEventListener(Fe,e))}function Me(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function R(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}function E(e){return typeof e=="string"?{type:"click"}:e}function N(e){return typeof e=="string"?e:e.type}function P(e){if(typeof e!="string"&&(e.type==="click"||e.type==="form_submit"||e.type==="scroll_depth"))return e.value}function mt(e){if(!(e instanceof Element))return!1;let t=e.tagName.toLowerCase();return t==="a"||t==="button"?!0:e.getAttribute("role")==="button"}function Be(e,t,n){if(n){try{let o=e;for(;o&&o!==t;){if(o.matches(n))return!0;o=o.parentElement}}catch(o){}return!1}let r=e;for(;r&&r!==t;){if(mt(r))return!0;r=r.parentElement}return!1}function D(e,t,n){if(t.type==="weighted_composite"){let s=new Set,d=[];return t.steps.forEach(({goal:a,name:y,weight:g},p)=>{let C=()=>{s.has(p)||(s.add(p),n.fireStep(y,g,p))};if(a.type==="click"){let w=f=>{let m=f.target;m instanceof Element&&Be(m,e,a.selector)&&C()};e.addEventListener("click",w),d.push(()=>e.removeEventListener("click",w));return}if(a.type==="form_submit"){let w=f=>{f.target instanceof HTMLFormElement&&e.contains(f.target)&&C()};e.addEventListener("submit",w),d.push(()=>e.removeEventListener("submit",w));return}if(a.type==="scroll_depth"){let w=Math.max(0,Math.min(1,a.threshold)),f=new IntersectionObserver(m=>{for(let l of m)if(l.intersectionRatio>=w){C(),f.disconnect();break}},{threshold:[w]});f.observe(e),d.push(()=>f.disconnect())}}),()=>{for(let a of d)a()}}let r=t.type==="composite"?t.all:[t],o=new Set(r.map((s,d)=>d)),i=s=>{o.delete(s),o.size===0&&n.fireGoal()},u=[];return r.forEach((s,d)=>{if(s.type==="click"){let a=y=>{let g=y.target;g instanceof Element&&Be(g,e,s.selector)&&(t.type==="composite"?i(d):n.fireGoal())};e.addEventListener("click",a),u.push(()=>e.removeEventListener("click",a));return}if(s.type==="form_submit"){let a=y=>{y.target instanceof HTMLFormElement&&e.contains(y.target)&&(t.type==="composite"?i(d):n.fireGoal())};e.addEventListener("submit",a),u.push(()=>e.removeEventListener("submit",a));return}if(s.type==="scroll_depth"){let a=Math.max(0,Math.min(1,s.threshold)),y=new IntersectionObserver(g=>{for(let p of g)if(p.intersectionRatio>=a){t.type==="composite"?i(d):n.fireGoal(),y.disconnect();break}},{threshold:[a]});y.observe(e),u.push(()=>y.disconnect());return}}),()=>{for(let s of u)s()}}var Ke=new Set,je=new Set;function B(e,t,n,r,o){let i=`${r}|${n}`;if(je.has(i))return;je.add(i);let u=o.type==="weighted_composite"&&!Ke.has(r);u&&Ke.add(r),e.track({projectId:t,componentId:n,eventType:"funnel_declared",payload:u?{funnelId:r,steps:o.steps.map(s=>({goalId:s.name,weight:s.weight}))}:{funnelId:r}})}function K(e,t,n,r){e.track({projectId:t,componentId:n,variantId:r,eventType:"variant_assigned",payload:{}})}var pt={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function V(){if(typeof window=="undefined")return pt;let e=window;return e.__sentient_registry||(e.__sentient_registry={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0}),e.__sentient_registry}function J(){V().version+=1;for(let e of V().listeners)e()}var Ve=()=>{};function Y(e){return R()?(V().components.set(e.id,e),J(),()=>{V().components.delete(e.id),J()}):Ve}function Z(e){return R()?(V().slots.set(e.id,e),J(),()=>{V().slots.delete(e.id),J()}):Ve}function ge(e){R()&&(V().sections=[...e],J())}import{jsx as Gt}from"react/jsx-runtime";function wt(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{let n=St((e=navigator.userAgent)!=null?e:""),r=ht((t=document.referrer)!=null?t:"",window.location.origin);return`${n}:${r}`}catch(n){return"desktop:direct"}}var Ne="https://api.sentient-ui.com/v1",I=vt({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialPersona:null,apiBaseUrl:Ne,debug:!1});function xt(e){let[t,n]=ee(!1),r=$e(e);r.current=e;let{cookie:o,value:i,event:u}=e!=null?e:{},s=typeof(e==null?void 0:e.check)=="function";return W(()=>{let d=()=>{var p;let y=r.current;if(!y)return!1;if(y.check)return y.check()===!0;if(!y.cookie||typeof document=="undefined")return!1;let g=`${y.cookie}=${(p=y.value)!=null?p:"accepted"}`;return document.cookie.split("; ").some(C=>C.trim()===g)};if(d()){n(!0);return}if(!u)return;let a=()=>{d()&&n(!0)};return window.addEventListener(u,a),()=>window.removeEventListener(u,a)},[o,i,u,s]),t}function At(e){var C,w;let[t,n]=ee(null),[r]=ee(()=>{var f;return(f=e.sessionSegment)!=null?f:wt()}),[o,i]=ee(de());W(()=>De(()=>i(de())),[]);let u=xt(e.consentFrom),s=e.consentFrom?e.consent===!0||u:e.consent;W(()=>{if(s===!1&&!e.preConsentBehavior){n(b=>(b==null||b.destroy(),null));return}let f={apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,sessionSegment:r,consent:s,preConsentBehavior:e.preConsentBehavior,respectDoNotTrack:e.respectDoNotTrack,ssrSessionId:e.ssrSessionId,country:e.country,localMode:e.localMode,initialSlots:e.initialSlots,initialPersona:e.initialPersona,ingestUrl:e.apiBaseUrl?`${e.apiBaseUrl.replace(/\/$/,"")}/events`:void 0},m=!1,l=null,c=null,S=b=>{e.engagement!==!1&&import("@sentientui/core/engagement").then(({startEngagementCapture:k})=>{m||(c=k(b,{apiKey:e.apiKey,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:b})=>{m||(l=b(q(A({},f),{graph:!0,captureDomText:e.captureDomText===!0})),n(l),S(l))}):(l=bt(f),n(l),S(l)),()=>{m=!0,c==null||c(),l==null||l.dispose()}},[s]),W(()=>{if(!t)return;let f=!1,m=async()=>{if(f)return;let c;try{c=await t.fetchWeights()}catch(S){return}if(!f)for(let S of c){let b={componentId:S.componentId,updatedAt:S.updatedAt,variants:S.variants.map(k=>{var G;return{variantId:k.variantId,pulls:k.pulls,avgReward:(G=k.avgReward)!=null?G:0}})};Ie(S.componentId,b)}};m();let l=setInterval(()=>{m()},6e4);return()=>{f=!0,clearInterval(l)}},[t]);let d=(C=e.ssrFallback)!=null?C:"first",a=((w=e.apiBaseUrl)!=null?w:Ne).replace(/\/$/,""),y=$e(null);W(()=>{var l;if(typeof process!="undefined"&&((l=process.env)==null?void 0:l.NODE_ENV)==="production")return;let f={apiKey:e.apiKey,context:e.context,country:e.country,apiBaseUrl:a},m=y.current;if(y.current=f,m!==null)for(let c of["apiKey","context","country","apiBaseUrl"])Object.is(m[c],f[c])||console.warn(`[sentient] AdaptiveProvider: \`${c}\` changed after initialisation, but the SDK client is stable for the session and only re-inits on \`consent\` \u2014 the new value is ignored. Remount the provider (e.g. via a changing \`key\` prop) to apply it.`)},[e.apiKey,e.context,e.country,a]),W(()=>{var f;typeof process!="undefined"&&((f=process.env)==null?void 0:f.NODE_ENV)==="production"||Me({apiKey:e.apiKey,apiBaseUrl:a,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,a]),W(()=>{let f=e.initialLayoutOrder;if(f&&f.length>0){ge(f);return}e.declaredSections&&e.declaredSections.length>0&&ge(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]);let g=We(()=>t&&o?Te(t):t,[t,o]),p=We(()=>{var f,m,l,c,S;return{client:g,apiKey:e.apiKey,initialAssignments:(f=e.initialAssignments)!=null?f:{},sessionSegment:r,ssrFallback:d,onAssignment:e.onAssignment,initialLayoutOrder:(m=e.initialLayoutOrder)!=null?m:null,initialSlots:(l=e.initialSlots)!=null?l:{},initialPersona:(c=e.initialPersona)!=null?c:null,apiBaseUrl:a,debug:(S=e.debug)!=null?S:!1}},[g,e.apiKey,e.initialAssignments,r,d,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialPersona,a,e.debug]);return Gt(I.Provider,{value:p,children:e.children})}function _(){return L(I).client}function T(){return L(I).apiKey}function me(){return L(I).initialAssignments}function te(){return L(I).sessionSegment}function Ue(){return L(I).ssrFallback}function ne(){return L(I).onAssignment}function Je(){return L(I).debug}function kt(){let e=L(I).initialLayoutOrder,t=yt(F,()=>{var n;return typeof window=="undefined"?null:(n=window.__sentient_layout_override)!=null?n:null},()=>null);return t!=null?t:e}function He(){return L(I).initialSlots}function ze(){return L(I).initialPersona}function Ct(){return L(I).apiBaseUrl}import{memo as Et,useEffect as j,useMemo as Qe,useRef as ie,useState as It}from"react";import{attachMicroSignalDetectors as Lt}from"@sentientui/core";import{useEffect as re,useRef as Xe,useState as _t,useSyncExternalStore as Rt}from"react";function U(e){var n;if(typeof window=="undefined")return null;let t=(n=window.__sentient_overrides)==null?void 0:n[e];if(t)return t;if(!window.location.search)return null;try{let r=new URLSearchParams(window.location.search);for(let o of r.getAll("sentient_variant")){let i=o.indexOf(":");if(i!==-1&&o.slice(0,i)===e)return o.slice(i+1)}}catch(r){}return null}var Ot=5;function qe(e,t){var r,o;let n=null;for(let i of e.variants){if(!t.includes(i.variantId))continue;let u=(r=i.pulls)!=null?r:0,s=u>0?u*i.avgReward/(u+Ot):0;(!n||s>n.score)&&(n={variantId:i.variantId,score:s})}return(o=n==null?void 0:n.variantId)!=null?o:null}function H(e,t,n,r){let o=me(),i=Ue(),u=_(),s=te(),d=ne(),a=Je(),y=Xe(null),g=Rt(F,()=>U(e),()=>null),p=g&&t.includes(g)?g:null,C=Xe(null);re(()=>{a&&p&&C.current!==p&&(C.current=p,console.info(`[sentient] override active: ${e} -> ${p}`))},[a,p,e]);let[w,f]=_t(()=>{var S,b;if(p)return{variantId:p,content:null,isLoading:!1,settled:!0};if(!u){let k=o[e];return k&&t.includes(k)?{variantId:k,content:null,isLoading:!1,settled:!0}:i==="first"&&t.length>0?{variantId:t[0],content:null,isLoading:!1,settled:!1}:{variantId:null,content:null,isLoading:!0,settled:!1}}let l=u.getAssignment(e,s);if(l&&(t.includes(l.variantId)||l.content))return{variantId:l.variantId,content:(S=l.content)!=null?S:null,isLoading:!1,settled:!0};let c=Le(e);if(c){let k=qe(c,t);if(k)return{variantId:k,content:null,isLoading:!1,settled:!0}}return{variantId:(b=t[0])!=null?b:null,content:null,isLoading:!1,settled:!1}}),m=l=>{d&&y.current!==l&&(y.current=l,d(e,l))};return re(()=>{var c;if(p||!u)return;let l=u.getAssignment(e,s);if(l&&(t.includes(l.variantId)||l.content)){f({variantId:l.variantId,content:(c=l.content)!=null?c:null,isLoading:!1,settled:!0}),m(l.variantId);return}f(S=>{var b;return S.variantId?S:{variantId:(b=t[0])!=null?b:null,content:null,isLoading:!1,settled:!1}})},[p,u,e,s]),re(()=>{if(p||!u)return;let l=u.getAssignment(e,s);if(l&&t.includes(l.variantId))return;let c=!1;return u.assign(e,t,n,r).then(S=>{var b;c||S&&(!t.includes(S.variantId)&&!S.content||(f({variantId:S.variantId,content:(b=S.content)!=null?b:null,isLoading:!1,settled:!0}),m(S.variantId)))}),()=>{c=!0}},[p,u,e,s]),re(()=>{if(!p&&u)return Ee(e,l=>{var b;let c=u.getAssignment(e,s);if(c&&(t.includes(c.variantId)||c.content)){f({variantId:c.variantId,content:(b=c.content)!=null?b:null,isLoading:!1,settled:!0});return}let S=qe(l,t);S&&f({variantId:S,content:null,isLoading:!1,settled:!0})})},[p,u,e,s]),p?{variantId:p,content:null,isLoading:!1,settled:!0,isOverride:!0}:w}import{jsx as Tt}from"react/jsx-runtime";function Pt(e){var b;let t=_(),n=T(),r=Object.keys(e.variants).join("\0"),o=Qe(()=>Object.keys(e.variants),[r]),{variantId:i,content:u,isOverride:s,settled:d}=H(e.id,o,e.agentData,e.agentDataByVariant),a=ie(null),[y,g]=It(!1);j(()=>{g(!0)},[]);let p=ie(!1),C=ie(new Set),w=ie(null),f=typeof e.goal=="string"?e.goal:JSON.stringify(e.goal),m=Qe(()=>E(e.goal),[f]),l=typeof e.goal=="string"?e.goal:m.type;if(j(()=>Y({id:e.id,variantIds:o,goal:l}),[e.id,o,l]),j(()=>{s||d&&(!t||!i||!n||w.current!==i&&(w.current=i,K(t,n,e.id,i)))},[t,i,n,e.id,s,d]),j(()=>{p.current=!1,C.current=new Set},[i,m]),j(()=>{s||!d||!t||!e.funnel||B(t,n,e.id,e.funnel,m)},[t,n,e.id,e.funnel,m,s,d]),j(()=>{if(s||!d||!t||!i)return;let k=a.current;if(!k)return;let G=null,x=0,h=()=>{x=Date.now(),G=setTimeout(()=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-x}}),G=null},800)},v=()=>{G!==null&&(clearTimeout(G),G=null)};return k.addEventListener("mouseenter",h),k.addEventListener("mouseleave",v),()=>{k.removeEventListener("mouseenter",h),k.removeEventListener("mouseleave",v),G!==null&&clearTimeout(G)}},[t,i,n,e.id,s,d]),j(()=>{if(s||!d||!t||!i)return;let k=a.current;if(!k)return;let G=Date.now();return Lt((x,h={})=>{var xe,Ae,ke;t.track({projectId:n,componentId:e.id,variantId:i,eventType:"micro_signal",payload:A({signalType:x},h)});let v=(xe=e.microSignalGoals)==null?void 0:xe[x];if(!v||C.current.has(x))return;C.current.add(x);let O=typeof v=="string"?v:v.name,M=typeof v=="string"?1:(Ae=v.weight)!=null?Ae:1,z=typeof v=="string"?0:(ke=v.stepIndex)!=null?ke:0;t.goal(O,{metadata:A({signalType:x},h),weight:M,stepIndex:z})},k,G)},[t,i,n,e.id,e.microSignalGoals,s,d]),j(()=>{if(s||!t||!i)return;let k=a.current;if(!k)return;let G=P(m);return D(k,m,{fireGoal:()=>{p.current||(p.current=!0,t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:l,payload:A({reward:1},G!==void 0?{goalValue:G}:{})}),t.goal(l,A({metadata:{componentId:e.id,variantId:i},weight:1,stepIndex:0},G!==void 0?{value:G}:{})))},fireStep:(x,h,v)=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:x,payload:{reward:h}}),t.goal(x,{metadata:{},weight:h,stepIndex:v})}})},[t,i,n,e.id,m,l,s]),e.clientOnly&&(!y||!t)||!i)return null;let c=(b=e.variants[i])!=null?b:null,S=c===null?u:null;return R()&&c===null&&S===null&&console.warn(`[sentient] <Adaptive id="${e.id}"> was assigned variant "${i}" but no matching key exists in props.variants. If this is a dashboard-managed text variant, use <AdaptiveText id="${e.id}"> instead.`),Tt("div",{ref:a,"data-sentient-id":e.id,"data-sentient-variant":i,children:c!=null?c:S})}var Dt=Et(Pt,(e,t)=>{if(e.id!==t.id||e.goal!==t.goal&&JSON.stringify(e.goal)!==JSON.stringify(t.goal)||e.microSignalGoals!==t.microSignalGoals||e.clientOnly!==t.clientOnly||e.agentData!==t.agentData||e.agentDataByVariant!==t.agentDataByVariant)return!1;if(e.variants===t.variants)return!0;let n=Object.keys(e.variants),r=Object.keys(t.variants);return n.length!==r.length?!1:n.every(o=>o in t.variants&&Object.is(e.variants[o],t.variants[o]))});import{useEffect as oe,useMemo as Ft,useRef as pe,useState as Ye,useSyncExternalStore as Mt}from"react";import{jsx as Kt}from"react/jsx-runtime";function Bt({id:e,default:t,component:n="span",className:r,goal:o}){var G;let i=_(),u=T(),s=ne(),d=te(),a=pe(null),y=pe(null),g=Mt(F,()=>U(e),()=>null),[p,C]=Ye(()=>{var x,h;return(h=(x=i==null?void 0:i.getAssignment(e,d))==null?void 0:x.content)!=null?h:null}),[w,f]=Ye(()=>{var x,h;return(h=(x=i==null?void 0:i.getAssignment(e,d))==null?void 0:x.variantId)!=null?h:null});oe(()=>{var h;if(g||!i||((h=i.getAssignment(e,d))==null?void 0:h.content)!==void 0)return;let x=!1;return i.assign(e).then(v=>{if(!x){if(!v){R()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}f(v.variantId),v.content&&C(v.content)}}),()=>{x=!0}},[i,e,d,g]),oe(()=>{g||!i||!w||!u||a.current!==w&&(a.current=w,i.track({projectId:u,componentId:e,variantId:w,eventType:"variant_assigned",payload:{}}),s==null||s(e,w))},[i,w,u,e,s,g]);let m=o===void 0?"":typeof o=="string"?o:JSON.stringify(o),l=Ft(()=>o===void 0?null:E(o),[m]),c=o===void 0?null:typeof o=="string"?o:l.type,S=pe(!1);oe(()=>{S.current=!1},[w,m]),oe(()=>{if(g||!i||!w||!u||!l||!c)return;let x=y.current;if(!x)return;let h=P(l);return D(x,l,{fireGoal:()=>{S.current||(S.current=!0,i.track({projectId:u,componentId:e,variantId:w,eventType:"goal_achieved",goalType:c,payload:A({reward:1},h!==void 0?{goalValue:h}:{})}),i.goal(c,A({metadata:{componentId:e,variantId:w},weight:1,stepIndex:0},h!==void 0?{value:h}:{})))},fireStep:(v,O,M)=>{i.track({projectId:u,componentId:e,variantId:w,eventType:"goal_achieved",goalType:v,payload:{reward:O}}),i.goal(v,{metadata:{},weight:O,stepIndex:M})}})},[i,w,u,e,l,c,g]);let b=p!=null?p:t;if(g){let x=i==null?void 0:i.getAssignment(e,d);b=x&&x.variantId===g&&(G=x.content)!=null?G:t}return Kt(n,{ref:x=>{y.current=x},className:r,children:b})}import{useCallback as jt,useRef as Vt}from"react";function ve(e){let t=_(),n=Vt(new Set);return jt((r,o)=>{var i,u;if(!U(e)){if(o!=null&&o.once){if(n.current.has(r))return;n.current.add(r)}t==null||t.componentGoal(e,r,o),t==null||t.goal(r,A(A(A({metadata:(i=o==null?void 0:o.metadata)!=null?i:{},weight:(u=o==null?void 0:o.reward)!=null?u:1,stepIndex:0},(o==null?void 0:o.value)!==void 0?{value:o.value}:{}),(o==null?void 0:o.currency)!==void 0?{currency:o.currency}:{}),(o==null?void 0:o.externalId)!==void 0?{externalId:o.externalId}:{}))}},[t,e])}import{useEffect as Wt,useRef as Ze}from"react";function $t(e,t={}){let d=t,{componentId:n}=d,r=Re(d,["componentId"]),o=_(),i=ve(n!=null?n:""),u=Ze(!1),s=Ze(r);s.current=r,Wt(()=>{if(!o||u.current)return;u.current=!0;let{metadata:a,reward:y,value:g,currency:p,externalId:C}=s.current;if(n){i(e,s.current);return}o.goal(e,A(A(A({metadata:a!=null?a:{},weight:y!=null?y:1,stepIndex:0},g!==void 0?{value:g}:{}),p!==void 0?{currency:p}:{}),C!==void 0?{externalId:C}:{}))},[o,n,e,i])}import{renderPrePaintScript as Nt}from"@sentientui/core";import{confidenceBand as Ut}from"@sentientui/policy";import{jsx as zt}from"react/jsx-runtime";function et(e){return JSON.stringify(e).replace(/</g,"\\u003c")}function Jt(e){return e.persona?'(function(){try{var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",'+et(e.persona.persona)+');d.setAttribute("data-sentient-confidence",'+et(Ut(e.persona.confidence))+");}catch(e){}})();":Nt(e.apiKey)}function Ht(e){return zt("script",{"data-sentient-persona-script":"",nonce:e.nonce,dangerouslySetInnerHTML:{__html:Jt(e)}})}import{useEffect as le,useMemo as Se,useRef as tn}from"react";import{validateSlotDecl as nn}from"@sentientui/policy";import{useEffect as ye,useReducer as Xt,useState as qt,useSyncExternalStore as nt}from"react";import{armOfResult as se,baselineResultFor as Qt}from"@sentientui/core";import{confidenceBand as Yt}from"@sentientui/policy";var tt=new Set;function ae(e,t){var y;nt(F,fe,()=>0);let n=_(),r=He(),[,o]=Xt(g=>g+1,0),i=typeof window!="undefined"?(y=window.__sentient_slot_overrides)==null?void 0:y[e]:void 0,u=i===void 0?r[e]:void 0,s=i===void 0&&u===void 0&&n?n.getSlotResult(e):null,d=(n==null?void 0:n.isLocal)===!0&&i===void 0&&u===void 0&&s===null;ye(()=>{if(!d||!n)return;let g=!1;return n.decide({slots:[t]}).then(p=>{!g&&p&&o()}),()=>{g=!0}},[n,e,d]);let a=(()=>{if(i!==void 0)return{result:i,arm:se(i),source:"override"};if(u!==void 0)return{result:u,arm:se(u),source:"preloaded"};if(s!==null)return{result:s,arm:se(s),source:"client"};let g=Qt(t);return{result:g,arm:se(g),source:"baseline"}})();return ye(()=>{R()&&(!n||n.isLocal===!0||a.source==="baseline"&&(tt.has(e)||(tt.add(e),console.warn(`[sentient] slot "${e}" resolved to its baseline \u2014 no SSR-preloaded or decided result. Keyed clients decide slots server-side, so this slot serves baseline for the whole session and records no exposure. Preload it via loadAdaptiveDecision()/initialSlots so it can serve a decided arm and learn.`))))},[n,a.source,e]),a}function Zt(){var t;if(typeof window=="undefined")return null;let e=window.__sentient_persona_override;if(e!=null&&e.persona)return{persona:e.persona,confidence:(t=e.confidence)!=null?t:1};try{let n=new URLSearchParams(window.location.search).get("sentient_persona");if(n)return{persona:n,confidence:1}}catch(n){}return null}function en(){let e=_(),t=ze();nt(F,fe,()=>0);let[n,r]=qt(!1);ye(()=>r(!0),[]);let o=s=>({persona:s.persona,confidence:s.confidence,band:Yt(s.confidence)});if(!n)return t?o(t):null;let i=Zt();if(i)return o(i);if(t)return o(t);let u=e?e.getPersona():null;return u?o(u):null}var he=new Set;function rn(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/[\\"]/g,"\\$&")}function on(e,t,n){let r=_(),o=T(),i=JSON.stringify(t),u=Se(()=>({id:e,dims:t}),[e,i]),{result:s,arm:d,source:a}=ae(e,u),y=Se(()=>typeof s=="string"?{}:s,[d]);if(R()&&!he.has(e)){let f=nn({id:e,dims:Object.fromEntries(Object.entries(t).map(([l,c])=>[l,[...c]]))}),m=Object.values(t).reduce((l,c)=>l*c.length,1);f.ok?m>4&&(he.add(e),console.warn(`[sentient] useAdaptiveTokens("${e}") declares ${m} combinations \u2014 more than the recommended 4. Each extra combination needs more traffic to learn; consider fewer dims/values.`)):(he.add(e),console.warn(`[sentient] useAdaptiveTokens("${e}"): invalid declaration \u2014 ${f.reason}. Serving baseline.`))}let g=(n==null?void 0:n.goal)===void 0?null:typeof n.goal=="string"?n.goal:JSON.stringify(n.goal);le(()=>Z({id:e,dims:t}),[e]);let p=tn(null);le(()=>{!r||a==="baseline"||a==="override"||p.current===d||(p.current=d,K(r,o,e,d))},[r,o,e,d,a]);let C=n==null?void 0:n.funnel;le(()=>{var f;!r||!C||a==="override"||B(r,o,e,C,E((f=n==null?void 0:n.goal)!=null?f:"click"))},[r,o,e,C,g,a]),le(()=>{if(!r||!(n!=null&&n.goal)||a==="override")return;let f=document.querySelector(`[data-sentient-slot="${rn(e)}"]`);if(!f){R()&&console.warn(`[sentient] useAdaptiveTokens("${e}"): a goal is declared but no element carries the returned props \u2014 spread {...props} on the slot's element.`);return}let m=N(n.goal),l=P(n.goal),c=!1;return D(f,E(n.goal),{fireGoal:()=>{c||(c=!0,l!==void 0?r.componentGoal(e,m,{value:l}):r.componentGoal(e,m),r.goal(m,A({metadata:{componentId:e,arm:d},weight:1,stepIndex:0},l!==void 0?{value:l}:{})))},fireStep:(S,b,k)=>{r.componentGoal(e,S,{reward:b}),r.goal(S,{metadata:{componentId:e,arm:d},weight:b,stepIndex:k})}})},[r,e,g,d,a]);let w=Se(()=>{let f={"data-sentient-slot":e};for(let[m,l]of Object.entries(y))f[`data-${m}`]=l;return f},[e,y]);return{tokens:y,props:w}}import{useCallback as rt,useEffect as $,useMemo as be,useRef as we,useState as sn}from"react";import{attachMicroSignalDetectors as an}from"@sentientui/core";var it=new Set;function ln(e,t){var x;if(R()&&!t.goal)throw new Error(`[sentient] useAdaptive("${e}"): a goal is required \u2014 without one the optimizer accumulates exposures with no rewards and cannot learn. Pass e.g. goal: 'buy_click'.`);let n=_(),r=T(),o=Object.keys(t.variants).join(" "),i=be(()=>Object.keys(t.variants),[o]),{variantId:u,isOverride:s,settled:d}=H(e,i),a=(x=u!=null?u:i[0])!=null?x:"",y=t.variants[a],[g,p]=sn(null),C=we(null),w=rt(h=>{C.current=h,p(h)},[]),f=typeof t.goal=="string"?t.goal:JSON.stringify(t.goal),m=be(()=>E(t.goal),[f]),l=N(t.goal);$(()=>Y({id:e,variantIds:i,goal:l}),[e,i,l]);let c=we(null);$(()=>{s||d&&(!n||!a||!g||c.current!==a&&(c.current=a,K(n,r,e,a)))},[n,r,e,a,g,s,d]);let S=t.funnel;$(()=>{s||!d||!n||!S||B(n,r,e,S,m)},[n,r,e,S,m,s,d]);let b=we(!1);$(()=>{b.current=!1},[a,f]),$(()=>{if(s||!n||!a||!g)return;let h=P(m);return D(g,m,{fireGoal:()=>{b.current||(b.current=!0,n.track({projectId:r,componentId:e,variantId:a,eventType:"goal_achieved",goalType:l,payload:A({reward:1},h!==void 0?{goalValue:h}:{})}),n.goal(l,A({metadata:{componentId:e,variantId:a},weight:1,stepIndex:0},h!==void 0?{value:h}:{})))},fireStep:(v,O,M)=>{n.track({projectId:r,componentId:e,variantId:a,eventType:"goal_achieved",goalType:v,payload:{reward:O}}),n.goal(v,{metadata:{},weight:O,stepIndex:M})}})},[n,g,a,r,e,m,l,s]),$(()=>{if(s||!n||!a||!g)return;let h=Date.now();return an((v,O={})=>{n.track({projectId:r,componentId:e,variantId:a,eventType:"micro_signal",payload:A({signalType:v},O)})},g,h)},[n,g,a,r,e,s]),$(()=>{if(!R()||!n)return;let h=setTimeout(()=>{!C.current&&!it.has(e)&&(it.add(e),console.warn(`[sentient] useAdaptive("${e}"): bind was never attached \u2014 spread {...bind} on the rendered element, otherwise exposure and goal tracking cannot work and the optimizer learns nothing.`))},0);return()=>clearTimeout(h)},[n,e]);let k=rt((h,v)=>{var M,z;if(s)return;let O=h!=null?h:l;n==null||n.componentGoal(e,O,v),n==null||n.goal(O,A(A(A({metadata:(M=v==null?void 0:v.metadata)!=null?M:{},weight:(z=v==null?void 0:v.reward)!=null?z:1,stepIndex:0},(v==null?void 0:v.value)!==void 0?{value:v.value}:{}),(v==null?void 0:v.currency)!==void 0?{currency:v.currency}:{}),(v==null?void 0:v.externalId)!==void 0?{externalId:v.externalId}:{}))},[n,e,l,s]),G=be(()=>({ref:w,"data-sentient-id":e,"data-sentient-variant":a}),[w,e,a]);return{variant:a,value:y,bind:G,fireGoal:k}}import{Children as un,isValidElement as cn,useEffect as ue,useMemo as ot,useRef as st}from"react";import{jsx as fn}from"react/jsx-runtime";var ce=new Set;function dn(e){var l;let t=_(),n=T(),r=st(null),o=Object.keys(e.arrangements).join(" "),i=ot(()=>Object.keys(e.arrangements),[o]),u=ot(()=>A({id:e.id,arms:i},e.baseline!==void 0?{baseline:e.baseline}:{}),[e.id,i,e.baseline]),{arm:s,source:d}=ae(e.id,u);R()&&e.baseline!==void 0&&e.baseline!==i[0]&&!ce.has(e.id+":baseline")&&(ce.add(e.id+":baseline"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: baseline "${e.baseline}" is not the first-declared arrangement ("${i[0]}"). The first arrangement should usually be the page's real incumbent (the holdout sees it).`));let a=un.toArray(e.children).filter(cn),y=new Map;for(let c of a)y.set(String((l=c.key)!=null?l:"").replace(/^\.\$/,""),c);let g=e.arrangements[s],p=g!==void 0&&g.length===a.length&&g.every(c=>y.has(c));R()&&g!==void 0&&!p&&!ce.has(e.id+":keys")&&(ce.add(e.id+":keys"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: arrangement "${s}" [${g.join(", ")}] does not match the children's keys \u2014 rendering declaration order (fail-safe).`));let C=p?g.map(c=>y.get(c)):a;ue(()=>Z({id:e.id,arms:Object.keys(e.arrangements)}),[e.id]);let w=st(null);ue(()=>{!t||d==="baseline"||d==="override"||w.current===s||(w.current=s,K(t,n,e.id,s))},[t,n,e.id,s,d]);let f=e.funnel;ue(()=>{var c;!t||!f||d==="override"||B(t,n,e.id,f,E((c=e.goal)!=null?c:"click"))},[t,n,e.id,f,d]);let m=e.goal===void 0?null:typeof e.goal=="string"?e.goal:JSON.stringify(e.goal);return ue(()=>{if(!t||e.goal===void 0||d==="override")return;let c=r.current;if(!c)return;let S=N(e.goal),b=P(e.goal),k=!1;return D(c,E(e.goal),{fireGoal:()=>{k||(k=!0,b!==void 0?t.componentGoal(e.id,S,{value:b}):t.componentGoal(e.id,S),t.goal(S,A({metadata:{componentId:e.id,arm:s},weight:1,stepIndex:0},b!==void 0?{value:b}:{})))},fireStep:(G,x,h)=>{t.componentGoal(e.id,G,{reward:x}),t.goal(G,{metadata:{componentId:e.id,arm:s},weight:x,stepIndex:h})}})},[t,e.id,m,s,d]),fn("div",{ref:r,"data-sentient-id":e.id,"data-sentient-variant":s,children:C})}import{deriveSessionSegment as gn}from"@sentientui/core";var mn=["page","blocks","layoutOrder"],at=new Map;function pn(e,t){at.set(e,t)}function lt(e){return at.get(e)}function vn(e){var o,i;let t=(i=(o=e.content)!=null?o:lt(e.page))!=null?i:{},n={};for(let[u,s]of Object.entries(t))mn.includes(u)||(n[u]=s);let r=q(A({},n),{page:e.page,blocks:e.blocks});return e.layoutOrder&&(r.layoutOrder=e.layoutOrder),r}function yn(e){return`<script type="application/ld+json">${ut(e)}</script>`}function ut(e){return JSON.stringify(A({"@context":"https://schema.org","@type":"WebPage"},e)).replace(/</g,"\\u003c")}function Sn(e){let t=[];e.title&&t.push(`# ${e.title}`,""),e.summary&&t.push(String(e.summary),"");for(let[n,r]of Object.entries(e))["page","title","summary","blocks","layoutOrder"].includes(n)||t.push(`## ${n}`,"","```json",JSON.stringify(r,null,2),"```","");if(e.blocks.length>0){t.push("## blocks","");for(let n of e.blocks)t.push(`- **${n.id}** \u2192 variant \`${n.variant}\``),n.content!==void 0&&t.push(""," ```json",JSON.stringify(n.content,null,2)," ```");t.push("")}return t.join(`
2
+ var ct=Object.defineProperty,dt=Object.defineProperties;var ft=Object.getOwnPropertyDescriptors;var X=Object.getOwnPropertySymbols;var Ge=Object.prototype.hasOwnProperty,_e=Object.prototype.propertyIsEnumerable;var Ce=(e,t,n)=>t in e?ct(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,A=(e,t)=>{for(var n in t||(t={}))Ge.call(t,n)&&Ce(e,n,t[n]);if(X)for(var n of X(t))_e.call(t,n)&&Ce(e,n,t[n]);return e},q=(e,t)=>dt(e,ft(t));var Re=(e,t)=>{var n={};for(var r in e)Ge.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&X)for(var r of X(e))t.indexOf(r)<0&&_e.call(e,r)&&(n[r]=e[r]);return n};import{createContext as vt,useContext as L,useEffect as W,useMemo as We,useRef as $e,useState as ee,useSyncExternalStore as yt}from"react";import{detectDeviceClass as St,detectTrafficSource as ht,init as bt}from"@sentientui/core";var Oe=new Map,Q=new Map;function Ee(e,t){let n=Q.get(e);return n||(n=new Set,Q.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&Q.delete(e)}}function Ie(e,t){Oe.set(e,t);let n=Q.get(e);if(n)for(let r of n)try{r(t)}catch(o){}}function Le(e){var t;return(t=Oe.get(e))!=null?t:null}var gt={on:!1,listeners:new Set};function Pe(){if(typeof window=="undefined")return gt;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function de(){return Pe().on}function De(e){let t=Pe().listeners;return t.add(e),()=>{t.delete(e)}}function Te(e){return{isLocal:e.isLocal,track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},fetchWeights:()=>Promise.resolve([]),getAssignment:(t,n)=>e.getAssignment(t,n),assign:(t,n,r,o)=>e.assign(t,n,r,o),decide:()=>Promise.resolve(null),getSlotResult:t=>e.getSlotResult(t),getPersona:()=>e.getPersona(),getGraph:()=>e.getGraph(),dispose:()=>e.dispose(),destroy:()=>e.destroy()}}var Fe="sentient:overrides-changed";function fe(){var e;return typeof window=="undefined"?0:(e=window.__sentient_overrides_version)!=null?e:0}function F(e){return typeof window=="undefined"?()=>{}:(window.addEventListener(Fe,e),()=>window.removeEventListener(Fe,e))}function Me(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function R(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}function E(e){return typeof e=="string"?{type:"click"}:e}function N(e){return typeof e=="string"?e:e.type}function P(e){if(typeof e!="string"&&(e.type==="click"||e.type==="form_submit"||e.type==="scroll_depth"))return e.value}function mt(e){if(!(e instanceof Element))return!1;let t=e.tagName.toLowerCase();return t==="a"||t==="button"?!0:e.getAttribute("role")==="button"}function Be(e,t,n){if(n){try{let o=e;for(;o&&o!==t;){if(o.matches(n))return!0;o=o.parentElement}}catch(o){}return!1}let r=e;for(;r&&r!==t;){if(mt(r))return!0;r=r.parentElement}return!1}function D(e,t,n){if(t.type==="weighted_composite"){let s=new Set,d=[];return t.steps.forEach(({goal:a,name:y,weight:g},p)=>{let C=()=>{s.has(p)||(s.add(p),n.fireStep(y,g,p))};if(a.type==="click"){let w=f=>{let m=f.target;m instanceof Element&&Be(m,e,a.selector)&&C()};e.addEventListener("click",w),d.push(()=>e.removeEventListener("click",w));return}if(a.type==="form_submit"){let w=f=>{f.target instanceof HTMLFormElement&&e.contains(f.target)&&C()};e.addEventListener("submit",w),d.push(()=>e.removeEventListener("submit",w));return}if(a.type==="scroll_depth"){let w=Math.max(0,Math.min(1,a.threshold)),f=new IntersectionObserver(m=>{for(let l of m)if(l.intersectionRatio>=w){C(),f.disconnect();break}},{threshold:[w]});f.observe(e),d.push(()=>f.disconnect())}}),()=>{for(let a of d)a()}}let r=t.type==="composite"?t.all:[t],o=new Set(r.map((s,d)=>d)),i=s=>{o.delete(s),o.size===0&&n.fireGoal()},u=[];return r.forEach((s,d)=>{if(s.type==="click"){let a=y=>{let g=y.target;g instanceof Element&&Be(g,e,s.selector)&&(t.type==="composite"?i(d):n.fireGoal())};e.addEventListener("click",a),u.push(()=>e.removeEventListener("click",a));return}if(s.type==="form_submit"){let a=y=>{y.target instanceof HTMLFormElement&&e.contains(y.target)&&(t.type==="composite"?i(d):n.fireGoal())};e.addEventListener("submit",a),u.push(()=>e.removeEventListener("submit",a));return}if(s.type==="scroll_depth"){let a=Math.max(0,Math.min(1,s.threshold)),y=new IntersectionObserver(g=>{for(let p of g)if(p.intersectionRatio>=a){t.type==="composite"?i(d):n.fireGoal(),y.disconnect();break}},{threshold:[a]});y.observe(e),u.push(()=>y.disconnect());return}}),()=>{for(let s of u)s()}}var Ke=new Set,je=new Set;function B(e,t,n,r,o){let i=`${r}|${n}`;if(je.has(i))return;je.add(i);let u=o.type==="weighted_composite"&&!Ke.has(r);u&&Ke.add(r),e.track({projectId:t,componentId:n,eventType:"funnel_declared",payload:u?{funnelId:r,steps:o.steps.map(s=>({goalId:s.name,weight:s.weight}))}:{funnelId:r}})}function K(e,t,n,r){e.track({projectId:t,componentId:n,variantId:r,eventType:"variant_assigned",payload:{}})}var pt={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function V(){if(typeof window=="undefined")return pt;let e=window;return e.__sentient_registry||(e.__sentient_registry={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0}),e.__sentient_registry}function J(){V().version+=1;for(let e of V().listeners)e()}var Ve=()=>{};function Y(e){return R()?(V().components.set(e.id,e),J(),()=>{V().components.delete(e.id),J()}):Ve}function Z(e){return R()?(V().slots.set(e.id,e),J(),()=>{V().slots.delete(e.id),J()}):Ve}function ge(e){R()&&(V().sections=[...e],J())}import{jsx as Gt}from"react/jsx-runtime";function wt(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{let n=St((e=navigator.userAgent)!=null?e:""),r=ht((t=document.referrer)!=null?t:"",window.location.origin);return`${n}:${r}`}catch(n){return"desktop:direct"}}var Ne="https://api.sentient-ui.com/v1",I=vt({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialPersona:null,apiBaseUrl:Ne,debug:!1});function xt(e){let[t,n]=ee(!1),r=$e(e);r.current=e;let{cookie:o,value:i,event:u}=e!=null?e:{},s=typeof(e==null?void 0:e.check)=="function";return W(()=>{let d=()=>{var p;let y=r.current;if(!y)return!1;if(y.check)return y.check()===!0;if(!y.cookie||typeof document=="undefined")return!1;let g=`${y.cookie}=${(p=y.value)!=null?p:"accepted"}`;return document.cookie.split("; ").some(C=>C.trim()===g)};if(d()){n(!0);return}if(!u)return;let a=()=>{d()&&n(!0)};return window.addEventListener(u,a),()=>window.removeEventListener(u,a)},[o,i,u,s]),t}function At(e){var C,w;let[t,n]=ee(null),[r]=ee(()=>{var f;return(f=e.sessionSegment)!=null?f:wt()}),[o,i]=ee(de());W(()=>De(()=>i(de())),[]);let u=xt(e.consentFrom),s=e.consentFrom?e.consent===!0||u:e.consent;W(()=>{if(s===!1&&!e.preConsentBehavior){n(b=>(b==null||b.destroy(),null));return}let f={apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,sessionSegment:r,consent:s,preConsentBehavior:e.preConsentBehavior,respectDoNotTrack:e.respectDoNotTrack,ssrSessionId:e.ssrSessionId,country:e.country,persona:e.persona,localMode:e.localMode,initialSlots:e.initialSlots,initialPersona:e.initialPersona,ingestUrl:e.apiBaseUrl?`${e.apiBaseUrl.replace(/\/$/,"")}/events`:void 0},m=!1,l=null,c=null,S=b=>{e.engagement!==!1&&import("@sentientui/core/engagement").then(({startEngagementCapture:k})=>{m||(c=k(b,{apiKey:e.apiKey,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:b})=>{m||(l=b(q(A({},f),{graph:!0,captureDomText:e.captureDomText===!0})),n(l),S(l))}):(l=bt(f),n(l),S(l)),()=>{m=!0,c==null||c(),l==null||l.dispose()}},[s]),W(()=>{if(!t)return;let f=!1,m=async()=>{if(f)return;let c;try{c=await t.fetchWeights()}catch(S){return}if(!f)for(let S of c){let b={componentId:S.componentId,updatedAt:S.updatedAt,variants:S.variants.map(k=>{var G;return{variantId:k.variantId,pulls:k.pulls,avgReward:(G=k.avgReward)!=null?G:0}})};Ie(S.componentId,b)}};m();let l=setInterval(()=>{m()},6e4);return()=>{f=!0,clearInterval(l)}},[t]);let d=(C=e.ssrFallback)!=null?C:"first",a=((w=e.apiBaseUrl)!=null?w:Ne).replace(/\/$/,""),y=$e(null);W(()=>{var l;if(typeof process!="undefined"&&((l=process.env)==null?void 0:l.NODE_ENV)==="production")return;let f={apiKey:e.apiKey,context:e.context,country:e.country,persona:e.persona,apiBaseUrl:a},m=y.current;if(y.current=f,m!==null)for(let c of["apiKey","context","country","persona","apiBaseUrl"])Object.is(m[c],f[c])||console.warn(`[sentient] AdaptiveProvider: \`${c}\` changed after initialisation, but the SDK client is stable for the session and only re-inits on \`consent\` \u2014 the new value is ignored. Remount the provider (e.g. via a changing \`key\` prop) to apply it.`)},[e.apiKey,e.context,e.country,e.persona,a]),W(()=>{var f;typeof process!="undefined"&&((f=process.env)==null?void 0:f.NODE_ENV)==="production"||Me({apiKey:e.apiKey,apiBaseUrl:a,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,a]),W(()=>{let f=e.initialLayoutOrder;if(f&&f.length>0){ge(f);return}e.declaredSections&&e.declaredSections.length>0&&ge(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]);let g=We(()=>t&&o?Te(t):t,[t,o]),p=We(()=>{var f,m,l,c,S;return{client:g,apiKey:e.apiKey,initialAssignments:(f=e.initialAssignments)!=null?f:{},sessionSegment:r,ssrFallback:d,onAssignment:e.onAssignment,initialLayoutOrder:(m=e.initialLayoutOrder)!=null?m:null,initialSlots:(l=e.initialSlots)!=null?l:{},initialPersona:(c=e.initialPersona)!=null?c:null,apiBaseUrl:a,debug:(S=e.debug)!=null?S:!1}},[g,e.apiKey,e.initialAssignments,r,d,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialPersona,a,e.debug]);return Gt(I.Provider,{value:p,children:e.children})}function _(){return L(I).client}function T(){return L(I).apiKey}function me(){return L(I).initialAssignments}function te(){return L(I).sessionSegment}function Ue(){return L(I).ssrFallback}function ne(){return L(I).onAssignment}function Je(){return L(I).debug}function kt(){let e=L(I).initialLayoutOrder,t=yt(F,()=>{var n;return typeof window=="undefined"?null:(n=window.__sentient_layout_override)!=null?n:null},()=>null);return t!=null?t:e}function He(){return L(I).initialSlots}function ze(){return L(I).initialPersona}function Ct(){return L(I).apiBaseUrl}import{memo as Et,useEffect as j,useMemo as Qe,useRef as ie,useState as It}from"react";import{attachMicroSignalDetectors as Lt}from"@sentientui/core";import{useEffect as re,useRef as Xe,useState as _t,useSyncExternalStore as Rt}from"react";function U(e){var n;if(typeof window=="undefined")return null;let t=(n=window.__sentient_overrides)==null?void 0:n[e];if(t)return t;if(!window.location.search)return null;try{let r=new URLSearchParams(window.location.search);for(let o of r.getAll("sentient_variant")){let i=o.indexOf(":");if(i!==-1&&o.slice(0,i)===e)return o.slice(i+1)}}catch(r){}return null}var Ot=5;function qe(e,t){var r,o;let n=null;for(let i of e.variants){if(!t.includes(i.variantId))continue;let u=(r=i.pulls)!=null?r:0,s=u>0?u*i.avgReward/(u+Ot):0;(!n||s>n.score)&&(n={variantId:i.variantId,score:s})}return(o=n==null?void 0:n.variantId)!=null?o:null}function H(e,t,n,r){let o=me(),i=Ue(),u=_(),s=te(),d=ne(),a=Je(),y=Xe(null),g=Rt(F,()=>U(e),()=>null),p=g&&t.includes(g)?g:null,C=Xe(null);re(()=>{a&&p&&C.current!==p&&(C.current=p,console.info(`[sentient] override active: ${e} -> ${p}`))},[a,p,e]);let[w,f]=_t(()=>{var S,b;if(p)return{variantId:p,content:null,isLoading:!1,settled:!0};if(!u){let k=o[e];return k&&t.includes(k)?{variantId:k,content:null,isLoading:!1,settled:!0}:i==="first"&&t.length>0?{variantId:t[0],content:null,isLoading:!1,settled:!1}:{variantId:null,content:null,isLoading:!0,settled:!1}}let l=u.getAssignment(e,s);if(l&&(t.includes(l.variantId)||l.content))return{variantId:l.variantId,content:(S=l.content)!=null?S:null,isLoading:!1,settled:!0};let c=Le(e);if(c){let k=qe(c,t);if(k)return{variantId:k,content:null,isLoading:!1,settled:!0}}return{variantId:(b=t[0])!=null?b:null,content:null,isLoading:!1,settled:!1}}),m=l=>{d&&y.current!==l&&(y.current=l,d(e,l))};return re(()=>{var c;if(p||!u)return;let l=u.getAssignment(e,s);if(l&&(t.includes(l.variantId)||l.content)){f({variantId:l.variantId,content:(c=l.content)!=null?c:null,isLoading:!1,settled:!0}),m(l.variantId);return}f(S=>{var b;return S.variantId?S:{variantId:(b=t[0])!=null?b:null,content:null,isLoading:!1,settled:!1}})},[p,u,e,s]),re(()=>{if(p||!u)return;let l=u.getAssignment(e,s);if(l&&t.includes(l.variantId))return;let c=!1;return u.assign(e,t,n,r).then(S=>{var b;c||S&&(!t.includes(S.variantId)&&!S.content||(f({variantId:S.variantId,content:(b=S.content)!=null?b:null,isLoading:!1,settled:!0}),m(S.variantId)))}),()=>{c=!0}},[p,u,e,s]),re(()=>{if(!p&&u)return Ee(e,l=>{var b;let c=u.getAssignment(e,s);if(c&&(t.includes(c.variantId)||c.content)){f({variantId:c.variantId,content:(b=c.content)!=null?b:null,isLoading:!1,settled:!0});return}let S=qe(l,t);S&&f({variantId:S,content:null,isLoading:!1,settled:!0})})},[p,u,e,s]),p?{variantId:p,content:null,isLoading:!1,settled:!0,isOverride:!0}:w}import{jsx as Tt}from"react/jsx-runtime";function Pt(e){var b;let t=_(),n=T(),r=Object.keys(e.variants).join("\0"),o=Qe(()=>Object.keys(e.variants),[r]),{variantId:i,content:u,isOverride:s,settled:d}=H(e.id,o,e.agentData,e.agentDataByVariant),a=ie(null),[y,g]=It(!1);j(()=>{g(!0)},[]);let p=ie(!1),C=ie(new Set),w=ie(null),f=typeof e.goal=="string"?e.goal:JSON.stringify(e.goal),m=Qe(()=>E(e.goal),[f]),l=typeof e.goal=="string"?e.goal:m.type;if(j(()=>Y({id:e.id,variantIds:o,goal:l}),[e.id,o,l]),j(()=>{s||d&&(!t||!i||!n||w.current!==i&&(w.current=i,K(t,n,e.id,i)))},[t,i,n,e.id,s,d]),j(()=>{p.current=!1,C.current=new Set},[i,m]),j(()=>{s||!d||!t||!e.funnel||B(t,n,e.id,e.funnel,m)},[t,n,e.id,e.funnel,m,s,d]),j(()=>{if(s||!d||!t||!i)return;let k=a.current;if(!k)return;let G=null,x=0,h=()=>{x=Date.now(),G=setTimeout(()=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-x}}),G=null},800)},v=()=>{G!==null&&(clearTimeout(G),G=null)};return k.addEventListener("mouseenter",h),k.addEventListener("mouseleave",v),()=>{k.removeEventListener("mouseenter",h),k.removeEventListener("mouseleave",v),G!==null&&clearTimeout(G)}},[t,i,n,e.id,s,d]),j(()=>{if(s||!d||!t||!i)return;let k=a.current;if(!k)return;let G=Date.now();return Lt((x,h={})=>{var xe,Ae,ke;t.track({projectId:n,componentId:e.id,variantId:i,eventType:"micro_signal",payload:A({signalType:x},h)});let v=(xe=e.microSignalGoals)==null?void 0:xe[x];if(!v||C.current.has(x))return;C.current.add(x);let O=typeof v=="string"?v:v.name,M=typeof v=="string"?1:(Ae=v.weight)!=null?Ae:1,z=typeof v=="string"?0:(ke=v.stepIndex)!=null?ke:0;t.goal(O,{metadata:A({signalType:x},h),weight:M,stepIndex:z})},k,G)},[t,i,n,e.id,e.microSignalGoals,s,d]),j(()=>{if(s||!t||!i)return;let k=a.current;if(!k)return;let G=P(m);return D(k,m,{fireGoal:()=>{p.current||(p.current=!0,t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:l,payload:A({reward:1},G!==void 0?{goalValue:G}:{})}),t.goal(l,A({metadata:{componentId:e.id,variantId:i},weight:1,stepIndex:0},G!==void 0?{value:G}:{})))},fireStep:(x,h,v)=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:x,payload:{reward:h}}),t.goal(x,{metadata:{},weight:h,stepIndex:v})}})},[t,i,n,e.id,m,l,s]),e.clientOnly&&(!y||!t)||!i)return null;let c=(b=e.variants[i])!=null?b:null,S=c===null?u:null;return R()&&c===null&&S===null&&console.warn(`[sentient] <Adaptive id="${e.id}"> was assigned variant "${i}" but no matching key exists in props.variants. If this is a dashboard-managed text variant, use <AdaptiveText id="${e.id}"> instead.`),Tt("div",{ref:a,"data-sentient-id":e.id,"data-sentient-variant":i,children:c!=null?c:S})}var Dt=Et(Pt,(e,t)=>{if(e.id!==t.id||e.goal!==t.goal&&JSON.stringify(e.goal)!==JSON.stringify(t.goal)||e.microSignalGoals!==t.microSignalGoals||e.clientOnly!==t.clientOnly||e.agentData!==t.agentData||e.agentDataByVariant!==t.agentDataByVariant)return!1;if(e.variants===t.variants)return!0;let n=Object.keys(e.variants),r=Object.keys(t.variants);return n.length!==r.length?!1:n.every(o=>o in t.variants&&Object.is(e.variants[o],t.variants[o]))});import{useEffect as oe,useMemo as Ft,useRef as pe,useState as Ye,useSyncExternalStore as Mt}from"react";import{jsx as Kt}from"react/jsx-runtime";function Bt({id:e,default:t,component:n="span",className:r,goal:o}){var G;let i=_(),u=T(),s=ne(),d=te(),a=pe(null),y=pe(null),g=Mt(F,()=>U(e),()=>null),[p,C]=Ye(()=>{var x,h;return(h=(x=i==null?void 0:i.getAssignment(e,d))==null?void 0:x.content)!=null?h:null}),[w,f]=Ye(()=>{var x,h;return(h=(x=i==null?void 0:i.getAssignment(e,d))==null?void 0:x.variantId)!=null?h:null});oe(()=>{var h;if(g||!i||((h=i.getAssignment(e,d))==null?void 0:h.content)!==void 0)return;let x=!1;return i.assign(e).then(v=>{if(!x){if(!v){R()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}f(v.variantId),v.content&&C(v.content)}}),()=>{x=!0}},[i,e,d,g]),oe(()=>{g||!i||!w||!u||a.current!==w&&(a.current=w,i.track({projectId:u,componentId:e,variantId:w,eventType:"variant_assigned",payload:{}}),s==null||s(e,w))},[i,w,u,e,s,g]);let m=o===void 0?"":typeof o=="string"?o:JSON.stringify(o),l=Ft(()=>o===void 0?null:E(o),[m]),c=o===void 0?null:typeof o=="string"?o:l.type,S=pe(!1);oe(()=>{S.current=!1},[w,m]),oe(()=>{if(g||!i||!w||!u||!l||!c)return;let x=y.current;if(!x)return;let h=P(l);return D(x,l,{fireGoal:()=>{S.current||(S.current=!0,i.track({projectId:u,componentId:e,variantId:w,eventType:"goal_achieved",goalType:c,payload:A({reward:1},h!==void 0?{goalValue:h}:{})}),i.goal(c,A({metadata:{componentId:e,variantId:w},weight:1,stepIndex:0},h!==void 0?{value:h}:{})))},fireStep:(v,O,M)=>{i.track({projectId:u,componentId:e,variantId:w,eventType:"goal_achieved",goalType:v,payload:{reward:O}}),i.goal(v,{metadata:{},weight:O,stepIndex:M})}})},[i,w,u,e,l,c,g]);let b=p!=null?p:t;if(g){let x=i==null?void 0:i.getAssignment(e,d);b=x&&x.variantId===g&&(G=x.content)!=null?G:t}return Kt(n,{ref:x=>{y.current=x},className:r,children:b})}import{useCallback as jt,useRef as Vt}from"react";function ve(e){let t=_(),n=Vt(new Set);return jt((r,o)=>{var i,u;if(!U(e)){if(o!=null&&o.once){if(n.current.has(r))return;n.current.add(r)}t==null||t.componentGoal(e,r,o),t==null||t.goal(r,A(A(A({metadata:(i=o==null?void 0:o.metadata)!=null?i:{},weight:(u=o==null?void 0:o.reward)!=null?u:1,stepIndex:0},(o==null?void 0:o.value)!==void 0?{value:o.value}:{}),(o==null?void 0:o.currency)!==void 0?{currency:o.currency}:{}),(o==null?void 0:o.externalId)!==void 0?{externalId:o.externalId}:{}))}},[t,e])}import{useEffect as Wt,useRef as Ze}from"react";function $t(e,t={}){let d=t,{componentId:n}=d,r=Re(d,["componentId"]),o=_(),i=ve(n!=null?n:""),u=Ze(!1),s=Ze(r);s.current=r,Wt(()=>{if(!o||u.current)return;u.current=!0;let{metadata:a,reward:y,value:g,currency:p,externalId:C}=s.current;if(n){i(e,s.current);return}o.goal(e,A(A(A({metadata:a!=null?a:{},weight:y!=null?y:1,stepIndex:0},g!==void 0?{value:g}:{}),p!==void 0?{currency:p}:{}),C!==void 0?{externalId:C}:{}))},[o,n,e,i])}import{renderPrePaintScript as Nt}from"@sentientui/core";import{confidenceBand as Ut}from"@sentientui/policy";import{jsx as zt}from"react/jsx-runtime";function et(e){return JSON.stringify(e).replace(/</g,"\\u003c")}function Jt(e){return e.persona?'(function(){try{var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",'+et(e.persona.persona)+');d.setAttribute("data-sentient-confidence",'+et(Ut(e.persona.confidence))+");}catch(e){}})();":Nt(e.apiKey)}function Ht(e){return zt("script",{"data-sentient-persona-script":"",nonce:e.nonce,dangerouslySetInnerHTML:{__html:Jt(e)}})}import{useEffect as le,useMemo as Se,useRef as tn}from"react";import{validateSlotDecl as nn}from"@sentientui/policy";import{useEffect as ye,useReducer as Xt,useState as qt,useSyncExternalStore as nt}from"react";import{armOfResult as se,baselineResultFor as Qt}from"@sentientui/core";import{confidenceBand as Yt}from"@sentientui/policy";var tt=new Set;function ae(e,t){var y;nt(F,fe,()=>0);let n=_(),r=He(),[,o]=Xt(g=>g+1,0),i=typeof window!="undefined"?(y=window.__sentient_slot_overrides)==null?void 0:y[e]:void 0,u=i===void 0?r[e]:void 0,s=i===void 0&&u===void 0&&n?n.getSlotResult(e):null,d=(n==null?void 0:n.isLocal)===!0&&i===void 0&&u===void 0&&s===null;ye(()=>{if(!d||!n)return;let g=!1;return n.decide({slots:[t]}).then(p=>{!g&&p&&o()}),()=>{g=!0}},[n,e,d]);let a=(()=>{if(i!==void 0)return{result:i,arm:se(i),source:"override"};if(u!==void 0)return{result:u,arm:se(u),source:"preloaded"};if(s!==null)return{result:s,arm:se(s),source:"client"};let g=Qt(t);return{result:g,arm:se(g),source:"baseline"}})();return ye(()=>{R()&&(!n||n.isLocal===!0||a.source==="baseline"&&(tt.has(e)||(tt.add(e),console.warn(`[sentient] slot "${e}" resolved to its baseline \u2014 no SSR-preloaded or decided result. Keyed clients decide slots server-side, so this slot serves baseline for the whole session and records no exposure. Preload it via loadAdaptiveDecision()/initialSlots so it can serve a decided arm and learn.`))))},[n,a.source,e]),a}function Zt(){var t;if(typeof window=="undefined")return null;let e=window.__sentient_persona_override;if(e!=null&&e.persona)return{persona:e.persona,confidence:(t=e.confidence)!=null?t:1};try{let n=new URLSearchParams(window.location.search).get("sentient_persona");if(n)return{persona:n,confidence:1}}catch(n){}return null}function en(){let e=_(),t=ze();nt(F,fe,()=>0);let[n,r]=qt(!1);ye(()=>r(!0),[]);let o=s=>({persona:s.persona,confidence:s.confidence,band:Yt(s.confidence)});if(!n)return t?o(t):null;let i=Zt();if(i)return o(i);if(t)return o(t);let u=e?e.getPersona():null;return u?o(u):null}var he=new Set;function rn(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/[\\"]/g,"\\$&")}function on(e,t,n){let r=_(),o=T(),i=JSON.stringify(t),u=Se(()=>({id:e,dims:t}),[e,i]),{result:s,arm:d,source:a}=ae(e,u),y=Se(()=>typeof s=="string"?{}:s,[d]);if(R()&&!he.has(e)){let f=nn({id:e,dims:Object.fromEntries(Object.entries(t).map(([l,c])=>[l,[...c]]))}),m=Object.values(t).reduce((l,c)=>l*c.length,1);f.ok?m>4&&(he.add(e),console.warn(`[sentient] useAdaptiveTokens("${e}") declares ${m} combinations \u2014 more than the recommended 4. Each extra combination needs more traffic to learn; consider fewer dims/values.`)):(he.add(e),console.warn(`[sentient] useAdaptiveTokens("${e}"): invalid declaration \u2014 ${f.reason}. Serving baseline.`))}let g=(n==null?void 0:n.goal)===void 0?null:typeof n.goal=="string"?n.goal:JSON.stringify(n.goal);le(()=>Z({id:e,dims:t}),[e]);let p=tn(null);le(()=>{!r||a==="baseline"||a==="override"||p.current===d||(p.current=d,K(r,o,e,d))},[r,o,e,d,a]);let C=n==null?void 0:n.funnel;le(()=>{var f;!r||!C||a==="override"||B(r,o,e,C,E((f=n==null?void 0:n.goal)!=null?f:"click"))},[r,o,e,C,g,a]),le(()=>{if(!r||!(n!=null&&n.goal)||a==="override")return;let f=document.querySelector(`[data-sentient-slot="${rn(e)}"]`);if(!f){R()&&console.warn(`[sentient] useAdaptiveTokens("${e}"): a goal is declared but no element carries the returned props \u2014 spread {...props} on the slot's element.`);return}let m=N(n.goal),l=P(n.goal),c=!1;return D(f,E(n.goal),{fireGoal:()=>{c||(c=!0,l!==void 0?r.componentGoal(e,m,{value:l}):r.componentGoal(e,m),r.goal(m,A({metadata:{componentId:e,arm:d},weight:1,stepIndex:0},l!==void 0?{value:l}:{})))},fireStep:(S,b,k)=>{r.componentGoal(e,S,{reward:b}),r.goal(S,{metadata:{componentId:e,arm:d},weight:b,stepIndex:k})}})},[r,e,g,d,a]);let w=Se(()=>{let f={"data-sentient-slot":e};for(let[m,l]of Object.entries(y))f[`data-${m}`]=l;return f},[e,y]);return{tokens:y,props:w}}import{useCallback as rt,useEffect as $,useMemo as be,useRef as we,useState as sn}from"react";import{attachMicroSignalDetectors as an}from"@sentientui/core";var it=new Set;function ln(e,t){var x;if(R()&&!t.goal)throw new Error(`[sentient] useAdaptive("${e}"): a goal is required \u2014 without one the optimizer accumulates exposures with no rewards and cannot learn. Pass e.g. goal: 'buy_click'.`);let n=_(),r=T(),o=Object.keys(t.variants).join(" "),i=be(()=>Object.keys(t.variants),[o]),{variantId:u,isOverride:s,settled:d}=H(e,i),a=(x=u!=null?u:i[0])!=null?x:"",y=t.variants[a],[g,p]=sn(null),C=we(null),w=rt(h=>{C.current=h,p(h)},[]),f=typeof t.goal=="string"?t.goal:JSON.stringify(t.goal),m=be(()=>E(t.goal),[f]),l=N(t.goal);$(()=>Y({id:e,variantIds:i,goal:l}),[e,i,l]);let c=we(null);$(()=>{s||d&&(!n||!a||!g||c.current!==a&&(c.current=a,K(n,r,e,a)))},[n,r,e,a,g,s,d]);let S=t.funnel;$(()=>{s||!d||!n||!S||B(n,r,e,S,m)},[n,r,e,S,m,s,d]);let b=we(!1);$(()=>{b.current=!1},[a,f]),$(()=>{if(s||!n||!a||!g)return;let h=P(m);return D(g,m,{fireGoal:()=>{b.current||(b.current=!0,n.track({projectId:r,componentId:e,variantId:a,eventType:"goal_achieved",goalType:l,payload:A({reward:1},h!==void 0?{goalValue:h}:{})}),n.goal(l,A({metadata:{componentId:e,variantId:a},weight:1,stepIndex:0},h!==void 0?{value:h}:{})))},fireStep:(v,O,M)=>{n.track({projectId:r,componentId:e,variantId:a,eventType:"goal_achieved",goalType:v,payload:{reward:O}}),n.goal(v,{metadata:{},weight:O,stepIndex:M})}})},[n,g,a,r,e,m,l,s]),$(()=>{if(s||!n||!a||!g)return;let h=Date.now();return an((v,O={})=>{n.track({projectId:r,componentId:e,variantId:a,eventType:"micro_signal",payload:A({signalType:v},O)})},g,h)},[n,g,a,r,e,s]),$(()=>{if(!R()||!n)return;let h=setTimeout(()=>{!C.current&&!it.has(e)&&(it.add(e),console.warn(`[sentient] useAdaptive("${e}"): bind was never attached \u2014 spread {...bind} on the rendered element, otherwise exposure and goal tracking cannot work and the optimizer learns nothing.`))},0);return()=>clearTimeout(h)},[n,e]);let k=rt((h,v)=>{var M,z;if(s)return;let O=h!=null?h:l;n==null||n.componentGoal(e,O,v),n==null||n.goal(O,A(A(A({metadata:(M=v==null?void 0:v.metadata)!=null?M:{},weight:(z=v==null?void 0:v.reward)!=null?z:1,stepIndex:0},(v==null?void 0:v.value)!==void 0?{value:v.value}:{}),(v==null?void 0:v.currency)!==void 0?{currency:v.currency}:{}),(v==null?void 0:v.externalId)!==void 0?{externalId:v.externalId}:{}))},[n,e,l,s]),G=be(()=>({ref:w,"data-sentient-id":e,"data-sentient-variant":a}),[w,e,a]);return{variant:a,value:y,bind:G,fireGoal:k}}import{Children as un,isValidElement as cn,useEffect as ue,useMemo as ot,useRef as st}from"react";import{jsx as fn}from"react/jsx-runtime";var ce=new Set;function dn(e){var l;let t=_(),n=T(),r=st(null),o=Object.keys(e.arrangements).join(" "),i=ot(()=>Object.keys(e.arrangements),[o]),u=ot(()=>A({id:e.id,arms:i},e.baseline!==void 0?{baseline:e.baseline}:{}),[e.id,i,e.baseline]),{arm:s,source:d}=ae(e.id,u);R()&&e.baseline!==void 0&&e.baseline!==i[0]&&!ce.has(e.id+":baseline")&&(ce.add(e.id+":baseline"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: baseline "${e.baseline}" is not the first-declared arrangement ("${i[0]}"). The first arrangement should usually be the page's real incumbent (the holdout sees it).`));let a=un.toArray(e.children).filter(cn),y=new Map;for(let c of a)y.set(String((l=c.key)!=null?l:"").replace(/^\.\$/,""),c);let g=e.arrangements[s],p=g!==void 0&&g.length===a.length&&g.every(c=>y.has(c));R()&&g!==void 0&&!p&&!ce.has(e.id+":keys")&&(ce.add(e.id+":keys"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: arrangement "${s}" [${g.join(", ")}] does not match the children's keys \u2014 rendering declaration order (fail-safe).`));let C=p?g.map(c=>y.get(c)):a;ue(()=>Z({id:e.id,arms:Object.keys(e.arrangements)}),[e.id]);let w=st(null);ue(()=>{!t||d==="baseline"||d==="override"||w.current===s||(w.current=s,K(t,n,e.id,s))},[t,n,e.id,s,d]);let f=e.funnel;ue(()=>{var c;!t||!f||d==="override"||B(t,n,e.id,f,E((c=e.goal)!=null?c:"click"))},[t,n,e.id,f,d]);let m=e.goal===void 0?null:typeof e.goal=="string"?e.goal:JSON.stringify(e.goal);return ue(()=>{if(!t||e.goal===void 0||d==="override")return;let c=r.current;if(!c)return;let S=N(e.goal),b=P(e.goal),k=!1;return D(c,E(e.goal),{fireGoal:()=>{k||(k=!0,b!==void 0?t.componentGoal(e.id,S,{value:b}):t.componentGoal(e.id,S),t.goal(S,A({metadata:{componentId:e.id,arm:s},weight:1,stepIndex:0},b!==void 0?{value:b}:{})))},fireStep:(G,x,h)=>{t.componentGoal(e.id,G,{reward:x}),t.goal(G,{metadata:{componentId:e.id,arm:s},weight:x,stepIndex:h})}})},[t,e.id,m,s,d]),fn("div",{ref:r,"data-sentient-id":e.id,"data-sentient-variant":s,children:C})}import{deriveSessionSegment as gn}from"@sentientui/core";var mn=["page","blocks","layoutOrder"],at=new Map;function pn(e,t){at.set(e,t)}function lt(e){return at.get(e)}function vn(e){var o,i;let t=(i=(o=e.content)!=null?o:lt(e.page))!=null?i:{},n={};for(let[u,s]of Object.entries(t))mn.includes(u)||(n[u]=s);let r=q(A({},n),{page:e.page,blocks:e.blocks});return e.layoutOrder&&(r.layoutOrder=e.layoutOrder),r}function yn(e){return`<script type="application/ld+json">${ut(e)}</script>`}function ut(e){return JSON.stringify(A({"@context":"https://schema.org","@type":"WebPage"},e)).replace(/</g,"\\u003c")}function Sn(e){let t=[];e.title&&t.push(`# ${e.title}`,""),e.summary&&t.push(String(e.summary),"");for(let[n,r]of Object.entries(e))["page","title","summary","blocks","layoutOrder"].includes(n)||t.push(`## ${n}`,"","```json",JSON.stringify(r,null,2),"```","");if(e.blocks.length>0){t.push("## blocks","");for(let n of e.blocks)t.push(`- **${n.id}** \u2192 variant \`${n.variant}\``),n.content!==void 0&&t.push(""," ```json",JSON.stringify(n.content,null,2)," ```");t.push("")}return t.join(`
3
3
  `).trimEnd()+`
4
4
  `}import{grantConsent as yi}from"@sentientui/core";export{Dt as Adaptive,dn as AdaptiveGroup,At as AdaptiveProvider,Bt as AdaptiveText,Ht as SentientPersonaScript,vn as buildAgentFeed,pn as defineAgentContent,gn as detectSegment,lt as getAgentContent,yi as grantConsent,yn as renderAgentJsonLd,ut as renderAgentJsonLdBody,Sn as renderAgentMarkdown,ln as useAdaptive,Ct as useAdaptiveApiBaseUrl,ve as useAdaptiveGoal,en as useAdaptivePersona,on as useAdaptiveTokens,H as useAssignment,me as useInitialAssignments,kt as useLayoutOrder,$t as usePageGoal,_ as useSentient};
5
5
  //# sourceMappingURL=index.mjs.map