@sentientui/react 0.14.3 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -6
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -7,16 +7,22 @@ learns which one converts best for each visitor type. Visit 1 learns; Visit 2 co
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install @sentientui/react # or: npx @sentientui/cli init (
|
|
10
|
+
npm install @sentientui/react # or: npx @sentientui/cli init (installs + writes .env.local + an example component)
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## 2-minute start (no account)
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
npx @sentientui/cli init
|
|
17
|
-
#
|
|
16
|
+
npx @sentientui/cli init
|
|
17
|
+
# then follow its printed instructions: wrap your app with <AdaptiveRoot> (or
|
|
18
|
+
# <AdaptiveProvider>) and mount the generated components/adaptive-example.tsx
|
|
19
|
+
npm run dev
|
|
20
|
+
# open http://localhost:3000?sentient_persona=buyer — the example adapts
|
|
18
21
|
```
|
|
19
22
|
|
|
23
|
+
The CLI installs the package, writes `.env.local`, and generates an example component — it does
|
|
24
|
+
**not** edit your layout, so nothing adapts until you do the wrap-and-mount step it prints.
|
|
25
|
+
|
|
20
26
|
With no API key the SDK runs in keyless **local mode**: deterministic simulated decisions, zero
|
|
21
27
|
network. Add a `pk_…` key from [sentient-ui.com](https://sentient-ui.com) to learn from real
|
|
22
28
|
traffic:
|
|
@@ -54,7 +60,13 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
54
60
|
`suppressHydrationWarning` on `<html>` is required: an inline script (rendered by
|
|
55
61
|
`AdaptiveRoot` as its first child) sets the persona attributes before first paint, exactly like
|
|
56
62
|
the `next-themes` pattern. Other React apps (Vite, CRA, Remix, Pages Router) use
|
|
57
|
-
`<AdaptiveProvider>` from `@sentientui/react` with the same props
|
|
63
|
+
`<AdaptiveProvider>` from `@sentientui/react` with the same props — **plus
|
|
64
|
+
`<SentientPersonaScript />` rendered in your document `<head>`** if you want the Rung-1a persona
|
|
65
|
+
attributes: only that inline script (which `AdaptiveRoot` includes for you) writes
|
|
66
|
+
`data-sentient-persona` / `data-sentient-confidence` in hosted mode. Without it, an
|
|
67
|
+
`AdaptiveProvider` app gets everything except the persona CSS hooks. (Keyless local mode writes
|
|
68
|
+
the attributes itself, so the demo works either way — don't let that mask a missing script when
|
|
69
|
+
you add a real key.)
|
|
58
70
|
|
|
59
71
|
## The adaptive ladder
|
|
60
72
|
|
|
@@ -423,7 +435,7 @@ Direct `@sentientui/core` users enable the same thing by importing `init` from `
|
|
|
423
435
|
|
|
424
436
|
## Consent management (GDPR)
|
|
425
437
|
|
|
426
|
-
|
|
438
|
+
By default the SDK initialises with `consent: true`, so tracking starts on first paint — opt-in consent is something you wire up, not the default. For GDPR-style opt-in, pass `consent={false}` until the visitor accepts your banner; no events are sent and no cookie is written while consent is false. To serve the best-performing variant while the cookie banner is pending (rather than freezing the UI), add `preConsentBehavior: 'statistical_winner'`:
|
|
427
439
|
|
|
428
440
|
```tsx
|
|
429
441
|
<AdaptiveProvider
|
package/dist/index.d.cts
CHANGED
|
@@ -215,6 +215,12 @@ type AssignmentState = {
|
|
|
215
215
|
/** Populated when the assigned variant is a dashboard-managed text variant. */
|
|
216
216
|
content: string | null;
|
|
217
217
|
isLoading: boolean;
|
|
218
|
+
/**
|
|
219
|
+
* True while a dev override (?sentient_variant= / window.__sentient_overrides)
|
|
220
|
+
* is forcing this variant. Consumers must suppress ALL tracking while set —
|
|
221
|
+
* the override contract is "no events recorded, weights unchanged".
|
|
222
|
+
*/
|
|
223
|
+
isOverride?: boolean;
|
|
218
224
|
};
|
|
219
225
|
/**
|
|
220
226
|
* Returns a sticky variant assignment for a component.
|
package/dist/index.d.ts
CHANGED
|
@@ -215,6 +215,12 @@ type AssignmentState = {
|
|
|
215
215
|
/** Populated when the assigned variant is a dashboard-managed text variant. */
|
|
216
216
|
content: string | null;
|
|
217
217
|
isLoading: boolean;
|
|
218
|
+
/**
|
|
219
|
+
* True while a dev override (?sentient_variant= / window.__sentient_overrides)
|
|
220
|
+
* is forcing this variant. Consumers must suppress ALL tracking while set —
|
|
221
|
+
* the override contract is "no events recorded, weights unchanged".
|
|
222
|
+
*/
|
|
223
|
+
isOverride?: boolean;
|
|
218
224
|
};
|
|
219
225
|
/**
|
|
220
226
|
* Returns a sticky variant assignment for a component.
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
"use strict";var at=Object.create;var V=Object.defineProperty,lt=Object.defineProperties,ct=Object.getOwnPropertyDescriptor,ut=Object.getOwnPropertyDescriptors,dt=Object.getOwnPropertyNames,pe=Object.getOwnPropertySymbols,gt=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable;var me=(e,t,n)=>t in e?V(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,G=(e,t)=>{for(var n in t||(t={}))ve.call(t,n)&&me(e,n,t[n]);if(pe)for(var n of pe(t))ft.call(t,n)&&me(e,n,t[n]);return e},H=(e,t)=>lt(e,ut(t));var pt=(e,t)=>{for(var n in t)V(e,n,{get:t[n],enumerable:!0})},ye=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of dt(t))!ve.call(e,i)&&i!==n&&V(e,i,{get:()=>t[i],enumerable:!(o=ct(t,i))||o.enumerable});return e};var mt=(e,t,n)=>(n=e!=null?at(gt(e)):{},ye(t||!e||!e.__esModule?V(n,"default",{value:e,enumerable:!0}):n,e)),vt=e=>ye(V({},"__esModule",{value:!0}),e);var Et={};pt(Et,{Adaptive:()=>De,AdaptiveGroup:()=>Qe,AdaptiveProvider:()=>Ce,AdaptiveText:()=>We,SentientPersonaScript:()=>Ue,buildAgentFeed:()=>tt,defineAgentContent:()=>et,detectSegment:()=>le.deriveSessionSegment,getAgentContent:()=>ce,getWeights:()=>Q,renderAgentJsonLd:()=>nt,renderAgentJsonLdBody:()=>ue,renderAgentMarkdown:()=>it,subscribeWeights:()=>X,updateWeights:()=>q,useAdaptive:()=>qe,useAdaptiveApiBaseUrl:()=>Le,useAdaptiveGoal:()=>je,useAdaptiveTokens:()=>Je,useAssignment:()=>N,useInitialAssignments:()=>te,useLayoutOrder:()=>Ge,useSentient:()=>_});module.exports=vt(Et);var w=require("react"),K=require("@sentientui/core");var Se=new Map,z=new Map;function X(e,t){let n=z.get(e);return n||(n=new Set,z.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&z.delete(e)}}function q(e,t){Se.set(e,t);let n=z.get(e);if(n)for(let o of n)try{o(t)}catch(i){}}function Q(e){var t;return(t=Se.get(e))!=null?t:null}var yt={on:!1,listeners:new Set};function he(){if(typeof window=="undefined")return yt;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function se(){return he().on}function we(e){let t=he().listeners;return t.add(e),()=>{t.delete(e)}}function be(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(),destroy:()=>e.destroy()}}var Ae="sentient:overrides-changed";function Y(){var e;return typeof window=="undefined"?0:(e=window.__sentient_overrides_version)!=null?e:0}function j(e){return typeof window=="undefined"?()=>{}:(window.addEventListener(Ae,e),()=>window.removeEventListener(Ae,e))}function xe(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}var St={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function F(){if(typeof window=="undefined")return St;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 J(){F().version+=1;for(let e of F().listeners)e()}function Z(e){return F().components.set(e.id,e),J(),()=>{F().components.delete(e.id),J()}}function ee(e){return F().slots.set(e.id,e),J(),()=>{F().slots.delete(e.id),J()}}function ke(e){F().sections=[...e],J()}var Oe=require("react/jsx-runtime");function ht(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{let n=(0,K.detectDeviceClass)((e=navigator.userAgent)!=null?e:""),o=(0,K.detectTrafficSource)((t=document.referrer)!=null?t:"",window.location.origin);return`${n}:${o}`}catch(n){return"desktop:direct"}}var _e="https://api.sentient-ui.com/v1",O=(0,w.createContext)({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialPersona:null,apiBaseUrl:_e});function Ce(e){var y,c;let[t,n]=(0,w.useState)(null),[o]=(0,w.useState)(()=>{var u;return(u=e.sessionSegment)!=null?u:ht()}),[i,m]=(0,w.useState)(se());(0,w.useEffect)(()=>we(()=>m(se())),[]),(0,w.useEffect)(()=>{if(e.consent===!1&&!e.preConsentBehavior){n(l=>(l==null||l.destroy(),null));return}let u={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},f=!1,s=null;return e.enableGraph?import("@sentientui/core/graph").then(({init:l})=>{f||(s=l(H(G({},u),{graph:!0})),n(s))}):(s=(0,K.init)(u),n(s)),()=>{f=!0,s==null||s.destroy()}},[e.consent]),(0,w.useEffect)(()=>{if(!t)return;let u=!1,f=async()=>{if(u)return;let l;try{l=await t.fetchWeights()}catch(b){return}if(!u)for(let b of l){let h={componentId:b.componentId,updatedAt:b.updatedAt,variants:b.variants.map(S=>{var v;return{variantId:S.variantId,pulls:S.pulls,avgReward:(v=S.avgReward)!=null?v:0}})};q(b.componentId,h)}};f();let s=setInterval(()=>{f()},6e4);return()=>{u=!0,clearInterval(s)}},[t]);let r=(y=e.ssrFallback)!=null?y:"first",a=(c=e.apiBaseUrl)!=null?c:_e;(0,w.useEffect)(()=>{var u;typeof process!="undefined"&&((u=process.env)==null?void 0:u.NODE_ENV)==="production"||xe({apiKey:e.apiKey,apiBaseUrl:a,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,a]),(0,w.useEffect)(()=>{e.initialLayoutOrder&&e.initialLayoutOrder.length>0&&ke(e.initialLayoutOrder)},[e.initialLayoutOrder]);let g=(0,w.useMemo)(()=>t&&i?be(t):t,[t,i]),d=(0,w.useMemo)(()=>{var u,f,s,l;return{client:g,apiKey:e.apiKey,initialAssignments:(u=e.initialAssignments)!=null?u:{},sessionSegment:o,ssrFallback:r,onAssignment:e.onAssignment,initialLayoutOrder:(f=e.initialLayoutOrder)!=null?f:null,initialSlots:(s=e.initialSlots)!=null?s:{},initialPersona:(l=e.initialPersona)!=null?l:null,apiBaseUrl:a}},[g,e.apiKey,e.initialAssignments,o,r,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialPersona,a]);return(0,Oe.jsx)(O.Provider,{value:d,children:e.children})}function _(){return(0,w.useContext)(O).client}function I(){return(0,w.useContext)(O).apiKey}function te(){return(0,w.useContext)(O).initialAssignments}function ne(){return(0,w.useContext)(O).sessionSegment}function Re(){return(0,w.useContext)(O).ssrFallback}function ie(){return(0,w.useContext)(O).onAssignment}function Ge(){let e=(0,w.useContext)(O).initialLayoutOrder,t=(0,w.useSyncExternalStore)(j,()=>{var n;return typeof window=="undefined"?null:(n=window.__sentient_layout_override)!=null?n:null},()=>null);return t!=null?t:e}function Ee(){return(0,w.useContext)(O).initialSlots}function Le(){return(0,w.useContext)(O).apiBaseUrl}var x=require("react"),Te=require("@sentientui/core");var L=require("react");function wt(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 m=i.indexOf(":");if(m!==-1&&i.slice(0,m)===e)return i.slice(m+1)}}catch(o){}return null}function Ie(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 N(e,t,n,o){let i=te(),m=Re(),r=_(),a=ne(),g=ie(),d=(0,L.useRef)(null);(0,L.useSyncExternalStore)(j,Y,()=>0);let y=wt(e),c=y&&t.includes(y)?y:null,u=(0,L.useRef)(null);c&&u.current!==c&&(u.current=c,console.info(`[sentient] override active: ${e} -> ${c}`));let f=(()=>{var v,p;if(c)return{variantId:c,content:null,isLoading:!1};if(!r){let A=i[e];return A&&t.includes(A)?{variantId:A,content:null,isLoading:!1}:m==="first"&&t.length>0?{variantId:t[0],content:null,isLoading:!1}:{variantId:null,content:null,isLoading:!0}}let h=r.getAssignment(e,a);if(h&&(t.includes(h.variantId)||h.content))return{variantId:h.variantId,content:(v=h.content)!=null?v:null,isLoading:!1};let S=Q(e);if(S){let A=Ie(S,t);if(A)return{variantId:A,content:null,isLoading:!1}}return{variantId:(p=t[0])!=null?p:null,content:null,isLoading:!1}})(),[s,l]=(0,L.useState)(f),b=h=>{g&&d.current!==h&&(d.current=h,g(e,h))};return(0,L.useEffect)(()=>{var S;if(c||!r)return;let h=r.getAssignment(e,a);if(h&&(t.includes(h.variantId)||h.content)){l({variantId:h.variantId,content:(S=h.content)!=null?S:null,isLoading:!1}),b(h.variantId);return}l(v=>{var p;return v.variantId?v:{variantId:(p=t[0])!=null?p:null,content:null,isLoading:!1}})},[c,r,e,a]),(0,L.useEffect)(()=>{if(c||!r)return;let h=r.getAssignment(e,a);if(h&&t.includes(h.variantId))return;let S=!1;return r.assign(e,t,n,o).then(v=>{var p;S||v&&(!t.includes(v.variantId)&&!v.content||(l({variantId:v.variantId,content:(p=v.content)!=null?p:null,isLoading:!1}),b(v.variantId)))}),()=>{S=!0}},[c,r,e,a]),(0,L.useEffect)(()=>{if(!c&&r)return X(e,h=>{var p;let S=r.getAssignment(e,a);if(S&&(t.includes(S.variantId)||S.content)){l({variantId:S.variantId,content:(p=S.content)!=null?p:null,isLoading:!1});return}let v=Ie(h,t);v&&l({variantId:v,content:null,isLoading:!1})})},[c,r,e,a]),c?{variantId:c,content:null,isLoading:!1}:s}function E(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}function T(e){return typeof e=="string"?{type:"click"}:e}function $(e){return typeof e=="string"?e:e.type}var bt=3e4;function At(e,t){try{let n=`_snt_pv_${e}_${t}`;return sessionStorage.getItem(n)?!1:(sessionStorage.setItem(n,"1"),!0)}catch(n){return!0}}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 Pe(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 D(e,t,n){if(t.type==="weighted_composite"){let a=new Set,g=[];return t.steps.forEach(({goal:d,name:y,weight:c},u)=>{let f=()=>{a.has(u)||(a.add(u),n.fireStep(y,c,u))};if(d.type==="click"){let s=l=>{let b=l.target;b instanceof Element&&Pe(b,e,d.selector)&&f()};e.addEventListener("click",s),g.push(()=>e.removeEventListener("click",s));return}if(d.type==="form_submit"){let s=l=>{l.target instanceof HTMLFormElement&&e.contains(l.target)&&f()};e.addEventListener("submit",s),g.push(()=>e.removeEventListener("submit",s));return}if(d.type==="scroll_depth"){let s=Math.max(0,Math.min(1,d.threshold)),l=new IntersectionObserver(b=>{for(let h of b)if(h.intersectionRatio>=s){f(),l.disconnect();break}},{threshold:[s]});l.observe(e),g.push(()=>l.disconnect())}}),()=>{for(let d of g)d()}}let o=t.type==="composite"?t.all:[t],i=new Set(o.map((a,g)=>g)),m=a=>{i.delete(a),i.size===0&&n.fireGoal()},r=[];return o.forEach((a,g)=>{if(a.type==="click"){let d=y=>{let c=y.target;c instanceof Element&&Pe(c,e,a.selector)&&(t.type==="composite"?m(g):n.fireGoal())};e.addEventListener("click",d),r.push(()=>e.removeEventListener("click",d));return}if(a.type==="form_submit"){let d=y=>{y.target instanceof HTMLFormElement&&e.contains(y.target)&&(t.type==="composite"?m(g):n.fireGoal())};e.addEventListener("submit",d),r.push(()=>e.removeEventListener("submit",d));return}if(a.type==="scroll_depth"){let d=Math.max(0,Math.min(1,a.threshold)),y=new IntersectionObserver(c=>{for(let u of c)if(u.intersectionRatio>=d){t.type==="composite"?m(g):n.fireGoal(),y.disconnect();break}},{threshold:[d]});y.observe(e),r.push(()=>y.disconnect());return}}),()=>{for(let a of r)a()}}function M(e,t,n,o,i){var a;let m=(a=i==null?void 0:i.innerHTML)!=null?a:"",r=m!==""&&At(n,o);e.track({projectId:t,componentId:n,variantId:o,eventType:"variant_assigned",payload:r?{previewHtml:m.slice(0,bt)}:{}})}var Me=require("react/jsx-runtime");function kt(e){var h;let t=_(),n=I(),o=(0,x.useMemo)(()=>Object.keys(e.variants),[e.variants]),{variantId:i,content:m}=N(e.id,o,e.agentData,e.agentDataByVariant),r=(0,x.useRef)(null),[a,g]=(0,x.useState)(!1);(0,x.useEffect)(()=>{g(!0)},[]);let d=(0,x.useRef)(!1),y=(0,x.useRef)(new Set),c=(0,x.useRef)(null),u=typeof e.goal=="string"?e.goal:JSON.stringify(e.goal),f=(0,x.useMemo)(()=>T(e.goal),[u]),s=typeof e.goal=="string"?e.goal:f.type;if((0,x.useEffect)(()=>Z({id:e.id,variantIds:o,goal:s}),[e.id,o,s]),(0,x.useEffect)(()=>{var v,p;!t||!i||!n||c.current===i||!((p=(v=r.current)==null?void 0:v.innerHTML)!=null&&p)||(c.current=i,M(t,n,e.id,i,r.current))},[t,i,n,e.id,a,m]),(0,x.useEffect)(()=>{d.current=!1,y.current=new Set},[i,f]),(0,x.useEffect)(()=>{if(!t||!i)return;let S=r.current;if(!S)return;let v=null,p=0,A=()=>{p=Date.now(),v=setTimeout(()=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-p}}),v=null},800)},C=()=>{v!==null&&(clearTimeout(v),v=null)};return S.addEventListener("mouseenter",A),S.addEventListener("mouseleave",C),()=>{S.removeEventListener("mouseenter",A),S.removeEventListener("mouseleave",C),v!==null&&clearTimeout(v)}},[t,i,n,e.id]),(0,x.useEffect)(()=>{if(!t||!i)return;let S=r.current;if(!S)return;let v=Date.now();return(0,Te.attachMicroSignalDetectors)((p,A={})=>{var de,ge,fe;t.track({projectId:n,componentId:e.id,variantId:i,eventType:"micro_signal",payload:G({signalType:p},A)});let C=(de=e.microSignalGoals)==null?void 0:de[p];if(!C||y.current.has(p))return;y.current.add(p);let rt=typeof C=="string"?C:C.name,ot=typeof C=="string"?1:(ge=C.weight)!=null?ge:1,st=typeof C=="string"?0:(fe=C.stepIndex)!=null?fe:0;t.goal(rt,G({signalType:p},A),ot,st)},S,v)},[t,i,n,e.id,e.microSignalGoals]),(0,x.useEffect)(()=>{if(!t||!i)return;let S=r.current;if(S)return D(S,f,{fireGoal:()=>{d.current||(d.current=!0,t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:s,payload:{reward:1}}),t.goal(s,{componentId:e.id,variantId:i},1,0))},fireStep:(v,p,A)=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:v,payload:{reward:p}}),t.goal(v,{},p,A)}})},[t,i,n,e.id,f,s]),e.clientOnly&&(!a||!t)||!i)return null;let l=(h=e.variants[i])!=null?h:null,b=l===null?m:null;return E()&&l===null&&b===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,Me.jsx)("div",{ref:r,"data-sentient-id":e.id,"data-sentient-variant":i,children:l!=null?l:b})}var De=(0,x.memo)(kt,(e,t)=>{if(e.id!==t.id||JSON.stringify(e.goal)!==JSON.stringify(t.goal)||e.microSignalGoals!==t.microSignalGoals)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)});var W=require("react");var Fe=require("react/jsx-runtime");function We({id:e,default:t,component:n="span",className:o}){let i=_(),m=I(),r=ie(),a=ne(),g=(0,W.useRef)(null),[d,y]=(0,W.useState)(()=>{var f,s;return(s=(f=i==null?void 0:i.getAssignment(e,a))==null?void 0:f.content)!=null?s:null}),[c,u]=(0,W.useState)(()=>{var f,s;return(s=(f=i==null?void 0:i.getAssignment(e,a))==null?void 0:f.variantId)!=null?s:null});return(0,W.useEffect)(()=>{var s;if(!i||((s=i.getAssignment(e,a))==null?void 0:s.content)!==void 0)return;let f=!1;return i.assign(e).then(l=>{if(!f){if(!l){E()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}u(l.variantId),l.content&&y(l.content)}}),()=>{f=!0}},[i,e,a]),(0,W.useEffect)(()=>{!i||!c||!m||g.current!==c&&(g.current=c,i.track({projectId:m,componentId:e,variantId:c,eventType:"variant_assigned",payload:{}}),r==null||r(e,c))},[i,c,m,e,r]),(0,Fe.jsx)(n,{className:o,children:d!=null?d:t})}var Be=require("react");function je(e){let t=_();return(0,Be.useCallback)((n,o)=>{t==null||t.componentGoal(e,n,o)},[t,e])}var Ne=require("@sentientui/core"),$e=require("@sentientui/policy"),Ve=require("react/jsx-runtime");function Ke(e){return JSON.stringify(e).replace(/</g,"\\u003c")}function _t(e){return e.persona?'(function(){try{var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",'+Ke(e.persona.persona)+');d.setAttribute("data-sentient-confidence",'+Ke((0,$e.confidenceBand)(e.persona.confidence))+");}catch(e){}})();":(0,Ne.renderPrePaintScript)(e.apiKey)}function Ue(e){return(0,Ve.jsx)("script",{"data-sentient-persona-script":"",dangerouslySetInnerHTML:{__html:_t(e)}})}var P=require("react"),He=require("@sentientui/policy");var U=require("react"),B=require("@sentientui/core"),Ct=require("@sentientui/policy");function re(e,t){var y;(0,U.useSyncExternalStore)(j,Y,()=>0);let n=_(),o=Ee(),[,i]=(0,U.useReducer)(c=>c+1,0),m=typeof window!="undefined"?(y=window.__sentient_slot_overrides)==null?void 0:y[e]:void 0,r=m===void 0?o[e]:void 0,a=m===void 0&&r===void 0&&n?n.getSlotResult(e):null,g=(n==null?void 0:n.isLocal)===!0&&m===void 0&&r===void 0&&a===null;if((0,U.useEffect)(()=>{if(!g||!n)return;let c=!1;return n.decide({slots:[t]}).then(u=>{!c&&u&&i()}),()=>{c=!0}},[n,e,g]),m!==void 0)return{result:m,arm:(0,B.armOfResult)(m),source:"override"};if(r!==void 0)return{result:r,arm:(0,B.armOfResult)(r),source:"preloaded"};if(a!==null)return{result:a,arm:(0,B.armOfResult)(a),source:"client"};let d=(0,B.baselineResultFor)(t);return{result:d,arm:(0,B.armOfResult)(d),source:"baseline"}}var ae=new Set;function Rt(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/"/g,'\\"')}function Je(e,t,n){let o=_(),i=I(),m=(0,P.useMemo)(()=>({id:e,dims:t}),[e]),{result:r,arm:a}=re(e,m),g=(0,P.useMemo)(()=>typeof r=="string"?{}:r,[a]);if(E()&&!ae.has(e)){let u=(0,He.validateSlotDecl)({id:e,dims:Object.fromEntries(Object.entries(t).map(([s,l])=>[s,[...l]]))}),f=Object.values(t).reduce((s,l)=>s*l.length,1);u.ok?f>4&&(ae.add(e),console.warn(`[sentient] useAdaptiveTokens("${e}") declares ${f} combinations \u2014 more than the recommended 4. Each extra combination needs more traffic to learn; consider fewer dims/values.`)):(ae.add(e),console.warn(`[sentient] useAdaptiveTokens("${e}"): invalid declaration \u2014 ${u.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,P.useEffect)(()=>ee({id:e,dims:t}),[e]);let y=(0,P.useRef)(null);(0,P.useEffect)(()=>{!o||y.current===a||(y.current=a,M(o,i,e,a,null))},[o,i,e,a]),(0,P.useEffect)(()=>{if(!o||!(n!=null&&n.goal))return;let u=document.querySelector(`[data-sentient-slot="${Rt(e)}"]`);if(!u){E()&&console.warn(`[sentient] useAdaptiveTokens("${e}"): a goal is declared but no element carries the returned props \u2014 spread {...props} on the slot's element.`);return}let f=$(n.goal),s=!1;return D(u,T(n.goal),{fireGoal:()=>{s||(s=!0,o.componentGoal(e,f))},fireStep:(l,b)=>{o.componentGoal(e,l,{reward:b})}})},[o,e,d,a]);let c=(0,P.useMemo)(()=>{let u={"data-sentient-slot":e};for(let[f,s]of Object.entries(g))u[`data-${f}`]=s;return u},[e,g]);return{tokens:g,props:c}}var k=require("react"),Xe=require("@sentientui/core");var ze=new Set;function qe(e,t){var v;if(E()&&!t.goal)throw new Error(`[sentient] useAdaptive("${e}"): a goal is required \u2014 without one the optimizer accumulates exposures with no rewards and cannot learn. Pass e.g. goal: 'buy_click'.`);let n=_(),o=I(),i=(0,k.useMemo)(()=>Object.keys(t.variants),[e]),{variantId:m}=N(e,i),r=(v=m!=null?m:i[0])!=null?v:"",a=t.variants[r],[g,d]=(0,k.useState)(null),y=(0,k.useRef)(null),c=(0,k.useCallback)(p=>{y.current=p,d(p)},[]),u=typeof t.goal=="string"?t.goal:JSON.stringify(t.goal),f=(0,k.useMemo)(()=>T(t.goal),[u]),s=$(t.goal);(0,k.useEffect)(()=>Z({id:e,variantIds:i,goal:s}),[e,i,s]);let l=(0,k.useRef)(null);(0,k.useEffect)(()=>{!n||!r||!g||l.current!==r&&(l.current=r,M(n,o,e,r,g))},[n,o,e,r,g]);let b=(0,k.useRef)(!1);(0,k.useEffect)(()=>{b.current=!1},[r,u]),(0,k.useEffect)(()=>{if(!(!n||!r||!g))return D(g,f,{fireGoal:()=>{b.current||(b.current=!0,n.track({projectId:o,componentId:e,variantId:r,eventType:"goal_achieved",goalType:s,payload:{reward:1}}),n.goal(s,{componentId:e,variantId:r},1,0))},fireStep:(p,A,C)=>{n.track({projectId:o,componentId:e,variantId:r,eventType:"goal_achieved",goalType:p,payload:{reward:A}}),n.goal(p,{},A,C)}})},[n,g,r,o,e,f,s]),(0,k.useEffect)(()=>{if(!n||!r||!g)return;let p=Date.now();return(0,Xe.attachMicroSignalDetectors)((A,C={})=>{n.track({projectId:o,componentId:e,variantId:r,eventType:"micro_signal",payload:G({signalType:A},C)})},g,p)},[n,g,r,o,e]),(0,k.useEffect)(()=>{if(!E()||!n)return;let p=setTimeout(()=>{!y.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(p)},[n,e]);let h=(0,k.useCallback)((p,A)=>{n==null||n.componentGoal(e,p!=null?p:s,A)},[n,e,s]),S=(0,k.useMemo)(()=>({ref:c,"data-sentient-id":e,"data-sentient-variant":r}),[c,e,r]);return{variant:r,value:a,bind:S,fireGoal:h}}var R=require("react");var Ye=require("react/jsx-runtime"),oe=new Set;function Qe(e){var s;let t=_(),n=I(),o=(0,R.useRef)(null),i=(0,R.useMemo)(()=>Object.keys(e.arrangements),[e.id]),m=(0,R.useMemo)(()=>G({id:e.id,arms:i},e.baseline!==void 0?{baseline:e.baseline}:{}),[e.id,i,e.baseline]),{arm:r}=re(e.id,m);E()&&e.baseline!==void 0&&e.baseline!==i[0]&&!oe.has(e.id+":baseline")&&(oe.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 a=R.Children.toArray(e.children).filter(R.isValidElement),g=new Map;for(let l of a)g.set(String((s=l.key)!=null?s:"").replace(/^\.\$/,""),l);let d=e.arrangements[r],y=d!==void 0&&d.length===a.length&&d.every(l=>g.has(l));E()&&d!==void 0&&!y&&!oe.has(e.id+":keys")&&(oe.add(e.id+":keys"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: arrangement "${r}" [${d.join(", ")}] does not match the children's keys \u2014 rendering declaration order (fail-safe).`));let c=y?d.map(l=>g.get(l)):a;(0,R.useEffect)(()=>ee({id:e.id,arms:Object.keys(e.arrangements)}),[e.id]);let u=(0,R.useRef)(null);(0,R.useEffect)(()=>{!t||u.current===r||(u.current=r,M(t,n,e.id,r,o.current))},[t,n,e.id,r]);let f=e.goal===void 0?null:typeof e.goal=="string"?e.goal:JSON.stringify(e.goal);return(0,R.useEffect)(()=>{if(!t||e.goal===void 0)return;let l=o.current;if(!l)return;let b=$(e.goal),h=!1;return D(l,T(e.goal),{fireGoal:()=>{h||(h=!0,t.componentGoal(e.id,b))},fireStep:(S,v)=>{t.componentGoal(e.id,S,{reward:v})}})},[t,e.id,f,r]),(0,Ye.jsx)("div",{ref:o,"data-sentient-id":e.id,"data-sentient-variant":r,children:c})}var le=require("@sentientui/core");var Gt=["page","blocks","layoutOrder"],Ze=new Map;function et(e,t){Ze.set(e,t)}function ce(e){return Ze.get(e)}function tt(e){var i,m;let t=(m=(i=e.content)!=null?i:ce(e.page))!=null?m:{},n={};for(let[r,a]of Object.entries(t))Gt.includes(r)||(n[r]=a);let o=H(G({},n),{page:e.page,blocks:e.blocks});return e.layoutOrder&&(o.layoutOrder=e.layoutOrder),o}function nt(e){return`<script type="application/ld+json">${ue(e)}</script>`}function ue(e){return JSON.stringify(G({"@context":"https://schema.org","@type":"WebPage"},e)).replace(/</g,"\\u003c")}function it(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 lt=Object.create;var H=Object.defineProperty,ct=Object.defineProperties,ut=Object.getOwnPropertyDescriptor,dt=Object.getOwnPropertyDescriptors,ft=Object.getOwnPropertyNames,me=Object.getOwnPropertySymbols,gt=Object.getPrototypeOf,ye=Object.prototype.hasOwnProperty,pt=Object.prototype.propertyIsEnumerable;var ve=(e,t,n)=>t in e?H(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,E=(e,t)=>{for(var n in t||(t={}))ye.call(t,n)&&ve(e,n,t[n]);if(me)for(var n of me(t))pt.call(t,n)&&ve(e,n,t[n]);return e},J=(e,t)=>ct(e,dt(t));var mt=(e,t)=>{for(var n in t)H(e,n,{get:t[n],enumerable:!0})},Se=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of ft(t))!ye.call(e,i)&&i!==n&&H(e,i,{get:()=>t[i],enumerable:!(o=ut(t,i))||o.enumerable});return e};var vt=(e,t,n)=>(n=e!=null?lt(gt(e)):{},Se(t||!e||!e.__esModule?H(n,"default",{value:e,enumerable:!0}):n,e)),yt=e=>Se(H({},"__esModule",{value:!0}),e);var Lt={};mt(Lt,{Adaptive:()=>Me,AdaptiveGroup:()=>Ye,AdaptiveProvider:()=>Re,AdaptiveText:()=>Fe,SentientPersonaScript:()=>Ve,buildAgentFeed:()=>nt,defineAgentContent:()=>tt,detectSegment:()=>ce.deriveSessionSegment,getAgentContent:()=>ue,getWeights:()=>Y,renderAgentJsonLd:()=>it,renderAgentJsonLdBody:()=>de,renderAgentMarkdown:()=>rt,subscribeWeights:()=>q,updateWeights:()=>Q,useAdaptive:()=>Qe,useAdaptiveApiBaseUrl:()=>Oe,useAdaptiveGoal:()=>Ke,useAdaptiveTokens:()=>ze,useAssignment:()=>$,useInitialAssignments:()=>ne,useLayoutOrder:()=>Ee,useSentient:()=>_});module.exports=yt(Lt);var w=require("react"),N=require("@sentientui/core");var he=new Map,X=new Map;function q(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 Q(e,t){he.set(e,t);let n=X.get(e);if(n)for(let o of n)try{o(t)}catch(i){}}function Y(e){var t;return(t=he.get(e))!=null?t:null}var St={on:!1,listeners:new Set};function we(){if(typeof window=="undefined")return St;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function ae(){return we().on}function be(e){let t=we().listeners;return t.add(e),()=>{t.delete(e)}}function Ae(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(),destroy:()=>e.destroy()}}var xe="sentient:overrides-changed";function Z(){var e;return typeof window=="undefined"?0:(e=window.__sentient_overrides_version)!=null?e:0}function K(e){return typeof window=="undefined"?()=>{}:(window.addEventListener(xe,e),()=>window.removeEventListener(xe,e))}function ke(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}var ht={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function B(){if(typeof window=="undefined")return ht;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(){B().version+=1;for(let e of B().listeners)e()}function ee(e){return B().components.set(e.id,e),z(),()=>{B().components.delete(e.id),z()}}function te(e){return B().slots.set(e.id,e),z(),()=>{B().slots.delete(e.id),z()}}function _e(e){B().sections=[...e],z()}var Ie=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 Ce="https://api.sentient-ui.com/v1",I=(0,w.createContext)({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialPersona:null,apiBaseUrl:Ce});function Re(e){var S,u;let[t,n]=(0,w.useState)(null),[o]=(0,w.useState)(()=>{var d;return(d=e.sessionSegment)!=null?d:wt()}),[i,f]=(0,w.useState)(ae());(0,w.useEffect)(()=>be(()=>f(ae())),[]),(0,w.useEffect)(()=>{if(e.consent===!1&&!e.preConsentBehavior){n(a=>(a==null||a.destroy(),null));return}let d={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,l=null;return e.enableGraph?import("@sentientui/core/graph").then(({init:a})=>{g||(l=a(J(E({},d),{graph:!0})),n(l))}):(l=(0,N.init)(d),n(l)),()=>{g=!0,l==null||l.destroy()}},[e.consent]),(0,w.useEffect)(()=>{if(!t)return;let d=!1,g=async()=>{if(d)return;let a;try{a=await t.fetchWeights()}catch(b){return}if(!d)for(let b of a){let m={componentId:b.componentId,updatedAt:b.updatedAt,variants:b.variants.map(A=>{var v;return{variantId:A.variantId,pulls:A.pulls,avgReward:(v=A.avgReward)!=null?v:0}})};Q(b.componentId,m)}};g();let l=setInterval(()=>{g()},6e4);return()=>{d=!0,clearInterval(l)}},[t]);let s=(S=e.ssrFallback)!=null?S:"first",r=(u=e.apiBaseUrl)!=null?u:Ce;(0,w.useEffect)(()=>{var d;typeof process!="undefined"&&((d=process.env)==null?void 0:d.NODE_ENV)==="production"||ke({apiKey:e.apiKey,apiBaseUrl:r,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,r]),(0,w.useEffect)(()=>{e.initialLayoutOrder&&e.initialLayoutOrder.length>0&&_e(e.initialLayoutOrder)},[e.initialLayoutOrder]);let p=(0,w.useMemo)(()=>t&&i?Ae(t):t,[t,i]),c=(0,w.useMemo)(()=>{var d,g,l,a;return{client:p,apiKey:e.apiKey,initialAssignments:(d=e.initialAssignments)!=null?d:{},sessionSegment:o,ssrFallback:s,onAssignment:e.onAssignment,initialLayoutOrder:(g=e.initialLayoutOrder)!=null?g:null,initialSlots:(l=e.initialSlots)!=null?l:{},initialPersona:(a=e.initialPersona)!=null?a:null,apiBaseUrl:r}},[p,e.apiKey,e.initialAssignments,o,s,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialPersona,r]);return(0,Ie.jsx)(I.Provider,{value:c,children:e.children})}function _(){return(0,w.useContext)(I).client}function P(){return(0,w.useContext)(I).apiKey}function ne(){return(0,w.useContext)(I).initialAssignments}function ie(){return(0,w.useContext)(I).sessionSegment}function Ge(){return(0,w.useContext)(I).ssrFallback}function re(){return(0,w.useContext)(I).onAssignment}function Ee(){let e=(0,w.useContext)(I).initialLayoutOrder,t=(0,w.useSyncExternalStore)(K,()=>{var n;return typeof window=="undefined"?null:(n=window.__sentient_layout_override)!=null?n:null},()=>null);return t!=null?t:e}function Le(){return(0,w.useContext)(I).initialSlots}function Oe(){return(0,w.useContext)(I).apiBaseUrl}var x=require("react"),De=require("@sentientui/core");var O=require("react");function bt(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 f=i.indexOf(":");if(f!==-1&&i.slice(0,f)===e)return i.slice(f+1)}}catch(o){}return null}function Pe(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 $(e,t,n,o){let i=ne(),f=Ge(),s=_(),r=ie(),p=re(),c=(0,O.useRef)(null);(0,O.useSyncExternalStore)(K,Z,()=>0);let S=bt(e),u=S&&t.includes(S)?S:null,d=(0,O.useRef)(null);u&&d.current!==u&&(d.current=u,console.info(`[sentient] override active: ${e} -> ${u}`));let g=(()=>{var v,h;if(u)return{variantId:u,content:null,isLoading:!1};if(!s){let y=i[e];return y&&t.includes(y)?{variantId:y,content:null,isLoading:!1}:f==="first"&&t.length>0?{variantId:t[0],content:null,isLoading:!1}:{variantId:null,content:null,isLoading:!0}}let m=s.getAssignment(e,r);if(m&&(t.includes(m.variantId)||m.content))return{variantId:m.variantId,content:(v=m.content)!=null?v:null,isLoading:!1};let A=Y(e);if(A){let y=Pe(A,t);if(y)return{variantId:y,content:null,isLoading:!1}}return{variantId:(h=t[0])!=null?h:null,content:null,isLoading:!1}})(),[l,a]=(0,O.useState)(g),b=m=>{p&&c.current!==m&&(c.current=m,p(e,m))};return(0,O.useEffect)(()=>{var A;if(u||!s)return;let m=s.getAssignment(e,r);if(m&&(t.includes(m.variantId)||m.content)){a({variantId:m.variantId,content:(A=m.content)!=null?A:null,isLoading:!1}),b(m.variantId);return}a(v=>{var h;return v.variantId?v:{variantId:(h=t[0])!=null?h:null,content:null,isLoading:!1}})},[u,s,e,r]),(0,O.useEffect)(()=>{if(u||!s)return;let m=s.getAssignment(e,r);if(m&&t.includes(m.variantId))return;let A=!1;return s.assign(e,t,n,o).then(v=>{var h;A||v&&(!t.includes(v.variantId)&&!v.content||(a({variantId:v.variantId,content:(h=v.content)!=null?h:null,isLoading:!1}),b(v.variantId)))}),()=>{A=!0}},[u,s,e,r]),(0,O.useEffect)(()=>{if(!u&&s)return q(e,m=>{var h;let A=s.getAssignment(e,r);if(A&&(t.includes(A.variantId)||A.content)){a({variantId:A.variantId,content:(h=A.content)!=null?h:null,isLoading:!1});return}let v=Pe(m,t);v&&a({variantId:v,content:null,isLoading:!1})})},[u,s,e,r]),u?{variantId:u,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 U(e){return typeof e=="string"?e:e.type}var At=3e4;function xt(e,t){try{let n=`_snt_pv_${e}_${t}`;return sessionStorage.getItem(n)?!1:(sessionStorage.setItem(n,"1"),!0)}catch(n){return!0}}function kt(e){if(!(e instanceof Element))return!1;let t=e.tagName.toLowerCase();return t==="a"||t==="button"?!0:e.getAttribute("role")==="button"}function Te(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(kt(o))return!0;o=o.parentElement}return!1}function M(e,t,n){if(t.type==="weighted_composite"){let r=new Set,p=[];return t.steps.forEach(({goal:c,name:S,weight:u},d)=>{let g=()=>{r.has(d)||(r.add(d),n.fireStep(S,u,d))};if(c.type==="click"){let l=a=>{let b=a.target;b instanceof Element&&Te(b,e,c.selector)&&g()};e.addEventListener("click",l),p.push(()=>e.removeEventListener("click",l));return}if(c.type==="form_submit"){let l=a=>{a.target instanceof HTMLFormElement&&e.contains(a.target)&&g()};e.addEventListener("submit",l),p.push(()=>e.removeEventListener("submit",l));return}if(c.type==="scroll_depth"){let l=Math.max(0,Math.min(1,c.threshold)),a=new IntersectionObserver(b=>{for(let m of b)if(m.intersectionRatio>=l){g(),a.disconnect();break}},{threshold:[l]});a.observe(e),p.push(()=>a.disconnect())}}),()=>{for(let c of p)c()}}let o=t.type==="composite"?t.all:[t],i=new Set(o.map((r,p)=>p)),f=r=>{i.delete(r),i.size===0&&n.fireGoal()},s=[];return o.forEach((r,p)=>{if(r.type==="click"){let c=S=>{let u=S.target;u instanceof Element&&Te(u,e,r.selector)&&(t.type==="composite"?f(p):n.fireGoal())};e.addEventListener("click",c),s.push(()=>e.removeEventListener("click",c));return}if(r.type==="form_submit"){let c=S=>{S.target instanceof HTMLFormElement&&e.contains(S.target)&&(t.type==="composite"?f(p):n.fireGoal())};e.addEventListener("submit",c),s.push(()=>e.removeEventListener("submit",c));return}if(r.type==="scroll_depth"){let c=Math.max(0,Math.min(1,r.threshold)),S=new IntersectionObserver(u=>{for(let d of u)if(d.intersectionRatio>=c){t.type==="composite"?f(p):n.fireGoal(),S.disconnect();break}},{threshold:[c]});S.observe(e),s.push(()=>S.disconnect());return}}),()=>{for(let r of s)r()}}function W(e,t,n,o,i){var r;let f=(r=i==null?void 0:i.innerHTML)!=null?r:"",s=f!==""&&xt(n,o);e.track({projectId:t,componentId:n,variantId:o,eventType:"variant_assigned",payload:s?{previewHtml:f.slice(0,At)}:{}})}var We=require("react/jsx-runtime");function _t(e){var A;let t=_(),n=P(),o=(0,x.useMemo)(()=>Object.keys(e.variants),[e.variants]),{variantId:i,content:f,isOverride:s}=$(e.id,o,e.agentData,e.agentDataByVariant),r=(0,x.useRef)(null),[p,c]=(0,x.useState)(!1);(0,x.useEffect)(()=>{c(!0)},[]);let S=(0,x.useRef)(!1),u=(0,x.useRef)(new Set),d=(0,x.useRef)(null),g=typeof e.goal=="string"?e.goal:JSON.stringify(e.goal),l=(0,x.useMemo)(()=>D(e.goal),[g]),a=typeof e.goal=="string"?e.goal:l.type;if((0,x.useEffect)(()=>ee({id:e.id,variantIds:o,goal:a}),[e.id,o,a]),(0,x.useEffect)(()=>{var h,y;s||!t||!i||!n||d.current===i||!((y=(h=r.current)==null?void 0:h.innerHTML)!=null&&y)||(d.current=i,W(t,n,e.id,i,r.current))},[t,i,n,e.id,p,f,s]),(0,x.useEffect)(()=>{S.current=!1,u.current=new Set},[i,l]),(0,x.useEffect)(()=>{if(s||!t||!i)return;let v=r.current;if(!v)return;let h=null,y=0,R=()=>{y=Date.now(),h=setTimeout(()=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"cursor_signal",payload:{hoverDuration:Date.now()-y}}),h=null},800)},C=()=>{h!==null&&(clearTimeout(h),h=null)};return v.addEventListener("mouseenter",R),v.addEventListener("mouseleave",C),()=>{v.removeEventListener("mouseenter",R),v.removeEventListener("mouseleave",C),h!==null&&clearTimeout(h)}},[t,i,n,e.id,s]),(0,x.useEffect)(()=>{if(s||!t||!i)return;let v=r.current;if(!v)return;let h=Date.now();return(0,De.attachMicroSignalDetectors)((y,R={})=>{var fe,ge,pe;t.track({projectId:n,componentId:e.id,variantId:i,eventType:"micro_signal",payload:E({signalType:y},R)});let C=(fe=e.microSignalGoals)==null?void 0:fe[y];if(!C||u.current.has(y))return;u.current.add(y);let ot=typeof C=="string"?C:C.name,st=typeof C=="string"?1:(ge=C.weight)!=null?ge:1,at=typeof C=="string"?0:(pe=C.stepIndex)!=null?pe:0;t.goal(ot,E({signalType:y},R),st,at)},v,h)},[t,i,n,e.id,e.microSignalGoals,s]),(0,x.useEffect)(()=>{if(s||!t||!i)return;let v=r.current;if(v)return M(v,l,{fireGoal:()=>{S.current||(S.current=!0,t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:a,payload:{reward:1}}),t.goal(a,{componentId:e.id,variantId:i},1,0))},fireStep:(h,y,R)=>{t.track({projectId:n,componentId:e.id,variantId:i,eventType:"goal_achieved",goalType:h,payload:{reward:y}}),t.goal(h,{},y,R)}})},[t,i,n,e.id,l,a,s]),e.clientOnly&&(!p||!t)||!i)return null;let b=(A=e.variants[i])!=null?A:null,m=b===null?f:null;return L()&&b===null&&m===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:b!=null?b:m})}var Me=(0,x.memo)(_t,(e,t)=>{if(e.id!==t.id||JSON.stringify(e.goal)!==JSON.stringify(t.goal)||e.microSignalGoals!==t.microSignalGoals)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)});var F=require("react");var Be=require("react/jsx-runtime");function Fe({id:e,default:t,component:n="span",className:o}){let i=_(),f=P(),s=re(),r=ie(),p=(0,F.useRef)(null),[c,S]=(0,F.useState)(()=>{var g,l;return(l=(g=i==null?void 0:i.getAssignment(e,r))==null?void 0:g.content)!=null?l:null}),[u,d]=(0,F.useState)(()=>{var g,l;return(l=(g=i==null?void 0:i.getAssignment(e,r))==null?void 0:g.variantId)!=null?l:null});return(0,F.useEffect)(()=>{var l;if(!i||((l=i.getAssignment(e,r))==null?void 0:l.content)!==void 0)return;let g=!1;return i.assign(e).then(a=>{if(!g){if(!a){L()&&console.warn(`[sentient] <AdaptiveText id="${e}"> assignment failed \u2014 showing default text.`);return}d(a.variantId),a.content&&S(a.content)}}),()=>{g=!0}},[i,e,r]),(0,F.useEffect)(()=>{!i||!u||!f||p.current!==u&&(p.current=u,i.track({projectId:f,componentId:e,variantId:u,eventType:"variant_assigned",payload:{}}),s==null||s(e,u))},[i,u,f,e,s]),(0,Be.jsx)(n,{className:o,children:c!=null?c:t})}var je=require("react");function Ke(e){let t=_();return(0,je.useCallback)((n,o)=>{t==null||t.componentGoal(e,n,o)},[t,e])}var $e=require("@sentientui/core"),Ue=require("@sentientui/policy"),He=require("react/jsx-runtime");function Ne(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",'+Ne(e.persona.persona)+');d.setAttribute("data-sentient-confidence",'+Ne((0,Ue.confidenceBand)(e.persona.confidence))+");}catch(e){}})();":(0,$e.renderPrePaintScript)(e.apiKey)}function Ve(e){return(0,He.jsx)("script",{"data-sentient-persona-script":"",dangerouslySetInnerHTML:{__html:Ct(e)}})}var T=require("react"),Je=require("@sentientui/policy");var V=require("react"),j=require("@sentientui/core"),Rt=require("@sentientui/policy");function oe(e,t){var S;(0,V.useSyncExternalStore)(K,Z,()=>0);let n=_(),o=Le(),[,i]=(0,V.useReducer)(u=>u+1,0),f=typeof window!="undefined"?(S=window.__sentient_slot_overrides)==null?void 0:S[e]:void 0,s=f===void 0?o[e]:void 0,r=f===void 0&&s===void 0&&n?n.getSlotResult(e):null,p=(n==null?void 0:n.isLocal)===!0&&f===void 0&&s===void 0&&r===null;if((0,V.useEffect)(()=>{if(!p||!n)return;let u=!1;return n.decide({slots:[t]}).then(d=>{!u&&d&&i()}),()=>{u=!0}},[n,e,p]),f!==void 0)return{result:f,arm:(0,j.armOfResult)(f),source:"override"};if(s!==void 0)return{result:s,arm:(0,j.armOfResult)(s),source:"preloaded"};if(r!==null)return{result:r,arm:(0,j.armOfResult)(r),source:"client"};let c=(0,j.baselineResultFor)(t);return{result:c,arm:(0,j.armOfResult)(c),source:"baseline"}}var le=new Set;function Gt(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/"/g,'\\"')}function ze(e,t,n){let o=_(),i=P(),f=(0,T.useMemo)(()=>({id:e,dims:t}),[e]),{result:s,arm:r}=oe(e,f),p=(0,T.useMemo)(()=>typeof s=="string"?{}:s,[r]);if(L()&&!le.has(e)){let d=(0,Je.validateSlotDecl)({id:e,dims:Object.fromEntries(Object.entries(t).map(([l,a])=>[l,[...a]]))}),g=Object.values(t).reduce((l,a)=>l*a.length,1);d.ok?g>4&&(le.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.`)):(le.add(e),console.warn(`[sentient] useAdaptiveTokens("${e}"): invalid declaration \u2014 ${d.reason}. Serving baseline.`))}let c=(n==null?void 0:n.goal)===void 0?null:typeof n.goal=="string"?n.goal:JSON.stringify(n.goal);(0,T.useEffect)(()=>te({id:e,dims:t}),[e]);let S=(0,T.useRef)(null);(0,T.useEffect)(()=>{!o||S.current===r||(S.current=r,W(o,i,e,r,null))},[o,i,e,r]),(0,T.useEffect)(()=>{if(!o||!(n!=null&&n.goal))return;let d=document.querySelector(`[data-sentient-slot="${Gt(e)}"]`);if(!d){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 g=U(n.goal),l=!1;return M(d,D(n.goal),{fireGoal:()=>{l||(l=!0,o.componentGoal(e,g))},fireStep:(a,b)=>{o.componentGoal(e,a,{reward:b})}})},[o,e,c,r]);let u=(0,T.useMemo)(()=>{let d={"data-sentient-slot":e};for(let[g,l]of Object.entries(p))d[`data-${g}`]=l;return d},[e,p]);return{tokens:p,props:u}}var k=require("react"),qe=require("@sentientui/core");var Xe=new Set;function Qe(e,t){var h;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,k.useMemo)(()=>Object.keys(t.variants),[e]),{variantId:f,isOverride:s}=$(e,i),r=(h=f!=null?f:i[0])!=null?h:"",p=t.variants[r],[c,S]=(0,k.useState)(null),u=(0,k.useRef)(null),d=(0,k.useCallback)(y=>{u.current=y,S(y)},[]),g=typeof t.goal=="string"?t.goal:JSON.stringify(t.goal),l=(0,k.useMemo)(()=>D(t.goal),[g]),a=U(t.goal);(0,k.useEffect)(()=>ee({id:e,variantIds:i,goal:a}),[e,i,a]);let b=(0,k.useRef)(null);(0,k.useEffect)(()=>{s||!n||!r||!c||b.current!==r&&(b.current=r,W(n,o,e,r,c))},[n,o,e,r,c,s]);let m=(0,k.useRef)(!1);(0,k.useEffect)(()=>{m.current=!1},[r,g]),(0,k.useEffect)(()=>{if(!s&&!(!n||!r||!c))return M(c,l,{fireGoal:()=>{m.current||(m.current=!0,n.track({projectId:o,componentId:e,variantId:r,eventType:"goal_achieved",goalType:a,payload:{reward:1}}),n.goal(a,{componentId:e,variantId:r},1,0))},fireStep:(y,R,C)=>{n.track({projectId:o,componentId:e,variantId:r,eventType:"goal_achieved",goalType:y,payload:{reward:R}}),n.goal(y,{},R,C)}})},[n,c,r,o,e,l,a,s]),(0,k.useEffect)(()=>{if(s||!n||!r||!c)return;let y=Date.now();return(0,qe.attachMicroSignalDetectors)((R,C={})=>{n.track({projectId:o,componentId:e,variantId:r,eventType:"micro_signal",payload:E({signalType:R},C)})},c,y)},[n,c,r,o,e,s]),(0,k.useEffect)(()=>{if(!L()||!n)return;let y=setTimeout(()=>{!u.current&&!Xe.has(e)&&(Xe.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(y)},[n,e]);let A=(0,k.useCallback)((y,R)=>{s||n==null||n.componentGoal(e,y!=null?y:a,R)},[n,e,a,s]),v=(0,k.useMemo)(()=>({ref:d,"data-sentient-id":e,"data-sentient-variant":r}),[d,e,r]);return{variant:r,value:p,bind:v,fireGoal:A}}var G=require("react");var Ze=require("react/jsx-runtime"),se=new Set;function Ye(e){var l;let t=_(),n=P(),o=(0,G.useRef)(null),i=(0,G.useMemo)(()=>Object.keys(e.arrangements),[e.id]),f=(0,G.useMemo)(()=>E({id:e.id,arms:i},e.baseline!==void 0?{baseline:e.baseline}:{}),[e.id,i,e.baseline]),{arm:s}=oe(e.id,f);L()&&e.baseline!==void 0&&e.baseline!==i[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 ("${i[0]}"). The first arrangement should usually be the page's real incumbent (the holdout sees it).`));let r=G.Children.toArray(e.children).filter(G.isValidElement),p=new Map;for(let a of r)p.set(String((l=a.key)!=null?l:"").replace(/^\.\$/,""),a);let c=e.arrangements[s],S=c!==void 0&&c.length===r.length&&c.every(a=>p.has(a));L()&&c!==void 0&&!S&&!se.has(e.id+":keys")&&(se.add(e.id+":keys"),console.warn(`[sentient] <AdaptiveGroup id="${e.id}">: arrangement "${s}" [${c.join(", ")}] does not match the children's keys \u2014 rendering declaration order (fail-safe).`));let u=S?c.map(a=>p.get(a)):r;(0,G.useEffect)(()=>te({id:e.id,arms:Object.keys(e.arrangements)}),[e.id]);let d=(0,G.useRef)(null);(0,G.useEffect)(()=>{!t||d.current===s||(d.current=s,W(t,n,e.id,s,o.current))},[t,n,e.id,s]);let g=e.goal===void 0?null:typeof e.goal=="string"?e.goal:JSON.stringify(e.goal);return(0,G.useEffect)(()=>{if(!t||e.goal===void 0)return;let a=o.current;if(!a)return;let b=U(e.goal),m=!1;return M(a,D(e.goal),{fireGoal:()=>{m||(m=!0,t.componentGoal(e.id,b))},fireStep:(A,v)=>{t.componentGoal(e.id,A,{reward:v})}})},[t,e.id,g,s]),(0,Ze.jsx)("div",{ref:o,"data-sentient-id":e.id,"data-sentient-variant":s,children:u})}var ce=require("@sentientui/core");var Et=["page","blocks","layoutOrder"],et=new Map;function tt(e,t){et.set(e,t)}function ue(e){return et.get(e)}function nt(e){var i,f;let t=(f=(i=e.content)!=null?i:ue(e.page))!=null?f:{},n={};for(let[s,r]of Object.entries(t))Et.includes(s)||(n[s]=r);let o=J(E({},n),{page:e.page,blocks:e.blocks});return e.layoutOrder&&(o.layoutOrder=e.layoutOrder),o}function it(e){return`<script type="application/ld+json">${de(e)}</script>`}function de(e){return JSON.stringify(E({"@context":"https://schema.org","@type":"WebPage"},e)).replace(/</g,"\\u003c")}function rt(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
4
|
`}0&&(module.exports={Adaptive,AdaptiveGroup,AdaptiveProvider,AdaptiveText,SentientPersonaScript,buildAgentFeed,defineAgentContent,detectSegment,getAgentContent,getWeights,renderAgentJsonLd,renderAgentJsonLdBody,renderAgentMarkdown,subscribeWeights,updateWeights,useAdaptive,useAdaptiveApiBaseUrl,useAdaptiveGoal,useAdaptiveTokens,useAssignment,useInitialAssignments,useLayoutOrder,useSentient});
|
|
5
5
|
//# sourceMappingURL=index.js.map
|