@sentientui/react 0.17.3 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +47 -7
- package/dist/index.d.ts +47 -7
- 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.js +2 -2
- package/dist/next/adaptive-root.js.map +1 -1
- package/dist/testing/node.js.map +1 -1
- package/dist/testing/node.mjs.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +1 -1
- package/dist/testing.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -194,9 +194,19 @@ type AdaptiveProps = {
|
|
|
194
194
|
* so agents see only the content currently being served to visitors.
|
|
195
195
|
*
|
|
196
196
|
* Prefer this over `agentData` when variants have meaningfully different content.
|
|
197
|
+
*
|
|
198
|
+
* Captured at MOUNT: this value is read once, when the component's assignment
|
|
199
|
+
* is requested, and is intentionally not part of the assign effect's deps.
|
|
200
|
+
* Changing it after mount does not re-send it — pass the final value on first
|
|
201
|
+
* render (e.g. from SSR/loader data, not a value that streams in later).
|
|
197
202
|
*/
|
|
198
203
|
agentDataByVariant?: Record<string, unknown>;
|
|
199
|
-
/**
|
|
204
|
+
/**
|
|
205
|
+
* @deprecated Use agentDataByVariant for variant-specific content. Stored as-is for the assigned variant.
|
|
206
|
+
*
|
|
207
|
+
* Captured at MOUNT (see `agentDataByVariant`): changing it after mount has no
|
|
208
|
+
* effect on what is sent for the assignment.
|
|
209
|
+
*/
|
|
200
210
|
agentData?: unknown;
|
|
201
211
|
};
|
|
202
212
|
declare function AdaptiveImpl(props: AdaptiveProps): JSX.Element | null;
|
|
@@ -234,11 +244,6 @@ type AdaptiveTextProps = {
|
|
|
234
244
|
*/
|
|
235
245
|
declare function AdaptiveText({ id, default: defaultText, component: Tag, className, goal: goalProp, }: AdaptiveTextProps): react_jsx_runtime.JSX.Element;
|
|
236
246
|
|
|
237
|
-
declare global {
|
|
238
|
-
interface Window {
|
|
239
|
-
__sentient_overrides?: Record<string, string>;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
247
|
type AssignmentState = {
|
|
243
248
|
variantId: string | null;
|
|
244
249
|
/** Populated when the assigned variant is a dashboard-managed text variant. */
|
|
@@ -288,6 +293,11 @@ type FireGoal = (goalType: string, opts?: ComponentGoalOptions) => void;
|
|
|
288
293
|
* firing. Use this for imperative handlers (click, form submit, custom events);
|
|
289
294
|
* for purely declarative goals prefer `<Adaptive goal={...}>`.
|
|
290
295
|
*
|
|
296
|
+
* Each call records one bandit reward event AND one session goal-funnel record.
|
|
297
|
+
* It has no cross-call latch, so a component that *also* declares a matching
|
|
298
|
+
* `<Adaptive goal>` (or fires this on every click) records one conversion per
|
|
299
|
+
* call — keep goal labels unique per conversion so counts aren't inflated.
|
|
300
|
+
*
|
|
291
301
|
* @example
|
|
292
302
|
* const fireContact = useAdaptiveGoal('hero_headline');
|
|
293
303
|
* <button onClick={() => fireContact('hero_contact', { metadata: { method } })}>Call</button>
|
|
@@ -376,6 +386,36 @@ declare function useAdaptive<T>(id: string, config: {
|
|
|
376
386
|
goal: string | GoalConfig;
|
|
377
387
|
}): UseAdaptiveResult<T>;
|
|
378
388
|
|
|
389
|
+
declare global {
|
|
390
|
+
interface Window {
|
|
391
|
+
/** Test/devtools forcing: slot id → forced result (applyScenario sets this). */
|
|
392
|
+
__sentient_slot_overrides?: Record<string, SlotResult>;
|
|
393
|
+
/** Test/devtools forcing: forced persona (applyScenario sets this). */
|
|
394
|
+
__sentient_persona_override?: {
|
|
395
|
+
persona: string;
|
|
396
|
+
confidence?: number;
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
type AdaptivePersona = {
|
|
401
|
+
persona: string;
|
|
402
|
+
confidence: number;
|
|
403
|
+
band: 'low' | 'medium' | 'high';
|
|
404
|
+
};
|
|
405
|
+
/**
|
|
406
|
+
* The current persona estimate for React consumers, resolved in priority
|
|
407
|
+
* order: a forced override (devtools / `applyScenario` / `?sentient_persona=`)
|
|
408
|
+
* → the SSR-provided `initialPersona` → the live client estimate (adopted
|
|
409
|
+
* attributes / snapshot / decide). Returns `null` when nothing is known yet.
|
|
410
|
+
*
|
|
411
|
+
* Hydration-safe: the first render (server + pre-hydration client) uses ONLY
|
|
412
|
+
* the SSR-provided persona so server and client agree; the override channel and
|
|
413
|
+
* the live client estimate — neither visible to the server — are read after
|
|
414
|
+
* mount. Re-renders when a persona/variant override is written, so devtools or
|
|
415
|
+
* a test forcing a persona mid-session takes effect immediately.
|
|
416
|
+
*/
|
|
417
|
+
declare function useAdaptivePersona(): AdaptivePersona | null;
|
|
418
|
+
|
|
379
419
|
type AdaptiveGroupProps = {
|
|
380
420
|
id: string;
|
|
381
421
|
/** Arrangement id → ordered child keys. FIRST key = baseline default. */
|
|
@@ -466,4 +506,4 @@ declare function renderAgentJsonLdBody(feed: AgentFeed): string;
|
|
|
466
506
|
/** Render the feed as Markdown for agents that negotiate `text/markdown`. */
|
|
467
507
|
declare function renderAgentMarkdown(feed: AgentFeed): string;
|
|
468
508
|
|
|
469
|
-
export { Adaptive, AdaptiveGroup, type AdaptiveGroupProps, 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, useAdaptiveTokens, useAssignment, useInitialAssignments, useLayoutOrder, useSentient };
|
|
509
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
"use strict";var ft=Object.create;var H=Object.defineProperty,gt=Object.defineProperties,pt=Object.getOwnPropertyDescriptor,mt=Object.getOwnPropertyDescriptors,vt=Object.getOwnPropertyNames,ge=Object.getOwnPropertySymbols,yt=Object.getPrototypeOf,me=Object.prototype.hasOwnProperty,St=Object.prototype.propertyIsEnumerable;var pe=(e,t,n)=>t in e?H(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,T=(e,t)=>{for(var n in t||(t={}))me.call(t,n)&&pe(e,n,t[n]);if(ge)for(var n of ge(t))St.call(t,n)&&pe(e,n,t[n]);return e},z=(e,t)=>gt(e,mt(t));var ht=(e,t)=>{for(var n in t)H(e,n,{get:t[n],enumerable:!0})},ve=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of vt(t))!me.call(e,i)&&i!==n&&H(e,i,{get:()=>t[i],enumerable:!(o=pt(t,i))||o.enumerable});return e};var ye=(e,t,n)=>(n=e!=null?ft(yt(e)):{},ve(t||!e||!e.__esModule?H(n,"default",{value:e,enumerable:!0}):n,e)),bt=e=>ve(H({},"__esModule",{value:!0}),e);var It={};ht(It,{Adaptive:()=>We,AdaptiveGroup:()=>nt,AdaptiveProvider:()=>Ee,AdaptiveText:()=>je,SentientPersonaScript:()=>ze,buildAgentFeed:()=>st,defineAgentContent:()=>ot,detectSegment:()=>ae.deriveSessionSegment,getAgentContent:()=>le,renderAgentJsonLd:()=>at,renderAgentJsonLdBody:()=>ue,renderAgentMarkdown:()=>lt,useAdaptive:()=>tt,useAdaptiveApiBaseUrl:()=>Pe,useAdaptiveGoal:()=>$e,useAdaptiveTokens:()=>Ye,useAssignment:()=>V,useInitialAssignments:()=>ee,useLayoutOrder:()=>Ie,useSentient:()=>R});module.exports=bt(It);var A=require("react"),$=require("@sentientui/core");var Se=new Map,q=new Map;function he(e,t){let n=q.get(e);return n||(n=new Set,q.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&q.delete(e)}}function be(e,t){Se.set(e,t);let n=q.get(e);if(n)for(let o of n)try{o(t)}catch(i){}}function we(e){var t;return(t=Se.get(e))!=null?t:null}var wt={on:!1,listeners:new Set};function Ae(){if(typeof window=="undefined")return wt;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function oe(){return Ae().on}function xe(e){let t=Ae().listeners;return t.add(e),()=>{t.delete(e)}}function ke(e){return{isLocal:e.isLocal,track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},fetchWeights:()=>Promise.resolve([]),getAssignment:(t,n)=>e.getAssignment(t,n),assign:(t,n,o,i)=>e.assign(t,n,o,i),decide:()=>Promise.resolve(null),getSlotResult:t=>e.getSlotResult(t),getPersona:()=>e.getPersona(),getGraph:()=>e.getGraph(),dispose:()=>e.dispose(),destroy:()=>e.destroy()}}var Ce="sentient:overrides-changed";function Q(){var e;return typeof window=="undefined"?0:(e=window.__sentient_overrides_version)!=null?e:0}function U(e){return typeof window=="undefined"?()=>{}:(window.addEventListener(Ce,e),()=>window.removeEventListener(Ce,e))}function _e(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}var At={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function K(){if(typeof window=="undefined")return At;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 X(){K().version+=1;for(let e of K().listeners)e()}function Y(e){return K().components.set(e.id,e),X(),()=>{K().components.delete(e.id),X()}}function Z(e){return K().slots.set(e.id,e),X(),()=>{K().slots.delete(e.id),X()}}function Re(e){K().sections=[...e],X()}var De=require("react/jsx-runtime");function xt(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{let n=(0,$.detectDeviceClass)((e=navigator.userAgent)!=null?e:""),o=(0,$.detectTrafficSource)((t=document.referrer)!=null?t:"",window.location.origin);return`${n}:${o}`}catch(n){return"desktop:direct"}}var Ge="https://api.sentient-ui.com/v1",P=(0,A.createContext)({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialPersona:null,apiBaseUrl:Ge,debug:!1});function Ee(e){var m,h;let[t,n]=(0,A.useState)(null),[o]=(0,A.useState)(()=>{var S;return(S=e.sessionSegment)!=null?S:xt()}),[i,a]=(0,A.useState)(oe());(0,A.useEffect)(()=>xe(()=>a(oe())),[]),(0,A.useEffect)(()=>{if(e.consent===!1&&!e.preConsentBehavior){n(b=>(b==null||b.destroy(),null));return}let S={apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,sessionSegment:o,consent:e.consent,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},g=!1,u=null,p=null,c=b=>{e.engagement!==!1&&import("@sentientui/core/engagement").then(({startEngagementCapture:x})=>{g||(p=x(b,{apiKey:e.apiKey,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:b})=>{g||(u=b(z(T({},S),{graph:!0})),n(u),c(u))}):(u=(0,$.init)(S),n(u),c(u)),()=>{g=!0,p==null||p(),u==null||u.dispose()}},[e.consent]),(0,A.useEffect)(()=>{if(!t)return;let S=!1,g=async()=>{if(S)return;let p;try{p=await t.fetchWeights()}catch(c){return}if(!S)for(let c of p){let b={componentId:c.componentId,updatedAt:c.updatedAt,variants:c.variants.map(x=>{var I;return{variantId:x.variantId,pulls:x.pulls,avgReward:(I=x.avgReward)!=null?I:0}})};be(c.componentId,b)}};g();let u=setInterval(()=>{g()},6e4);return()=>{S=!0,clearInterval(u)}},[t]);let r=(m=e.ssrFallback)!=null?m:"first",s=(h=e.apiBaseUrl)!=null?h:Ge;(0,A.useEffect)(()=>{var S;typeof process!="undefined"&&((S=process.env)==null?void 0:S.NODE_ENV)==="production"||_e({apiKey:e.apiKey,apiBaseUrl:s,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,s]),(0,A.useEffect)(()=>{e.initialLayoutOrder&&e.initialLayoutOrder.length>0&&Re(e.initialLayoutOrder)},[e.initialLayoutOrder]);let l=(0,A.useMemo)(()=>t&&i?ke(t):t,[t,i]),y=(0,A.useMemo)(()=>{var S,g,u,p,c;return{client:l,apiKey:e.apiKey,initialAssignments:(S=e.initialAssignments)!=null?S:{},sessionSegment:o,ssrFallback:r,onAssignment:e.onAssignment,initialLayoutOrder:(g=e.initialLayoutOrder)!=null?g:null,initialSlots:(u=e.initialSlots)!=null?u:{},initialPersona:(p=e.initialPersona)!=null?p:null,apiBaseUrl:s,debug:(c=e.debug)!=null?c:!1}},[l,e.apiKey,e.initialAssignments,o,r,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialPersona,s,e.debug]);return(0,De.jsx)(P.Provider,{value:y,children:e.children})}function R(){return(0,A.useContext)(P).client}function D(){return(0,A.useContext)(P).apiKey}function ee(){return(0,A.useContext)(P).initialAssignments}function te(){return(0,A.useContext)(P).sessionSegment}function Le(){return(0,A.useContext)(P).ssrFallback}function ne(){return(0,A.useContext)(P).onAssignment}function Oe(){return(0,A.useContext)(P).debug}function Ie(){let e=(0,A.useContext)(P).initialLayoutOrder,t=(0,A.useSyncExternalStore)(U,()=>{var n;return typeof window=="undefined"?null:(n=window.__sentient_layout_override)!=null?n:null},()=>null);return t!=null?t:e}function Te(){return(0,A.useContext)(P).initialSlots}function Pe(){return(0,A.useContext)(P).apiBaseUrl}var C=require("react"),Fe=require("@sentientui/core");var E=require("react");function kt(e){var n;if(typeof window=="undefined")return null;let t=(n=window.__sentient_overrides)==null?void 0:n[e];if(t)return t;try{let o=new URLSearchParams(window.location.search);for(let i of o.getAll("sentient_variant")){let a=i.indexOf(":");if(a!==-1&&i.slice(0,a)===e)return i.slice(a+1)}}catch(o){}return null}var Ct=5;function Me(e,t){var o,i;let n=null;for(let a of e.variants){if(!t.includes(a.variantId))continue;let r=(o=a.pulls)!=null?o:0,s=r>0?r*a.avgReward/(r+Ct):0;(!n||s>n.score)&&(n={variantId:a.variantId,score:s})}return(i=n==null?void 0:n.variantId)!=null?i:null}function V(e,t,n,o){let i=ee(),a=Le(),r=R(),s=te(),l=ne(),y=Oe(),m=(0,E.useRef)(null);(0,E.useSyncExternalStore)(U,Q,()=>0);let[h,S]=(0,E.useState)(!1);(0,E.useEffect)(()=>S(!0),[]);let g=h?kt(e):null,u=g&&t.includes(g)?g:null,p=(0,E.useRef)(null);(0,E.useEffect)(()=>{y&&u&&p.current!==u&&(p.current=u,console.info(`[sentient] override active: ${e} -> ${u}`))},[y,u,e]);let c=(()=>{var f,w;if(u)return{variantId:u,content:null,isLoading:!1,settled:!0};if(!r){let k=i[e];return k&&t.includes(k)?{variantId:k,content:null,isLoading:!1,settled:!0}:a==="first"&&t.length>0?{variantId:t[0],content:null,isLoading:!1,settled:!1}:{variantId:null,content:null,isLoading:!0,settled:!1}}let d=r.getAssignment(e,s);if(d&&(t.includes(d.variantId)||d.content))return{variantId:d.variantId,content:(f=d.content)!=null?f:null,isLoading:!1,settled:!0};let v=we(e);if(v){let k=Me(v,t);if(k)return{variantId:k,content:null,isLoading:!1,settled:!0}}return{variantId:(w=t[0])!=null?w:null,content:null,isLoading:!1,settled:!1}})(),[b,x]=(0,E.useState)(c),I=d=>{l&&m.current!==d&&(m.current=d,l(e,d))};return(0,E.useEffect)(()=>{var v;if(u||!r)return;let d=r.getAssignment(e,s);if(d&&(t.includes(d.variantId)||d.content)){x({variantId:d.variantId,content:(v=d.content)!=null?v:null,isLoading:!1,settled:!0}),I(d.variantId);return}x(f=>{var w;return f.variantId?f:{variantId:(w=t[0])!=null?w:null,content:null,isLoading:!1,settled:!1}})},[u,r,e,s]),(0,E.useEffect)(()=>{if(u||!r)return;let d=r.getAssignment(e,s);if(d&&t.includes(d.variantId))return;let v=!1;return r.assign(e,t,n,o).then(f=>{var w;v||f&&(!t.includes(f.variantId)&&!f.content||(x({variantId:f.variantId,content:(w=f.content)!=null?w:null,isLoading:!1,settled:!0}),I(f.variantId)))}),()=>{v=!0}},[u,r,e,s]),(0,E.useEffect)(()=>{if(!u&&r)return he(e,d=>{var w;let v=r.getAssignment(e,s);if(v&&(t.includes(v.variantId)||v.content)){x({variantId:v.variantId,content:(w=v.content)!=null?w:null,isLoading:!1,settled:!0});return}let f=Me(d,t);f&&x({variantId:f,content:null,isLoading:!1,settled:!0})})},[u,r,e,s]),u?{variantId:u,content:null,isLoading:!1,settled:!0,isOverride:!0}:b}function G(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}function M(e){return typeof e=="string"?{type:"click"}:e}function J(e){return typeof e=="string"?e:e.type}function _t(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 i=e;for(;i&&i!==t;){if(i.matches(n))return!0;i=i.parentElement}}catch(i){}return!1}let o=e;for(;o&&o!==t;){if(_t(o))return!0;o=o.parentElement}return!1}function B(e,t,n){if(t.type==="weighted_composite"){let s=new Set,l=[];return t.steps.forEach(({goal:y,name:m,weight:h},S)=>{let g=()=>{s.has(S)||(s.add(S),n.fireStep(m,h,S))};if(y.type==="click"){let u=p=>{let c=p.target;c instanceof Element&&Be(c,e,y.selector)&&g()};e.addEventListener("click",u),l.push(()=>e.removeEventListener("click",u));return}if(y.type==="form_submit"){let u=p=>{p.target instanceof HTMLFormElement&&e.contains(p.target)&&g()};e.addEventListener("submit",u),l.push(()=>e.removeEventListener("submit",u));return}if(y.type==="scroll_depth"){let u=Math.max(0,Math.min(1,y.threshold)),p=new IntersectionObserver(c=>{for(let b of c)if(b.intersectionRatio>=u){g(),p.disconnect();break}},{threshold:[u]});p.observe(e),l.push(()=>p.disconnect())}}),()=>{for(let y of l)y()}}let o=t.type==="composite"?t.all:[t],i=new Set(o.map((s,l)=>l)),a=s=>{i.delete(s),i.size===0&&n.fireGoal()},r=[];return o.forEach((s,l)=>{if(s.type==="click"){let y=m=>{let h=m.target;h instanceof Element&&Be(h,e,s.selector)&&(t.type==="composite"?a(l):n.fireGoal())};e.addEventListener("click",y),r.push(()=>e.removeEventListener("click",y));return}if(s.type==="form_submit"){let y=m=>{m.target instanceof HTMLFormElement&&e.contains(m.target)&&(t.type==="composite"?a(l):n.fireGoal())};e.addEventListener("submit",y),r.push(()=>e.removeEventListener("submit",y));return}if(s.type==="scroll_depth"){let y=Math.max(0,Math.min(1,s.threshold)),m=new IntersectionObserver(h=>{for(let S of h)if(S.intersectionRatio>=y){t.type==="composite"?a(l):n.fireGoal(),m.disconnect();break}},{threshold:[y]});m.observe(e),r.push(()=>m.disconnect());return}}),()=>{for(let s of r)s()}}function W(e,t,n,o){e.track({projectId:t,componentId:n,variantId:o,eventType:"variant_assigned",payload:{}})}var Ke=require("react/jsx-runtime");function Rt(e){var I;let t=R(),n=D(),o=(0,C.useMemo)(()=>Object.keys(e.variants),[e.variants]),{variantId:i,content:a,isOverride:r,settled:s}=V(e.id,o,e.agentData,e.agentDataByVariant),l=(0,C.useRef)(null),[y,m]=(0,C.useState)(!1);(0,C.useEffect)(()=>{m(!0)},[]);let h=(0,C.useRef)(!1),S=(0,C.useRef)(new Set),g=(0,C.useRef)(null),u=typeof e.goal=="string"?e.goal:JSON.stringify(e.goal),p=(0,C.useMemo)(()=>M(e.goal),[u]),c=typeof e.goal=="string"?e.goal:p.type;if((0,C.useEffect)(()=>Y({id:e.id,variantIds:o,goal:c}),[e.id,o,c]),(0,C.useEffect)(()=>{r||s&&(!t||!i||!n||g.current!==i&&(g.current=i,W(t,n,e.id,i)))},[t,i,n,e.id,r,s]),(0,C.useEffect)(()=>{h.current=!1,S.current=new Set},[i,p]),(0,C.useEffect)(()=>{if(r||!t||!i)return;let d=l.current;if(!d)return;let v=null,f=0,w=()=>{f=Date.now(),v=setTimeout(()=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-f}}),v=null},800)},k=()=>{v!==null&&(clearTimeout(v),v=null)};return d.addEventListener("mouseenter",w),d.addEventListener("mouseleave",k),()=>{d.removeEventListener("mouseenter",w),d.removeEventListener("mouseleave",k),v!==null&&clearTimeout(v)}},[t,i,n,e.id,r]),(0,C.useEffect)(()=>{if(r||!t||!i)return;let d=l.current;if(!d)return;let v=Date.now();return(0,Fe.attachMicroSignalDetectors)((f,w={})=>{var ce,de,fe;t.track({projectId:n,componentId:e.id,variantId:i,eventType:"micro_signal",payload:T({signalType:f},w)});let k=(ce=e.microSignalGoals)==null?void 0:ce[f];if(!k||S.current.has(f))return;S.current.add(f);let ut=typeof k=="string"?k:k.name,ct=typeof k=="string"?1:(de=k.weight)!=null?de:1,dt=typeof k=="string"?0:(fe=k.stepIndex)!=null?fe:0;t.goal(ut,T({signalType:f},w),ct,dt)},d,v)},[t,i,n,e.id,e.microSignalGoals,r]),(0,C.useEffect)(()=>{if(r||!t||!i)return;let d=l.current;if(d)return B(d,p,{fireGoal:()=>{h.current||(h.current=!0,t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:c,payload:{reward:1}}),t.goal(c,{componentId:e.id,variantId:i},1,0))},fireStep:(v,f,w)=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:v,payload:{reward:f}}),t.goal(v,{},f,w)}})},[t,i,n,e.id,p,c,r]),e.clientOnly&&(!y||!t)||!i)return null;let b=(I=e.variants[i])!=null?I:null,x=b===null?a:null;return G()&&b===null&&x===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,Ke.jsx)("div",{ref:l,"data-sentient-id":e.id,"data-sentient-variant":i,children:b!=null?b:x})}var We=(0,C.memo)(Rt,(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(i=>i in t.variants&&Object.is(e.variants[i],t.variants[i]))});var L=require("react");var Ne=require("react/jsx-runtime");function je({id:e,default:t,component:n="span",className:o,goal:i}){let a=R(),r=D(),s=ne(),l=te(),y=(0,L.useRef)(null),m=(0,L.useRef)(null),[h,S]=(0,L.useState)(()=>{var d,v;return(v=(d=a==null?void 0:a.getAssignment(e,l))==null?void 0:d.content)!=null?v:null}),[g,u]=(0,L.useState)(()=>{var d,v;return(v=(d=a==null?void 0:a.getAssignment(e,l))==null?void 0:d.variantId)!=null?v:null});(0,L.useEffect)(()=>{var v;if(!a||((v=a.getAssignment(e,l))==null?void 0:v.content)!==void 0)return;let d=!1;return a.assign(e).then(f=>{if(!d){if(!f){G()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}u(f.variantId),f.content&&S(f.content)}}),()=>{d=!0}},[a,e,l]),(0,L.useEffect)(()=>{!a||!g||!r||y.current!==g&&(y.current=g,a.track({projectId:r,componentId:e,variantId:g,eventType:"variant_assigned",payload:{}}),s==null||s(e,g))},[a,g,r,e,s]);let p=i===void 0?"":typeof i=="string"?i:JSON.stringify(i),c=(0,L.useMemo)(()=>i===void 0?null:M(i),[p]),b=i===void 0?null:typeof i=="string"?i:c.type,x=(0,L.useRef)(!1);return(0,L.useEffect)(()=>{x.current=!1},[g,p]),(0,L.useEffect)(()=>{if(!a||!g||!r||!c||!b)return;let d=m.current;if(d)return B(d,c,{fireGoal:()=>{x.current||(x.current=!0,a.track({projectId:r,componentId:e,variantId:g,eventType:"goal_achieved",goalType:b,payload:{reward:1}}),a.goal(b,{componentId:e,variantId:g},1,0))},fireStep:(v,f,w)=>{a.track({projectId:r,componentId:e,variantId:g,eventType:"goal_achieved",goalType:v,payload:{reward:f}}),a.goal(v,{},f,w)}})},[a,g,r,e,c,b]),(0,Ne.jsx)(n,{ref:d=>{m.current=d},className:o,children:h!=null?h:t})}var Ue=require("react");function $e(e){let t=R();return(0,Ue.useCallback)((n,o)=>{t==null||t.componentGoal(e,n,o)},[t,e])}var Je=require("@sentientui/core"),He=require("@sentientui/policy"),Xe=require("react/jsx-runtime");function Ve(e){return JSON.stringify(e).replace(/</g,"\\u003c")}function Gt(e){return e.persona?'(function(){try{var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",'+Ve(e.persona.persona)+');d.setAttribute("data-sentient-confidence",'+Ve((0,He.confidenceBand)(e.persona.confidence))+");}catch(e){}})();":(0,Je.renderPrePaintScript)(e.apiKey)}function ze(e){return(0,Xe.jsx)("script",{"data-sentient-persona-script":"",dangerouslySetInnerHTML:{__html:Gt(e)}})}var F=require("react"),Qe=require("@sentientui/policy");var N=require("react"),j=require("@sentientui/core"),Et=require("@sentientui/policy");var qe=new Set;function ie(e,t){var m;(0,N.useSyncExternalStore)(U,Q,()=>0);let n=R(),o=Te(),[,i]=(0,N.useReducer)(h=>h+1,0),a=typeof window!="undefined"?(m=window.__sentient_slot_overrides)==null?void 0:m[e]:void 0,r=a===void 0?o[e]:void 0,s=a===void 0&&r===void 0&&n?n.getSlotResult(e):null,l=(n==null?void 0:n.isLocal)===!0&&a===void 0&&r===void 0&&s===null;(0,N.useEffect)(()=>{if(!l||!n)return;let h=!1;return n.decide({slots:[t]}).then(S=>{!h&&S&&i()}),()=>{h=!0}},[n,e,l]);let y=(()=>{if(a!==void 0)return{result:a,arm:(0,j.armOfResult)(a),source:"override"};if(r!==void 0)return{result:r,arm:(0,j.armOfResult)(r),source:"preloaded"};if(s!==null)return{result:s,arm:(0,j.armOfResult)(s),source:"client"};let h=(0,j.baselineResultFor)(t);return{result:h,arm:(0,j.armOfResult)(h),source:"baseline"}})();return(0,N.useEffect)(()=>{G()&&(!n||n.isLocal===!0||y.source==="baseline"&&(qe.has(e)||(qe.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,y.source,e]),y}var se=new Set;function Lt(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/"/g,'\\"')}function Ye(e,t,n){let o=R(),i=D(),a=(0,F.useMemo)(()=>({id:e,dims:t}),[e]),{result:r,arm:s,source:l}=ie(e,a),y=(0,F.useMemo)(()=>typeof r=="string"?{}:r,[s]);if(G()&&!se.has(e)){let g=(0,Qe.validateSlotDecl)({id:e,dims:Object.fromEntries(Object.entries(t).map(([p,c])=>[p,[...c]]))}),u=Object.values(t).reduce((p,c)=>p*c.length,1);g.ok?u>4&&(se.add(e),console.warn(`[sentient] useAdaptiveTokens("${e}") declares ${u} combinations \u2014 more than the recommended 4. Each extra combination needs more traffic to learn; consider fewer dims/values.`)):(se.add(e),console.warn(`[sentient] useAdaptiveTokens("${e}"): invalid declaration \u2014 ${g.reason}. Serving baseline.`))}let m=(n==null?void 0:n.goal)===void 0?null:typeof n.goal=="string"?n.goal:JSON.stringify(n.goal);(0,F.useEffect)(()=>Z({id:e,dims:t}),[e]);let h=(0,F.useRef)(null);(0,F.useEffect)(()=>{!o||l==="baseline"||h.current===s||(h.current=s,W(o,i,e,s))},[o,i,e,s,l]),(0,F.useEffect)(()=>{if(!o||!(n!=null&&n.goal))return;let g=document.querySelector(`[data-sentient-slot="${Lt(e)}"]`);if(!g){G()&&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 u=J(n.goal),p=!1;return B(g,M(n.goal),{fireGoal:()=>{p||(p=!0,o.componentGoal(e,u))},fireStep:(c,b)=>{o.componentGoal(e,c,{reward:b})}})},[o,e,m,s]);let S=(0,F.useMemo)(()=>{let g={"data-sentient-slot":e};for(let[u,p]of Object.entries(y))g[`data-${u}`]=p;return g},[e,y]);return{tokens:y,props:S}}var _=require("react"),et=require("@sentientui/core");var Ze=new Set;function tt(e,t){var v;if(G()&&!t.goal)throw new Error(`[sentient] useAdaptive("${e}"): a goal is required \u2014 without one the optimizer accumulates exposures with no rewards and cannot learn. Pass e.g. goal: 'buy_click'.`);let n=R(),o=D(),i=(0,_.useMemo)(()=>Object.keys(t.variants),[e]),{variantId:a,isOverride:r,settled:s}=V(e,i),l=(v=a!=null?a:i[0])!=null?v:"",y=t.variants[l],[m,h]=(0,_.useState)(null),S=(0,_.useRef)(null),g=(0,_.useCallback)(f=>{S.current=f,h(f)},[]),u=typeof t.goal=="string"?t.goal:JSON.stringify(t.goal),p=(0,_.useMemo)(()=>M(t.goal),[u]),c=J(t.goal);(0,_.useEffect)(()=>Y({id:e,variantIds:i,goal:c}),[e,i,c]);let b=(0,_.useRef)(null);(0,_.useEffect)(()=>{r||s&&(!n||!l||!m||b.current!==l&&(b.current=l,W(n,o,e,l)))},[n,o,e,l,m,r,s]);let x=(0,_.useRef)(!1);(0,_.useEffect)(()=>{x.current=!1},[l,u]),(0,_.useEffect)(()=>{if(!r&&!(!n||!l||!m))return B(m,p,{fireGoal:()=>{x.current||(x.current=!0,n.track({projectId:o,componentId:e,variantId:l,eventType:"goal_achieved",goalType:c,payload:{reward:1}}),n.goal(c,{componentId:e,variantId:l},1,0))},fireStep:(f,w,k)=>{n.track({projectId:o,componentId:e,variantId:l,eventType:"goal_achieved",goalType:f,payload:{reward:w}}),n.goal(f,{},w,k)}})},[n,m,l,o,e,p,c,r]),(0,_.useEffect)(()=>{if(r||!n||!l||!m)return;let f=Date.now();return(0,et.attachMicroSignalDetectors)((w,k={})=>{n.track({projectId:o,componentId:e,variantId:l,eventType:"micro_signal",payload:T({signalType:w},k)})},m,f)},[n,m,l,o,e,r]),(0,_.useEffect)(()=>{if(!G()||!n)return;let f=setTimeout(()=>{!S.current&&!Ze.has(e)&&(Ze.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(f)},[n,e]);let I=(0,_.useCallback)((f,w)=>{r||n==null||n.componentGoal(e,f!=null?f:c,w)},[n,e,c,r]),d=(0,_.useMemo)(()=>({ref:g,"data-sentient-id":e,"data-sentient-variant":l}),[g,e,l]);return{variant:l,value:y,bind:d,fireGoal:I}}var O=require("react");var it=require("react/jsx-runtime"),re=new Set;function nt(e){var p;let t=R(),n=D(),o=(0,O.useRef)(null),i=(0,O.useMemo)(()=>Object.keys(e.arrangements),[e.id]),a=(0,O.useMemo)(()=>T({id:e.id,arms:i},e.baseline!==void 0?{baseline:e.baseline}:{}),[e.id,i,e.baseline]),{arm:r,source:s}=ie(e.id,a);G()&&e.baseline!==void 0&&e.baseline!==i[0]&&!re.has(e.id+":baseline")&&(re.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=O.Children.toArray(e.children).filter(O.isValidElement),y=new Map;for(let c of l)y.set(String((p=c.key)!=null?p:"").replace(/^\.\$/,""),c);let m=e.arrangements[r],h=m!==void 0&&m.length===l.length&&m.every(c=>y.has(c));G()&&m!==void 0&&!h&&!re.has(e.id+":keys")&&(re.add(e.id+":keys"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: arrangement "${r}" [${m.join(", ")}] does not match the children's keys \u2014 rendering declaration order (fail-safe).`));let S=h?m.map(c=>y.get(c)):l;(0,O.useEffect)(()=>Z({id:e.id,arms:Object.keys(e.arrangements)}),[e.id]);let g=(0,O.useRef)(null);(0,O.useEffect)(()=>{!t||s==="baseline"||g.current===r||(g.current=r,W(t,n,e.id,r))},[t,n,e.id,r,s]);let u=e.goal===void 0?null:typeof e.goal=="string"?e.goal:JSON.stringify(e.goal);return(0,O.useEffect)(()=>{if(!t||e.goal===void 0)return;let c=o.current;if(!c)return;let b=J(e.goal),x=!1;return B(c,M(e.goal),{fireGoal:()=>{x||(x=!0,t.componentGoal(e.id,b))},fireStep:(I,d)=>{t.componentGoal(e.id,I,{reward:d})}})},[t,e.id,u,r]),(0,it.jsx)("div",{ref:o,"data-sentient-id":e.id,"data-sentient-variant":r,children:S})}var ae=require("@sentientui/core");var Ot=["page","blocks","layoutOrder"],rt=new Map;function ot(e,t){rt.set(e,t)}function le(e){return rt.get(e)}function st(e){var i,a;let t=(a=(i=e.content)!=null?i:le(e.page))!=null?a:{},n={};for(let[r,s]of Object.entries(t))Ot.includes(r)||(n[r]=s);let o=z(T({},n),{page:e.page,blocks:e.blocks});return e.layoutOrder&&(o.layoutOrder=e.layoutOrder),o}function at(e){return`<script type="application/ld+json">${ue(e)}</script>`}function ue(e){return JSON.stringify(T({"@context":"https://schema.org","@type":"WebPage"},e)).replace(/</g,"\\u003c")}function lt(e){let t=[];e.title&&t.push(`# ${e.title}`,""),e.summary&&t.push(String(e.summary),"");for(let[n,o]of Object.entries(e))["page","title","summary","blocks","layoutOrder"].includes(n)||t.push(`## ${n}`,"","```json",JSON.stringify(o,null,2),"```","");if(e.blocks.length>0){t.push("## blocks","");for(let n of e.blocks)t.push(`- **${n.id}** \u2192 variant \`${n.variant}\``),n.content!==void 0&&t.push(""," ```json",JSON.stringify(n.content,null,2)," ```");t.push("")}return t.join(`
|
|
2
|
+
"use strict";var St=Object.create;var q=Object.defineProperty,ht=Object.defineProperties,bt=Object.getOwnPropertyDescriptor,wt=Object.getOwnPropertyDescriptors,At=Object.getOwnPropertyNames,ye=Object.getOwnPropertySymbols,xt=Object.getPrototypeOf,he=Object.prototype.hasOwnProperty,kt=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))kt.call(t,n)&&Se(e,n,t[n]);return e},Z=(e,t)=>ht(e,wt(t));var Ct=(e,t)=>{for(var n in t)q(e,n,{get:t[n],enumerable:!0})},be=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of At(t))!he.call(e,a)&&a!==n&&q(e,a,{get:()=>t[a],enumerable:!(o=bt(t,a))||o.enumerable});return e};var we=(e,t,n)=>(n=e!=null?St(xt(e)):{},be(t||!e||!e.__esModule?q(n,"default",{value:e,enumerable:!0}):n,e)),_t=e=>be(q({},"__esModule",{value:!0}),e);var Bt={};Ct(Bt,{Adaptive:()=>Ve,AdaptiveGroup:()=>ct,AdaptiveProvider:()=>De,AdaptiveText:()=>He,SentientPersonaScript:()=>et,buildAgentFeed:()=>pt,defineAgentContent:()=>gt,detectSegment:()=>de.deriveSessionSegment,getAgentContent:()=>fe,renderAgentJsonLd:()=>mt,renderAgentJsonLdBody:()=>ge,renderAgentMarkdown:()=>vt,useAdaptive:()=>ut,useAdaptiveApiBaseUrl:()=>We,useAdaptiveGoal:()=>qe,useAdaptivePersona:()=>it,useAdaptiveTokens:()=>st,useAssignment:()=>X,useInitialAssignments:()=>re,useLayoutOrder:()=>Ke,useSentient:()=>E});module.exports=_t(Bt);var A=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 o of n)try{o(t)}catch(a){}}function Ce(e){var t;return(t=Ae.get(e))!=null?t:null}var Rt={on:!1,listeners:new Set};function _e(){if(typeof window=="undefined")return Rt;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function le(){return _e().on}function Re(e){let t=_e().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,o,a)=>e.assign(t,n,o,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 ue(){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 Gt(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 o=e;for(;o&&o!==t;){if(Gt(o))return!0;o=o.parentElement}return!1}function K(e,t,n){if(t.type==="weighted_composite"){let i=new Set,d=[];return t.steps.forEach(({goal:l,name:b,weight:f},y)=>{let S=()=>{i.has(y)||(i.add(y),n.fireStep(b,f,y))};if(l.type==="click"){let c=g=>{let p=g.target;p instanceof Element&&Le(p,e,l.selector)&&S()};e.addEventListener("click",c),d.push(()=>e.removeEventListener("click",c));return}if(l.type==="form_submit"){let c=g=>{g.target instanceof HTMLFormElement&&e.contains(g.target)&&S()};e.addEventListener("submit",c),d.push(()=>e.removeEventListener("submit",c));return}if(l.type==="scroll_depth"){let c=Math.max(0,Math.min(1,l.threshold)),g=new IntersectionObserver(p=>{for(let s of p)if(s.intersectionRatio>=c){S(),g.disconnect();break}},{threshold:[c]});g.observe(e),d.push(()=>g.disconnect())}}),()=>{for(let l of d)l()}}let o=t.type==="composite"?t.all:[t],a=new Set(o.map((i,d)=>d)),r=i=>{a.delete(i),a.size===0&&n.fireGoal()},u=[];return o.forEach((i,d)=>{if(i.type==="click"){let l=b=>{let f=b.target;f instanceof Element&&Le(f,e,i.selector)&&(t.type==="composite"?r(d):n.fireGoal())};e.addEventListener("click",l),u.push(()=>e.removeEventListener("click",l));return}if(i.type==="form_submit"){let l=b=>{b.target instanceof HTMLFormElement&&e.contains(b.target)&&(t.type==="composite"?r(d):n.fireGoal())};e.addEventListener("submit",l),u.push(()=>e.removeEventListener("submit",l));return}if(i.type==="scroll_depth"){let l=Math.max(0,Math.min(1,i.threshold)),b=new IntersectionObserver(f=>{for(let y of f)if(y.intersectionRatio>=l){t.type==="composite"?r(d):n.fireGoal(),b.disconnect();break}},{threshold:[l]});b.observe(e),u.push(()=>b.disconnect());return}}),()=>{for(let i of u)i()}}function N(e,t,n,o){e.track({projectId:t,componentId:n,variantId:o,eventType:"variant_assigned",payload:{}})}var Ot={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function U(){if(typeof window=="undefined")return Ot;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(){U().version+=1;for(let e of U().listeners)e()}var Ie=()=>{};function te(e){return O()?(U().components.set(e.id,e),Q(),()=>{U().components.delete(e.id),Q()}):Ie}function ne(e){return O()?(U().slots.set(e.id,e),Q(),()=>{U().slots.delete(e.id),Q()}):Ie}function Pe(e){O()&&(U().sections=[...e],Q())}var Ne=require("react/jsx-runtime");function Et(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{let n=(0,H.detectDeviceClass)((e=navigator.userAgent)!=null?e:""),o=(0,H.detectTrafficSource)((t=document.referrer)!=null?t:"",window.location.origin);return`${n}:${o}`}catch(n){return"desktop:direct"}}var Te="https://api.sentient-ui.com/v1",T=(0,A.createContext)({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialPersona:null,apiBaseUrl:Te,debug:!1});function De(e){var f,y;let[t,n]=(0,A.useState)(null),[o]=(0,A.useState)(()=>{var S;return(S=e.sessionSegment)!=null?S:Et()}),[a,r]=(0,A.useState)(le());(0,A.useEffect)(()=>Re(()=>r(le())),[]),(0,A.useEffect)(()=>{if(e.consent===!1&&!e.preConsentBehavior){n(m=>(m==null||m.destroy(),null));return}let S={apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,sessionSegment:o,consent:e.consent,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},c=!1,g=null,p=null,s=m=>{e.engagement!==!1&&import("@sentientui/core/engagement").then(({startEngagementCapture:h})=>{c||(p=h(m,{apiKey:e.apiKey,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:m})=>{c||(g=m(Z(P({},S),{graph:!0})),n(g),s(g))}):(g=(0,H.init)(S),n(g),s(g)),()=>{c=!0,p==null||p(),g==null||g.dispose()}},[e.consent]),(0,A.useEffect)(()=>{if(!t)return;let S=!1,c=async()=>{if(S)return;let p;try{p=await t.fetchWeights()}catch(s){return}if(!S)for(let s of p){let m={componentId:s.componentId,updatedAt:s.updatedAt,variants:s.variants.map(h=>{var k;return{variantId:h.variantId,pulls:h.pulls,avgReward:(k=h.avgReward)!=null?k:0}})};ke(s.componentId,m)}};c();let g=setInterval(()=>{c()},6e4);return()=>{S=!0,clearInterval(g)}},[t]);let u=(f=e.ssrFallback)!=null?f:"first",i=((y=e.apiBaseUrl)!=null?y:Te).replace(/\/$/,""),d=(0,A.useRef)(null);(0,A.useEffect)(()=>{var g;if(typeof process!="undefined"&&((g=process.env)==null?void 0:g.NODE_ENV)==="production")return;let S={apiKey:e.apiKey,context:e.context,country:e.country,apiBaseUrl:i},c=d.current;if(d.current=S,c!==null)for(let p of["apiKey","context","country","apiBaseUrl"])Object.is(c[p],S[p])||console.warn(`[sentient] AdaptiveProvider: \`${p}\` 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,i]),(0,A.useEffect)(()=>{var S;typeof process!="undefined"&&((S=process.env)==null?void 0:S.NODE_ENV)==="production"||Ee({apiKey:e.apiKey,apiBaseUrl:i,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,i]),(0,A.useEffect)(()=>{e.initialLayoutOrder&&e.initialLayoutOrder.length>0&&Pe(e.initialLayoutOrder)},[e.initialLayoutOrder]);let l=(0,A.useMemo)(()=>t&&a?Ge(t):t,[t,a]),b=(0,A.useMemo)(()=>{var S,c,g,p,s;return{client:l,apiKey:e.apiKey,initialAssignments:(S=e.initialAssignments)!=null?S:{},sessionSegment:o,ssrFallback:u,onAssignment:e.onAssignment,initialLayoutOrder:(c=e.initialLayoutOrder)!=null?c:null,initialSlots:(g=e.initialSlots)!=null?g:{},initialPersona:(p=e.initialPersona)!=null?p:null,apiBaseUrl:i,debug:(s=e.debug)!=null?s:!1}},[l,e.apiKey,e.initialAssignments,o,u,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialPersona,i,e.debug]);return(0,Ne.jsx)(T.Provider,{value:b,children:e.children})}function E(){return(0,A.useContext)(T).client}function j(){return(0,A.useContext)(T).apiKey}function re(){return(0,A.useContext)(T).initialAssignments}function ie(){return(0,A.useContext)(T).sessionSegment}function Me(){return(0,A.useContext)(T).ssrFallback}function oe(){return(0,A.useContext)(T).onAssignment}function Be(){return(0,A.useContext)(T).debug}function Ke(){let e=(0,A.useContext)(T).initialLayoutOrder,t=(0,A.useSyncExternalStore)(W,()=>{var n;return typeof window=="undefined"?null:(n=window.__sentient_layout_override)!=null?n:null},()=>null);return t!=null?t:e}function je(){return(0,A.useContext)(T).initialSlots}function Fe(){return(0,A.useContext)(T).initialPersona}function We(){return(0,A.useContext)(T).apiBaseUrl}var R=require("react"),$e=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 o=new URLSearchParams(window.location.search);for(let a of o.getAll("sentient_variant")){let r=a.indexOf(":");if(r!==-1&&a.slice(0,r)===e)return a.slice(r+1)}}catch(o){}return null}var Lt=5;function Ue(e,t){var o,a;let n=null;for(let r of e.variants){if(!t.includes(r.variantId))continue;let u=(o=r.pulls)!=null?o:0,i=u>0?u*r.avgReward/(u+Lt):0;(!n||i>n.score)&&(n={variantId:r.variantId,score:i})}return(a=n==null?void 0:n.variantId)!=null?a:null}function X(e,t,n,o){let a=re(),r=Me(),u=E(),i=ie(),d=oe(),l=Be(),b=(0,D.useRef)(null),f=(0,D.useSyncExternalStore)(W,()=>z(e),()=>null),y=f&&t.includes(f)?f:null,S=(0,D.useRef)(null);(0,D.useEffect)(()=>{l&&y&&S.current!==y&&(S.current=y,console.info(`[sentient] override active: ${e} -> ${y}`))},[l,y,e]);let[c,g]=(0,D.useState)(()=>{var h,k;if(y)return{variantId:y,content:null,isLoading:!1,settled:!0};if(!u){let C=a[e];return C&&t.includes(C)?{variantId:C,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=u.getAssignment(e,i);if(s&&(t.includes(s.variantId)||s.content))return{variantId:s.variantId,content:(h=s.content)!=null?h:null,isLoading:!1,settled:!0};let m=Ce(e);if(m){let C=Ue(m,t);if(C)return{variantId:C,content:null,isLoading:!1,settled:!0}}return{variantId:(k=t[0])!=null?k:null,content:null,isLoading:!1,settled:!1}}),p=s=>{d&&b.current!==s&&(b.current=s,d(e,s))};return(0,D.useEffect)(()=>{var m;if(y||!u)return;let s=u.getAssignment(e,i);if(s&&(t.includes(s.variantId)||s.content)){g({variantId:s.variantId,content:(m=s.content)!=null?m:null,isLoading:!1,settled:!0}),p(s.variantId);return}g(h=>{var k;return h.variantId?h:{variantId:(k=t[0])!=null?k:null,content:null,isLoading:!1,settled:!1}})},[y,u,e,i]),(0,D.useEffect)(()=>{if(y||!u)return;let s=u.getAssignment(e,i);if(s&&t.includes(s.variantId))return;let m=!1;return u.assign(e,t,n,o).then(h=>{var k;m||h&&(!t.includes(h.variantId)&&!h.content||(g({variantId:h.variantId,content:(k=h.content)!=null?k:null,isLoading:!1,settled:!0}),p(h.variantId)))}),()=>{m=!0}},[y,u,e,i]),(0,D.useEffect)(()=>{if(!y&&u)return xe(e,s=>{var k;let m=u.getAssignment(e,i);if(m&&(t.includes(m.variantId)||m.content)){g({variantId:m.variantId,content:(k=m.content)!=null?k:null,isLoading:!1,settled:!0});return}let h=Ue(s,t);h&&g({variantId:h,content:null,isLoading:!1,settled:!0})})},[y,u,e,i]),y?{variantId:y,content:null,isLoading:!1,settled:!0,isOverride:!0}:c}var Je=require("react/jsx-runtime");function It(e){var k;let t=E(),n=j(),o=Object.keys(e.variants).join("\0"),a=(0,R.useMemo)(()=>Object.keys(e.variants),[o]),{variantId:r,content:u,isOverride:i,settled:d}=X(e.id,a,e.agentData,e.agentDataByVariant),l=(0,R.useRef)(null),[b,f]=(0,R.useState)(!1);(0,R.useEffect)(()=>{f(!0)},[]);let y=(0,R.useRef)(!1),S=(0,R.useRef)(new Set),c=(0,R.useRef)(null),g=typeof e.goal=="string"?e.goal:JSON.stringify(e.goal),p=(0,R.useMemo)(()=>B(e.goal),[g]),s=typeof e.goal=="string"?e.goal:p.type;if((0,R.useEffect)(()=>te({id:e.id,variantIds:a,goal:s}),[e.id,a,s]),(0,R.useEffect)(()=>{i||d&&(!t||!r||!n||c.current!==r&&(c.current=r,N(t,n,e.id,r)))},[t,r,n,e.id,i,d]),(0,R.useEffect)(()=>{y.current=!1,S.current=new Set},[r,p]),(0,R.useEffect)(()=>{if(i||!d||!t||!r)return;let C=l.current;if(!C)return;let _=null,v=0,w=()=>{v=Date.now(),_=setTimeout(()=>{t.track({projectId:n,componentId:e.id,variantId:r,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-v}}),_=null},800)},x=()=>{_!==null&&(clearTimeout(_),_=null)};return C.addEventListener("mouseenter",w),C.addEventListener("mouseleave",x),()=>{C.removeEventListener("mouseenter",w),C.removeEventListener("mouseleave",x),_!==null&&clearTimeout(_)}},[t,r,n,e.id,i,d]),(0,R.useEffect)(()=>{if(i||!d||!t||!r)return;let C=l.current;if(!C)return;let _=Date.now();return(0,$e.attachMicroSignalDetectors)((v,w={})=>{var pe,me,ve;t.track({projectId:n,componentId:e.id,variantId:r,eventType:"micro_signal",payload:P({signalType:v},w)});let x=(pe=e.microSignalGoals)==null?void 0:pe[v];if(!x||S.current.has(v))return;S.current.add(v);let V=typeof x=="string"?x:x.name,Y=typeof x=="string"?1:(me=x.weight)!=null?me:1,yt=typeof x=="string"?0:(ve=x.stepIndex)!=null?ve:0;t.goal(V,P({signalType:v},w),Y,yt)},C,_)},[t,r,n,e.id,e.microSignalGoals,i,d]),(0,R.useEffect)(()=>{if(i||!t||!r)return;let C=l.current;if(C)return K(C,p,{fireGoal:()=>{y.current||(y.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:(_,v,w)=>{t.track({projectId:n,componentId:e.id,variantId:r,eventType:"goal_achieved",goalType:_,payload:{reward:v}}),t.goal(_,{},v,w)}})},[t,r,n,e.id,p,s,i]),e.clientOnly&&(!b||!t)||!r)return null;let m=(k=e.variants[r])!=null?k:null,h=m===null?u:null;return O()&&m===null&&h===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:m!=null?m:h})}var Ve=(0,R.memo)(It,(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(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:o,goal:a}){var _;let r=E(),u=j(),i=oe(),d=ie(),l=(0,L.useRef)(null),b=(0,L.useRef)(null),f=(0,L.useSyncExternalStore)(W,()=>z(e),()=>null),[y,S]=(0,L.useState)(()=>{var v,w;return(w=(v=r==null?void 0:r.getAssignment(e,d))==null?void 0:v.content)!=null?w:null}),[c,g]=(0,L.useState)(()=>{var v,w;return(w=(v=r==null?void 0:r.getAssignment(e,d))==null?void 0:v.variantId)!=null?w:null});(0,L.useEffect)(()=>{var w;if(f||!r||((w=r.getAssignment(e,d))==null?void 0:w.content)!==void 0)return;let v=!1;return r.assign(e).then(x=>{if(!v){if(!x){O()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}g(x.variantId),x.content&&S(x.content)}}),()=>{v=!0}},[r,e,d,f]),(0,L.useEffect)(()=>{f||!r||!c||!u||l.current!==c&&(l.current=c,r.track({projectId:u,componentId:e,variantId:c,eventType:"variant_assigned",payload:{}}),i==null||i(e,c))},[r,c,u,e,i,f]);let p=a===void 0?"":typeof a=="string"?a:JSON.stringify(a),s=(0,L.useMemo)(()=>a===void 0?null:B(a),[p]),m=a===void 0?null:typeof a=="string"?a:s.type,h=(0,L.useRef)(!1);(0,L.useEffect)(()=>{h.current=!1},[c,p]),(0,L.useEffect)(()=>{if(f||!r||!c||!u||!s||!m)return;let v=b.current;if(v)return K(v,s,{fireGoal:()=>{h.current||(h.current=!0,r.track({projectId:u,componentId:e,variantId:c,eventType:"goal_achieved",goalType:m,payload:{reward:1}}),r.goal(m,{componentId:e,variantId:c},1,0))},fireStep:(w,x,V)=>{r.track({projectId:u,componentId:e,variantId:c,eventType:"goal_achieved",goalType:w,payload:{reward:x}}),r.goal(w,{},x,V)}})},[r,c,u,e,s,m,f]);let k=y!=null?y:t;if(f){let v=r==null?void 0:r.getAssignment(e,d);k=v&&v.variantId===f&&(_=v.content)!=null?_:t}return(0,ze.jsx)(n,{ref:v=>{b.current=v},className:o,children:k})}var Xe=require("react");function qe(e){let t=E();return(0,Xe.useCallback)((n,o)=>{var a,r;z(e)||(t==null||t.componentGoal(e,n,o),t==null||t.goal(n,(a=o==null?void 0:o.metadata)!=null?a:{},(r=o==null?void 0:o.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 Pt(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":"",dangerouslySetInnerHTML:{__html:Pt(e)}})}var F=require("react"),ot=require("@sentientui/policy");var M=require("react"),$=require("@sentientui/core"),rt=require("@sentientui/policy");var nt=new Set;function se(e,t){var b;(0,M.useSyncExternalStore)(W,ue,()=>0);let n=E(),o=je(),[,a]=(0,M.useReducer)(f=>f+1,0),r=typeof window!="undefined"?(b=window.__sentient_slot_overrides)==null?void 0:b[e]:void 0,u=r===void 0?o[e]:void 0,i=r===void 0&&u===void 0&&n?n.getSlotResult(e):null,d=(n==null?void 0:n.isLocal)===!0&&r===void 0&&u===void 0&&i===null;(0,M.useEffect)(()=>{if(!d||!n)return;let f=!1;return n.decide({slots:[t]}).then(y=>{!f&&y&&a()}),()=>{f=!0}},[n,e,d]);let l=(()=>{if(r!==void 0)return{result:r,arm:(0,$.armOfResult)(r),source:"override"};if(u!==void 0)return{result:u,arm:(0,$.armOfResult)(u),source:"preloaded"};if(i!==null)return{result:i,arm:(0,$.armOfResult)(i),source:"client"};let f=(0,$.baselineResultFor)(t);return{result:f,arm:(0,$.armOfResult)(f),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 Tt(){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=Fe();(0,M.useSyncExternalStore)(W,ue,()=>0);let[n,o]=(0,M.useState)(!1);(0,M.useEffect)(()=>o(!0),[]);let a=i=>({persona:i.persona,confidence:i.confidence,band:(0,rt.confidenceBand)(i.confidence)});if(!n)return t?a(t):null;let r=Tt();if(r)return a(r);if(t)return a(t);let u=e?e.getPersona():null;return u?a(u):null}var ce=new Set;function Dt(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/[\\"]/g,"\\$&")}function st(e,t,n){let o=E(),a=j(),r=JSON.stringify(t),u=(0,F.useMemo)(()=>({id:e,dims:t}),[e,r]),{result:i,arm:d,source:l}=se(e,u),b=(0,F.useMemo)(()=>typeof i=="string"?{}:i,[d]);if(O()&&!ce.has(e)){let c=(0,ot.validateSlotDecl)({id:e,dims:Object.fromEntries(Object.entries(t).map(([p,s])=>[p,[...s]]))}),g=Object.values(t).reduce((p,s)=>p*s.length,1);c.ok?g>4&&(ce.add(e),console.warn(`[sentient] useAdaptiveTokens("${e}") declares ${g} combinations \u2014 more than the recommended 4. Each extra combination needs more traffic to learn; consider fewer dims/values.`)):(ce.add(e),console.warn(`[sentient] useAdaptiveTokens("${e}"): invalid declaration \u2014 ${c.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,F.useEffect)(()=>ne({id:e,dims:t}),[e]);let y=(0,F.useRef)(null);(0,F.useEffect)(()=>{!o||l==="baseline"||l==="override"||y.current===d||(y.current=d,N(o,a,e,d))},[o,a,e,d,l]),(0,F.useEffect)(()=>{if(!o||!(n!=null&&n.goal)||l==="override")return;let c=document.querySelector(`[data-sentient-slot="${Dt(e)}"]`);if(!c){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 g=J(n.goal),p=!1;return K(c,B(n.goal),{fireGoal:()=>{p||(p=!0,o.componentGoal(e,g),o.goal(g,{componentId:e,arm:d},1,0))},fireStep:(s,m,h)=>{o.componentGoal(e,s,{reward:m}),o.goal(s,{componentId:e,arm:d},m,h)}})},[o,e,f,d,l]);let S=(0,F.useMemo)(()=>{let c={"data-sentient-slot":e};for(let[g,p]of Object.entries(b))c[`data-${g}`]=p;return c},[e,b]);return{tokens:b,props:S}}var G=require("react"),lt=require("@sentientui/core");var at=new Set;function ut(e,t){var _;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(),o=j(),a=Object.keys(t.variants).join(" "),r=(0,G.useMemo)(()=>Object.keys(t.variants),[a]),{variantId:u,isOverride:i,settled:d}=X(e,r),l=(_=u!=null?u:r[0])!=null?_:"",b=t.variants[l],[f,y]=(0,G.useState)(null),S=(0,G.useRef)(null),c=(0,G.useCallback)(v=>{S.current=v,y(v)},[]),g=typeof t.goal=="string"?t.goal:JSON.stringify(t.goal),p=(0,G.useMemo)(()=>B(t.goal),[g]),s=J(t.goal);(0,G.useEffect)(()=>te({id:e,variantIds:r,goal:s}),[e,r,s]);let m=(0,G.useRef)(null);(0,G.useEffect)(()=>{i||d&&(!n||!l||!f||m.current!==l&&(m.current=l,N(n,o,e,l)))},[n,o,e,l,f,i,d]);let h=(0,G.useRef)(!1);(0,G.useEffect)(()=>{h.current=!1},[l,g]),(0,G.useEffect)(()=>{if(!i&&!(!n||!l||!f))return K(f,p,{fireGoal:()=>{h.current||(h.current=!0,n.track({projectId:o,componentId:e,variantId:l,eventType:"goal_achieved",goalType:s,payload:{reward:1}}),n.goal(s,{componentId:e,variantId:l},1,0))},fireStep:(v,w,x)=>{n.track({projectId:o,componentId:e,variantId:l,eventType:"goal_achieved",goalType:v,payload:{reward:w}}),n.goal(v,{},w,x)}})},[n,f,l,o,e,p,s,i]),(0,G.useEffect)(()=>{if(i||!n||!l||!f)return;let v=Date.now();return(0,lt.attachMicroSignalDetectors)((w,x={})=>{n.track({projectId:o,componentId:e,variantId:l,eventType:"micro_signal",payload:P({signalType:w},x)})},f,v)},[n,f,l,o,e,i]),(0,G.useEffect)(()=>{if(!O()||!n)return;let v=setTimeout(()=>{!S.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(v)},[n,e]);let k=(0,G.useCallback)((v,w)=>{var V,Y;if(i)return;let x=v!=null?v:s;n==null||n.componentGoal(e,x,w),n==null||n.goal(x,(V=w==null?void 0:w.metadata)!=null?V:{},(Y=w==null?void 0:w.reward)!=null?Y:1,0)},[n,e,s,i]),C=(0,G.useMemo)(()=>({ref:c,"data-sentient-id":e,"data-sentient-variant":l}),[c,e,l]);return{variant:l,value:b,bind:C,fireGoal:k}}var I=require("react");var dt=require("react/jsx-runtime"),ae=new Set;function ct(e){var p;let t=E(),n=j(),o=(0,I.useRef)(null),a=Object.keys(e.arrangements).join(" "),r=(0,I.useMemo)(()=>Object.keys(e.arrangements),[a]),u=(0,I.useMemo)(()=>P({id:e.id,arms:r},e.baseline!==void 0?{baseline:e.baseline}:{}),[e.id,r,e.baseline]),{arm:i,source:d}=se(e.id,u);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),b=new Map;for(let s of l)b.set(String((p=s.key)!=null?p:"").replace(/^\.\$/,""),s);let f=e.arrangements[i],y=f!==void 0&&f.length===l.length&&f.every(s=>b.has(s));O()&&f!==void 0&&!y&&!ae.has(e.id+":keys")&&(ae.add(e.id+":keys"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: arrangement "${i}" [${f.join(", ")}] does not match the children's keys \u2014 rendering declaration order (fail-safe).`));let S=y?f.map(s=>b.get(s)):l;(0,I.useEffect)(()=>ne({id:e.id,arms:Object.keys(e.arrangements)}),[e.id]);let c=(0,I.useRef)(null);(0,I.useEffect)(()=>{!t||d==="baseline"||d==="override"||c.current===i||(c.current=i,N(t,n,e.id,i))},[t,n,e.id,i,d]);let g=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||d==="override")return;let s=o.current;if(!s)return;let m=J(e.goal),h=!1;return K(s,B(e.goal),{fireGoal:()=>{h||(h=!0,t.componentGoal(e.id,m),t.goal(m,{componentId:e.id,arm:i},1,0))},fireStep:(k,C,_)=>{t.componentGoal(e.id,k,{reward:C}),t.goal(k,{componentId:e.id,arm:i},C,_)}})},[t,e.id,g,i,d]),(0,dt.jsx)("div",{ref:o,"data-sentient-id":e.id,"data-sentient-variant":i,children:S})}var de=require("@sentientui/core");var Mt=["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[u,i]of Object.entries(t))Mt.includes(u)||(n[u]=i);let o=Z(P({},n),{page:e.page,blocks:e.blocks});return e.layoutOrder&&(o.layoutOrder=e.layoutOrder),o}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,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
|
-
`}0&&(module.exports={Adaptive,AdaptiveGroup,AdaptiveProvider,AdaptiveText,SentientPersonaScript,buildAgentFeed,defineAgentContent,detectSegment,getAgentContent,renderAgentJsonLd,renderAgentJsonLdBody,renderAgentMarkdown,useAdaptive,useAdaptiveApiBaseUrl,useAdaptiveGoal,useAdaptiveTokens,useAssignment,useInitialAssignments,useLayoutOrder,useSentient});
|
|
4
|
+
`}0&&(module.exports={Adaptive,AdaptiveGroup,AdaptiveProvider,AdaptiveText,SentientPersonaScript,buildAgentFeed,defineAgentContent,detectSegment,getAgentContent,renderAgentJsonLd,renderAgentJsonLdBody,renderAgentMarkdown,useAdaptive,useAdaptiveApiBaseUrl,useAdaptiveGoal,useAdaptivePersona,useAdaptiveTokens,useAssignment,useInitialAssignments,useLayoutOrder,useSentient});
|
|
5
5
|
//# sourceMappingURL=index.js.map
|