@sentientui/react 0.27.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.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/testing/react.js +1 -1
- package/dist/testing/react.js.map +1 -1
- package/dist/testing/react.mjs +1 -1
- package/dist/testing/react.mjs.map +1 -1
- package/package.json +4 -3
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:()=>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(`
|
|
2
|
+
"use strict";var Lt=Object.create;var Y=Object.defineProperty,Dt=Object.defineProperties,Tt=Object.getOwnPropertyDescriptor,Pt=Object.getOwnPropertyDescriptors,Ft=Object.getOwnPropertyNames,ne=Object.getOwnPropertySymbols,Mt=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty,Ee=Object.prototype.propertyIsEnumerable;var Oe=(e,t,n)=>t in e?Y(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,k=(e,t)=>{for(var n in t||(t={}))ve.call(t,n)&&Oe(e,n,t[n]);if(ne)for(var n of ne(t))Ee.call(t,n)&&Oe(e,n,t[n]);return e},re=(e,t)=>Dt(e,Pt(t));var Ie=(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&&Ee.call(e,r)&&(n[r]=e[r]);return n};var Kt=(e,t)=>{for(var n in t)Y(e,n,{get:t[n],enumerable:!0})},Le=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ft(t))!ve.call(e,i)&&i!==n&&Y(e,i,{get:()=>t[i],enumerable:!(r=Tt(t,i))||r.enumerable});return e};var De=(e,t,n)=>(n=e!=null?Lt(Mt(e)):{},Le(t||!e||!e.__esModule?Y(n,"default",{value:e,enumerable:!0}):n,e)),Bt=e=>Le(Y({},"__esModule",{value:!0}),e);var qt={};Kt(qt,{Adaptive:()=>ot,AdaptiveGroup:()=>_t,AdaptiveProvider:()=>qe,AdaptiveText:()=>at,SentientPersonaScript:()=>gt,buildAgentFeed:()=>Rt,defineAgentContent:()=>Gt,detectSegment:()=>xe.deriveSessionSegment,getAgentContent:()=>_e,grantConsent:()=>It.grantConsent,renderAgentJsonLd:()=>Ot,renderAgentJsonLdBody:()=>ke,renderAgentMarkdown:()=>Et,useAdaptive:()=>xt,useAdaptiveApiBaseUrl:()=>nt,useAdaptiveGoal:()=>ge,useAdaptivePersona:()=>yt,useAdaptiveTokens:()=>bt,useAssignment:()=>Q,useInitialAssignments:()=>le,useLayoutOrder:()=>Ze,usePageGoal:()=>ut,useSentient:()=>O});module.exports=Bt(qt);var A=require("react"),ae=require("@sentientui/core");var Te=new Map,ie=new Map;function Pe(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 Fe(e,t){Te.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=Te.get(e))!=null?t:null}var jt={on:!1,listeners:new Set};function Me(){if(typeof window=="undefined")return jt;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function Se(){return Me().on}function Ke(e){let t=Me().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 $e(){var e;return typeof window=="undefined"?0:(e=window.__sentient_overrides_version)!=null?e:0}function N(e){return typeof window=="undefined"?()=>{}:(window.addEventListener(je,e),()=>window.removeEventListener(je,e))}function Ve(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 P(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 Ne(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 $t(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($t(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&&Ne(`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&&Ne(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,Je=new Set;function U(e,t,n,r,i){let o=`${r}|${n}`;if(Je.has(o))return;Je.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 Vt={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function H(){if(typeof window=="undefined")return Vt;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 He=()=>{};function oe(e){return R()?(H().components.set(e.id,e),Z(),()=>{H().components.delete(e.id),Z()}):He}function se(e){return R()?(H().slots.set(e.id,e),Z(),()=>{H().slots.delete(e.id),Z()}):He}function we(e){R()&&(H().sections=[...e],Z())}var ze="0.28.0",Ae=ze!=="0.0.0-dev"?{name:"react",version:ze}:void 0;var rt=require("react/jsx-runtime");function Nt(){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 Xe="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:Xe,debug:!1});function Wt(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 qe(e){var w,x;let[t,n]=(0,A.useState)(null),[r]=(0,A.useState)(()=>{var u;return(u=e.sessionSegment)!=null?u:Nt()}),[i,o]=(0,A.useState)(Se());(0,A.useEffect)(()=>Ke(()=>o(Se())),[]);let f=Wt(e.consentFrom),l=e.consentFrom?e.consent===!0||f:e.consent,d=(0,A.useRef)(null);(0,A.useEffect)(()=>{var _;if(l===!1&&!e.preConsentBehavior){(_=d.current)==null||_.destroy(),d.current=null,n(null);return}let u=k({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},Ae?{sdk:Ae}:{}),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(re(k({},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 _={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}})};Fe(h.componentId,_)}};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:Xe).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"||Ve({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,rt.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 Qe(){return(0,A.useContext)(F).ssrFallback}function ce(){return(0,A.useContext)(F).onAssignment}function Ye(){return(0,A.useContext)(F).debug}function Ze(){let e=(0,A.useContext)(F).initialLayoutOrder,t=(0,A.useSyncExternalStore)(N,()=>{var n;return typeof window=="undefined"?null:(n=window.__sentient_layout_override)!=null?n:null},()=>null);return t!=null?t:e}function et(){return(0,A.useContext)(F).initialSlots}function tt(){return(0,A.useContext)(F).initialPersona}function nt(){return(0,A.useContext)(F).apiBaseUrl}var E=require("react"),it=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=Qe(),f=O(),l=ue(),d=ce(),c=Ye(),m=(0,M.useRef)(null),g=(0,M.useSyncExternalStore)(N,()=>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 _=i[e];return _&&t.includes(_)?{variantId:_,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 _=(0,de.pickFromWeights)(a.variants,t);if(_)return{variantId:_,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 _;return h.variantId?h:{variantId:(_=t[0])!=null?_: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 Pe(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 st=require("react/jsx-runtime");function Ut(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)(()=>P(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||U(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 _=c.current;if(!_)return;let G=null,S=0,b=()=>{S=Date.now(),G=setTimeout(()=>{t.track({projectId:n,componentId:e.id,variantId:o,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-S}}),G=null},800)},y=()=>{G!==null&&(clearTimeout(G),G=null)};return _.addEventListener("mouseenter",b),_.addEventListener("mouseleave",y),()=>{_.removeEventListener("mouseenter",b),_.removeEventListener("mouseleave",y),G!==null&&clearTimeout(G)}},[t,o,n,e.id,l,d]),(0,E.useEffect)(()=>{if(l||!d||!t||!o)return;let _=c.current;if(!_)return;let G=Date.now();return(0,it.attachMicroSignalDetectors)((S,b={})=>{var Ce,Ge,Re;t.track({projectId:n,componentId:e.id,variantId:o,eventType:"micro_signal",payload:k({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,W=typeof y=="string"?1:(Ge=y.weight)!=null?Ge:1,te=typeof y=="string"?0:(Re=y.stepIndex)!=null?Re:0;t.goal(T,{metadata:k({signalType:S},b),weight:W,stepIndex:te})},_,G)},[t,o,n,e.id,e.microSignalGoals,l,d]),(0,E.useEffect)(()=>{if(l||!d||!t||!o)return;let _=c.current;if(!_)return;let G=j(u);return $(_,u,{fireGoal:()=>{v.current||(v.current=!0,t.track({projectId:n,componentId:e.id,variantId:o,eventType:"goal_achieved",goalType:s,payload:k({reward:1},G!==void 0?{goalValue:G}:{})}),t.goal(s,k({metadata:{componentId:e.id,variantId:o},weight:1,stepIndex:0},G!==void 0?{value:G}:{})))},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,st.jsx)("div",{ref:c,"data-sentient-id":e.id,"data-sentient-variant":o,children:a!=null?a:p})}var ot=(0,E.memo)(Ut,(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 lt=require("react/jsx-runtime");function at({id:e,default:t,component:n="span",className:r,goal:i}){var G;let o=O(),f=V(),l=ce(),d=ue(),c=(0,L.useRef)(null),m=(0,L.useRef)(null),g=(0,L.useSyncExternalStore)(N,()=>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:P(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=j(s);return $(S,s,{fireGoal:()=>{p.current||(p.current=!0,o.track({projectId:f,componentId:e,variantId:w,eventType:"goal_achieved",goalType:a,payload:k({reward:1},b!==void 0?{goalValue:b}:{})}),o.goal(a,k({metadata:{componentId:e,variantId:w},weight:1,stepIndex:0},b!==void 0?{value:b}:{})))},fireStep:(y,T,W)=>{o.track({projectId:f,componentId:e,variantId:w,eventType:"goal_achieved",goalType:y,payload:{reward:T}}),o.goal(y,{metadata:{},weight:T,stepIndex:W})}})},[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&&(G=S.content)!=null?G:t}return(0,lt.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,k(k(k({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 ut(e,t={}){let d=t,{componentId:n}=d,r=Ie(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,k(k(k({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 dt=require("@sentientui/core"),ft=require("@sentientui/policy"),mt=require("react/jsx-runtime");function ct(e){return JSON.stringify(e).replace(/</g,"\\u003c")}function Jt(e){return e.persona?'(function(){try{var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",'+ct(e.persona.persona)+');d.setAttribute("data-sentient-confidence",'+ct((0,ft.confidenceBand)(e.persona.confidence))+");}catch(e){}})();":(0,dt.renderPrePaintScript)(e.apiKey)}function gt(e){return(0,mt.jsx)("script",{"data-sentient-persona-script":"",nonce:e.nonce,dangerouslySetInnerHTML:{__html:Jt(e)}})}var B=require("react"),ht=require("@sentientui/policy");var K=require("react"),z=require("@sentientui/core"),vt=require("@sentientui/policy");var pt=new Set;function me(e,t){let n=O(),r=et(),[,i]=(0,K.useReducer)(m=>m+1,0),o=(0,K.useSyncExternalStore)(N,()=>{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,K.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,K.useEffect)(()=>{R()&&(!n||n.isLocal===!0||c.source==="baseline"&&(pt.has(e)||(pt.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 Ht(){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 yt(){let e=O(),t=tt();(0,K.useSyncExternalStore)(N,$e,()=>0);let[n,r]=(0,K.useState)(!1);(0,K.useEffect)(()=>r(!0),[]);let i=l=>({persona:l.persona,confidence:l.confidence,band:(0,vt.confidenceBand)(l.confidence)});if(!n)return t?i(t):null;let o=Ht();if(o)return i(o);if(t)return i(t);let f=e?e.getPersona():null;return f?i(f):null}var St=new Set;function zt(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/[\\"]/g,"\\$&")}function bt(e,t,n){let r=O(),i=V(),o=JSON.stringify(t),f=(0,B.useMemo)(()=>({id:e,dims:t}),[e,o]),{result:l,arm:d,source:c}=me(e,f),m=(0,B.useMemo)(()=>typeof l=="string"?{}:l,[d]);if(R()&&!St.has(e)){St.add(e);let x=(0,ht.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,B.useEffect)(()=>se({id:e,dims:t}),[e]);let v=(0,B.useRef)(null);(0,B.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,B.useEffect)(()=>{var x;!r||!C||c==="override"||U(r,i,e,C,P((x=n==null?void 0:n.goal)!=null?x:"click"))},[r,i,e,C,g,c]),(0,B.useEffect)(()=>{if(!r||!(n!=null&&n.goal)||c==="override"||c==="baseline")return;let x=document.querySelector(`[data-sentient-slot="${zt(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=j(n.goal),a=!1;return $(x,P(n.goal),{fireGoal:()=>{a||(a=!0,s!==void 0?r.componentGoal(e,u,{value:s}):r.componentGoal(e,u),r.goal(u,k({metadata:{componentId:e,arm:d},weight:1,stepIndex:0},s!==void 0?{value:s}:{})))},fireStep:(p,h,_)=>{r.componentGoal(e,p,{reward:h}),r.goal(p,{metadata:{componentId:e,arm:d},weight:h,stepIndex:_})}},u)},[r,e,g,d,c]);let w=(0,B.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"),At=require("@sentientui/core");var wt=new Set;function xt(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?P(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||U(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=j(u);return $(g,u,{fireGoal:()=>{h.current||(h.current=!0,n.track({projectId:r,componentId:e,variantId:c,eventType:"goal_achieved",goalType:s,payload:k({reward:1},b!==void 0?{goalValue:b}:{})}),n.goal(s,k({metadata:{componentId:e,variantId:c},weight:1,stepIndex:0},b!==void 0?{value:b}:{})))},fireStep:(y,T,W)=>{n.track({projectId:r,componentId:e,variantId:c,eventType:"goal_achieved",goalType:y,payload:{reward:T}}),n.goal(y,{metadata:{},weight:T,stepIndex:W})}},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,At.attachMicroSignalDetectors)((y,T={})=>{n.track({projectId:r,componentId:e,variantId:c,eventType:"micro_signal",payload:k({signalType:y},T)})},g,b)},[n,g,c,r,e,l]),(0,I.useEffect)(()=>{if(!R()||!n)return;let b=setTimeout(()=>{!C.current&&!wt.has(e)&&(wt.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 _=(0,I.useCallback)((b,y)=>{var W,te;if(l)return;let T=b!=null?b:s;T&&(n==null||n.componentGoal(e,T,y),n==null||n.goal(T,k(k(k({metadata:(W=y==null?void 0:y.metadata)!=null?W:{},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]),G=(0,I.useMemo)(()=>({ref:w,"data-sentient-id":e,"data-sentient-variant":c}),[w,e,c]);return{variant:c,value:m,bind:G,fireGoal:_}}var D=require("react");var kt=require("react/jsx-runtime"),pe=new Set;function _t(e){var s;let t=O(),n=V(),r=(0,D.useRef)(null),i=Object.keys(e.arrangements).join(" "),o=(0,D.useMemo)(()=>Object.keys(e.arrangements),[i]),f=(0,D.useMemo)(()=>k({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=D.Children.toArray(e.children).filter(D.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,D.useEffect)(()=>se({id:e.id,arms:Object.keys(e.arrangements)}),[e.id]);let w=(0,D.useRef)(null);(0,D.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,D.useEffect)(()=>{var a;!t||!x||d==="override"||U(t,n,e.id,x,P((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,D.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=j(e.goal),_=!1;return $(a,P(e.goal),{fireGoal:()=>{_||(_=!0,h!==void 0?t.componentGoal(e.id,p,{value:h}):t.componentGoal(e.id,p),t.goal(p,k({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]),(0,kt.jsx)("div",{ref:r,"data-sentient-id":e.id,"data-sentient-variant":l,children:C})}var xe=require("@sentientui/core");var Xt=["page","blocks","layoutOrder"],Ct=new Map;function Gt(e,t){Ct.set(e,t)}function _e(e){return Ct.get(e)}function Rt(e){var i,o;let t=(o=(i=e.content)!=null?i:_e(e.page))!=null?o:{},n={};for(let[f,l]of Object.entries(t))Xt.includes(f)||(n[f]=l);let r=re(k({},n),{page:e.page,blocks:e.blocks});return e.layoutOrder&&(r.layoutOrder=e.layoutOrder),r}function Ot(e){return`<script type="application/ld+json">${ke(e)}</script>`}function ke(e){return JSON.stringify(k({"@context":"https://schema.org","@type":"WebPage"},e)).replace(/</g,"\\u003c")}function Et(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
|
-
`}var
|
|
4
|
+
`}var It=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
|