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