@sentientui/react 0.20.0 → 0.22.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/README.md +27 -0
- package/dist/index.d.cts +21 -0
- package/dist/index.d.ts +21 -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 +2 -2
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
|
@@ -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';
|
|
@@ -223,6 +226,15 @@ type AdaptiveProps = {
|
|
|
223
226
|
id: string;
|
|
224
227
|
variants: Record<string, ReactNode>;
|
|
225
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;
|
|
226
238
|
/**
|
|
227
239
|
* When a passive micro-signal fires on this component, also record a named goal.
|
|
228
240
|
* Use for inferred goals surfaced in the dashboard (e.g. rage_click → 'confused_by_hero').
|
|
@@ -440,6 +452,9 @@ declare function SentientPersonaScript(props: SentientPersonaScriptProps): JSX.E
|
|
|
440
452
|
|
|
441
453
|
type UseAdaptiveTokensOptions = {
|
|
442
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;
|
|
443
458
|
};
|
|
444
459
|
type UseAdaptiveTokensResult = {
|
|
445
460
|
tokens: Record<string, string>;
|
|
@@ -491,6 +506,9 @@ type UseAdaptiveResult<T> = {
|
|
|
491
506
|
declare function useAdaptive<T>(id: string, config: {
|
|
492
507
|
variants: Record<string, T>;
|
|
493
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;
|
|
494
512
|
}): UseAdaptiveResult<T>;
|
|
495
513
|
|
|
496
514
|
declare global {
|
|
@@ -531,6 +549,9 @@ type AdaptiveGroupProps = {
|
|
|
531
549
|
baseline?: string;
|
|
532
550
|
/** Optional slot-scoped goal — credited via componentGoal(group id). */
|
|
533
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;
|
|
534
555
|
/** Keyed children — every key referenced by an arrangement must exist. */
|
|
535
556
|
children: ReactNode;
|
|
536
557
|
};
|
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';
|
|
@@ -223,6 +226,15 @@ type AdaptiveProps = {
|
|
|
223
226
|
id: string;
|
|
224
227
|
variants: Record<string, ReactNode>;
|
|
225
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;
|
|
226
238
|
/**
|
|
227
239
|
* When a passive micro-signal fires on this component, also record a named goal.
|
|
228
240
|
* Use for inferred goals surfaced in the dashboard (e.g. rage_click → 'confused_by_hero').
|
|
@@ -440,6 +452,9 @@ declare function SentientPersonaScript(props: SentientPersonaScriptProps): JSX.E
|
|
|
440
452
|
|
|
441
453
|
type UseAdaptiveTokensOptions = {
|
|
442
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;
|
|
443
458
|
};
|
|
444
459
|
type UseAdaptiveTokensResult = {
|
|
445
460
|
tokens: Record<string, string>;
|
|
@@ -491,6 +506,9 @@ type UseAdaptiveResult<T> = {
|
|
|
491
506
|
declare function useAdaptive<T>(id: string, config: {
|
|
492
507
|
variants: Record<string, T>;
|
|
493
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;
|
|
494
512
|
}): UseAdaptiveResult<T>;
|
|
495
513
|
|
|
496
514
|
declare global {
|
|
@@ -531,6 +549,9 @@ type AdaptiveGroupProps = {
|
|
|
531
549
|
baseline?: string;
|
|
532
550
|
/** Optional slot-scoped goal — credited via componentGoal(group id). */
|
|
533
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;
|
|
534
555
|
/** Keyed children — every key referenced by an arrangement must exist. */
|
|
535
556
|
children: ReactNode;
|
|
536
557
|
};
|
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 _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
|