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