@sentientui/react 0.19.1 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -91,6 +91,16 @@ type AdaptiveProviderProps = {
91
91
  * `useLayoutOrder()` returns this on first render so there is no layout shift.
92
92
  */
93
93
  initialLayoutOrder?: string[] | null;
94
+ /**
95
+ * The section ids the app declares as reorderable, independent of any
96
+ * decision. `AdaptiveRoot` forwards its `sections` prop here.
97
+ *
98
+ * Devtools reads this to offer layout previewing: a page whose decision was
99
+ * gated by consent, or timed out, has no `initialLayoutOrder`, and registering
100
+ * only that left the layout panel empty in exactly the situation you reach for
101
+ * it — running the site locally before accepting a cookie banner.
102
+ */
103
+ declaredSections?: string[];
94
104
  /**
95
105
  * SSR-preloaded slot results from `loadAdaptiveDecision()` (the `slots`
96
106
  * field of its result). Guarantees `useAdaptiveTokens`/`AdaptiveGroup`
@@ -179,13 +189,16 @@ declare function useAdaptiveApiBaseUrl(): string;
179
189
  type ScrollDepthGoal = {
180
190
  type: 'scroll_depth';
181
191
  threshold: number;
192
+ value?: number;
182
193
  };
183
194
  type ClickGoal = {
184
195
  type: 'click';
185
196
  selector?: string;
197
+ value?: number;
186
198
  };
187
199
  type FormSubmitGoal = {
188
200
  type: 'form_submit';
201
+ value?: number;
189
202
  };
190
203
  type CompositeGoal = {
191
204
  type: 'composite';
@@ -318,7 +331,20 @@ type AssignmentState = {
318
331
  */
319
332
  declare function useAssignment(componentId: string, variantIds: string[], agentData?: unknown, agentDataByVariant?: Record<string, unknown>): AssignmentState;
320
333
 
321
- type FireGoal = (goalType: string, opts?: ComponentGoalOptions) => void;
334
+ interface FireGoalOptions extends ComponentGoalOptions {
335
+ /**
336
+ * Record this goal at most once per mounted component, however many times the
337
+ * callback is invoked. Use it for conversions that are a state, not an action
338
+ * — "reached step 3", "form validated", an effect that may re-run — where a
339
+ * second record is double counting rather than a second conversion.
340
+ *
341
+ * Leave it off for genuine repeat actions (each click of "add to cart" is its
342
+ * own conversion). The latch is per goal type and lives for the lifetime of
343
+ * the component holding the callback, so a remount can record again.
344
+ */
345
+ once?: boolean;
346
+ }
347
+ type FireGoal = (goalType: string, opts?: FireGoalOptions) => void;
322
348
  /**
323
349
  * Returns a `fireGoal(goalType, opts?)` callback that records a conversion
324
350
  * attributed to the variant currently served for `componentId` — so it shows
@@ -340,6 +366,48 @@ type FireGoal = (goalType: string, opts?: ComponentGoalOptions) => void;
340
366
  */
341
367
  declare function useAdaptiveGoal(componentId: string): FireGoal;
342
368
 
369
+ interface PageGoalOptions extends ComponentGoalOptions {
370
+ /**
371
+ * Credit the arrival to the variant currently served for this component —
372
+ * typically the CTA on the page the visitor came FROM. The served variant is
373
+ * read from the assignment cache, which is localStorage-backed, so the credit
374
+ * survives the navigation. Omit for a session-level goal with no per-variant
375
+ * attribution.
376
+ */
377
+ componentId?: string;
378
+ }
379
+ /**
380
+ * Records `goalName` once, when a page or route is reached.
381
+ *
382
+ * Use this for funnel steps that are a *destination* rather than a click:
383
+ * reaching /pricing, landing on a signup form, opening a checkout. Arrival is
384
+ * the better signal — it survives the navigation that a click goal can lose,
385
+ * and it also counts visitors who arrived from the nav, a search result or a
386
+ * shared link, none of whom clicked the CTA being measured.
387
+ *
388
+ * Two things this handles that hand-rolling `useAdaptiveGoal` in an effect does
389
+ * not, both of which fail silently:
390
+ *
391
+ * - **Fires once.** `useAdaptiveGoal` has no latch, so a remount — or React's
392
+ * double-invoked effects in development — records the same arrival twice and
393
+ * inflates the funnel.
394
+ * - **Waits for consent.** Under a consent gate the client does not exist when
395
+ * the page mounts, and a visitor who accepts a moment later would lose the
396
+ * goal entirely. The arrival is held until the SDK is running, then sent.
397
+ *
398
+ * Safe during SSR (effects do not run on the server) and a no-op without a
399
+ * provider above it.
400
+ *
401
+ * @example
402
+ * // Credit reaching the pricing page to whichever hero CTA sent them.
403
+ * usePageGoal('pricing_view', { componentId: 'hero_cta' });
404
+ *
405
+ * @example
406
+ * // Session-level only — no component to attribute it to.
407
+ * usePageGoal('docs_view');
408
+ */
409
+ declare function usePageGoal(goalName: string, opts?: PageGoalOptions): void;
410
+
343
411
  type SentientPersonaScriptProps = {
344
412
  /** Publishable API key — selects the localStorage snapshot in the fallback path. */
345
413
  apiKey: string;
@@ -548,4 +616,4 @@ declare function renderAgentJsonLdBody(feed: AgentFeed): string;
548
616
  /** Render the feed as Markdown for agents that negotiate `text/markdown`. */
549
617
  declare function renderAgentMarkdown(feed: AgentFeed): string;
550
618
 
551
- export { Adaptive, AdaptiveGroup, type AdaptiveGroupProps, type AdaptivePersona, type AdaptiveProps, AdaptiveProvider, type AdaptiveProviderProps, AdaptiveText, type AdaptiveTextProps, type AgentBlock, type AgentFeed, type AssignmentState, type ClickGoal, type ComponentWeights, type CompositeGoal, type FireGoal, type FormSubmitGoal, type GoalConfig, type MicroSignalGoalConfig, type MicroSignalGoals, type ScrollDepthGoal, SentientPersonaScript, type SentientPersonaScriptProps, type SsrFallback, type UseAdaptiveBind, type UseAdaptiveResult, type UseAdaptiveTokensOptions, type UseAdaptiveTokensResult, type VariantWeight, type WeightedCompositeGoal, type WeightedStep, buildAgentFeed, defineAgentContent, getAgentContent, renderAgentJsonLd, renderAgentJsonLdBody, renderAgentMarkdown, useAdaptive, useAdaptiveApiBaseUrl, useAdaptiveGoal, useAdaptivePersona, useAdaptiveTokens, useAssignment, useInitialAssignments, useLayoutOrder, useSentient };
619
+ export { Adaptive, AdaptiveGroup, type AdaptiveGroupProps, type AdaptivePersona, type AdaptiveProps, AdaptiveProvider, type AdaptiveProviderProps, AdaptiveText, type AdaptiveTextProps, type AgentBlock, type AgentFeed, type AssignmentState, type ClickGoal, type ComponentWeights, type CompositeGoal, type FireGoal, type FormSubmitGoal, type GoalConfig, type MicroSignalGoalConfig, type MicroSignalGoals, type PageGoalOptions, type ScrollDepthGoal, SentientPersonaScript, type SentientPersonaScriptProps, type SsrFallback, type UseAdaptiveBind, type UseAdaptiveResult, type UseAdaptiveTokensOptions, type UseAdaptiveTokensResult, type VariantWeight, type WeightedCompositeGoal, type WeightedStep, buildAgentFeed, defineAgentContent, getAgentContent, renderAgentJsonLd, renderAgentJsonLdBody, renderAgentMarkdown, useAdaptive, useAdaptiveApiBaseUrl, useAdaptiveGoal, useAdaptivePersona, useAdaptiveTokens, useAssignment, useInitialAssignments, useLayoutOrder, usePageGoal, useSentient };
package/dist/index.d.ts CHANGED
@@ -91,6 +91,16 @@ type AdaptiveProviderProps = {
91
91
  * `useLayoutOrder()` returns this on first render so there is no layout shift.
92
92
  */
93
93
  initialLayoutOrder?: string[] | null;
94
+ /**
95
+ * The section ids the app declares as reorderable, independent of any
96
+ * decision. `AdaptiveRoot` forwards its `sections` prop here.
97
+ *
98
+ * Devtools reads this to offer layout previewing: a page whose decision was
99
+ * gated by consent, or timed out, has no `initialLayoutOrder`, and registering
100
+ * only that left the layout panel empty in exactly the situation you reach for
101
+ * it — running the site locally before accepting a cookie banner.
102
+ */
103
+ declaredSections?: string[];
94
104
  /**
95
105
  * SSR-preloaded slot results from `loadAdaptiveDecision()` (the `slots`
96
106
  * field of its result). Guarantees `useAdaptiveTokens`/`AdaptiveGroup`
@@ -179,13 +189,16 @@ declare function useAdaptiveApiBaseUrl(): string;
179
189
  type ScrollDepthGoal = {
180
190
  type: 'scroll_depth';
181
191
  threshold: number;
192
+ value?: number;
182
193
  };
183
194
  type ClickGoal = {
184
195
  type: 'click';
185
196
  selector?: string;
197
+ value?: number;
186
198
  };
187
199
  type FormSubmitGoal = {
188
200
  type: 'form_submit';
201
+ value?: number;
189
202
  };
190
203
  type CompositeGoal = {
191
204
  type: 'composite';
@@ -318,7 +331,20 @@ type AssignmentState = {
318
331
  */
319
332
  declare function useAssignment(componentId: string, variantIds: string[], agentData?: unknown, agentDataByVariant?: Record<string, unknown>): AssignmentState;
320
333
 
321
- type FireGoal = (goalType: string, opts?: ComponentGoalOptions) => void;
334
+ interface FireGoalOptions extends ComponentGoalOptions {
335
+ /**
336
+ * Record this goal at most once per mounted component, however many times the
337
+ * callback is invoked. Use it for conversions that are a state, not an action
338
+ * — "reached step 3", "form validated", an effect that may re-run — where a
339
+ * second record is double counting rather than a second conversion.
340
+ *
341
+ * Leave it off for genuine repeat actions (each click of "add to cart" is its
342
+ * own conversion). The latch is per goal type and lives for the lifetime of
343
+ * the component holding the callback, so a remount can record again.
344
+ */
345
+ once?: boolean;
346
+ }
347
+ type FireGoal = (goalType: string, opts?: FireGoalOptions) => void;
322
348
  /**
323
349
  * Returns a `fireGoal(goalType, opts?)` callback that records a conversion
324
350
  * attributed to the variant currently served for `componentId` — so it shows
@@ -340,6 +366,48 @@ type FireGoal = (goalType: string, opts?: ComponentGoalOptions) => void;
340
366
  */
341
367
  declare function useAdaptiveGoal(componentId: string): FireGoal;
342
368
 
369
+ interface PageGoalOptions extends ComponentGoalOptions {
370
+ /**
371
+ * Credit the arrival to the variant currently served for this component —
372
+ * typically the CTA on the page the visitor came FROM. The served variant is
373
+ * read from the assignment cache, which is localStorage-backed, so the credit
374
+ * survives the navigation. Omit for a session-level goal with no per-variant
375
+ * attribution.
376
+ */
377
+ componentId?: string;
378
+ }
379
+ /**
380
+ * Records `goalName` once, when a page or route is reached.
381
+ *
382
+ * Use this for funnel steps that are a *destination* rather than a click:
383
+ * reaching /pricing, landing on a signup form, opening a checkout. Arrival is
384
+ * the better signal — it survives the navigation that a click goal can lose,
385
+ * and it also counts visitors who arrived from the nav, a search result or a
386
+ * shared link, none of whom clicked the CTA being measured.
387
+ *
388
+ * Two things this handles that hand-rolling `useAdaptiveGoal` in an effect does
389
+ * not, both of which fail silently:
390
+ *
391
+ * - **Fires once.** `useAdaptiveGoal` has no latch, so a remount — or React's
392
+ * double-invoked effects in development — records the same arrival twice and
393
+ * inflates the funnel.
394
+ * - **Waits for consent.** Under a consent gate the client does not exist when
395
+ * the page mounts, and a visitor who accepts a moment later would lose the
396
+ * goal entirely. The arrival is held until the SDK is running, then sent.
397
+ *
398
+ * Safe during SSR (effects do not run on the server) and a no-op without a
399
+ * provider above it.
400
+ *
401
+ * @example
402
+ * // Credit reaching the pricing page to whichever hero CTA sent them.
403
+ * usePageGoal('pricing_view', { componentId: 'hero_cta' });
404
+ *
405
+ * @example
406
+ * // Session-level only — no component to attribute it to.
407
+ * usePageGoal('docs_view');
408
+ */
409
+ declare function usePageGoal(goalName: string, opts?: PageGoalOptions): void;
410
+
343
411
  type SentientPersonaScriptProps = {
344
412
  /** Publishable API key — selects the localStorage snapshot in the fallback path. */
345
413
  apiKey: string;
@@ -548,4 +616,4 @@ declare function renderAgentJsonLdBody(feed: AgentFeed): string;
548
616
  /** Render the feed as Markdown for agents that negotiate `text/markdown`. */
549
617
  declare function renderAgentMarkdown(feed: AgentFeed): string;
550
618
 
551
- export { Adaptive, AdaptiveGroup, type AdaptiveGroupProps, type AdaptivePersona, type AdaptiveProps, AdaptiveProvider, type AdaptiveProviderProps, AdaptiveText, type AdaptiveTextProps, type AgentBlock, type AgentFeed, type AssignmentState, type ClickGoal, type ComponentWeights, type CompositeGoal, type FireGoal, type FormSubmitGoal, type GoalConfig, type MicroSignalGoalConfig, type MicroSignalGoals, type ScrollDepthGoal, SentientPersonaScript, type SentientPersonaScriptProps, type SsrFallback, type UseAdaptiveBind, type UseAdaptiveResult, type UseAdaptiveTokensOptions, type UseAdaptiveTokensResult, type VariantWeight, type WeightedCompositeGoal, type WeightedStep, buildAgentFeed, defineAgentContent, getAgentContent, renderAgentJsonLd, renderAgentJsonLdBody, renderAgentMarkdown, useAdaptive, useAdaptiveApiBaseUrl, useAdaptiveGoal, useAdaptivePersona, useAdaptiveTokens, useAssignment, useInitialAssignments, useLayoutOrder, useSentient };
619
+ export { Adaptive, AdaptiveGroup, type AdaptiveGroupProps, type AdaptivePersona, type AdaptiveProps, AdaptiveProvider, type AdaptiveProviderProps, AdaptiveText, type AdaptiveTextProps, type AgentBlock, type AgentFeed, type AssignmentState, type ClickGoal, type ComponentWeights, type CompositeGoal, type FireGoal, type FormSubmitGoal, type GoalConfig, type MicroSignalGoalConfig, type MicroSignalGoals, type PageGoalOptions, type ScrollDepthGoal, SentientPersonaScript, type SentientPersonaScriptProps, type SsrFallback, type UseAdaptiveBind, type UseAdaptiveResult, type UseAdaptiveTokensOptions, type UseAdaptiveTokensResult, type VariantWeight, type WeightedCompositeGoal, type WeightedStep, buildAgentFeed, defineAgentContent, getAgentContent, renderAgentJsonLd, renderAgentJsonLdBody, renderAgentMarkdown, useAdaptive, useAdaptiveApiBaseUrl, useAdaptiveGoal, useAdaptivePersona, useAdaptiveTokens, useAssignment, useInitialAssignments, useLayoutOrder, usePageGoal, useSentient };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- "use strict";var ht=Object.create;var q=Object.defineProperty,bt=Object.defineProperties,wt=Object.getOwnPropertyDescriptor,At=Object.getOwnPropertyDescriptors,xt=Object.getOwnPropertyNames,ye=Object.getOwnPropertySymbols,kt=Object.getPrototypeOf,he=Object.prototype.hasOwnProperty,Ct=Object.prototype.propertyIsEnumerable;var Se=(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={}))he.call(t,n)&&Se(e,n,t[n]);if(ye)for(var n of ye(t))Ct.call(t,n)&&Se(e,n,t[n]);return e},Z=(e,t)=>bt(e,At(t));var Rt=(e,t)=>{for(var n in t)q(e,n,{get:t[n],enumerable:!0})},be=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of xt(t))!he.call(e,a)&&a!==n&&q(e,a,{get:()=>t[a],enumerable:!(i=wt(t,a))||i.enumerable});return e};var we=(e,t,n)=>(n=e!=null?ht(kt(e)):{},be(t||!e||!e.__esModule?q(n,"default",{value:e,enumerable:!0}):n,e)),_t=e=>be(q({},"__esModule",{value:!0}),e);var Kt={};Rt(Kt,{Adaptive:()=>Ve,AdaptiveGroup:()=>ut,AdaptiveProvider:()=>De,AdaptiveText:()=>He,SentientPersonaScript:()=>et,buildAgentFeed:()=>pt,defineAgentContent:()=>gt,detectSegment:()=>de.deriveSessionSegment,getAgentContent:()=>fe,grantConsent:()=>yt.grantConsent,renderAgentJsonLd:()=>mt,renderAgentJsonLdBody:()=>ge,renderAgentMarkdown:()=>vt,useAdaptive:()=>ct,useAdaptiveApiBaseUrl:()=>We,useAdaptiveGoal:()=>qe,useAdaptivePersona:()=>it,useAdaptiveTokens:()=>st,useAssignment:()=>X,useInitialAssignments:()=>re,useLayoutOrder:()=>Fe,useSentient:()=>E});module.exports=_t(Kt);var b=require("react"),H=require("@sentientui/core");var Ae=new Map,ee=new Map;function xe(e,t){let n=ee.get(e);return n||(n=new Set,ee.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&ee.delete(e)}}function ke(e,t){Ae.set(e,t);let n=ee.get(e);if(n)for(let i of n)try{i(t)}catch(a){}}function Ce(e){var t;return(t=Ae.get(e))!=null?t:null}var Gt={on:!1,listeners:new Set};function Re(){if(typeof window=="undefined")return Gt;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function le(){return Re().on}function _e(e){let t=Re().listeners;return t.add(e),()=>{t.delete(e)}}function Ge(e){return{isLocal:e.isLocal,track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},fetchWeights:()=>Promise.resolve([]),getAssignment:(t,n)=>e.getAssignment(t,n),assign:(t,n,i,a)=>e.assign(t,n,i,a),decide:()=>Promise.resolve(null),getSlotResult:t=>e.getSlotResult(t),getPersona:()=>e.getPersona(),getGraph:()=>e.getGraph(),dispose:()=>e.dispose(),destroy:()=>e.destroy()}}var Oe="sentient:overrides-changed";function ce(){var e;return typeof window=="undefined"?0:(e=window.__sentient_overrides_version)!=null?e:0}function W(e){return typeof window=="undefined"?()=>{}:(window.addEventListener(Oe,e),()=>window.removeEventListener(Oe,e))}function Ee(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function O(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}function B(e){return typeof e=="string"?{type:"click"}:e}function J(e){return typeof e=="string"?e:e.type}function Ot(e){if(!(e instanceof Element))return!1;let t=e.tagName.toLowerCase();return t==="a"||t==="button"?!0:e.getAttribute("role")==="button"}function Le(e,t,n){if(n){try{let a=e;for(;a&&a!==t;){if(a.matches(n))return!0;a=a.parentElement}}catch(a){}return!1}let i=e;for(;i&&i!==t;){if(Ot(i))return!0;i=i.parentElement}return!1}function F(e,t,n){if(t.type==="weighted_composite"){let o=new Set,u=[];return t.steps.forEach(({goal:l,name:h,weight:d},p)=>{let C=()=>{o.has(p)||(o.add(p),n.fireStep(h,d,p))};if(l.type==="click"){let m=f=>{let v=f.target;v instanceof Element&&Le(v,e,l.selector)&&C()};e.addEventListener("click",m),u.push(()=>e.removeEventListener("click",m));return}if(l.type==="form_submit"){let m=f=>{f.target instanceof HTMLFormElement&&e.contains(f.target)&&C()};e.addEventListener("submit",m),u.push(()=>e.removeEventListener("submit",m));return}if(l.type==="scroll_depth"){let m=Math.max(0,Math.min(1,l.threshold)),f=new IntersectionObserver(v=>{for(let s of v)if(s.intersectionRatio>=m){C(),f.disconnect();break}},{threshold:[m]});f.observe(e),u.push(()=>f.disconnect())}}),()=>{for(let l of u)l()}}let i=t.type==="composite"?t.all:[t],a=new Set(i.map((o,u)=>u)),r=o=>{a.delete(o),a.size===0&&n.fireGoal()},c=[];return i.forEach((o,u)=>{if(o.type==="click"){let l=h=>{let d=h.target;d instanceof Element&&Le(d,e,o.selector)&&(t.type==="composite"?r(u):n.fireGoal())};e.addEventListener("click",l),c.push(()=>e.removeEventListener("click",l));return}if(o.type==="form_submit"){let l=h=>{h.target instanceof HTMLFormElement&&e.contains(h.target)&&(t.type==="composite"?r(u):n.fireGoal())};e.addEventListener("submit",l),c.push(()=>e.removeEventListener("submit",l));return}if(o.type==="scroll_depth"){let l=Math.max(0,Math.min(1,o.threshold)),h=new IntersectionObserver(d=>{for(let p of d)if(p.intersectionRatio>=l){t.type==="composite"?r(u):n.fireGoal(),h.disconnect();break}},{threshold:[l]});h.observe(e),c.push(()=>h.disconnect());return}}),()=>{for(let o of c)o()}}function N(e,t,n,i){e.track({projectId:t,componentId:n,variantId:i,eventType:"variant_assigned",payload:{}})}var Et={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function $(){if(typeof window=="undefined")return Et;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(){$().version+=1;for(let e of $().listeners)e()}var Ie=()=>{};function te(e){return O()?($().components.set(e.id,e),Q(),()=>{$().components.delete(e.id),Q()}):Ie}function ne(e){return O()?($().slots.set(e.id,e),Q(),()=>{$().slots.delete(e.id),Q()}):Ie}function Pe(e){O()&&($().sections=[...e],Q())}var Ne=require("react/jsx-runtime");function Lt(){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 Te="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:Te,debug:!1});function It(e){let[t,n]=(0,b.useState)(!1),i=(0,b.useRef)(e);i.current=e;let{cookie:a,value:r,event:c}=e!=null?e:{},o=typeof(e==null?void 0:e.check)=="function";return(0,b.useEffect)(()=>{let u=()=>{var p;let h=i.current;if(!h)return!1;if(h.check)return h.check()===!0;if(!h.cookie||typeof document=="undefined")return!1;let d=`${h.cookie}=${(p=h.value)!=null?p:"accepted"}`;return document.cookie.split("; ").some(C=>C.trim()===d)};if(u()){n(!0);return}if(!c)return;let l=()=>{u()&&n(!0)};return window.addEventListener(c,l),()=>window.removeEventListener(c,l)},[a,r,c,o]),t}function De(e){var C,m;let[t,n]=(0,b.useState)(null),[i]=(0,b.useState)(()=>{var f;return(f=e.sessionSegment)!=null?f:Lt()}),[a,r]=(0,b.useState)(le());(0,b.useEffect)(()=>_e(()=>r(le())),[]);let c=It(e.consentFrom),o=e.consentFrom?e.consent===!0||c:e.consent;(0,b.useEffect)(()=>{if(o===!1&&!e.preConsentBehavior){n(w=>(w==null||w.destroy(),null));return}let f={apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,sessionSegment:i,consent:o,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},v=!1,s=null,g=null,y=w=>{e.engagement!==!1&&import("@sentientui/core/engagement").then(({startEngagementCapture:x})=>{v||(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})=>{v||(s=w(Z(P({},f),{graph:!0,captureDomText:e.captureDomText===!0})),n(s),y(s))}):(s=(0,H.init)(f),n(s),y(s)),()=>{v=!0,g==null||g(),s==null||s.dispose()}},[o]),(0,b.useEffect)(()=>{if(!t)return;let f=!1,v=async()=>{if(f)return;let g;try{g=await t.fetchWeights()}catch(y){return}if(!f)for(let y of g){let w={componentId:y.componentId,updatedAt:y.updatedAt,variants:y.variants.map(x=>{var R;return{variantId:x.variantId,pulls:x.pulls,avgReward:(R=x.avgReward)!=null?R:0}})};ke(y.componentId,w)}};v();let s=setInterval(()=>{v()},6e4);return()=>{f=!0,clearInterval(s)}},[t]);let u=(C=e.ssrFallback)!=null?C:"first",l=((m=e.apiBaseUrl)!=null?m:Te).replace(/\/$/,""),h=(0,b.useRef)(null);(0,b.useEffect)(()=>{var s;if(typeof process!="undefined"&&((s=process.env)==null?void 0:s.NODE_ENV)==="production")return;let f={apiKey:e.apiKey,context:e.context,country:e.country,apiBaseUrl:l},v=h.current;if(h.current=f,v!==null)for(let g of["apiKey","context","country","apiBaseUrl"])Object.is(v[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,b.useEffect)(()=>{var f;typeof process!="undefined"&&((f=process.env)==null?void 0:f.NODE_ENV)==="production"||Ee({apiKey:e.apiKey,apiBaseUrl:l,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,l]),(0,b.useEffect)(()=>{e.initialLayoutOrder&&e.initialLayoutOrder.length>0&&Pe(e.initialLayoutOrder)},[e.initialLayoutOrder]);let d=(0,b.useMemo)(()=>t&&a?Ge(t):t,[t,a]),p=(0,b.useMemo)(()=>{var f,v,s,g,y;return{client:d,apiKey:e.apiKey,initialAssignments:(f=e.initialAssignments)!=null?f:{},sessionSegment:i,ssrFallback:u,onAssignment:e.onAssignment,initialLayoutOrder:(v=e.initialLayoutOrder)!=null?v:null,initialSlots:(s=e.initialSlots)!=null?s:{},initialPersona:(g=e.initialPersona)!=null?g:null,apiBaseUrl:l,debug:(y=e.debug)!=null?y:!1}},[d,e.apiKey,e.initialAssignments,i,u,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialPersona,l,e.debug]);return(0,Ne.jsx)(T.Provider,{value:p,children:e.children})}function E(){return(0,b.useContext)(T).client}function K(){return(0,b.useContext)(T).apiKey}function re(){return(0,b.useContext)(T).initialAssignments}function ie(){return(0,b.useContext)(T).sessionSegment}function Me(){return(0,b.useContext)(T).ssrFallback}function oe(){return(0,b.useContext)(T).onAssignment}function Be(){return(0,b.useContext)(T).debug}function Fe(){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 Ke(){return(0,b.useContext)(T).initialSlots}function je(){return(0,b.useContext)(T).initialPersona}function We(){return(0,b.useContext)(T).apiBaseUrl}var _=require("react"),Ue=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 a of i.getAll("sentient_variant")){let r=a.indexOf(":");if(r!==-1&&a.slice(0,r)===e)return a.slice(r+1)}}catch(i){}return null}var Pt=5;function $e(e,t){var i,a;let n=null;for(let r of e.variants){if(!t.includes(r.variantId))continue;let c=(i=r.pulls)!=null?i:0,o=c>0?c*r.avgReward/(c+Pt):0;(!n||o>n.score)&&(n={variantId:r.variantId,score:o})}return(a=n==null?void 0:n.variantId)!=null?a:null}function X(e,t,n,i){let a=re(),r=Me(),c=E(),o=ie(),u=oe(),l=Be(),h=(0,D.useRef)(null),d=(0,D.useSyncExternalStore)(W,()=>z(e),()=>null),p=d&&t.includes(d)?d:null,C=(0,D.useRef)(null);(0,D.useEffect)(()=>{l&&p&&C.current!==p&&(C.current=p,console.info(`[sentient] override active: ${e} -> ${p}`))},[l,p,e]);let[m,f]=(0,D.useState)(()=>{var y,w;if(p)return{variantId:p,content:null,isLoading:!1,settled:!0};if(!c){let x=a[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 s=c.getAssignment(e,o);if(s&&(t.includes(s.variantId)||s.content))return{variantId:s.variantId,content:(y=s.content)!=null?y:null,isLoading:!1,settled:!0};let g=Ce(e);if(g){let x=$e(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}}),v=s=>{u&&h.current!==s&&(h.current=s,u(e,s))};return(0,D.useEffect)(()=>{var g;if(p||!c)return;let s=c.getAssignment(e,o);if(s&&(t.includes(s.variantId)||s.content)){f({variantId:s.variantId,content:(g=s.content)!=null?g:null,isLoading:!1,settled:!0}),v(s.variantId);return}f(y=>{var w;return y.variantId?y:{variantId:(w=t[0])!=null?w:null,content:null,isLoading:!1,settled:!1}})},[p,c,e,o]),(0,D.useEffect)(()=>{if(p||!c)return;let s=c.getAssignment(e,o);if(s&&t.includes(s.variantId))return;let g=!1;return c.assign(e,t,n,i).then(y=>{var w;g||y&&(!t.includes(y.variantId)&&!y.content||(f({variantId:y.variantId,content:(w=y.content)!=null?w:null,isLoading:!1,settled:!0}),v(y.variantId)))}),()=>{g=!0}},[p,c,e,o]),(0,D.useEffect)(()=>{if(!p&&c)return xe(e,s=>{var w;let g=c.getAssignment(e,o);if(g&&(t.includes(g.variantId)||g.content)){f({variantId:g.variantId,content:(w=g.content)!=null?w:null,isLoading:!1,settled:!0});return}let y=$e(s,t);y&&f({variantId:y,content:null,isLoading:!1,settled:!0})})},[p,c,e,o]),p?{variantId:p,content:null,isLoading:!1,settled:!0,isOverride:!0}:m}var Je=require("react/jsx-runtime");function Tt(e){var w;let t=E(),n=K(),i=Object.keys(e.variants).join("\0"),a=(0,_.useMemo)(()=>Object.keys(e.variants),[i]),{variantId:r,content:c,isOverride:o,settled:u}=X(e.id,a,e.agentData,e.agentDataByVariant),l=(0,_.useRef)(null),[h,d]=(0,_.useState)(!1);(0,_.useEffect)(()=>{d(!0)},[]);let p=(0,_.useRef)(!1),C=(0,_.useRef)(new Set),m=(0,_.useRef)(null),f=typeof e.goal=="string"?e.goal:JSON.stringify(e.goal),v=(0,_.useMemo)(()=>B(e.goal),[f]),s=typeof e.goal=="string"?e.goal:v.type;if((0,_.useEffect)(()=>te({id:e.id,variantIds:a,goal:s}),[e.id,a,s]),(0,_.useEffect)(()=>{o||u&&(!t||!r||!n||m.current!==r&&(m.current=r,N(t,n,e.id,r)))},[t,r,n,e.id,o,u]),(0,_.useEffect)(()=>{p.current=!1,C.current=new Set},[r,v]),(0,_.useEffect)(()=>{if(o||!u||!t||!r)return;let x=l.current;if(!x)return;let R=null,S=0,A=()=>{S=Date.now(),R=setTimeout(()=>{t.track({projectId:n,componentId:e.id,variantId:r,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-S}}),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,o,u]),(0,_.useEffect)(()=>{if(o||!u||!t||!r)return;let x=l.current;if(!x)return;let R=Date.now();return(0,Ue.attachMicroSignalDetectors)((S,A={})=>{var pe,me,ve;t.track({projectId:n,componentId:e.id,variantId:r,eventType:"micro_signal",payload:P({signalType:S},A)});let k=(pe=e.microSignalGoals)==null?void 0:pe[S];if(!k||C.current.has(S))return;C.current.add(S);let V=typeof k=="string"?k:k.name,Y=typeof k=="string"?1:(me=k.weight)!=null?me:1,St=typeof k=="string"?0:(ve=k.stepIndex)!=null?ve:0;t.goal(V,P({signalType:S},A),Y,St)},x,R)},[t,r,n,e.id,e.microSignalGoals,o,u]),(0,_.useEffect)(()=>{if(o||!t||!r)return;let x=l.current;if(x)return F(x,v,{fireGoal:()=>{p.current||(p.current=!0,t.track({projectId:n,componentId:e.id,variantId:r,eventType:"goal_achieved",goalType:s,payload:{reward:1}}),t.goal(s,{componentId:e.id,variantId:r},1,0))},fireStep:(R,S,A)=>{t.track({projectId:n,componentId:e.id,variantId:r,eventType:"goal_achieved",goalType:R,payload:{reward:S}}),t.goal(R,{},S,A)}})},[t,r,n,e.id,v,s,o]),e.clientOnly&&(!h||!t)||!r)return null;let g=(w=e.variants[r])!=null?w:null,y=g===null?c:null;return O()&&g===null&&y===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,Je.jsx)("div",{ref:l,"data-sentient-id":e.id,"data-sentient-variant":r,children:g!=null?g:y})}var Ve=(0,_.memo)(Tt,(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(a=>a in t.variants&&Object.is(e.variants[a],t.variants[a]))});var L=require("react");var ze=require("react/jsx-runtime");function He({id:e,default:t,component:n="span",className:i,goal:a}){var R;let r=E(),c=K(),o=oe(),u=ie(),l=(0,L.useRef)(null),h=(0,L.useRef)(null),d=(0,L.useSyncExternalStore)(W,()=>z(e),()=>null),[p,C]=(0,L.useState)(()=>{var S,A;return(A=(S=r==null?void 0:r.getAssignment(e,u))==null?void 0:S.content)!=null?A:null}),[m,f]=(0,L.useState)(()=>{var S,A;return(A=(S=r==null?void 0:r.getAssignment(e,u))==null?void 0:S.variantId)!=null?A:null});(0,L.useEffect)(()=>{var A;if(d||!r||((A=r.getAssignment(e,u))==null?void 0:A.content)!==void 0)return;let S=!1;return r.assign(e).then(k=>{if(!S){if(!k){O()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}f(k.variantId),k.content&&C(k.content)}}),()=>{S=!0}},[r,e,u,d]),(0,L.useEffect)(()=>{d||!r||!m||!c||l.current!==m&&(l.current=m,r.track({projectId:c,componentId:e,variantId:m,eventType:"variant_assigned",payload:{}}),o==null||o(e,m))},[r,m,c,e,o,d]);let v=a===void 0?"":typeof a=="string"?a:JSON.stringify(a),s=(0,L.useMemo)(()=>a===void 0?null:B(a),[v]),g=a===void 0?null:typeof a=="string"?a:s.type,y=(0,L.useRef)(!1);(0,L.useEffect)(()=>{y.current=!1},[m,v]),(0,L.useEffect)(()=>{if(d||!r||!m||!c||!s||!g)return;let S=h.current;if(S)return F(S,s,{fireGoal:()=>{y.current||(y.current=!0,r.track({projectId:c,componentId:e,variantId:m,eventType:"goal_achieved",goalType:g,payload:{reward:1}}),r.goal(g,{componentId:e,variantId:m},1,0))},fireStep:(A,k,V)=>{r.track({projectId:c,componentId:e,variantId:m,eventType:"goal_achieved",goalType:A,payload:{reward:k}}),r.goal(A,{},k,V)}})},[r,m,c,e,s,g,d]);let w=p!=null?p:t;if(d){let S=r==null?void 0:r.getAssignment(e,u);w=S&&S.variantId===d&&(R=S.content)!=null?R:t}return(0,ze.jsx)(n,{ref:S=>{h.current=S},className:i,children:w})}var Xe=require("react");function qe(e){let t=E();return(0,Xe.useCallback)((n,i)=>{var a,r;z(e)||(t==null||t.componentGoal(e,n,i),t==null||t.goal(n,(a=i==null?void 0:i.metadata)!=null?a:{},(r=i==null?void 0:i.reward)!=null?r:1,0))},[t,e])}var Ye=require("@sentientui/core"),Ze=require("@sentientui/policy"),tt=require("react/jsx-runtime");function Qe(e){return JSON.stringify(e).replace(/</g,"\\u003c")}function Dt(e){return e.persona?'(function(){try{var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",'+Qe(e.persona.persona)+');d.setAttribute("data-sentient-confidence",'+Qe((0,Ze.confidenceBand)(e.persona.confidence))+");}catch(e){}})();":(0,Ye.renderPrePaintScript)(e.apiKey)}function et(e){return(0,tt.jsx)("script",{"data-sentient-persona-script":"",nonce:e.nonce,dangerouslySetInnerHTML:{__html:Dt(e)}})}var j=require("react"),ot=require("@sentientui/policy");var M=require("react"),U=require("@sentientui/core"),rt=require("@sentientui/policy");var nt=new Set;function se(e,t){var h;(0,M.useSyncExternalStore)(W,ce,()=>0);let n=E(),i=Ke(),[,a]=(0,M.useReducer)(d=>d+1,0),r=typeof window!="undefined"?(h=window.__sentient_slot_overrides)==null?void 0:h[e]:void 0,c=r===void 0?i[e]:void 0,o=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&&o===null;(0,M.useEffect)(()=>{if(!u||!n)return;let d=!1;return n.decide({slots:[t]}).then(p=>{!d&&p&&a()}),()=>{d=!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(o!==null)return{result:o,arm:(0,U.armOfResult)(o),source:"client"};let d=(0,U.baselineResultFor)(t);return{result:d,arm:(0,U.armOfResult)(d),source:"baseline"}})();return(0,M.useEffect)(()=>{O()&&(!n||n.isLocal===!0||l.source==="baseline"&&(nt.has(e)||(nt.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 Mt(){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 it(){let e=E(),t=je();(0,M.useSyncExternalStore)(W,ce,()=>0);let[n,i]=(0,M.useState)(!1);(0,M.useEffect)(()=>i(!0),[]);let a=o=>({persona:o.persona,confidence:o.confidence,band:(0,rt.confidenceBand)(o.confidence)});if(!n)return t?a(t):null;let r=Mt();if(r)return a(r);if(t)return a(t);let c=e?e.getPersona():null;return c?a(c):null}var ue=new Set;function Bt(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/[\\"]/g,"\\$&")}function st(e,t,n){let i=E(),a=K(),r=JSON.stringify(t),c=(0,j.useMemo)(()=>({id:e,dims:t}),[e,r]),{result:o,arm:u,source:l}=se(e,c),h=(0,j.useMemo)(()=>typeof o=="string"?{}:o,[u]);if(O()&&!ue.has(e)){let m=(0,ot.validateSlotDecl)({id:e,dims:Object.fromEntries(Object.entries(t).map(([v,s])=>[v,[...s]]))}),f=Object.values(t).reduce((v,s)=>v*s.length,1);m.ok?f>4&&(ue.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.`)):(ue.add(e),console.warn(`[sentient] useAdaptiveTokens("${e}"): invalid declaration \u2014 ${m.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,j.useEffect)(()=>ne({id:e,dims:t}),[e]);let p=(0,j.useRef)(null);(0,j.useEffect)(()=>{!i||l==="baseline"||l==="override"||p.current===u||(p.current=u,N(i,a,e,u))},[i,a,e,u,l]),(0,j.useEffect)(()=>{if(!i||!(n!=null&&n.goal)||l==="override")return;let m=document.querySelector(`[data-sentient-slot="${Bt(e)}"]`);if(!m){O()&&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=J(n.goal),v=!1;return F(m,B(n.goal),{fireGoal:()=>{v||(v=!0,i.componentGoal(e,f),i.goal(f,{componentId:e,arm:u},1,0))},fireStep:(s,g,y)=>{i.componentGoal(e,s,{reward:g}),i.goal(s,{componentId:e,arm:u},g,y)}})},[i,e,d,u,l]);let C=(0,j.useMemo)(()=>{let m={"data-sentient-slot":e};for(let[f,v]of Object.entries(h))m[`data-${f}`]=v;return m},[e,h]);return{tokens:h,props:C}}var G=require("react"),lt=require("@sentientui/core");var at=new Set;function ct(e,t){var R;if(O()&&!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=E(),i=K(),a=Object.keys(t.variants).join(" "),r=(0,G.useMemo)(()=>Object.keys(t.variants),[a]),{variantId:c,isOverride:o,settled:u}=X(e,r),l=(R=c!=null?c:r[0])!=null?R:"",h=t.variants[l],[d,p]=(0,G.useState)(null),C=(0,G.useRef)(null),m=(0,G.useCallback)(S=>{C.current=S,p(S)},[]),f=typeof t.goal=="string"?t.goal:JSON.stringify(t.goal),v=(0,G.useMemo)(()=>B(t.goal),[f]),s=J(t.goal);(0,G.useEffect)(()=>te({id:e,variantIds:r,goal:s}),[e,r,s]);let g=(0,G.useRef)(null);(0,G.useEffect)(()=>{o||u&&(!n||!l||!d||g.current!==l&&(g.current=l,N(n,i,e,l)))},[n,i,e,l,d,o,u]);let y=(0,G.useRef)(!1);(0,G.useEffect)(()=>{y.current=!1},[l,f]),(0,G.useEffect)(()=>{if(!o&&!(!n||!l||!d))return F(d,v,{fireGoal:()=>{y.current||(y.current=!0,n.track({projectId:i,componentId:e,variantId:l,eventType:"goal_achieved",goalType:s,payload:{reward:1}}),n.goal(s,{componentId:e,variantId:l},1,0))},fireStep:(S,A,k)=>{n.track({projectId:i,componentId:e,variantId:l,eventType:"goal_achieved",goalType:S,payload:{reward:A}}),n.goal(S,{},A,k)}})},[n,d,l,i,e,v,s,o]),(0,G.useEffect)(()=>{if(o||!n||!l||!d)return;let S=Date.now();return(0,lt.attachMicroSignalDetectors)((A,k={})=>{n.track({projectId:i,componentId:e,variantId:l,eventType:"micro_signal",payload:P({signalType:A},k)})},d,S)},[n,d,l,i,e,o]),(0,G.useEffect)(()=>{if(!O()||!n)return;let S=setTimeout(()=>{!C.current&&!at.has(e)&&(at.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(S)},[n,e]);let w=(0,G.useCallback)((S,A)=>{var V,Y;if(o)return;let k=S!=null?S:s;n==null||n.componentGoal(e,k,A),n==null||n.goal(k,(V=A==null?void 0:A.metadata)!=null?V:{},(Y=A==null?void 0:A.reward)!=null?Y:1,0)},[n,e,s,o]),x=(0,G.useMemo)(()=>({ref:m,"data-sentient-id":e,"data-sentient-variant":l}),[m,e,l]);return{variant:l,value:h,bind:x,fireGoal:w}}var I=require("react");var dt=require("react/jsx-runtime"),ae=new Set;function ut(e){var v;let t=E(),n=K(),i=(0,I.useRef)(null),a=Object.keys(e.arrangements).join(" "),r=(0,I.useMemo)(()=>Object.keys(e.arrangements),[a]),c=(0,I.useMemo)(()=>P({id:e.id,arms:r},e.baseline!==void 0?{baseline:e.baseline}:{}),[e.id,r,e.baseline]),{arm:o,source:u}=se(e.id,c);O()&&e.baseline!==void 0&&e.baseline!==r[0]&&!ae.has(e.id+":baseline")&&(ae.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),h=new Map;for(let s of l)h.set(String((v=s.key)!=null?v:"").replace(/^\.\$/,""),s);let d=e.arrangements[o],p=d!==void 0&&d.length===l.length&&d.every(s=>h.has(s));O()&&d!==void 0&&!p&&!ae.has(e.id+":keys")&&(ae.add(e.id+":keys"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: arrangement "${o}" [${d.join(", ")}] does not match the children's keys \u2014 rendering declaration order (fail-safe).`));let C=p?d.map(s=>h.get(s)):l;(0,I.useEffect)(()=>ne({id:e.id,arms:Object.keys(e.arrangements)}),[e.id]);let m=(0,I.useRef)(null);(0,I.useEffect)(()=>{!t||u==="baseline"||u==="override"||m.current===o||(m.current=o,N(t,n,e.id,o))},[t,n,e.id,o,u]);let f=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 s=i.current;if(!s)return;let g=J(e.goal),y=!1;return F(s,B(e.goal),{fireGoal:()=>{y||(y=!0,t.componentGoal(e.id,g),t.goal(g,{componentId:e.id,arm:o},1,0))},fireStep:(w,x,R)=>{t.componentGoal(e.id,w,{reward:x}),t.goal(w,{componentId:e.id,arm:o},x,R)}})},[t,e.id,f,o,u]),(0,dt.jsx)("div",{ref:i,"data-sentient-id":e.id,"data-sentient-variant":o,children:C})}var de=require("@sentientui/core");var Ft=["page","blocks","layoutOrder"],ft=new Map;function gt(e,t){ft.set(e,t)}function fe(e){return ft.get(e)}function pt(e){var a,r;let t=(r=(a=e.content)!=null?a:fe(e.page))!=null?r:{},n={};for(let[c,o]of Object.entries(t))Ft.includes(c)||(n[c]=o);let i=Z(P({},n),{page:e.page,blocks:e.blocks});return e.layoutOrder&&(i.layoutOrder=e.layoutOrder),i}function mt(e){return`<script type="application/ld+json">${ge(e)}</script>`}function ge(e){return JSON.stringify(P({"@context":"https://schema.org","@type":"WebPage"},e)).replace(/</g,"\\u003c")}function vt(e){let t=[];e.title&&t.push(`# ${e.title}`,""),e.summary&&t.push(String(e.summary),"");for(let[n,i]of Object.entries(e))["page","title","summary","blocks","layoutOrder"].includes(n)||t.push(`## ${n}`,"","```json",JSON.stringify(i,null,2),"```","");if(e.blocks.length>0){t.push("## blocks","");for(let n of e.blocks)t.push(`- **${n.id}** \u2192 variant \`${n.variant}\``),n.content!==void 0&&t.push(""," ```json",JSON.stringify(n.content,null,2)," ```");t.push("")}return t.join(`
2
+ "use strict";var kt=Object.create;var Y=Object.defineProperty,Ct=Object.defineProperties,Gt=Object.getOwnPropertyDescriptor,Rt=Object.getOwnPropertyDescriptors,_t=Object.getOwnPropertyNames,te=Object.getOwnPropertySymbols,Ot=Object.getPrototypeOf,ge=Object.prototype.hasOwnProperty,Ce=Object.prototype.propertyIsEnumerable;var ke=(e,t,n)=>t in e?Y(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,A=(e,t)=>{for(var n in t||(t={}))ge.call(t,n)&&ke(e,n,t[n]);if(te)for(var n of te(t))Ce.call(t,n)&&ke(e,n,t[n]);return e},ne=(e,t)=>Ct(e,Rt(t));var Ge=(e,t)=>{var n={};for(var o in e)ge.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(e!=null&&te)for(var o of te(e))t.indexOf(o)<0&&Ce.call(e,o)&&(n[o]=e[o]);return n};var Et=(e,t)=>{for(var n in t)Y(e,n,{get:t[n],enumerable:!0})},Re=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of _t(t))!ge.call(e,r)&&r!==n&&Y(e,r,{get:()=>t[r],enumerable:!(o=Gt(t,r))||o.enumerable});return e};var _e=(e,t,n)=>(n=e!=null?kt(Ot(e)):{},Re(t||!e||!e.__esModule?Y(n,"default",{value:e,enumerable:!0}):n,e)),It=e=>Re(Y({},"__esModule",{value:!0}),e);var $t={};Et($t,{Adaptive:()=>Qe,AdaptiveGroup:()=>pt,AdaptiveProvider:()=>Ve,AdaptiveText:()=>Ze,SentientPersonaScript:()=>ot,buildAgentFeed:()=>ht,defineAgentContent:()=>St,detectSegment:()=>Se.deriveSessionSegment,getAgentContent:()=>he,grantConsent:()=>xt.grantConsent,renderAgentJsonLd:()=>bt,renderAgentJsonLdBody:()=>be,renderAgentMarkdown:()=>wt,useAdaptive:()=>mt,useAdaptiveApiBaseUrl:()=>He,useAdaptiveGoal:()=>ce,useAdaptivePersona:()=>ut,useAdaptiveTokens:()=>dt,useAssignment:()=>Q,useInitialAssignments:()=>se,useLayoutOrder:()=>Ne,usePageGoal:()=>tt,useSentient:()=>_});module.exports=It($t);var w=require("react"),X=require("@sentientui/core");var Oe=new Map,re=new Map;function Ee(e,t){let n=re.get(e);return n||(n=new Set,re.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&re.delete(e)}}function Ie(e,t){Oe.set(e,t);let n=re.get(e);if(n)for(let o of n)try{o(t)}catch(r){}}function Le(e){var t;return(t=Oe.get(e))!=null?t:null}var Lt={on:!1,listeners:new Set};function Pe(){if(typeof window=="undefined")return Lt;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function me(){return Pe().on}function Te(e){let t=Pe().listeners;return t.add(e),()=>{t.delete(e)}}function De(e){return{isLocal:e.isLocal,track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},fetchWeights:()=>Promise.resolve([]),getAssignment:(t,n)=>e.getAssignment(t,n),assign:(t,n,o,r)=>e.assign(t,n,o,r),decide:()=>Promise.resolve(null),getSlotResult:t=>e.getSlotResult(t),getPersona:()=>e.getPersona(),getGraph:()=>e.getGraph(),dispose:()=>e.dispose(),destroy:()=>e.destroy()}}var Me="sentient:overrides-changed";function pe(){var e;return typeof window=="undefined"?0:(e=window.__sentient_overrides_version)!=null?e:0}function $(e){return typeof window=="undefined"?()=>{}:(window.addEventListener(Me,e),()=>window.removeEventListener(Me,e))}function Fe(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function I(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}function F(e){return typeof e=="string"?{type:"click"}:e}function z(e){return typeof e=="string"?e:e.type}function B(e){if(typeof e!="string"&&(e.type==="click"||e.type==="form_submit"||e.type==="scroll_depth"))return e.value}function Pt(e){if(!(e instanceof Element))return!1;let t=e.tagName.toLowerCase();return t==="a"||t==="button"?!0:e.getAttribute("role")==="button"}function Be(e,t,n){if(n){try{let r=e;for(;r&&r!==t;){if(r.matches(n))return!0;r=r.parentElement}}catch(r){}return!1}let o=e;for(;o&&o!==t;){if(Pt(o))return!0;o=o.parentElement}return!1}function K(e,t,n){if(t.type==="weighted_composite"){let s=new Set,c=[];return t.steps.forEach(({goal:l,name:h,weight:d},m)=>{let G=()=>{s.has(m)||(s.add(m),n.fireStep(h,d,m))};if(l.type==="click"){let b=f=>{let p=f.target;p instanceof Element&&Be(p,e,l.selector)&&G()};e.addEventListener("click",b),c.push(()=>e.removeEventListener("click",b));return}if(l.type==="form_submit"){let b=f=>{f.target instanceof HTMLFormElement&&e.contains(f.target)&&G()};e.addEventListener("submit",b),c.push(()=>e.removeEventListener("submit",b));return}if(l.type==="scroll_depth"){let b=Math.max(0,Math.min(1,l.threshold)),f=new IntersectionObserver(p=>{for(let a of p)if(a.intersectionRatio>=b){G(),f.disconnect();break}},{threshold:[b]});f.observe(e),c.push(()=>f.disconnect())}}),()=>{for(let l of c)l()}}let o=t.type==="composite"?t.all:[t],r=new Set(o.map((s,c)=>c)),i=s=>{r.delete(s),r.size===0&&n.fireGoal()},u=[];return o.forEach((s,c)=>{if(s.type==="click"){let l=h=>{let d=h.target;d instanceof Element&&Be(d,e,s.selector)&&(t.type==="composite"?i(c):n.fireGoal())};e.addEventListener("click",l),u.push(()=>e.removeEventListener("click",l));return}if(s.type==="form_submit"){let l=h=>{h.target instanceof HTMLFormElement&&e.contains(h.target)&&(t.type==="composite"?i(c):n.fireGoal())};e.addEventListener("submit",l),u.push(()=>e.removeEventListener("submit",l));return}if(s.type==="scroll_depth"){let l=Math.max(0,Math.min(1,s.threshold)),h=new IntersectionObserver(d=>{for(let m of d)if(m.intersectionRatio>=l){t.type==="composite"?i(c):n.fireGoal(),h.disconnect();break}},{threshold:[l]});h.observe(e),u.push(()=>h.disconnect());return}}),()=>{for(let s of u)s()}}function N(e,t,n,o){e.track({projectId:t,componentId:n,variantId:o,eventType:"variant_assigned",payload:{}})}var Tt={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function U(){if(typeof window=="undefined")return Tt;let e=window;return e.__sentient_registry||(e.__sentient_registry={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0}),e.__sentient_registry}function Z(){U().version+=1;for(let e of U().listeners)e()}var Ke=()=>{};function ie(e){return I()?(U().components.set(e.id,e),Z(),()=>{U().components.delete(e.id),Z()}):Ke}function oe(e){return I()?(U().slots.set(e.id,e),Z(),()=>{U().slots.delete(e.id),Z()}):Ke}function ve(e){I()&&(U().sections=[...e],Z())}var ze=require("react/jsx-runtime");function Dt(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{let n=(0,X.detectDeviceClass)((e=navigator.userAgent)!=null?e:""),o=(0,X.detectTrafficSource)((t=document.referrer)!=null?t:"",window.location.origin);return`${n}:${o}`}catch(n){return"desktop:direct"}}var je="https://api.sentient-ui.com/v1",T=(0,w.createContext)({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialPersona:null,apiBaseUrl:je,debug:!1});function Mt(e){let[t,n]=(0,w.useState)(!1),o=(0,w.useRef)(e);o.current=e;let{cookie:r,value:i,event:u}=e!=null?e:{},s=typeof(e==null?void 0:e.check)=="function";return(0,w.useEffect)(()=>{let c=()=>{var m;let h=o.current;if(!h)return!1;if(h.check)return h.check()===!0;if(!h.cookie||typeof document=="undefined")return!1;let d=`${h.cookie}=${(m=h.value)!=null?m:"accepted"}`;return document.cookie.split("; ").some(G=>G.trim()===d)};if(c()){n(!0);return}if(!u)return;let l=()=>{c()&&n(!0)};return window.addEventListener(u,l),()=>window.removeEventListener(u,l)},[r,i,u,s]),t}function Ve(e){var G,b;let[t,n]=(0,w.useState)(null),[o]=(0,w.useState)(()=>{var f;return(f=e.sessionSegment)!=null?f:Dt()}),[r,i]=(0,w.useState)(me());(0,w.useEffect)(()=>Te(()=>i(me())),[]);let u=Mt(e.consentFrom),s=e.consentFrom?e.consent===!0||u:e.consent;(0,w.useEffect)(()=>{if(s===!1&&!e.preConsentBehavior){n(x=>(x==null||x.destroy(),null));return}let f={apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,sessionSegment:o,consent:s,preConsentBehavior:e.preConsentBehavior,respectDoNotTrack:e.respectDoNotTrack,ssrSessionId:e.ssrSessionId,country:e.country,localMode:e.localMode,initialSlots:e.initialSlots,initialPersona:e.initialPersona,ingestUrl:e.apiBaseUrl?`${e.apiBaseUrl.replace(/\/$/,"")}/events`:void 0},p=!1,a=null,g=null,S=x=>{e.engagement!==!1&&import("@sentientui/core/engagement").then(({startEngagementCapture:k})=>{p||(g=k(x,{apiKey:e.apiKey,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:x})=>{p||(a=x(ne(A({},f),{graph:!0,captureDomText:e.captureDomText===!0})),n(a),S(a))}):(a=(0,X.init)(f),n(a),S(a)),()=>{p=!0,g==null||g(),a==null||a.dispose()}},[s]),(0,w.useEffect)(()=>{if(!t)return;let f=!1,p=async()=>{if(f)return;let g;try{g=await t.fetchWeights()}catch(S){return}if(!f)for(let S of g){let x={componentId:S.componentId,updatedAt:S.updatedAt,variants:S.variants.map(k=>{var R;return{variantId:k.variantId,pulls:k.pulls,avgReward:(R=k.avgReward)!=null?R:0}})};Ie(S.componentId,x)}};p();let a=setInterval(()=>{p()},6e4);return()=>{f=!0,clearInterval(a)}},[t]);let c=(G=e.ssrFallback)!=null?G:"first",l=((b=e.apiBaseUrl)!=null?b:je).replace(/\/$/,""),h=(0,w.useRef)(null);(0,w.useEffect)(()=>{var a;if(typeof process!="undefined"&&((a=process.env)==null?void 0:a.NODE_ENV)==="production")return;let f={apiKey:e.apiKey,context:e.context,country:e.country,apiBaseUrl:l},p=h.current;if(h.current=f,p!==null)for(let g of["apiKey","context","country","apiBaseUrl"])Object.is(p[g],f[g])||console.warn(`[sentient] AdaptiveProvider: \`${g}\` changed after initialisation, but the SDK client is stable for the session and only re-inits on \`consent\` \u2014 the new value is ignored. Remount the provider (e.g. via a changing \`key\` prop) to apply it.`)},[e.apiKey,e.context,e.country,l]),(0,w.useEffect)(()=>{var f;typeof process!="undefined"&&((f=process.env)==null?void 0:f.NODE_ENV)==="production"||Fe({apiKey:e.apiKey,apiBaseUrl:l,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,l]),(0,w.useEffect)(()=>{let f=e.initialLayoutOrder;if(f&&f.length>0){ve(f);return}e.declaredSections&&e.declaredSections.length>0&&ve(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]);let d=(0,w.useMemo)(()=>t&&r?De(t):t,[t,r]),m=(0,w.useMemo)(()=>{var f,p,a,g,S;return{client:d,apiKey:e.apiKey,initialAssignments:(f=e.initialAssignments)!=null?f:{},sessionSegment:o,ssrFallback:c,onAssignment:e.onAssignment,initialLayoutOrder:(p=e.initialLayoutOrder)!=null?p:null,initialSlots:(a=e.initialSlots)!=null?a:{},initialPersona:(g=e.initialPersona)!=null?g:null,apiBaseUrl:l,debug:(S=e.debug)!=null?S:!1}},[d,e.apiKey,e.initialAssignments,o,c,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialPersona,l,e.debug]);return(0,ze.jsx)(T.Provider,{value:m,children:e.children})}function _(){return(0,w.useContext)(T).client}function j(){return(0,w.useContext)(T).apiKey}function se(){return(0,w.useContext)(T).initialAssignments}function ae(){return(0,w.useContext)(T).sessionSegment}function We(){return(0,w.useContext)(T).ssrFallback}function le(){return(0,w.useContext)(T).onAssignment}function $e(){return(0,w.useContext)(T).debug}function Ne(){let e=(0,w.useContext)(T).initialLayoutOrder,t=(0,w.useSyncExternalStore)($,()=>{var n;return typeof window=="undefined"?null:(n=window.__sentient_layout_override)!=null?n:null},()=>null);return t!=null?t:e}function Ue(){return(0,w.useContext)(T).initialSlots}function Je(){return(0,w.useContext)(T).initialPersona}function He(){return(0,w.useContext)(T).apiBaseUrl}var O=require("react"),qe=require("@sentientui/core");var D=require("react");function q(e){var n;if(typeof window=="undefined")return null;let t=(n=window.__sentient_overrides)==null?void 0:n[e];if(t)return t;if(!window.location.search)return null;try{let o=new URLSearchParams(window.location.search);for(let r of o.getAll("sentient_variant")){let i=r.indexOf(":");if(i!==-1&&r.slice(0,i)===e)return r.slice(i+1)}}catch(o){}return null}var Ft=5;function Xe(e,t){var o,r;let n=null;for(let i of e.variants){if(!t.includes(i.variantId))continue;let u=(o=i.pulls)!=null?o:0,s=u>0?u*i.avgReward/(u+Ft):0;(!n||s>n.score)&&(n={variantId:i.variantId,score:s})}return(r=n==null?void 0:n.variantId)!=null?r:null}function Q(e,t,n,o){let r=se(),i=We(),u=_(),s=ae(),c=le(),l=$e(),h=(0,D.useRef)(null),d=(0,D.useSyncExternalStore)($,()=>q(e),()=>null),m=d&&t.includes(d)?d:null,G=(0,D.useRef)(null);(0,D.useEffect)(()=>{l&&m&&G.current!==m&&(G.current=m,console.info(`[sentient] override active: ${e} -> ${m}`))},[l,m,e]);let[b,f]=(0,D.useState)(()=>{var S,x;if(m)return{variantId:m,content:null,isLoading:!1,settled:!0};if(!u){let k=r[e];return k&&t.includes(k)?{variantId:k,content:null,isLoading:!1,settled:!0}:i==="first"&&t.length>0?{variantId:t[0],content:null,isLoading:!1,settled:!1}:{variantId:null,content:null,isLoading:!0,settled:!1}}let a=u.getAssignment(e,s);if(a&&(t.includes(a.variantId)||a.content))return{variantId:a.variantId,content:(S=a.content)!=null?S:null,isLoading:!1,settled:!0};let g=Le(e);if(g){let k=Xe(g,t);if(k)return{variantId:k,content:null,isLoading:!1,settled:!0}}return{variantId:(x=t[0])!=null?x:null,content:null,isLoading:!1,settled:!1}}),p=a=>{c&&h.current!==a&&(h.current=a,c(e,a))};return(0,D.useEffect)(()=>{var g;if(m||!u)return;let a=u.getAssignment(e,s);if(a&&(t.includes(a.variantId)||a.content)){f({variantId:a.variantId,content:(g=a.content)!=null?g:null,isLoading:!1,settled:!0}),p(a.variantId);return}f(S=>{var x;return S.variantId?S:{variantId:(x=t[0])!=null?x:null,content:null,isLoading:!1,settled:!1}})},[m,u,e,s]),(0,D.useEffect)(()=>{if(m||!u)return;let a=u.getAssignment(e,s);if(a&&t.includes(a.variantId))return;let g=!1;return u.assign(e,t,n,o).then(S=>{var x;g||S&&(!t.includes(S.variantId)&&!S.content||(f({variantId:S.variantId,content:(x=S.content)!=null?x:null,isLoading:!1,settled:!0}),p(S.variantId)))}),()=>{g=!0}},[m,u,e,s]),(0,D.useEffect)(()=>{if(!m&&u)return Ee(e,a=>{var x;let g=u.getAssignment(e,s);if(g&&(t.includes(g.variantId)||g.content)){f({variantId:g.variantId,content:(x=g.content)!=null?x:null,isLoading:!1,settled:!0});return}let S=Xe(a,t);S&&f({variantId:S,content:null,isLoading:!1,settled:!0})})},[m,u,e,s]),m?{variantId:m,content:null,isLoading:!1,settled:!0,isOverride:!0}:b}var Ye=require("react/jsx-runtime");function Bt(e){var x;let t=_(),n=j(),o=Object.keys(e.variants).join("\0"),r=(0,O.useMemo)(()=>Object.keys(e.variants),[o]),{variantId:i,content:u,isOverride:s,settled:c}=Q(e.id,r,e.agentData,e.agentDataByVariant),l=(0,O.useRef)(null),[h,d]=(0,O.useState)(!1);(0,O.useEffect)(()=>{d(!0)},[]);let m=(0,O.useRef)(!1),G=(0,O.useRef)(new Set),b=(0,O.useRef)(null),f=typeof e.goal=="string"?e.goal:JSON.stringify(e.goal),p=(0,O.useMemo)(()=>F(e.goal),[f]),a=typeof e.goal=="string"?e.goal:p.type;if((0,O.useEffect)(()=>ie({id:e.id,variantIds:r,goal:a}),[e.id,r,a]),(0,O.useEffect)(()=>{s||c&&(!t||!i||!n||b.current!==i&&(b.current=i,N(t,n,e.id,i)))},[t,i,n,e.id,s,c]),(0,O.useEffect)(()=>{m.current=!1,G.current=new Set},[i,p]),(0,O.useEffect)(()=>{if(s||!c||!t||!i)return;let k=l.current;if(!k)return;let R=null,v=0,y=()=>{v=Date.now(),R=setTimeout(()=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-v}}),R=null},800)},C=()=>{R!==null&&(clearTimeout(R),R=null)};return k.addEventListener("mouseenter",y),k.addEventListener("mouseleave",C),()=>{k.removeEventListener("mouseenter",y),k.removeEventListener("mouseleave",C),R!==null&&clearTimeout(R)}},[t,i,n,e.id,s,c]),(0,O.useEffect)(()=>{if(s||!c||!t||!i)return;let k=l.current;if(!k)return;let R=Date.now();return(0,qe.attachMicroSignalDetectors)((v,y={})=>{var we,xe,Ae;t.track({projectId:n,componentId:e.id,variantId:i,eventType:"micro_signal",payload:A({signalType:v},y)});let C=(we=e.microSignalGoals)==null?void 0:we[v];if(!C||G.current.has(v))return;G.current.add(v);let W=typeof C=="string"?C:C.name,H=typeof C=="string"?1:(xe=C.weight)!=null?xe:1,At=typeof C=="string"?0:(Ae=C.stepIndex)!=null?Ae:0;t.goal(W,{metadata:A({signalType:v},y),weight:H,stepIndex:At})},k,R)},[t,i,n,e.id,e.microSignalGoals,s,c]),(0,O.useEffect)(()=>{if(s||!t||!i)return;let k=l.current;if(!k)return;let R=B(p);return K(k,p,{fireGoal:()=>{m.current||(m.current=!0,t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:a,payload:A({reward:1},R!==void 0?{goalValue:R}:{})}),t.goal(a,A({metadata:{componentId:e.id,variantId:i},weight:1,stepIndex:0},R!==void 0?{value:R}:{})))},fireStep:(v,y,C)=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:v,payload:{reward:y}}),t.goal(v,{metadata:{},weight:y,stepIndex:C})}})},[t,i,n,e.id,p,a,s]),e.clientOnly&&(!h||!t)||!i)return null;let g=(x=e.variants[i])!=null?x:null,S=g===null?u:null;return I()&&g===null&&S===null&&console.warn(`[sentient] <Adaptive id="${e.id}"> was assigned variant "${i}" but no matching key exists in props.variants. If this is a dashboard-managed text variant, use <AdaptiveText id="${e.id}"> instead.`),(0,Ye.jsx)("div",{ref:l,"data-sentient-id":e.id,"data-sentient-variant":i,children:g!=null?g:S})}var Qe=(0,O.memo)(Bt,(e,t)=>{if(e.id!==t.id||e.goal!==t.goal&&JSON.stringify(e.goal)!==JSON.stringify(t.goal)||e.microSignalGoals!==t.microSignalGoals||e.clientOnly!==t.clientOnly||e.agentData!==t.agentData||e.agentDataByVariant!==t.agentDataByVariant)return!1;if(e.variants===t.variants)return!0;let n=Object.keys(e.variants),o=Object.keys(t.variants);return n.length!==o.length?!1:n.every(r=>r in t.variants&&Object.is(e.variants[r],t.variants[r]))});var L=require("react");var et=require("react/jsx-runtime");function Ze({id:e,default:t,component:n="span",className:o,goal:r}){var R;let i=_(),u=j(),s=le(),c=ae(),l=(0,L.useRef)(null),h=(0,L.useRef)(null),d=(0,L.useSyncExternalStore)($,()=>q(e),()=>null),[m,G]=(0,L.useState)(()=>{var v,y;return(y=(v=i==null?void 0:i.getAssignment(e,c))==null?void 0:v.content)!=null?y:null}),[b,f]=(0,L.useState)(()=>{var v,y;return(y=(v=i==null?void 0:i.getAssignment(e,c))==null?void 0:v.variantId)!=null?y:null});(0,L.useEffect)(()=>{var y;if(d||!i||((y=i.getAssignment(e,c))==null?void 0:y.content)!==void 0)return;let v=!1;return i.assign(e).then(C=>{if(!v){if(!C){I()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}f(C.variantId),C.content&&G(C.content)}}),()=>{v=!0}},[i,e,c,d]),(0,L.useEffect)(()=>{d||!i||!b||!u||l.current!==b&&(l.current=b,i.track({projectId:u,componentId:e,variantId:b,eventType:"variant_assigned",payload:{}}),s==null||s(e,b))},[i,b,u,e,s,d]);let p=r===void 0?"":typeof r=="string"?r:JSON.stringify(r),a=(0,L.useMemo)(()=>r===void 0?null:F(r),[p]),g=r===void 0?null:typeof r=="string"?r:a.type,S=(0,L.useRef)(!1);(0,L.useEffect)(()=>{S.current=!1},[b,p]),(0,L.useEffect)(()=>{if(d||!i||!b||!u||!a||!g)return;let v=h.current;if(!v)return;let y=B(a);return K(v,a,{fireGoal:()=>{S.current||(S.current=!0,i.track({projectId:u,componentId:e,variantId:b,eventType:"goal_achieved",goalType:g,payload:A({reward:1},y!==void 0?{goalValue:y}:{})}),i.goal(g,A({metadata:{componentId:e,variantId:b},weight:1,stepIndex:0},y!==void 0?{value:y}:{})))},fireStep:(C,W,H)=>{i.track({projectId:u,componentId:e,variantId:b,eventType:"goal_achieved",goalType:C,payload:{reward:W}}),i.goal(C,{metadata:{},weight:W,stepIndex:H})}})},[i,b,u,e,a,g,d]);let x=m!=null?m:t;if(d){let v=i==null?void 0:i.getAssignment(e,c);x=v&&v.variantId===d&&(R=v.content)!=null?R:t}return(0,et.jsx)(n,{ref:v=>{h.current=v},className:o,children:x})}var ue=require("react");function ce(e){let t=_(),n=(0,ue.useRef)(new Set);return(0,ue.useCallback)((o,r)=>{var i,u;if(!q(e)){if(r!=null&&r.once){if(n.current.has(o))return;n.current.add(o)}t==null||t.componentGoal(e,o,r),t==null||t.goal(o,A(A(A({metadata:(i=r==null?void 0:r.metadata)!=null?i:{},weight:(u=r==null?void 0:r.reward)!=null?u:1,stepIndex:0},(r==null?void 0:r.value)!==void 0?{value:r.value}:{}),(r==null?void 0:r.currency)!==void 0?{currency:r.currency}:{}),(r==null?void 0:r.externalId)!==void 0?{externalId:r.externalId}:{}))}},[t,e])}var ee=require("react");function tt(e,t={}){let c=t,{componentId:n}=c,o=Ge(c,["componentId"]),r=_(),i=ce(n!=null?n:""),u=(0,ee.useRef)(!1),s=(0,ee.useRef)(o);s.current=o,(0,ee.useEffect)(()=>{if(!r||u.current)return;u.current=!0;let{metadata:l,reward:h,value:d,currency:m,externalId:G}=s.current;if(n){i(e,s.current);return}r.goal(e,A(A(A({metadata:l!=null?l:{},weight:h!=null?h:1,stepIndex:0},d!==void 0?{value:d}:{}),m!==void 0?{currency:m}:{}),G!==void 0?{externalId:G}:{}))},[r,n,e,i])}var rt=require("@sentientui/core"),it=require("@sentientui/policy"),st=require("react/jsx-runtime");function nt(e){return JSON.stringify(e).replace(/</g,"\\u003c")}function Kt(e){return e.persona?'(function(){try{var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",'+nt(e.persona.persona)+');d.setAttribute("data-sentient-confidence",'+nt((0,it.confidenceBand)(e.persona.confidence))+");}catch(e){}})();":(0,rt.renderPrePaintScript)(e.apiKey)}function ot(e){return(0,st.jsx)("script",{"data-sentient-persona-script":"",nonce:e.nonce,dangerouslySetInnerHTML:{__html:Kt(e)}})}var V=require("react"),ct=require("@sentientui/policy");var M=require("react"),J=require("@sentientui/core"),lt=require("@sentientui/policy");var at=new Set;function de(e,t){var h;(0,M.useSyncExternalStore)($,pe,()=>0);let n=_(),o=Ue(),[,r]=(0,M.useReducer)(d=>d+1,0),i=typeof window!="undefined"?(h=window.__sentient_slot_overrides)==null?void 0:h[e]:void 0,u=i===void 0?o[e]:void 0,s=i===void 0&&u===void 0&&n?n.getSlotResult(e):null,c=(n==null?void 0:n.isLocal)===!0&&i===void 0&&u===void 0&&s===null;(0,M.useEffect)(()=>{if(!c||!n)return;let d=!1;return n.decide({slots:[t]}).then(m=>{!d&&m&&r()}),()=>{d=!0}},[n,e,c]);let l=(()=>{if(i!==void 0)return{result:i,arm:(0,J.armOfResult)(i),source:"override"};if(u!==void 0)return{result:u,arm:(0,J.armOfResult)(u),source:"preloaded"};if(s!==null)return{result:s,arm:(0,J.armOfResult)(s),source:"client"};let d=(0,J.baselineResultFor)(t);return{result:d,arm:(0,J.armOfResult)(d),source:"baseline"}})();return(0,M.useEffect)(()=>{I()&&(!n||n.isLocal===!0||l.source==="baseline"&&(at.has(e)||(at.add(e),console.warn(`[sentient] slot "${e}" resolved to its baseline \u2014 no SSR-preloaded or decided result. Keyed clients decide slots server-side, so this slot serves baseline for the whole session and records no exposure. Preload it via loadAdaptiveDecision()/initialSlots so it can serve a decided arm and learn.`))))},[n,l.source,e]),l}function jt(){var t;if(typeof window=="undefined")return null;let e=window.__sentient_persona_override;if(e!=null&&e.persona)return{persona:e.persona,confidence:(t=e.confidence)!=null?t:1};try{let n=new URLSearchParams(window.location.search).get("sentient_persona");if(n)return{persona:n,confidence:1}}catch(n){}return null}function ut(){let e=_(),t=Je();(0,M.useSyncExternalStore)($,pe,()=>0);let[n,o]=(0,M.useState)(!1);(0,M.useEffect)(()=>o(!0),[]);let r=s=>({persona:s.persona,confidence:s.confidence,band:(0,lt.confidenceBand)(s.confidence)});if(!n)return t?r(t):null;let i=jt();if(i)return r(i);if(t)return r(t);let u=e?e.getPersona():null;return u?r(u):null}var ye=new Set;function Vt(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/[\\"]/g,"\\$&")}function dt(e,t,n){let o=_(),r=j(),i=JSON.stringify(t),u=(0,V.useMemo)(()=>({id:e,dims:t}),[e,i]),{result:s,arm:c,source:l}=de(e,u),h=(0,V.useMemo)(()=>typeof s=="string"?{}:s,[c]);if(I()&&!ye.has(e)){let b=(0,ct.validateSlotDecl)({id:e,dims:Object.fromEntries(Object.entries(t).map(([p,a])=>[p,[...a]]))}),f=Object.values(t).reduce((p,a)=>p*a.length,1);b.ok?f>4&&(ye.add(e),console.warn(`[sentient] useAdaptiveTokens("${e}") declares ${f} combinations \u2014 more than the recommended 4. Each extra combination needs more traffic to learn; consider fewer dims/values.`)):(ye.add(e),console.warn(`[sentient] useAdaptiveTokens("${e}"): invalid declaration \u2014 ${b.reason}. Serving baseline.`))}let d=(n==null?void 0:n.goal)===void 0?null:typeof n.goal=="string"?n.goal:JSON.stringify(n.goal);(0,V.useEffect)(()=>oe({id:e,dims:t}),[e]);let m=(0,V.useRef)(null);(0,V.useEffect)(()=>{!o||l==="baseline"||l==="override"||m.current===c||(m.current=c,N(o,r,e,c))},[o,r,e,c,l]),(0,V.useEffect)(()=>{if(!o||!(n!=null&&n.goal)||l==="override")return;let b=document.querySelector(`[data-sentient-slot="${Vt(e)}"]`);if(!b){I()&&console.warn(`[sentient] useAdaptiveTokens("${e}"): a goal is declared but no element carries the returned props \u2014 spread {...props} on the slot's element.`);return}let f=z(n.goal),p=B(n.goal),a=!1;return K(b,F(n.goal),{fireGoal:()=>{a||(a=!0,p!==void 0?o.componentGoal(e,f,{value:p}):o.componentGoal(e,f),o.goal(f,A({metadata:{componentId:e,arm:c},weight:1,stepIndex:0},p!==void 0?{value:p}:{})))},fireStep:(g,S,x)=>{o.componentGoal(e,g,{reward:S}),o.goal(g,{metadata:{componentId:e,arm:c},weight:S,stepIndex:x})}})},[o,e,d,c,l]);let G=(0,V.useMemo)(()=>{let b={"data-sentient-slot":e};for(let[f,p]of Object.entries(h))b[`data-${f}`]=p;return b},[e,h]);return{tokens:h,props:G}}var E=require("react"),gt=require("@sentientui/core");var ft=new Set;function mt(e,t){var R;if(I()&&!t.goal)throw new Error(`[sentient] useAdaptive("${e}"): a goal is required \u2014 without one the optimizer accumulates exposures with no rewards and cannot learn. Pass e.g. goal: 'buy_click'.`);let n=_(),o=j(),r=Object.keys(t.variants).join(" "),i=(0,E.useMemo)(()=>Object.keys(t.variants),[r]),{variantId:u,isOverride:s,settled:c}=Q(e,i),l=(R=u!=null?u:i[0])!=null?R:"",h=t.variants[l],[d,m]=(0,E.useState)(null),G=(0,E.useRef)(null),b=(0,E.useCallback)(v=>{G.current=v,m(v)},[]),f=typeof t.goal=="string"?t.goal:JSON.stringify(t.goal),p=(0,E.useMemo)(()=>F(t.goal),[f]),a=z(t.goal);(0,E.useEffect)(()=>ie({id:e,variantIds:i,goal:a}),[e,i,a]);let g=(0,E.useRef)(null);(0,E.useEffect)(()=>{s||c&&(!n||!l||!d||g.current!==l&&(g.current=l,N(n,o,e,l)))},[n,o,e,l,d,s,c]);let S=(0,E.useRef)(!1);(0,E.useEffect)(()=>{S.current=!1},[l,f]),(0,E.useEffect)(()=>{if(s||!n||!l||!d)return;let v=B(p);return K(d,p,{fireGoal:()=>{S.current||(S.current=!0,n.track({projectId:o,componentId:e,variantId:l,eventType:"goal_achieved",goalType:a,payload:A({reward:1},v!==void 0?{goalValue:v}:{})}),n.goal(a,A({metadata:{componentId:e,variantId:l},weight:1,stepIndex:0},v!==void 0?{value:v}:{})))},fireStep:(y,C,W)=>{n.track({projectId:o,componentId:e,variantId:l,eventType:"goal_achieved",goalType:y,payload:{reward:C}}),n.goal(y,{metadata:{},weight:C,stepIndex:W})}})},[n,d,l,o,e,p,a,s]),(0,E.useEffect)(()=>{if(s||!n||!l||!d)return;let v=Date.now();return(0,gt.attachMicroSignalDetectors)((y,C={})=>{n.track({projectId:o,componentId:e,variantId:l,eventType:"micro_signal",payload:A({signalType:y},C)})},d,v)},[n,d,l,o,e,s]),(0,E.useEffect)(()=>{if(!I()||!n)return;let v=setTimeout(()=>{!G.current&&!ft.has(e)&&(ft.add(e),console.warn(`[sentient] useAdaptive("${e}"): bind was never attached \u2014 spread {...bind} on the rendered element, otherwise exposure and goal tracking cannot work and the optimizer learns nothing.`))},0);return()=>clearTimeout(v)},[n,e]);let x=(0,E.useCallback)((v,y)=>{var W,H;if(s)return;let C=v!=null?v:a;n==null||n.componentGoal(e,C,y),n==null||n.goal(C,A(A(A({metadata:(W=y==null?void 0:y.metadata)!=null?W:{},weight:(H=y==null?void 0:y.reward)!=null?H:1,stepIndex:0},(y==null?void 0:y.value)!==void 0?{value:y.value}:{}),(y==null?void 0:y.currency)!==void 0?{currency:y.currency}:{}),(y==null?void 0:y.externalId)!==void 0?{externalId:y.externalId}:{}))},[n,e,a,s]),k=(0,E.useMemo)(()=>({ref:b,"data-sentient-id":e,"data-sentient-variant":l}),[b,e,l]);return{variant:l,value:h,bind:k,fireGoal:x}}var P=require("react");var vt=require("react/jsx-runtime"),fe=new Set;function pt(e){var p;let t=_(),n=j(),o=(0,P.useRef)(null),r=Object.keys(e.arrangements).join(" "),i=(0,P.useMemo)(()=>Object.keys(e.arrangements),[r]),u=(0,P.useMemo)(()=>A({id:e.id,arms:i},e.baseline!==void 0?{baseline:e.baseline}:{}),[e.id,i,e.baseline]),{arm:s,source:c}=de(e.id,u);I()&&e.baseline!==void 0&&e.baseline!==i[0]&&!fe.has(e.id+":baseline")&&(fe.add(e.id+":baseline"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: baseline "${e.baseline}" is not the first-declared arrangement ("${i[0]}"). The first arrangement should usually be the page's real incumbent (the holdout sees it).`));let l=P.Children.toArray(e.children).filter(P.isValidElement),h=new Map;for(let a of l)h.set(String((p=a.key)!=null?p:"").replace(/^\.\$/,""),a);let d=e.arrangements[s],m=d!==void 0&&d.length===l.length&&d.every(a=>h.has(a));I()&&d!==void 0&&!m&&!fe.has(e.id+":keys")&&(fe.add(e.id+":keys"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: arrangement "${s}" [${d.join(", ")}] does not match the children's keys \u2014 rendering declaration order (fail-safe).`));let G=m?d.map(a=>h.get(a)):l;(0,P.useEffect)(()=>oe({id:e.id,arms:Object.keys(e.arrangements)}),[e.id]);let b=(0,P.useRef)(null);(0,P.useEffect)(()=>{!t||c==="baseline"||c==="override"||b.current===s||(b.current=s,N(t,n,e.id,s))},[t,n,e.id,s,c]);let f=e.goal===void 0?null:typeof e.goal=="string"?e.goal:JSON.stringify(e.goal);return(0,P.useEffect)(()=>{if(!t||e.goal===void 0||c==="override")return;let a=o.current;if(!a)return;let g=z(e.goal),S=B(e.goal),x=!1;return K(a,F(e.goal),{fireGoal:()=>{x||(x=!0,S!==void 0?t.componentGoal(e.id,g,{value:S}):t.componentGoal(e.id,g),t.goal(g,A({metadata:{componentId:e.id,arm:s},weight:1,stepIndex:0},S!==void 0?{value:S}:{})))},fireStep:(k,R,v)=>{t.componentGoal(e.id,k,{reward:R}),t.goal(k,{metadata:{componentId:e.id,arm:s},weight:R,stepIndex:v})}})},[t,e.id,f,s,c]),(0,vt.jsx)("div",{ref:o,"data-sentient-id":e.id,"data-sentient-variant":s,children:G})}var Se=require("@sentientui/core");var Wt=["page","blocks","layoutOrder"],yt=new Map;function St(e,t){yt.set(e,t)}function he(e){return yt.get(e)}function ht(e){var r,i;let t=(i=(r=e.content)!=null?r:he(e.page))!=null?i:{},n={};for(let[u,s]of Object.entries(t))Wt.includes(u)||(n[u]=s);let o=ne(A({},n),{page:e.page,blocks:e.blocks});return e.layoutOrder&&(o.layoutOrder=e.layoutOrder),o}function bt(e){return`<script type="application/ld+json">${be(e)}</script>`}function be(e){return JSON.stringify(A({"@context":"https://schema.org","@type":"WebPage"},e)).replace(/</g,"\\u003c")}function wt(e){let t=[];e.title&&t.push(`# ${e.title}`,""),e.summary&&t.push(String(e.summary),"");for(let[n,o]of Object.entries(e))["page","title","summary","blocks","layoutOrder"].includes(n)||t.push(`## ${n}`,"","```json",JSON.stringify(o,null,2),"```","");if(e.blocks.length>0){t.push("## blocks","");for(let n of e.blocks)t.push(`- **${n.id}** \u2192 variant \`${n.variant}\``),n.content!==void 0&&t.push(""," ```json",JSON.stringify(n.content,null,2)," ```");t.push("")}return t.join(`
3
3
  `).trimEnd()+`
4
- `}var yt=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,useSentient});
4
+ `}var xt=require("@sentientui/core");0&&(module.exports={Adaptive,AdaptiveGroup,AdaptiveProvider,AdaptiveText,SentientPersonaScript,buildAgentFeed,defineAgentContent,detectSegment,getAgentContent,grantConsent,renderAgentJsonLd,renderAgentJsonLdBody,renderAgentMarkdown,useAdaptive,useAdaptiveApiBaseUrl,useAdaptiveGoal,useAdaptivePersona,useAdaptiveTokens,useAssignment,useInitialAssignments,useLayoutOrder,usePageGoal,useSentient});
5
5
  //# sourceMappingURL=index.js.map