@sentientui/react 0.21.0 → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -0
- package/dist/index.d.cts +18 -0
- package/dist/index.d.ts +18 -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/llms.txt +8 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -254,6 +254,33 @@ goal={{
|
|
|
254
254
|
|
|
255
255
|
Each goal fires at most once per variant mount. `WeightedCompositeGoal` fires each step's reward independently; `CompositeGoal` waits for all sub-goals and fires reward `1.0` once.
|
|
256
256
|
|
|
257
|
+
#### Funnels — `funnel` prop
|
|
258
|
+
|
|
259
|
+
Add `funnel="<funnelId>"` to `<Adaptive>`, `useAdaptive`, `useAdaptiveTokens`, or `<AdaptiveGroup>` to declare that the component serves a multi-step funnel (the journey shown on the dashboard's Goals → Funnels tab). The optimizer then scores the component on journey progress: small credit for reaching intermediate steps, full credit at completion (revenue-scaled when the final conversion carries a `value`).
|
|
260
|
+
|
|
261
|
+
```tsx
|
|
262
|
+
// Declares BOTH the funnel's steps and this component's membership —
|
|
263
|
+
// a weighted_composite goal + funnel id creates the funnel server-side.
|
|
264
|
+
<Adaptive
|
|
265
|
+
id="hero"
|
|
266
|
+
funnel="checkout"
|
|
267
|
+
goal={{
|
|
268
|
+
type: 'weighted_composite',
|
|
269
|
+
steps: [
|
|
270
|
+
{ goal: { type: 'scroll_depth', threshold: 0.5 }, name: 'viewed_pricing', weight: 0.2 },
|
|
271
|
+
{ goal: { type: 'click' }, name: 'clicked_cta', weight: 0.4 },
|
|
272
|
+
{ goal: { type: 'form_submit' }, name: 'signed_up', weight: 1.0 },
|
|
273
|
+
],
|
|
274
|
+
}}
|
|
275
|
+
variants={...}
|
|
276
|
+
/>
|
|
277
|
+
|
|
278
|
+
// Membership-only: joins a funnel built in the dashboard or chat.
|
|
279
|
+
<Adaptive id="pricing-cta" funnel="checkout" goal="click" variants={...} />
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
The funnel id is stable — a funnel created in the dashboard or chat is referenced from code with the exact id it shows. Code declarations never overwrite a funnel edited by a human; the dashboard version wins and the component still serves it.
|
|
283
|
+
|
|
257
284
|
### `<AdaptiveText>`
|
|
258
285
|
|
|
259
286
|
Lightweight text-only variant (renders an inline `<span>` wrapper by default — change it via the `component` prop; no automatic goal wiring). Useful when you publish text variants from the dashboard WYSIWYG.
|
package/dist/index.d.cts
CHANGED
|
@@ -226,6 +226,15 @@ type AdaptiveProps = {
|
|
|
226
226
|
id: string;
|
|
227
227
|
variants: Record<string, ReactNode>;
|
|
228
228
|
goal: string | GoalConfig;
|
|
229
|
+
/**
|
|
230
|
+
* Funnel this component serves (stable funnel id, e.g. "checkout" —
|
|
231
|
+
* shown on the dashboard's Funnels tab). Declares membership to the server;
|
|
232
|
+
* a weighted_composite goal also declares the funnel's ordered steps, so a
|
|
233
|
+
* code-first funnel appears in the dashboard without opening it. The
|
|
234
|
+
* optimizer then trains this component on journey progress: small credit for
|
|
235
|
+
* intermediate steps, full (or revenue-scaled) credit at completion.
|
|
236
|
+
*/
|
|
237
|
+
funnel?: string;
|
|
229
238
|
/**
|
|
230
239
|
* When a passive micro-signal fires on this component, also record a named goal.
|
|
231
240
|
* Use for inferred goals surfaced in the dashboard (e.g. rage_click → 'confused_by_hero').
|
|
@@ -443,6 +452,9 @@ declare function SentientPersonaScript(props: SentientPersonaScriptProps): JSX.E
|
|
|
443
452
|
|
|
444
453
|
type UseAdaptiveTokensOptions = {
|
|
445
454
|
goal?: string | GoalConfig;
|
|
455
|
+
/** Funnel this slot serves (stable funnel id, e.g. "checkout") — same
|
|
456
|
+
* declaration semantics as <Adaptive funnel="...">. */
|
|
457
|
+
funnel?: string;
|
|
446
458
|
};
|
|
447
459
|
type UseAdaptiveTokensResult = {
|
|
448
460
|
tokens: Record<string, string>;
|
|
@@ -494,6 +506,9 @@ type UseAdaptiveResult<T> = {
|
|
|
494
506
|
declare function useAdaptive<T>(id: string, config: {
|
|
495
507
|
variants: Record<string, T>;
|
|
496
508
|
goal: string | GoalConfig;
|
|
509
|
+
/** Funnel this component serves (stable funnel id, e.g. "checkout") —
|
|
510
|
+
* same declaration semantics as <Adaptive funnel="...">. */
|
|
511
|
+
funnel?: string;
|
|
497
512
|
}): UseAdaptiveResult<T>;
|
|
498
513
|
|
|
499
514
|
declare global {
|
|
@@ -534,6 +549,9 @@ type AdaptiveGroupProps = {
|
|
|
534
549
|
baseline?: string;
|
|
535
550
|
/** Optional slot-scoped goal — credited via componentGoal(group id). */
|
|
536
551
|
goal?: string | GoalConfig;
|
|
552
|
+
/** Funnel this group serves (stable funnel id, e.g. "checkout") — same
|
|
553
|
+
* declaration semantics as <Adaptive funnel="...">. */
|
|
554
|
+
funnel?: string;
|
|
537
555
|
/** Keyed children — every key referenced by an arrangement must exist. */
|
|
538
556
|
children: ReactNode;
|
|
539
557
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -226,6 +226,15 @@ type AdaptiveProps = {
|
|
|
226
226
|
id: string;
|
|
227
227
|
variants: Record<string, ReactNode>;
|
|
228
228
|
goal: string | GoalConfig;
|
|
229
|
+
/**
|
|
230
|
+
* Funnel this component serves (stable funnel id, e.g. "checkout" —
|
|
231
|
+
* shown on the dashboard's Funnels tab). Declares membership to the server;
|
|
232
|
+
* a weighted_composite goal also declares the funnel's ordered steps, so a
|
|
233
|
+
* code-first funnel appears in the dashboard without opening it. The
|
|
234
|
+
* optimizer then trains this component on journey progress: small credit for
|
|
235
|
+
* intermediate steps, full (or revenue-scaled) credit at completion.
|
|
236
|
+
*/
|
|
237
|
+
funnel?: string;
|
|
229
238
|
/**
|
|
230
239
|
* When a passive micro-signal fires on this component, also record a named goal.
|
|
231
240
|
* Use for inferred goals surfaced in the dashboard (e.g. rage_click → 'confused_by_hero').
|
|
@@ -443,6 +452,9 @@ declare function SentientPersonaScript(props: SentientPersonaScriptProps): JSX.E
|
|
|
443
452
|
|
|
444
453
|
type UseAdaptiveTokensOptions = {
|
|
445
454
|
goal?: string | GoalConfig;
|
|
455
|
+
/** Funnel this slot serves (stable funnel id, e.g. "checkout") — same
|
|
456
|
+
* declaration semantics as <Adaptive funnel="...">. */
|
|
457
|
+
funnel?: string;
|
|
446
458
|
};
|
|
447
459
|
type UseAdaptiveTokensResult = {
|
|
448
460
|
tokens: Record<string, string>;
|
|
@@ -494,6 +506,9 @@ type UseAdaptiveResult<T> = {
|
|
|
494
506
|
declare function useAdaptive<T>(id: string, config: {
|
|
495
507
|
variants: Record<string, T>;
|
|
496
508
|
goal: string | GoalConfig;
|
|
509
|
+
/** Funnel this component serves (stable funnel id, e.g. "checkout") —
|
|
510
|
+
* same declaration semantics as <Adaptive funnel="...">. */
|
|
511
|
+
funnel?: string;
|
|
497
512
|
}): UseAdaptiveResult<T>;
|
|
498
513
|
|
|
499
514
|
declare global {
|
|
@@ -534,6 +549,9 @@ type AdaptiveGroupProps = {
|
|
|
534
549
|
baseline?: string;
|
|
535
550
|
/** Optional slot-scoped goal — credited via componentGoal(group id). */
|
|
536
551
|
goal?: string | GoalConfig;
|
|
552
|
+
/** Funnel this group serves (stable funnel id, e.g. "checkout") — same
|
|
553
|
+
* declaration semantics as <Adaptive funnel="...">. */
|
|
554
|
+
funnel?: string;
|
|
537
555
|
/** Keyed children — every key referenced by an arrangement must exist. */
|
|
538
556
|
children: ReactNode;
|
|
539
557
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
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(`
|
|
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(`
|
|
3
3
|
`).trimEnd()+`
|
|
4
|
-
`}var
|
|
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
|