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