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