@sentientui/react 0.16.0 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  'use client';
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,k=(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},B=(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(),dispose:()=>e.dispose(),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 F(){P().version+=1;for(let e of P().listeners)e()}function U(e){return P().components.set(e.id,e),F(),()=>{P().components.delete(e.id),F()}}function V(e){return P().slots.set(e.id,e),F(),()=>{P().slots.delete(e.id),F()}}function Ae(e){P().sections=[...e],F()}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 _e="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:_e});function it(e){var S,u;let[t,n]=ne(null),[o]=ne(()=>{var d;return(d=e.sessionSegment)!=null?d:nt()}),[i,g]=ne(te());j(()=>Se(()=>g(te())),[]),j(()=>{if(e.consent===!1&&!e.preConsentBehavior){n(f=>(f==null||f.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},p=!1,l=null,a=null,w=f=>{e.engagement!==!1&&import("@sentientui/core/engagement").then(({startEngagementCapture:b})=>{p||(a=b(f,{apiKey:e.apiKey,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:f})=>{p||(l=f(B(k({},d),{graph:!0})),n(l),w(l))}):(l=tt(d),n(l),w(l)),()=>{p=!0,a==null||a(),l==null||l.dispose()}},[e.consent]),j(()=>{if(!t)return;let d=!1,p=async()=>{if(d)return;let a;try{a=await t.fetchWeights()}catch(w){return}if(!d)for(let w of a){let f={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,f)}};p();let l=setInterval(()=>{p()},6e4);return()=>{d=!0,clearInterval(l)}},[t]);let s=(S=e.ssrFallback)!=null?S:"first",r=(u=e.apiBaseUrl)!=null?u:_e;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 m=xe(()=>t&&i?he(t):t,[t,i]),c=xe(()=>{var d,p,l,a;return{client:m,apiKey:e.apiKey,initialAssignments:(d=e.initialAssignments)!=null?d:{},sessionSegment:o,ssrFallback:s,onAssignment:e.onAssignment,initialLayoutOrder:(p=e.initialLayoutOrder)!=null?p:null,initialSlots:(l=e.initialSlots)!=null?l:{},initialPersona:(a=e.initialPersona)!=null?a:null,apiBaseUrl:r}},[m,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 ke(){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 Oe,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 g=i.indexOf(":");if(g!==-1&&i.slice(0,g)===e)return i.slice(g+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(),g=ke(),s=A(),r=H(),m=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 p=(()=>{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}:g==="first"&&t.length>0?{variantId:t[0],content:null,isLoading:!1}:{variantId:null,content:null,isLoading:!0}}let f=s.getAssignment(e,r);if(f&&(t.includes(f.variantId)||f.content))return{variantId:f.variantId,content:(v=f.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(p),w=f=>{m&&c.current!==f&&(c.current=f,m(e,f))};return re(()=>{var b;if(u||!s)return;let f=s.getAssignment(e,r);if(f&&(t.includes(f.variantId)||f.content)){a({variantId:f.variantId,content:(b=f.content)!=null?b:null,isLoading:!1}),w(f.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 f=s.getAssignment(e,r);if(f&&t.includes(f.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,f=>{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(f,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 O(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 L(e,t,n){if(t.type==="weighted_composite"){let r=new Set,m=[];return t.steps.forEach(({goal:c,name:S,weight:u},d)=>{let p=()=>{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)&&p()};e.addEventListener("click",l),m.push(()=>e.removeEventListener("click",l));return}if(c.type==="form_submit"){let l=a=>{a.target instanceof HTMLFormElement&&e.contains(a.target)&&p()};e.addEventListener("submit",l),m.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 f of w)if(f.intersectionRatio>=l){p(),a.disconnect();break}},{threshold:[l]});a.observe(e),m.push(()=>a.disconnect())}}),()=>{for(let c of m)c()}}let o=t.type==="composite"?t.all:[t],i=new Set(o.map((r,m)=>m)),g=r=>{i.delete(r),i.size===0&&n.fireGoal()},s=[];return o.forEach((r,m)=>{if(r.type==="click"){let c=S=>{let u=S.target;u instanceof Element&&Ee(u,e,r.selector)&&(t.type==="composite"?g(m):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"?g(m):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"?g(m):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 g=(r=i==null?void 0:i.innerHTML)!=null?r:"",s=g!==""&&dt(n,o);e.track({projectId:t,componentId:n,variantId:o,eventType:"variant_assigned",payload:s?{previewHtml:g.slice(0,ut)}:{}})}import{jsx as St}from"react/jsx-runtime";function vt(e){var b;let t=A(),n=G(),o=Oe(()=>Object.keys(e.variants),[e.variants]),{variantId:i,content:g,isOverride:s}=K(e.id,o,e.agentData,e.agentDataByVariant),r=z(null),[m,c]=pt(!1);T(()=>{c(!0)},[]);let S=z(!1),u=z(new Set),d=z(null),p=typeof e.goal=="string"?e.goal:JSON.stringify(e.goal),l=Oe(()=>O(e.goal),[p]),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,m,g,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,_=()=>{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",_),v.addEventListener("mouseleave",x),()=>{v.removeEventListener("mouseenter",_),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,_={})=>{var de,fe,ge;t.track({projectId:n,componentId:e.id,variantId:i,eventType:"micro_signal",payload:k({signalType:y},_)});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,k({signalType:y},_),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 L(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,_)=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:h,payload:{reward:y}}),t.goal(h,{},y,_)}})},[t,i,n,e.id,l,a,s]),e.clientOnly&&(!m||!t)||!i)return null;let w=(b=e.variants[i])!=null?b:null,f=w===null?g:null;return C()&&w===null&&f===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:f})}var yt=gt(vt,(e,t)=>{if(e.id!==t.id||JSON.stringify(e.goal)!==JSON.stringify(t.goal)||e.microSignalGoals!==t.microSignalGoals||e.clientOnly!==t.clientOnly||e.agentData!==t.agentData||e.agentDataByVariant!==t.agentDataByVariant)return!1;if(e.variants===t.variants)return!0;let n=Object.keys(e.variants),o=Object.keys(t.variants);return n.length!==o.length?!1:n.every(i=>i in t.variants&&Object.is(e.variants[i],t.variants[i]))});import{useEffect as Le,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(),g=G(),s=J(),r=H(),m=ht(null),[c,S]=Ie(()=>{var p,l;return(l=(p=i==null?void 0:i.getAssignment(e,r))==null?void 0:p.content)!=null?l:null}),[u,d]=Ie(()=>{var p,l;return(l=(p=i==null?void 0:i.getAssignment(e,r))==null?void 0:p.variantId)!=null?l:null});return Le(()=>{var l;if(!i||((l=i.getAssignment(e,r))==null?void 0:l.content)!==void 0)return;let p=!1;return i.assign(e).then(a=>{if(!p){if(!a){C()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}d(a.variantId),a.content&&S(a.content)}}),()=>{p=!0}},[i,e,r]),Le(()=>{!i||!u||!g||m.current!==u&&(m.current=u,i.track({projectId:g,componentId:e,variantId:u,eventType:"variant_assigned",payload:{}}),s==null||s(e,u))},[i,u,g,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 _t}from"@sentientui/core";import{confidenceBand as kt}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(kt(e.persona.confidence))+");}catch(e){}})();":_t(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 Ot,useSyncExternalStore as Lt}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;Lt(D,$,()=>0);let n=A(),o=Ce(),[,i]=Ot(u=>u+1,0),g=typeof window!="undefined"?(S=window.__sentient_slot_overrides)==null?void 0:S[e]:void 0,s=g===void 0?o[e]:void 0,r=g===void 0&&s===void 0&&n?n.getSlotResult(e):null,m=(n==null?void 0:n.isLocal)===!0&&g===void 0&&s===void 0&&r===null;if(Et(()=>{if(!m||!n)return;let u=!1;return n.decide({slots:[t]}).then(d=>{!u&&d&&i()}),()=>{u=!0}},[n,e,m]),g!==void 0)return{result:g,arm:X(g),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(),g=se(()=>({id:e,dims:t}),[e]),{result:s,arm:r}=q(e,g),m=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]]))}),p=Object.values(t).reduce((l,a)=>l*a.length,1);d.ok?p>4&&(ae.add(e),console.warn(`[sentient] useAdaptiveTokens("${e}") declares ${p} 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 p=M(n.goal),l=!1;return L(d,O(n.goal),{fireGoal:()=>{l||(l=!0,o.componentGoal(e,p))},fireStep:(a,w)=>{o.componentGoal(e,a,{reward:w})}})},[o,e,c,r]);let u=se(()=>{let d={"data-sentient-slot":e};for(let[p,l]of Object.entries(m))d[`data-${p}`]=l;return d},[e,m]);return{tokens:m,props:u}}import{useCallback as Te,useEffect as W,useMemo as le,useRef as ce,useState as Wt}from"react";import{attachMicroSignalDetectors as Bt}from"@sentientui/core";var De=new Set;function Ft(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:g,isOverride:s}=K(e,i),r=(h=g!=null?g:i[0])!=null?h:"",m=t.variants[r],[c,S]=Wt(null),u=ce(null),d=Te(y=>{u.current=y,S(y)},[]),p=typeof t.goal=="string"?t.goal:JSON.stringify(t.goal),l=le(()=>O(t.goal),[p]),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 f=ce(!1);W(()=>{f.current=!1},[r,p]),W(()=>{if(!s&&!(!n||!r||!c))return L(c,l,{fireGoal:()=>{f.current||(f.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,_,x)=>{n.track({projectId:o,componentId:e,variantId:r,eventType:"goal_achieved",goalType:y,payload:{reward:_}}),n.goal(y,{},_,x)}})},[n,c,r,o,e,l,a,s]),W(()=>{if(s||!n||!r||!c)return;let y=Date.now();return Bt((_,x={})=>{n.track({projectId:o,componentId:e,variantId:r,eventType:"micro_signal",payload:k({signalType:_},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,_)=>{s||n==null||n.componentGoal(e,y!=null?y:a,_)},[n,e,a,s]),v=le(()=>({ref:d,"data-sentient-id":e,"data-sentient-variant":r}),[d,e,r]);return{variant:r,value:m,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]),g=Me(()=>k({id:e.id,arms:i},e.baseline!==void 0?{baseline:e.baseline}:{}),[e.id,i,e.baseline]),{arm:s}=q(e.id,g);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),m=new Map;for(let a of r)m.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=>m.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=>m.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 p=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),f=!1;return L(a,O(e.goal),{fireGoal:()=>{f||(f=!0,t.componentGoal(e.id,w))},fireStep:(b,v)=>{t.componentGoal(e.id,b,{reward:v})}})},[t,e.id,p,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"],Be=new Map;function Ht(e,t){Be.set(e,t)}function Fe(e){return Be.get(e)}function Jt(e){var i,g;let t=(g=(i=e.content)!=null?i:Fe(e.page))!=null?g:{},n={};for(let[s,r]of Object.entries(t))Vt.includes(s)||(n[s]=r);let o=B(k({},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(k({"@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(`
2
+ var $e=Object.defineProperty,Ve=Object.defineProperties;var Je=Object.getOwnPropertyDescriptors;var pe=Object.getOwnPropertySymbols;var He=Object.prototype.hasOwnProperty,ze=Object.prototype.propertyIsEnumerable;var me=(e,t,n)=>t in e?$e(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,C=(e,t)=>{for(var n in t||(t={}))He.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},B=(e,t)=>Ve(e,Je(t));import{createContext as Qe,useContext as O,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(),dispose:()=>e.dispose(),destroy:()=>e.destroy()}}var we="sentient:overrides-changed";function U(){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 F(){P().version+=1;for(let e of P().listeners)e()}function $(e){return P().components.set(e.id,e),F(),()=>{P().components.delete(e.id),F()}}function V(e){return P().slots.set(e.id,e),F(),()=>{P().slots.delete(e.id),F()}}function Ae(e){P().sections=[...e],F()}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 v,u;let[t,n]=ne(null),[o]=ne(()=>{var d;return(d=e.sessionSegment)!=null?d:nt()}),[i,p]=ne(te());j(()=>Se(()=>p(te())),[]),j(()=>{if(e.consent===!1&&!e.preConsentBehavior){n(f=>(f==null||f.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,a=null,h=f=>{e.engagement!==!1&&import("@sentientui/core/engagement").then(({startEngagementCapture:w})=>{g||(a=w(f,{apiKey:e.apiKey,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:f})=>{g||(l=f(B(C({},d),{graph:!0})),n(l),h(l))}):(l=tt(d),n(l),h(l)),()=>{g=!0,a==null||a(),l==null||l.dispose()}},[e.consent]),j(()=>{if(!t)return;let d=!1,g=async()=>{if(d)return;let a;try{a=await t.fetchWeights()}catch(h){return}if(!d)for(let h of a){let f={componentId:h.componentId,updatedAt:h.updatedAt,variants:h.variants.map(w=>{var y;return{variantId:w.variantId,pulls:w.pulls,avgReward:(y=w.avgReward)!=null?y:0}})};Z(h.componentId,f)}};g();let l=setInterval(()=>{g()},6e4);return()=>{d=!0,clearInterval(l)}},[t]);let s=(v=e.ssrFallback)!=null?v:"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 m=xe(()=>t&&i?he(t):t,[t,i]),c=xe(()=>{var d,g,l,a;return{client:m,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}},[m,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 O(R).client}function G(){return O(R).apiKey}function ie(){return O(R).initialAssignments}function J(){return O(R).sessionSegment}function Ce(){return O(R).ssrFallback}function H(){return O(R).onAssignment}function rt(){let e=O(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 _e(){return O(R).initialSlots}function ot(){return O(R).apiBaseUrl}import{memo as dt,useEffect as T,useMemo as Ee,useRef as z,useState as ft}from"react";import{attachMicroSignalDetectors as gt}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 p=i.indexOf(":");if(p!==-1&&i.slice(0,p)===e)return i.slice(p+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(),p=Ce(),s=A(),r=J(),m=H(),c=Re(null);lt(D,U,()=>0);let v=ct(e),u=v&&t.includes(v)?v:null,d=Re(null);u&&d.current!==u&&(d.current=u,console.info(`[sentient] override active: ${e} -> ${u}`));let g=(()=>{var y,b;if(u)return{variantId:u,content:null,isLoading:!1};if(!s){let S=i[e];return S&&t.includes(S)?{variantId:S,content:null,isLoading:!1}:p==="first"&&t.length>0?{variantId:t[0],content:null,isLoading:!1}:{variantId:null,content:null,isLoading:!0}}let f=s.getAssignment(e,r);if(f&&(t.includes(f.variantId)||f.content))return{variantId:f.variantId,content:(y=f.content)!=null?y:null,isLoading:!1};let w=ee(e);if(w){let S=Ge(w,t);if(S)return{variantId:S,content:null,isLoading:!1}}return{variantId:(b=t[0])!=null?b:null,content:null,isLoading:!1}})(),[l,a]=at(g),h=f=>{m&&c.current!==f&&(c.current=f,m(e,f))};return re(()=>{var w;if(u||!s)return;let f=s.getAssignment(e,r);if(f&&(t.includes(f.variantId)||f.content)){a({variantId:f.variantId,content:(w=f.content)!=null?w:null,isLoading:!1}),h(f.variantId);return}a(y=>{var b;return y.variantId?y:{variantId:(b=t[0])!=null?b:null,content:null,isLoading:!1}})},[u,s,e,r]),re(()=>{if(u||!s)return;let f=s.getAssignment(e,r);if(f&&t.includes(f.variantId))return;let w=!1;return s.assign(e,t,n,o).then(y=>{var b;w||y&&(!t.includes(y.variantId)&&!y.content||(a({variantId:y.variantId,content:(b=y.content)!=null?b:null,isLoading:!1}),h(y.variantId)))}),()=>{w=!0}},[u,s,e,r]),re(()=>{if(!u&&s)return Y(e,f=>{var b;let w=s.getAssignment(e,r);if(w&&(t.includes(w.variantId)||w.content)){a({variantId:w.variantId,content:(b=w.content)!=null?b:null,isLoading:!1});return}let y=Ge(f,t);y&&a({variantId:y,content:null,isLoading:!1})})},[u,s,e,r]),u?{variantId:u,content:null,isLoading:!1,isOverride:!0}:l}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 M(e){return typeof e=="string"?e:e.type}function ut(e){if(!(e instanceof Element))return!1;let t=e.tagName.toLowerCase();return t==="a"||t==="button"?!0:e.getAttribute("role")==="button"}function Oe(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(ut(o))return!0;o=o.parentElement}return!1}function L(e,t,n){if(t.type==="weighted_composite"){let r=new Set,m=[];return t.steps.forEach(({goal:c,name:v,weight:u},d)=>{let g=()=>{r.has(d)||(r.add(d),n.fireStep(v,u,d))};if(c.type==="click"){let l=a=>{let h=a.target;h instanceof Element&&Oe(h,e,c.selector)&&g()};e.addEventListener("click",l),m.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),m.push(()=>e.removeEventListener("submit",l));return}if(c.type==="scroll_depth"){let l=Math.max(0,Math.min(1,c.threshold)),a=new IntersectionObserver(h=>{for(let f of h)if(f.intersectionRatio>=l){g(),a.disconnect();break}},{threshold:[l]});a.observe(e),m.push(()=>a.disconnect())}}),()=>{for(let c of m)c()}}let o=t.type==="composite"?t.all:[t],i=new Set(o.map((r,m)=>m)),p=r=>{i.delete(r),i.size===0&&n.fireGoal()},s=[];return o.forEach((r,m)=>{if(r.type==="click"){let c=v=>{let u=v.target;u instanceof Element&&Oe(u,e,r.selector)&&(t.type==="composite"?p(m):n.fireGoal())};e.addEventListener("click",c),s.push(()=>e.removeEventListener("click",c));return}if(r.type==="form_submit"){let c=v=>{v.target instanceof HTMLFormElement&&e.contains(v.target)&&(t.type==="composite"?p(m):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)),v=new IntersectionObserver(u=>{for(let d of u)if(d.intersectionRatio>=c){t.type==="composite"?p(m):n.fireGoal(),v.disconnect();break}},{threshold:[c]});v.observe(e),s.push(()=>v.disconnect());return}}),()=>{for(let r of s)r()}}function I(e,t,n,o){e.track({projectId:t,componentId:n,variantId:o,eventType:"variant_assigned",payload:{}})}import{jsx as vt}from"react/jsx-runtime";function pt(e){var w;let t=A(),n=G(),o=Ee(()=>Object.keys(e.variants),[e.variants]),{variantId:i,content:p,isOverride:s}=K(e.id,o,e.agentData,e.agentDataByVariant),r=z(null),[m,c]=ft(!1);T(()=>{c(!0)},[]);let v=z(!1),u=z(new Set),d=z(null),g=typeof e.goal=="string"?e.goal:JSON.stringify(e.goal),l=Ee(()=>E(e.goal),[g]),a=typeof e.goal=="string"?e.goal:l.type;if(T(()=>$({id:e.id,variantIds:o,goal:a}),[e.id,o,a]),T(()=>{s||!t||!i||!n||d.current!==i&&(d.current=i,I(t,n,e.id,i))},[t,i,n,e.id,s]),T(()=>{v.current=!1,u.current=new Set},[i,l]),T(()=>{if(s||!t||!i)return;let y=r.current;if(!y)return;let b=null,S=0,k=()=>{S=Date.now(),b=setTimeout(()=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-S}}),b=null},800)},x=()=>{b!==null&&(clearTimeout(b),b=null)};return y.addEventListener("mouseenter",k),y.addEventListener("mouseleave",x),()=>{y.removeEventListener("mouseenter",k),y.removeEventListener("mouseleave",x),b!==null&&clearTimeout(b)}},[t,i,n,e.id,s]),T(()=>{if(s||!t||!i)return;let y=r.current;if(!y)return;let b=Date.now();return gt((S,k={})=>{var de,fe,ge;t.track({projectId:n,componentId:e.id,variantId:i,eventType:"micro_signal",payload:C({signalType:S},k)});let x=(de=e.microSignalGoals)==null?void 0:de[S];if(!x||u.current.has(S))return;u.current.add(S);let Ke=typeof x=="string"?x:x.name,Ne=typeof x=="string"?1:(fe=x.weight)!=null?fe:1,Ue=typeof x=="string"?0:(ge=x.stepIndex)!=null?ge:0;t.goal(Ke,C({signalType:S},k),Ne,Ue)},y,b)},[t,i,n,e.id,e.microSignalGoals,s]),T(()=>{if(s||!t||!i)return;let y=r.current;if(y)return L(y,l,{fireGoal:()=>{v.current||(v.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:(b,S,k)=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:b,payload:{reward:S}}),t.goal(b,{},S,k)}})},[t,i,n,e.id,l,a,s]),e.clientOnly&&(!m||!t)||!i)return null;let h=(w=e.variants[i])!=null?w:null,f=h===null?p:null;return _()&&h===null&&f===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.`),vt("div",{ref:r,"data-sentient-id":e.id,"data-sentient-variant":i,children:h!=null?h:f})}var mt=dt(pt,(e,t)=>{if(e.id!==t.id||JSON.stringify(e.goal)!==JSON.stringify(t.goal)||e.microSignalGoals!==t.microSignalGoals||e.clientOnly!==t.clientOnly||e.agentData!==t.agentData||e.agentDataByVariant!==t.agentDataByVariant)return!1;if(e.variants===t.variants)return!0;let n=Object.keys(e.variants),o=Object.keys(t.variants);return n.length!==o.length?!1:n.every(i=>i in t.variants&&Object.is(e.variants[i],t.variants[i]))});import{useEffect as Le,useRef as yt,useState as Ie}from"react";import{jsx as ht}from"react/jsx-runtime";function St({id:e,default:t,component:n="span",className:o}){let i=A(),p=G(),s=H(),r=J(),m=yt(null),[c,v]=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 Le(()=>{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){_()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}d(a.variantId),a.content&&v(a.content)}}),()=>{g=!0}},[i,e,r]),Le(()=>{!i||!u||!p||m.current!==u&&(m.current=u,i.track({projectId:p,componentId:e,variantId:u,eventType:"variant_assigned",payload:{}}),s==null||s(e,u))},[i,u,p,e,s]),ht(n,{className:o,children:c!=null?c:t})}import{useCallback as wt}from"react";function bt(e){let t=A();return wt((n,o)=>{t==null||t.componentGoal(e,n,o)},[t,e])}import{renderPrePaintScript as At}from"@sentientui/core";import{confidenceBand as xt}from"@sentientui/policy";import{jsx as _t}from"react/jsx-runtime";function Pe(e){return JSON.stringify(e).replace(/</g,"\\u003c")}function kt(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(xt(e.persona.confidence))+");}catch(e){}})();":At(e.apiKey)}function Ct(e){return _t("script",{"data-sentient-persona-script":"",dangerouslySetInnerHTML:{__html:kt(e)}})}import{useEffect as oe,useMemo as se,useRef as Lt}from"react";import{validateSlotDecl as It}from"@sentientui/policy";import{useEffect as Rt,useReducer as Gt,useSyncExternalStore as Ot}from"react";import{armOfResult as X,baselineResultFor as Et}from"@sentientui/core";import{confidenceBand as Nn}from"@sentientui/policy";function q(e,t){var v;Ot(D,U,()=>0);let n=A(),o=_e(),[,i]=Gt(u=>u+1,0),p=typeof window!="undefined"?(v=window.__sentient_slot_overrides)==null?void 0:v[e]:void 0,s=p===void 0?o[e]:void 0,r=p===void 0&&s===void 0&&n?n.getSlotResult(e):null,m=(n==null?void 0:n.isLocal)===!0&&p===void 0&&s===void 0&&r===null;if(Rt(()=>{if(!m||!n)return;let u=!1;return n.decide({slots:[t]}).then(d=>{!u&&d&&i()}),()=>{u=!0}},[n,e,m]),p!==void 0)return{result:p,arm:X(p),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=Et(t);return{result:c,arm:X(c),source:"baseline"}}var ae=new Set;function Pt(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/"/g,'\\"')}function Tt(e,t,n){let o=A(),i=G(),p=se(()=>({id:e,dims:t}),[e]),{result:s,arm:r}=q(e,p),m=se(()=>typeof s=="string"?{}:s,[r]);if(_()&&!ae.has(e)){let d=It({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 v=Lt(null);oe(()=>{!o||v.current===r||(v.current=r,I(o,i,e,r))},[o,i,e,r]),oe(()=>{if(!o||!(n!=null&&n.goal))return;let d=document.querySelector(`[data-sentient-slot="${Pt(e)}"]`);if(!d){_()&&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 L(d,E(n.goal),{fireGoal:()=>{l||(l=!0,o.componentGoal(e,g))},fireStep:(a,h)=>{o.componentGoal(e,a,{reward:h})}})},[o,e,c,r]);let u=se(()=>{let d={"data-sentient-slot":e};for(let[g,l]of Object.entries(m))d[`data-${g}`]=l;return d},[e,m]);return{tokens:m,props:u}}import{useCallback as Te,useEffect as W,useMemo as le,useRef as ce,useState as Dt}from"react";import{attachMicroSignalDetectors as Mt}from"@sentientui/core";var De=new Set;function Wt(e,t){var b;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=G(),i=le(()=>Object.keys(t.variants),[e]),{variantId:p,isOverride:s}=K(e,i),r=(b=p!=null?p:i[0])!=null?b:"",m=t.variants[r],[c,v]=Dt(null),u=ce(null),d=Te(S=>{u.current=S,v(S)},[]),g=typeof t.goal=="string"?t.goal:JSON.stringify(t.goal),l=le(()=>E(t.goal),[g]),a=M(t.goal);W(()=>$({id:e,variantIds:i,goal:a}),[e,i,a]);let h=ce(null);W(()=>{s||!n||!r||!c||h.current!==r&&(h.current=r,I(n,o,e,r))},[n,o,e,r,c,s]);let f=ce(!1);W(()=>{f.current=!1},[r,g]),W(()=>{if(!s&&!(!n||!r||!c))return L(c,l,{fireGoal:()=>{f.current||(f.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:(S,k,x)=>{n.track({projectId:o,componentId:e,variantId:r,eventType:"goal_achieved",goalType:S,payload:{reward:k}}),n.goal(S,{},k,x)}})},[n,c,r,o,e,l,a,s]),W(()=>{if(s||!n||!r||!c)return;let S=Date.now();return Mt((k,x={})=>{n.track({projectId:o,componentId:e,variantId:r,eventType:"micro_signal",payload:C({signalType:k},x)})},c,S)},[n,c,r,o,e,s]),W(()=>{if(!_()||!n)return;let S=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(S)},[n,e]);let w=Te((S,k)=>{s||n==null||n.componentGoal(e,S!=null?S:a,k)},[n,e,a,s]),y=le(()=>({ref:d,"data-sentient-id":e,"data-sentient-variant":r}),[d,e,r]);return{variant:r,value:m,bind:y,fireGoal:w}}import{Children as Bt,isValidElement as Ft,useEffect as ue,useMemo as Me,useRef as We}from"react";import{jsx as Kt}from"react/jsx-runtime";var Q=new Set;function jt(e){var l;let t=A(),n=G(),o=We(null),i=Me(()=>Object.keys(e.arrangements),[e.id]),p=Me(()=>C({id:e.id,arms:i},e.baseline!==void 0?{baseline:e.baseline}:{}),[e.id,i,e.baseline]),{arm:s}=q(e.id,p);_()&&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=Bt.toArray(e.children).filter(Ft),m=new Map;for(let a of r)m.set(String((l=a.key)!=null?l:"").replace(/^\.\$/,""),a);let c=e.arrangements[s],v=c!==void 0&&c.length===r.length&&c.every(a=>m.has(a));_()&&c!==void 0&&!v&&!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=v?c.map(a=>m.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))},[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 h=M(e.goal),f=!1;return L(a,E(e.goal),{fireGoal:()=>{f||(f=!0,t.componentGoal(e.id,h))},fireStep:(w,y)=>{t.componentGoal(e.id,w,{reward:y})}})},[t,e.id,g,s]),Kt("div",{ref:o,"data-sentient-id":e.id,"data-sentient-variant":s,children:u})}import{deriveSessionSegment as Nt}from"@sentientui/core";var Ut=["page","blocks","layoutOrder"],Be=new Map;function $t(e,t){Be.set(e,t)}function Fe(e){return Be.get(e)}function Vt(e){var i,p;let t=(p=(i=e.content)!=null?i:Fe(e.page))!=null?p:{},n={};for(let[s,r]of Object.entries(t))Ut.includes(s)||(n[s]=r);let o=B(C({},n),{page:e.page,blocks:e.blocks});return e.layoutOrder&&(o.layoutOrder=e.layoutOrder),o}function Jt(e){return`<script type="application/ld+json">${je(e)}</script>`}function je(e){return JSON.stringify(C({"@context":"https://schema.org","@type":"WebPage"},e)).replace(/</g,"\\u003c")}function Ht(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{yt as Adaptive,Nt as AdaptiveGroup,it as AdaptiveProvider,wt as AdaptiveText,Rt as SentientPersonaScript,Jt as buildAgentFeed,Ht as defineAgentContent,Ut as detectSegment,Fe as getAgentContent,ee as getWeights,zt as renderAgentJsonLd,je as renderAgentJsonLdBody,Xt as renderAgentMarkdown,Y as subscribeWeights,Z as updateWeights,Ft as useAdaptive,ot as useAdaptiveApiBaseUrl,xt as useAdaptiveGoal,Mt as useAdaptiveTokens,K as useAssignment,ie as useInitialAssignments,rt as useLayoutOrder,A as useSentient};
4
+ `}export{mt as Adaptive,jt as AdaptiveGroup,it as AdaptiveProvider,St as AdaptiveText,Ct as SentientPersonaScript,Vt as buildAgentFeed,$t as defineAgentContent,Nt as detectSegment,Fe as getAgentContent,ee as getWeights,Jt as renderAgentJsonLd,je as renderAgentJsonLdBody,Ht as renderAgentMarkdown,Y as subscribeWeights,Z as updateWeights,Wt as useAdaptive,ot as useAdaptiveApiBaseUrl,bt as useAdaptiveGoal,Tt as useAdaptiveTokens,K as useAssignment,ie as useInitialAssignments,rt as useLayoutOrder,A as useSentient};
5
5
  //# sourceMappingURL=index.mjs.map