@sentientui/react 0.19.0 → 0.20.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 +25 -1
- package/dist/devtools.js +1 -1
- package/dist/devtools.js.map +1 -1
- package/dist/devtools.mjs +1 -1
- package/dist/devtools.mjs.map +1 -1
- package/dist/index.d.cts +67 -2
- package/dist/index.d.ts +67 -2
- 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/next/adaptive-root.d.ts +10 -0
- package/dist/next/adaptive-root.js +2 -2
- package/dist/next/adaptive-root.js.map +1 -1
- package/dist/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 +1 -1
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`
|
|
@@ -318,7 +328,20 @@ type AssignmentState = {
|
|
|
318
328
|
*/
|
|
319
329
|
declare function useAssignment(componentId: string, variantIds: string[], agentData?: unknown, agentDataByVariant?: Record<string, unknown>): AssignmentState;
|
|
320
330
|
|
|
321
|
-
|
|
331
|
+
interface FireGoalOptions extends ComponentGoalOptions {
|
|
332
|
+
/**
|
|
333
|
+
* Record this goal at most once per mounted component, however many times the
|
|
334
|
+
* callback is invoked. Use it for conversions that are a state, not an action
|
|
335
|
+
* — "reached step 3", "form validated", an effect that may re-run — where a
|
|
336
|
+
* second record is double counting rather than a second conversion.
|
|
337
|
+
*
|
|
338
|
+
* Leave it off for genuine repeat actions (each click of "add to cart" is its
|
|
339
|
+
* own conversion). The latch is per goal type and lives for the lifetime of
|
|
340
|
+
* the component holding the callback, so a remount can record again.
|
|
341
|
+
*/
|
|
342
|
+
once?: boolean;
|
|
343
|
+
}
|
|
344
|
+
type FireGoal = (goalType: string, opts?: FireGoalOptions) => void;
|
|
322
345
|
/**
|
|
323
346
|
* Returns a `fireGoal(goalType, opts?)` callback that records a conversion
|
|
324
347
|
* attributed to the variant currently served for `componentId` — so it shows
|
|
@@ -340,6 +363,48 @@ type FireGoal = (goalType: string, opts?: ComponentGoalOptions) => void;
|
|
|
340
363
|
*/
|
|
341
364
|
declare function useAdaptiveGoal(componentId: string): FireGoal;
|
|
342
365
|
|
|
366
|
+
interface PageGoalOptions extends ComponentGoalOptions {
|
|
367
|
+
/**
|
|
368
|
+
* Credit the arrival to the variant currently served for this component —
|
|
369
|
+
* typically the CTA on the page the visitor came FROM. The served variant is
|
|
370
|
+
* read from the assignment cache, which is localStorage-backed, so the credit
|
|
371
|
+
* survives the navigation. Omit for a session-level goal with no per-variant
|
|
372
|
+
* attribution.
|
|
373
|
+
*/
|
|
374
|
+
componentId?: string;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Records `goalName` once, when a page or route is reached.
|
|
378
|
+
*
|
|
379
|
+
* Use this for funnel steps that are a *destination* rather than a click:
|
|
380
|
+
* reaching /pricing, landing on a signup form, opening a checkout. Arrival is
|
|
381
|
+
* the better signal — it survives the navigation that a click goal can lose,
|
|
382
|
+
* and it also counts visitors who arrived from the nav, a search result or a
|
|
383
|
+
* shared link, none of whom clicked the CTA being measured.
|
|
384
|
+
*
|
|
385
|
+
* Two things this handles that hand-rolling `useAdaptiveGoal` in an effect does
|
|
386
|
+
* not, both of which fail silently:
|
|
387
|
+
*
|
|
388
|
+
* - **Fires once.** `useAdaptiveGoal` has no latch, so a remount — or React's
|
|
389
|
+
* double-invoked effects in development — records the same arrival twice and
|
|
390
|
+
* inflates the funnel.
|
|
391
|
+
* - **Waits for consent.** Under a consent gate the client does not exist when
|
|
392
|
+
* the page mounts, and a visitor who accepts a moment later would lose the
|
|
393
|
+
* goal entirely. The arrival is held until the SDK is running, then sent.
|
|
394
|
+
*
|
|
395
|
+
* Safe during SSR (effects do not run on the server) and a no-op without a
|
|
396
|
+
* provider above it.
|
|
397
|
+
*
|
|
398
|
+
* @example
|
|
399
|
+
* // Credit reaching the pricing page to whichever hero CTA sent them.
|
|
400
|
+
* usePageGoal('pricing_view', { componentId: 'hero_cta' });
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* // Session-level only — no component to attribute it to.
|
|
404
|
+
* usePageGoal('docs_view');
|
|
405
|
+
*/
|
|
406
|
+
declare function usePageGoal(goalName: string, opts?: PageGoalOptions): void;
|
|
407
|
+
|
|
343
408
|
type SentientPersonaScriptProps = {
|
|
344
409
|
/** Publishable API key — selects the localStorage snapshot in the fallback path. */
|
|
345
410
|
apiKey: string;
|
|
@@ -548,4 +613,4 @@ declare function renderAgentJsonLdBody(feed: AgentFeed): string;
|
|
|
548
613
|
/** Render the feed as Markdown for agents that negotiate `text/markdown`. */
|
|
549
614
|
declare function renderAgentMarkdown(feed: AgentFeed): string;
|
|
550
615
|
|
|
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 };
|
|
616
|
+
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`
|
|
@@ -318,7 +328,20 @@ type AssignmentState = {
|
|
|
318
328
|
*/
|
|
319
329
|
declare function useAssignment(componentId: string, variantIds: string[], agentData?: unknown, agentDataByVariant?: Record<string, unknown>): AssignmentState;
|
|
320
330
|
|
|
321
|
-
|
|
331
|
+
interface FireGoalOptions extends ComponentGoalOptions {
|
|
332
|
+
/**
|
|
333
|
+
* Record this goal at most once per mounted component, however many times the
|
|
334
|
+
* callback is invoked. Use it for conversions that are a state, not an action
|
|
335
|
+
* — "reached step 3", "form validated", an effect that may re-run — where a
|
|
336
|
+
* second record is double counting rather than a second conversion.
|
|
337
|
+
*
|
|
338
|
+
* Leave it off for genuine repeat actions (each click of "add to cart" is its
|
|
339
|
+
* own conversion). The latch is per goal type and lives for the lifetime of
|
|
340
|
+
* the component holding the callback, so a remount can record again.
|
|
341
|
+
*/
|
|
342
|
+
once?: boolean;
|
|
343
|
+
}
|
|
344
|
+
type FireGoal = (goalType: string, opts?: FireGoalOptions) => void;
|
|
322
345
|
/**
|
|
323
346
|
* Returns a `fireGoal(goalType, opts?)` callback that records a conversion
|
|
324
347
|
* attributed to the variant currently served for `componentId` — so it shows
|
|
@@ -340,6 +363,48 @@ type FireGoal = (goalType: string, opts?: ComponentGoalOptions) => void;
|
|
|
340
363
|
*/
|
|
341
364
|
declare function useAdaptiveGoal(componentId: string): FireGoal;
|
|
342
365
|
|
|
366
|
+
interface PageGoalOptions extends ComponentGoalOptions {
|
|
367
|
+
/**
|
|
368
|
+
* Credit the arrival to the variant currently served for this component —
|
|
369
|
+
* typically the CTA on the page the visitor came FROM. The served variant is
|
|
370
|
+
* read from the assignment cache, which is localStorage-backed, so the credit
|
|
371
|
+
* survives the navigation. Omit for a session-level goal with no per-variant
|
|
372
|
+
* attribution.
|
|
373
|
+
*/
|
|
374
|
+
componentId?: string;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Records `goalName` once, when a page or route is reached.
|
|
378
|
+
*
|
|
379
|
+
* Use this for funnel steps that are a *destination* rather than a click:
|
|
380
|
+
* reaching /pricing, landing on a signup form, opening a checkout. Arrival is
|
|
381
|
+
* the better signal — it survives the navigation that a click goal can lose,
|
|
382
|
+
* and it also counts visitors who arrived from the nav, a search result or a
|
|
383
|
+
* shared link, none of whom clicked the CTA being measured.
|
|
384
|
+
*
|
|
385
|
+
* Two things this handles that hand-rolling `useAdaptiveGoal` in an effect does
|
|
386
|
+
* not, both of which fail silently:
|
|
387
|
+
*
|
|
388
|
+
* - **Fires once.** `useAdaptiveGoal` has no latch, so a remount — or React's
|
|
389
|
+
* double-invoked effects in development — records the same arrival twice and
|
|
390
|
+
* inflates the funnel.
|
|
391
|
+
* - **Waits for consent.** Under a consent gate the client does not exist when
|
|
392
|
+
* the page mounts, and a visitor who accepts a moment later would lose the
|
|
393
|
+
* goal entirely. The arrival is held until the SDK is running, then sent.
|
|
394
|
+
*
|
|
395
|
+
* Safe during SSR (effects do not run on the server) and a no-op without a
|
|
396
|
+
* provider above it.
|
|
397
|
+
*
|
|
398
|
+
* @example
|
|
399
|
+
* // Credit reaching the pricing page to whichever hero CTA sent them.
|
|
400
|
+
* usePageGoal('pricing_view', { componentId: 'hero_cta' });
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* // Session-level only — no component to attribute it to.
|
|
404
|
+
* usePageGoal('docs_view');
|
|
405
|
+
*/
|
|
406
|
+
declare function usePageGoal(goalName: string, opts?: PageGoalOptions): void;
|
|
407
|
+
|
|
343
408
|
type SentientPersonaScriptProps = {
|
|
344
409
|
/** Publishable API key — selects the localStorage snapshot in the fallback path. */
|
|
345
410
|
apiKey: string;
|
|
@@ -548,4 +613,4 @@ declare function renderAgentJsonLdBody(feed: AgentFeed): string;
|
|
|
548
613
|
/** Render the feed as Markdown for agents that negotiate `text/markdown`. */
|
|
549
614
|
declare function renderAgentMarkdown(feed: AgentFeed): string;
|
|
550
615
|
|
|
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 };
|
|
616
|
+
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 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(`
|
|
3
3
|
`).trimEnd()+`
|
|
4
|
-
`}var
|
|
4
|
+
`}var wt=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
|