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