@sentientui/react 0.25.1 → 0.26.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/README.md +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/next/adaptive-root.d.ts +24 -0
- package/dist/next/adaptive-root.js +2 -2
- package/dist/next/adaptive-root.js.map +1 -1
- package/dist/server.d.cts +9 -0
- package/dist/server.d.ts +9 -0
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +1 -1
- package/dist/server.mjs.map +1 -1
- package/dist/testing/react.js +1 -1
- package/dist/testing/react.js.map +1 -1
- package/dist/testing/react.mjs +1 -1
- package/dist/testing/react.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
var gt=Object.defineProperty,mt=Object.defineProperties;var pt=Object.getOwnPropertyDescriptors;var X=Object.getOwnPropertySymbols;var Oe=Object.prototype.hasOwnProperty,Ee=Object.prototype.propertyIsEnumerable;var Re=(e,t,n)=>t in e?gt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,C=(e,t)=>{for(var n in t||(t={}))Oe.call(t,n)&&Re(e,n,t[n]);if(X)for(var n of X(t))Ee.call(t,n)&&Re(e,n,t[n]);return e},q=(e,t)=>mt(e,pt(t));var Ie=(e,t)=>{var n={};for(var r in e)Oe.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&&Ee.call(e,r)&&(n[r]=e[r]);return n};import{createContext as ht,useContext as L,useEffect as $,useMemo as Je,useRef as ve,useState as ee,useSyncExternalStore as bt}from"react";import{deriveSessionSegment as wt,init as xt}from"@sentientui/core";var Le=new Map,Q=new Map;function Pe(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 Te(e,t){Le.set(e,t);let n=Q.get(e);if(n)for(let r of n)try{r(t)}catch(o){}}function de(e){var t;return(t=Le.get(e))!=null?t:null}var vt={on:!1,listeners:new Set};function De(){if(typeof window=="undefined")return vt;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function fe(){return De().on}function Fe(e){let t=De().listeners;return t.add(e),()=>{t.delete(e)}}function Me(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 Be="sentient:overrides-changed";function Ke(){var e;return typeof window=="undefined"?0:(e=window.__sentient_overrides_version)!=null?e:0}function F(e){return typeof window=="undefined"?()=>{}:(window.addEventListener(Be,e),()=>window.removeEventListener(Be,e))}function je(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}var ge=new Set,me=!1;function Ve(e){if(ge.has(e))return!0;if(ge.add(e),!me){me=!0;let t=()=>{me=!1,ge.clear()};if(typeof MessageChannel=="function"){let n=new MessageChannel;n.port1.onmessage=()=>{n.port1.close(),n.port2.close(),t()},n.port2.postMessage(0)}else setTimeout(t,0)}return!1}function yt(e){if(!(e instanceof Element))return!1;let t=e.tagName.toLowerCase();return t==="a"||t==="button"?!0:e.getAttribute("role")==="button"}function $e(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(yt(r))return!0;r=r.parentElement}return!1}function T(e,t,n,r){if(t.type==="weighted_composite"){let u=new Set,m=[];return t.steps.forEach(({goal:g,name:p,weight:k},w)=>{let x=(c=!1)=>{u.has(w)||c&&r!==void 0&&Ve(`step\0${p}\0${k}\0${w}`)||(u.add(w),n.fireStep(p,k,w))};if(g.type==="click"){let c=s=>{let l=s.target;l instanceof Element&&$e(l,e,g.selector)&&x()};e.addEventListener("click",c),m.push(()=>e.removeEventListener("click",c));return}if(g.type==="form_submit"){let c=s=>{s.target instanceof HTMLFormElement&&e.contains(s.target)&&x()};e.addEventListener("submit",c),m.push(()=>e.removeEventListener("submit",c));return}if(g.type==="scroll_depth"){let c=Math.max(0,Math.min(1,g.threshold)),s=new IntersectionObserver(l=>{for(let v of l)if(v.intersectionRatio>=c){x(!0),s.disconnect();break}},{threshold:[c]});s.observe(e),m.push(()=>s.disconnect())}}),()=>{for(let g of m)g()}}let o=t.type==="composite"?t.all:[t],i=new Set(o.map((u,m)=>m)),f=()=>{r!==void 0&&Ve(r)||n.fireGoal()},a=(u,m=!1)=>{i.delete(u),i.size===0&&(m?f():n.fireGoal())},d=[];return o.forEach((u,m)=>{if(u.type==="click"){let g=p=>{let k=p.target;k instanceof Element&&$e(k,e,u.selector)&&(t.type==="composite"?a(m):n.fireGoal())};e.addEventListener("click",g),d.push(()=>e.removeEventListener("click",g));return}if(u.type==="form_submit"){let g=p=>{p.target instanceof HTMLFormElement&&e.contains(p.target)&&(t.type==="composite"?a(m):n.fireGoal())};e.addEventListener("submit",g),d.push(()=>e.removeEventListener("submit",g));return}if(u.type==="scroll_depth"){let g=Math.max(0,Math.min(1,u.threshold)),p=new IntersectionObserver(k=>{for(let w of k)if(w.intersectionRatio>=g){t.type==="composite"?a(m,!0):f(),p.disconnect();break}},{threshold:[g]});p.observe(e),d.push(()=>p.disconnect());return}}),()=>{for(let u of d)u()}}var We=new Set,Ne=new Set;function B(e,t,n,r,o){let i=`${r}|${n}`;if(Ne.has(i))return;Ne.add(i);let f=o.type==="weighted_composite"&&!We.has(r);f&&We.add(r),e.track({projectId:t,componentId:n,eventType:"funnel_declared",payload:f?{funnelId:r,steps:o.steps.map(a=>({goalId:a.name,weight:a.weight}))}:{funnelId:r}})}function K(e,t,n,r){e.track({projectId:t,componentId:n,variantId:r,eventType:"variant_assigned",payload:{}})}var St={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function V(){if(typeof window=="undefined")return St;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 Ue=()=>{};function Y(e){return R()?(V().components.set(e.id,e),J(),()=>{V().components.delete(e.id),J()}):Ue}function Z(e){return R()?(V().slots.set(e.id,e),J(),()=>{V().slots.delete(e.id),J()}):Ue}function pe(e){R()&&(V().sections=[...e],J())}import{jsx as Rt}from"react/jsx-runtime";function At(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{return wt({userAgent:(e=navigator.userAgent)!=null?e:"",referer:(t=document.referrer)!=null?t:"",appOrigin:window.location.origin})}catch(n){return"desktop:direct"}}var He="https://api.sentient-ui.com/v1",I=ht({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialPersona:null,apiBaseUrl:He,debug:!1});function kt(e){let[t,n]=ee(!1),r=ve(e);r.current=e;let{cookie:o,value:i,event:f}=e!=null?e:{},a=typeof(e==null?void 0:e.check)=="function";return $(()=>{let d=()=>{var p;let m=r.current;if(!m)return!1;if(m.check)return m.check()===!0;if(!m.cookie||typeof document=="undefined")return!1;let g=`${m.cookie}=${(p=m.value)!=null?p:"accepted"}`;return document.cookie.split("; ").some(k=>k.trim()===g)};if(n(d()),!f)return;let u=()=>{n(d())};return window.addEventListener(f,u),()=>window.removeEventListener(f,u)},[o,i,f,a]),t}function Ct(e){var w,x;let[t,n]=ee(null),[r]=ee(()=>{var c;return(c=e.sessionSegment)!=null?c:At()}),[o,i]=ee(fe());$(()=>Fe(()=>i(fe())),[]);let f=kt(e.consentFrom),a=e.consentFrom?e.consent===!0||f:e.consent,d=ve(null);$(()=>{var A;if(a===!1&&!e.preConsentBehavior){(A=d.current)==null||A.destroy(),d.current=null,n(null);return}let c={apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,sessionSegment:r,consent:a,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},s=!1,l=null,v=null,h=G=>{e.engagement!==!1&&import("@sentientui/core/engagement").then(({startEngagementCapture:S})=>{s||(v=S(G,{apiKey:e.apiKey,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:G})=>{s||(l=G(q(C({},c),{graph:!0,captureDomText:e.captureDomText===!0})),d.current=l,n(l),h(l))}):(l=xt(c),d.current=l,n(l),h(l)),()=>{s=!0,v==null||v(),l==null||l.dispose()}},[a]),$(()=>{if(!t)return;let c=!1,s=async()=>{if(c)return;let v;try{v=await t.fetchWeights()}catch(h){return}if(!c)for(let h of v){let A={componentId:h.componentId,updatedAt:h.updatedAt,variants:h.variants.map(G=>{var S;return{variantId:G.variantId,pulls:G.pulls,avgReward:(S=G.avgReward)!=null?S:0}})};Te(h.componentId,A)}};s();let l=setInterval(()=>{s()},6e4);return()=>{c=!0,clearInterval(l)}},[t]);let u=(w=e.ssrFallback)!=null?w:"first",m=((x=e.apiBaseUrl)!=null?x:He).replace(/\/$/,""),g=ve(null);$(()=>{var l;if(typeof process!="undefined"&&((l=process.env)==null?void 0:l.NODE_ENV)==="production")return;let c={apiKey:e.apiKey,context:e.context,country:e.country,persona:e.persona,apiBaseUrl:m},s=g.current;if(g.current=c,s!==null)for(let v of["apiKey","context","country","persona","apiBaseUrl"])Object.is(s[v],c[v])||console.warn(`[sentient] AdaptiveProvider: \`${v}\` 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,m]),$(()=>{var c;typeof process!="undefined"&&((c=process.env)==null?void 0:c.NODE_ENV)==="production"||je({apiKey:e.apiKey,apiBaseUrl:m,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,m]),$(()=>{let c=e.initialLayoutOrder;if(c&&c.length>0){pe(c);return}e.declaredSections&&e.declaredSections.length>0&&pe(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]);let p=Je(()=>t&&o?Me(t):t,[t,o]),k=Je(()=>{var c,s,l,v,h;return{client:p,apiKey:e.apiKey,initialAssignments:(c=e.initialAssignments)!=null?c:{},sessionSegment:r,ssrFallback:u,onAssignment:e.onAssignment,initialLayoutOrder:(s=e.initialLayoutOrder)!=null?s:null,initialSlots:(l=e.initialSlots)!=null?l:{},initialPersona:(v=e.initialPersona)!=null?v:null,apiBaseUrl:m,debug:(h=e.debug)!=null?h:!1}},[p,e.apiKey,e.initialAssignments,r,u,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialPersona,m,e.debug]);return Rt(I.Provider,{value:k,children:e.children})}function _(){return L(I).client}function D(){return L(I).apiKey}function ye(){return L(I).initialAssignments}function te(){return L(I).sessionSegment}function ze(){return L(I).ssrFallback}function ne(){return L(I).onAssignment}function Xe(){return L(I).debug}function Gt(){let e=L(I).initialLayoutOrder,t=bt(F,()=>{var n;return typeof window=="undefined"?null:(n=window.__sentient_layout_override)!=null?n:null},()=>null);return t!=null?t:e}function qe(){return L(I).initialSlots}function Qe(){return L(I).initialPersona}function _t(){return L(I).apiBaseUrl}import{memo as It,useEffect as j,useMemo as Ze,useRef as ie,useState as Lt}from"react";import{attachMicroSignalDetectors as Pt}from"@sentientui/core";import{useEffect as re,useRef as Ye,useState as Ot,useSyncExternalStore as Et}from"react";import{pickFromWeights as Se}from"@sentientui/policy";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}function H(e,t,n,r){let o=ye(),i=ze(),f=_(),a=te(),d=ne(),u=Xe(),m=Ye(null),g=Et(F,()=>U(e),()=>null),p=g&&t.includes(g)?g:null,k=Ye(null);re(()=>{u&&p&&k.current!==p&&(k.current=p,console.info(`[sentient] override active: ${e} -> ${p}`))},[u,p,e]);let[w,x]=Ot(()=>{var v,h;if(p)return{variantId:p,content:null,isLoading:!1,settled:!0};if(!f){let A=o[e];return A&&t.includes(A)?{variantId:A,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 s=f.getAssignment(e,a);if(s&&(t.includes(s.variantId)||s.content))return{variantId:s.variantId,content:(v=s.content)!=null?v:null,isLoading:!1,settled:!0};let l=de(e);if(l){let A=Se(l.variants,t);if(A)return{variantId:A,content:null,isLoading:!1,settled:!0}}return{variantId:(h=t[0])!=null?h:null,content:null,isLoading:!1,settled:!1}}),c=s=>{d&&m.current!==s&&(m.current=s,d(e,s))};return re(()=>{var v;if(p||!f)return;let s=f.getAssignment(e,a);if(s&&(t.includes(s.variantId)||s.content)){x({variantId:s.variantId,content:(v=s.content)!=null?v:null,isLoading:!1,settled:!0}),c(s.variantId);return}let l=de(e);if(l&&w.settled&&w.variantId&&w.variantId===Se(l.variants,t)){c(w.variantId);return}x(h=>{var A;return h.variantId?h:{variantId:(A=t[0])!=null?A:null,content:null,isLoading:!1,settled:!1}})},[p,f,e,a]),re(()=>{if(p||!f)return;let s=f.getAssignment(e,a);if(s&&t.includes(s.variantId))return;let l=!1;return f.assign(e,t,n,r).then(v=>{var h;l||v&&(!t.includes(v.variantId)&&!v.content||(x({variantId:v.variantId,content:(h=v.content)!=null?h:null,isLoading:!1,settled:!0}),c(v.variantId)))}),()=>{l=!0}},[p,f,e,a]),re(()=>{if(!p&&f)return Pe(e,s=>{var h;let l=f.getAssignment(e,a);if(l&&(t.includes(l.variantId)||l.content)){x({variantId:l.variantId,content:(h=l.content)!=null?h:null,isLoading:!1,settled:!0}),c(l.variantId);return}let v=Se(s.variants,t);v&&(x({variantId:v,content:null,isLoading:!1,settled:!0}),c(v))})},[p,f,e,a]),p?{variantId:p,content:null,isLoading:!1,settled:!0,isOverride:!0}:w}import{jsx as Ft}from"react/jsx-runtime";function Tt(e){var h;let t=_(),n=D(),r=Object.keys(e.variants).join("\0"),o=Ze(()=>Object.keys(e.variants),[r]),{variantId:i,content:f,isOverride:a,settled:d}=H(e.id,o,e.agentData,e.agentDataByVariant),u=ie(null),[m,g]=Lt(!1);j(()=>{g(!0)},[]);let p=ie(!1),k=ie(new Set),w=ie(null),x=typeof e.goal=="string"?e.goal:JSON.stringify(e.goal),c=Ze(()=>E(e.goal),[x]),s=typeof e.goal=="string"?e.goal:c.type;if(j(()=>Y({id:e.id,variantIds:o,goal:s}),[e.id,o,s]),j(()=>{a||d&&(!t||!i||!n||w.current!==i&&(w.current=i,K(t,n,e.id,i)))},[t,i,n,e.id,a,d]),j(()=>{p.current=!1,k.current=new Set},[i,c]),j(()=>{a||!d||!t||!e.funnel||B(t,n,e.id,e.funnel,c)},[t,n,e.id,e.funnel,c,a,d]),j(()=>{if(a||!d||!t||!i)return;let A=u.current;if(!A)return;let G=null,S=0,b=()=>{S=Date.now(),G=setTimeout(()=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-S}}),G=null},800)},y=()=>{G!==null&&(clearTimeout(G),G=null)};return A.addEventListener("mouseenter",b),A.addEventListener("mouseleave",y),()=>{A.removeEventListener("mouseenter",b),A.removeEventListener("mouseleave",y),G!==null&&clearTimeout(G)}},[t,i,n,e.id,a,d]),j(()=>{if(a||!d||!t||!i)return;let A=u.current;if(!A)return;let G=Date.now();return Pt((S,b={})=>{var Ce,Ge,_e;t.track({projectId:n,componentId:e.id,variantId:i,eventType:"micro_signal",payload:C({signalType:S},b)});let y=(Ce=e.microSignalGoals)==null?void 0:Ce[S];if(!y||k.current.has(S))return;k.current.add(S);let O=typeof y=="string"?y:y.name,M=typeof y=="string"?1:(Ge=y.weight)!=null?Ge:1,z=typeof y=="string"?0:(_e=y.stepIndex)!=null?_e:0;t.goal(O,{metadata:C({signalType:S},b),weight:M,stepIndex:z})},A,G)},[t,i,n,e.id,e.microSignalGoals,a,d]),j(()=>{if(a||!d||!t||!i)return;let A=u.current;if(!A)return;let G=P(c);return T(A,c,{fireGoal:()=>{p.current||(p.current=!0,t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:s,payload:C({reward:1},G!==void 0?{goalValue:G}:{})}),t.goal(s,C({metadata:{componentId:e.id,variantId:i},weight:1,stepIndex:0},G!==void 0?{value:G}:{})))},fireStep:(S,b,y)=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:S,payload:{reward:b}}),t.goal(S,{metadata:{},weight:b,stepIndex:y})}},s)},[t,i,n,e.id,c,s,a,d]),e.clientOnly&&(!m||!t)||!i)return null;let l=(h=e.variants[i])!=null?h:null,v=l===null?f:null;return R()&&l===null&&v===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.`),Ft("div",{ref:u,"data-sentient-id":e.id,"data-sentient-variant":i,children:l!=null?l:v})}var Dt=It(Tt,(e,t)=>{if(e.id!==t.id||e.goal!==t.goal&&JSON.stringify(e.goal)!==JSON.stringify(t.goal)||e.microSignalGoals!==t.microSignalGoals||e.funnel!==t.funnel||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 Mt,useRef as he,useState as et,useSyncExternalStore as Bt}from"react";import{jsx as jt}from"react/jsx-runtime";function Kt({id:e,default:t,component:n="span",className:r,goal:o}){var G;let i=_(),f=D(),a=ne(),d=te(),u=he(null),m=he(null),g=Bt(F,()=>U(e),()=>null),[p,k]=et(()=>{var S,b;return(b=(S=i==null?void 0:i.getAssignment(e,d))==null?void 0:S.content)!=null?b:null}),[w,x]=et(()=>{var S,b;return(b=(S=i==null?void 0:i.getAssignment(e,d))==null?void 0:S.variantId)!=null?b:null});oe(()=>{if(g||!i)return;let S=i.getAssignment(e,d);if((S==null?void 0:S.content)!==void 0){x(S.variantId),k(S.content);return}let b=!1;return i.assign(e).then(y=>{if(!b){if(!y){R()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}x(y.variantId),y.content&&k(y.content)}}),()=>{b=!0}},[i,e,d,g]),oe(()=>{g||!i||!w||!f||u.current!==w&&(u.current=w,i.track({projectId:f,componentId:e,variantId:w,eventType:"variant_assigned",payload:{}}),a==null||a(e,w))},[i,w,f,e,a,g]);let c=o===void 0?"":typeof o=="string"?o:JSON.stringify(o),s=Mt(()=>o===void 0?null:E(o),[c]),l=o===void 0?null:typeof o=="string"?o:s.type,v=he(!1);oe(()=>{v.current=!1},[w,c]),oe(()=>{if(g||!i||!w||!f||!s||!l)return;let S=m.current;if(!S)return;let b=P(s);return T(S,s,{fireGoal:()=>{v.current||(v.current=!0,i.track({projectId:f,componentId:e,variantId:w,eventType:"goal_achieved",goalType:l,payload:C({reward:1},b!==void 0?{goalValue:b}:{})}),i.goal(l,C({metadata:{componentId:e,variantId:w},weight:1,stepIndex:0},b!==void 0?{value:b}:{})))},fireStep:(y,O,M)=>{i.track({projectId:f,componentId:e,variantId:w,eventType:"goal_achieved",goalType:y,payload:{reward:O}}),i.goal(y,{metadata:{},weight:O,stepIndex:M})}})},[i,w,f,e,s,l,g]);let h=p!=null?p:t;if(g){let S=i==null?void 0:i.getAssignment(e,d);h=S&&S.variantId===g&&(G=S.content)!=null?G:t}return jt(n,{ref:S=>{m.current=S},className:r,children:h})}import{useCallback as Vt,useRef as $t}from"react";function be(e){let t=_(),n=$t(new Set);return Vt((r,o)=>{var i,f;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,C(C(C({metadata:(i=o==null?void 0:o.metadata)!=null?i:{},weight:(f=o==null?void 0:o.reward)!=null?f: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 tt}from"react";function Nt(e,t={}){let d=t,{componentId:n}=d,r=Ie(d,["componentId"]),o=_(),i=be(n!=null?n:""),f=tt(!1),a=tt(r);a.current=r,Wt(()=>{if(!o||f.current)return;f.current=!0;let{metadata:u,reward:m,value:g,currency:p,externalId:k}=a.current;if(n){i(e,a.current);return}o.goal(e,C(C(C({metadata:u!=null?u:{},weight:m!=null?m:1,stepIndex:0},g!==void 0?{value:g}:{}),p!==void 0?{currency:p}:{}),k!==void 0?{externalId:k}:{}))},[o,n,e,i])}import{renderPrePaintScript as Ut}from"@sentientui/core";import{confidenceBand as Jt}from"@sentientui/policy";import{jsx as Xt}from"react/jsx-runtime";function nt(e){return JSON.stringify(e).replace(/</g,"\\u003c")}function Ht(e){return e.persona?'(function(){try{var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",'+nt(e.persona.persona)+');d.setAttribute("data-sentient-confidence",'+nt(Jt(e.persona.confidence))+");}catch(e){}})();":Ut(e.apiKey)}function zt(e){return Xt("script",{"data-sentient-persona-script":"",nonce:e.nonce,dangerouslySetInnerHTML:{__html:Ht(e)}})}import{useEffect as le,useMemo as xe,useRef as nn}from"react";import{validateSlotDecl as rn}from"@sentientui/policy";import{useEffect as we,useReducer as qt,useState as Qt,useSyncExternalStore as it}from"react";import{armOfResult as se,baselineResultFor as Yt}from"@sentientui/core";import{confidenceBand as Zt}from"@sentientui/policy";var rt=new Set;function ae(e,t){let n=_(),r=qe(),[,o]=qt(m=>m+1,0),i=it(F,()=>{var m;return typeof window!="undefined"?(m=window.__sentient_slot_overrides)==null?void 0:m[e]:void 0},()=>{}),f=i===void 0?r[e]:void 0,a=i===void 0&&f===void 0&&n?n.getSlotResult(e):null,d=(n==null?void 0:n.isLocal)===!0&&i===void 0&&f===void 0&&a===null;we(()=>{if(!d||!n)return;let m=!1;return n.decide({slots:[t]}).then(g=>{!m&&g&&o()}),()=>{m=!0}},[n,e,d]);let u=(()=>{if(i!==void 0)return{result:i,arm:se(i),source:"override"};if(f!==void 0)return{result:f,arm:se(f),source:"preloaded"};if(a!==null)return{result:a,arm:se(a),source:"client"};let m=Yt(t);return{result:m,arm:se(m),source:"baseline"}})();return we(()=>{R()&&(!n||n.isLocal===!0||u.source==="baseline"&&(rt.has(e)||(rt.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,u.source,e]),u}function en(){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 tn(){let e=_(),t=Qe();it(F,Ke,()=>0);let[n,r]=Qt(!1);we(()=>r(!0),[]);let o=a=>({persona:a.persona,confidence:a.confidence,band:Zt(a.confidence)});if(!n)return t?o(t):null;let i=en();if(i)return o(i);if(t)return o(t);let f=e?e.getPersona():null;return f?o(f):null}var ot=new Set;function on(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/[\\"]/g,"\\$&")}function sn(e,t,n){let r=_(),o=D(),i=JSON.stringify(t),f=xe(()=>({id:e,dims:t}),[e,i]),{result:a,arm:d,source:u}=ae(e,f),m=xe(()=>typeof a=="string"?{}:a,[d]);if(R()&&!ot.has(e)){ot.add(e);let x=rn({id:e,dims:Object.fromEntries(Object.entries(t).map(([s,l])=>[s,[...l]]))}),c=Object.values(t).reduce((s,l)=>s*l.length,1);x.ok?c>4&&console.warn(`[sentient] useAdaptiveTokens("${e}") declares ${c} combinations \u2014 more than the recommended 4. Each extra combination needs more traffic to learn; consider fewer dims/values.`):console.warn(`[sentient] useAdaptiveTokens("${e}"): invalid declaration \u2014 ${x.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=nn(null);le(()=>{!r||u==="baseline"||u==="override"||p.current===d||(p.current=d,K(r,o,e,d))},[r,o,e,d,u]);let k=n==null?void 0:n.funnel;le(()=>{var x;!r||!k||u==="override"||B(r,o,e,k,E((x=n==null?void 0:n.goal)!=null?x:"click"))},[r,o,e,k,g,u]),le(()=>{if(!r||!(n!=null&&n.goal)||u==="override"||u==="baseline")return;let x=document.querySelector(`[data-sentient-slot="${on(e)}"]`);if(!x){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 c=N(n.goal),s=P(n.goal),l=!1;return T(x,E(n.goal),{fireGoal:()=>{l||(l=!0,s!==void 0?r.componentGoal(e,c,{value:s}):r.componentGoal(e,c),r.goal(c,C({metadata:{componentId:e,arm:d},weight:1,stepIndex:0},s!==void 0?{value:s}:{})))},fireStep:(v,h,A)=>{r.componentGoal(e,v,{reward:h}),r.goal(v,{metadata:{componentId:e,arm:d},weight:h,stepIndex:A})}},c)},[r,e,g,d,u]);let w=xe(()=>{let x={"data-sentient-slot":e};for(let[c,s]of Object.entries(m))x[`data-${c}`]=s;return x},[e,m]);return{tokens:m,props:w}}import{useCallback as st,useEffect as W,useMemo as Ae,useRef as ke,useState as an}from"react";import{attachMicroSignalDetectors as ln}from"@sentientui/core";var at=new Set;function un(e,t){var S;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=D(),o=Object.keys(t.variants).join(" "),i=Ae(()=>Object.keys(t.variants),[o]),{variantId:f,isOverride:a,settled:d}=H(e,i),u=(S=f!=null?f:i[0])!=null?S:"",m=t.variants[u],[g,p]=an(null),k=ke(null),w=st(b=>{k.current=b,p(b)},[]),x=typeof t.goal=="string"?t.goal:JSON.stringify(t.goal),c=Ae(()=>t.goal?E(t.goal):null,[x]),s=t.goal?N(t.goal):"";W(()=>Y({id:e,variantIds:i,goal:s}),[e,i,s]);let l=ke(null);W(()=>{a||d&&(!n||!u||!g||l.current!==u&&(l.current=u,K(n,r,e,u)))},[n,r,e,u,g,a,d]);let v=t.funnel;W(()=>{a||!d||!n||!v||!c||B(n,r,e,v,c)},[n,r,e,v,c,a,d]);let h=ke(!1);W(()=>{h.current=!1},[u,x]),W(()=>{if(a||!d||!n||!u||!g||!c)return;let b=P(c);return T(g,c,{fireGoal:()=>{h.current||(h.current=!0,n.track({projectId:r,componentId:e,variantId:u,eventType:"goal_achieved",goalType:s,payload:C({reward:1},b!==void 0?{goalValue:b}:{})}),n.goal(s,C({metadata:{componentId:e,variantId:u},weight:1,stepIndex:0},b!==void 0?{value:b}:{})))},fireStep:(y,O,M)=>{n.track({projectId:r,componentId:e,variantId:u,eventType:"goal_achieved",goalType:y,payload:{reward:O}}),n.goal(y,{metadata:{},weight:O,stepIndex:M})}},s)},[n,g,u,r,e,c,s,a,d]),W(()=>{if(a||!n||!u||!g)return;let b=Date.now();return ln((y,O={})=>{n.track({projectId:r,componentId:e,variantId:u,eventType:"micro_signal",payload:C({signalType:y},O)})},g,b)},[n,g,u,r,e,a]),W(()=>{if(!R()||!n)return;let b=setTimeout(()=>{!k.current&&!at.has(e)&&(at.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(b)},[n,e]);let A=st((b,y)=>{var M,z;if(a)return;let O=b!=null?b:s;O&&(n==null||n.componentGoal(e,O,y),n==null||n.goal(O,C(C(C({metadata:(M=y==null?void 0:y.metadata)!=null?M:{},weight:(z=y==null?void 0:y.reward)!=null?z:1,stepIndex:0},(y==null?void 0:y.value)!==void 0?{value:y.value}:{}),(y==null?void 0:y.currency)!==void 0?{currency:y.currency}:{}),(y==null?void 0:y.externalId)!==void 0?{externalId:y.externalId}:{})))},[n,e,s,a]),G=Ae(()=>({ref:w,"data-sentient-id":e,"data-sentient-variant":u}),[w,e,u]);return{variant:u,value:m,bind:G,fireGoal:A}}import{Children as cn,isValidElement as dn,useEffect as ue,useMemo as lt,useRef as ut}from"react";import{jsx as gn}from"react/jsx-runtime";var ce=new Set;function fn(e){var s;let t=_(),n=D(),r=ut(null),o=Object.keys(e.arrangements).join(" "),i=lt(()=>Object.keys(e.arrangements),[o]),f=lt(()=>C({id:e.id,arms:i},e.baseline!==void 0?{baseline:e.baseline}:{}),[e.id,i,e.baseline]),{arm:a,source:d}=ae(e.id,f);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 u=cn.toArray(e.children).filter(dn),m=new Map;for(let l of u)m.set(String((s=l.key)!=null?s:"").replace(/^\.\$/,""),l);let g=e.arrangements[a],p=g!==void 0&&g.length===u.length&&g.every(l=>m.has(l));R()&&g!==void 0&&!p&&!ce.has(e.id+":keys")&&(ce.add(e.id+":keys"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: arrangement "${a}" [${g.join(", ")}] does not match the children's keys \u2014 rendering declaration order (fail-safe).`));let k=p?g.map(l=>m.get(l)):u;ue(()=>Z({id:e.id,arms:Object.keys(e.arrangements)}),[e.id]);let w=ut(null);ue(()=>{!t||d==="baseline"||d==="override"||w.current===a||(w.current=a,K(t,n,e.id,a))},[t,n,e.id,a,d]);let x=e.funnel;ue(()=>{var l;!t||!x||d==="override"||B(t,n,e.id,x,E((l=e.goal)!=null?l:"click"))},[t,n,e.id,x,d]);let c=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"||d==="baseline")return;let l=r.current;if(!l)return;let v=N(e.goal),h=P(e.goal),A=!1;return T(l,E(e.goal),{fireGoal:()=>{A||(A=!0,h!==void 0?t.componentGoal(e.id,v,{value:h}):t.componentGoal(e.id,v),t.goal(v,C({metadata:{componentId:e.id,arm:a},weight:1,stepIndex:0},h!==void 0?{value:h}:{})))},fireStep:(G,S,b)=>{t.componentGoal(e.id,G,{reward:S}),t.goal(G,{metadata:{componentId:e.id,arm:a},weight:S,stepIndex:b})}},v)},[t,e.id,c,a,d]),gn("div",{ref:r,"data-sentient-id":e.id,"data-sentient-variant":a,children:k})}import{deriveSessionSegment as mn}from"@sentientui/core";var pn=["page","blocks","layoutOrder"],ct=new Map;function vn(e,t){ct.set(e,t)}function dt(e){return ct.get(e)}function yn(e){var o,i;let t=(i=(o=e.content)!=null?o:dt(e.page))!=null?i:{},n={};for(let[f,a]of Object.entries(t))pn.includes(f)||(n[f]=a);let r=q(C({},n),{page:e.page,blocks:e.blocks});return e.layoutOrder&&(r.layoutOrder=e.layoutOrder),r}function Sn(e){return`<script type="application/ld+json">${ft(e)}</script>`}function ft(e){return JSON.stringify(C({"@context":"https://schema.org","@type":"WebPage"},e)).replace(/</g,"\\u003c")}function hn(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 gt=Object.defineProperty,mt=Object.defineProperties;var pt=Object.getOwnPropertyDescriptors;var X=Object.getOwnPropertySymbols;var Oe=Object.prototype.hasOwnProperty,Ee=Object.prototype.propertyIsEnumerable;var Re=(e,t,n)=>t in e?gt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,C=(e,t)=>{for(var n in t||(t={}))Oe.call(t,n)&&Re(e,n,t[n]);if(X)for(var n of X(t))Ee.call(t,n)&&Re(e,n,t[n]);return e},q=(e,t)=>mt(e,pt(t));var Ie=(e,t)=>{var n={};for(var r in e)Oe.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&&Ee.call(e,r)&&(n[r]=e[r]);return n};import{createContext as ht,useContext as L,useEffect as K,useMemo as Je,useRef as ve,useState as ee,useSyncExternalStore as bt}from"react";import{deriveSessionSegment as wt,init as At}from"@sentientui/core";var Le=new Map,Q=new Map;function Pe(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 Te(e,t){Le.set(e,t);let n=Q.get(e);if(n)for(let r of n)try{r(t)}catch(o){}}function de(e){var t;return(t=Le.get(e))!=null?t:null}var vt={on:!1,listeners:new Set};function De(){if(typeof window=="undefined")return vt;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function fe(){return De().on}function Fe(e){let t=De().listeners;return t.add(e),()=>{t.delete(e)}}function Me(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 Be="sentient:overrides-changed";function je(){var e;return typeof window=="undefined"?0:(e=window.__sentient_overrides_version)!=null?e:0}function F(e){return typeof window=="undefined"?()=>{}:(window.addEventListener(Be,e),()=>window.removeEventListener(Be,e))}function Ke(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function _(){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 U(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}var ge=new Set,me=!1;function $e(e){if(ge.has(e))return!0;if(ge.add(e),!me){me=!0;let t=()=>{me=!1,ge.clear()};if(typeof MessageChannel=="function"){let n=new MessageChannel;n.port1.onmessage=()=>{n.port1.close(),n.port2.close(),t()},n.port2.postMessage(0)}else setTimeout(t,0)}return!1}function yt(e){if(!(e instanceof Element))return!1;let t=e.tagName.toLowerCase();return t==="a"||t==="button"?!0:e.getAttribute("role")==="button"}function Ve(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(yt(r))return!0;r=r.parentElement}return!1}function T(e,t,n,r){if(t.type==="weighted_composite"){let c=new Set,m=[];return t.steps.forEach(({goal:g,name:v,weight:k},w)=>{let A=(u=!1)=>{c.has(w)||u&&r!==void 0&&$e(`step\0${v}\0${k}\0${w}`)||(c.add(w),n.fireStep(v,k,w))};if(g.type==="click"){let u=s=>{let a=s.target;a instanceof Element&&Ve(a,e,g.selector)&&A()};e.addEventListener("click",u),m.push(()=>e.removeEventListener("click",u));return}if(g.type==="form_submit"){let u=s=>{s.target instanceof HTMLFormElement&&e.contains(s.target)&&A()};e.addEventListener("submit",u),m.push(()=>e.removeEventListener("submit",u));return}if(g.type==="scroll_depth"){let u=Math.max(0,Math.min(1,g.threshold)),s=new IntersectionObserver(a=>{for(let p of a)if(p.intersectionRatio>=u){A(!0),s.disconnect();break}},{threshold:[u]});s.observe(e),m.push(()=>s.disconnect())}}),()=>{for(let g of m)g()}}let o=t.type==="composite"?t.all:[t],i=new Set(o.map((c,m)=>m)),f=()=>{r!==void 0&&$e(r)||n.fireGoal()},l=(c,m=!1)=>{i.delete(c),i.size===0&&(m?f():n.fireGoal())},d=[];return o.forEach((c,m)=>{if(c.type==="click"){let g=v=>{let k=v.target;k instanceof Element&&Ve(k,e,c.selector)&&(t.type==="composite"?l(m):n.fireGoal())};e.addEventListener("click",g),d.push(()=>e.removeEventListener("click",g));return}if(c.type==="form_submit"){let g=v=>{v.target instanceof HTMLFormElement&&e.contains(v.target)&&(t.type==="composite"?l(m):n.fireGoal())};e.addEventListener("submit",g),d.push(()=>e.removeEventListener("submit",g));return}if(c.type==="scroll_depth"){let g=Math.max(0,Math.min(1,c.threshold)),v=new IntersectionObserver(k=>{for(let w of k)if(w.intersectionRatio>=g){t.type==="composite"?l(m,!0):f(),v.disconnect();break}},{threshold:[g]});v.observe(e),d.push(()=>v.disconnect());return}}),()=>{for(let c of d)c()}}var We=new Set,Ue=new Set;function B(e,t,n,r,o){let i=`${r}|${n}`;if(Ue.has(i))return;Ue.add(i);let f=o.type==="weighted_composite"&&!We.has(r);f&&We.add(r),e.track({projectId:t,componentId:n,eventType:"funnel_declared",payload:f?{funnelId:r,steps:o.steps.map(l=>({goalId:l.name,weight:l.weight}))}:{funnelId:r}})}function j(e,t,n,r){e.track({projectId:t,componentId:n,variantId:r,eventType:"variant_assigned",payload:{}})}var St={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function V(){if(typeof window=="undefined")return St;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 Ne=()=>{};function Y(e){return _()?(V().components.set(e.id,e),J(),()=>{V().components.delete(e.id),J()}):Ne}function Z(e){return _()?(V().slots.set(e.id,e),J(),()=>{V().slots.delete(e.id),J()}):Ne}function pe(e){_()&&(V().sections=[...e],J())}import{jsx as Rt}from"react/jsx-runtime";function xt(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{return wt({userAgent:(e=navigator.userAgent)!=null?e:"",referer:(t=document.referrer)!=null?t:"",appOrigin:window.location.origin})}catch(n){return"desktop:direct"}}var He="https://api.sentient-ui.com/v1",I=ht({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialPersona:null,apiBaseUrl:He,debug:!1});function kt(e){let[t,n]=ee(!1),r=ve(e);r.current=e;let{cookie:o,value:i,event:f}=e!=null?e:{},l=typeof(e==null?void 0:e.check)=="function";return K(()=>{let d=()=>{var v;let m=r.current;if(!m)return!1;if(m.check)return m.check()===!0;if(!m.cookie||typeof document=="undefined")return!1;let g=`${m.cookie}=${(v=m.value)!=null?v:"accepted"}`;return document.cookie.split("; ").some(k=>k.trim()===g)};if(n(d()),!f)return;let c=()=>{n(d())};return window.addEventListener(f,c),()=>window.removeEventListener(f,c)},[o,i,f,l]),t}function Ct(e){var w,A;let[t,n]=ee(null),[r]=ee(()=>{var u;return(u=e.sessionSegment)!=null?u:xt()}),[o,i]=ee(fe());K(()=>Fe(()=>i(fe())),[]);let f=kt(e.consentFrom),l=e.consentFrom?e.consent===!0||f:e.consent,d=ve(null);K(()=>{var x;if(l===!1&&!e.preConsentBehavior){(x=d.current)==null||x.destroy(),d.current=null,n(null);return}let u={apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,sessionSegment:r,consent:l,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},s=!1,a=null,p=null,h=G=>{e.engagement!==!1&&import("@sentientui/core/engagement").then(({startEngagementCapture:S})=>{s||(p=S(G,{apiKey:e.apiKey,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:G})=>{s||(a=G(q(C({},u),{graph:!0,captureDomText:e.captureDomText===!0})),d.current=a,n(a),h(a))}):(a=At(u),d.current=a,n(a),h(a)),()=>{s=!0,p==null||p(),a==null||a.dispose()}},[l]),K(()=>{if(!t)return;let u=!1,s=async()=>{if(u)return;let p;try{p=await t.fetchWeights()}catch(h){return}if(!u)for(let h of p){let x={componentId:h.componentId,updatedAt:h.updatedAt,variants:h.variants.map(G=>{var S;return{variantId:G.variantId,pulls:G.pulls,avgReward:(S=G.avgReward)!=null?S:0}})};Te(h.componentId,x)}};s();let a=setInterval(()=>{s()},6e4);return()=>{u=!0,clearInterval(a)}},[t]);let c=(w=e.ssrFallback)!=null?w:"first",m=((A=e.apiBaseUrl)!=null?A:He).replace(/\/$/,""),g=ve(null);K(()=>{var a;if(typeof process!="undefined"&&((a=process.env)==null?void 0:a.NODE_ENV)==="production")return;let u={apiKey:e.apiKey,context:e.context,country:e.country,persona:e.persona,apiBaseUrl:m},s=g.current;if(g.current=u,s!==null)for(let p of["apiKey","context","country","persona","apiBaseUrl"])Object.is(s[p],u[p])||console.warn(`[sentient] AdaptiveProvider: \`${p}\` 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,m]),K(()=>{var u;typeof process!="undefined"&&((u=process.env)==null?void 0:u.NODE_ENV)==="production"||Ke({apiKey:e.apiKey,apiBaseUrl:m,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,m]),K(()=>{let u=e.initialLayoutOrder;if(u&&u.length>0){pe(u);return}e.declaredSections&&e.declaredSections.length>0&&pe(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]),K(()=>{if(!_())return;let u=e.declaredSections;if(!u||u.length===0||typeof document=="undefined")return;let s=new Set(Array.from(document.querySelectorAll("[data-sentient-id]"),p=>p.getAttribute("data-sentient-id"))),a=u.filter(p=>!s.has(p));a.length>0&&console.warn(`[SentientUI] Declared section${a.length>1?"s":""} ${a.map(p=>`"${p}"`).join(", ")} ${a.length>1?"have":"has"} no matching data-sentient-id element, so the layout engine cannot learn what they are and will serve the same order to every persona. Add data-sentient-id="<sectionId>" (plus optional data-sentient-type) to each section's element.`)},[e.declaredSections]);let v=Je(()=>t&&o?Me(t):t,[t,o]),k=Je(()=>{var u,s,a,p,h;return{client:v,apiKey:e.apiKey,initialAssignments:(u=e.initialAssignments)!=null?u:{},sessionSegment:r,ssrFallback:c,onAssignment:e.onAssignment,initialLayoutOrder:(s=e.initialLayoutOrder)!=null?s:null,initialSlots:(a=e.initialSlots)!=null?a:{},initialPersona:(p=e.initialPersona)!=null?p:null,apiBaseUrl:m,debug:(h=e.debug)!=null?h:!1}},[v,e.apiKey,e.initialAssignments,r,c,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialPersona,m,e.debug]);return Rt(I.Provider,{value:k,children:e.children})}function R(){return L(I).client}function D(){return L(I).apiKey}function ye(){return L(I).initialAssignments}function te(){return L(I).sessionSegment}function ze(){return L(I).ssrFallback}function ne(){return L(I).onAssignment}function Xe(){return L(I).debug}function Gt(){let e=L(I).initialLayoutOrder,t=bt(F,()=>{var n;return typeof window=="undefined"?null:(n=window.__sentient_layout_override)!=null?n:null},()=>null);return t!=null?t:e}function qe(){return L(I).initialSlots}function Qe(){return L(I).initialPersona}function _t(){return L(I).apiBaseUrl}import{memo as It,useEffect as $,useMemo as Ze,useRef as ie,useState as Lt}from"react";import{attachMicroSignalDetectors as Pt}from"@sentientui/core";import{useEffect as re,useRef as Ye,useState as Ot,useSyncExternalStore as Et}from"react";import{pickFromWeights as Se}from"@sentientui/policy";function N(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}function H(e,t,n,r){let o=ye(),i=ze(),f=R(),l=te(),d=ne(),c=Xe(),m=Ye(null),g=Et(F,()=>N(e),()=>null),v=g&&t.includes(g)?g:null,k=Ye(null);re(()=>{c&&v&&k.current!==v&&(k.current=v,console.info(`[sentient] override active: ${e} -> ${v}`))},[c,v,e]);let[w,A]=Ot(()=>{var p,h;if(v)return{variantId:v,content:null,isLoading:!1,settled:!0};if(!f){let x=o[e];return x&&t.includes(x)?{variantId:x,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 s=f.getAssignment(e,l);if(s&&(t.includes(s.variantId)||s.content))return{variantId:s.variantId,content:(p=s.content)!=null?p:null,isLoading:!1,settled:!0};let a=de(e);if(a){let x=Se(a.variants,t);if(x)return{variantId:x,content:null,isLoading:!1,settled:!0}}return{variantId:(h=t[0])!=null?h:null,content:null,isLoading:!1,settled:!1}}),u=s=>{d&&m.current!==s&&(m.current=s,d(e,s))};return re(()=>{var p;if(v||!f)return;let s=f.getAssignment(e,l);if(s&&(t.includes(s.variantId)||s.content)){A({variantId:s.variantId,content:(p=s.content)!=null?p:null,isLoading:!1,settled:!0}),u(s.variantId);return}let a=de(e);if(a&&w.settled&&w.variantId&&w.variantId===Se(a.variants,t)){u(w.variantId);return}A(h=>{var x;return h.variantId?h:{variantId:(x=t[0])!=null?x:null,content:null,isLoading:!1,settled:!1}})},[v,f,e,l]),re(()=>{if(v||!f)return;let s=f.getAssignment(e,l);if(s&&t.includes(s.variantId))return;let a=!1;return f.assign(e,t,n,r).then(p=>{var h;a||p&&(!t.includes(p.variantId)&&!p.content||(A({variantId:p.variantId,content:(h=p.content)!=null?h:null,isLoading:!1,settled:!0}),u(p.variantId)))}),()=>{a=!0}},[v,f,e,l]),re(()=>{if(!v&&f)return Pe(e,s=>{var h;let a=f.getAssignment(e,l);if(a&&(t.includes(a.variantId)||a.content)){A({variantId:a.variantId,content:(h=a.content)!=null?h:null,isLoading:!1,settled:!0}),u(a.variantId);return}let p=Se(s.variants,t);p&&(A({variantId:p,content:null,isLoading:!1,settled:!0}),u(p))})},[v,f,e,l]),v?{variantId:v,content:null,isLoading:!1,settled:!0,isOverride:!0}:w}import{jsx as Ft}from"react/jsx-runtime";function Tt(e){var h;let t=R(),n=D(),r=Object.keys(e.variants).join("\0"),o=Ze(()=>Object.keys(e.variants),[r]),{variantId:i,content:f,isOverride:l,settled:d}=H(e.id,o,e.agentData,e.agentDataByVariant),c=ie(null),[m,g]=Lt(!1);$(()=>{g(!0)},[]);let v=ie(!1),k=ie(new Set),w=ie(null),A=typeof e.goal=="string"?e.goal:JSON.stringify(e.goal),u=Ze(()=>E(e.goal),[A]),s=typeof e.goal=="string"?e.goal:u.type;if($(()=>Y({id:e.id,variantIds:o,goal:s}),[e.id,o,s]),$(()=>{l||d&&(!t||!i||!n||w.current!==i&&(w.current=i,j(t,n,e.id,i)))},[t,i,n,e.id,l,d]),$(()=>{v.current=!1,k.current=new Set},[i,u]),$(()=>{l||!d||!t||!e.funnel||B(t,n,e.id,e.funnel,u)},[t,n,e.id,e.funnel,u,l,d]),$(()=>{if(l||!d||!t||!i)return;let x=c.current;if(!x)return;let G=null,S=0,b=()=>{S=Date.now(),G=setTimeout(()=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-S}}),G=null},800)},y=()=>{G!==null&&(clearTimeout(G),G=null)};return x.addEventListener("mouseenter",b),x.addEventListener("mouseleave",y),()=>{x.removeEventListener("mouseenter",b),x.removeEventListener("mouseleave",y),G!==null&&clearTimeout(G)}},[t,i,n,e.id,l,d]),$(()=>{if(l||!d||!t||!i)return;let x=c.current;if(!x)return;let G=Date.now();return Pt((S,b={})=>{var Ce,Ge,_e;t.track({projectId:n,componentId:e.id,variantId:i,eventType:"micro_signal",payload:C({signalType:S},b)});let y=(Ce=e.microSignalGoals)==null?void 0:Ce[S];if(!y||k.current.has(S))return;k.current.add(S);let O=typeof y=="string"?y:y.name,M=typeof y=="string"?1:(Ge=y.weight)!=null?Ge:1,z=typeof y=="string"?0:(_e=y.stepIndex)!=null?_e:0;t.goal(O,{metadata:C({signalType:S},b),weight:M,stepIndex:z})},x,G)},[t,i,n,e.id,e.microSignalGoals,l,d]),$(()=>{if(l||!d||!t||!i)return;let x=c.current;if(!x)return;let G=P(u);return T(x,u,{fireGoal:()=>{v.current||(v.current=!0,t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:s,payload:C({reward:1},G!==void 0?{goalValue:G}:{})}),t.goal(s,C({metadata:{componentId:e.id,variantId:i},weight:1,stepIndex:0},G!==void 0?{value:G}:{})))},fireStep:(S,b,y)=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:S,payload:{reward:b}}),t.goal(S,{metadata:{},weight:b,stepIndex:y})}},s)},[t,i,n,e.id,u,s,l,d]),e.clientOnly&&(!m||!t)||!i)return null;let a=(h=e.variants[i])!=null?h:null,p=a===null?f:null;return _()&&a===null&&p===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.`),Ft("div",{ref:c,"data-sentient-id":e.id,"data-sentient-variant":i,children:a!=null?a:p})}var Dt=It(Tt,(e,t)=>{if(e.id!==t.id||e.goal!==t.goal&&JSON.stringify(e.goal)!==JSON.stringify(t.goal)||e.microSignalGoals!==t.microSignalGoals||e.funnel!==t.funnel||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 Mt,useRef as he,useState as et,useSyncExternalStore as Bt}from"react";import{jsx as Kt}from"react/jsx-runtime";function jt({id:e,default:t,component:n="span",className:r,goal:o}){var G;let i=R(),f=D(),l=ne(),d=te(),c=he(null),m=he(null),g=Bt(F,()=>N(e),()=>null),[v,k]=et(()=>{var S,b;return(b=(S=i==null?void 0:i.getAssignment(e,d))==null?void 0:S.content)!=null?b:null}),[w,A]=et(()=>{var S,b;return(b=(S=i==null?void 0:i.getAssignment(e,d))==null?void 0:S.variantId)!=null?b:null});oe(()=>{if(g||!i)return;let S=i.getAssignment(e,d);if((S==null?void 0:S.content)!==void 0){A(S.variantId),k(S.content);return}let b=!1;return i.assign(e).then(y=>{if(!b){if(!y){_()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}A(y.variantId),y.content&&k(y.content)}}),()=>{b=!0}},[i,e,d,g]),oe(()=>{g||!i||!w||!f||c.current!==w&&(c.current=w,i.track({projectId:f,componentId:e,variantId:w,eventType:"variant_assigned",payload:{}}),l==null||l(e,w))},[i,w,f,e,l,g]);let u=o===void 0?"":typeof o=="string"?o:JSON.stringify(o),s=Mt(()=>o===void 0?null:E(o),[u]),a=o===void 0?null:typeof o=="string"?o:s.type,p=he(!1);oe(()=>{p.current=!1},[w,u]),oe(()=>{if(g||!i||!w||!f||!s||!a)return;let S=m.current;if(!S)return;let b=P(s);return T(S,s,{fireGoal:()=>{p.current||(p.current=!0,i.track({projectId:f,componentId:e,variantId:w,eventType:"goal_achieved",goalType:a,payload:C({reward:1},b!==void 0?{goalValue:b}:{})}),i.goal(a,C({metadata:{componentId:e,variantId:w},weight:1,stepIndex:0},b!==void 0?{value:b}:{})))},fireStep:(y,O,M)=>{i.track({projectId:f,componentId:e,variantId:w,eventType:"goal_achieved",goalType:y,payload:{reward:O}}),i.goal(y,{metadata:{},weight:O,stepIndex:M})}})},[i,w,f,e,s,a,g]);let h=v!=null?v:t;if(g){let S=i==null?void 0:i.getAssignment(e,d);h=S&&S.variantId===g&&(G=S.content)!=null?G:t}return Kt(n,{ref:S=>{m.current=S},className:r,children:h})}import{useCallback as $t,useRef as Vt}from"react";function be(e){let t=R(),n=Vt(new Set);return $t((r,o)=>{var i,f;if(!N(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,C(C(C({metadata:(i=o==null?void 0:o.metadata)!=null?i:{},weight:(f=o==null?void 0:o.reward)!=null?f: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 tt}from"react";function Ut(e,t={}){let d=t,{componentId:n}=d,r=Ie(d,["componentId"]),o=R(),i=be(n!=null?n:""),f=tt(!1),l=tt(r);l.current=r,Wt(()=>{if(!o||f.current)return;f.current=!0;let{metadata:c,reward:m,value:g,currency:v,externalId:k}=l.current;if(n){i(e,l.current);return}o.goal(e,C(C(C({metadata:c!=null?c:{},weight:m!=null?m:1,stepIndex:0},g!==void 0?{value:g}:{}),v!==void 0?{currency:v}:{}),k!==void 0?{externalId:k}:{}))},[o,n,e,i])}import{renderPrePaintScript as Nt}from"@sentientui/core";import{confidenceBand as Jt}from"@sentientui/policy";import{jsx as Xt}from"react/jsx-runtime";function nt(e){return JSON.stringify(e).replace(/</g,"\\u003c")}function Ht(e){return e.persona?'(function(){try{var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",'+nt(e.persona.persona)+');d.setAttribute("data-sentient-confidence",'+nt(Jt(e.persona.confidence))+");}catch(e){}})();":Nt(e.apiKey)}function zt(e){return Xt("script",{"data-sentient-persona-script":"",nonce:e.nonce,dangerouslySetInnerHTML:{__html:Ht(e)}})}import{useEffect as le,useMemo as Ae,useRef as nn}from"react";import{validateSlotDecl as rn}from"@sentientui/policy";import{useEffect as we,useReducer as qt,useState as Qt,useSyncExternalStore as it}from"react";import{armOfResult as se,baselineResultFor as Yt}from"@sentientui/core";import{confidenceBand as Zt}from"@sentientui/policy";var rt=new Set;function ae(e,t){let n=R(),r=qe(),[,o]=qt(m=>m+1,0),i=it(F,()=>{var m;return typeof window!="undefined"?(m=window.__sentient_slot_overrides)==null?void 0:m[e]:void 0},()=>{}),f=i===void 0?r[e]:void 0,l=i===void 0&&f===void 0&&n?n.getSlotResult(e):null,d=(n==null?void 0:n.isLocal)===!0&&i===void 0&&f===void 0&&l===null;we(()=>{if(!d||!n)return;let m=!1;return n.decide({slots:[t]}).then(g=>{!m&&g&&o()}),()=>{m=!0}},[n,e,d]);let c=(()=>{if(i!==void 0)return{result:i,arm:se(i),source:"override"};if(f!==void 0)return{result:f,arm:se(f),source:"preloaded"};if(l!==null)return{result:l,arm:se(l),source:"client"};let m=Yt(t);return{result:m,arm:se(m),source:"baseline"}})();return we(()=>{_()&&(!n||n.isLocal===!0||c.source==="baseline"&&(rt.has(e)||(rt.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,c.source,e]),c}function en(){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 tn(){let e=R(),t=Qe();it(F,je,()=>0);let[n,r]=Qt(!1);we(()=>r(!0),[]);let o=l=>({persona:l.persona,confidence:l.confidence,band:Zt(l.confidence)});if(!n)return t?o(t):null;let i=en();if(i)return o(i);if(t)return o(t);let f=e?e.getPersona():null;return f?o(f):null}var ot=new Set;function on(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/[\\"]/g,"\\$&")}function sn(e,t,n){let r=R(),o=D(),i=JSON.stringify(t),f=Ae(()=>({id:e,dims:t}),[e,i]),{result:l,arm:d,source:c}=ae(e,f),m=Ae(()=>typeof l=="string"?{}:l,[d]);if(_()&&!ot.has(e)){ot.add(e);let A=rn({id:e,dims:Object.fromEntries(Object.entries(t).map(([s,a])=>[s,[...a]]))}),u=Object.values(t).reduce((s,a)=>s*a.length,1);A.ok?u>4&&console.warn(`[sentient] useAdaptiveTokens("${e}") declares ${u} combinations \u2014 more than the recommended 4. Each extra combination needs more traffic to learn; consider fewer dims/values.`):console.warn(`[sentient] useAdaptiveTokens("${e}"): invalid declaration \u2014 ${A.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 v=nn(null);le(()=>{!r||c==="baseline"||c==="override"||v.current===d||(v.current=d,j(r,o,e,d))},[r,o,e,d,c]);let k=n==null?void 0:n.funnel;le(()=>{var A;!r||!k||c==="override"||B(r,o,e,k,E((A=n==null?void 0:n.goal)!=null?A:"click"))},[r,o,e,k,g,c]),le(()=>{if(!r||!(n!=null&&n.goal)||c==="override"||c==="baseline")return;let A=document.querySelector(`[data-sentient-slot="${on(e)}"]`);if(!A){_()&&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 u=U(n.goal),s=P(n.goal),a=!1;return T(A,E(n.goal),{fireGoal:()=>{a||(a=!0,s!==void 0?r.componentGoal(e,u,{value:s}):r.componentGoal(e,u),r.goal(u,C({metadata:{componentId:e,arm:d},weight:1,stepIndex:0},s!==void 0?{value:s}:{})))},fireStep:(p,h,x)=>{r.componentGoal(e,p,{reward:h}),r.goal(p,{metadata:{componentId:e,arm:d},weight:h,stepIndex:x})}},u)},[r,e,g,d,c]);let w=Ae(()=>{let A={"data-sentient-slot":e};for(let[u,s]of Object.entries(m))A[`data-${u}`]=s;return A},[e,m]);return{tokens:m,props:w}}import{useCallback as st,useEffect as W,useMemo as xe,useRef as ke,useState as an}from"react";import{attachMicroSignalDetectors as ln}from"@sentientui/core";var at=new Set;function un(e,t){var S;if(_()&&!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(),r=D(),o=Object.keys(t.variants).join(" "),i=xe(()=>Object.keys(t.variants),[o]),{variantId:f,isOverride:l,settled:d}=H(e,i),c=(S=f!=null?f:i[0])!=null?S:"",m=t.variants[c],[g,v]=an(null),k=ke(null),w=st(b=>{k.current=b,v(b)},[]),A=typeof t.goal=="string"?t.goal:JSON.stringify(t.goal),u=xe(()=>t.goal?E(t.goal):null,[A]),s=t.goal?U(t.goal):"";W(()=>Y({id:e,variantIds:i,goal:s}),[e,i,s]);let a=ke(null);W(()=>{l||d&&(!n||!c||!g||a.current!==c&&(a.current=c,j(n,r,e,c)))},[n,r,e,c,g,l,d]);let p=t.funnel;W(()=>{l||!d||!n||!p||!u||B(n,r,e,p,u)},[n,r,e,p,u,l,d]);let h=ke(!1);W(()=>{h.current=!1},[c,A]),W(()=>{if(l||!d||!n||!c||!g||!u)return;let b=P(u);return T(g,u,{fireGoal:()=>{h.current||(h.current=!0,n.track({projectId:r,componentId:e,variantId:c,eventType:"goal_achieved",goalType:s,payload:C({reward:1},b!==void 0?{goalValue:b}:{})}),n.goal(s,C({metadata:{componentId:e,variantId:c},weight:1,stepIndex:0},b!==void 0?{value:b}:{})))},fireStep:(y,O,M)=>{n.track({projectId:r,componentId:e,variantId:c,eventType:"goal_achieved",goalType:y,payload:{reward:O}}),n.goal(y,{metadata:{},weight:O,stepIndex:M})}},s)},[n,g,c,r,e,u,s,l,d]),W(()=>{if(l||!n||!c||!g)return;let b=Date.now();return ln((y,O={})=>{n.track({projectId:r,componentId:e,variantId:c,eventType:"micro_signal",payload:C({signalType:y},O)})},g,b)},[n,g,c,r,e,l]),W(()=>{if(!_()||!n)return;let b=setTimeout(()=>{!k.current&&!at.has(e)&&(at.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(b)},[n,e]);let x=st((b,y)=>{var M,z;if(l)return;let O=b!=null?b:s;O&&(n==null||n.componentGoal(e,O,y),n==null||n.goal(O,C(C(C({metadata:(M=y==null?void 0:y.metadata)!=null?M:{},weight:(z=y==null?void 0:y.reward)!=null?z:1,stepIndex:0},(y==null?void 0:y.value)!==void 0?{value:y.value}:{}),(y==null?void 0:y.currency)!==void 0?{currency:y.currency}:{}),(y==null?void 0:y.externalId)!==void 0?{externalId:y.externalId}:{})))},[n,e,s,l]),G=xe(()=>({ref:w,"data-sentient-id":e,"data-sentient-variant":c}),[w,e,c]);return{variant:c,value:m,bind:G,fireGoal:x}}import{Children as cn,isValidElement as dn,useEffect as ue,useMemo as lt,useRef as ut}from"react";import{jsx as gn}from"react/jsx-runtime";var ce=new Set;function fn(e){var s;let t=R(),n=D(),r=ut(null),o=Object.keys(e.arrangements).join(" "),i=lt(()=>Object.keys(e.arrangements),[o]),f=lt(()=>C({id:e.id,arms:i},e.baseline!==void 0?{baseline:e.baseline}:{}),[e.id,i,e.baseline]),{arm:l,source:d}=ae(e.id,f);_()&&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 c=cn.toArray(e.children).filter(dn),m=new Map;for(let a of c)m.set(String((s=a.key)!=null?s:"").replace(/^\.\$/,""),a);let g=e.arrangements[l],v=g!==void 0&&g.length===c.length&&g.every(a=>m.has(a));_()&&g!==void 0&&!v&&!ce.has(e.id+":keys")&&(ce.add(e.id+":keys"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: arrangement "${l}" [${g.join(", ")}] does not match the children's keys \u2014 rendering declaration order (fail-safe).`));let k=v?g.map(a=>m.get(a)):c;ue(()=>Z({id:e.id,arms:Object.keys(e.arrangements)}),[e.id]);let w=ut(null);ue(()=>{!t||d==="baseline"||d==="override"||w.current===l||(w.current=l,j(t,n,e.id,l))},[t,n,e.id,l,d]);let A=e.funnel;ue(()=>{var a;!t||!A||d==="override"||B(t,n,e.id,A,E((a=e.goal)!=null?a:"click"))},[t,n,e.id,A,d]);let u=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"||d==="baseline")return;let a=r.current;if(!a)return;let p=U(e.goal),h=P(e.goal),x=!1;return T(a,E(e.goal),{fireGoal:()=>{x||(x=!0,h!==void 0?t.componentGoal(e.id,p,{value:h}):t.componentGoal(e.id,p),t.goal(p,C({metadata:{componentId:e.id,arm:l},weight:1,stepIndex:0},h!==void 0?{value:h}:{})))},fireStep:(G,S,b)=>{t.componentGoal(e.id,G,{reward:S}),t.goal(G,{metadata:{componentId:e.id,arm:l},weight:S,stepIndex:b})}},p)},[t,e.id,u,l,d]),gn("div",{ref:r,"data-sentient-id":e.id,"data-sentient-variant":l,children:k})}import{deriveSessionSegment as mn}from"@sentientui/core";var pn=["page","blocks","layoutOrder"],ct=new Map;function vn(e,t){ct.set(e,t)}function dt(e){return ct.get(e)}function yn(e){var o,i;let t=(i=(o=e.content)!=null?o:dt(e.page))!=null?i:{},n={};for(let[f,l]of Object.entries(t))pn.includes(f)||(n[f]=l);let r=q(C({},n),{page:e.page,blocks:e.blocks});return e.layoutOrder&&(r.layoutOrder=e.layoutOrder),r}function Sn(e){return`<script type="application/ld+json">${ft(e)}</script>`}function ft(e){return JSON.stringify(C({"@context":"https://schema.org","@type":"WebPage"},e)).replace(/</g,"\\u003c")}function hn(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
|
-
`}import{grantConsent as
|
|
4
|
+
`}import{grantConsent as bi}from"@sentientui/core";export{Dt as Adaptive,fn as AdaptiveGroup,Ct as AdaptiveProvider,jt as AdaptiveText,zt as SentientPersonaScript,yn as buildAgentFeed,vn as defineAgentContent,mn as detectSegment,dt as getAgentContent,bi as grantConsent,Sn as renderAgentJsonLd,ft as renderAgentJsonLdBody,hn as renderAgentMarkdown,un as useAdaptive,_t as useAdaptiveApiBaseUrl,be as useAdaptiveGoal,tn as useAdaptivePersona,sn as useAdaptiveTokens,H as useAssignment,ye as useInitialAssignments,Gt as useLayoutOrder,Ut as usePageGoal,R as useSentient};
|
|
5
5
|
//# sourceMappingURL=index.mjs.map
|