@sentientui/react 0.18.5 → 0.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
3
  import { SentientConfig, SlotResult, SentientClient, MicroSignalType, ComponentGoalOptions } from '@sentientui/core';
4
- export { deriveSessionSegment as detectSegment } from '@sentientui/core';
4
+ export { deriveSessionSegment as detectSegment, grantConsent } from '@sentientui/core';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
 
7
7
  /** How to render adaptive slots during SSR when assignments are not preloaded. */
@@ -34,6 +34,37 @@ type AdaptiveProviderProps = {
34
34
  * initialise and begin tracking.
35
35
  */
36
36
  consent?: boolean;
37
+ /**
38
+ * Where to read the visitor's consent decision from, so the SDK can gate and
39
+ * un-gate itself instead of the host app wiring `grantConsent()` by hand.
40
+ *
41
+ * Keep your own banner or CMP — this only tells us how to observe it. The
42
+ * provider reads the source on mount, re-reads it whenever `event` fires, and
43
+ * initialises the moment it grants. Nothing is requested and no cookie is set
44
+ * until then, and there is no page reload.
45
+ *
46
+ * Because the provider owns the whole lifecycle there is no ordering rule to
47
+ * get right: pass this instead of managing `consent` yourself.
48
+ *
49
+ * @example // cookie written by your own banner
50
+ * consentFrom={{ cookie: 'cookie_consent', value: 'accepted', event: 'consent-decided' }}
51
+ * @example // a CMP that exposes an object rather than a cookie
52
+ * consentFrom={{ check: () => window.Cookiebot?.consent?.statistics === true,
53
+ * event: 'CookiebotOnAccept' }}
54
+ */
55
+ consentFrom?: {
56
+ /** Cookie to read. Granted when its value equals `value`. */
57
+ cookie?: string;
58
+ /** Cookie value that means granted. @default 'accepted' */
59
+ value?: string;
60
+ /** Predicate for CMPs with a JS API. Takes precedence over `cookie`. */
61
+ check?: () => boolean;
62
+ /**
63
+ * `window` event that signals a decision. The source is re-read when it
64
+ * fires — the event's payload is never trusted — so any CMP's event works.
65
+ */
66
+ event?: string;
67
+ };
37
68
  /**
38
69
  * Behavior before consent is granted. Pass `'statistical_winner'` to serve the
39
70
  * best-performing variant via `GET /v1/winner` with zero tracking while the
@@ -125,7 +156,7 @@ type AdaptiveProviderProps = {
125
156
  };
126
157
  /**
127
158
  * Initialises the Sentient core SDK in a useEffect (SSR-safe) and exposes the
128
- * client via React context. Re-initialises when `consent` changes.
159
+ * client via React context. Re-initialises when consent changes.
129
160
  */
130
161
  declare function AdaptiveProvider(props: AdaptiveProviderProps): JSX.Element;
131
162
  /**
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
3
  import { SentientConfig, SlotResult, SentientClient, MicroSignalType, ComponentGoalOptions } from '@sentientui/core';
4
- export { deriveSessionSegment as detectSegment } from '@sentientui/core';
4
+ export { deriveSessionSegment as detectSegment, grantConsent } from '@sentientui/core';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
 
7
7
  /** How to render adaptive slots during SSR when assignments are not preloaded. */
@@ -34,6 +34,37 @@ type AdaptiveProviderProps = {
34
34
  * initialise and begin tracking.
35
35
  */
36
36
  consent?: boolean;
37
+ /**
38
+ * Where to read the visitor's consent decision from, so the SDK can gate and
39
+ * un-gate itself instead of the host app wiring `grantConsent()` by hand.
40
+ *
41
+ * Keep your own banner or CMP — this only tells us how to observe it. The
42
+ * provider reads the source on mount, re-reads it whenever `event` fires, and
43
+ * initialises the moment it grants. Nothing is requested and no cookie is set
44
+ * until then, and there is no page reload.
45
+ *
46
+ * Because the provider owns the whole lifecycle there is no ordering rule to
47
+ * get right: pass this instead of managing `consent` yourself.
48
+ *
49
+ * @example // cookie written by your own banner
50
+ * consentFrom={{ cookie: 'cookie_consent', value: 'accepted', event: 'consent-decided' }}
51
+ * @example // a CMP that exposes an object rather than a cookie
52
+ * consentFrom={{ check: () => window.Cookiebot?.consent?.statistics === true,
53
+ * event: 'CookiebotOnAccept' }}
54
+ */
55
+ consentFrom?: {
56
+ /** Cookie to read. Granted when its value equals `value`. */
57
+ cookie?: string;
58
+ /** Cookie value that means granted. @default 'accepted' */
59
+ value?: string;
60
+ /** Predicate for CMPs with a JS API. Takes precedence over `cookie`. */
61
+ check?: () => boolean;
62
+ /**
63
+ * `window` event that signals a decision. The source is re-read when it
64
+ * fires — the event's payload is never trusted — so any CMP's event works.
65
+ */
66
+ event?: string;
67
+ };
37
68
  /**
38
69
  * Behavior before consent is granted. Pass `'statistical_winner'` to serve the
39
70
  * best-performing variant via `GET /v1/winner` with zero tracking while the
@@ -125,7 +156,7 @@ type AdaptiveProviderProps = {
125
156
  };
126
157
  /**
127
158
  * Initialises the Sentient core SDK in a useEffect (SSR-safe) and exposes the
128
- * client via React context. Re-initialises when `consent` changes.
159
+ * client via React context. Re-initialises when consent changes.
129
160
  */
130
161
  declare function AdaptiveProvider(props: AdaptiveProviderProps): JSX.Element;
131
162
  /**
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- "use strict";var St=Object.create;var q=Object.defineProperty,ht=Object.defineProperties,bt=Object.getOwnPropertyDescriptor,wt=Object.getOwnPropertyDescriptors,At=Object.getOwnPropertyNames,ye=Object.getOwnPropertySymbols,xt=Object.getPrototypeOf,he=Object.prototype.hasOwnProperty,kt=Object.prototype.propertyIsEnumerable;var Se=(e,t,n)=>t in e?q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,T=(e,t)=>{for(var n in t||(t={}))he.call(t,n)&&Se(e,n,t[n]);if(ye)for(var n of ye(t))kt.call(t,n)&&Se(e,n,t[n]);return e},Z=(e,t)=>ht(e,wt(t));var Ct=(e,t)=>{for(var n in t)q(e,n,{get:t[n],enumerable:!0})},be=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of At(t))!he.call(e,a)&&a!==n&&q(e,a,{get:()=>t[a],enumerable:!(o=bt(t,a))||o.enumerable});return e};var we=(e,t,n)=>(n=e!=null?St(xt(e)):{},be(t||!e||!e.__esModule?q(n,"default",{value:e,enumerable:!0}):n,e)),_t=e=>be(q({},"__esModule",{value:!0}),e);var Bt={};Ct(Bt,{Adaptive:()=>Ve,AdaptiveGroup:()=>ct,AdaptiveProvider:()=>De,AdaptiveText:()=>He,SentientPersonaScript:()=>et,buildAgentFeed:()=>pt,defineAgentContent:()=>gt,detectSegment:()=>de.deriveSessionSegment,getAgentContent:()=>fe,renderAgentJsonLd:()=>mt,renderAgentJsonLdBody:()=>ge,renderAgentMarkdown:()=>vt,useAdaptive:()=>ut,useAdaptiveApiBaseUrl:()=>We,useAdaptiveGoal:()=>qe,useAdaptivePersona:()=>it,useAdaptiveTokens:()=>st,useAssignment:()=>X,useInitialAssignments:()=>re,useLayoutOrder:()=>Ke,useSentient:()=>E});module.exports=_t(Bt);var A=require("react"),H=require("@sentientui/core");var Ae=new Map,ee=new Map;function xe(e,t){let n=ee.get(e);return n||(n=new Set,ee.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&ee.delete(e)}}function ke(e,t){Ae.set(e,t);let n=ee.get(e);if(n)for(let o of n)try{o(t)}catch(a){}}function Ce(e){var t;return(t=Ae.get(e))!=null?t:null}var Rt={on:!1,listeners:new Set};function _e(){if(typeof window=="undefined")return Rt;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function le(){return _e().on}function Re(e){let t=_e().listeners;return t.add(e),()=>{t.delete(e)}}function Ge(e){return{isLocal:e.isLocal,track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},fetchWeights:()=>Promise.resolve([]),getAssignment:(t,n)=>e.getAssignment(t,n),assign:(t,n,o,a)=>e.assign(t,n,o,a),decide:()=>Promise.resolve(null),getSlotResult:t=>e.getSlotResult(t),getPersona:()=>e.getPersona(),getGraph:()=>e.getGraph(),dispose:()=>e.dispose(),destroy:()=>e.destroy()}}var Oe="sentient:overrides-changed";function ue(){var e;return typeof window=="undefined"?0:(e=window.__sentient_overrides_version)!=null?e:0}function W(e){return typeof window=="undefined"?()=>{}:(window.addEventListener(Oe,e),()=>window.removeEventListener(Oe,e))}function Ee(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function O(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}function B(e){return typeof e=="string"?{type:"click"}:e}function J(e){return typeof e=="string"?e:e.type}function Gt(e){if(!(e instanceof Element))return!1;let t=e.tagName.toLowerCase();return t==="a"||t==="button"?!0:e.getAttribute("role")==="button"}function Le(e,t,n){if(n){try{let a=e;for(;a&&a!==t;){if(a.matches(n))return!0;a=a.parentElement}}catch(a){}return!1}let o=e;for(;o&&o!==t;){if(Gt(o))return!0;o=o.parentElement}return!1}function K(e,t,n){if(t.type==="weighted_composite"){let i=new Set,d=[];return t.steps.forEach(({goal:l,name:b,weight:f},y)=>{let S=()=>{i.has(y)||(i.add(y),n.fireStep(b,f,y))};if(l.type==="click"){let c=g=>{let p=g.target;p instanceof Element&&Le(p,e,l.selector)&&S()};e.addEventListener("click",c),d.push(()=>e.removeEventListener("click",c));return}if(l.type==="form_submit"){let c=g=>{g.target instanceof HTMLFormElement&&e.contains(g.target)&&S()};e.addEventListener("submit",c),d.push(()=>e.removeEventListener("submit",c));return}if(l.type==="scroll_depth"){let c=Math.max(0,Math.min(1,l.threshold)),g=new IntersectionObserver(p=>{for(let s of p)if(s.intersectionRatio>=c){S(),g.disconnect();break}},{threshold:[c]});g.observe(e),d.push(()=>g.disconnect())}}),()=>{for(let l of d)l()}}let o=t.type==="composite"?t.all:[t],a=new Set(o.map((i,d)=>d)),r=i=>{a.delete(i),a.size===0&&n.fireGoal()},u=[];return o.forEach((i,d)=>{if(i.type==="click"){let l=b=>{let f=b.target;f instanceof Element&&Le(f,e,i.selector)&&(t.type==="composite"?r(d):n.fireGoal())};e.addEventListener("click",l),u.push(()=>e.removeEventListener("click",l));return}if(i.type==="form_submit"){let l=b=>{b.target instanceof HTMLFormElement&&e.contains(b.target)&&(t.type==="composite"?r(d):n.fireGoal())};e.addEventListener("submit",l),u.push(()=>e.removeEventListener("submit",l));return}if(i.type==="scroll_depth"){let l=Math.max(0,Math.min(1,i.threshold)),b=new IntersectionObserver(f=>{for(let y of f)if(y.intersectionRatio>=l){t.type==="composite"?r(d):n.fireGoal(),b.disconnect();break}},{threshold:[l]});b.observe(e),u.push(()=>b.disconnect());return}}),()=>{for(let i of u)i()}}function N(e,t,n,o){e.track({projectId:t,componentId:n,variantId:o,eventType:"variant_assigned",payload:{}})}var Ot={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function U(){if(typeof window=="undefined")return Ot;let e=window;return e.__sentient_registry||(e.__sentient_registry={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0}),e.__sentient_registry}function Q(){U().version+=1;for(let e of U().listeners)e()}var Ie=()=>{};function te(e){return O()?(U().components.set(e.id,e),Q(),()=>{U().components.delete(e.id),Q()}):Ie}function ne(e){return O()?(U().slots.set(e.id,e),Q(),()=>{U().slots.delete(e.id),Q()}):Ie}function Te(e){O()&&(U().sections=[...e],Q())}var Ne=require("react/jsx-runtime");function Et(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{let n=(0,H.detectDeviceClass)((e=navigator.userAgent)!=null?e:""),o=(0,H.detectTrafficSource)((t=document.referrer)!=null?t:"",window.location.origin);return`${n}:${o}`}catch(n){return"desktop:direct"}}var Pe="https://api.sentient-ui.com/v1",P=(0,A.createContext)({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialPersona:null,apiBaseUrl:Pe,debug:!1});function De(e){var f,y;let[t,n]=(0,A.useState)(null),[o]=(0,A.useState)(()=>{var S;return(S=e.sessionSegment)!=null?S:Et()}),[a,r]=(0,A.useState)(le());(0,A.useEffect)(()=>Re(()=>r(le())),[]),(0,A.useEffect)(()=>{if(e.consent===!1&&!e.preConsentBehavior){n(m=>(m==null||m.destroy(),null));return}let S={apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,sessionSegment:o,consent:e.consent,preConsentBehavior:e.preConsentBehavior,respectDoNotTrack:e.respectDoNotTrack,ssrSessionId:e.ssrSessionId,country:e.country,localMode:e.localMode,initialSlots:e.initialSlots,initialPersona:e.initialPersona,ingestUrl:e.apiBaseUrl?`${e.apiBaseUrl.replace(/\/$/,"")}/events`:void 0},c=!1,g=null,p=null,s=m=>{e.engagement!==!1&&import("@sentientui/core/engagement").then(({startEngagementCapture:h})=>{c||(p=h(m,{apiKey:e.apiKey,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:m})=>{c||(g=m(Z(T({},S),{graph:!0,captureDomText:e.captureDomText===!0})),n(g),s(g))}):(g=(0,H.init)(S),n(g),s(g)),()=>{c=!0,p==null||p(),g==null||g.dispose()}},[e.consent]),(0,A.useEffect)(()=>{if(!t)return;let S=!1,c=async()=>{if(S)return;let p;try{p=await t.fetchWeights()}catch(s){return}if(!S)for(let s of p){let m={componentId:s.componentId,updatedAt:s.updatedAt,variants:s.variants.map(h=>{var k;return{variantId:h.variantId,pulls:h.pulls,avgReward:(k=h.avgReward)!=null?k:0}})};ke(s.componentId,m)}};c();let g=setInterval(()=>{c()},6e4);return()=>{S=!0,clearInterval(g)}},[t]);let u=(f=e.ssrFallback)!=null?f:"first",i=((y=e.apiBaseUrl)!=null?y:Pe).replace(/\/$/,""),d=(0,A.useRef)(null);(0,A.useEffect)(()=>{var g;if(typeof process!="undefined"&&((g=process.env)==null?void 0:g.NODE_ENV)==="production")return;let S={apiKey:e.apiKey,context:e.context,country:e.country,apiBaseUrl:i},c=d.current;if(d.current=S,c!==null)for(let p of["apiKey","context","country","apiBaseUrl"])Object.is(c[p],S[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,i]),(0,A.useEffect)(()=>{var S;typeof process!="undefined"&&((S=process.env)==null?void 0:S.NODE_ENV)==="production"||Ee({apiKey:e.apiKey,apiBaseUrl:i,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,i]),(0,A.useEffect)(()=>{e.initialLayoutOrder&&e.initialLayoutOrder.length>0&&Te(e.initialLayoutOrder)},[e.initialLayoutOrder]);let l=(0,A.useMemo)(()=>t&&a?Ge(t):t,[t,a]),b=(0,A.useMemo)(()=>{var S,c,g,p,s;return{client:l,apiKey:e.apiKey,initialAssignments:(S=e.initialAssignments)!=null?S:{},sessionSegment:o,ssrFallback:u,onAssignment:e.onAssignment,initialLayoutOrder:(c=e.initialLayoutOrder)!=null?c:null,initialSlots:(g=e.initialSlots)!=null?g:{},initialPersona:(p=e.initialPersona)!=null?p:null,apiBaseUrl:i,debug:(s=e.debug)!=null?s:!1}},[l,e.apiKey,e.initialAssignments,o,u,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialPersona,i,e.debug]);return(0,Ne.jsx)(P.Provider,{value:b,children:e.children})}function E(){return(0,A.useContext)(P).client}function j(){return(0,A.useContext)(P).apiKey}function re(){return(0,A.useContext)(P).initialAssignments}function ie(){return(0,A.useContext)(P).sessionSegment}function Me(){return(0,A.useContext)(P).ssrFallback}function oe(){return(0,A.useContext)(P).onAssignment}function Be(){return(0,A.useContext)(P).debug}function Ke(){let e=(0,A.useContext)(P).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 je(){return(0,A.useContext)(P).initialSlots}function Fe(){return(0,A.useContext)(P).initialPersona}function We(){return(0,A.useContext)(P).apiBaseUrl}var R=require("react"),$e=require("@sentientui/core");var D=require("react");function z(e){var n;if(typeof window=="undefined")return null;let t=(n=window.__sentient_overrides)==null?void 0:n[e];if(t)return t;if(!window.location.search)return null;try{let o=new URLSearchParams(window.location.search);for(let a of o.getAll("sentient_variant")){let r=a.indexOf(":");if(r!==-1&&a.slice(0,r)===e)return a.slice(r+1)}}catch(o){}return null}var Lt=5;function Ue(e,t){var o,a;let n=null;for(let r of e.variants){if(!t.includes(r.variantId))continue;let u=(o=r.pulls)!=null?o:0,i=u>0?u*r.avgReward/(u+Lt):0;(!n||i>n.score)&&(n={variantId:r.variantId,score:i})}return(a=n==null?void 0:n.variantId)!=null?a:null}function X(e,t,n,o){let a=re(),r=Me(),u=E(),i=ie(),d=oe(),l=Be(),b=(0,D.useRef)(null),f=(0,D.useSyncExternalStore)(W,()=>z(e),()=>null),y=f&&t.includes(f)?f:null,S=(0,D.useRef)(null);(0,D.useEffect)(()=>{l&&y&&S.current!==y&&(S.current=y,console.info(`[sentient] override active: ${e} -> ${y}`))},[l,y,e]);let[c,g]=(0,D.useState)(()=>{var h,k;if(y)return{variantId:y,content:null,isLoading:!1,settled:!0};if(!u){let C=a[e];return C&&t.includes(C)?{variantId:C,content:null,isLoading:!1,settled:!0}:r==="first"&&t.length>0?{variantId:t[0],content:null,isLoading:!1,settled:!1}:{variantId:null,content:null,isLoading:!0,settled:!1}}let s=u.getAssignment(e,i);if(s&&(t.includes(s.variantId)||s.content))return{variantId:s.variantId,content:(h=s.content)!=null?h:null,isLoading:!1,settled:!0};let m=Ce(e);if(m){let C=Ue(m,t);if(C)return{variantId:C,content:null,isLoading:!1,settled:!0}}return{variantId:(k=t[0])!=null?k:null,content:null,isLoading:!1,settled:!1}}),p=s=>{d&&b.current!==s&&(b.current=s,d(e,s))};return(0,D.useEffect)(()=>{var m;if(y||!u)return;let s=u.getAssignment(e,i);if(s&&(t.includes(s.variantId)||s.content)){g({variantId:s.variantId,content:(m=s.content)!=null?m:null,isLoading:!1,settled:!0}),p(s.variantId);return}g(h=>{var k;return h.variantId?h:{variantId:(k=t[0])!=null?k:null,content:null,isLoading:!1,settled:!1}})},[y,u,e,i]),(0,D.useEffect)(()=>{if(y||!u)return;let s=u.getAssignment(e,i);if(s&&t.includes(s.variantId))return;let m=!1;return u.assign(e,t,n,o).then(h=>{var k;m||h&&(!t.includes(h.variantId)&&!h.content||(g({variantId:h.variantId,content:(k=h.content)!=null?k:null,isLoading:!1,settled:!0}),p(h.variantId)))}),()=>{m=!0}},[y,u,e,i]),(0,D.useEffect)(()=>{if(!y&&u)return xe(e,s=>{var k;let m=u.getAssignment(e,i);if(m&&(t.includes(m.variantId)||m.content)){g({variantId:m.variantId,content:(k=m.content)!=null?k:null,isLoading:!1,settled:!0});return}let h=Ue(s,t);h&&g({variantId:h,content:null,isLoading:!1,settled:!0})})},[y,u,e,i]),y?{variantId:y,content:null,isLoading:!1,settled:!0,isOverride:!0}:c}var Je=require("react/jsx-runtime");function It(e){var k;let t=E(),n=j(),o=Object.keys(e.variants).join("\0"),a=(0,R.useMemo)(()=>Object.keys(e.variants),[o]),{variantId:r,content:u,isOverride:i,settled:d}=X(e.id,a,e.agentData,e.agentDataByVariant),l=(0,R.useRef)(null),[b,f]=(0,R.useState)(!1);(0,R.useEffect)(()=>{f(!0)},[]);let y=(0,R.useRef)(!1),S=(0,R.useRef)(new Set),c=(0,R.useRef)(null),g=typeof e.goal=="string"?e.goal:JSON.stringify(e.goal),p=(0,R.useMemo)(()=>B(e.goal),[g]),s=typeof e.goal=="string"?e.goal:p.type;if((0,R.useEffect)(()=>te({id:e.id,variantIds:a,goal:s}),[e.id,a,s]),(0,R.useEffect)(()=>{i||d&&(!t||!r||!n||c.current!==r&&(c.current=r,N(t,n,e.id,r)))},[t,r,n,e.id,i,d]),(0,R.useEffect)(()=>{y.current=!1,S.current=new Set},[r,p]),(0,R.useEffect)(()=>{if(i||!d||!t||!r)return;let C=l.current;if(!C)return;let _=null,v=0,w=()=>{v=Date.now(),_=setTimeout(()=>{t.track({projectId:n,componentId:e.id,variantId:r,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-v}}),_=null},800)},x=()=>{_!==null&&(clearTimeout(_),_=null)};return C.addEventListener("mouseenter",w),C.addEventListener("mouseleave",x),()=>{C.removeEventListener("mouseenter",w),C.removeEventListener("mouseleave",x),_!==null&&clearTimeout(_)}},[t,r,n,e.id,i,d]),(0,R.useEffect)(()=>{if(i||!d||!t||!r)return;let C=l.current;if(!C)return;let _=Date.now();return(0,$e.attachMicroSignalDetectors)((v,w={})=>{var pe,me,ve;t.track({projectId:n,componentId:e.id,variantId:r,eventType:"micro_signal",payload:T({signalType:v},w)});let x=(pe=e.microSignalGoals)==null?void 0:pe[v];if(!x||S.current.has(v))return;S.current.add(v);let V=typeof x=="string"?x:x.name,Y=typeof x=="string"?1:(me=x.weight)!=null?me:1,yt=typeof x=="string"?0:(ve=x.stepIndex)!=null?ve:0;t.goal(V,T({signalType:v},w),Y,yt)},C,_)},[t,r,n,e.id,e.microSignalGoals,i,d]),(0,R.useEffect)(()=>{if(i||!t||!r)return;let C=l.current;if(C)return K(C,p,{fireGoal:()=>{y.current||(y.current=!0,t.track({projectId:n,componentId:e.id,variantId:r,eventType:"goal_achieved",goalType:s,payload:{reward:1}}),t.goal(s,{componentId:e.id,variantId:r},1,0))},fireStep:(_,v,w)=>{t.track({projectId:n,componentId:e.id,variantId:r,eventType:"goal_achieved",goalType:_,payload:{reward:v}}),t.goal(_,{},v,w)}})},[t,r,n,e.id,p,s,i]),e.clientOnly&&(!b||!t)||!r)return null;let m=(k=e.variants[r])!=null?k:null,h=m===null?u:null;return O()&&m===null&&h===null&&console.warn(`[sentient] <Adaptive id="${e.id}"> was assigned variant "${r}" but no matching key exists in props.variants. If this is a dashboard-managed text variant, use <AdaptiveText id="${e.id}"> instead.`),(0,Je.jsx)("div",{ref:l,"data-sentient-id":e.id,"data-sentient-variant":r,children:m!=null?m:h})}var Ve=(0,R.memo)(It,(e,t)=>{if(e.id!==t.id||e.goal!==t.goal&&JSON.stringify(e.goal)!==JSON.stringify(t.goal)||e.microSignalGoals!==t.microSignalGoals||e.clientOnly!==t.clientOnly||e.agentData!==t.agentData||e.agentDataByVariant!==t.agentDataByVariant)return!1;if(e.variants===t.variants)return!0;let n=Object.keys(e.variants),o=Object.keys(t.variants);return n.length!==o.length?!1:n.every(a=>a in t.variants&&Object.is(e.variants[a],t.variants[a]))});var L=require("react");var ze=require("react/jsx-runtime");function He({id:e,default:t,component:n="span",className:o,goal:a}){var _;let r=E(),u=j(),i=oe(),d=ie(),l=(0,L.useRef)(null),b=(0,L.useRef)(null),f=(0,L.useSyncExternalStore)(W,()=>z(e),()=>null),[y,S]=(0,L.useState)(()=>{var v,w;return(w=(v=r==null?void 0:r.getAssignment(e,d))==null?void 0:v.content)!=null?w:null}),[c,g]=(0,L.useState)(()=>{var v,w;return(w=(v=r==null?void 0:r.getAssignment(e,d))==null?void 0:v.variantId)!=null?w:null});(0,L.useEffect)(()=>{var w;if(f||!r||((w=r.getAssignment(e,d))==null?void 0:w.content)!==void 0)return;let v=!1;return r.assign(e).then(x=>{if(!v){if(!x){O()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}g(x.variantId),x.content&&S(x.content)}}),()=>{v=!0}},[r,e,d,f]),(0,L.useEffect)(()=>{f||!r||!c||!u||l.current!==c&&(l.current=c,r.track({projectId:u,componentId:e,variantId:c,eventType:"variant_assigned",payload:{}}),i==null||i(e,c))},[r,c,u,e,i,f]);let p=a===void 0?"":typeof a=="string"?a:JSON.stringify(a),s=(0,L.useMemo)(()=>a===void 0?null:B(a),[p]),m=a===void 0?null:typeof a=="string"?a:s.type,h=(0,L.useRef)(!1);(0,L.useEffect)(()=>{h.current=!1},[c,p]),(0,L.useEffect)(()=>{if(f||!r||!c||!u||!s||!m)return;let v=b.current;if(v)return K(v,s,{fireGoal:()=>{h.current||(h.current=!0,r.track({projectId:u,componentId:e,variantId:c,eventType:"goal_achieved",goalType:m,payload:{reward:1}}),r.goal(m,{componentId:e,variantId:c},1,0))},fireStep:(w,x,V)=>{r.track({projectId:u,componentId:e,variantId:c,eventType:"goal_achieved",goalType:w,payload:{reward:x}}),r.goal(w,{},x,V)}})},[r,c,u,e,s,m,f]);let k=y!=null?y:t;if(f){let v=r==null?void 0:r.getAssignment(e,d);k=v&&v.variantId===f&&(_=v.content)!=null?_:t}return(0,ze.jsx)(n,{ref:v=>{b.current=v},className:o,children:k})}var Xe=require("react");function qe(e){let t=E();return(0,Xe.useCallback)((n,o)=>{var a,r;z(e)||(t==null||t.componentGoal(e,n,o),t==null||t.goal(n,(a=o==null?void 0:o.metadata)!=null?a:{},(r=o==null?void 0:o.reward)!=null?r:1,0))},[t,e])}var Ye=require("@sentientui/core"),Ze=require("@sentientui/policy"),tt=require("react/jsx-runtime");function Qe(e){return JSON.stringify(e).replace(/</g,"\\u003c")}function Tt(e){return e.persona?'(function(){try{var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",'+Qe(e.persona.persona)+');d.setAttribute("data-sentient-confidence",'+Qe((0,Ze.confidenceBand)(e.persona.confidence))+");}catch(e){}})();":(0,Ye.renderPrePaintScript)(e.apiKey)}function et(e){return(0,tt.jsx)("script",{"data-sentient-persona-script":"",nonce:e.nonce,dangerouslySetInnerHTML:{__html:Tt(e)}})}var F=require("react"),ot=require("@sentientui/policy");var M=require("react"),$=require("@sentientui/core"),rt=require("@sentientui/policy");var nt=new Set;function se(e,t){var b;(0,M.useSyncExternalStore)(W,ue,()=>0);let n=E(),o=je(),[,a]=(0,M.useReducer)(f=>f+1,0),r=typeof window!="undefined"?(b=window.__sentient_slot_overrides)==null?void 0:b[e]:void 0,u=r===void 0?o[e]:void 0,i=r===void 0&&u===void 0&&n?n.getSlotResult(e):null,d=(n==null?void 0:n.isLocal)===!0&&r===void 0&&u===void 0&&i===null;(0,M.useEffect)(()=>{if(!d||!n)return;let f=!1;return n.decide({slots:[t]}).then(y=>{!f&&y&&a()}),()=>{f=!0}},[n,e,d]);let l=(()=>{if(r!==void 0)return{result:r,arm:(0,$.armOfResult)(r),source:"override"};if(u!==void 0)return{result:u,arm:(0,$.armOfResult)(u),source:"preloaded"};if(i!==null)return{result:i,arm:(0,$.armOfResult)(i),source:"client"};let f=(0,$.baselineResultFor)(t);return{result:f,arm:(0,$.armOfResult)(f),source:"baseline"}})();return(0,M.useEffect)(()=>{O()&&(!n||n.isLocal===!0||l.source==="baseline"&&(nt.has(e)||(nt.add(e),console.warn(`[sentient] slot "${e}" resolved to its baseline \u2014 no SSR-preloaded or decided result. Keyed clients decide slots server-side, so this slot serves baseline for the whole session and records no exposure. Preload it via loadAdaptiveDecision()/initialSlots so it can serve a decided arm and learn.`))))},[n,l.source,e]),l}function Pt(){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 it(){let e=E(),t=Fe();(0,M.useSyncExternalStore)(W,ue,()=>0);let[n,o]=(0,M.useState)(!1);(0,M.useEffect)(()=>o(!0),[]);let a=i=>({persona:i.persona,confidence:i.confidence,band:(0,rt.confidenceBand)(i.confidence)});if(!n)return t?a(t):null;let r=Pt();if(r)return a(r);if(t)return a(t);let u=e?e.getPersona():null;return u?a(u):null}var ce=new Set;function Dt(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/[\\"]/g,"\\$&")}function st(e,t,n){let o=E(),a=j(),r=JSON.stringify(t),u=(0,F.useMemo)(()=>({id:e,dims:t}),[e,r]),{result:i,arm:d,source:l}=se(e,u),b=(0,F.useMemo)(()=>typeof i=="string"?{}:i,[d]);if(O()&&!ce.has(e)){let c=(0,ot.validateSlotDecl)({id:e,dims:Object.fromEntries(Object.entries(t).map(([p,s])=>[p,[...s]]))}),g=Object.values(t).reduce((p,s)=>p*s.length,1);c.ok?g>4&&(ce.add(e),console.warn(`[sentient] useAdaptiveTokens("${e}") declares ${g} combinations \u2014 more than the recommended 4. Each extra combination needs more traffic to learn; consider fewer dims/values.`)):(ce.add(e),console.warn(`[sentient] useAdaptiveTokens("${e}"): invalid declaration \u2014 ${c.reason}. Serving baseline.`))}let f=(n==null?void 0:n.goal)===void 0?null:typeof n.goal=="string"?n.goal:JSON.stringify(n.goal);(0,F.useEffect)(()=>ne({id:e,dims:t}),[e]);let y=(0,F.useRef)(null);(0,F.useEffect)(()=>{!o||l==="baseline"||l==="override"||y.current===d||(y.current=d,N(o,a,e,d))},[o,a,e,d,l]),(0,F.useEffect)(()=>{if(!o||!(n!=null&&n.goal)||l==="override")return;let c=document.querySelector(`[data-sentient-slot="${Dt(e)}"]`);if(!c){O()&&console.warn(`[sentient] useAdaptiveTokens("${e}"): a goal is declared but no element carries the returned props \u2014 spread {...props} on the slot's element.`);return}let g=J(n.goal),p=!1;return K(c,B(n.goal),{fireGoal:()=>{p||(p=!0,o.componentGoal(e,g),o.goal(g,{componentId:e,arm:d},1,0))},fireStep:(s,m,h)=>{o.componentGoal(e,s,{reward:m}),o.goal(s,{componentId:e,arm:d},m,h)}})},[o,e,f,d,l]);let S=(0,F.useMemo)(()=>{let c={"data-sentient-slot":e};for(let[g,p]of Object.entries(b))c[`data-${g}`]=p;return c},[e,b]);return{tokens:b,props:S}}var G=require("react"),lt=require("@sentientui/core");var at=new Set;function ut(e,t){var _;if(O()&&!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=E(),o=j(),a=Object.keys(t.variants).join(" "),r=(0,G.useMemo)(()=>Object.keys(t.variants),[a]),{variantId:u,isOverride:i,settled:d}=X(e,r),l=(_=u!=null?u:r[0])!=null?_:"",b=t.variants[l],[f,y]=(0,G.useState)(null),S=(0,G.useRef)(null),c=(0,G.useCallback)(v=>{S.current=v,y(v)},[]),g=typeof t.goal=="string"?t.goal:JSON.stringify(t.goal),p=(0,G.useMemo)(()=>B(t.goal),[g]),s=J(t.goal);(0,G.useEffect)(()=>te({id:e,variantIds:r,goal:s}),[e,r,s]);let m=(0,G.useRef)(null);(0,G.useEffect)(()=>{i||d&&(!n||!l||!f||m.current!==l&&(m.current=l,N(n,o,e,l)))},[n,o,e,l,f,i,d]);let h=(0,G.useRef)(!1);(0,G.useEffect)(()=>{h.current=!1},[l,g]),(0,G.useEffect)(()=>{if(!i&&!(!n||!l||!f))return K(f,p,{fireGoal:()=>{h.current||(h.current=!0,n.track({projectId:o,componentId:e,variantId:l,eventType:"goal_achieved",goalType:s,payload:{reward:1}}),n.goal(s,{componentId:e,variantId:l},1,0))},fireStep:(v,w,x)=>{n.track({projectId:o,componentId:e,variantId:l,eventType:"goal_achieved",goalType:v,payload:{reward:w}}),n.goal(v,{},w,x)}})},[n,f,l,o,e,p,s,i]),(0,G.useEffect)(()=>{if(i||!n||!l||!f)return;let v=Date.now();return(0,lt.attachMicroSignalDetectors)((w,x={})=>{n.track({projectId:o,componentId:e,variantId:l,eventType:"micro_signal",payload:T({signalType:w},x)})},f,v)},[n,f,l,o,e,i]),(0,G.useEffect)(()=>{if(!O()||!n)return;let v=setTimeout(()=>{!S.current&&!at.has(e)&&(at.add(e),console.warn(`[sentient] useAdaptive("${e}"): bind was never attached \u2014 spread {...bind} on the rendered element, otherwise exposure and goal tracking cannot work and the optimizer learns nothing.`))},0);return()=>clearTimeout(v)},[n,e]);let k=(0,G.useCallback)((v,w)=>{var V,Y;if(i)return;let x=v!=null?v:s;n==null||n.componentGoal(e,x,w),n==null||n.goal(x,(V=w==null?void 0:w.metadata)!=null?V:{},(Y=w==null?void 0:w.reward)!=null?Y:1,0)},[n,e,s,i]),C=(0,G.useMemo)(()=>({ref:c,"data-sentient-id":e,"data-sentient-variant":l}),[c,e,l]);return{variant:l,value:b,bind:C,fireGoal:k}}var I=require("react");var dt=require("react/jsx-runtime"),ae=new Set;function ct(e){var p;let t=E(),n=j(),o=(0,I.useRef)(null),a=Object.keys(e.arrangements).join(" "),r=(0,I.useMemo)(()=>Object.keys(e.arrangements),[a]),u=(0,I.useMemo)(()=>T({id:e.id,arms:r},e.baseline!==void 0?{baseline:e.baseline}:{}),[e.id,r,e.baseline]),{arm:i,source:d}=se(e.id,u);O()&&e.baseline!==void 0&&e.baseline!==r[0]&&!ae.has(e.id+":baseline")&&(ae.add(e.id+":baseline"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: baseline "${e.baseline}" is not the first-declared arrangement ("${r[0]}"). The first arrangement should usually be the page's real incumbent (the holdout sees it).`));let l=I.Children.toArray(e.children).filter(I.isValidElement),b=new Map;for(let s of l)b.set(String((p=s.key)!=null?p:"").replace(/^\.\$/,""),s);let f=e.arrangements[i],y=f!==void 0&&f.length===l.length&&f.every(s=>b.has(s));O()&&f!==void 0&&!y&&!ae.has(e.id+":keys")&&(ae.add(e.id+":keys"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: arrangement "${i}" [${f.join(", ")}] does not match the children's keys \u2014 rendering declaration order (fail-safe).`));let S=y?f.map(s=>b.get(s)):l;(0,I.useEffect)(()=>ne({id:e.id,arms:Object.keys(e.arrangements)}),[e.id]);let c=(0,I.useRef)(null);(0,I.useEffect)(()=>{!t||d==="baseline"||d==="override"||c.current===i||(c.current=i,N(t,n,e.id,i))},[t,n,e.id,i,d]);let g=e.goal===void 0?null:typeof e.goal=="string"?e.goal:JSON.stringify(e.goal);return(0,I.useEffect)(()=>{if(!t||e.goal===void 0||d==="override")return;let s=o.current;if(!s)return;let m=J(e.goal),h=!1;return K(s,B(e.goal),{fireGoal:()=>{h||(h=!0,t.componentGoal(e.id,m),t.goal(m,{componentId:e.id,arm:i},1,0))},fireStep:(k,C,_)=>{t.componentGoal(e.id,k,{reward:C}),t.goal(k,{componentId:e.id,arm:i},C,_)}})},[t,e.id,g,i,d]),(0,dt.jsx)("div",{ref:o,"data-sentient-id":e.id,"data-sentient-variant":i,children:S})}var de=require("@sentientui/core");var Mt=["page","blocks","layoutOrder"],ft=new Map;function gt(e,t){ft.set(e,t)}function fe(e){return ft.get(e)}function pt(e){var a,r;let t=(r=(a=e.content)!=null?a:fe(e.page))!=null?r:{},n={};for(let[u,i]of Object.entries(t))Mt.includes(u)||(n[u]=i);let o=Z(T({},n),{page:e.page,blocks:e.blocks});return e.layoutOrder&&(o.layoutOrder=e.layoutOrder),o}function mt(e){return`<script type="application/ld+json">${ge(e)}</script>`}function ge(e){return JSON.stringify(T({"@context":"https://schema.org","@type":"WebPage"},e)).replace(/</g,"\\u003c")}function vt(e){let t=[];e.title&&t.push(`# ${e.title}`,""),e.summary&&t.push(String(e.summary),"");for(let[n,o]of Object.entries(e))["page","title","summary","blocks","layoutOrder"].includes(n)||t.push(`## ${n}`,"","```json",JSON.stringify(o,null,2),"```","");if(e.blocks.length>0){t.push("## blocks","");for(let n of e.blocks)t.push(`- **${n.id}** \u2192 variant \`${n.variant}\``),n.content!==void 0&&t.push(""," ```json",JSON.stringify(n.content,null,2)," ```");t.push("")}return t.join(`
2
+ "use strict";var ht=Object.create;var q=Object.defineProperty,bt=Object.defineProperties,wt=Object.getOwnPropertyDescriptor,At=Object.getOwnPropertyDescriptors,xt=Object.getOwnPropertyNames,ye=Object.getOwnPropertySymbols,kt=Object.getPrototypeOf,he=Object.prototype.hasOwnProperty,Ct=Object.prototype.propertyIsEnumerable;var Se=(e,t,n)=>t in e?q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,P=(e,t)=>{for(var n in t||(t={}))he.call(t,n)&&Se(e,n,t[n]);if(ye)for(var n of ye(t))Ct.call(t,n)&&Se(e,n,t[n]);return e},Z=(e,t)=>bt(e,At(t));var Rt=(e,t)=>{for(var n in t)q(e,n,{get:t[n],enumerable:!0})},be=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of xt(t))!he.call(e,a)&&a!==n&&q(e,a,{get:()=>t[a],enumerable:!(i=wt(t,a))||i.enumerable});return e};var we=(e,t,n)=>(n=e!=null?ht(kt(e)):{},be(t||!e||!e.__esModule?q(n,"default",{value:e,enumerable:!0}):n,e)),_t=e=>be(q({},"__esModule",{value:!0}),e);var Kt={};Rt(Kt,{Adaptive:()=>Ve,AdaptiveGroup:()=>ut,AdaptiveProvider:()=>De,AdaptiveText:()=>He,SentientPersonaScript:()=>et,buildAgentFeed:()=>pt,defineAgentContent:()=>gt,detectSegment:()=>de.deriveSessionSegment,getAgentContent:()=>fe,grantConsent:()=>yt.grantConsent,renderAgentJsonLd:()=>mt,renderAgentJsonLdBody:()=>ge,renderAgentMarkdown:()=>vt,useAdaptive:()=>ct,useAdaptiveApiBaseUrl:()=>We,useAdaptiveGoal:()=>qe,useAdaptivePersona:()=>it,useAdaptiveTokens:()=>st,useAssignment:()=>X,useInitialAssignments:()=>re,useLayoutOrder:()=>Fe,useSentient:()=>E});module.exports=_t(Kt);var b=require("react"),H=require("@sentientui/core");var Ae=new Map,ee=new Map;function xe(e,t){let n=ee.get(e);return n||(n=new Set,ee.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&ee.delete(e)}}function ke(e,t){Ae.set(e,t);let n=ee.get(e);if(n)for(let i of n)try{i(t)}catch(a){}}function Ce(e){var t;return(t=Ae.get(e))!=null?t:null}var Gt={on:!1,listeners:new Set};function Re(){if(typeof window=="undefined")return Gt;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function le(){return Re().on}function _e(e){let t=Re().listeners;return t.add(e),()=>{t.delete(e)}}function Ge(e){return{isLocal:e.isLocal,track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},fetchWeights:()=>Promise.resolve([]),getAssignment:(t,n)=>e.getAssignment(t,n),assign:(t,n,i,a)=>e.assign(t,n,i,a),decide:()=>Promise.resolve(null),getSlotResult:t=>e.getSlotResult(t),getPersona:()=>e.getPersona(),getGraph:()=>e.getGraph(),dispose:()=>e.dispose(),destroy:()=>e.destroy()}}var Oe="sentient:overrides-changed";function ce(){var e;return typeof window=="undefined"?0:(e=window.__sentient_overrides_version)!=null?e:0}function W(e){return typeof window=="undefined"?()=>{}:(window.addEventListener(Oe,e),()=>window.removeEventListener(Oe,e))}function Ee(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function O(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}function B(e){return typeof e=="string"?{type:"click"}:e}function J(e){return typeof e=="string"?e:e.type}function Ot(e){if(!(e instanceof Element))return!1;let t=e.tagName.toLowerCase();return t==="a"||t==="button"?!0:e.getAttribute("role")==="button"}function Le(e,t,n){if(n){try{let a=e;for(;a&&a!==t;){if(a.matches(n))return!0;a=a.parentElement}}catch(a){}return!1}let i=e;for(;i&&i!==t;){if(Ot(i))return!0;i=i.parentElement}return!1}function F(e,t,n){if(t.type==="weighted_composite"){let o=new Set,u=[];return t.steps.forEach(({goal:l,name:h,weight:d},p)=>{let C=()=>{o.has(p)||(o.add(p),n.fireStep(h,d,p))};if(l.type==="click"){let m=f=>{let v=f.target;v instanceof Element&&Le(v,e,l.selector)&&C()};e.addEventListener("click",m),u.push(()=>e.removeEventListener("click",m));return}if(l.type==="form_submit"){let m=f=>{f.target instanceof HTMLFormElement&&e.contains(f.target)&&C()};e.addEventListener("submit",m),u.push(()=>e.removeEventListener("submit",m));return}if(l.type==="scroll_depth"){let m=Math.max(0,Math.min(1,l.threshold)),f=new IntersectionObserver(v=>{for(let s of v)if(s.intersectionRatio>=m){C(),f.disconnect();break}},{threshold:[m]});f.observe(e),u.push(()=>f.disconnect())}}),()=>{for(let l of u)l()}}let i=t.type==="composite"?t.all:[t],a=new Set(i.map((o,u)=>u)),r=o=>{a.delete(o),a.size===0&&n.fireGoal()},c=[];return i.forEach((o,u)=>{if(o.type==="click"){let l=h=>{let d=h.target;d instanceof Element&&Le(d,e,o.selector)&&(t.type==="composite"?r(u):n.fireGoal())};e.addEventListener("click",l),c.push(()=>e.removeEventListener("click",l));return}if(o.type==="form_submit"){let l=h=>{h.target instanceof HTMLFormElement&&e.contains(h.target)&&(t.type==="composite"?r(u):n.fireGoal())};e.addEventListener("submit",l),c.push(()=>e.removeEventListener("submit",l));return}if(o.type==="scroll_depth"){let l=Math.max(0,Math.min(1,o.threshold)),h=new IntersectionObserver(d=>{for(let p of d)if(p.intersectionRatio>=l){t.type==="composite"?r(u):n.fireGoal(),h.disconnect();break}},{threshold:[l]});h.observe(e),c.push(()=>h.disconnect());return}}),()=>{for(let o of c)o()}}function N(e,t,n,i){e.track({projectId:t,componentId:n,variantId:i,eventType:"variant_assigned",payload:{}})}var Et={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function $(){if(typeof window=="undefined")return Et;let e=window;return e.__sentient_registry||(e.__sentient_registry={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0}),e.__sentient_registry}function Q(){$().version+=1;for(let e of $().listeners)e()}var Ie=()=>{};function te(e){return O()?($().components.set(e.id,e),Q(),()=>{$().components.delete(e.id),Q()}):Ie}function ne(e){return O()?($().slots.set(e.id,e),Q(),()=>{$().slots.delete(e.id),Q()}):Ie}function Pe(e){O()&&($().sections=[...e],Q())}var Ne=require("react/jsx-runtime");function Lt(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{let n=(0,H.detectDeviceClass)((e=navigator.userAgent)!=null?e:""),i=(0,H.detectTrafficSource)((t=document.referrer)!=null?t:"",window.location.origin);return`${n}:${i}`}catch(n){return"desktop:direct"}}var Te="https://api.sentient-ui.com/v1",T=(0,b.createContext)({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialPersona:null,apiBaseUrl:Te,debug:!1});function It(e){let[t,n]=(0,b.useState)(!1),i=(0,b.useRef)(e);i.current=e;let{cookie:a,value:r,event:c}=e!=null?e:{},o=typeof(e==null?void 0:e.check)=="function";return(0,b.useEffect)(()=>{let u=()=>{var p;let h=i.current;if(!h)return!1;if(h.check)return h.check()===!0;if(!h.cookie||typeof document=="undefined")return!1;let d=`${h.cookie}=${(p=h.value)!=null?p:"accepted"}`;return document.cookie.split("; ").some(C=>C.trim()===d)};if(u()){n(!0);return}if(!c)return;let l=()=>{u()&&n(!0)};return window.addEventListener(c,l),()=>window.removeEventListener(c,l)},[a,r,c,o]),t}function De(e){var C,m;let[t,n]=(0,b.useState)(null),[i]=(0,b.useState)(()=>{var f;return(f=e.sessionSegment)!=null?f:Lt()}),[a,r]=(0,b.useState)(le());(0,b.useEffect)(()=>_e(()=>r(le())),[]);let c=It(e.consentFrom),o=e.consentFrom?e.consent===!0||c:e.consent;(0,b.useEffect)(()=>{if(o===!1&&!e.preConsentBehavior){n(w=>(w==null||w.destroy(),null));return}let f={apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,sessionSegment:i,consent:o,preConsentBehavior:e.preConsentBehavior,respectDoNotTrack:e.respectDoNotTrack,ssrSessionId:e.ssrSessionId,country:e.country,localMode:e.localMode,initialSlots:e.initialSlots,initialPersona:e.initialPersona,ingestUrl:e.apiBaseUrl?`${e.apiBaseUrl.replace(/\/$/,"")}/events`:void 0},v=!1,s=null,g=null,y=w=>{e.engagement!==!1&&import("@sentientui/core/engagement").then(({startEngagementCapture:x})=>{v||(g=x(w,{apiKey:e.apiKey,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:w})=>{v||(s=w(Z(P({},f),{graph:!0,captureDomText:e.captureDomText===!0})),n(s),y(s))}):(s=(0,H.init)(f),n(s),y(s)),()=>{v=!0,g==null||g(),s==null||s.dispose()}},[o]),(0,b.useEffect)(()=>{if(!t)return;let f=!1,v=async()=>{if(f)return;let g;try{g=await t.fetchWeights()}catch(y){return}if(!f)for(let y of g){let w={componentId:y.componentId,updatedAt:y.updatedAt,variants:y.variants.map(x=>{var R;return{variantId:x.variantId,pulls:x.pulls,avgReward:(R=x.avgReward)!=null?R:0}})};ke(y.componentId,w)}};v();let s=setInterval(()=>{v()},6e4);return()=>{f=!0,clearInterval(s)}},[t]);let u=(C=e.ssrFallback)!=null?C:"first",l=((m=e.apiBaseUrl)!=null?m:Te).replace(/\/$/,""),h=(0,b.useRef)(null);(0,b.useEffect)(()=>{var s;if(typeof process!="undefined"&&((s=process.env)==null?void 0:s.NODE_ENV)==="production")return;let f={apiKey:e.apiKey,context:e.context,country:e.country,apiBaseUrl:l},v=h.current;if(h.current=f,v!==null)for(let g of["apiKey","context","country","apiBaseUrl"])Object.is(v[g],f[g])||console.warn(`[sentient] AdaptiveProvider: \`${g}\` 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,l]),(0,b.useEffect)(()=>{var f;typeof process!="undefined"&&((f=process.env)==null?void 0:f.NODE_ENV)==="production"||Ee({apiKey:e.apiKey,apiBaseUrl:l,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,l]),(0,b.useEffect)(()=>{e.initialLayoutOrder&&e.initialLayoutOrder.length>0&&Pe(e.initialLayoutOrder)},[e.initialLayoutOrder]);let d=(0,b.useMemo)(()=>t&&a?Ge(t):t,[t,a]),p=(0,b.useMemo)(()=>{var f,v,s,g,y;return{client:d,apiKey:e.apiKey,initialAssignments:(f=e.initialAssignments)!=null?f:{},sessionSegment:i,ssrFallback:u,onAssignment:e.onAssignment,initialLayoutOrder:(v=e.initialLayoutOrder)!=null?v:null,initialSlots:(s=e.initialSlots)!=null?s:{},initialPersona:(g=e.initialPersona)!=null?g:null,apiBaseUrl:l,debug:(y=e.debug)!=null?y:!1}},[d,e.apiKey,e.initialAssignments,i,u,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialPersona,l,e.debug]);return(0,Ne.jsx)(T.Provider,{value:p,children:e.children})}function E(){return(0,b.useContext)(T).client}function K(){return(0,b.useContext)(T).apiKey}function re(){return(0,b.useContext)(T).initialAssignments}function ie(){return(0,b.useContext)(T).sessionSegment}function Me(){return(0,b.useContext)(T).ssrFallback}function oe(){return(0,b.useContext)(T).onAssignment}function Be(){return(0,b.useContext)(T).debug}function Fe(){let e=(0,b.useContext)(T).initialLayoutOrder,t=(0,b.useSyncExternalStore)(W,()=>{var n;return typeof window=="undefined"?null:(n=window.__sentient_layout_override)!=null?n:null},()=>null);return t!=null?t:e}function Ke(){return(0,b.useContext)(T).initialSlots}function je(){return(0,b.useContext)(T).initialPersona}function We(){return(0,b.useContext)(T).apiBaseUrl}var _=require("react"),Ue=require("@sentientui/core");var D=require("react");function z(e){var n;if(typeof window=="undefined")return null;let t=(n=window.__sentient_overrides)==null?void 0:n[e];if(t)return t;if(!window.location.search)return null;try{let i=new URLSearchParams(window.location.search);for(let a of i.getAll("sentient_variant")){let r=a.indexOf(":");if(r!==-1&&a.slice(0,r)===e)return a.slice(r+1)}}catch(i){}return null}var Pt=5;function $e(e,t){var i,a;let n=null;for(let r of e.variants){if(!t.includes(r.variantId))continue;let c=(i=r.pulls)!=null?i:0,o=c>0?c*r.avgReward/(c+Pt):0;(!n||o>n.score)&&(n={variantId:r.variantId,score:o})}return(a=n==null?void 0:n.variantId)!=null?a:null}function X(e,t,n,i){let a=re(),r=Me(),c=E(),o=ie(),u=oe(),l=Be(),h=(0,D.useRef)(null),d=(0,D.useSyncExternalStore)(W,()=>z(e),()=>null),p=d&&t.includes(d)?d:null,C=(0,D.useRef)(null);(0,D.useEffect)(()=>{l&&p&&C.current!==p&&(C.current=p,console.info(`[sentient] override active: ${e} -> ${p}`))},[l,p,e]);let[m,f]=(0,D.useState)(()=>{var y,w;if(p)return{variantId:p,content:null,isLoading:!1,settled:!0};if(!c){let x=a[e];return x&&t.includes(x)?{variantId:x,content:null,isLoading:!1,settled:!0}:r==="first"&&t.length>0?{variantId:t[0],content:null,isLoading:!1,settled:!1}:{variantId:null,content:null,isLoading:!0,settled:!1}}let s=c.getAssignment(e,o);if(s&&(t.includes(s.variantId)||s.content))return{variantId:s.variantId,content:(y=s.content)!=null?y:null,isLoading:!1,settled:!0};let g=Ce(e);if(g){let x=$e(g,t);if(x)return{variantId:x,content:null,isLoading:!1,settled:!0}}return{variantId:(w=t[0])!=null?w:null,content:null,isLoading:!1,settled:!1}}),v=s=>{u&&h.current!==s&&(h.current=s,u(e,s))};return(0,D.useEffect)(()=>{var g;if(p||!c)return;let s=c.getAssignment(e,o);if(s&&(t.includes(s.variantId)||s.content)){f({variantId:s.variantId,content:(g=s.content)!=null?g:null,isLoading:!1,settled:!0}),v(s.variantId);return}f(y=>{var w;return y.variantId?y:{variantId:(w=t[0])!=null?w:null,content:null,isLoading:!1,settled:!1}})},[p,c,e,o]),(0,D.useEffect)(()=>{if(p||!c)return;let s=c.getAssignment(e,o);if(s&&t.includes(s.variantId))return;let g=!1;return c.assign(e,t,n,i).then(y=>{var w;g||y&&(!t.includes(y.variantId)&&!y.content||(f({variantId:y.variantId,content:(w=y.content)!=null?w:null,isLoading:!1,settled:!0}),v(y.variantId)))}),()=>{g=!0}},[p,c,e,o]),(0,D.useEffect)(()=>{if(!p&&c)return xe(e,s=>{var w;let g=c.getAssignment(e,o);if(g&&(t.includes(g.variantId)||g.content)){f({variantId:g.variantId,content:(w=g.content)!=null?w:null,isLoading:!1,settled:!0});return}let y=$e(s,t);y&&f({variantId:y,content:null,isLoading:!1,settled:!0})})},[p,c,e,o]),p?{variantId:p,content:null,isLoading:!1,settled:!0,isOverride:!0}:m}var Je=require("react/jsx-runtime");function Tt(e){var w;let t=E(),n=K(),i=Object.keys(e.variants).join("\0"),a=(0,_.useMemo)(()=>Object.keys(e.variants),[i]),{variantId:r,content:c,isOverride:o,settled:u}=X(e.id,a,e.agentData,e.agentDataByVariant),l=(0,_.useRef)(null),[h,d]=(0,_.useState)(!1);(0,_.useEffect)(()=>{d(!0)},[]);let p=(0,_.useRef)(!1),C=(0,_.useRef)(new Set),m=(0,_.useRef)(null),f=typeof e.goal=="string"?e.goal:JSON.stringify(e.goal),v=(0,_.useMemo)(()=>B(e.goal),[f]),s=typeof e.goal=="string"?e.goal:v.type;if((0,_.useEffect)(()=>te({id:e.id,variantIds:a,goal:s}),[e.id,a,s]),(0,_.useEffect)(()=>{o||u&&(!t||!r||!n||m.current!==r&&(m.current=r,N(t,n,e.id,r)))},[t,r,n,e.id,o,u]),(0,_.useEffect)(()=>{p.current=!1,C.current=new Set},[r,v]),(0,_.useEffect)(()=>{if(o||!u||!t||!r)return;let x=l.current;if(!x)return;let R=null,S=0,A=()=>{S=Date.now(),R=setTimeout(()=>{t.track({projectId:n,componentId:e.id,variantId:r,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-S}}),R=null},800)},k=()=>{R!==null&&(clearTimeout(R),R=null)};return x.addEventListener("mouseenter",A),x.addEventListener("mouseleave",k),()=>{x.removeEventListener("mouseenter",A),x.removeEventListener("mouseleave",k),R!==null&&clearTimeout(R)}},[t,r,n,e.id,o,u]),(0,_.useEffect)(()=>{if(o||!u||!t||!r)return;let x=l.current;if(!x)return;let R=Date.now();return(0,Ue.attachMicroSignalDetectors)((S,A={})=>{var pe,me,ve;t.track({projectId:n,componentId:e.id,variantId:r,eventType:"micro_signal",payload:P({signalType:S},A)});let k=(pe=e.microSignalGoals)==null?void 0:pe[S];if(!k||C.current.has(S))return;C.current.add(S);let V=typeof k=="string"?k:k.name,Y=typeof k=="string"?1:(me=k.weight)!=null?me:1,St=typeof k=="string"?0:(ve=k.stepIndex)!=null?ve:0;t.goal(V,P({signalType:S},A),Y,St)},x,R)},[t,r,n,e.id,e.microSignalGoals,o,u]),(0,_.useEffect)(()=>{if(o||!t||!r)return;let x=l.current;if(x)return F(x,v,{fireGoal:()=>{p.current||(p.current=!0,t.track({projectId:n,componentId:e.id,variantId:r,eventType:"goal_achieved",goalType:s,payload:{reward:1}}),t.goal(s,{componentId:e.id,variantId:r},1,0))},fireStep:(R,S,A)=>{t.track({projectId:n,componentId:e.id,variantId:r,eventType:"goal_achieved",goalType:R,payload:{reward:S}}),t.goal(R,{},S,A)}})},[t,r,n,e.id,v,s,o]),e.clientOnly&&(!h||!t)||!r)return null;let g=(w=e.variants[r])!=null?w:null,y=g===null?c:null;return O()&&g===null&&y===null&&console.warn(`[sentient] <Adaptive id="${e.id}"> was assigned variant "${r}" but no matching key exists in props.variants. If this is a dashboard-managed text variant, use <AdaptiveText id="${e.id}"> instead.`),(0,Je.jsx)("div",{ref:l,"data-sentient-id":e.id,"data-sentient-variant":r,children:g!=null?g:y})}var Ve=(0,_.memo)(Tt,(e,t)=>{if(e.id!==t.id||e.goal!==t.goal&&JSON.stringify(e.goal)!==JSON.stringify(t.goal)||e.microSignalGoals!==t.microSignalGoals||e.clientOnly!==t.clientOnly||e.agentData!==t.agentData||e.agentDataByVariant!==t.agentDataByVariant)return!1;if(e.variants===t.variants)return!0;let n=Object.keys(e.variants),i=Object.keys(t.variants);return n.length!==i.length?!1:n.every(a=>a in t.variants&&Object.is(e.variants[a],t.variants[a]))});var L=require("react");var ze=require("react/jsx-runtime");function He({id:e,default:t,component:n="span",className:i,goal:a}){var R;let r=E(),c=K(),o=oe(),u=ie(),l=(0,L.useRef)(null),h=(0,L.useRef)(null),d=(0,L.useSyncExternalStore)(W,()=>z(e),()=>null),[p,C]=(0,L.useState)(()=>{var S,A;return(A=(S=r==null?void 0:r.getAssignment(e,u))==null?void 0:S.content)!=null?A:null}),[m,f]=(0,L.useState)(()=>{var S,A;return(A=(S=r==null?void 0:r.getAssignment(e,u))==null?void 0:S.variantId)!=null?A:null});(0,L.useEffect)(()=>{var A;if(d||!r||((A=r.getAssignment(e,u))==null?void 0:A.content)!==void 0)return;let S=!1;return r.assign(e).then(k=>{if(!S){if(!k){O()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}f(k.variantId),k.content&&C(k.content)}}),()=>{S=!0}},[r,e,u,d]),(0,L.useEffect)(()=>{d||!r||!m||!c||l.current!==m&&(l.current=m,r.track({projectId:c,componentId:e,variantId:m,eventType:"variant_assigned",payload:{}}),o==null||o(e,m))},[r,m,c,e,o,d]);let v=a===void 0?"":typeof a=="string"?a:JSON.stringify(a),s=(0,L.useMemo)(()=>a===void 0?null:B(a),[v]),g=a===void 0?null:typeof a=="string"?a:s.type,y=(0,L.useRef)(!1);(0,L.useEffect)(()=>{y.current=!1},[m,v]),(0,L.useEffect)(()=>{if(d||!r||!m||!c||!s||!g)return;let S=h.current;if(S)return F(S,s,{fireGoal:()=>{y.current||(y.current=!0,r.track({projectId:c,componentId:e,variantId:m,eventType:"goal_achieved",goalType:g,payload:{reward:1}}),r.goal(g,{componentId:e,variantId:m},1,0))},fireStep:(A,k,V)=>{r.track({projectId:c,componentId:e,variantId:m,eventType:"goal_achieved",goalType:A,payload:{reward:k}}),r.goal(A,{},k,V)}})},[r,m,c,e,s,g,d]);let w=p!=null?p:t;if(d){let S=r==null?void 0:r.getAssignment(e,u);w=S&&S.variantId===d&&(R=S.content)!=null?R:t}return(0,ze.jsx)(n,{ref:S=>{h.current=S},className:i,children:w})}var Xe=require("react");function qe(e){let t=E();return(0,Xe.useCallback)((n,i)=>{var a,r;z(e)||(t==null||t.componentGoal(e,n,i),t==null||t.goal(n,(a=i==null?void 0:i.metadata)!=null?a:{},(r=i==null?void 0:i.reward)!=null?r:1,0))},[t,e])}var Ye=require("@sentientui/core"),Ze=require("@sentientui/policy"),tt=require("react/jsx-runtime");function Qe(e){return JSON.stringify(e).replace(/</g,"\\u003c")}function Dt(e){return e.persona?'(function(){try{var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",'+Qe(e.persona.persona)+');d.setAttribute("data-sentient-confidence",'+Qe((0,Ze.confidenceBand)(e.persona.confidence))+");}catch(e){}})();":(0,Ye.renderPrePaintScript)(e.apiKey)}function et(e){return(0,tt.jsx)("script",{"data-sentient-persona-script":"",nonce:e.nonce,dangerouslySetInnerHTML:{__html:Dt(e)}})}var j=require("react"),ot=require("@sentientui/policy");var M=require("react"),U=require("@sentientui/core"),rt=require("@sentientui/policy");var nt=new Set;function se(e,t){var h;(0,M.useSyncExternalStore)(W,ce,()=>0);let n=E(),i=Ke(),[,a]=(0,M.useReducer)(d=>d+1,0),r=typeof window!="undefined"?(h=window.__sentient_slot_overrides)==null?void 0:h[e]:void 0,c=r===void 0?i[e]:void 0,o=r===void 0&&c===void 0&&n?n.getSlotResult(e):null,u=(n==null?void 0:n.isLocal)===!0&&r===void 0&&c===void 0&&o===null;(0,M.useEffect)(()=>{if(!u||!n)return;let d=!1;return n.decide({slots:[t]}).then(p=>{!d&&p&&a()}),()=>{d=!0}},[n,e,u]);let l=(()=>{if(r!==void 0)return{result:r,arm:(0,U.armOfResult)(r),source:"override"};if(c!==void 0)return{result:c,arm:(0,U.armOfResult)(c),source:"preloaded"};if(o!==null)return{result:o,arm:(0,U.armOfResult)(o),source:"client"};let d=(0,U.baselineResultFor)(t);return{result:d,arm:(0,U.armOfResult)(d),source:"baseline"}})();return(0,M.useEffect)(()=>{O()&&(!n||n.isLocal===!0||l.source==="baseline"&&(nt.has(e)||(nt.add(e),console.warn(`[sentient] slot "${e}" resolved to its baseline \u2014 no SSR-preloaded or decided result. Keyed clients decide slots server-side, so this slot serves baseline for the whole session and records no exposure. Preload it via loadAdaptiveDecision()/initialSlots so it can serve a decided arm and learn.`))))},[n,l.source,e]),l}function Mt(){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 it(){let e=E(),t=je();(0,M.useSyncExternalStore)(W,ce,()=>0);let[n,i]=(0,M.useState)(!1);(0,M.useEffect)(()=>i(!0),[]);let a=o=>({persona:o.persona,confidence:o.confidence,band:(0,rt.confidenceBand)(o.confidence)});if(!n)return t?a(t):null;let r=Mt();if(r)return a(r);if(t)return a(t);let c=e?e.getPersona():null;return c?a(c):null}var ue=new Set;function Bt(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/[\\"]/g,"\\$&")}function st(e,t,n){let i=E(),a=K(),r=JSON.stringify(t),c=(0,j.useMemo)(()=>({id:e,dims:t}),[e,r]),{result:o,arm:u,source:l}=se(e,c),h=(0,j.useMemo)(()=>typeof o=="string"?{}:o,[u]);if(O()&&!ue.has(e)){let m=(0,ot.validateSlotDecl)({id:e,dims:Object.fromEntries(Object.entries(t).map(([v,s])=>[v,[...s]]))}),f=Object.values(t).reduce((v,s)=>v*s.length,1);m.ok?f>4&&(ue.add(e),console.warn(`[sentient] useAdaptiveTokens("${e}") declares ${f} combinations \u2014 more than the recommended 4. Each extra combination needs more traffic to learn; consider fewer dims/values.`)):(ue.add(e),console.warn(`[sentient] useAdaptiveTokens("${e}"): invalid declaration \u2014 ${m.reason}. Serving baseline.`))}let d=(n==null?void 0:n.goal)===void 0?null:typeof n.goal=="string"?n.goal:JSON.stringify(n.goal);(0,j.useEffect)(()=>ne({id:e,dims:t}),[e]);let p=(0,j.useRef)(null);(0,j.useEffect)(()=>{!i||l==="baseline"||l==="override"||p.current===u||(p.current=u,N(i,a,e,u))},[i,a,e,u,l]),(0,j.useEffect)(()=>{if(!i||!(n!=null&&n.goal)||l==="override")return;let m=document.querySelector(`[data-sentient-slot="${Bt(e)}"]`);if(!m){O()&&console.warn(`[sentient] useAdaptiveTokens("${e}"): a goal is declared but no element carries the returned props \u2014 spread {...props} on the slot's element.`);return}let f=J(n.goal),v=!1;return F(m,B(n.goal),{fireGoal:()=>{v||(v=!0,i.componentGoal(e,f),i.goal(f,{componentId:e,arm:u},1,0))},fireStep:(s,g,y)=>{i.componentGoal(e,s,{reward:g}),i.goal(s,{componentId:e,arm:u},g,y)}})},[i,e,d,u,l]);let C=(0,j.useMemo)(()=>{let m={"data-sentient-slot":e};for(let[f,v]of Object.entries(h))m[`data-${f}`]=v;return m},[e,h]);return{tokens:h,props:C}}var G=require("react"),lt=require("@sentientui/core");var at=new Set;function ct(e,t){var R;if(O()&&!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=E(),i=K(),a=Object.keys(t.variants).join(" "),r=(0,G.useMemo)(()=>Object.keys(t.variants),[a]),{variantId:c,isOverride:o,settled:u}=X(e,r),l=(R=c!=null?c:r[0])!=null?R:"",h=t.variants[l],[d,p]=(0,G.useState)(null),C=(0,G.useRef)(null),m=(0,G.useCallback)(S=>{C.current=S,p(S)},[]),f=typeof t.goal=="string"?t.goal:JSON.stringify(t.goal),v=(0,G.useMemo)(()=>B(t.goal),[f]),s=J(t.goal);(0,G.useEffect)(()=>te({id:e,variantIds:r,goal:s}),[e,r,s]);let g=(0,G.useRef)(null);(0,G.useEffect)(()=>{o||u&&(!n||!l||!d||g.current!==l&&(g.current=l,N(n,i,e,l)))},[n,i,e,l,d,o,u]);let y=(0,G.useRef)(!1);(0,G.useEffect)(()=>{y.current=!1},[l,f]),(0,G.useEffect)(()=>{if(!o&&!(!n||!l||!d))return F(d,v,{fireGoal:()=>{y.current||(y.current=!0,n.track({projectId:i,componentId:e,variantId:l,eventType:"goal_achieved",goalType:s,payload:{reward:1}}),n.goal(s,{componentId:e,variantId:l},1,0))},fireStep:(S,A,k)=>{n.track({projectId:i,componentId:e,variantId:l,eventType:"goal_achieved",goalType:S,payload:{reward:A}}),n.goal(S,{},A,k)}})},[n,d,l,i,e,v,s,o]),(0,G.useEffect)(()=>{if(o||!n||!l||!d)return;let S=Date.now();return(0,lt.attachMicroSignalDetectors)((A,k={})=>{n.track({projectId:i,componentId:e,variantId:l,eventType:"micro_signal",payload:P({signalType:A},k)})},d,S)},[n,d,l,i,e,o]),(0,G.useEffect)(()=>{if(!O()||!n)return;let S=setTimeout(()=>{!C.current&&!at.has(e)&&(at.add(e),console.warn(`[sentient] useAdaptive("${e}"): bind was never attached \u2014 spread {...bind} on the rendered element, otherwise exposure and goal tracking cannot work and the optimizer learns nothing.`))},0);return()=>clearTimeout(S)},[n,e]);let w=(0,G.useCallback)((S,A)=>{var V,Y;if(o)return;let k=S!=null?S:s;n==null||n.componentGoal(e,k,A),n==null||n.goal(k,(V=A==null?void 0:A.metadata)!=null?V:{},(Y=A==null?void 0:A.reward)!=null?Y:1,0)},[n,e,s,o]),x=(0,G.useMemo)(()=>({ref:m,"data-sentient-id":e,"data-sentient-variant":l}),[m,e,l]);return{variant:l,value:h,bind:x,fireGoal:w}}var I=require("react");var dt=require("react/jsx-runtime"),ae=new Set;function ut(e){var v;let t=E(),n=K(),i=(0,I.useRef)(null),a=Object.keys(e.arrangements).join(" "),r=(0,I.useMemo)(()=>Object.keys(e.arrangements),[a]),c=(0,I.useMemo)(()=>P({id:e.id,arms:r},e.baseline!==void 0?{baseline:e.baseline}:{}),[e.id,r,e.baseline]),{arm:o,source:u}=se(e.id,c);O()&&e.baseline!==void 0&&e.baseline!==r[0]&&!ae.has(e.id+":baseline")&&(ae.add(e.id+":baseline"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: baseline "${e.baseline}" is not the first-declared arrangement ("${r[0]}"). The first arrangement should usually be the page's real incumbent (the holdout sees it).`));let l=I.Children.toArray(e.children).filter(I.isValidElement),h=new Map;for(let s of l)h.set(String((v=s.key)!=null?v:"").replace(/^\.\$/,""),s);let d=e.arrangements[o],p=d!==void 0&&d.length===l.length&&d.every(s=>h.has(s));O()&&d!==void 0&&!p&&!ae.has(e.id+":keys")&&(ae.add(e.id+":keys"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: arrangement "${o}" [${d.join(", ")}] does not match the children's keys \u2014 rendering declaration order (fail-safe).`));let C=p?d.map(s=>h.get(s)):l;(0,I.useEffect)(()=>ne({id:e.id,arms:Object.keys(e.arrangements)}),[e.id]);let m=(0,I.useRef)(null);(0,I.useEffect)(()=>{!t||u==="baseline"||u==="override"||m.current===o||(m.current=o,N(t,n,e.id,o))},[t,n,e.id,o,u]);let f=e.goal===void 0?null:typeof e.goal=="string"?e.goal:JSON.stringify(e.goal);return(0,I.useEffect)(()=>{if(!t||e.goal===void 0||u==="override")return;let s=i.current;if(!s)return;let g=J(e.goal),y=!1;return F(s,B(e.goal),{fireGoal:()=>{y||(y=!0,t.componentGoal(e.id,g),t.goal(g,{componentId:e.id,arm:o},1,0))},fireStep:(w,x,R)=>{t.componentGoal(e.id,w,{reward:x}),t.goal(w,{componentId:e.id,arm:o},x,R)}})},[t,e.id,f,o,u]),(0,dt.jsx)("div",{ref:i,"data-sentient-id":e.id,"data-sentient-variant":o,children:C})}var de=require("@sentientui/core");var Ft=["page","blocks","layoutOrder"],ft=new Map;function gt(e,t){ft.set(e,t)}function fe(e){return ft.get(e)}function pt(e){var a,r;let t=(r=(a=e.content)!=null?a:fe(e.page))!=null?r:{},n={};for(let[c,o]of Object.entries(t))Ft.includes(c)||(n[c]=o);let i=Z(P({},n),{page:e.page,blocks:e.blocks});return e.layoutOrder&&(i.layoutOrder=e.layoutOrder),i}function mt(e){return`<script type="application/ld+json">${ge(e)}</script>`}function ge(e){return JSON.stringify(P({"@context":"https://schema.org","@type":"WebPage"},e)).replace(/</g,"\\u003c")}function vt(e){let t=[];e.title&&t.push(`# ${e.title}`,""),e.summary&&t.push(String(e.summary),"");for(let[n,i]of Object.entries(e))["page","title","summary","blocks","layoutOrder"].includes(n)||t.push(`## ${n}`,"","```json",JSON.stringify(i,null,2),"```","");if(e.blocks.length>0){t.push("## blocks","");for(let n of e.blocks)t.push(`- **${n.id}** \u2192 variant \`${n.variant}\``),n.content!==void 0&&t.push(""," ```json",JSON.stringify(n.content,null,2)," ```");t.push("")}return t.join(`
3
3
  `).trimEnd()+`
4
- `}0&&(module.exports={Adaptive,AdaptiveGroup,AdaptiveProvider,AdaptiveText,SentientPersonaScript,buildAgentFeed,defineAgentContent,detectSegment,getAgentContent,renderAgentJsonLd,renderAgentJsonLdBody,renderAgentMarkdown,useAdaptive,useAdaptiveApiBaseUrl,useAdaptiveGoal,useAdaptivePersona,useAdaptiveTokens,useAssignment,useInitialAssignments,useLayoutOrder,useSentient});
4
+ `}var yt=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,useSentient});
5
5
  //# sourceMappingURL=index.js.map