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