@sentientui/react 0.27.0 → 0.29.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/devtools.js +1 -1
- package/dist/devtools.js.map +1 -1
- package/dist/devtools.mjs +1 -1
- package/dist/devtools.mjs.map +1 -1
- package/dist/index.d.cts +32 -2
- package/dist/index.d.ts +32 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/next/adaptive-root.d.ts +10 -1
- package/dist/next/adaptive-root.js +2 -2
- package/dist/next/adaptive-root.js.map +1 -1
- package/dist/server.d.cts +3 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +1 -1
- package/dist/server.mjs.map +1 -1
- package/dist/testing/msw.d.cts +3 -0
- package/dist/testing/msw.d.ts +3 -0
- package/dist/testing/msw.js +1 -1
- package/dist/testing/msw.js.map +1 -1
- package/dist/testing/msw.mjs +1 -1
- package/dist/testing/msw.mjs.map +1 -1
- package/dist/testing/node.d.cts +3 -0
- package/dist/testing/node.d.ts +3 -0
- package/dist/testing/node.js +1 -1
- package/dist/testing/node.js.map +1 -1
- package/dist/testing/node.mjs +1 -1
- package/dist/testing/node.mjs.map +1 -1
- package/dist/testing/react.d.cts +3 -0
- package/dist/testing/react.d.ts +3 -0
- package/dist/testing/react.js +1 -1
- package/dist/testing/react.js.map +1 -1
- package/dist/testing/react.mjs +1 -1
- package/dist/testing/react.mjs.map +1 -1
- package/dist/testing.d.cts +3 -0
- package/dist/testing.d.ts +3 -0
- package/dist/testing.js +1 -1
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +1 -1
- package/dist/testing.mjs.map +1 -1
- package/package.json +4 -3
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
var gt=Object.defineProperty,mt=Object.defineProperties;var pt=Object.getOwnPropertyDescriptors;var X=Object.getOwnPropertySymbols;var Oe=Object.prototype.hasOwnProperty,Ee=Object.prototype.propertyIsEnumerable;var Re=(e,t,n)=>t in e?gt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,C=(e,t)=>{for(var n in t||(t={}))Oe.call(t,n)&&Re(e,n,t[n]);if(X)for(var n of X(t))Ee.call(t,n)&&Re(e,n,t[n]);return e},q=(e,t)=>mt(e,pt(t));var Ie=(e,t)=>{var n={};for(var r in e)Oe.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&X)for(var r of X(e))t.indexOf(r)<0&&Ee.call(e,r)&&(n[r]=e[r]);return n};import{createContext as ht,useContext as L,useEffect as K,useMemo as Je,useRef as ve,useState as ee,useSyncExternalStore as bt}from"react";import{deriveSessionSegment as wt,init as At}from"@sentientui/core";var Le=new Map,Q=new Map;function Pe(e,t){let n=Q.get(e);return n||(n=new Set,Q.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&Q.delete(e)}}function Te(e,t){Le.set(e,t);let n=Q.get(e);if(n)for(let r of n)try{r(t)}catch(o){}}function de(e){var t;return(t=Le.get(e))!=null?t:null}var vt={on:!1,listeners:new Set};function De(){if(typeof window=="undefined")return vt;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function fe(){return De().on}function Fe(e){let t=De().listeners;return t.add(e),()=>{t.delete(e)}}function Me(e){return{isLocal:e.isLocal,track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},fetchWeights:()=>Promise.resolve([]),getAssignment:(t,n)=>e.getAssignment(t,n),assign:(t,n,r,o)=>e.assign(t,n,r,o),decide:()=>Promise.resolve(null),getSlotResult:t=>e.getSlotResult(t),getPersona:()=>e.getPersona(),getGraph:()=>e.getGraph(),dispose:()=>e.dispose(),destroy:()=>e.destroy()}}var Be="sentient:overrides-changed";function je(){var e;return typeof window=="undefined"?0:(e=window.__sentient_overrides_version)!=null?e:0}function F(e){return typeof window=="undefined"?()=>{}:(window.addEventListener(Be,e),()=>window.removeEventListener(Be,e))}function Ke(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function _(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}function E(e){return typeof e=="string"?{type:"click"}:e}function U(e){return typeof e=="string"?e:e.type}function P(e){if(typeof e!="string"&&(e.type==="click"||e.type==="form_submit"||e.type==="scroll_depth"))return e.value}var ge=new Set,me=!1;function $e(e){if(ge.has(e))return!0;if(ge.add(e),!me){me=!0;let t=()=>{me=!1,ge.clear()};if(typeof MessageChannel=="function"){let n=new MessageChannel;n.port1.onmessage=()=>{n.port1.close(),n.port2.close(),t()},n.port2.postMessage(0)}else setTimeout(t,0)}return!1}function yt(e){if(!(e instanceof Element))return!1;let t=e.tagName.toLowerCase();return t==="a"||t==="button"?!0:e.getAttribute("role")==="button"}function Ve(e,t,n){if(n){try{let o=e;for(;o&&o!==t;){if(o.matches(n))return!0;o=o.parentElement}}catch(o){}return!1}let r=e;for(;r&&r!==t;){if(yt(r))return!0;r=r.parentElement}return!1}function T(e,t,n,r){if(t.type==="weighted_composite"){let c=new Set,m=[];return t.steps.forEach(({goal:g,name:v,weight:k},w)=>{let A=(u=!1)=>{c.has(w)||u&&r!==void 0&&$e(`step\0${v}\0${k}\0${w}`)||(c.add(w),n.fireStep(v,k,w))};if(g.type==="click"){let u=s=>{let a=s.target;a instanceof Element&&Ve(a,e,g.selector)&&A()};e.addEventListener("click",u),m.push(()=>e.removeEventListener("click",u));return}if(g.type==="form_submit"){let u=s=>{s.target instanceof HTMLFormElement&&e.contains(s.target)&&A()};e.addEventListener("submit",u),m.push(()=>e.removeEventListener("submit",u));return}if(g.type==="scroll_depth"){let u=Math.max(0,Math.min(1,g.threshold)),s=new IntersectionObserver(a=>{for(let p of a)if(p.intersectionRatio>=u){A(!0),s.disconnect();break}},{threshold:[u]});s.observe(e),m.push(()=>s.disconnect())}}),()=>{for(let g of m)g()}}let o=t.type==="composite"?t.all:[t],i=new Set(o.map((c,m)=>m)),f=()=>{r!==void 0&&$e(r)||n.fireGoal()},l=(c,m=!1)=>{i.delete(c),i.size===0&&(m?f():n.fireGoal())},d=[];return o.forEach((c,m)=>{if(c.type==="click"){let g=v=>{let k=v.target;k instanceof Element&&Ve(k,e,c.selector)&&(t.type==="composite"?l(m):n.fireGoal())};e.addEventListener("click",g),d.push(()=>e.removeEventListener("click",g));return}if(c.type==="form_submit"){let g=v=>{v.target instanceof HTMLFormElement&&e.contains(v.target)&&(t.type==="composite"?l(m):n.fireGoal())};e.addEventListener("submit",g),d.push(()=>e.removeEventListener("submit",g));return}if(c.type==="scroll_depth"){let g=Math.max(0,Math.min(1,c.threshold)),v=new IntersectionObserver(k=>{for(let w of k)if(w.intersectionRatio>=g){t.type==="composite"?l(m,!0):f(),v.disconnect();break}},{threshold:[g]});v.observe(e),d.push(()=>v.disconnect());return}}),()=>{for(let c of d)c()}}var We=new Set,Ue=new Set;function B(e,t,n,r,o){let i=`${r}|${n}`;if(Ue.has(i))return;Ue.add(i);let f=o.type==="weighted_composite"&&!We.has(r);f&&We.add(r),e.track({projectId:t,componentId:n,eventType:"funnel_declared",payload:f?{funnelId:r,steps:o.steps.map(l=>({goalId:l.name,weight:l.weight}))}:{funnelId:r}})}function j(e,t,n,r){e.track({projectId:t,componentId:n,variantId:r,eventType:"variant_assigned",payload:{}})}var St={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function V(){if(typeof window=="undefined")return St;let e=window;return e.__sentient_registry||(e.__sentient_registry={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0}),e.__sentient_registry}function J(){V().version+=1;for(let e of V().listeners)e()}var Ne=()=>{};function Y(e){return _()?(V().components.set(e.id,e),J(),()=>{V().components.delete(e.id),J()}):Ne}function Z(e){return _()?(V().slots.set(e.id,e),J(),()=>{V().slots.delete(e.id),J()}):Ne}function pe(e){_()&&(V().sections=[...e],J())}import{jsx as Rt}from"react/jsx-runtime";function xt(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{return wt({userAgent:(e=navigator.userAgent)!=null?e:"",referer:(t=document.referrer)!=null?t:"",appOrigin:window.location.origin})}catch(n){return"desktop:direct"}}var He="https://api.sentient-ui.com/v1",I=ht({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialPersona:null,apiBaseUrl:He,debug:!1});function kt(e){let[t,n]=ee(!1),r=ve(e);r.current=e;let{cookie:o,value:i,event:f}=e!=null?e:{},l=typeof(e==null?void 0:e.check)=="function";return K(()=>{let d=()=>{var v;let m=r.current;if(!m)return!1;if(m.check)return m.check()===!0;if(!m.cookie||typeof document=="undefined")return!1;let g=`${m.cookie}=${(v=m.value)!=null?v:"accepted"}`;return document.cookie.split("; ").some(k=>k.trim()===g)};if(n(d()),!f)return;let c=()=>{n(d())};return window.addEventListener(f,c),()=>window.removeEventListener(f,c)},[o,i,f,l]),t}function Ct(e){var w,A;let[t,n]=ee(null),[r]=ee(()=>{var u;return(u=e.sessionSegment)!=null?u:xt()}),[o,i]=ee(fe());K(()=>Fe(()=>i(fe())),[]);let f=kt(e.consentFrom),l=e.consentFrom?e.consent===!0||f:e.consent,d=ve(null);K(()=>{var x;if(l===!1&&!e.preConsentBehavior){(x=d.current)==null||x.destroy(),d.current=null,n(null);return}let u={apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,sessionSegment:r,consent:l,preConsentBehavior:e.preConsentBehavior,respectDoNotTrack:e.respectDoNotTrack,ssrSessionId:e.ssrSessionId,country:e.country,persona:e.persona,localMode:e.localMode,initialSlots:e.initialSlots,initialPersona:e.initialPersona,ingestUrl:e.apiBaseUrl?`${e.apiBaseUrl.replace(/\/$/,"")}/events`:void 0},s=!1,a=null,p=null,h=G=>{e.engagement!==!1&&import("@sentientui/core/engagement").then(({startEngagementCapture:S})=>{s||(p=S(G,{apiKey:e.apiKey,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:G})=>{s||(a=G(q(C({},u),{graph:!0,captureDomText:e.captureDomText===!0})),d.current=a,n(a),h(a))}):(a=At(u),d.current=a,n(a),h(a)),()=>{s=!0,p==null||p(),a==null||a.dispose()}},[l]),K(()=>{if(!t)return;let u=!1,s=async()=>{if(u)return;let p;try{p=await t.fetchWeights()}catch(h){return}if(!u)for(let h of p){let x={componentId:h.componentId,updatedAt:h.updatedAt,variants:h.variants.map(G=>{var S;return{variantId:G.variantId,pulls:G.pulls,avgReward:(S=G.avgReward)!=null?S:0}})};Te(h.componentId,x)}};s();let a=setInterval(()=>{s()},6e4);return()=>{u=!0,clearInterval(a)}},[t]);let c=(w=e.ssrFallback)!=null?w:"first",m=((A=e.apiBaseUrl)!=null?A:He).replace(/\/$/,""),g=ve(null);K(()=>{var a;if(typeof process!="undefined"&&((a=process.env)==null?void 0:a.NODE_ENV)==="production")return;let u={apiKey:e.apiKey,context:e.context,country:e.country,persona:e.persona,apiBaseUrl:m},s=g.current;if(g.current=u,s!==null)for(let p of["apiKey","context","country","persona","apiBaseUrl"])Object.is(s[p],u[p])||console.warn(`[sentient] AdaptiveProvider: \`${p}\` changed after initialisation, but the SDK client is stable for the session and only re-inits on \`consent\` \u2014 the new value is ignored. Remount the provider (e.g. via a changing \`key\` prop) to apply it.`)},[e.apiKey,e.context,e.country,e.persona,m]),K(()=>{var u;typeof process!="undefined"&&((u=process.env)==null?void 0:u.NODE_ENV)==="production"||Ke({apiKey:e.apiKey,apiBaseUrl:m,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,m]),K(()=>{let u=e.initialLayoutOrder;if(u&&u.length>0){pe(u);return}e.declaredSections&&e.declaredSections.length>0&&pe(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]),K(()=>{if(!_())return;let u=e.declaredSections;if(!u||u.length===0||typeof document=="undefined")return;let s=new Set(Array.from(document.querySelectorAll("[data-sentient-id]"),p=>p.getAttribute("data-sentient-id"))),a=u.filter(p=>!s.has(p));a.length>0&&console.warn(`[SentientUI] Declared section${a.length>1?"s":""} ${a.map(p=>`"${p}"`).join(", ")} ${a.length>1?"have":"has"} no matching data-sentient-id element, so the layout engine cannot learn what they are and will serve the same order to every persona. Add data-sentient-id="<sectionId>" (plus optional data-sentient-type) to each section's element.`)},[e.declaredSections]);let v=Je(()=>t&&o?Me(t):t,[t,o]),k=Je(()=>{var u,s,a,p,h;return{client:v,apiKey:e.apiKey,initialAssignments:(u=e.initialAssignments)!=null?u:{},sessionSegment:r,ssrFallback:c,onAssignment:e.onAssignment,initialLayoutOrder:(s=e.initialLayoutOrder)!=null?s:null,initialSlots:(a=e.initialSlots)!=null?a:{},initialPersona:(p=e.initialPersona)!=null?p:null,apiBaseUrl:m,debug:(h=e.debug)!=null?h:!1}},[v,e.apiKey,e.initialAssignments,r,c,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialPersona,m,e.debug]);return Rt(I.Provider,{value:k,children:e.children})}function R(){return L(I).client}function D(){return L(I).apiKey}function ye(){return L(I).initialAssignments}function te(){return L(I).sessionSegment}function ze(){return L(I).ssrFallback}function ne(){return L(I).onAssignment}function Xe(){return L(I).debug}function Gt(){let e=L(I).initialLayoutOrder,t=bt(F,()=>{var n;return typeof window=="undefined"?null:(n=window.__sentient_layout_override)!=null?n:null},()=>null);return t!=null?t:e}function qe(){return L(I).initialSlots}function Qe(){return L(I).initialPersona}function _t(){return L(I).apiBaseUrl}import{memo as It,useEffect as $,useMemo as Ze,useRef as ie,useState as Lt}from"react";import{attachMicroSignalDetectors as Pt}from"@sentientui/core";import{useEffect as re,useRef as Ye,useState as Ot,useSyncExternalStore as Et}from"react";import{pickFromWeights as Se}from"@sentientui/policy";function N(e){var n;if(typeof window=="undefined")return null;let t=(n=window.__sentient_overrides)==null?void 0:n[e];if(t)return t;if(!window.location.search)return null;try{let r=new URLSearchParams(window.location.search);for(let o of r.getAll("sentient_variant")){let i=o.indexOf(":");if(i!==-1&&o.slice(0,i)===e)return o.slice(i+1)}}catch(r){}return null}function H(e,t,n,r){let o=ye(),i=ze(),f=R(),l=te(),d=ne(),c=Xe(),m=Ye(null),g=Et(F,()=>N(e),()=>null),v=g&&t.includes(g)?g:null,k=Ye(null);re(()=>{c&&v&&k.current!==v&&(k.current=v,console.info(`[sentient] override active: ${e} -> ${v}`))},[c,v,e]);let[w,A]=Ot(()=>{var p,h;if(v)return{variantId:v,content:null,isLoading:!1,settled:!0};if(!f){let x=o[e];return x&&t.includes(x)?{variantId:x,content:null,isLoading:!1,settled:!0}:i==="first"&&t.length>0?{variantId:t[0],content:null,isLoading:!1,settled:!1}:{variantId:null,content:null,isLoading:!0,settled:!1}}let s=f.getAssignment(e,l);if(s&&(t.includes(s.variantId)||s.content))return{variantId:s.variantId,content:(p=s.content)!=null?p:null,isLoading:!1,settled:!0};let a=de(e);if(a){let x=Se(a.variants,t);if(x)return{variantId:x,content:null,isLoading:!1,settled:!0}}return{variantId:(h=t[0])!=null?h:null,content:null,isLoading:!1,settled:!1}}),u=s=>{d&&m.current!==s&&(m.current=s,d(e,s))};return re(()=>{var p;if(v||!f)return;let s=f.getAssignment(e,l);if(s&&(t.includes(s.variantId)||s.content)){A({variantId:s.variantId,content:(p=s.content)!=null?p:null,isLoading:!1,settled:!0}),u(s.variantId);return}let a=de(e);if(a&&w.settled&&w.variantId&&w.variantId===Se(a.variants,t)){u(w.variantId);return}A(h=>{var x;return h.variantId?h:{variantId:(x=t[0])!=null?x:null,content:null,isLoading:!1,settled:!1}})},[v,f,e,l]),re(()=>{if(v||!f)return;let s=f.getAssignment(e,l);if(s&&t.includes(s.variantId))return;let a=!1;return f.assign(e,t,n,r).then(p=>{var h;a||p&&(!t.includes(p.variantId)&&!p.content||(A({variantId:p.variantId,content:(h=p.content)!=null?h:null,isLoading:!1,settled:!0}),u(p.variantId)))}),()=>{a=!0}},[v,f,e,l]),re(()=>{if(!v&&f)return Pe(e,s=>{var h;let a=f.getAssignment(e,l);if(a&&(t.includes(a.variantId)||a.content)){A({variantId:a.variantId,content:(h=a.content)!=null?h:null,isLoading:!1,settled:!0}),u(a.variantId);return}let p=Se(s.variants,t);p&&(A({variantId:p,content:null,isLoading:!1,settled:!0}),u(p))})},[v,f,e,l]),v?{variantId:v,content:null,isLoading:!1,settled:!0,isOverride:!0}:w}import{jsx as Ft}from"react/jsx-runtime";function Tt(e){var h;let t=R(),n=D(),r=Object.keys(e.variants).join("\0"),o=Ze(()=>Object.keys(e.variants),[r]),{variantId:i,content:f,isOverride:l,settled:d}=H(e.id,o,e.agentData,e.agentDataByVariant),c=ie(null),[m,g]=Lt(!1);$(()=>{g(!0)},[]);let v=ie(!1),k=ie(new Set),w=ie(null),A=typeof e.goal=="string"?e.goal:JSON.stringify(e.goal),u=Ze(()=>E(e.goal),[A]),s=typeof e.goal=="string"?e.goal:u.type;if($(()=>Y({id:e.id,variantIds:o,goal:s}),[e.id,o,s]),$(()=>{l||d&&(!t||!i||!n||w.current!==i&&(w.current=i,j(t,n,e.id,i)))},[t,i,n,e.id,l,d]),$(()=>{v.current=!1,k.current=new Set},[i,u]),$(()=>{l||!d||!t||!e.funnel||B(t,n,e.id,e.funnel,u)},[t,n,e.id,e.funnel,u,l,d]),$(()=>{if(l||!d||!t||!i)return;let x=c.current;if(!x)return;let G=null,S=0,b=()=>{S=Date.now(),G=setTimeout(()=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-S}}),G=null},800)},y=()=>{G!==null&&(clearTimeout(G),G=null)};return x.addEventListener("mouseenter",b),x.addEventListener("mouseleave",y),()=>{x.removeEventListener("mouseenter",b),x.removeEventListener("mouseleave",y),G!==null&&clearTimeout(G)}},[t,i,n,e.id,l,d]),$(()=>{if(l||!d||!t||!i)return;let x=c.current;if(!x)return;let G=Date.now();return Pt((S,b={})=>{var Ce,Ge,_e;t.track({projectId:n,componentId:e.id,variantId:i,eventType:"micro_signal",payload:C({signalType:S},b)});let y=(Ce=e.microSignalGoals)==null?void 0:Ce[S];if(!y||k.current.has(S))return;k.current.add(S);let O=typeof y=="string"?y:y.name,M=typeof y=="string"?1:(Ge=y.weight)!=null?Ge:1,z=typeof y=="string"?0:(_e=y.stepIndex)!=null?_e:0;t.goal(O,{metadata:C({signalType:S},b),weight:M,stepIndex:z})},x,G)},[t,i,n,e.id,e.microSignalGoals,l,d]),$(()=>{if(l||!d||!t||!i)return;let x=c.current;if(!x)return;let G=P(u);return T(x,u,{fireGoal:()=>{v.current||(v.current=!0,t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:s,payload:C({reward:1},G!==void 0?{goalValue:G}:{})}),t.goal(s,C({metadata:{componentId:e.id,variantId:i},weight:1,stepIndex:0},G!==void 0?{value:G}:{})))},fireStep:(S,b,y)=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:S,payload:{reward:b}}),t.goal(S,{metadata:{},weight:b,stepIndex:y})}},s)},[t,i,n,e.id,u,s,l,d]),e.clientOnly&&(!m||!t)||!i)return null;let a=(h=e.variants[i])!=null?h:null,p=a===null?f:null;return _()&&a===null&&p===null&&console.warn(`[sentient] <Adaptive id="${e.id}"> was assigned variant "${i}" but no matching key exists in props.variants. If this is a dashboard-managed text variant, use <AdaptiveText id="${e.id}"> instead.`),Ft("div",{ref:c,"data-sentient-id":e.id,"data-sentient-variant":i,children:a!=null?a:p})}var Dt=It(Tt,(e,t)=>{if(e.id!==t.id||e.goal!==t.goal&&JSON.stringify(e.goal)!==JSON.stringify(t.goal)||e.microSignalGoals!==t.microSignalGoals||e.funnel!==t.funnel||e.clientOnly!==t.clientOnly||e.agentData!==t.agentData||e.agentDataByVariant!==t.agentDataByVariant)return!1;if(e.variants===t.variants)return!0;let n=Object.keys(e.variants),r=Object.keys(t.variants);return n.length!==r.length?!1:n.every(o=>o in t.variants&&Object.is(e.variants[o],t.variants[o]))});import{useEffect as oe,useMemo as Mt,useRef as he,useState as et,useSyncExternalStore as Bt}from"react";import{jsx as Kt}from"react/jsx-runtime";function jt({id:e,default:t,component:n="span",className:r,goal:o}){var G;let i=R(),f=D(),l=ne(),d=te(),c=he(null),m=he(null),g=Bt(F,()=>N(e),()=>null),[v,k]=et(()=>{var S,b;return(b=(S=i==null?void 0:i.getAssignment(e,d))==null?void 0:S.content)!=null?b:null}),[w,A]=et(()=>{var S,b;return(b=(S=i==null?void 0:i.getAssignment(e,d))==null?void 0:S.variantId)!=null?b:null});oe(()=>{if(g||!i)return;let S=i.getAssignment(e,d);if((S==null?void 0:S.content)!==void 0){A(S.variantId),k(S.content);return}let b=!1;return i.assign(e).then(y=>{if(!b){if(!y){_()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}A(y.variantId),y.content&&k(y.content)}}),()=>{b=!0}},[i,e,d,g]),oe(()=>{g||!i||!w||!f||c.current!==w&&(c.current=w,i.track({projectId:f,componentId:e,variantId:w,eventType:"variant_assigned",payload:{}}),l==null||l(e,w))},[i,w,f,e,l,g]);let u=o===void 0?"":typeof o=="string"?o:JSON.stringify(o),s=Mt(()=>o===void 0?null:E(o),[u]),a=o===void 0?null:typeof o=="string"?o:s.type,p=he(!1);oe(()=>{p.current=!1},[w,u]),oe(()=>{if(g||!i||!w||!f||!s||!a)return;let S=m.current;if(!S)return;let b=P(s);return T(S,s,{fireGoal:()=>{p.current||(p.current=!0,i.track({projectId:f,componentId:e,variantId:w,eventType:"goal_achieved",goalType:a,payload:C({reward:1},b!==void 0?{goalValue:b}:{})}),i.goal(a,C({metadata:{componentId:e,variantId:w},weight:1,stepIndex:0},b!==void 0?{value:b}:{})))},fireStep:(y,O,M)=>{i.track({projectId:f,componentId:e,variantId:w,eventType:"goal_achieved",goalType:y,payload:{reward:O}}),i.goal(y,{metadata:{},weight:O,stepIndex:M})}})},[i,w,f,e,s,a,g]);let h=v!=null?v:t;if(g){let S=i==null?void 0:i.getAssignment(e,d);h=S&&S.variantId===g&&(G=S.content)!=null?G:t}return Kt(n,{ref:S=>{m.current=S},className:r,children:h})}import{useCallback as $t,useRef as Vt}from"react";function be(e){let t=R(),n=Vt(new Set);return $t((r,o)=>{var i,f;if(!N(e)){if(o!=null&&o.once){if(n.current.has(r))return;n.current.add(r)}t==null||t.componentGoal(e,r,o),t==null||t.goal(r,C(C(C({metadata:(i=o==null?void 0:o.metadata)!=null?i:{},weight:(f=o==null?void 0:o.reward)!=null?f:1,stepIndex:0},(o==null?void 0:o.value)!==void 0?{value:o.value}:{}),(o==null?void 0:o.currency)!==void 0?{currency:o.currency}:{}),(o==null?void 0:o.externalId)!==void 0?{externalId:o.externalId}:{}))}},[t,e])}import{useEffect as Wt,useRef as tt}from"react";function Ut(e,t={}){let d=t,{componentId:n}=d,r=Ie(d,["componentId"]),o=R(),i=be(n!=null?n:""),f=tt(!1),l=tt(r);l.current=r,Wt(()=>{if(!o||f.current)return;f.current=!0;let{metadata:c,reward:m,value:g,currency:v,externalId:k}=l.current;if(n){i(e,l.current);return}o.goal(e,C(C(C({metadata:c!=null?c:{},weight:m!=null?m:1,stepIndex:0},g!==void 0?{value:g}:{}),v!==void 0?{currency:v}:{}),k!==void 0?{externalId:k}:{}))},[o,n,e,i])}import{renderPrePaintScript as Nt}from"@sentientui/core";import{confidenceBand as Jt}from"@sentientui/policy";import{jsx as Xt}from"react/jsx-runtime";function nt(e){return JSON.stringify(e).replace(/</g,"\\u003c")}function Ht(e){return e.persona?'(function(){try{var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",'+nt(e.persona.persona)+');d.setAttribute("data-sentient-confidence",'+nt(Jt(e.persona.confidence))+");}catch(e){}})();":Nt(e.apiKey)}function zt(e){return Xt("script",{"data-sentient-persona-script":"",nonce:e.nonce,dangerouslySetInnerHTML:{__html:Ht(e)}})}import{useEffect as le,useMemo as Ae,useRef as nn}from"react";import{validateSlotDecl as rn}from"@sentientui/policy";import{useEffect as we,useReducer as qt,useState as Qt,useSyncExternalStore as it}from"react";import{armOfResult as se,baselineResultFor as Yt}from"@sentientui/core";import{confidenceBand as Zt}from"@sentientui/policy";var rt=new Set;function ae(e,t){let n=R(),r=qe(),[,o]=qt(m=>m+1,0),i=it(F,()=>{var m;return typeof window!="undefined"?(m=window.__sentient_slot_overrides)==null?void 0:m[e]:void 0},()=>{}),f=i===void 0?r[e]:void 0,l=i===void 0&&f===void 0&&n?n.getSlotResult(e):null,d=(n==null?void 0:n.isLocal)===!0&&i===void 0&&f===void 0&&l===null;we(()=>{if(!d||!n)return;let m=!1;return n.decide({slots:[t]}).then(g=>{!m&&g&&o()}),()=>{m=!0}},[n,e,d]);let c=(()=>{if(i!==void 0)return{result:i,arm:se(i),source:"override"};if(f!==void 0)return{result:f,arm:se(f),source:"preloaded"};if(l!==null)return{result:l,arm:se(l),source:"client"};let m=Yt(t);return{result:m,arm:se(m),source:"baseline"}})();return we(()=>{_()&&(!n||n.isLocal===!0||c.source==="baseline"&&(rt.has(e)||(rt.add(e),console.warn(`[sentient] slot "${e}" resolved to its baseline \u2014 no SSR-preloaded or decided result. Keyed clients decide slots server-side, so this slot serves baseline for the whole session and records no exposure. Preload it via loadAdaptiveDecision()/initialSlots so it can serve a decided arm and learn.`))))},[n,c.source,e]),c}function en(){var t;if(typeof window=="undefined")return null;let e=window.__sentient_persona_override;if(e!=null&&e.persona)return{persona:e.persona,confidence:(t=e.confidence)!=null?t:1};try{let n=new URLSearchParams(window.location.search).get("sentient_persona");if(n)return{persona:n,confidence:1}}catch(n){}return null}function tn(){let e=R(),t=Qe();it(F,je,()=>0);let[n,r]=Qt(!1);we(()=>r(!0),[]);let o=l=>({persona:l.persona,confidence:l.confidence,band:Zt(l.confidence)});if(!n)return t?o(t):null;let i=en();if(i)return o(i);if(t)return o(t);let f=e?e.getPersona():null;return f?o(f):null}var ot=new Set;function on(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/[\\"]/g,"\\$&")}function sn(e,t,n){let r=R(),o=D(),i=JSON.stringify(t),f=Ae(()=>({id:e,dims:t}),[e,i]),{result:l,arm:d,source:c}=ae(e,f),m=Ae(()=>typeof l=="string"?{}:l,[d]);if(_()&&!ot.has(e)){ot.add(e);let A=rn({id:e,dims:Object.fromEntries(Object.entries(t).map(([s,a])=>[s,[...a]]))}),u=Object.values(t).reduce((s,a)=>s*a.length,1);A.ok?u>4&&console.warn(`[sentient] useAdaptiveTokens("${e}") declares ${u} combinations \u2014 more than the recommended 4. Each extra combination needs more traffic to learn; consider fewer dims/values.`):console.warn(`[sentient] useAdaptiveTokens("${e}"): invalid declaration \u2014 ${A.reason}. Serving baseline.`)}let g=(n==null?void 0:n.goal)===void 0?null:typeof n.goal=="string"?n.goal:JSON.stringify(n.goal);le(()=>Z({id:e,dims:t}),[e]);let v=nn(null);le(()=>{!r||c==="baseline"||c==="override"||v.current===d||(v.current=d,j(r,o,e,d))},[r,o,e,d,c]);let k=n==null?void 0:n.funnel;le(()=>{var A;!r||!k||c==="override"||B(r,o,e,k,E((A=n==null?void 0:n.goal)!=null?A:"click"))},[r,o,e,k,g,c]),le(()=>{if(!r||!(n!=null&&n.goal)||c==="override"||c==="baseline")return;let A=document.querySelector(`[data-sentient-slot="${on(e)}"]`);if(!A){_()&&console.warn(`[sentient] useAdaptiveTokens("${e}"): a goal is declared but no element carries the returned props \u2014 spread {...props} on the slot's element.`);return}let u=U(n.goal),s=P(n.goal),a=!1;return T(A,E(n.goal),{fireGoal:()=>{a||(a=!0,s!==void 0?r.componentGoal(e,u,{value:s}):r.componentGoal(e,u),r.goal(u,C({metadata:{componentId:e,arm:d},weight:1,stepIndex:0},s!==void 0?{value:s}:{})))},fireStep:(p,h,x)=>{r.componentGoal(e,p,{reward:h}),r.goal(p,{metadata:{componentId:e,arm:d},weight:h,stepIndex:x})}},u)},[r,e,g,d,c]);let w=Ae(()=>{let A={"data-sentient-slot":e};for(let[u,s]of Object.entries(m))A[`data-${u}`]=s;return A},[e,m]);return{tokens:m,props:w}}import{useCallback as st,useEffect as W,useMemo as xe,useRef as ke,useState as an}from"react";import{attachMicroSignalDetectors as ln}from"@sentientui/core";var at=new Set;function un(e,t){var S;if(_()&&!t.goal)throw new Error(`[sentient] useAdaptive("${e}"): a goal is required \u2014 without one the optimizer accumulates exposures with no rewards and cannot learn. Pass e.g. goal: 'buy_click'.`);let n=R(),r=D(),o=Object.keys(t.variants).join(" "),i=xe(()=>Object.keys(t.variants),[o]),{variantId:f,isOverride:l,settled:d}=H(e,i),c=(S=f!=null?f:i[0])!=null?S:"",m=t.variants[c],[g,v]=an(null),k=ke(null),w=st(b=>{k.current=b,v(b)},[]),A=typeof t.goal=="string"?t.goal:JSON.stringify(t.goal),u=xe(()=>t.goal?E(t.goal):null,[A]),s=t.goal?U(t.goal):"";W(()=>Y({id:e,variantIds:i,goal:s}),[e,i,s]);let a=ke(null);W(()=>{l||d&&(!n||!c||!g||a.current!==c&&(a.current=c,j(n,r,e,c)))},[n,r,e,c,g,l,d]);let p=t.funnel;W(()=>{l||!d||!n||!p||!u||B(n,r,e,p,u)},[n,r,e,p,u,l,d]);let h=ke(!1);W(()=>{h.current=!1},[c,A]),W(()=>{if(l||!d||!n||!c||!g||!u)return;let b=P(u);return T(g,u,{fireGoal:()=>{h.current||(h.current=!0,n.track({projectId:r,componentId:e,variantId:c,eventType:"goal_achieved",goalType:s,payload:C({reward:1},b!==void 0?{goalValue:b}:{})}),n.goal(s,C({metadata:{componentId:e,variantId:c},weight:1,stepIndex:0},b!==void 0?{value:b}:{})))},fireStep:(y,O,M)=>{n.track({projectId:r,componentId:e,variantId:c,eventType:"goal_achieved",goalType:y,payload:{reward:O}}),n.goal(y,{metadata:{},weight:O,stepIndex:M})}},s)},[n,g,c,r,e,u,s,l,d]),W(()=>{if(l||!n||!c||!g)return;let b=Date.now();return ln((y,O={})=>{n.track({projectId:r,componentId:e,variantId:c,eventType:"micro_signal",payload:C({signalType:y},O)})},g,b)},[n,g,c,r,e,l]),W(()=>{if(!_()||!n)return;let b=setTimeout(()=>{!k.current&&!at.has(e)&&(at.add(e),console.warn(`[sentient] useAdaptive("${e}"): bind was never attached \u2014 spread {...bind} on the rendered element, otherwise exposure and goal tracking cannot work and the optimizer learns nothing.`))},0);return()=>clearTimeout(b)},[n,e]);let x=st((b,y)=>{var M,z;if(l)return;let O=b!=null?b:s;O&&(n==null||n.componentGoal(e,O,y),n==null||n.goal(O,C(C(C({metadata:(M=y==null?void 0:y.metadata)!=null?M:{},weight:(z=y==null?void 0:y.reward)!=null?z:1,stepIndex:0},(y==null?void 0:y.value)!==void 0?{value:y.value}:{}),(y==null?void 0:y.currency)!==void 0?{currency:y.currency}:{}),(y==null?void 0:y.externalId)!==void 0?{externalId:y.externalId}:{})))},[n,e,s,l]),G=xe(()=>({ref:w,"data-sentient-id":e,"data-sentient-variant":c}),[w,e,c]);return{variant:c,value:m,bind:G,fireGoal:x}}import{Children as cn,isValidElement as dn,useEffect as ue,useMemo as lt,useRef as ut}from"react";import{jsx as gn}from"react/jsx-runtime";var ce=new Set;function fn(e){var s;let t=R(),n=D(),r=ut(null),o=Object.keys(e.arrangements).join(" "),i=lt(()=>Object.keys(e.arrangements),[o]),f=lt(()=>C({id:e.id,arms:i},e.baseline!==void 0?{baseline:e.baseline}:{}),[e.id,i,e.baseline]),{arm:l,source:d}=ae(e.id,f);_()&&e.baseline!==void 0&&e.baseline!==i[0]&&!ce.has(e.id+":baseline")&&(ce.add(e.id+":baseline"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: baseline "${e.baseline}" is not the first-declared arrangement ("${i[0]}"). The first arrangement should usually be the page's real incumbent (the holdout sees it).`));let c=cn.toArray(e.children).filter(dn),m=new Map;for(let a of c)m.set(String((s=a.key)!=null?s:"").replace(/^\.\$/,""),a);let g=e.arrangements[l],v=g!==void 0&&g.length===c.length&&g.every(a=>m.has(a));_()&&g!==void 0&&!v&&!ce.has(e.id+":keys")&&(ce.add(e.id+":keys"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: arrangement "${l}" [${g.join(", ")}] does not match the children's keys \u2014 rendering declaration order (fail-safe).`));let k=v?g.map(a=>m.get(a)):c;ue(()=>Z({id:e.id,arms:Object.keys(e.arrangements)}),[e.id]);let w=ut(null);ue(()=>{!t||d==="baseline"||d==="override"||w.current===l||(w.current=l,j(t,n,e.id,l))},[t,n,e.id,l,d]);let A=e.funnel;ue(()=>{var a;!t||!A||d==="override"||B(t,n,e.id,A,E((a=e.goal)!=null?a:"click"))},[t,n,e.id,A,d]);let u=e.goal===void 0?null:typeof e.goal=="string"?e.goal:JSON.stringify(e.goal);return ue(()=>{if(!t||e.goal===void 0||d==="override"||d==="baseline")return;let a=r.current;if(!a)return;let p=U(e.goal),h=P(e.goal),x=!1;return T(a,E(e.goal),{fireGoal:()=>{x||(x=!0,h!==void 0?t.componentGoal(e.id,p,{value:h}):t.componentGoal(e.id,p),t.goal(p,C({metadata:{componentId:e.id,arm:l},weight:1,stepIndex:0},h!==void 0?{value:h}:{})))},fireStep:(G,S,b)=>{t.componentGoal(e.id,G,{reward:S}),t.goal(G,{metadata:{componentId:e.id,arm:l},weight:S,stepIndex:b})}},p)},[t,e.id,u,l,d]),gn("div",{ref:r,"data-sentient-id":e.id,"data-sentient-variant":l,children:k})}import{deriveSessionSegment as mn}from"@sentientui/core";var pn=["page","blocks","layoutOrder"],ct=new Map;function vn(e,t){ct.set(e,t)}function dt(e){return ct.get(e)}function yn(e){var o,i;let t=(i=(o=e.content)!=null?o:dt(e.page))!=null?i:{},n={};for(let[f,l]of Object.entries(t))pn.includes(f)||(n[f]=l);let r=q(C({},n),{page:e.page,blocks:e.blocks});return e.layoutOrder&&(r.layoutOrder=e.layoutOrder),r}function Sn(e){return`<script type="application/ld+json">${ft(e)}</script>`}function ft(e){return JSON.stringify(C({"@context":"https://schema.org","@type":"WebPage"},e)).replace(/</g,"\\u003c")}function hn(e){let t=[];e.title&&t.push(`# ${e.title}`,""),e.summary&&t.push(String(e.summary),"");for(let[n,r]of Object.entries(e))["page","title","summary","blocks","layoutOrder"].includes(n)||t.push(`## ${n}`,"","```json",JSON.stringify(r,null,2),"```","");if(e.blocks.length>0){t.push("## blocks","");for(let n of e.blocks)t.push(`- **${n.id}** \u2192 variant \`${n.variant}\``),n.content!==void 0&&t.push(""," ```json",JSON.stringify(n.content,null,2)," ```");t.push("")}return t.join(`
|
|
2
|
+
var Tt=Object.defineProperty,Ft=Object.defineProperties;var Bt=Object.getOwnPropertyDescriptors;var Q=Object.getOwnPropertySymbols;var Be=Object.prototype.hasOwnProperty,Me=Object.prototype.propertyIsEnumerable;var Fe=(e,t,n)=>t in e?Tt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,S=(e,t)=>{for(var n in t||(t={}))Be.call(t,n)&&Fe(e,n,t[n]);if(Q)for(var n of Q(t))Me.call(t,n)&&Fe(e,n,t[n]);return e},K=(e,t)=>Ft(e,Bt(t));var Ke=(e,t)=>{var n={};for(var i in e)Be.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(e!=null&&Q)for(var i of Q(e))t.indexOf(i)<0&&Me.call(e,i)&&(n[i]=e[i]);return n};import{createContext as Nt,useContext as L,useEffect as V,useMemo as tt,useRef as xe,useState as te,useSyncExternalStore as $t}from"react";import{deriveSessionSegment as Vt,init as Wt}from"@sentientui/core";var je=new Map,Y=new Map;function Ne(e,t){let n=Y.get(e);return n||(n=new Set,Y.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&Y.delete(e)}}function $e(e,t){je.set(e,t);let n=Y.get(e);if(n)for(let i of n)try{i(t)}catch(s){}}function ve(e){var t;return(t=je.get(e))!=null?t:null}var Mt={on:!1,listeners:new Set};function Ve(){if(typeof window=="undefined")return Mt;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function ye(){return Ve().on}function We(e){let t=Ve().listeners;return t.add(e),()=>{t.delete(e)}}function Ue(e){return{isLocal:e.isLocal,track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},fetchWeights:()=>Promise.resolve([]),getAssignment:(t,n)=>e.getAssignment(t,n),assign:(t,n,i,s)=>e.assign(t,n,i,s),decide:()=>Promise.resolve(null),getSlotResult:t=>e.getSlotResult(t),getSlotConfig:t=>e.getSlotConfig(t),getSitePalette:()=>e.getSitePalette(),reportSlots:t=>e.reportSlots(t),getPersona:()=>e.getPersona(),getGraph:()=>e.getGraph(),dispose:()=>e.dispose(),destroy:()=>e.destroy()}}var Je="sentient:overrides-changed";function He(){var e;return typeof window=="undefined"?0:(e=window.__sentient_overrides_version)!=null?e:0}function D(e){return typeof window=="undefined"?()=>{}:(window.addEventListener(Je,e),()=>window.removeEventListener(Je,e))}function Xe(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function _(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}function P(e){return typeof e=="string"?{type:"click"}:e}function N(e){return typeof e=="string"?e:e.type}function T(e){if(typeof e!="string"&&(e.type==="click"||e.type==="form_submit"||e.type==="scroll_depth"))return e.value}var Se=new Set,he=!1;function ze(e){if(Se.has(e))return!0;if(Se.add(e),!he){he=!0;let t=()=>{he=!1,Se.clear()};if(typeof MessageChannel=="function"){let n=new MessageChannel;n.port1.onmessage=()=>{n.port1.close(),n.port2.close(),t()},n.port2.postMessage(0)}else setTimeout(t,0)}return!1}function Kt(e){if(!(e instanceof Element))return!1;let t=e.tagName.toLowerCase();return t==="a"||t==="button"?!0:e.getAttribute("role")==="button"}function qe(e,t,n){if(n){try{let s=e;for(;s&&s!==t;){if(s.matches(n))return!0;s=s.parentElement}}catch(s){}return!1}let i=e;for(;i&&i!==t;){if(Kt(i))return!0;i=i.parentElement}return!1}function F(e,t,n,i){if(t.type==="weighted_composite"){let l=new Set,d=[];return t.steps.forEach(({goal:f,name:p,weight:h},b)=>{let y=(c=!1)=>{l.has(b)||c&&i!==void 0&&ze(`step\0${p}\0${h}\0${b}`)||(l.add(b),n.fireStep(p,h,b))};if(f.type==="click"){let c=u=>{let g=u.target;g instanceof Element&&qe(g,e,f.selector)&&y()};e.addEventListener("click",c),d.push(()=>e.removeEventListener("click",c));return}if(f.type==="form_submit"){let c=u=>{u.target instanceof HTMLFormElement&&e.contains(u.target)&&y()};e.addEventListener("submit",c),d.push(()=>e.removeEventListener("submit",c));return}if(f.type==="scroll_depth"){let c=Math.max(0,Math.min(1,f.threshold)),u=new IntersectionObserver(g=>{for(let v of g)if(v.intersectionRatio>=c){y(!0),u.disconnect();break}},{threshold:[c]});u.observe(e),d.push(()=>u.disconnect())}}),()=>{for(let f of d)f()}}let s=t.type==="composite"?t.all:[t],r=new Set(s.map((l,d)=>d)),m=()=>{i!==void 0&&ze(i)||n.fireGoal()},o=(l,d=!1)=>{r.delete(l),r.size===0&&(d?m():n.fireGoal())},a=[];return s.forEach((l,d)=>{if(l.type==="click"){let f=p=>{let h=p.target;h instanceof Element&&qe(h,e,l.selector)&&(t.type==="composite"?o(d):n.fireGoal())};e.addEventListener("click",f),a.push(()=>e.removeEventListener("click",f));return}if(l.type==="form_submit"){let f=p=>{p.target instanceof HTMLFormElement&&e.contains(p.target)&&(t.type==="composite"?o(d):n.fireGoal())};e.addEventListener("submit",f),a.push(()=>e.removeEventListener("submit",f));return}if(l.type==="scroll_depth"){let f=Math.max(0,Math.min(1,l.threshold)),p=new IntersectionObserver(h=>{for(let b of h)if(b.intersectionRatio>=f){t.type==="composite"?o(d,!0):m(),p.disconnect();break}},{threshold:[f]});p.observe(e),a.push(()=>p.disconnect());return}}),()=>{for(let l of a)l()}}var Ze=new Set,Qe=new Set;function $(e,t,n,i,s){let r=`${i}|${n}`;if(Qe.has(r))return;Qe.add(r);let m=s.type==="weighted_composite"&&!Ze.has(i);m&&Ze.add(i),e.track({projectId:t,componentId:n,eventType:"funnel_declared",payload:m?{funnelId:i,steps:s.steps.map(o=>({goalId:o.name,weight:o.weight}))}:{funnelId:i}})}function j(e,t,n,i){e.track({projectId:t,componentId:n,variantId:i,eventType:"variant_assigned",payload:{}})}var jt={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function U(){if(typeof window=="undefined")return jt;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 q(){U().version+=1;for(let e of U().listeners)e()}var Ye=()=>{};function ee(e){return _()?(U().components.set(e.id,e),q(),()=>{U().components.delete(e.id),q()}):Ye}function X(e){return _()?(U().slots.set(e.id,e),q(),()=>{U().slots.delete(e.id),q()}):Ye}function be(e){_()&&(U().sections=[...e],q())}var et="0.29.0",we=et!=="0.0.0-dev"?{name:"react",version:et}:void 0;import{jsx as qt}from"react/jsx-runtime";function Ut(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{return Vt({userAgent:(e=navigator.userAgent)!=null?e:"",referer:(t=document.referrer)!=null?t:"",appOrigin:window.location.origin})}catch(n){return"desktop:direct"}}var nt="https://api.sentient-ui.com/v1",I=Nt({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialSlotConfig:{},initialPalette:null,initialPersona:null,apiBaseUrl:nt,debug:!1});function Jt(e){let[t,n]=te(!1),i=xe(e);i.current=e;let{cookie:s,value:r,event:m}=e!=null?e:{},o=typeof(e==null?void 0:e.check)=="function";return V(()=>{let a=()=>{var p;let d=i.current;if(!d)return!1;if(d.check)return d.check()===!0;if(!d.cookie||typeof document=="undefined")return!1;let f=`${d.cookie}=${(p=d.value)!=null?p:"accepted"}`;return document.cookie.split("; ").some(h=>h.trim()===f)};if(n(a()),!m)return;let l=()=>{n(a())};return window.addEventListener(m,l),()=>window.removeEventListener(m,l)},[s,r,m,o]),t}function Ht(e){var b,y;let[t,n]=te(null),[i]=te(()=>{var c;return(c=e.sessionSegment)!=null?c:Ut()}),[s,r]=te(ye());V(()=>We(()=>r(ye())),[]);let m=Jt(e.consentFrom),o=e.consentFrom?e.consent===!0||m:e.consent,a=xe(null);V(()=>{var k;if(o===!1&&!e.preConsentBehavior){(k=a.current)==null||k.destroy(),a.current=null,n(null);return}let c=S({apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,sessionSegment:i,consent:o,preConsentBehavior:e.preConsentBehavior,respectDoNotTrack:e.respectDoNotTrack,ssrSessionId:e.ssrSessionId,country:e.country,persona:e.persona,localMode:e.localMode,initialSlots:e.initialSlots,initialSlotConfig:e.initialSlotConfig,initialPalette:e.initialPalette,initialPersona:e.initialPersona,ingestUrl:e.apiBaseUrl?`${e.apiBaseUrl.replace(/\/$/,"")}/events`:void 0},we?{sdk:we}:{}),u=!1,g=null,v=null,C=R=>{e.engagement!==!1&&import("@sentientui/core/engagement").then(({startEngagementCapture:x})=>{u||(v=x(R,{apiKey:e.apiKey,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:R})=>{u||(g=R(K(S({},c),{graph:!0,captureDomText:e.captureDomText===!0})),a.current=g,n(g),C(g))}):(g=Wt(c),a.current=g,n(g),C(g)),()=>{u=!0,v==null||v(),g==null||g.dispose()}},[o]),V(()=>{if(!t)return;let c=!1,u=async()=>{if(c)return;let v;try{v=await t.fetchWeights()}catch(C){return}if(!c)for(let C of v){let k={componentId:C.componentId,updatedAt:C.updatedAt,variants:C.variants.map(R=>{var x;return{variantId:R.variantId,pulls:R.pulls,avgReward:(x=R.avgReward)!=null?x:0}})};$e(C.componentId,k)}};u();let g=setInterval(()=>{u()},6e4);return()=>{c=!0,clearInterval(g)}},[t]);let l=(b=e.ssrFallback)!=null?b:"first",d=((y=e.apiBaseUrl)!=null?y:nt).replace(/\/$/,""),f=xe(null);V(()=>{var g;if(typeof process!="undefined"&&((g=process.env)==null?void 0:g.NODE_ENV)==="production")return;let c={apiKey:e.apiKey,context:e.context,country:e.country,persona:e.persona,apiBaseUrl:d},u=f.current;if(f.current=c,u!==null)for(let v of["apiKey","context","country","persona","apiBaseUrl"])Object.is(u[v],c[v])||console.warn(`[sentient] AdaptiveProvider: \`${v}\` changed after initialisation, but the SDK client is stable for the session and only re-inits on \`consent\` \u2014 the new value is ignored. Remount the provider (e.g. via a changing \`key\` prop) to apply it.`)},[e.apiKey,e.context,e.country,e.persona,d]),V(()=>{var c;typeof process!="undefined"&&((c=process.env)==null?void 0:c.NODE_ENV)==="production"||Xe({apiKey:e.apiKey,apiBaseUrl:d,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,d]),V(()=>{let c=e.initialLayoutOrder;if(c&&c.length>0){be(c);return}e.declaredSections&&e.declaredSections.length>0&&be(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]),V(()=>{if(!_())return;let c=e.declaredSections;if(!c||c.length===0||typeof document=="undefined")return;let u=new Set(Array.from(document.querySelectorAll("[data-sentient-id]"),v=>v.getAttribute("data-sentient-id"))),g=c.filter(v=>!u.has(v));g.length>0&&console.warn(`[SentientUI] Declared section${g.length>1?"s":""} ${g.map(v=>`"${v}"`).join(", ")} ${g.length>1?"have":"has"} no matching data-sentient-id element, so the layout engine cannot learn what they are and will serve the same order to every persona. Add data-sentient-id="<sectionId>" (plus optional data-sentient-type) to each section's element.`)},[e.declaredSections]);let p=tt(()=>t&&s?Ue(t):t,[t,s]),h=tt(()=>{var c,u,g,v,C,k,R;return{client:p,apiKey:e.apiKey,initialAssignments:(c=e.initialAssignments)!=null?c:{},sessionSegment:i,ssrFallback:l,onAssignment:e.onAssignment,initialLayoutOrder:(u=e.initialLayoutOrder)!=null?u:null,initialSlots:(g=e.initialSlots)!=null?g:{},initialSlotConfig:(v=e.initialSlotConfig)!=null?v:{},initialPalette:(C=e.initialPalette)!=null?C:null,initialPersona:(k=e.initialPersona)!=null?k:null,apiBaseUrl:d,debug:(R=e.debug)!=null?R:!1}},[p,e.apiKey,e.initialAssignments,i,l,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialSlotConfig,e.initialPalette,e.initialPersona,d,e.debug]);return qt(I.Provider,{value:h,children:e.children})}function G(){return L(I).client}function B(){return L(I).apiKey}function Ae(){return L(I).initialAssignments}function ne(){return L(I).sessionSegment}function rt(){return L(I).ssrFallback}function re(){return L(I).onAssignment}function it(){return L(I).debug}function Xt(){let e=L(I).initialLayoutOrder,t=$t(D,()=>{var n;return typeof window=="undefined"?null:(n=window.__sentient_layout_override)!=null?n:null},()=>null);return t!=null?t:e}function ie(){return L(I).initialSlots}function ot(){return L(I).initialPersona}function st(){return L(I).initialSlotConfig}function at(){return L(I).initialPalette}function zt(){return L(I).apiBaseUrl}import{memo as Yt,useEffect as W,useMemo as ut,useRef as se,useState as en}from"react";import{attachMicroSignalDetectors as tn}from"@sentientui/core";import{useEffect as oe,useRef as lt,useState as Zt,useSyncExternalStore as Qt}from"react";import{pickFromWeights as Ce}from"@sentientui/policy";function z(e){var n;if(typeof window=="undefined")return null;let t=(n=window.__sentient_overrides)==null?void 0:n[e];if(t)return t;if(!window.location.search)return null;try{let i=new URLSearchParams(window.location.search);for(let s of i.getAll("sentient_variant")){let r=s.indexOf(":");if(r!==-1&&s.slice(0,r)===e)return s.slice(r+1)}}catch(i){}return null}function Z(e,t,n,i){let s=Ae(),r=rt(),m=G(),o=ne(),a=re(),l=it(),d=lt(null),f=Qt(D,()=>z(e),()=>null),p=f&&t.includes(f)?f:null,h=lt(null);oe(()=>{l&&p&&h.current!==p&&(h.current=p,console.info(`[sentient] override active: ${e} -> ${p}`))},[l,p,e]);let[b,y]=Zt(()=>{var v,C;if(p)return{variantId:p,content:null,isLoading:!1,settled:!0};if(!m){let k=s[e];return k&&t.includes(k)?{variantId:k,content:null,isLoading:!1,settled:!0}:r==="first"&&t.length>0?{variantId:t[0],content:null,isLoading:!1,settled:!1}:{variantId:null,content:null,isLoading:!0,settled:!1}}let u=m.getAssignment(e,o);if(u&&(t.includes(u.variantId)||u.content))return{variantId:u.variantId,content:(v=u.content)!=null?v:null,isLoading:!1,settled:!0};let g=ve(e);if(g){let k=Ce(g.variants,t);if(k)return{variantId:k,content:null,isLoading:!1,settled:!0}}return{variantId:(C=t[0])!=null?C:null,content:null,isLoading:!1,settled:!1}}),c=u=>{a&&d.current!==u&&(d.current=u,a(e,u))};return oe(()=>{var v;if(p||!m)return;let u=m.getAssignment(e,o);if(u&&(t.includes(u.variantId)||u.content)){y({variantId:u.variantId,content:(v=u.content)!=null?v:null,isLoading:!1,settled:!0}),c(u.variantId);return}let g=ve(e);if(g&&b.settled&&b.variantId&&b.variantId===Ce(g.variants,t)){c(b.variantId);return}y(C=>{var k;return C.variantId?C:{variantId:(k=t[0])!=null?k:null,content:null,isLoading:!1,settled:!1}})},[p,m,e,o]),oe(()=>{if(p||!m)return;let u=m.getAssignment(e,o);if(u&&t.includes(u.variantId))return;let g=!1;return m.assign(e,t,n,i).then(v=>{var C;g||v&&(!t.includes(v.variantId)&&!v.content||(y({variantId:v.variantId,content:(C=v.content)!=null?C:null,isLoading:!1,settled:!0}),c(v.variantId)))}),()=>{g=!0}},[p,m,e,o]),oe(()=>{if(!p&&m)return Ne(e,u=>{var C;let g=m.getAssignment(e,o);if(g&&(t.includes(g.variantId)||g.content)){y({variantId:g.variantId,content:(C=g.content)!=null?C:null,isLoading:!1,settled:!0}),c(g.variantId);return}let v=Ce(u.variants,t);v&&(y({variantId:v,content:null,isLoading:!1,settled:!0}),c(v))})},[p,m,e,o]),p?{variantId:p,content:null,isLoading:!1,settled:!0,isOverride:!0}:b}import{jsx as on}from"react/jsx-runtime";function nn(e){var C;let t=G(),n=B(),i=Object.keys(e.variants).join("\0"),s=ut(()=>Object.keys(e.variants),[i]),{variantId:r,content:m,isOverride:o,settled:a}=Z(e.id,s,e.agentData,e.agentDataByVariant),l=se(null),[d,f]=en(!1);W(()=>{f(!0)},[]);let p=se(!1),h=se(new Set),b=se(null),y=typeof e.goal=="string"?e.goal:JSON.stringify(e.goal),c=ut(()=>P(e.goal),[y]),u=typeof e.goal=="string"?e.goal:c.type;if(W(()=>ee({id:e.id,variantIds:s,goal:u}),[e.id,s,u]),W(()=>{o||a&&(!t||!r||!n||b.current!==r&&(b.current=r,j(t,n,e.id,r)))},[t,r,n,e.id,o,a]),W(()=>{p.current=!1,h.current=new Set},[r,c]),W(()=>{o||!a||!t||!e.funnel||$(t,n,e.id,e.funnel,c)},[t,n,e.id,e.funnel,c,o,a]),W(()=>{if(o||!a||!t||!r)return;let k=l.current;if(!k)return;let R=null,x=0,A=()=>{x=Date.now(),R=setTimeout(()=>{t.track({projectId:n,componentId:e.id,variantId:r,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-x}}),R=null},800)},w=()=>{R!==null&&(clearTimeout(R),R=null)};return k.addEventListener("mouseenter",A),k.addEventListener("mouseleave",w),()=>{k.removeEventListener("mouseenter",A),k.removeEventListener("mouseleave",w),R!==null&&clearTimeout(R)}},[t,r,n,e.id,o,a]),W(()=>{if(o||!a||!t||!r)return;let k=l.current;if(!k)return;let R=Date.now();return tn((x,A={})=>{var Le,De,Te;t.track({projectId:n,componentId:e.id,variantId:r,eventType:"micro_signal",payload:S({signalType:x},A)});let w=(Le=e.microSignalGoals)==null?void 0:Le[x];if(!w||h.current.has(x))return;h.current.add(x);let E=typeof w=="string"?w:w.name,M=typeof w=="string"?1:(De=w.weight)!=null?De:1,H=typeof w=="string"?0:(Te=w.stepIndex)!=null?Te:0;t.goal(E,{metadata:S({signalType:x},A),weight:M,stepIndex:H})},k,R)},[t,r,n,e.id,e.microSignalGoals,o,a]),W(()=>{if(o||!a||!t||!r)return;let k=l.current;if(!k)return;let R=T(c);return F(k,c,{fireGoal:()=>{p.current||(p.current=!0,t.track({projectId:n,componentId:e.id,variantId:r,eventType:"goal_achieved",goalType:u,payload:S({reward:1},R!==void 0?{goalValue:R}:{})}),t.goal(u,S({metadata:{componentId:e.id,variantId:r},weight:1,stepIndex:0},R!==void 0?{value:R}:{})))},fireStep:(x,A,w)=>{t.track({projectId:n,componentId:e.id,variantId:r,eventType:"goal_achieved",goalType:x,payload:{reward:A}}),t.goal(x,{metadata:{},weight:A,stepIndex:w})}},u)},[t,r,n,e.id,c,u,o,a]),e.clientOnly&&(!d||!t)||!r)return null;let g=(C=e.variants[r])!=null?C:null,v=g===null?m:null;return _()&&g===null&&v===null&&console.warn(`[sentient] <Adaptive id="${e.id}"> was assigned variant "${r}" but no matching key exists in props.variants. If this is a dashboard-managed text variant, use <AdaptiveText id="${e.id}"> instead.`),on("div",{ref:l,"data-sentient-id":e.id,"data-sentient-variant":r,children:g!=null?g:v})}var rn=Yt(nn,(e,t)=>{if(e.id!==t.id||e.goal!==t.goal&&JSON.stringify(e.goal)!==JSON.stringify(t.goal)||e.microSignalGoals!==t.microSignalGoals||e.funnel!==t.funnel||e.clientOnly!==t.clientOnly||e.agentData!==t.agentData||e.agentDataByVariant!==t.agentDataByVariant)return!1;if(e.variants===t.variants)return!0;let n=Object.keys(e.variants),i=Object.keys(t.variants);return n.length!==i.length?!1:n.every(s=>s in t.variants&&Object.is(e.variants[s],t.variants[s]))});import{useEffect as ae,useMemo as sn,useRef as ke,useState as ct,useSyncExternalStore as an}from"react";import{jsx as un}from"react/jsx-runtime";function ln({id:e,default:t,component:n="span",className:i,goal:s}){var R;let r=G(),m=B(),o=re(),a=ne(),l=ke(null),d=ke(null),f=an(D,()=>z(e),()=>null),[p,h]=ct(()=>{var x,A;return(A=(x=r==null?void 0:r.getAssignment(e,a))==null?void 0:x.content)!=null?A:null}),[b,y]=ct(()=>{var x,A;return(A=(x=r==null?void 0:r.getAssignment(e,a))==null?void 0:x.variantId)!=null?A:null});ae(()=>{if(f||!r)return;let x=r.getAssignment(e,a);if((x==null?void 0:x.content)!==void 0){y(x.variantId),h(x.content);return}let A=!1;return r.assign(e).then(w=>{if(!A){if(!w){_()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}y(w.variantId),w.content&&h(w.content)}}),()=>{A=!0}},[r,e,a,f]),ae(()=>{f||!r||!b||!m||l.current!==b&&(l.current=b,r.track({projectId:m,componentId:e,variantId:b,eventType:"variant_assigned",payload:{}}),o==null||o(e,b))},[r,b,m,e,o,f]);let c=s===void 0?"":typeof s=="string"?s:JSON.stringify(s),u=sn(()=>s===void 0?null:P(s),[c]),g=s===void 0?null:typeof s=="string"?s:u.type,v=ke(!1);ae(()=>{v.current=!1},[b,c]),ae(()=>{if(f||!r||!b||!m||!u||!g)return;let x=d.current;if(!x)return;let A=T(u);return F(x,u,{fireGoal:()=>{v.current||(v.current=!0,r.track({projectId:m,componentId:e,variantId:b,eventType:"goal_achieved",goalType:g,payload:S({reward:1},A!==void 0?{goalValue:A}:{})}),r.goal(g,S({metadata:{componentId:e,variantId:b},weight:1,stepIndex:0},A!==void 0?{value:A}:{})))},fireStep:(w,E,M)=>{r.track({projectId:m,componentId:e,variantId:b,eventType:"goal_achieved",goalType:w,payload:{reward:E}}),r.goal(w,{metadata:{},weight:E,stepIndex:M})}})},[r,b,m,e,u,g,f]);let C=p!=null?p:t;if(f){let x=r==null?void 0:r.getAssignment(e,a);C=x&&x.variantId===f&&(R=x.content)!=null?R:t}return un(n,{ref:x=>{d.current=x},className:i,children:C})}import{useCallback as cn,useRef as dn}from"react";function Re(e){let t=G(),n=dn(new Set);return cn((i,s)=>{var r,m;if(!z(e)){if(s!=null&&s.once){if(n.current.has(i))return;n.current.add(i)}t==null||t.componentGoal(e,i,s),t==null||t.goal(i,S(S(S({metadata:(r=s==null?void 0:s.metadata)!=null?r:{},weight:(m=s==null?void 0:s.reward)!=null?m:1,stepIndex:0},(s==null?void 0:s.value)!==void 0?{value:s.value}:{}),(s==null?void 0:s.currency)!==void 0?{currency:s.currency}:{}),(s==null?void 0:s.externalId)!==void 0?{externalId:s.externalId}:{}))}},[t,e])}import{useEffect as fn,useRef as dt}from"react";function gn(e,t={}){let a=t,{componentId:n}=a,i=Ke(a,["componentId"]),s=G(),r=Re(n!=null?n:""),m=dt(!1),o=dt(i);o.current=i,fn(()=>{if(!s||m.current)return;m.current=!0;let{metadata:l,reward:d,value:f,currency:p,externalId:h}=o.current;if(n){r(e,o.current);return}s.goal(e,S(S(S({metadata:l!=null?l:{},weight:d!=null?d:1,stepIndex:0},f!==void 0?{value:f}:{}),p!==void 0?{currency:p}:{}),h!==void 0?{externalId:h}:{}))},[s,n,e,r])}import{renderPrePaintScript as mn}from"@sentientui/core";import{confidenceBand as pn}from"@sentientui/policy";import{jsx as Sn}from"react/jsx-runtime";function ft(e){return JSON.stringify(e).replace(/</g,"\\u003c")}function vn(e){return e.persona?'(function(){try{var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",'+ft(e.persona.persona)+');d.setAttribute("data-sentient-confidence",'+ft(pn(e.persona.confidence))+");}catch(e){}})();":mn(e.apiKey)}function yn(e){return Sn("script",{"data-sentient-persona-script":"",nonce:e.nonce,dangerouslySetInnerHTML:{__html:vn(e)}})}import{useEffect as ce,useMemo as Ge,useRef as kn}from"react";import{validateSlotDecl as Rn}from"@sentientui/policy";import{useEffect as _e,useReducer as hn,useState as bn,useSyncExternalStore as mt}from"react";import{armOfResult as le,baselineResultFor as wn}from"@sentientui/core";import{confidenceBand as xn}from"@sentientui/policy";var gt=new Set;function ue(e,t){let n=G(),i=ie(),[,s]=hn(d=>d+1,0),r=mt(D,()=>{var d;return typeof window!="undefined"?(d=window.__sentient_slot_overrides)==null?void 0:d[e]:void 0},()=>{}),m=r===void 0?i[e]:void 0,o=r===void 0&&m===void 0&&n?n.getSlotResult(e):null,a=(n==null?void 0:n.isLocal)===!0&&r===void 0&&m===void 0&&o===null;_e(()=>{if(!a||!n)return;let d=!1;return n.decide({slots:[t]}).then(f=>{!d&&f&&s()}),()=>{d=!0}},[n,e,a]);let l=(()=>{if(r!==void 0)return{result:r,arm:le(r),source:"override"};if(m!==void 0)return{result:m,arm:le(m),source:"preloaded"};if(o!==null)return{result:o,arm:le(o),source:"client"};let d=wn(t);return{result:d,arm:le(d),source:"baseline"}})();return _e(()=>{_()&&(!n||n.isLocal===!0||l.source==="baseline"&&(gt.has(e)||(gt.add(e),console.warn(`[sentient] slot "${e}" resolved to its baseline \u2014 no SSR-preloaded or decided result. Keyed clients decide slots server-side, so this slot serves baseline for the whole session and records no exposure. Preload it via loadAdaptiveDecision()/initialSlots so it can serve a decided arm and learn.`))))},[n,l.source,e]),l}function An(){var t;if(typeof window=="undefined")return null;let e=window.__sentient_persona_override;if(e!=null&&e.persona)return{persona:e.persona,confidence:(t=e.confidence)!=null?t:1};try{let n=new URLSearchParams(window.location.search).get("sentient_persona");if(n)return{persona:n,confidence:1}}catch(n){}return null}function Cn(){let e=G(),t=ot();mt(D,He,()=>0);let[n,i]=bn(!1);_e(()=>i(!0),[]);let s=o=>({persona:o.persona,confidence:o.confidence,band:xn(o.confidence)});if(!n)return t?s(t):null;let r=An();if(r)return s(r);if(t)return s(t);let m=e?e.getPersona():null;return m?s(m):null}var pt=new Set;function _n(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/[\\"]/g,"\\$&")}function Gn(e,t,n){let i=G(),s=B(),r=JSON.stringify(t),m=Ge(()=>({id:e,dims:t}),[e,r]),{result:o,arm:a,source:l}=ue(e,m),d=Ge(()=>typeof o=="string"?{}:o,[a]);if(_()&&!pt.has(e)){pt.add(e);let y=Rn({id:e,dims:Object.fromEntries(Object.entries(t).map(([u,g])=>[u,[...g]]))}),c=Object.values(t).reduce((u,g)=>u*g.length,1);y.ok?c>4&&console.warn(`[sentient] useAdaptiveTokens("${e}") declares ${c} combinations \u2014 more than the recommended 4. Each extra combination needs more traffic to learn; consider fewer dims/values.`):console.warn(`[sentient] useAdaptiveTokens("${e}"): invalid declaration \u2014 ${y.reason}. Serving baseline.`)}let f=(n==null?void 0:n.goal)===void 0?null:typeof n.goal=="string"?n.goal:JSON.stringify(n.goal);ce(()=>X({id:e,dims:t}),[e]);let p=kn(null);ce(()=>{!i||l==="baseline"||l==="override"||p.current===a||(p.current=a,j(i,s,e,a))},[i,s,e,a,l]);let h=n==null?void 0:n.funnel;ce(()=>{var y;!i||!h||l==="override"||$(i,s,e,h,P((y=n==null?void 0:n.goal)!=null?y:"click"))},[i,s,e,h,f,l]),ce(()=>{if(!i||!(n!=null&&n.goal)||l==="override"||l==="baseline")return;let y=document.querySelector(`[data-sentient-slot="${_n(e)}"]`);if(!y){_()&&console.warn(`[sentient] useAdaptiveTokens("${e}"): a goal is declared but no element carries the returned props \u2014 spread {...props} on the slot's element.`);return}let c=N(n.goal),u=T(n.goal),g=!1;return F(y,P(n.goal),{fireGoal:()=>{g||(g=!0,u!==void 0?i.componentGoal(e,c,{value:u}):i.componentGoal(e,c),i.goal(c,S({metadata:{componentId:e,arm:a},weight:1,stepIndex:0},u!==void 0?{value:u}:{})))},fireStep:(v,C,k)=>{i.componentGoal(e,v,{reward:C}),i.goal(v,{metadata:{componentId:e,arm:a},weight:C,stepIndex:k})}},c)},[i,e,f,a,l]);let b=Ge(()=>{let y={"data-sentient-slot":e};for(let[c,u]of Object.entries(d))y[`data-${c}`]=u;return y},[e,d]);return{tokens:d,props:b}}import{useEffect as ge,useMemo as Tn,useRef as Rt}from"react";import{containsFormBlock as Fn}from"@sentientui/core";import{useEffect as Oe,useReducer as On,useSyncExternalStore as vt}from"react";import{armOfResult as En}from"@sentientui/core";var yt=new Set;function St(e){var b;let t=G(),n=ie(),i=st(),s=at(),[,r]=On(y=>y+1,0),m=vt(D,()=>{var y;return typeof window!="undefined"?(y=window.__sentient_slot_config_overrides)==null?void 0:y[e]:void 0},()=>{}),o=vt(D,()=>{var y;return typeof window!="undefined"?(y=window.__sentient_slot_overrides)==null?void 0:y[e]:void 0},()=>{}),a=m===void 0?i[e]:void 0,l=m===void 0&&a===void 0&&t?t.getSlotConfig(e):null,d=y=>y==null?"":En(y),f=(b=s!=null?s:t==null?void 0:t.getSitePalette())!=null?b:null,p=(t==null?void 0:t.isLocal)===!0&&m===void 0&&a===void 0&&l===null;Oe(()=>{if(!p||!t)return;let y=!1;return t.decide({slotsFrom:"registry"}).then(c=>{!y&&c&&r()}),()=>{y=!0}},[t,e,p]);let h=(()=>{var y,c;return m!==void 0?{config:m,arm:d(o),palette:f,source:"override"}:a!==void 0?{config:a,arm:d((y=n[e])!=null?y:t==null?void 0:t.getSlotResult(e)),palette:f,source:"preloaded"}:l!==null?{config:l,arm:d((c=t==null?void 0:t.getSlotResult(e))!=null?c:n[e]),palette:f,source:"client"}:{config:null,arm:"",palette:f,source:"none"}})();return Oe(()=>{!t||t.isLocal===!0||h.source!=="none"||t.reportSlots([e])},[t,h.source,e]),Oe(()=>{_()&&(!t||t.isLocal===!0||h.source==="none"&&(yt.has(e)||(yt.add(e),console.warn(`[sentient] AdaptiveSlot "${e}" has no server config \u2014 rendering its baseline children. Preload it via loadAdaptiveDecision({ slotsFrom: 'registry' }) and pass initialSlotConfig/initialSlots to <AdaptiveProvider> so it can serve a decided arm and learn.`))))},[t,h.source,e]),h}import{Fragment as ht}from"react";import{jsx as O,jsxs as At}from"react/jsx-runtime";var de={none:"0",sm:"8px",md:"16px",lg:"24px"},Ee={start:"flex-start",center:"center",end:"flex-end",stretch:"stretch",between:"space-between"},Ct={sm:"0.875em",md:"1em",lg:"1.25em"},Pn={sm:"1.25em",md:"1.5em",lg:"2em"},bt={sm:"6px 14px",md:"10px 20px",lg:"14px 28px"},wt={sm:"8px",md:"16px",lg:"32px"},In={square:"1 / 1",landscape:"4 / 3",wide:"16 / 9"},Ln={normal:"400",medium:"500",bold:"700"};function xt(e){return S(S({},e==="muted"?{opacity:.7}:{}),e==="accent"?{fontWeight:600}:{})}function kt(e,t,n){var i,s,r,m;return K(S({display:"inline-block",padding:(i=bt[n!=null?n:"md"])!=null?i:bt.md,borderRadius:(s=t==null?void 0:t.radius)!=null?s:"8px",font:"inherit"},n?{fontSize:Ct[n]}:{}),{textDecoration:e==="ghost"?"underline":"none",cursor:"pointer",background:e==="primary"?(r=t==null?void 0:t.primaryBg)!=null?r:"#111827":"transparent",color:e==="primary"?(m=t==null?void 0:t.primaryText)!=null?m:"#ffffff":"inherit",border:e==="secondary"?"1px solid currentColor":"none"})}function Dn({node:e,opts:t}){var s,r,m;let n=(s=e.emphasis)!=null?s:"primary",i={padding:"8px 10px",font:"inherit",border:"1px solid currentColor",borderRadius:(m=(r=t.palette)==null?void 0:r.radius)!=null?m:"8px"};return At("form",{onSubmit:o=>{var d,f,p;o.preventDefault();let a=new FormData(o.currentTarget),l={};for(let h of e.fields)l[h.name]=String((d=a.get(h.name))!=null?d:"");(f=t.onFormGoal)==null||f.call(t,e.submitGoal);try{(p=t.onFormSubmit)==null||p.call(t,l)}catch(h){}},style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e.fields.map(o=>{var a,l;return At("label",{style:{display:"flex",flexDirection:"column",gap:"4px",font:"inherit"},children:[o.label,o.kind==="textarea"?O("textarea",{name:o.name,required:o.required,placeholder:o.placeholder,rows:3,style:i}):o.kind==="select"?O("select",{name:o.name,required:o.required,style:i,children:((a=o.options)!=null?a:[]).map(d=>O("option",{value:d,children:d},d))}):O("input",{name:o.name,type:(l=o.inputType)!=null?l:"text",required:o.required,placeholder:o.placeholder,style:i})]},o.name)}),O("button",{type:"submit",style:kt(n,t.palette),children:e.submitLabel})]})}function fe(e,t){var n,i,s,r,m,o,a,l,d;try{switch(e.type){case"stack":{let f=(i=de[(n=e.gap)!=null?n:"md"])!=null?i:de.md;return O("div",{style:S(S(S({display:"flex",flexDirection:e.direction,gap:f},e.align?{alignItems:Ee[e.align]}:{}),e.justify?{justifyContent:Ee[e.justify]}:{}),e.wrap?{flexWrap:"wrap"}:{}),children:((s=e.children)!=null?s:[]).map((p,h)=>{let b=fe(p,t);return b===null?null:O(ht,{children:b},h)})})}case"grid":{let f=(m=de[(r=e.gap)!=null?r:"md"])!=null?m:de.md;return O("div",{style:S({display:"grid",gridTemplateColumns:`repeat(auto-fit, minmax(max(200px, calc((100% - ${e.columns-1} * ${f}) / ${e.columns})), 1fr))`,gap:f},e.align?{alignItems:Ee[e.align]}:{}),children:((o=e.children)!=null?o:[]).map((p,h)=>{let b=fe(p,t);return b===null?null:O(ht,{children:b},h)})})}case"text":return O("p",{style:S(S(S(S({margin:0},e.size?{fontSize:Ct[e.size]}:{}),e.weight?{fontWeight:Ln[e.weight]}:{}),e.align?{textAlign:e.align}:{}),xt(e.tone)),children:e.value});case"heading":{let f=`h${e.level}`;return O(f,{style:S({margin:0,fontSize:Pn[(a=e.size)!=null?a:"md"]},e.align?{textAlign:e.align}:{}),children:e.value})}case"button":{let f=(l=e.emphasis)!=null?l:"primary";return O("a",K(S({href:e.href},e.tag?{"data-sentient-tag":e.tag}:{}),{style:kt(f,t.palette,e.size),children:e.label}))}case"link":return O("a",K(S({href:e.href},e.tag?{"data-sentient-tag":e.tag}:{}),{style:{color:"inherit",textDecoration:"underline"},children:e.label}));case"image":return O("img",{src:e.src,alt:e.alt,style:S(S({display:"block",maxWidth:"100%"},e.ratio&&e.ratio!=="auto"?{aspectRatio:In[e.ratio],width:"100%"}:{}),e.fit?{objectFit:e.fit}:{})});case"badge":return O("span",{style:S({display:"inline-block",padding:"2px 10px",borderRadius:"999px",fontSize:"0.75em",border:"1px solid currentColor"},xt(e.tone)),children:e.value});case"spacer":return O("div",{style:{height:(d=wt[e.size])!=null?d:wt.md}});case"form":return O(Dn,{node:e,opts:t});default:return null}}catch(f){return null}}import{jsx as Mn}from"react/jsx-runtime";var _t=new Set;function Bn({id:e,children:t,onFormSubmit:n,goal:i,className:s}){var C,k;let r=G(),m=B(),{config:o,arm:a,palette:l,source:d}=St(e),f=Rt(null),p=a!==""?(C=o==null?void 0:o.blocks)==null?void 0:C[a]:void 0,h=p!==void 0&&Fn(p)&&!n;ge(()=>{!h||!_()||_t.has(e)||(_t.add(e),console.warn(`[sentient] AdaptiveSlot "${e}" was served a form arm but has no onFormSubmit handler \u2014 rendering its baseline children instead. Pass onFormSubmit to render generated forms.`))},[h,e]);let b=R=>{!r||d==="override"||(r.componentGoal(e,R),r.goal(R,{metadata:{componentId:e,arm:a},weight:1,stepIndex:0}))},y=t;p!==void 0&&!h?y=(k=fe(p,{palette:l,onFormSubmit:n,onFormGoal:b}))!=null?k:t:(o==null?void 0:o.content)!==void 0&&d!=="none"&&(y=o.content);let c=o!=null&&o.blocks?Object.keys(o.blocks).sort().join("|"):"";ge(()=>X({id:e,arms:c===""?void 0:c.split("|")}),[e,c]);let u=Rt(null);ge(()=>{!r||d==="none"||d==="override"||a===""||u.current===a||(u.current=a,j(r,m,e,a))},[r,m,e,a,d]);let g=i===void 0?null:typeof i=="string"?i:JSON.stringify(i);ge(()=>{if(!r||!i||d==="override"||d==="none")return;let R=f.current;if(!R)return;let x=N(i),A=T(i),w=!1;return F(R,P(i),{fireGoal:()=>{w||(w=!0,A!==void 0?r.componentGoal(e,x,{value:A}):r.componentGoal(e,x),r.goal(x,S({metadata:{componentId:e,arm:a},weight:1,stepIndex:0},A!==void 0?{value:A}:{})))},fireStep:(E,M,H)=>{r.componentGoal(e,E,{reward:M}),r.goal(E,{metadata:{componentId:e,arm:a},weight:M,stepIndex:H})}},x)},[r,e,g,a,d]);let v=Tn(()=>S({"data-sentient-slot":e},a!==""?{"data-sentient-arm":a}:{}),[e,a]);return Mn("div",K(S({ref:f,className:s},v),{children:y}))}import{useCallback as Gt,useEffect as J,useMemo as Pe,useRef as Ie,useState as Kn}from"react";import{attachMicroSignalDetectors as jn}from"@sentientui/core";var Ot=new Set;function Nn(e,t){var x;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=G(),i=B(),s=Object.keys(t.variants).join(" "),r=Pe(()=>Object.keys(t.variants),[s]),{variantId:m,isOverride:o,settled:a}=Z(e,r),l=(x=m!=null?m:r[0])!=null?x:"",d=t.variants[l],[f,p]=Kn(null),h=Ie(null),b=Gt(A=>{h.current=A,p(A)},[]),y=typeof t.goal=="string"?t.goal:JSON.stringify(t.goal),c=Pe(()=>t.goal?P(t.goal):null,[y]),u=t.goal?N(t.goal):"";J(()=>ee({id:e,variantIds:r,goal:u}),[e,r,u]);let g=Ie(null);J(()=>{o||a&&(!n||!l||!f||g.current!==l&&(g.current=l,j(n,i,e,l)))},[n,i,e,l,f,o,a]);let v=t.funnel;J(()=>{o||!a||!n||!v||!c||$(n,i,e,v,c)},[n,i,e,v,c,o,a]);let C=Ie(!1);J(()=>{C.current=!1},[l,y]),J(()=>{if(o||!a||!n||!l||!f||!c)return;let A=T(c);return F(f,c,{fireGoal:()=>{C.current||(C.current=!0,n.track({projectId:i,componentId:e,variantId:l,eventType:"goal_achieved",goalType:u,payload:S({reward:1},A!==void 0?{goalValue:A}:{})}),n.goal(u,S({metadata:{componentId:e,variantId:l},weight:1,stepIndex:0},A!==void 0?{value:A}:{})))},fireStep:(w,E,M)=>{n.track({projectId:i,componentId:e,variantId:l,eventType:"goal_achieved",goalType:w,payload:{reward:E}}),n.goal(w,{metadata:{},weight:E,stepIndex:M})}},u)},[n,f,l,i,e,c,u,o,a]),J(()=>{if(o||!n||!l||!f)return;let A=Date.now();return jn((w,E={})=>{n.track({projectId:i,componentId:e,variantId:l,eventType:"micro_signal",payload:S({signalType:w},E)})},f,A)},[n,f,l,i,e,o]),J(()=>{if(!_()||!n)return;let A=setTimeout(()=>{!h.current&&!Ot.has(e)&&(Ot.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(A)},[n,e]);let k=Gt((A,w)=>{var M,H;if(o)return;let E=A!=null?A:u;E&&(n==null||n.componentGoal(e,E,w),n==null||n.goal(E,S(S(S({metadata:(M=w==null?void 0:w.metadata)!=null?M:{},weight:(H=w==null?void 0:w.reward)!=null?H:1,stepIndex:0},(w==null?void 0:w.value)!==void 0?{value:w.value}:{}),(w==null?void 0:w.currency)!==void 0?{currency:w.currency}:{}),(w==null?void 0:w.externalId)!==void 0?{externalId:w.externalId}:{})))},[n,e,u,o]),R=Pe(()=>({ref:b,"data-sentient-id":e,"data-sentient-variant":l}),[b,e,l]);return{variant:l,value:d,bind:R,fireGoal:k}}import{Children as $n,isValidElement as Vn,useEffect as me,useMemo as Et,useRef as Pt}from"react";import{jsx as Un}from"react/jsx-runtime";var pe=new Set;function Wn(e){var u;let t=G(),n=B(),i=Pt(null),s=Object.keys(e.arrangements).join(" "),r=Et(()=>Object.keys(e.arrangements),[s]),m=Et(()=>S({id:e.id,arms:r},e.baseline!==void 0?{baseline:e.baseline}:{}),[e.id,r,e.baseline]),{arm:o,source:a}=ue(e.id,m);_()&&e.baseline!==void 0&&e.baseline!==r[0]&&!pe.has(e.id+":baseline")&&(pe.add(e.id+":baseline"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: baseline "${e.baseline}" is not the first-declared arrangement ("${r[0]}"). The first arrangement should usually be the page's real incumbent (the holdout sees it).`));let l=$n.toArray(e.children).filter(Vn),d=new Map;for(let g of l)d.set(String((u=g.key)!=null?u:"").replace(/^\.\$/,""),g);let f=e.arrangements[o],p=f!==void 0&&f.length===l.length&&f.every(g=>d.has(g));_()&&f!==void 0&&!p&&!pe.has(e.id+":keys")&&(pe.add(e.id+":keys"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: arrangement "${o}" [${f.join(", ")}] does not match the children's keys \u2014 rendering declaration order (fail-safe).`));let h=p?f.map(g=>d.get(g)):l;me(()=>X({id:e.id,arms:Object.keys(e.arrangements)}),[e.id]);let b=Pt(null);me(()=>{!t||a==="baseline"||a==="override"||b.current===o||(b.current=o,j(t,n,e.id,o))},[t,n,e.id,o,a]);let y=e.funnel;me(()=>{var g;!t||!y||a==="override"||$(t,n,e.id,y,P((g=e.goal)!=null?g:"click"))},[t,n,e.id,y,a]);let c=e.goal===void 0?null:typeof e.goal=="string"?e.goal:JSON.stringify(e.goal);return me(()=>{if(!t||e.goal===void 0||a==="override"||a==="baseline")return;let g=i.current;if(!g)return;let v=N(e.goal),C=T(e.goal),k=!1;return F(g,P(e.goal),{fireGoal:()=>{k||(k=!0,C!==void 0?t.componentGoal(e.id,v,{value:C}):t.componentGoal(e.id,v),t.goal(v,S({metadata:{componentId:e.id,arm:o},weight:1,stepIndex:0},C!==void 0?{value:C}:{})))},fireStep:(R,x,A)=>{t.componentGoal(e.id,R,{reward:x}),t.goal(R,{metadata:{componentId:e.id,arm:o},weight:x,stepIndex:A})}},v)},[t,e.id,c,o,a]),Un("div",{ref:i,"data-sentient-id":e.id,"data-sentient-variant":o,children:h})}import{deriveSessionSegment as Jn}from"@sentientui/core";var Hn=["page","blocks","layoutOrder"],It=new Map;function Xn(e,t){It.set(e,t)}function Lt(e){return It.get(e)}function zn(e){var s,r;let t=(r=(s=e.content)!=null?s:Lt(e.page))!=null?r:{},n={};for(let[m,o]of Object.entries(t))Hn.includes(m)||(n[m]=o);let i=K(S({},n),{page:e.page,blocks:e.blocks});return e.layoutOrder&&(i.layoutOrder=e.layoutOrder),i}function qn(e){return`<script type="application/ld+json">${Dt(e)}</script>`}function Dt(e){return JSON.stringify(S({"@context":"https://schema.org","@type":"WebPage"},e)).replace(/</g,"\\u003c")}function Zn(e){let t=[];e.title&&t.push(`# ${e.title}`,""),e.summary&&t.push(String(e.summary),"");for(let[n,i]of Object.entries(e))["page","title","summary","blocks","layoutOrder"].includes(n)||t.push(`## ${n}`,"","```json",JSON.stringify(i,null,2),"```","");if(e.blocks.length>0){t.push("## blocks","");for(let n of e.blocks)t.push(`- **${n.id}** \u2192 variant \`${n.variant}\``),n.content!==void 0&&t.push(""," ```json",JSON.stringify(n.content,null,2)," ```");t.push("")}return t.join(`
|
|
3
3
|
`).trimEnd()+`
|
|
4
|
-
`}import{grantConsent as
|
|
4
|
+
`}import{grantConsent as xo}from"@sentientui/core";export{rn as Adaptive,Wn as AdaptiveGroup,Ht as AdaptiveProvider,Bn as AdaptiveSlot,ln as AdaptiveText,yn as SentientPersonaScript,zn as buildAgentFeed,Xn as defineAgentContent,Jn as detectSegment,Lt as getAgentContent,xo as grantConsent,qn as renderAgentJsonLd,Dt as renderAgentJsonLdBody,Zn as renderAgentMarkdown,Nn as useAdaptive,zt as useAdaptiveApiBaseUrl,Re as useAdaptiveGoal,Cn as useAdaptivePersona,Gn as useAdaptiveTokens,Z as useAssignment,Ae as useInitialAssignments,Xt as useLayoutOrder,gn as usePageGoal,G as useSentient};
|
|
5
5
|
//# sourceMappingURL=index.mjs.map
|