@sentientui/react 0.25.1 → 0.26.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -188,7 +188,7 @@ Imported from `@sentientui/react/next`.
188
188
  | Prop | Type | Description |
189
189
  |------|------|-------------|
190
190
  | `components` | `Array<{ id: string; variantIds: string[] }>` *(optional, default `[]`)* | Components to preload server-side. `id` must match `<Adaptive id="…">`. Omit when the tree uses only slots/sections or assigns client-side. |
191
- | `sections` | `string[]` *(optional)* | Page section IDs in default order. When provided, a single `POST /v1/decide` returns both layout order and assignments; `useLayoutOrder()` becomes available. |
191
+ | `sections` | `string[]` *(optional)* | Page section IDs in default order. When provided, a single `POST /v1/decide` returns both layout order and assignments; `useLayoutOrder()` becomes available. Give each section's element `data-sentient-id="<sectionId>"` (optionally an explicit `data-sentient-type`) so the graph scanner can register it — without it the server types the section `generic` and every persona gets the same order. The provider warns about unresolvable ids in development. |
192
192
  | `apiKey` | `string` | `pk_…` key — used by both the browser SDK and server-side SSR requests. |
193
193
  | `appOrigin` | `string` *(default `http://localhost:3001`)* | Your app origin (e.g. `https://yourapp.com`). Must be on the project's allowed-origins list. Always set in production. |
194
194
  | `context` | `'landing' \| 'ecommerce' \| 'saas' \| 'marketplace'` | Type of product. Used for segment weighting and analytics grouping. |
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- "use strict";var Et=Object.create;var Y=Object.defineProperty,It=Object.defineProperties,Lt=Object.getOwnPropertyDescriptor,Pt=Object.getOwnPropertyDescriptors,Tt=Object.getOwnPropertyNames,ne=Object.getOwnPropertySymbols,Dt=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty,Oe=Object.prototype.propertyIsEnumerable;var Re=(e,t,n)=>t in e?Y(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,G=(e,t)=>{for(var n in t||(t={}))ve.call(t,n)&&Re(e,n,t[n]);if(ne)for(var n of ne(t))Oe.call(t,n)&&Re(e,n,t[n]);return e},re=(e,t)=>It(e,Pt(t));var Ee=(e,t)=>{var n={};for(var r in e)ve.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&ne)for(var r of ne(e))t.indexOf(r)<0&&Oe.call(e,r)&&(n[r]=e[r]);return n};var Ft=(e,t)=>{for(var n in t)Y(e,n,{get:t[n],enumerable:!0})},Ie=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Tt(t))!ve.call(e,i)&&i!==n&&Y(e,i,{get:()=>t[i],enumerable:!(r=Lt(t,i))||r.enumerable});return e};var Le=(e,t,n)=>(n=e!=null?Et(Dt(e)):{},Ie(t||!e||!e.__esModule?Y(n,"default",{value:e,enumerable:!0}):n,e)),Mt=e=>Ie(Y({},"__esModule",{value:!0}),e);var zt={};Ft(zt,{Adaptive:()=>rt,AdaptiveGroup:()=>xt,AdaptiveProvider:()=>ze,AdaptiveText:()=>ot,SentientPersonaScript:()=>dt,buildAgentFeed:()=>Gt,defineAgentContent:()=>Ct,detectSegment:()=>xe.deriveSessionSegment,getAgentContent:()=>Ae,grantConsent:()=>Ot.grantConsent,renderAgentJsonLd:()=>_t,renderAgentJsonLdBody:()=>ke,renderAgentMarkdown:()=>Rt,useAdaptive:()=>wt,useAdaptiveApiBaseUrl:()=>et,useAdaptiveGoal:()=>ge,useAdaptivePersona:()=>pt,useAdaptiveTokens:()=>St,useAssignment:()=>Q,useInitialAssignments:()=>le,useLayoutOrder:()=>Qe,usePageGoal:()=>at,useSentient:()=>R});module.exports=Mt(zt);var A=require("react"),ae=require("@sentientui/core");var Pe=new Map,ie=new Map;function Te(e,t){let n=ie.get(e);return n||(n=new Set,ie.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&ie.delete(e)}}function De(e,t){Pe.set(e,t);let n=ie.get(e);if(n)for(let r of n)try{r(t)}catch(i){}}function ye(e){var t;return(t=Pe.get(e))!=null?t:null}var Bt={on:!1,listeners:new Set};function Fe(){if(typeof window=="undefined")return Bt;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function Se(){return Fe().on}function Me(e){let t=Fe().listeners;return t.add(e),()=>{t.delete(e)}}function Be(e){return{isLocal:e.isLocal,track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},fetchWeights:()=>Promise.resolve([]),getAssignment:(t,n)=>e.getAssignment(t,n),assign:(t,n,r,i)=>e.assign(t,n,r,i),decide:()=>Promise.resolve(null),getSlotResult:t=>e.getSlotResult(t),getPersona:()=>e.getPersona(),getGraph:()=>e.getGraph(),dispose:()=>e.dispose(),destroy:()=>e.destroy()}}var Ke="sentient:overrides-changed";function je(){var e;return typeof window=="undefined"?0:(e=window.__sentient_overrides_version)!=null?e:0}function W(e){return typeof window=="undefined"?()=>{}:(window.addEventListener(Ke,e),()=>window.removeEventListener(Ke,e))}function Ve(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function I(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}function D(e){return typeof e=="string"?{type:"click"}:e}function X(e){return typeof e=="string"?e:e.type}function j(e){if(typeof e!="string"&&(e.type==="click"||e.type==="form_submit"||e.type==="scroll_depth"))return e.value}var he=new Set,be=!1;function $e(e){if(he.has(e))return!0;if(he.add(e),!be){be=!0;let t=()=>{be=!1,he.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 We(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 r=e;for(;r&&r!==t;){if(Kt(r))return!0;r=r.parentElement}return!1}function V(e,t,n,r){if(t.type==="weighted_composite"){let u=new Set,m=[];return t.steps.forEach(({goal:g,name:p,weight:C},w)=>{let x=(c=!1)=>{u.has(w)||c&&r!==void 0&&$e(`step\0${p}\0${C}\0${w}`)||(u.add(w),n.fireStep(p,C,w))};if(g.type==="click"){let c=s=>{let l=s.target;l instanceof Element&&We(l,e,g.selector)&&x()};e.addEventListener("click",c),m.push(()=>e.removeEventListener("click",c));return}if(g.type==="form_submit"){let c=s=>{s.target instanceof HTMLFormElement&&e.contains(s.target)&&x()};e.addEventListener("submit",c),m.push(()=>e.removeEventListener("submit",c));return}if(g.type==="scroll_depth"){let c=Math.max(0,Math.min(1,g.threshold)),s=new IntersectionObserver(l=>{for(let v of l)if(v.intersectionRatio>=c){x(!0),s.disconnect();break}},{threshold:[c]});s.observe(e),m.push(()=>s.disconnect())}}),()=>{for(let g of m)g()}}let i=t.type==="composite"?t.all:[t],o=new Set(i.map((u,m)=>m)),f=()=>{r!==void 0&&$e(r)||n.fireGoal()},a=(u,m=!1)=>{o.delete(u),o.size===0&&(m?f():n.fireGoal())},d=[];return i.forEach((u,m)=>{if(u.type==="click"){let g=p=>{let C=p.target;C instanceof Element&&We(C,e,u.selector)&&(t.type==="composite"?a(m):n.fireGoal())};e.addEventListener("click",g),d.push(()=>e.removeEventListener("click",g));return}if(u.type==="form_submit"){let g=p=>{p.target instanceof HTMLFormElement&&e.contains(p.target)&&(t.type==="composite"?a(m):n.fireGoal())};e.addEventListener("submit",g),d.push(()=>e.removeEventListener("submit",g));return}if(u.type==="scroll_depth"){let g=Math.max(0,Math.min(1,u.threshold)),p=new IntersectionObserver(C=>{for(let w of C)if(w.intersectionRatio>=g){t.type==="composite"?a(m,!0):f(),p.disconnect();break}},{threshold:[g]});p.observe(e),d.push(()=>p.disconnect());return}}),()=>{for(let u of d)u()}}var Ne=new Set,Ue=new Set;function U(e,t,n,r,i){let o=`${r}|${n}`;if(Ue.has(o))return;Ue.add(o);let f=i.type==="weighted_composite"&&!Ne.has(r);f&&Ne.add(r),e.track({projectId:t,componentId:n,eventType:"funnel_declared",payload:f?{funnelId:r,steps:i.steps.map(a=>({goalId:a.name,weight:a.weight}))}:{funnelId:r}})}function J(e,t,n,r){e.track({projectId:t,componentId:n,variantId:r,eventType:"variant_assigned",payload:{}})}var jt={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function H(){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 Z(){H().version+=1;for(let e of H().listeners)e()}var Je=()=>{};function oe(e){return I()?(H().components.set(e.id,e),Z(),()=>{H().components.delete(e.id),Z()}):Je}function se(e){return I()?(H().slots.set(e.id,e),Z(),()=>{H().slots.delete(e.id),Z()}):Je}function we(e){I()&&(H().sections=[...e],Z())}var tt=require("react/jsx-runtime");function Vt(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{return(0,ae.deriveSessionSegment)({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",F=(0,A.createContext)({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialPersona:null,apiBaseUrl:He,debug:!1});function $t(e){let[t,n]=(0,A.useState)(!1),r=(0,A.useRef)(e);r.current=e;let{cookie:i,value:o,event:f}=e!=null?e:{},a=typeof(e==null?void 0:e.check)=="function";return(0,A.useEffect)(()=>{let d=()=>{var p;let m=r.current;if(!m)return!1;if(m.check)return m.check()===!0;if(!m.cookie||typeof document=="undefined")return!1;let g=`${m.cookie}=${(p=m.value)!=null?p:"accepted"}`;return document.cookie.split("; ").some(C=>C.trim()===g)};if(n(d()),!f)return;let u=()=>{n(d())};return window.addEventListener(f,u),()=>window.removeEventListener(f,u)},[i,o,f,a]),t}function ze(e){var w,x;let[t,n]=(0,A.useState)(null),[r]=(0,A.useState)(()=>{var c;return(c=e.sessionSegment)!=null?c:Vt()}),[i,o]=(0,A.useState)(Se());(0,A.useEffect)(()=>Me(()=>o(Se())),[]);let f=$t(e.consentFrom),a=e.consentFrom?e.consent===!0||f:e.consent,d=(0,A.useRef)(null);(0,A.useEffect)(()=>{var k;if(a===!1&&!e.preConsentBehavior){(k=d.current)==null||k.destroy(),d.current=null,n(null);return}let c={apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,sessionSegment:r,consent:a,preConsentBehavior:e.preConsentBehavior,respectDoNotTrack:e.respectDoNotTrack,ssrSessionId:e.ssrSessionId,country:e.country,persona:e.persona,localMode:e.localMode,initialSlots:e.initialSlots,initialPersona:e.initialPersona,ingestUrl:e.apiBaseUrl?`${e.apiBaseUrl.replace(/\/$/,"")}/events`:void 0},s=!1,l=null,v=null,h=_=>{e.engagement!==!1&&import("@sentientui/core/engagement").then(({startEngagementCapture:S})=>{s||(v=S(_,{apiKey:e.apiKey,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:_})=>{s||(l=_(re(G({},c),{graph:!0,captureDomText:e.captureDomText===!0})),d.current=l,n(l),h(l))}):(l=(0,ae.init)(c),d.current=l,n(l),h(l)),()=>{s=!0,v==null||v(),l==null||l.dispose()}},[a]),(0,A.useEffect)(()=>{if(!t)return;let c=!1,s=async()=>{if(c)return;let v;try{v=await t.fetchWeights()}catch(h){return}if(!c)for(let h of v){let k={componentId:h.componentId,updatedAt:h.updatedAt,variants:h.variants.map(_=>{var S;return{variantId:_.variantId,pulls:_.pulls,avgReward:(S=_.avgReward)!=null?S:0}})};De(h.componentId,k)}};s();let l=setInterval(()=>{s()},6e4);return()=>{c=!0,clearInterval(l)}},[t]);let u=(w=e.ssrFallback)!=null?w:"first",m=((x=e.apiBaseUrl)!=null?x:He).replace(/\/$/,""),g=(0,A.useRef)(null);(0,A.useEffect)(()=>{var l;if(typeof process!="undefined"&&((l=process.env)==null?void 0:l.NODE_ENV)==="production")return;let c={apiKey:e.apiKey,context:e.context,country:e.country,persona:e.persona,apiBaseUrl:m},s=g.current;if(g.current=c,s!==null)for(let v of["apiKey","context","country","persona","apiBaseUrl"])Object.is(s[v],c[v])||console.warn(`[sentient] AdaptiveProvider: \`${v}\` changed after initialisation, but the SDK client is stable for the session and only re-inits on \`consent\` \u2014 the new value is ignored. Remount the provider (e.g. via a changing \`key\` prop) to apply it.`)},[e.apiKey,e.context,e.country,e.persona,m]),(0,A.useEffect)(()=>{var c;typeof process!="undefined"&&((c=process.env)==null?void 0:c.NODE_ENV)==="production"||Ve({apiKey:e.apiKey,apiBaseUrl:m,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,m]),(0,A.useEffect)(()=>{let c=e.initialLayoutOrder;if(c&&c.length>0){we(c);return}e.declaredSections&&e.declaredSections.length>0&&we(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]);let p=(0,A.useMemo)(()=>t&&i?Be(t):t,[t,i]),C=(0,A.useMemo)(()=>{var c,s,l,v,h;return{client:p,apiKey:e.apiKey,initialAssignments:(c=e.initialAssignments)!=null?c:{},sessionSegment:r,ssrFallback:u,onAssignment:e.onAssignment,initialLayoutOrder:(s=e.initialLayoutOrder)!=null?s:null,initialSlots:(l=e.initialSlots)!=null?l:{},initialPersona:(v=e.initialPersona)!=null?v:null,apiBaseUrl:m,debug:(h=e.debug)!=null?h:!1}},[p,e.apiKey,e.initialAssignments,r,u,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialPersona,m,e.debug]);return(0,tt.jsx)(F.Provider,{value:C,children:e.children})}function R(){return(0,A.useContext)(F).client}function $(){return(0,A.useContext)(F).apiKey}function le(){return(0,A.useContext)(F).initialAssignments}function ue(){return(0,A.useContext)(F).sessionSegment}function Xe(){return(0,A.useContext)(F).ssrFallback}function ce(){return(0,A.useContext)(F).onAssignment}function qe(){return(0,A.useContext)(F).debug}function Qe(){let e=(0,A.useContext)(F).initialLayoutOrder,t=(0,A.useSyncExternalStore)(W,()=>{var n;return typeof window=="undefined"?null:(n=window.__sentient_layout_override)!=null?n:null},()=>null);return t!=null?t:e}function Ye(){return(0,A.useContext)(F).initialSlots}function Ze(){return(0,A.useContext)(F).initialPersona}function et(){return(0,A.useContext)(F).apiBaseUrl}var O=require("react"),nt=require("@sentientui/core");var M=require("react"),de=require("@sentientui/policy");function q(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 i of r.getAll("sentient_variant")){let o=i.indexOf(":");if(o!==-1&&i.slice(0,o)===e)return i.slice(o+1)}}catch(r){}return null}function Q(e,t,n,r){let i=le(),o=Xe(),f=R(),a=ue(),d=ce(),u=qe(),m=(0,M.useRef)(null),g=(0,M.useSyncExternalStore)(W,()=>q(e),()=>null),p=g&&t.includes(g)?g:null,C=(0,M.useRef)(null);(0,M.useEffect)(()=>{u&&p&&C.current!==p&&(C.current=p,console.info(`[sentient] override active: ${e} -> ${p}`))},[u,p,e]);let[w,x]=(0,M.useState)(()=>{var v,h;if(p)return{variantId:p,content:null,isLoading:!1,settled:!0};if(!f){let k=i[e];return k&&t.includes(k)?{variantId:k,content:null,isLoading:!1,settled:!0}:o==="first"&&t.length>0?{variantId:t[0],content:null,isLoading:!1,settled:!1}:{variantId:null,content:null,isLoading:!0,settled:!1}}let s=f.getAssignment(e,a);if(s&&(t.includes(s.variantId)||s.content))return{variantId:s.variantId,content:(v=s.content)!=null?v:null,isLoading:!1,settled:!0};let l=ye(e);if(l){let k=(0,de.pickFromWeights)(l.variants,t);if(k)return{variantId:k,content:null,isLoading:!1,settled:!0}}return{variantId:(h=t[0])!=null?h:null,content:null,isLoading:!1,settled:!1}}),c=s=>{d&&m.current!==s&&(m.current=s,d(e,s))};return(0,M.useEffect)(()=>{var v;if(p||!f)return;let s=f.getAssignment(e,a);if(s&&(t.includes(s.variantId)||s.content)){x({variantId:s.variantId,content:(v=s.content)!=null?v:null,isLoading:!1,settled:!0}),c(s.variantId);return}let l=ye(e);if(l&&w.settled&&w.variantId&&w.variantId===(0,de.pickFromWeights)(l.variants,t)){c(w.variantId);return}x(h=>{var k;return h.variantId?h:{variantId:(k=t[0])!=null?k:null,content:null,isLoading:!1,settled:!1}})},[p,f,e,a]),(0,M.useEffect)(()=>{if(p||!f)return;let s=f.getAssignment(e,a);if(s&&t.includes(s.variantId))return;let l=!1;return f.assign(e,t,n,r).then(v=>{var h;l||v&&(!t.includes(v.variantId)&&!v.content||(x({variantId:v.variantId,content:(h=v.content)!=null?h:null,isLoading:!1,settled:!0}),c(v.variantId)))}),()=>{l=!0}},[p,f,e,a]),(0,M.useEffect)(()=>{if(!p&&f)return Te(e,s=>{var h;let l=f.getAssignment(e,a);if(l&&(t.includes(l.variantId)||l.content)){x({variantId:l.variantId,content:(h=l.content)!=null?h:null,isLoading:!1,settled:!0}),c(l.variantId);return}let v=(0,de.pickFromWeights)(s.variants,t);v&&(x({variantId:v,content:null,isLoading:!1,settled:!0}),c(v))})},[p,f,e,a]),p?{variantId:p,content:null,isLoading:!1,settled:!0,isOverride:!0}:w}var it=require("react/jsx-runtime");function Wt(e){var h;let t=R(),n=$(),r=Object.keys(e.variants).join("\0"),i=(0,O.useMemo)(()=>Object.keys(e.variants),[r]),{variantId:o,content:f,isOverride:a,settled:d}=Q(e.id,i,e.agentData,e.agentDataByVariant),u=(0,O.useRef)(null),[m,g]=(0,O.useState)(!1);(0,O.useEffect)(()=>{g(!0)},[]);let p=(0,O.useRef)(!1),C=(0,O.useRef)(new Set),w=(0,O.useRef)(null),x=typeof e.goal=="string"?e.goal:JSON.stringify(e.goal),c=(0,O.useMemo)(()=>D(e.goal),[x]),s=typeof e.goal=="string"?e.goal:c.type;if((0,O.useEffect)(()=>oe({id:e.id,variantIds:i,goal:s}),[e.id,i,s]),(0,O.useEffect)(()=>{a||d&&(!t||!o||!n||w.current!==o&&(w.current=o,J(t,n,e.id,o)))},[t,o,n,e.id,a,d]),(0,O.useEffect)(()=>{p.current=!1,C.current=new Set},[o,c]),(0,O.useEffect)(()=>{a||!d||!t||!e.funnel||U(t,n,e.id,e.funnel,c)},[t,n,e.id,e.funnel,c,a,d]),(0,O.useEffect)(()=>{if(a||!d||!t||!o)return;let k=u.current;if(!k)return;let _=null,S=0,b=()=>{S=Date.now(),_=setTimeout(()=>{t.track({projectId:n,componentId:e.id,variantId:o,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-S}}),_=null},800)},y=()=>{_!==null&&(clearTimeout(_),_=null)};return k.addEventListener("mouseenter",b),k.addEventListener("mouseleave",y),()=>{k.removeEventListener("mouseenter",b),k.removeEventListener("mouseleave",y),_!==null&&clearTimeout(_)}},[t,o,n,e.id,a,d]),(0,O.useEffect)(()=>{if(a||!d||!t||!o)return;let k=u.current;if(!k)return;let _=Date.now();return(0,nt.attachMicroSignalDetectors)((S,b={})=>{var Ce,Ge,_e;t.track({projectId:n,componentId:e.id,variantId:o,eventType:"micro_signal",payload:G({signalType:S},b)});let y=(Ce=e.microSignalGoals)==null?void 0:Ce[S];if(!y||C.current.has(S))return;C.current.add(S);let T=typeof y=="string"?y:y.name,N=typeof y=="string"?1:(Ge=y.weight)!=null?Ge:1,te=typeof y=="string"?0:(_e=y.stepIndex)!=null?_e:0;t.goal(T,{metadata:G({signalType:S},b),weight:N,stepIndex:te})},k,_)},[t,o,n,e.id,e.microSignalGoals,a,d]),(0,O.useEffect)(()=>{if(a||!d||!t||!o)return;let k=u.current;if(!k)return;let _=j(c);return V(k,c,{fireGoal:()=>{p.current||(p.current=!0,t.track({projectId:n,componentId:e.id,variantId:o,eventType:"goal_achieved",goalType:s,payload:G({reward:1},_!==void 0?{goalValue:_}:{})}),t.goal(s,G({metadata:{componentId:e.id,variantId:o},weight:1,stepIndex:0},_!==void 0?{value:_}:{})))},fireStep:(S,b,y)=>{t.track({projectId:n,componentId:e.id,variantId:o,eventType:"goal_achieved",goalType:S,payload:{reward:b}}),t.goal(S,{metadata:{},weight:b,stepIndex:y})}},s)},[t,o,n,e.id,c,s,a,d]),e.clientOnly&&(!m||!t)||!o)return null;let l=(h=e.variants[o])!=null?h:null,v=l===null?f:null;return I()&&l===null&&v===null&&console.warn(`[sentient] <Adaptive id="${e.id}"> was assigned variant "${o}" but no matching key exists in props.variants. If this is a dashboard-managed text variant, use <AdaptiveText id="${e.id}"> instead.`),(0,it.jsx)("div",{ref:u,"data-sentient-id":e.id,"data-sentient-variant":o,children:l!=null?l:v})}var rt=(0,O.memo)(Wt,(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(i=>i in t.variants&&Object.is(e.variants[i],t.variants[i]))});var L=require("react");var st=require("react/jsx-runtime");function ot({id:e,default:t,component:n="span",className:r,goal:i}){var _;let o=R(),f=$(),a=ce(),d=ue(),u=(0,L.useRef)(null),m=(0,L.useRef)(null),g=(0,L.useSyncExternalStore)(W,()=>q(e),()=>null),[p,C]=(0,L.useState)(()=>{var S,b;return(b=(S=o==null?void 0:o.getAssignment(e,d))==null?void 0:S.content)!=null?b:null}),[w,x]=(0,L.useState)(()=>{var S,b;return(b=(S=o==null?void 0:o.getAssignment(e,d))==null?void 0:S.variantId)!=null?b:null});(0,L.useEffect)(()=>{if(g||!o)return;let S=o.getAssignment(e,d);if((S==null?void 0:S.content)!==void 0){x(S.variantId),C(S.content);return}let b=!1;return o.assign(e).then(y=>{if(!b){if(!y){I()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}x(y.variantId),y.content&&C(y.content)}}),()=>{b=!0}},[o,e,d,g]),(0,L.useEffect)(()=>{g||!o||!w||!f||u.current!==w&&(u.current=w,o.track({projectId:f,componentId:e,variantId:w,eventType:"variant_assigned",payload:{}}),a==null||a(e,w))},[o,w,f,e,a,g]);let c=i===void 0?"":typeof i=="string"?i:JSON.stringify(i),s=(0,L.useMemo)(()=>i===void 0?null:D(i),[c]),l=i===void 0?null:typeof i=="string"?i:s.type,v=(0,L.useRef)(!1);(0,L.useEffect)(()=>{v.current=!1},[w,c]),(0,L.useEffect)(()=>{if(g||!o||!w||!f||!s||!l)return;let S=m.current;if(!S)return;let b=j(s);return V(S,s,{fireGoal:()=>{v.current||(v.current=!0,o.track({projectId:f,componentId:e,variantId:w,eventType:"goal_achieved",goalType:l,payload:G({reward:1},b!==void 0?{goalValue:b}:{})}),o.goal(l,G({metadata:{componentId:e,variantId:w},weight:1,stepIndex:0},b!==void 0?{value:b}:{})))},fireStep:(y,T,N)=>{o.track({projectId:f,componentId:e,variantId:w,eventType:"goal_achieved",goalType:y,payload:{reward:T}}),o.goal(y,{metadata:{},weight:T,stepIndex:N})}})},[o,w,f,e,s,l,g]);let h=p!=null?p:t;if(g){let S=o==null?void 0:o.getAssignment(e,d);h=S&&S.variantId===g&&(_=S.content)!=null?_:t}return(0,st.jsx)(n,{ref:S=>{m.current=S},className:r,children:h})}var fe=require("react");function ge(e){let t=R(),n=(0,fe.useRef)(new Set);return(0,fe.useCallback)((r,i)=>{var o,f;if(!q(e)){if(i!=null&&i.once){if(n.current.has(r))return;n.current.add(r)}t==null||t.componentGoal(e,r,i),t==null||t.goal(r,G(G(G({metadata:(o=i==null?void 0:i.metadata)!=null?o:{},weight:(f=i==null?void 0:i.reward)!=null?f:1,stepIndex:0},(i==null?void 0:i.value)!==void 0?{value:i.value}:{}),(i==null?void 0:i.currency)!==void 0?{currency:i.currency}:{}),(i==null?void 0:i.externalId)!==void 0?{externalId:i.externalId}:{}))}},[t,e])}var ee=require("react");function at(e,t={}){let d=t,{componentId:n}=d,r=Ee(d,["componentId"]),i=R(),o=ge(n!=null?n:""),f=(0,ee.useRef)(!1),a=(0,ee.useRef)(r);a.current=r,(0,ee.useEffect)(()=>{if(!i||f.current)return;f.current=!0;let{metadata:u,reward:m,value:g,currency:p,externalId:C}=a.current;if(n){o(e,a.current);return}i.goal(e,G(G(G({metadata:u!=null?u:{},weight:m!=null?m:1,stepIndex:0},g!==void 0?{value:g}:{}),p!==void 0?{currency:p}:{}),C!==void 0?{externalId:C}:{}))},[i,n,e,o])}var ut=require("@sentientui/core"),ct=require("@sentientui/policy"),ft=require("react/jsx-runtime");function lt(e){return JSON.stringify(e).replace(/</g,"\\u003c")}function Nt(e){return e.persona?'(function(){try{var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",'+lt(e.persona.persona)+');d.setAttribute("data-sentient-confidence",'+lt((0,ct.confidenceBand)(e.persona.confidence))+");}catch(e){}})();":(0,ut.renderPrePaintScript)(e.apiKey)}function dt(e){return(0,ft.jsx)("script",{"data-sentient-persona-script":"",nonce:e.nonce,dangerouslySetInnerHTML:{__html:Nt(e)}})}var K=require("react"),yt=require("@sentientui/policy");var B=require("react"),z=require("@sentientui/core"),mt=require("@sentientui/policy");var gt=new Set;function me(e,t){let n=R(),r=Ye(),[,i]=(0,B.useReducer)(m=>m+1,0),o=(0,B.useSyncExternalStore)(W,()=>{var m;return typeof window!="undefined"?(m=window.__sentient_slot_overrides)==null?void 0:m[e]:void 0},()=>{}),f=o===void 0?r[e]:void 0,a=o===void 0&&f===void 0&&n?n.getSlotResult(e):null,d=(n==null?void 0:n.isLocal)===!0&&o===void 0&&f===void 0&&a===null;(0,B.useEffect)(()=>{if(!d||!n)return;let m=!1;return n.decide({slots:[t]}).then(g=>{!m&&g&&i()}),()=>{m=!0}},[n,e,d]);let u=(()=>{if(o!==void 0)return{result:o,arm:(0,z.armOfResult)(o),source:"override"};if(f!==void 0)return{result:f,arm:(0,z.armOfResult)(f),source:"preloaded"};if(a!==null)return{result:a,arm:(0,z.armOfResult)(a),source:"client"};let m=(0,z.baselineResultFor)(t);return{result:m,arm:(0,z.armOfResult)(m),source:"baseline"}})();return(0,B.useEffect)(()=>{I()&&(!n||n.isLocal===!0||u.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,u.source,e]),u}function Ut(){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 pt(){let e=R(),t=Ze();(0,B.useSyncExternalStore)(W,je,()=>0);let[n,r]=(0,B.useState)(!1);(0,B.useEffect)(()=>r(!0),[]);let i=a=>({persona:a.persona,confidence:a.confidence,band:(0,mt.confidenceBand)(a.confidence)});if(!n)return t?i(t):null;let o=Ut();if(o)return i(o);if(t)return i(t);let f=e?e.getPersona():null;return f?i(f):null}var vt=new Set;function Jt(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/[\\"]/g,"\\$&")}function St(e,t,n){let r=R(),i=$(),o=JSON.stringify(t),f=(0,K.useMemo)(()=>({id:e,dims:t}),[e,o]),{result:a,arm:d,source:u}=me(e,f),m=(0,K.useMemo)(()=>typeof a=="string"?{}:a,[d]);if(I()&&!vt.has(e)){vt.add(e);let x=(0,yt.validateSlotDecl)({id:e,dims:Object.fromEntries(Object.entries(t).map(([s,l])=>[s,[...l]]))}),c=Object.values(t).reduce((s,l)=>s*l.length,1);x.ok?c>4&&console.warn(`[sentient] useAdaptiveTokens("${e}") declares ${c} combinations \u2014 more than the recommended 4. Each extra combination needs more traffic to learn; consider fewer dims/values.`):console.warn(`[sentient] useAdaptiveTokens("${e}"): invalid declaration \u2014 ${x.reason}. Serving baseline.`)}let g=(n==null?void 0:n.goal)===void 0?null:typeof n.goal=="string"?n.goal:JSON.stringify(n.goal);(0,K.useEffect)(()=>se({id:e,dims:t}),[e]);let p=(0,K.useRef)(null);(0,K.useEffect)(()=>{!r||u==="baseline"||u==="override"||p.current===d||(p.current=d,J(r,i,e,d))},[r,i,e,d,u]);let C=n==null?void 0:n.funnel;(0,K.useEffect)(()=>{var x;!r||!C||u==="override"||U(r,i,e,C,D((x=n==null?void 0:n.goal)!=null?x:"click"))},[r,i,e,C,g,u]),(0,K.useEffect)(()=>{if(!r||!(n!=null&&n.goal)||u==="override"||u==="baseline")return;let x=document.querySelector(`[data-sentient-slot="${Jt(e)}"]`);if(!x){I()&&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=X(n.goal),s=j(n.goal),l=!1;return V(x,D(n.goal),{fireGoal:()=>{l||(l=!0,s!==void 0?r.componentGoal(e,c,{value:s}):r.componentGoal(e,c),r.goal(c,G({metadata:{componentId:e,arm:d},weight:1,stepIndex:0},s!==void 0?{value:s}:{})))},fireStep:(v,h,k)=>{r.componentGoal(e,v,{reward:h}),r.goal(v,{metadata:{componentId:e,arm:d},weight:h,stepIndex:k})}},c)},[r,e,g,d,u]);let w=(0,K.useMemo)(()=>{let x={"data-sentient-slot":e};for(let[c,s]of Object.entries(m))x[`data-${c}`]=s;return x},[e,m]);return{tokens:m,props:w}}var E=require("react"),bt=require("@sentientui/core");var ht=new Set;function wt(e,t){var S;if(I()&&!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=$(),i=Object.keys(t.variants).join(" "),o=(0,E.useMemo)(()=>Object.keys(t.variants),[i]),{variantId:f,isOverride:a,settled:d}=Q(e,o),u=(S=f!=null?f:o[0])!=null?S:"",m=t.variants[u],[g,p]=(0,E.useState)(null),C=(0,E.useRef)(null),w=(0,E.useCallback)(b=>{C.current=b,p(b)},[]),x=typeof t.goal=="string"?t.goal:JSON.stringify(t.goal),c=(0,E.useMemo)(()=>t.goal?D(t.goal):null,[x]),s=t.goal?X(t.goal):"";(0,E.useEffect)(()=>oe({id:e,variantIds:o,goal:s}),[e,o,s]);let l=(0,E.useRef)(null);(0,E.useEffect)(()=>{a||d&&(!n||!u||!g||l.current!==u&&(l.current=u,J(n,r,e,u)))},[n,r,e,u,g,a,d]);let v=t.funnel;(0,E.useEffect)(()=>{a||!d||!n||!v||!c||U(n,r,e,v,c)},[n,r,e,v,c,a,d]);let h=(0,E.useRef)(!1);(0,E.useEffect)(()=>{h.current=!1},[u,x]),(0,E.useEffect)(()=>{if(a||!d||!n||!u||!g||!c)return;let b=j(c);return V(g,c,{fireGoal:()=>{h.current||(h.current=!0,n.track({projectId:r,componentId:e,variantId:u,eventType:"goal_achieved",goalType:s,payload:G({reward:1},b!==void 0?{goalValue:b}:{})}),n.goal(s,G({metadata:{componentId:e,variantId:u},weight:1,stepIndex:0},b!==void 0?{value:b}:{})))},fireStep:(y,T,N)=>{n.track({projectId:r,componentId:e,variantId:u,eventType:"goal_achieved",goalType:y,payload:{reward:T}}),n.goal(y,{metadata:{},weight:T,stepIndex:N})}},s)},[n,g,u,r,e,c,s,a,d]),(0,E.useEffect)(()=>{if(a||!n||!u||!g)return;let b=Date.now();return(0,bt.attachMicroSignalDetectors)((y,T={})=>{n.track({projectId:r,componentId:e,variantId:u,eventType:"micro_signal",payload:G({signalType:y},T)})},g,b)},[n,g,u,r,e,a]),(0,E.useEffect)(()=>{if(!I()||!n)return;let b=setTimeout(()=>{!C.current&&!ht.has(e)&&(ht.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 k=(0,E.useCallback)((b,y)=>{var N,te;if(a)return;let T=b!=null?b:s;T&&(n==null||n.componentGoal(e,T,y),n==null||n.goal(T,G(G(G({metadata:(N=y==null?void 0:y.metadata)!=null?N:{},weight:(te=y==null?void 0:y.reward)!=null?te:1,stepIndex:0},(y==null?void 0:y.value)!==void 0?{value:y.value}:{}),(y==null?void 0:y.currency)!==void 0?{currency:y.currency}:{}),(y==null?void 0:y.externalId)!==void 0?{externalId:y.externalId}:{})))},[n,e,s,a]),_=(0,E.useMemo)(()=>({ref:w,"data-sentient-id":e,"data-sentient-variant":u}),[w,e,u]);return{variant:u,value:m,bind:_,fireGoal:k}}var P=require("react");var At=require("react/jsx-runtime"),pe=new Set;function xt(e){var s;let t=R(),n=$(),r=(0,P.useRef)(null),i=Object.keys(e.arrangements).join(" "),o=(0,P.useMemo)(()=>Object.keys(e.arrangements),[i]),f=(0,P.useMemo)(()=>G({id:e.id,arms:o},e.baseline!==void 0?{baseline:e.baseline}:{}),[e.id,o,e.baseline]),{arm:a,source:d}=me(e.id,f);I()&&e.baseline!==void 0&&e.baseline!==o[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 ("${o[0]}"). The first arrangement should usually be the page's real incumbent (the holdout sees it).`));let u=P.Children.toArray(e.children).filter(P.isValidElement),m=new Map;for(let l of u)m.set(String((s=l.key)!=null?s:"").replace(/^\.\$/,""),l);let g=e.arrangements[a],p=g!==void 0&&g.length===u.length&&g.every(l=>m.has(l));I()&&g!==void 0&&!p&&!pe.has(e.id+":keys")&&(pe.add(e.id+":keys"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: arrangement "${a}" [${g.join(", ")}] does not match the children's keys \u2014 rendering declaration order (fail-safe).`));let C=p?g.map(l=>m.get(l)):u;(0,P.useEffect)(()=>se({id:e.id,arms:Object.keys(e.arrangements)}),[e.id]);let w=(0,P.useRef)(null);(0,P.useEffect)(()=>{!t||d==="baseline"||d==="override"||w.current===a||(w.current=a,J(t,n,e.id,a))},[t,n,e.id,a,d]);let x=e.funnel;(0,P.useEffect)(()=>{var l;!t||!x||d==="override"||U(t,n,e.id,x,D((l=e.goal)!=null?l:"click"))},[t,n,e.id,x,d]);let c=e.goal===void 0?null:typeof e.goal=="string"?e.goal:JSON.stringify(e.goal);return(0,P.useEffect)(()=>{if(!t||e.goal===void 0||d==="override"||d==="baseline")return;let l=r.current;if(!l)return;let v=X(e.goal),h=j(e.goal),k=!1;return V(l,D(e.goal),{fireGoal:()=>{k||(k=!0,h!==void 0?t.componentGoal(e.id,v,{value:h}):t.componentGoal(e.id,v),t.goal(v,G({metadata:{componentId:e.id,arm:a},weight:1,stepIndex:0},h!==void 0?{value:h}:{})))},fireStep:(_,S,b)=>{t.componentGoal(e.id,_,{reward:S}),t.goal(_,{metadata:{componentId:e.id,arm:a},weight:S,stepIndex:b})}},v)},[t,e.id,c,a,d]),(0,At.jsx)("div",{ref:r,"data-sentient-id":e.id,"data-sentient-variant":a,children:C})}var xe=require("@sentientui/core");var Ht=["page","blocks","layoutOrder"],kt=new Map;function Ct(e,t){kt.set(e,t)}function Ae(e){return kt.get(e)}function Gt(e){var i,o;let t=(o=(i=e.content)!=null?i:Ae(e.page))!=null?o:{},n={};for(let[f,a]of Object.entries(t))Ht.includes(f)||(n[f]=a);let r=re(G({},n),{page:e.page,blocks:e.blocks});return e.layoutOrder&&(r.layoutOrder=e.layoutOrder),r}function _t(e){return`<script type="application/ld+json">${ke(e)}</script>`}function ke(e){return JSON.stringify(G({"@context":"https://schema.org","@type":"WebPage"},e)).replace(/</g,"\\u003c")}function Rt(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
+ "use strict";var Et=Object.create;var Y=Object.defineProperty,It=Object.defineProperties,Lt=Object.getOwnPropertyDescriptor,Pt=Object.getOwnPropertyDescriptors,Tt=Object.getOwnPropertyNames,ne=Object.getOwnPropertySymbols,Dt=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty,Oe=Object.prototype.propertyIsEnumerable;var Re=(e,t,n)=>t in e?Y(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,G=(e,t)=>{for(var n in t||(t={}))ve.call(t,n)&&Re(e,n,t[n]);if(ne)for(var n of ne(t))Oe.call(t,n)&&Re(e,n,t[n]);return e},re=(e,t)=>It(e,Pt(t));var Ee=(e,t)=>{var n={};for(var r in e)ve.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&ne)for(var r of ne(e))t.indexOf(r)<0&&Oe.call(e,r)&&(n[r]=e[r]);return n};var Ft=(e,t)=>{for(var n in t)Y(e,n,{get:t[n],enumerable:!0})},Ie=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Tt(t))!ve.call(e,i)&&i!==n&&Y(e,i,{get:()=>t[i],enumerable:!(r=Lt(t,i))||r.enumerable});return e};var Le=(e,t,n)=>(n=e!=null?Et(Dt(e)):{},Ie(t||!e||!e.__esModule?Y(n,"default",{value:e,enumerable:!0}):n,e)),Mt=e=>Ie(Y({},"__esModule",{value:!0}),e);var zt={};Ft(zt,{Adaptive:()=>rt,AdaptiveGroup:()=>At,AdaptiveProvider:()=>ze,AdaptiveText:()=>ot,SentientPersonaScript:()=>dt,buildAgentFeed:()=>Gt,defineAgentContent:()=>Ct,detectSegment:()=>Ae.deriveSessionSegment,getAgentContent:()=>xe,grantConsent:()=>Ot.grantConsent,renderAgentJsonLd:()=>_t,renderAgentJsonLdBody:()=>ke,renderAgentMarkdown:()=>Rt,useAdaptive:()=>wt,useAdaptiveApiBaseUrl:()=>et,useAdaptiveGoal:()=>ge,useAdaptivePersona:()=>pt,useAdaptiveTokens:()=>St,useAssignment:()=>Q,useInitialAssignments:()=>le,useLayoutOrder:()=>Qe,usePageGoal:()=>at,useSentient:()=>O});module.exports=Mt(zt);var A=require("react"),ae=require("@sentientui/core");var Pe=new Map,ie=new Map;function Te(e,t){let n=ie.get(e);return n||(n=new Set,ie.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&ie.delete(e)}}function De(e,t){Pe.set(e,t);let n=ie.get(e);if(n)for(let r of n)try{r(t)}catch(i){}}function ye(e){var t;return(t=Pe.get(e))!=null?t:null}var Bt={on:!1,listeners:new Set};function Fe(){if(typeof window=="undefined")return Bt;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function Se(){return Fe().on}function Me(e){let t=Fe().listeners;return t.add(e),()=>{t.delete(e)}}function Be(e){return{isLocal:e.isLocal,track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},fetchWeights:()=>Promise.resolve([]),getAssignment:(t,n)=>e.getAssignment(t,n),assign:(t,n,r,i)=>e.assign(t,n,r,i),decide:()=>Promise.resolve(null),getSlotResult:t=>e.getSlotResult(t),getPersona:()=>e.getPersona(),getGraph:()=>e.getGraph(),dispose:()=>e.dispose(),destroy:()=>e.destroy()}}var je="sentient:overrides-changed";function Ke(){var e;return typeof window=="undefined"?0:(e=window.__sentient_overrides_version)!=null?e:0}function W(e){return typeof window=="undefined"?()=>{}:(window.addEventListener(je,e),()=>window.removeEventListener(je,e))}function $e(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function R(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}function D(e){return typeof e=="string"?{type:"click"}:e}function X(e){return typeof e=="string"?e:e.type}function K(e){if(typeof e!="string"&&(e.type==="click"||e.type==="form_submit"||e.type==="scroll_depth"))return e.value}var he=new Set,be=!1;function Ve(e){if(he.has(e))return!0;if(he.add(e),!be){be=!0;let t=()=>{be=!1,he.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 jt(e){if(!(e instanceof Element))return!1;let t=e.tagName.toLowerCase();return t==="a"||t==="button"?!0:e.getAttribute("role")==="button"}function We(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 r=e;for(;r&&r!==t;){if(jt(r))return!0;r=r.parentElement}return!1}function $(e,t,n,r){if(t.type==="weighted_composite"){let c=new Set,m=[];return t.steps.forEach(({goal:g,name:v,weight:C},w)=>{let x=(u=!1)=>{c.has(w)||u&&r!==void 0&&Ve(`step\0${v}\0${C}\0${w}`)||(c.add(w),n.fireStep(v,C,w))};if(g.type==="click"){let u=s=>{let a=s.target;a instanceof Element&&We(a,e,g.selector)&&x()};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)&&x()};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){x(!0),s.disconnect();break}},{threshold:[u]});s.observe(e),m.push(()=>s.disconnect())}}),()=>{for(let g of m)g()}}let i=t.type==="composite"?t.all:[t],o=new Set(i.map((c,m)=>m)),f=()=>{r!==void 0&&Ve(r)||n.fireGoal()},l=(c,m=!1)=>{o.delete(c),o.size===0&&(m?f():n.fireGoal())},d=[];return i.forEach((c,m)=>{if(c.type==="click"){let g=v=>{let C=v.target;C instanceof Element&&We(C,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(C=>{for(let w of C)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 Ue=new Set,Ne=new Set;function N(e,t,n,r,i){let o=`${r}|${n}`;if(Ne.has(o))return;Ne.add(o);let f=i.type==="weighted_composite"&&!Ue.has(r);f&&Ue.add(r),e.track({projectId:t,componentId:n,eventType:"funnel_declared",payload:f?{funnelId:r,steps:i.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 Kt={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function H(){if(typeof window=="undefined")return Kt;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 Z(){H().version+=1;for(let e of H().listeners)e()}var Je=()=>{};function oe(e){return R()?(H().components.set(e.id,e),Z(),()=>{H().components.delete(e.id),Z()}):Je}function se(e){return R()?(H().slots.set(e.id,e),Z(),()=>{H().slots.delete(e.id),Z()}):Je}function we(e){R()&&(H().sections=[...e],Z())}var tt=require("react/jsx-runtime");function $t(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{return(0,ae.deriveSessionSegment)({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",F=(0,A.createContext)({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialPersona:null,apiBaseUrl:He,debug:!1});function Vt(e){let[t,n]=(0,A.useState)(!1),r=(0,A.useRef)(e);r.current=e;let{cookie:i,value:o,event:f}=e!=null?e:{},l=typeof(e==null?void 0:e.check)=="function";return(0,A.useEffect)(()=>{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(C=>C.trim()===g)};if(n(d()),!f)return;let c=()=>{n(d())};return window.addEventListener(f,c),()=>window.removeEventListener(f,c)},[i,o,f,l]),t}function ze(e){var w,x;let[t,n]=(0,A.useState)(null),[r]=(0,A.useState)(()=>{var u;return(u=e.sessionSegment)!=null?u:$t()}),[i,o]=(0,A.useState)(Se());(0,A.useEffect)(()=>Me(()=>o(Se())),[]);let f=Vt(e.consentFrom),l=e.consentFrom?e.consent===!0||f:e.consent,d=(0,A.useRef)(null);(0,A.useEffect)(()=>{var k;if(l===!1&&!e.preConsentBehavior){(k=d.current)==null||k.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=_=>{e.engagement!==!1&&import("@sentientui/core/engagement").then(({startEngagementCapture:S})=>{s||(p=S(_,{apiKey:e.apiKey,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:_})=>{s||(a=_(re(G({},u),{graph:!0,captureDomText:e.captureDomText===!0})),d.current=a,n(a),h(a))}):(a=(0,ae.init)(u),d.current=a,n(a),h(a)),()=>{s=!0,p==null||p(),a==null||a.dispose()}},[l]),(0,A.useEffect)(()=>{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 k={componentId:h.componentId,updatedAt:h.updatedAt,variants:h.variants.map(_=>{var S;return{variantId:_.variantId,pulls:_.pulls,avgReward:(S=_.avgReward)!=null?S:0}})};De(h.componentId,k)}};s();let a=setInterval(()=>{s()},6e4);return()=>{u=!0,clearInterval(a)}},[t]);let c=(w=e.ssrFallback)!=null?w:"first",m=((x=e.apiBaseUrl)!=null?x:He).replace(/\/$/,""),g=(0,A.useRef)(null);(0,A.useEffect)(()=>{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]),(0,A.useEffect)(()=>{var u;typeof process!="undefined"&&((u=process.env)==null?void 0:u.NODE_ENV)==="production"||$e({apiKey:e.apiKey,apiBaseUrl:m,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,m]),(0,A.useEffect)(()=>{let u=e.initialLayoutOrder;if(u&&u.length>0){we(u);return}e.declaredSections&&e.declaredSections.length>0&&we(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]),(0,A.useEffect)(()=>{if(!R())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=(0,A.useMemo)(()=>t&&i?Be(t):t,[t,i]),C=(0,A.useMemo)(()=>{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(0,tt.jsx)(F.Provider,{value:C,children:e.children})}function O(){return(0,A.useContext)(F).client}function V(){return(0,A.useContext)(F).apiKey}function le(){return(0,A.useContext)(F).initialAssignments}function ue(){return(0,A.useContext)(F).sessionSegment}function Xe(){return(0,A.useContext)(F).ssrFallback}function ce(){return(0,A.useContext)(F).onAssignment}function qe(){return(0,A.useContext)(F).debug}function Qe(){let e=(0,A.useContext)(F).initialLayoutOrder,t=(0,A.useSyncExternalStore)(W,()=>{var n;return typeof window=="undefined"?null:(n=window.__sentient_layout_override)!=null?n:null},()=>null);return t!=null?t:e}function Ye(){return(0,A.useContext)(F).initialSlots}function Ze(){return(0,A.useContext)(F).initialPersona}function et(){return(0,A.useContext)(F).apiBaseUrl}var E=require("react"),nt=require("@sentientui/core");var M=require("react"),de=require("@sentientui/policy");function q(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 i of r.getAll("sentient_variant")){let o=i.indexOf(":");if(o!==-1&&i.slice(0,o)===e)return i.slice(o+1)}}catch(r){}return null}function Q(e,t,n,r){let i=le(),o=Xe(),f=O(),l=ue(),d=ce(),c=qe(),m=(0,M.useRef)(null),g=(0,M.useSyncExternalStore)(W,()=>q(e),()=>null),v=g&&t.includes(g)?g:null,C=(0,M.useRef)(null);(0,M.useEffect)(()=>{c&&v&&C.current!==v&&(C.current=v,console.info(`[sentient] override active: ${e} -> ${v}`))},[c,v,e]);let[w,x]=(0,M.useState)(()=>{var p,h;if(v)return{variantId:v,content:null,isLoading:!1,settled:!0};if(!f){let k=i[e];return k&&t.includes(k)?{variantId:k,content:null,isLoading:!1,settled:!0}:o==="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=ye(e);if(a){let k=(0,de.pickFromWeights)(a.variants,t);if(k)return{variantId:k,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(0,M.useEffect)(()=>{var p;if(v||!f)return;let s=f.getAssignment(e,l);if(s&&(t.includes(s.variantId)||s.content)){x({variantId:s.variantId,content:(p=s.content)!=null?p:null,isLoading:!1,settled:!0}),u(s.variantId);return}let a=ye(e);if(a&&w.settled&&w.variantId&&w.variantId===(0,de.pickFromWeights)(a.variants,t)){u(w.variantId);return}x(h=>{var k;return h.variantId?h:{variantId:(k=t[0])!=null?k:null,content:null,isLoading:!1,settled:!1}})},[v,f,e,l]),(0,M.useEffect)(()=>{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||(x({variantId:p.variantId,content:(h=p.content)!=null?h:null,isLoading:!1,settled:!0}),u(p.variantId)))}),()=>{a=!0}},[v,f,e,l]),(0,M.useEffect)(()=>{if(!v&&f)return Te(e,s=>{var h;let a=f.getAssignment(e,l);if(a&&(t.includes(a.variantId)||a.content)){x({variantId:a.variantId,content:(h=a.content)!=null?h:null,isLoading:!1,settled:!0}),u(a.variantId);return}let p=(0,de.pickFromWeights)(s.variants,t);p&&(x({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}var it=require("react/jsx-runtime");function Wt(e){var h;let t=O(),n=V(),r=Object.keys(e.variants).join("\0"),i=(0,E.useMemo)(()=>Object.keys(e.variants),[r]),{variantId:o,content:f,isOverride:l,settled:d}=Q(e.id,i,e.agentData,e.agentDataByVariant),c=(0,E.useRef)(null),[m,g]=(0,E.useState)(!1);(0,E.useEffect)(()=>{g(!0)},[]);let v=(0,E.useRef)(!1),C=(0,E.useRef)(new Set),w=(0,E.useRef)(null),x=typeof e.goal=="string"?e.goal:JSON.stringify(e.goal),u=(0,E.useMemo)(()=>D(e.goal),[x]),s=typeof e.goal=="string"?e.goal:u.type;if((0,E.useEffect)(()=>oe({id:e.id,variantIds:i,goal:s}),[e.id,i,s]),(0,E.useEffect)(()=>{l||d&&(!t||!o||!n||w.current!==o&&(w.current=o,J(t,n,e.id,o)))},[t,o,n,e.id,l,d]),(0,E.useEffect)(()=>{v.current=!1,C.current=new Set},[o,u]),(0,E.useEffect)(()=>{l||!d||!t||!e.funnel||N(t,n,e.id,e.funnel,u)},[t,n,e.id,e.funnel,u,l,d]),(0,E.useEffect)(()=>{if(l||!d||!t||!o)return;let k=c.current;if(!k)return;let _=null,S=0,b=()=>{S=Date.now(),_=setTimeout(()=>{t.track({projectId:n,componentId:e.id,variantId:o,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-S}}),_=null},800)},y=()=>{_!==null&&(clearTimeout(_),_=null)};return k.addEventListener("mouseenter",b),k.addEventListener("mouseleave",y),()=>{k.removeEventListener("mouseenter",b),k.removeEventListener("mouseleave",y),_!==null&&clearTimeout(_)}},[t,o,n,e.id,l,d]),(0,E.useEffect)(()=>{if(l||!d||!t||!o)return;let k=c.current;if(!k)return;let _=Date.now();return(0,nt.attachMicroSignalDetectors)((S,b={})=>{var Ce,Ge,_e;t.track({projectId:n,componentId:e.id,variantId:o,eventType:"micro_signal",payload:G({signalType:S},b)});let y=(Ce=e.microSignalGoals)==null?void 0:Ce[S];if(!y||C.current.has(S))return;C.current.add(S);let T=typeof y=="string"?y:y.name,U=typeof y=="string"?1:(Ge=y.weight)!=null?Ge:1,te=typeof y=="string"?0:(_e=y.stepIndex)!=null?_e:0;t.goal(T,{metadata:G({signalType:S},b),weight:U,stepIndex:te})},k,_)},[t,o,n,e.id,e.microSignalGoals,l,d]),(0,E.useEffect)(()=>{if(l||!d||!t||!o)return;let k=c.current;if(!k)return;let _=K(u);return $(k,u,{fireGoal:()=>{v.current||(v.current=!0,t.track({projectId:n,componentId:e.id,variantId:o,eventType:"goal_achieved",goalType:s,payload:G({reward:1},_!==void 0?{goalValue:_}:{})}),t.goal(s,G({metadata:{componentId:e.id,variantId:o},weight:1,stepIndex:0},_!==void 0?{value:_}:{})))},fireStep:(S,b,y)=>{t.track({projectId:n,componentId:e.id,variantId:o,eventType:"goal_achieved",goalType:S,payload:{reward:b}}),t.goal(S,{metadata:{},weight:b,stepIndex:y})}},s)},[t,o,n,e.id,u,s,l,d]),e.clientOnly&&(!m||!t)||!o)return null;let a=(h=e.variants[o])!=null?h:null,p=a===null?f:null;return R()&&a===null&&p===null&&console.warn(`[sentient] <Adaptive id="${e.id}"> was assigned variant "${o}" but no matching key exists in props.variants. If this is a dashboard-managed text variant, use <AdaptiveText id="${e.id}"> instead.`),(0,it.jsx)("div",{ref:c,"data-sentient-id":e.id,"data-sentient-variant":o,children:a!=null?a:p})}var rt=(0,E.memo)(Wt,(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(i=>i in t.variants&&Object.is(e.variants[i],t.variants[i]))});var L=require("react");var st=require("react/jsx-runtime");function ot({id:e,default:t,component:n="span",className:r,goal:i}){var _;let o=O(),f=V(),l=ce(),d=ue(),c=(0,L.useRef)(null),m=(0,L.useRef)(null),g=(0,L.useSyncExternalStore)(W,()=>q(e),()=>null),[v,C]=(0,L.useState)(()=>{var S,b;return(b=(S=o==null?void 0:o.getAssignment(e,d))==null?void 0:S.content)!=null?b:null}),[w,x]=(0,L.useState)(()=>{var S,b;return(b=(S=o==null?void 0:o.getAssignment(e,d))==null?void 0:S.variantId)!=null?b:null});(0,L.useEffect)(()=>{if(g||!o)return;let S=o.getAssignment(e,d);if((S==null?void 0:S.content)!==void 0){x(S.variantId),C(S.content);return}let b=!1;return o.assign(e).then(y=>{if(!b){if(!y){R()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}x(y.variantId),y.content&&C(y.content)}}),()=>{b=!0}},[o,e,d,g]),(0,L.useEffect)(()=>{g||!o||!w||!f||c.current!==w&&(c.current=w,o.track({projectId:f,componentId:e,variantId:w,eventType:"variant_assigned",payload:{}}),l==null||l(e,w))},[o,w,f,e,l,g]);let u=i===void 0?"":typeof i=="string"?i:JSON.stringify(i),s=(0,L.useMemo)(()=>i===void 0?null:D(i),[u]),a=i===void 0?null:typeof i=="string"?i:s.type,p=(0,L.useRef)(!1);(0,L.useEffect)(()=>{p.current=!1},[w,u]),(0,L.useEffect)(()=>{if(g||!o||!w||!f||!s||!a)return;let S=m.current;if(!S)return;let b=K(s);return $(S,s,{fireGoal:()=>{p.current||(p.current=!0,o.track({projectId:f,componentId:e,variantId:w,eventType:"goal_achieved",goalType:a,payload:G({reward:1},b!==void 0?{goalValue:b}:{})}),o.goal(a,G({metadata:{componentId:e,variantId:w},weight:1,stepIndex:0},b!==void 0?{value:b}:{})))},fireStep:(y,T,U)=>{o.track({projectId:f,componentId:e,variantId:w,eventType:"goal_achieved",goalType:y,payload:{reward:T}}),o.goal(y,{metadata:{},weight:T,stepIndex:U})}})},[o,w,f,e,s,a,g]);let h=v!=null?v:t;if(g){let S=o==null?void 0:o.getAssignment(e,d);h=S&&S.variantId===g&&(_=S.content)!=null?_:t}return(0,st.jsx)(n,{ref:S=>{m.current=S},className:r,children:h})}var fe=require("react");function ge(e){let t=O(),n=(0,fe.useRef)(new Set);return(0,fe.useCallback)((r,i)=>{var o,f;if(!q(e)){if(i!=null&&i.once){if(n.current.has(r))return;n.current.add(r)}t==null||t.componentGoal(e,r,i),t==null||t.goal(r,G(G(G({metadata:(o=i==null?void 0:i.metadata)!=null?o:{},weight:(f=i==null?void 0:i.reward)!=null?f:1,stepIndex:0},(i==null?void 0:i.value)!==void 0?{value:i.value}:{}),(i==null?void 0:i.currency)!==void 0?{currency:i.currency}:{}),(i==null?void 0:i.externalId)!==void 0?{externalId:i.externalId}:{}))}},[t,e])}var ee=require("react");function at(e,t={}){let d=t,{componentId:n}=d,r=Ee(d,["componentId"]),i=O(),o=ge(n!=null?n:""),f=(0,ee.useRef)(!1),l=(0,ee.useRef)(r);l.current=r,(0,ee.useEffect)(()=>{if(!i||f.current)return;f.current=!0;let{metadata:c,reward:m,value:g,currency:v,externalId:C}=l.current;if(n){o(e,l.current);return}i.goal(e,G(G(G({metadata:c!=null?c:{},weight:m!=null?m:1,stepIndex:0},g!==void 0?{value:g}:{}),v!==void 0?{currency:v}:{}),C!==void 0?{externalId:C}:{}))},[i,n,e,o])}var ut=require("@sentientui/core"),ct=require("@sentientui/policy"),ft=require("react/jsx-runtime");function lt(e){return JSON.stringify(e).replace(/</g,"\\u003c")}function Ut(e){return e.persona?'(function(){try{var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",'+lt(e.persona.persona)+');d.setAttribute("data-sentient-confidence",'+lt((0,ct.confidenceBand)(e.persona.confidence))+");}catch(e){}})();":(0,ut.renderPrePaintScript)(e.apiKey)}function dt(e){return(0,ft.jsx)("script",{"data-sentient-persona-script":"",nonce:e.nonce,dangerouslySetInnerHTML:{__html:Ut(e)}})}var j=require("react"),yt=require("@sentientui/policy");var B=require("react"),z=require("@sentientui/core"),mt=require("@sentientui/policy");var gt=new Set;function me(e,t){let n=O(),r=Ye(),[,i]=(0,B.useReducer)(m=>m+1,0),o=(0,B.useSyncExternalStore)(W,()=>{var m;return typeof window!="undefined"?(m=window.__sentient_slot_overrides)==null?void 0:m[e]:void 0},()=>{}),f=o===void 0?r[e]:void 0,l=o===void 0&&f===void 0&&n?n.getSlotResult(e):null,d=(n==null?void 0:n.isLocal)===!0&&o===void 0&&f===void 0&&l===null;(0,B.useEffect)(()=>{if(!d||!n)return;let m=!1;return n.decide({slots:[t]}).then(g=>{!m&&g&&i()}),()=>{m=!0}},[n,e,d]);let c=(()=>{if(o!==void 0)return{result:o,arm:(0,z.armOfResult)(o),source:"override"};if(f!==void 0)return{result:f,arm:(0,z.armOfResult)(f),source:"preloaded"};if(l!==null)return{result:l,arm:(0,z.armOfResult)(l),source:"client"};let m=(0,z.baselineResultFor)(t);return{result:m,arm:(0,z.armOfResult)(m),source:"baseline"}})();return(0,B.useEffect)(()=>{R()&&(!n||n.isLocal===!0||c.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,c.source,e]),c}function Nt(){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 pt(){let e=O(),t=Ze();(0,B.useSyncExternalStore)(W,Ke,()=>0);let[n,r]=(0,B.useState)(!1);(0,B.useEffect)(()=>r(!0),[]);let i=l=>({persona:l.persona,confidence:l.confidence,band:(0,mt.confidenceBand)(l.confidence)});if(!n)return t?i(t):null;let o=Nt();if(o)return i(o);if(t)return i(t);let f=e?e.getPersona():null;return f?i(f):null}var vt=new Set;function Jt(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/[\\"]/g,"\\$&")}function St(e,t,n){let r=O(),i=V(),o=JSON.stringify(t),f=(0,j.useMemo)(()=>({id:e,dims:t}),[e,o]),{result:l,arm:d,source:c}=me(e,f),m=(0,j.useMemo)(()=>typeof l=="string"?{}:l,[d]);if(R()&&!vt.has(e)){vt.add(e);let x=(0,yt.validateSlotDecl)({id:e,dims:Object.fromEntries(Object.entries(t).map(([s,a])=>[s,[...a]]))}),u=Object.values(t).reduce((s,a)=>s*a.length,1);x.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 ${x.reason}. Serving baseline.`)}let g=(n==null?void 0:n.goal)===void 0?null:typeof n.goal=="string"?n.goal:JSON.stringify(n.goal);(0,j.useEffect)(()=>se({id:e,dims:t}),[e]);let v=(0,j.useRef)(null);(0,j.useEffect)(()=>{!r||c==="baseline"||c==="override"||v.current===d||(v.current=d,J(r,i,e,d))},[r,i,e,d,c]);let C=n==null?void 0:n.funnel;(0,j.useEffect)(()=>{var x;!r||!C||c==="override"||N(r,i,e,C,D((x=n==null?void 0:n.goal)!=null?x:"click"))},[r,i,e,C,g,c]),(0,j.useEffect)(()=>{if(!r||!(n!=null&&n.goal)||c==="override"||c==="baseline")return;let x=document.querySelector(`[data-sentient-slot="${Jt(e)}"]`);if(!x){R()&&console.warn(`[sentient] useAdaptiveTokens("${e}"): a goal is declared but no element carries the returned props \u2014 spread {...props} on the slot's element.`);return}let u=X(n.goal),s=K(n.goal),a=!1;return $(x,D(n.goal),{fireGoal:()=>{a||(a=!0,s!==void 0?r.componentGoal(e,u,{value:s}):r.componentGoal(e,u),r.goal(u,G({metadata:{componentId:e,arm:d},weight:1,stepIndex:0},s!==void 0?{value:s}:{})))},fireStep:(p,h,k)=>{r.componentGoal(e,p,{reward:h}),r.goal(p,{metadata:{componentId:e,arm:d},weight:h,stepIndex:k})}},u)},[r,e,g,d,c]);let w=(0,j.useMemo)(()=>{let x={"data-sentient-slot":e};for(let[u,s]of Object.entries(m))x[`data-${u}`]=s;return x},[e,m]);return{tokens:m,props:w}}var I=require("react"),bt=require("@sentientui/core");var ht=new Set;function wt(e,t){var S;if(R()&&!t.goal)throw new Error(`[sentient] useAdaptive("${e}"): a goal is required \u2014 without one the optimizer accumulates exposures with no rewards and cannot learn. Pass e.g. goal: 'buy_click'.`);let n=O(),r=V(),i=Object.keys(t.variants).join(" "),o=(0,I.useMemo)(()=>Object.keys(t.variants),[i]),{variantId:f,isOverride:l,settled:d}=Q(e,o),c=(S=f!=null?f:o[0])!=null?S:"",m=t.variants[c],[g,v]=(0,I.useState)(null),C=(0,I.useRef)(null),w=(0,I.useCallback)(b=>{C.current=b,v(b)},[]),x=typeof t.goal=="string"?t.goal:JSON.stringify(t.goal),u=(0,I.useMemo)(()=>t.goal?D(t.goal):null,[x]),s=t.goal?X(t.goal):"";(0,I.useEffect)(()=>oe({id:e,variantIds:o,goal:s}),[e,o,s]);let a=(0,I.useRef)(null);(0,I.useEffect)(()=>{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;(0,I.useEffect)(()=>{l||!d||!n||!p||!u||N(n,r,e,p,u)},[n,r,e,p,u,l,d]);let h=(0,I.useRef)(!1);(0,I.useEffect)(()=>{h.current=!1},[c,x]),(0,I.useEffect)(()=>{if(l||!d||!n||!c||!g||!u)return;let b=K(u);return $(g,u,{fireGoal:()=>{h.current||(h.current=!0,n.track({projectId:r,componentId:e,variantId:c,eventType:"goal_achieved",goalType:s,payload:G({reward:1},b!==void 0?{goalValue:b}:{})}),n.goal(s,G({metadata:{componentId:e,variantId:c},weight:1,stepIndex:0},b!==void 0?{value:b}:{})))},fireStep:(y,T,U)=>{n.track({projectId:r,componentId:e,variantId:c,eventType:"goal_achieved",goalType:y,payload:{reward:T}}),n.goal(y,{metadata:{},weight:T,stepIndex:U})}},s)},[n,g,c,r,e,u,s,l,d]),(0,I.useEffect)(()=>{if(l||!n||!c||!g)return;let b=Date.now();return(0,bt.attachMicroSignalDetectors)((y,T={})=>{n.track({projectId:r,componentId:e,variantId:c,eventType:"micro_signal",payload:G({signalType:y},T)})},g,b)},[n,g,c,r,e,l]),(0,I.useEffect)(()=>{if(!R()||!n)return;let b=setTimeout(()=>{!C.current&&!ht.has(e)&&(ht.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 k=(0,I.useCallback)((b,y)=>{var U,te;if(l)return;let T=b!=null?b:s;T&&(n==null||n.componentGoal(e,T,y),n==null||n.goal(T,G(G(G({metadata:(U=y==null?void 0:y.metadata)!=null?U:{},weight:(te=y==null?void 0:y.reward)!=null?te: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]),_=(0,I.useMemo)(()=>({ref:w,"data-sentient-id":e,"data-sentient-variant":c}),[w,e,c]);return{variant:c,value:m,bind:_,fireGoal:k}}var P=require("react");var xt=require("react/jsx-runtime"),pe=new Set;function At(e){var s;let t=O(),n=V(),r=(0,P.useRef)(null),i=Object.keys(e.arrangements).join(" "),o=(0,P.useMemo)(()=>Object.keys(e.arrangements),[i]),f=(0,P.useMemo)(()=>G({id:e.id,arms:o},e.baseline!==void 0?{baseline:e.baseline}:{}),[e.id,o,e.baseline]),{arm:l,source:d}=me(e.id,f);R()&&e.baseline!==void 0&&e.baseline!==o[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 ("${o[0]}"). The first arrangement should usually be the page's real incumbent (the holdout sees it).`));let c=P.Children.toArray(e.children).filter(P.isValidElement),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));R()&&g!==void 0&&!v&&!pe.has(e.id+":keys")&&(pe.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 C=v?g.map(a=>m.get(a)):c;(0,P.useEffect)(()=>se({id:e.id,arms:Object.keys(e.arrangements)}),[e.id]);let w=(0,P.useRef)(null);(0,P.useEffect)(()=>{!t||d==="baseline"||d==="override"||w.current===l||(w.current=l,J(t,n,e.id,l))},[t,n,e.id,l,d]);let x=e.funnel;(0,P.useEffect)(()=>{var a;!t||!x||d==="override"||N(t,n,e.id,x,D((a=e.goal)!=null?a:"click"))},[t,n,e.id,x,d]);let u=e.goal===void 0?null:typeof e.goal=="string"?e.goal:JSON.stringify(e.goal);return(0,P.useEffect)(()=>{if(!t||e.goal===void 0||d==="override"||d==="baseline")return;let a=r.current;if(!a)return;let p=X(e.goal),h=K(e.goal),k=!1;return $(a,D(e.goal),{fireGoal:()=>{k||(k=!0,h!==void 0?t.componentGoal(e.id,p,{value:h}):t.componentGoal(e.id,p),t.goal(p,G({metadata:{componentId:e.id,arm:l},weight:1,stepIndex:0},h!==void 0?{value:h}:{})))},fireStep:(_,S,b)=>{t.componentGoal(e.id,_,{reward:S}),t.goal(_,{metadata:{componentId:e.id,arm:l},weight:S,stepIndex:b})}},p)},[t,e.id,u,l,d]),(0,xt.jsx)("div",{ref:r,"data-sentient-id":e.id,"data-sentient-variant":l,children:C})}var Ae=require("@sentientui/core");var Ht=["page","blocks","layoutOrder"],kt=new Map;function Ct(e,t){kt.set(e,t)}function xe(e){return kt.get(e)}function Gt(e){var i,o;let t=(o=(i=e.content)!=null?i:xe(e.page))!=null?o:{},n={};for(let[f,l]of Object.entries(t))Ht.includes(f)||(n[f]=l);let r=re(G({},n),{page:e.page,blocks:e.blocks});return e.layoutOrder&&(r.layoutOrder=e.layoutOrder),r}function _t(e){return`<script type="application/ld+json">${ke(e)}</script>`}function ke(e){return JSON.stringify(G({"@context":"https://schema.org","@type":"WebPage"},e)).replace(/</g,"\\u003c")}function Rt(e){let t=[];e.title&&t.push(`# ${e.title}`,""),e.summary&&t.push(String(e.summary),"");for(let[n,r]of Object.entries(e))["page","title","summary","blocks","layoutOrder"].includes(n)||t.push(`## ${n}`,"","```json",JSON.stringify(r,null,2),"```","");if(e.blocks.length>0){t.push("## blocks","");for(let n of e.blocks)t.push(`- **${n.id}** \u2192 variant \`${n.variant}\``),n.content!==void 0&&t.push(""," ```json",JSON.stringify(n.content,null,2)," ```");t.push("")}return t.join(`
3
3
  `).trimEnd()+`
4
4
  `}var Ot=require("@sentientui/core");0&&(module.exports={Adaptive,AdaptiveGroup,AdaptiveProvider,AdaptiveText,SentientPersonaScript,buildAgentFeed,defineAgentContent,detectSegment,getAgentContent,grantConsent,renderAgentJsonLd,renderAgentJsonLdBody,renderAgentMarkdown,useAdaptive,useAdaptiveApiBaseUrl,useAdaptiveGoal,useAdaptivePersona,useAdaptiveTokens,useAssignment,useInitialAssignments,useLayoutOrder,usePageGoal,useSentient});
5
5
  //# sourceMappingURL=index.js.map