@sentientui/react 0.14.2 → 0.15.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 $e=Object.defineProperty,Ue=Object.defineProperties;var Ve=Object.getOwnPropertyDescriptors;var fe=Object.getOwnPropertySymbols;var He=Object.prototype.hasOwnProperty,Je=Object.prototype.propertyIsEnumerable;var pe=(e,t,n)=>t in e?$e(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,k=(e,t)=>{for(var n in t||(t={}))He.call(t,n)&&pe(e,n,t[n]);if(fe)for(var n of fe(t))Je.call(t,n)&&pe(e,n,t[n]);return e},W=(e,t)=>Ue(e,Ve(t));import{createContext as qe,useContext as G,useEffect as B,useMemo as Ae,useState as te,useSyncExternalStore as Qe}from"react";import{detectDeviceClass as Ye,detectTrafficSource as Ze,init as et}from"@sentientui/core";var me=new Map,K=new Map;function Q(e,t){let n=K.get(e);return n||(n=new Set,K.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&K.delete(e)}}function Y(e,t){me.set(e,t);let n=K.get(e);if(n)for(let o of n)try{o(t)}catch(i){}}function Z(e){var t;return(t=me.get(e))!=null?t:null}var ze={on:!1,listeners:new Set};function ve(){if(typeof window=="undefined")return ze;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function ee(){return ve().on}function ye(e){let t=ve().listeners;return t.add(e),()=>{t.delete(e)}}function Se(e){return{isLocal:e.isLocal,track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},fetchWeights:()=>Promise.resolve([]),getAssignment:(t,n)=>e.getAssignment(t,n),assign:(t,n,o,i)=>e.assign(t,n,o,i),decide:()=>Promise.resolve(null),getSlotResult:t=>e.getSlotResult(t),getPersona:()=>e.getPersona(),getGraph:()=>e.getGraph(),destroy:()=>e.destroy()}}var he="sentient:overrides-changed";function N(){var e;return typeof window=="undefined"?0:(e=window.__sentient_overrides_version)!=null?e:0}function T(e){return typeof window=="undefined"?()=>{}:(window.addEventListener(he,e),()=>window.removeEventListener(he,e))}function we(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}var Xe={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function I(){if(typeof window=="undefined")return Xe;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 F(){I().version+=1;for(let e of I().listeners)e()}function $(e){return I().components.set(e.id,e),F(),()=>{I().components.delete(e.id),F()}}function U(e){return I().slots.set(e.id,e),F(),()=>{I().slots.delete(e.id),F()}}function be(e){I().sections=[...e],F()}import{jsx as ot}from"react/jsx-runtime";function tt(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{let n=Ye((e=navigator.userAgent)!=null?e:""),o=Ze((t=document.referrer)!=null?t:"",window.location.origin);return`${n}:${o}`}catch(n){return"desktop:direct"}}var xe="https://api.sentient-ui.com/v1",C=qe({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialPersona:null,apiBaseUrl:xe});function nt(e){var y,c;let[t,n]=te(null),[o]=te(()=>{var u;return(u=e.sessionSegment)!=null?u:tt()}),[i,m]=te(ee());B(()=>ye(()=>m(ee())),[]),B(()=>{if(e.consent===!1&&!e.preConsentBehavior){n(l=>(l==null||l.destroy(),null));return}let u={apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,sessionSegment:o,consent:e.consent,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},f=!1,s=null;return e.enableGraph?import("@sentientui/core/graph").then(({init:l})=>{f||(s=l(W(k({},u),{graph:!0})),n(s))}):(s=et(u),n(s)),()=>{f=!0,s==null||s.destroy()}},[e.consent]),B(()=>{if(!t)return;let u=!1,f=async()=>{if(u)return;let l;try{l=await t.fetchWeights()}catch(w){return}if(!u)for(let w of l){let h={componentId:w.componentId,updatedAt:w.updatedAt,variants:w.variants.map(S=>{var v;return{variantId:S.variantId,pulls:S.pulls,avgReward:(v=S.avgReward)!=null?v:0}})};Y(w.componentId,h)}};f();let s=setInterval(()=>{f()},6e4);return()=>{u=!0,clearInterval(s)}},[t]);let r=(y=e.ssrFallback)!=null?y:"first",a=(c=e.apiBaseUrl)!=null?c:xe;B(()=>{var u;typeof process!="undefined"&&((u=process.env)==null?void 0:u.NODE_ENV)==="production"||we({apiKey:e.apiKey,apiBaseUrl:a,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,a]),B(()=>{e.initialLayoutOrder&&e.initialLayoutOrder.length>0&&be(e.initialLayoutOrder)},[e.initialLayoutOrder]);let g=Ae(()=>t&&i?Se(t):t,[t,i]),d=Ae(()=>{var u,f,s,l;return{client:g,apiKey:e.apiKey,initialAssignments:(u=e.initialAssignments)!=null?u:{},sessionSegment:o,ssrFallback:r,onAssignment:e.onAssignment,initialLayoutOrder:(f=e.initialLayoutOrder)!=null?f:null,initialSlots:(s=e.initialSlots)!=null?s:{},initialPersona:(l=e.initialPersona)!=null?l:null,apiBaseUrl:a}},[g,e.apiKey,e.initialAssignments,o,r,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialPersona,a]);return ot(C.Provider,{value:d,children:e.children})}function A(){return G(C).client}function R(){return G(C).apiKey}function ne(){return G(C).initialAssignments}function V(){return G(C).sessionSegment}function ke(){return G(C).ssrFallback}function H(){return G(C).onAssignment}function it(){let e=G(C).initialLayoutOrder,t=Qe(T,()=>{var n;return typeof window=="undefined"?null:(n=window.__sentient_layout_override)!=null?n:null},()=>null);return t!=null?t:e}function _e(){return G(C).initialSlots}function rt(){return G(C).apiBaseUrl}import{memo as gt,useEffect as P,useMemo as Ee,useRef as J,useState as ft}from"react";import{attachMicroSignalDetectors as pt}from"@sentientui/core";import{useEffect as ie,useRef as Ce,useState as st,useSyncExternalStore as at}from"react";function lt(e){var n;if(typeof window=="undefined")return null;let t=(n=window.__sentient_overrides)==null?void 0:n[e];if(t)return t;try{let o=new URLSearchParams(window.location.search);for(let i of o.getAll("sentient_variant")){let m=i.indexOf(":");if(m!==-1&&i.slice(0,m)===e)return i.slice(m+1)}}catch(o){}return null}function Re(e,t){var o;let n=null;for(let i of e.variants)t.includes(i.variantId)&&(!n||i.avgReward>n.avgReward)&&(n={variantId:i.variantId,avgReward:i.avgReward});return(o=n==null?void 0:n.variantId)!=null?o:null}function j(e,t,n,o){let i=ne(),m=ke(),r=A(),a=V(),g=H(),d=Ce(null);at(T,N,()=>0);let y=lt(e),c=y&&t.includes(y)?y:null,u=Ce(null);c&&u.current!==c&&(u.current=c,console.info(`[sentient] override active: ${e} -> ${c}`));let f=(()=>{var v,p;if(c)return{variantId:c,content:null,isLoading:!1};if(!r){let b=i[e];return b&&t.includes(b)?{variantId:b,content:null,isLoading:!1}:m==="first"&&t.length>0?{variantId:t[0],content:null,isLoading:!1}:{variantId:null,content:null,isLoading:!0}}let h=r.getAssignment(e,a);if(h&&(t.includes(h.variantId)||h.content))return{variantId:h.variantId,content:(v=h.content)!=null?v:null,isLoading:!1};let S=Z(e);if(S){let b=Re(S,t);if(b)return{variantId:b,content:null,isLoading:!1}}return{variantId:(p=t[0])!=null?p:null,content:null,isLoading:!1}})(),[s,l]=st(f),w=h=>{g&&d.current!==h&&(d.current=h,g(e,h))};return ie(()=>{var S;if(c||!r)return;let h=r.getAssignment(e,a);if(h&&(t.includes(h.variantId)||h.content)){l({variantId:h.variantId,content:(S=h.content)!=null?S:null,isLoading:!1}),w(h.variantId);return}l(v=>{var p;return v.variantId?v:{variantId:(p=t[0])!=null?p:null,content:null,isLoading:!1}})},[c,r,e,a]),ie(()=>{if(c||!r)return;let h=r.getAssignment(e,a);if(h&&t.includes(h.variantId))return;let S=!1;return r.assign(e,t,n,o).then(v=>{var p;S||v&&(!t.includes(v.variantId)&&!v.content||(l({variantId:v.variantId,content:(p=v.content)!=null?p:null,isLoading:!1}),w(v.variantId)))}),()=>{S=!0}},[c,r,e,a]),ie(()=>{if(!c&&r)return Q(e,h=>{var p;let S=r.getAssignment(e,a);if(S&&(t.includes(S.variantId)||S.content)){l({variantId:S.variantId,content:(p=S.content)!=null?p:null,isLoading:!1});return}let v=Re(h,t);v&&l({variantId:v,content:null,isLoading:!1})})},[c,r,e,a]),c?{variantId:c,content:null,isLoading:!1}:s}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 D(e){return typeof e=="string"?e:e.type}var ct=3e4;function ut(e,t){try{let n=`_snt_pv_${e}_${t}`;return sessionStorage.getItem(n)?!1:(sessionStorage.setItem(n,"1"),!0)}catch(n){return!0}}function dt(e){if(!(e instanceof Element))return!1;let t=e.tagName.toLowerCase();return t==="a"||t==="button"?!0:e.getAttribute("role")==="button"}function Ge(e,t,n){if(n){try{let i=e;for(;i&&i!==t;){if(i.matches(n))return!0;i=i.parentElement}}catch(i){}return!1}let o=e;for(;o&&o!==t;){if(dt(o))return!0;o=o.parentElement}return!1}function L(e,t,n){if(t.type==="weighted_composite"){let a=new Set,g=[];return t.steps.forEach(({goal:d,name:y,weight:c},u)=>{let f=()=>{a.has(u)||(a.add(u),n.fireStep(y,c,u))};if(d.type==="click"){let s=l=>{let w=l.target;w instanceof Element&&Ge(w,e,d.selector)&&f()};e.addEventListener("click",s),g.push(()=>e.removeEventListener("click",s));return}if(d.type==="form_submit"){let s=l=>{l.target instanceof HTMLFormElement&&e.contains(l.target)&&f()};e.addEventListener("submit",s),g.push(()=>e.removeEventListener("submit",s));return}if(d.type==="scroll_depth"){let s=Math.max(0,Math.min(1,d.threshold)),l=new IntersectionObserver(w=>{for(let h of w)if(h.intersectionRatio>=s){f(),l.disconnect();break}},{threshold:[s]});l.observe(e),g.push(()=>l.disconnect())}}),()=>{for(let d of g)d()}}let o=t.type==="composite"?t.all:[t],i=new Set(o.map((a,g)=>g)),m=a=>{i.delete(a),i.size===0&&n.fireGoal()},r=[];return o.forEach((a,g)=>{if(a.type==="click"){let d=y=>{let c=y.target;c instanceof Element&&Ge(c,e,a.selector)&&(t.type==="composite"?m(g):n.fireGoal())};e.addEventListener("click",d),r.push(()=>e.removeEventListener("click",d));return}if(a.type==="form_submit"){let d=y=>{y.target instanceof HTMLFormElement&&e.contains(y.target)&&(t.type==="composite"?m(g):n.fireGoal())};e.addEventListener("submit",d),r.push(()=>e.removeEventListener("submit",d));return}if(a.type==="scroll_depth"){let d=Math.max(0,Math.min(1,a.threshold)),y=new IntersectionObserver(c=>{for(let u of c)if(u.intersectionRatio>=d){t.type==="composite"?m(g):n.fireGoal(),y.disconnect();break}},{threshold:[d]});y.observe(e),r.push(()=>y.disconnect());return}}),()=>{for(let a of r)a()}}function O(e,t,n,o,i){var a;let m=(a=i==null?void 0:i.innerHTML)!=null?a:"",r=m!==""&&ut(n,o);e.track({projectId:t,componentId:n,variantId:o,eventType:"variant_assigned",payload:r?{previewHtml:m.slice(0,ct)}:{}})}import{jsx as yt}from"react/jsx-runtime";function mt(e){var h;let t=A(),n=R(),o=Ee(()=>Object.keys(e.variants),[e.variants]),{variantId:i,content:m}=j(e.id,o,e.agentData,e.agentDataByVariant),r=J(null),[a,g]=ft(!1);P(()=>{g(!0)},[]);let d=J(!1),y=J(new Set),c=J(null),u=typeof e.goal=="string"?e.goal:JSON.stringify(e.goal),f=Ee(()=>E(e.goal),[u]),s=typeof e.goal=="string"?e.goal:f.type;if(P(()=>$({id:e.id,variantIds:o,goal:s}),[e.id,o,s]),P(()=>{var v,p;!t||!i||!n||c.current===i||!((p=(v=r.current)==null?void 0:v.innerHTML)!=null&&p)||(c.current=i,O(t,n,e.id,i,r.current))},[t,i,n,e.id,a,m]),P(()=>{d.current=!1,y.current=new Set},[i,f]),P(()=>{if(!t||!i)return;let S=r.current;if(!S)return;let v=null,p=0,b=()=>{p=Date.now(),v=setTimeout(()=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-p}}),v=null},800)},x=()=>{v!==null&&(clearTimeout(v),v=null)};return S.addEventListener("mouseenter",b),S.addEventListener("mouseleave",x),()=>{S.removeEventListener("mouseenter",b),S.removeEventListener("mouseleave",x),v!==null&&clearTimeout(v)}},[t,i,n,e.id]),P(()=>{if(!t||!i)return;let S=r.current;if(!S)return;let v=Date.now();return pt((p,b={})=>{var ue,de,ge;t.track({projectId:n,componentId:e.id,variantId:i,eventType:"micro_signal",payload:k({signalType:p},b)});let x=(ue=e.microSignalGoals)==null?void 0:ue[p];if(!x||y.current.has(p))return;y.current.add(p);let je=typeof x=="string"?x:x.name,Ke=typeof x=="string"?1:(de=x.weight)!=null?de:1,Ne=typeof x=="string"?0:(ge=x.stepIndex)!=null?ge:0;t.goal(je,k({signalType:p},b),Ke,Ne)},S,v)},[t,i,n,e.id,e.microSignalGoals]),P(()=>{if(!t||!i)return;let S=r.current;if(S)return L(S,f,{fireGoal:()=>{d.current||(d.current=!0,t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:s,payload:{reward:1}}),t.goal(s,{componentId:e.id,variantId:i},1,0))},fireStep:(v,p,b)=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:v,payload:{reward:p}}),t.goal(v,{},p,b)}})},[t,i,n,e.id,f,s]),e.clientOnly&&(!a||!t)||!i)return null;let l=(h=e.variants[i])!=null?h:null,w=l===null?m:null;return _()&&l===null&&w===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.`),yt("div",{ref:r,"data-sentient-id":e.id,"data-sentient-variant":i,children:l!=null?l:w})}var vt=gt(mt,(e,t)=>{if(e.id!==t.id||JSON.stringify(e.goal)!==JSON.stringify(t.goal)||e.microSignalGoals!==t.microSignalGoals)return!1;if(e.variants===t.variants)return!0;let n=Object.keys(e.variants),o=Object.keys(t.variants);return n.length!==o.length?!1:n.every(i=>i in t.variants)});import{useEffect as Le,useRef as St,useState as Oe}from"react";import{jsx as wt}from"react/jsx-runtime";function ht({id:e,default:t,component:n="span",className:o}){let i=A(),m=R(),r=H(),a=V(),g=St(null),[d,y]=Oe(()=>{var f,s;return(s=(f=i==null?void 0:i.getAssignment(e,a))==null?void 0:f.content)!=null?s:null}),[c,u]=Oe(()=>{var f,s;return(s=(f=i==null?void 0:i.getAssignment(e,a))==null?void 0:f.variantId)!=null?s:null});return Le(()=>{var s;if(!i||((s=i.getAssignment(e,a))==null?void 0:s.content)!==void 0)return;let f=!1;return i.assign(e).then(l=>{if(!f){if(!l){_()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}u(l.variantId),l.content&&y(l.content)}}),()=>{f=!0}},[i,e,a]),Le(()=>{!i||!c||!m||g.current!==c&&(g.current=c,i.track({projectId:m,componentId:e,variantId:c,eventType:"variant_assigned",payload:{}}),r==null||r(e,c))},[i,c,m,e,r]),wt(n,{className:o,children:d!=null?d:t})}import{useCallback as bt}from"react";function At(e){let t=A();return bt((n,o)=>{t==null||t.componentGoal(e,n,o)},[t,e])}import{renderPrePaintScript as xt}from"@sentientui/core";import{confidenceBand as kt}from"@sentientui/policy";import{jsx as Rt}from"react/jsx-runtime";function Ie(e){return JSON.stringify(e).replace(/</g,"\\u003c")}function _t(e){return e.persona?'(function(){try{var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",'+Ie(e.persona.persona)+');d.setAttribute("data-sentient-confidence",'+Ie(kt(e.persona.confidence))+");}catch(e){}})();":xt(e.apiKey)}function Ct(e){return Rt("script",{"data-sentient-persona-script":"",dangerouslySetInnerHTML:{__html:_t(e)}})}import{useEffect as re,useMemo as oe,useRef as It}from"react";import{validateSlotDecl as Pt}from"@sentientui/policy";import{useEffect as Gt,useReducer as Et,useSyncExternalStore as Lt}from"react";import{armOfResult as z,baselineResultFor as Ot}from"@sentientui/core";import{confidenceBand as $n}from"@sentientui/policy";function X(e,t){var y;Lt(T,N,()=>0);let n=A(),o=_e(),[,i]=Et(c=>c+1,0),m=typeof window!="undefined"?(y=window.__sentient_slot_overrides)==null?void 0:y[e]:void 0,r=m===void 0?o[e]:void 0,a=m===void 0&&r===void 0&&n?n.getSlotResult(e):null,g=(n==null?void 0:n.isLocal)===!0&&m===void 0&&r===void 0&&a===null;if(Gt(()=>{if(!g||!n)return;let c=!1;return n.decide({slots:[t]}).then(u=>{!c&&u&&i()}),()=>{c=!0}},[n,e,g]),m!==void 0)return{result:m,arm:z(m),source:"override"};if(r!==void 0)return{result:r,arm:z(r),source:"preloaded"};if(a!==null)return{result:a,arm:z(a),source:"client"};let d=Ot(t);return{result:d,arm:z(d),source:"baseline"}}var se=new Set;function Tt(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/"/g,'\\"')}function Dt(e,t,n){let o=A(),i=R(),m=oe(()=>({id:e,dims:t}),[e]),{result:r,arm:a}=X(e,m),g=oe(()=>typeof r=="string"?{}:r,[a]);if(_()&&!se.has(e)){let u=Pt({id:e,dims:Object.fromEntries(Object.entries(t).map(([s,l])=>[s,[...l]]))}),f=Object.values(t).reduce((s,l)=>s*l.length,1);u.ok?f>4&&(se.add(e),console.warn(`[sentient] useAdaptiveTokens("${e}") declares ${f} combinations \u2014 more than the recommended 4. Each extra combination needs more traffic to learn; consider fewer dims/values.`)):(se.add(e),console.warn(`[sentient] useAdaptiveTokens("${e}"): invalid declaration \u2014 ${u.reason}. Serving baseline.`))}let d=(n==null?void 0:n.goal)===void 0?null:typeof n.goal=="string"?n.goal:JSON.stringify(n.goal);re(()=>U({id:e,dims:t}),[e]);let y=It(null);re(()=>{!o||y.current===a||(y.current=a,O(o,i,e,a,null))},[o,i,e,a]),re(()=>{if(!o||!(n!=null&&n.goal))return;let u=document.querySelector(`[data-sentient-slot="${Tt(e)}"]`);if(!u){_()&&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 f=D(n.goal),s=!1;return L(u,E(n.goal),{fireGoal:()=>{s||(s=!0,o.componentGoal(e,f))},fireStep:(l,w)=>{o.componentGoal(e,l,{reward:w})}})},[o,e,d,a]);let c=oe(()=>{let u={"data-sentient-slot":e};for(let[f,s]of Object.entries(g))u[`data-${f}`]=s;return u},[e,g]);return{tokens:g,props:c}}import{useCallback as Pe,useEffect as M,useMemo as ae,useRef as le,useState as Mt}from"react";import{attachMicroSignalDetectors as Wt}from"@sentientui/core";var Te=new Set;function Ft(e,t){var v;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=A(),o=R(),i=ae(()=>Object.keys(t.variants),[e]),{variantId:m}=j(e,i),r=(v=m!=null?m:i[0])!=null?v:"",a=t.variants[r],[g,d]=Mt(null),y=le(null),c=Pe(p=>{y.current=p,d(p)},[]),u=typeof t.goal=="string"?t.goal:JSON.stringify(t.goal),f=ae(()=>E(t.goal),[u]),s=D(t.goal);M(()=>$({id:e,variantIds:i,goal:s}),[e,i,s]);let l=le(null);M(()=>{!n||!r||!g||l.current!==r&&(l.current=r,O(n,o,e,r,g))},[n,o,e,r,g]);let w=le(!1);M(()=>{w.current=!1},[r,u]),M(()=>{if(!(!n||!r||!g))return L(g,f,{fireGoal:()=>{w.current||(w.current=!0,n.track({projectId:o,componentId:e,variantId:r,eventType:"goal_achieved",goalType:s,payload:{reward:1}}),n.goal(s,{componentId:e,variantId:r},1,0))},fireStep:(p,b,x)=>{n.track({projectId:o,componentId:e,variantId:r,eventType:"goal_achieved",goalType:p,payload:{reward:b}}),n.goal(p,{},b,x)}})},[n,g,r,o,e,f,s]),M(()=>{if(!n||!r||!g)return;let p=Date.now();return Wt((b,x={})=>{n.track({projectId:o,componentId:e,variantId:r,eventType:"micro_signal",payload:k({signalType:b},x)})},g,p)},[n,g,r,o,e]),M(()=>{if(!_()||!n)return;let p=setTimeout(()=>{!y.current&&!Te.has(e)&&(Te.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(p)},[n,e]);let h=Pe((p,b)=>{n==null||n.componentGoal(e,p!=null?p:s,b)},[n,e,s]),S=ae(()=>({ref:c,"data-sentient-id":e,"data-sentient-variant":r}),[c,e,r]);return{variant:r,value:a,bind:S,fireGoal:h}}import{Children as Bt,isValidElement as jt,useEffect as ce,useMemo as De,useRef as Me}from"react";import{jsx as Nt}from"react/jsx-runtime";var q=new Set;function Kt(e){var s;let t=A(),n=R(),o=Me(null),i=De(()=>Object.keys(e.arrangements),[e.id]),m=De(()=>k({id:e.id,arms:i},e.baseline!==void 0?{baseline:e.baseline}:{}),[e.id,i,e.baseline]),{arm:r}=X(e.id,m);_()&&e.baseline!==void 0&&e.baseline!==i[0]&&!q.has(e.id+":baseline")&&(q.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=Bt.toArray(e.children).filter(jt),g=new Map;for(let l of a)g.set(String((s=l.key)!=null?s:"").replace(/^\.\$/,""),l);let d=e.arrangements[r],y=d!==void 0&&d.length===a.length&&d.every(l=>g.has(l));_()&&d!==void 0&&!y&&!q.has(e.id+":keys")&&(q.add(e.id+":keys"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: arrangement "${r}" [${d.join(", ")}] does not match the children's keys \u2014 rendering declaration order (fail-safe).`));let c=y?d.map(l=>g.get(l)):a;ce(()=>U({id:e.id,arms:Object.keys(e.arrangements)}),[e.id]);let u=Me(null);ce(()=>{!t||u.current===r||(u.current=r,O(t,n,e.id,r,o.current))},[t,n,e.id,r]);let f=e.goal===void 0?null:typeof e.goal=="string"?e.goal:JSON.stringify(e.goal);return ce(()=>{if(!t||e.goal===void 0)return;let l=o.current;if(!l)return;let w=D(e.goal),h=!1;return L(l,E(e.goal),{fireGoal:()=>{h||(h=!0,t.componentGoal(e.id,w))},fireStep:(S,v)=>{t.componentGoal(e.id,S,{reward:v})}})},[t,e.id,f,r]),Nt("div",{ref:o,"data-sentient-id":e.id,"data-sentient-variant":r,children:c})}import{deriveSessionSegment as $t}from"@sentientui/core";var Ut=["page","blocks","layoutOrder"],We=new Map;function Vt(e,t){We.set(e,t)}function Fe(e){return We.get(e)}function Ht(e){var i,m;let t=(m=(i=e.content)!=null?i:Fe(e.page))!=null?m:{},n={};for(let[r,a]of Object.entries(t))Ut.includes(r)||(n[r]=a);let o=W(k({},n),{page:e.page,blocks:e.blocks});return e.layoutOrder&&(o.layoutOrder=e.layoutOrder),o}function Jt(e){return`<script type="application/ld+json">${Be(e)}</script>`}function Be(e){return JSON.stringify(k({"@context":"https://schema.org","@type":"WebPage"},e)).replace(/</g,"\\u003c")}function zt(e){let t=[];e.title&&t.push(`# ${e.title}`,""),e.summary&&t.push(String(e.summary),"");for(let[n,o]of Object.entries(e))["page","title","summary","blocks","layoutOrder"].includes(n)||t.push(`## ${n}`,"","```json",JSON.stringify(o,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 Ue=Object.defineProperty,Ve=Object.defineProperties;var He=Object.getOwnPropertyDescriptors;var pe=Object.getOwnPropertySymbols;var Je=Object.prototype.hasOwnProperty,ze=Object.prototype.propertyIsEnumerable;var me=(e,t,n)=>t in e?Ue(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,_=(e,t)=>{for(var n in t||(t={}))Je.call(t,n)&&me(e,n,t[n]);if(pe)for(var n of pe(t))ze.call(t,n)&&me(e,n,t[n]);return e},F=(e,t)=>Ve(e,He(t));import{createContext as Qe,useContext as E,useEffect as j,useMemo as xe,useState as ne,useSyncExternalStore as Ye}from"react";import{detectDeviceClass as Ze,detectTrafficSource as et,init as tt}from"@sentientui/core";var ve=new Map,N=new Map;function Y(e,t){let n=N.get(e);return n||(n=new Set,N.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&N.delete(e)}}function Z(e,t){ve.set(e,t);let n=N.get(e);if(n)for(let o of n)try{o(t)}catch(i){}}function ee(e){var t;return(t=ve.get(e))!=null?t:null}var Xe={on:!1,listeners:new Set};function ye(){if(typeof window=="undefined")return Xe;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function te(){return ye().on}function Se(e){let t=ye().listeners;return t.add(e),()=>{t.delete(e)}}function he(e){return{isLocal:e.isLocal,track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},fetchWeights:()=>Promise.resolve([]),getAssignment:(t,n)=>e.getAssignment(t,n),assign:(t,n,o,i)=>e.assign(t,n,o,i),decide:()=>Promise.resolve(null),getSlotResult:t=>e.getSlotResult(t),getPersona:()=>e.getPersona(),getGraph:()=>e.getGraph(),destroy:()=>e.destroy()}}var we="sentient:overrides-changed";function $(){var e;return typeof window=="undefined"?0:(e=window.__sentient_overrides_version)!=null?e:0}function D(e){return typeof window=="undefined"?()=>{}:(window.addEventListener(we,e),()=>window.removeEventListener(we,e))}function be(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}var qe={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function P(){if(typeof window=="undefined")return qe;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 B(){P().version+=1;for(let e of P().listeners)e()}function U(e){return P().components.set(e.id,e),B(),()=>{P().components.delete(e.id),B()}}function V(e){return P().slots.set(e.id,e),B(),()=>{P().slots.delete(e.id),B()}}function Ae(e){P().sections=[...e],B()}import{jsx as st}from"react/jsx-runtime";function nt(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{let n=Ze((e=navigator.userAgent)!=null?e:""),o=et((t=document.referrer)!=null?t:"",window.location.origin);return`${n}:${o}`}catch(n){return"desktop:direct"}}var ke="https://api.sentient-ui.com/v1",R=Qe({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialPersona:null,apiBaseUrl:ke});function it(e){var S,u;let[t,n]=ne(null),[o]=ne(()=>{var d;return(d=e.sessionSegment)!=null?d:nt()}),[i,f]=ne(te());j(()=>Se(()=>f(te())),[]),j(()=>{if(e.consent===!1&&!e.preConsentBehavior){n(a=>(a==null||a.destroy(),null));return}let d={apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,sessionSegment:o,consent:e.consent,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},g=!1,l=null;return e.enableGraph?import("@sentientui/core/graph").then(({init:a})=>{g||(l=a(F(_({},d),{graph:!0})),n(l))}):(l=tt(d),n(l)),()=>{g=!0,l==null||l.destroy()}},[e.consent]),j(()=>{if(!t)return;let d=!1,g=async()=>{if(d)return;let a;try{a=await t.fetchWeights()}catch(w){return}if(!d)for(let w of a){let m={componentId:w.componentId,updatedAt:w.updatedAt,variants:w.variants.map(b=>{var v;return{variantId:b.variantId,pulls:b.pulls,avgReward:(v=b.avgReward)!=null?v:0}})};Z(w.componentId,m)}};g();let l=setInterval(()=>{g()},6e4);return()=>{d=!0,clearInterval(l)}},[t]);let s=(S=e.ssrFallback)!=null?S:"first",r=(u=e.apiBaseUrl)!=null?u:ke;j(()=>{var d;typeof process!="undefined"&&((d=process.env)==null?void 0:d.NODE_ENV)==="production"||be({apiKey:e.apiKey,apiBaseUrl:r,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,r]),j(()=>{e.initialLayoutOrder&&e.initialLayoutOrder.length>0&&Ae(e.initialLayoutOrder)},[e.initialLayoutOrder]);let p=xe(()=>t&&i?he(t):t,[t,i]),c=xe(()=>{var d,g,l,a;return{client:p,apiKey:e.apiKey,initialAssignments:(d=e.initialAssignments)!=null?d:{},sessionSegment:o,ssrFallback:s,onAssignment:e.onAssignment,initialLayoutOrder:(g=e.initialLayoutOrder)!=null?g:null,initialSlots:(l=e.initialSlots)!=null?l:{},initialPersona:(a=e.initialPersona)!=null?a:null,apiBaseUrl:r}},[p,e.apiKey,e.initialAssignments,o,s,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialPersona,r]);return st(R.Provider,{value:c,children:e.children})}function A(){return E(R).client}function G(){return E(R).apiKey}function ie(){return E(R).initialAssignments}function H(){return E(R).sessionSegment}function _e(){return E(R).ssrFallback}function J(){return E(R).onAssignment}function rt(){let e=E(R).initialLayoutOrder,t=Ye(D,()=>{var n;return typeof window=="undefined"?null:(n=window.__sentient_layout_override)!=null?n:null},()=>null);return t!=null?t:e}function Ce(){return E(R).initialSlots}function ot(){return E(R).apiBaseUrl}import{memo as gt,useEffect as T,useMemo as Le,useRef as z,useState as pt}from"react";import{attachMicroSignalDetectors as mt}from"@sentientui/core";import{useEffect as re,useRef as Re,useState as at,useSyncExternalStore as lt}from"react";function ct(e){var n;if(typeof window=="undefined")return null;let t=(n=window.__sentient_overrides)==null?void 0:n[e];if(t)return t;try{let o=new URLSearchParams(window.location.search);for(let i of o.getAll("sentient_variant")){let f=i.indexOf(":");if(f!==-1&&i.slice(0,f)===e)return i.slice(f+1)}}catch(o){}return null}function Ge(e,t){var o;let n=null;for(let i of e.variants)t.includes(i.variantId)&&(!n||i.avgReward>n.avgReward)&&(n={variantId:i.variantId,avgReward:i.avgReward});return(o=n==null?void 0:n.variantId)!=null?o:null}function K(e,t,n,o){let i=ie(),f=_e(),s=A(),r=H(),p=J(),c=Re(null);lt(D,$,()=>0);let S=ct(e),u=S&&t.includes(S)?S:null,d=Re(null);u&&d.current!==u&&(d.current=u,console.info(`[sentient] override active: ${e} -> ${u}`));let g=(()=>{var v,h;if(u)return{variantId:u,content:null,isLoading:!1};if(!s){let y=i[e];return y&&t.includes(y)?{variantId:y,content:null,isLoading:!1}:f==="first"&&t.length>0?{variantId:t[0],content:null,isLoading:!1}:{variantId:null,content:null,isLoading:!0}}let m=s.getAssignment(e,r);if(m&&(t.includes(m.variantId)||m.content))return{variantId:m.variantId,content:(v=m.content)!=null?v:null,isLoading:!1};let b=ee(e);if(b){let y=Ge(b,t);if(y)return{variantId:y,content:null,isLoading:!1}}return{variantId:(h=t[0])!=null?h:null,content:null,isLoading:!1}})(),[l,a]=at(g),w=m=>{p&&c.current!==m&&(c.current=m,p(e,m))};return re(()=>{var b;if(u||!s)return;let m=s.getAssignment(e,r);if(m&&(t.includes(m.variantId)||m.content)){a({variantId:m.variantId,content:(b=m.content)!=null?b:null,isLoading:!1}),w(m.variantId);return}a(v=>{var h;return v.variantId?v:{variantId:(h=t[0])!=null?h:null,content:null,isLoading:!1}})},[u,s,e,r]),re(()=>{if(u||!s)return;let m=s.getAssignment(e,r);if(m&&t.includes(m.variantId))return;let b=!1;return s.assign(e,t,n,o).then(v=>{var h;b||v&&(!t.includes(v.variantId)&&!v.content||(a({variantId:v.variantId,content:(h=v.content)!=null?h:null,isLoading:!1}),w(v.variantId)))}),()=>{b=!0}},[u,s,e,r]),re(()=>{if(!u&&s)return Y(e,m=>{var h;let b=s.getAssignment(e,r);if(b&&(t.includes(b.variantId)||b.content)){a({variantId:b.variantId,content:(h=b.content)!=null?h:null,isLoading:!1});return}let v=Ge(m,t);v&&a({variantId:v,content:null,isLoading:!1})})},[u,s,e,r]),u?{variantId:u,content:null,isLoading:!1,isOverride:!0}:l}function C(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}function L(e){return typeof e=="string"?{type:"click"}:e}function M(e){return typeof e=="string"?e:e.type}var ut=3e4;function dt(e,t){try{let n=`_snt_pv_${e}_${t}`;return sessionStorage.getItem(n)?!1:(sessionStorage.setItem(n,"1"),!0)}catch(n){return!0}}function ft(e){if(!(e instanceof Element))return!1;let t=e.tagName.toLowerCase();return t==="a"||t==="button"?!0:e.getAttribute("role")==="button"}function Ee(e,t,n){if(n){try{let i=e;for(;i&&i!==t;){if(i.matches(n))return!0;i=i.parentElement}}catch(i){}return!1}let o=e;for(;o&&o!==t;){if(ft(o))return!0;o=o.parentElement}return!1}function O(e,t,n){if(t.type==="weighted_composite"){let r=new Set,p=[];return t.steps.forEach(({goal:c,name:S,weight:u},d)=>{let g=()=>{r.has(d)||(r.add(d),n.fireStep(S,u,d))};if(c.type==="click"){let l=a=>{let w=a.target;w instanceof Element&&Ee(w,e,c.selector)&&g()};e.addEventListener("click",l),p.push(()=>e.removeEventListener("click",l));return}if(c.type==="form_submit"){let l=a=>{a.target instanceof HTMLFormElement&&e.contains(a.target)&&g()};e.addEventListener("submit",l),p.push(()=>e.removeEventListener("submit",l));return}if(c.type==="scroll_depth"){let l=Math.max(0,Math.min(1,c.threshold)),a=new IntersectionObserver(w=>{for(let m of w)if(m.intersectionRatio>=l){g(),a.disconnect();break}},{threshold:[l]});a.observe(e),p.push(()=>a.disconnect())}}),()=>{for(let c of p)c()}}let o=t.type==="composite"?t.all:[t],i=new Set(o.map((r,p)=>p)),f=r=>{i.delete(r),i.size===0&&n.fireGoal()},s=[];return o.forEach((r,p)=>{if(r.type==="click"){let c=S=>{let u=S.target;u instanceof Element&&Ee(u,e,r.selector)&&(t.type==="composite"?f(p):n.fireGoal())};e.addEventListener("click",c),s.push(()=>e.removeEventListener("click",c));return}if(r.type==="form_submit"){let c=S=>{S.target instanceof HTMLFormElement&&e.contains(S.target)&&(t.type==="composite"?f(p):n.fireGoal())};e.addEventListener("submit",c),s.push(()=>e.removeEventListener("submit",c));return}if(r.type==="scroll_depth"){let c=Math.max(0,Math.min(1,r.threshold)),S=new IntersectionObserver(u=>{for(let d of u)if(d.intersectionRatio>=c){t.type==="composite"?f(p):n.fireGoal(),S.disconnect();break}},{threshold:[c]});S.observe(e),s.push(()=>S.disconnect());return}}),()=>{for(let r of s)r()}}function I(e,t,n,o,i){var r;let f=(r=i==null?void 0:i.innerHTML)!=null?r:"",s=f!==""&&dt(n,o);e.track({projectId:t,componentId:n,variantId:o,eventType:"variant_assigned",payload:s?{previewHtml:f.slice(0,ut)}:{}})}import{jsx as St}from"react/jsx-runtime";function vt(e){var b;let t=A(),n=G(),o=Le(()=>Object.keys(e.variants),[e.variants]),{variantId:i,content:f,isOverride:s}=K(e.id,o,e.agentData,e.agentDataByVariant),r=z(null),[p,c]=pt(!1);T(()=>{c(!0)},[]);let S=z(!1),u=z(new Set),d=z(null),g=typeof e.goal=="string"?e.goal:JSON.stringify(e.goal),l=Le(()=>L(e.goal),[g]),a=typeof e.goal=="string"?e.goal:l.type;if(T(()=>U({id:e.id,variantIds:o,goal:a}),[e.id,o,a]),T(()=>{var h,y;s||!t||!i||!n||d.current===i||!((y=(h=r.current)==null?void 0:h.innerHTML)!=null&&y)||(d.current=i,I(t,n,e.id,i,r.current))},[t,i,n,e.id,p,f,s]),T(()=>{S.current=!1,u.current=new Set},[i,l]),T(()=>{if(s||!t||!i)return;let v=r.current;if(!v)return;let h=null,y=0,k=()=>{y=Date.now(),h=setTimeout(()=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-y}}),h=null},800)},x=()=>{h!==null&&(clearTimeout(h),h=null)};return v.addEventListener("mouseenter",k),v.addEventListener("mouseleave",x),()=>{v.removeEventListener("mouseenter",k),v.removeEventListener("mouseleave",x),h!==null&&clearTimeout(h)}},[t,i,n,e.id,s]),T(()=>{if(s||!t||!i)return;let v=r.current;if(!v)return;let h=Date.now();return mt((y,k={})=>{var de,fe,ge;t.track({projectId:n,componentId:e.id,variantId:i,eventType:"micro_signal",payload:_({signalType:y},k)});let x=(de=e.microSignalGoals)==null?void 0:de[y];if(!x||u.current.has(y))return;u.current.add(y);let Ke=typeof x=="string"?x:x.name,Ne=typeof x=="string"?1:(fe=x.weight)!=null?fe:1,$e=typeof x=="string"?0:(ge=x.stepIndex)!=null?ge:0;t.goal(Ke,_({signalType:y},k),Ne,$e)},v,h)},[t,i,n,e.id,e.microSignalGoals,s]),T(()=>{if(s||!t||!i)return;let v=r.current;if(v)return O(v,l,{fireGoal:()=>{S.current||(S.current=!0,t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:a,payload:{reward:1}}),t.goal(a,{componentId:e.id,variantId:i},1,0))},fireStep:(h,y,k)=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:h,payload:{reward:y}}),t.goal(h,{},y,k)}})},[t,i,n,e.id,l,a,s]),e.clientOnly&&(!p||!t)||!i)return null;let w=(b=e.variants[i])!=null?b:null,m=w===null?f:null;return C()&&w===null&&m===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.`),St("div",{ref:r,"data-sentient-id":e.id,"data-sentient-variant":i,children:w!=null?w:m})}var yt=gt(vt,(e,t)=>{if(e.id!==t.id||JSON.stringify(e.goal)!==JSON.stringify(t.goal)||e.microSignalGoals!==t.microSignalGoals)return!1;if(e.variants===t.variants)return!0;let n=Object.keys(e.variants),o=Object.keys(t.variants);return n.length!==o.length?!1:n.every(i=>i in t.variants)});import{useEffect as Oe,useRef as ht,useState as Ie}from"react";import{jsx as bt}from"react/jsx-runtime";function wt({id:e,default:t,component:n="span",className:o}){let i=A(),f=G(),s=J(),r=H(),p=ht(null),[c,S]=Ie(()=>{var g,l;return(l=(g=i==null?void 0:i.getAssignment(e,r))==null?void 0:g.content)!=null?l:null}),[u,d]=Ie(()=>{var g,l;return(l=(g=i==null?void 0:i.getAssignment(e,r))==null?void 0:g.variantId)!=null?l:null});return Oe(()=>{var l;if(!i||((l=i.getAssignment(e,r))==null?void 0:l.content)!==void 0)return;let g=!1;return i.assign(e).then(a=>{if(!g){if(!a){C()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}d(a.variantId),a.content&&S(a.content)}}),()=>{g=!0}},[i,e,r]),Oe(()=>{!i||!u||!f||p.current!==u&&(p.current=u,i.track({projectId:f,componentId:e,variantId:u,eventType:"variant_assigned",payload:{}}),s==null||s(e,u))},[i,u,f,e,s]),bt(n,{className:o,children:c!=null?c:t})}import{useCallback as At}from"react";function xt(e){let t=A();return At((n,o)=>{t==null||t.componentGoal(e,n,o)},[t,e])}import{renderPrePaintScript as kt}from"@sentientui/core";import{confidenceBand as _t}from"@sentientui/policy";import{jsx as Gt}from"react/jsx-runtime";function Pe(e){return JSON.stringify(e).replace(/</g,"\\u003c")}function Ct(e){return e.persona?'(function(){try{var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",'+Pe(e.persona.persona)+');d.setAttribute("data-sentient-confidence",'+Pe(_t(e.persona.confidence))+");}catch(e){}})();":kt(e.apiKey)}function Rt(e){return Gt("script",{"data-sentient-persona-script":"",dangerouslySetInnerHTML:{__html:Ct(e)}})}import{useEffect as oe,useMemo as se,useRef as Pt}from"react";import{validateSlotDecl as Tt}from"@sentientui/policy";import{useEffect as Et,useReducer as Lt,useSyncExternalStore as Ot}from"react";import{armOfResult as X,baselineResultFor as It}from"@sentientui/core";import{confidenceBand as Un}from"@sentientui/policy";function q(e,t){var S;Ot(D,$,()=>0);let n=A(),o=Ce(),[,i]=Lt(u=>u+1,0),f=typeof window!="undefined"?(S=window.__sentient_slot_overrides)==null?void 0:S[e]:void 0,s=f===void 0?o[e]:void 0,r=f===void 0&&s===void 0&&n?n.getSlotResult(e):null,p=(n==null?void 0:n.isLocal)===!0&&f===void 0&&s===void 0&&r===null;if(Et(()=>{if(!p||!n)return;let u=!1;return n.decide({slots:[t]}).then(d=>{!u&&d&&i()}),()=>{u=!0}},[n,e,p]),f!==void 0)return{result:f,arm:X(f),source:"override"};if(s!==void 0)return{result:s,arm:X(s),source:"preloaded"};if(r!==null)return{result:r,arm:X(r),source:"client"};let c=It(t);return{result:c,arm:X(c),source:"baseline"}}var ae=new Set;function Dt(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/"/g,'\\"')}function Mt(e,t,n){let o=A(),i=G(),f=se(()=>({id:e,dims:t}),[e]),{result:s,arm:r}=q(e,f),p=se(()=>typeof s=="string"?{}:s,[r]);if(C()&&!ae.has(e)){let d=Tt({id:e,dims:Object.fromEntries(Object.entries(t).map(([l,a])=>[l,[...a]]))}),g=Object.values(t).reduce((l,a)=>l*a.length,1);d.ok?g>4&&(ae.add(e),console.warn(`[sentient] useAdaptiveTokens("${e}") declares ${g} combinations \u2014 more than the recommended 4. Each extra combination needs more traffic to learn; consider fewer dims/values.`)):(ae.add(e),console.warn(`[sentient] useAdaptiveTokens("${e}"): invalid declaration \u2014 ${d.reason}. Serving baseline.`))}let c=(n==null?void 0:n.goal)===void 0?null:typeof n.goal=="string"?n.goal:JSON.stringify(n.goal);oe(()=>V({id:e,dims:t}),[e]);let S=Pt(null);oe(()=>{!o||S.current===r||(S.current=r,I(o,i,e,r,null))},[o,i,e,r]),oe(()=>{if(!o||!(n!=null&&n.goal))return;let d=document.querySelector(`[data-sentient-slot="${Dt(e)}"]`);if(!d){C()&&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 g=M(n.goal),l=!1;return O(d,L(n.goal),{fireGoal:()=>{l||(l=!0,o.componentGoal(e,g))},fireStep:(a,w)=>{o.componentGoal(e,a,{reward:w})}})},[o,e,c,r]);let u=se(()=>{let d={"data-sentient-slot":e};for(let[g,l]of Object.entries(p))d[`data-${g}`]=l;return d},[e,p]);return{tokens:p,props:u}}import{useCallback as Te,useEffect as W,useMemo as le,useRef as ce,useState as Wt}from"react";import{attachMicroSignalDetectors as Ft}from"@sentientui/core";var De=new Set;function Bt(e,t){var h;if(C()&&!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=A(),o=G(),i=le(()=>Object.keys(t.variants),[e]),{variantId:f,isOverride:s}=K(e,i),r=(h=f!=null?f:i[0])!=null?h:"",p=t.variants[r],[c,S]=Wt(null),u=ce(null),d=Te(y=>{u.current=y,S(y)},[]),g=typeof t.goal=="string"?t.goal:JSON.stringify(t.goal),l=le(()=>L(t.goal),[g]),a=M(t.goal);W(()=>U({id:e,variantIds:i,goal:a}),[e,i,a]);let w=ce(null);W(()=>{s||!n||!r||!c||w.current!==r&&(w.current=r,I(n,o,e,r,c))},[n,o,e,r,c,s]);let m=ce(!1);W(()=>{m.current=!1},[r,g]),W(()=>{if(!s&&!(!n||!r||!c))return O(c,l,{fireGoal:()=>{m.current||(m.current=!0,n.track({projectId:o,componentId:e,variantId:r,eventType:"goal_achieved",goalType:a,payload:{reward:1}}),n.goal(a,{componentId:e,variantId:r},1,0))},fireStep:(y,k,x)=>{n.track({projectId:o,componentId:e,variantId:r,eventType:"goal_achieved",goalType:y,payload:{reward:k}}),n.goal(y,{},k,x)}})},[n,c,r,o,e,l,a,s]),W(()=>{if(s||!n||!r||!c)return;let y=Date.now();return Ft((k,x={})=>{n.track({projectId:o,componentId:e,variantId:r,eventType:"micro_signal",payload:_({signalType:k},x)})},c,y)},[n,c,r,o,e,s]),W(()=>{if(!C()||!n)return;let y=setTimeout(()=>{!u.current&&!De.has(e)&&(De.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(y)},[n,e]);let b=Te((y,k)=>{s||n==null||n.componentGoal(e,y!=null?y:a,k)},[n,e,a,s]),v=le(()=>({ref:d,"data-sentient-id":e,"data-sentient-variant":r}),[d,e,r]);return{variant:r,value:p,bind:v,fireGoal:b}}import{Children as jt,isValidElement as Kt,useEffect as ue,useMemo as Me,useRef as We}from"react";import{jsx as $t}from"react/jsx-runtime";var Q=new Set;function Nt(e){var l;let t=A(),n=G(),o=We(null),i=Me(()=>Object.keys(e.arrangements),[e.id]),f=Me(()=>_({id:e.id,arms:i},e.baseline!==void 0?{baseline:e.baseline}:{}),[e.id,i,e.baseline]),{arm:s}=q(e.id,f);C()&&e.baseline!==void 0&&e.baseline!==i[0]&&!Q.has(e.id+":baseline")&&(Q.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 r=jt.toArray(e.children).filter(Kt),p=new Map;for(let a of r)p.set(String((l=a.key)!=null?l:"").replace(/^\.\$/,""),a);let c=e.arrangements[s],S=c!==void 0&&c.length===r.length&&c.every(a=>p.has(a));C()&&c!==void 0&&!S&&!Q.has(e.id+":keys")&&(Q.add(e.id+":keys"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: arrangement "${s}" [${c.join(", ")}] does not match the children's keys \u2014 rendering declaration order (fail-safe).`));let u=S?c.map(a=>p.get(a)):r;ue(()=>V({id:e.id,arms:Object.keys(e.arrangements)}),[e.id]);let d=We(null);ue(()=>{!t||d.current===s||(d.current=s,I(t,n,e.id,s,o.current))},[t,n,e.id,s]);let g=e.goal===void 0?null:typeof e.goal=="string"?e.goal:JSON.stringify(e.goal);return ue(()=>{if(!t||e.goal===void 0)return;let a=o.current;if(!a)return;let w=M(e.goal),m=!1;return O(a,L(e.goal),{fireGoal:()=>{m||(m=!0,t.componentGoal(e.id,w))},fireStep:(b,v)=>{t.componentGoal(e.id,b,{reward:v})}})},[t,e.id,g,s]),$t("div",{ref:o,"data-sentient-id":e.id,"data-sentient-variant":s,children:u})}import{deriveSessionSegment as Ut}from"@sentientui/core";var Vt=["page","blocks","layoutOrder"],Fe=new Map;function Ht(e,t){Fe.set(e,t)}function Be(e){return Fe.get(e)}function Jt(e){var i,f;let t=(f=(i=e.content)!=null?i:Be(e.page))!=null?f:{},n={};for(let[s,r]of Object.entries(t))Vt.includes(s)||(n[s]=r);let o=F(_({},n),{page:e.page,blocks:e.blocks});return e.layoutOrder&&(o.layoutOrder=e.layoutOrder),o}function zt(e){return`<script type="application/ld+json">${je(e)}</script>`}function je(e){return JSON.stringify(_({"@context":"https://schema.org","@type":"WebPage"},e)).replace(/</g,"\\u003c")}function Xt(e){let t=[];e.title&&t.push(`# ${e.title}`,""),e.summary&&t.push(String(e.summary),"");for(let[n,o]of Object.entries(e))["page","title","summary","blocks","layoutOrder"].includes(n)||t.push(`## ${n}`,"","```json",JSON.stringify(o,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
- `}export{vt as Adaptive,Kt as AdaptiveGroup,nt as AdaptiveProvider,ht as AdaptiveText,Ct as SentientPersonaScript,Ht as buildAgentFeed,Vt as defineAgentContent,$t as detectSegment,Fe as getAgentContent,Z as getWeights,Jt as renderAgentJsonLd,Be as renderAgentJsonLdBody,zt as renderAgentMarkdown,Q as subscribeWeights,Y as updateWeights,Ft as useAdaptive,rt as useAdaptiveApiBaseUrl,At as useAdaptiveGoal,Dt as useAdaptiveTokens,j as useAssignment,ne as useInitialAssignments,it as useLayoutOrder,A as useSentient};
4
+ `}export{yt as Adaptive,Nt as AdaptiveGroup,it as AdaptiveProvider,wt as AdaptiveText,Rt as SentientPersonaScript,Jt as buildAgentFeed,Ht as defineAgentContent,Ut as detectSegment,Be as getAgentContent,ee as getWeights,zt as renderAgentJsonLd,je as renderAgentJsonLdBody,Xt as renderAgentMarkdown,Y as subscribeWeights,Z as updateWeights,Bt as useAdaptive,ot as useAdaptiveApiBaseUrl,xt as useAdaptiveGoal,Mt as useAdaptiveTokens,K as useAssignment,ie as useInitialAssignments,rt as useLayoutOrder,A as useSentient};
5
5
  //# sourceMappingURL=index.mjs.map