@sentientui/core 0.23.0 → 0.25.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.
Files changed (51) hide show
  1. package/dist/chunk-2NVSFI4V.mjs +2 -0
  2. package/dist/chunk-2NVSFI4V.mjs.map +1 -0
  3. package/dist/chunk-RL5B6M4G.mjs +2 -0
  4. package/dist/chunk-RL5B6M4G.mjs.map +1 -0
  5. package/dist/chunk-WKXD7KI3.mjs +2 -0
  6. package/dist/chunk-WKXD7KI3.mjs.map +1 -0
  7. package/dist/chunk-Z6ILOYBD.mjs +2 -0
  8. package/dist/chunk-Z6ILOYBD.mjs.map +1 -0
  9. package/dist/{index-BbrtAtrY.d.ts → index-BjVvN7cU.d.ts} +1 -1
  10. package/dist/{index-CXxvWxCB.d.cts → index-Cd0gMdJv.d.cts} +1 -1
  11. package/dist/index-engagement.d.cts +1 -1
  12. package/dist/index-engagement.d.ts +1 -1
  13. package/dist/index-engagement.js +1 -1
  14. package/dist/index-engagement.js.map +1 -1
  15. package/dist/index-engagement.mjs +1 -1
  16. package/dist/index-engagement.mjs.map +1 -1
  17. package/dist/index-graph.d.cts +3 -3
  18. package/dist/index-graph.d.ts +3 -3
  19. package/dist/index-graph.js +1 -1
  20. package/dist/index-graph.js.map +1 -1
  21. package/dist/index-graph.mjs +1 -1
  22. package/dist/index-local.d.cts +2 -2
  23. package/dist/index-local.d.ts +2 -2
  24. package/dist/index-server.d.cts +10 -2
  25. package/dist/index-server.d.ts +10 -2
  26. package/dist/index-server.js +1 -1
  27. package/dist/index-server.js.map +1 -1
  28. package/dist/index-server.mjs +1 -1
  29. package/dist/index-server.mjs.map +1 -1
  30. package/dist/index-topics.d.cts +16 -1
  31. package/dist/index-topics.d.ts +16 -1
  32. package/dist/index-topics.js +1 -1
  33. package/dist/index-topics.js.map +1 -1
  34. package/dist/index-topics.mjs +1 -1
  35. package/dist/index-topics.mjs.map +1 -1
  36. package/dist/index.d.cts +2 -2
  37. package/dist/index.d.ts +2 -2
  38. package/dist/index.js +1 -1
  39. package/dist/index.js.map +1 -1
  40. package/dist/index.mjs +1 -1
  41. package/dist/{session-meta-BVvq5RBB.d.cts → session-meta-C-bMqVeq.d.cts} +32 -1
  42. package/dist/{session-meta-BVvq5RBB.d.ts → session-meta-C-bMqVeq.d.ts} +32 -1
  43. package/package.json +2 -2
  44. package/dist/chunk-2RH7I6AP.mjs +0 -2
  45. package/dist/chunk-2RH7I6AP.mjs.map +0 -1
  46. package/dist/chunk-EWP6FTHE.mjs +0 -2
  47. package/dist/chunk-EWP6FTHE.mjs.map +0 -1
  48. package/dist/chunk-KIP52DUJ.mjs +0 -2
  49. package/dist/chunk-KIP52DUJ.mjs.map +0 -1
  50. package/dist/chunk-QNEYUJJJ.mjs +0 -2
  51. package/dist/chunk-QNEYUJJJ.mjs.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{A as R,B as S,a as r,b as s,c as t,d as u,e as v,f as w,g as x,h as y,i as z,j as A,k as B,l as C,m as D,n as E,o as F,p as G,q as H,r as I,s as J,t as K,u as L,v as M,w as N,x as O,y as P,z as Q}from"./chunk-2RH7I6AP.mjs";import{b as a,c as b,d as c,e as d,f as e,g as f,h as g,i as h,j as i,k as j,l as k,m as l,n as m,p as n,q as o,r as p,s as q}from"./chunk-QNEYUJJJ.mjs";import"./chunk-TMCGHANO.mjs";export{f as AGENT_INTENTS,y as BLOCK_ALIGNS,D as BLOCK_EMPHASES,G as BLOCK_FITS,x as BLOCK_GAPS,H as BLOCK_GRID_COLUMNS,I as BLOCK_HEADING_LEVELS,z as BLOCK_JUSTIFIES,F as BLOCK_RATIOS,A as BLOCK_SIZES,E as BLOCK_TEXT_ALIGNS,C as BLOCK_TONES,B as BLOCK_WEIGHTS,a as LEGACY_SESSION_COOKIE_NAME,w as LOCAL_MODE_BANNER,M as MAX_BLOCK_ARMS,L as MAX_BLOCK_CHILDREN,K as MAX_BLOCK_DEPTH,J as MAX_BLOCK_NODES,N as MAX_BLOCK_TEXT_LEN,v as PROD_KEYLESS_ERROR,r as SNAPSHOT_STORAGE_KEY_PREFIX,P as _registerConsentUpgradeInit,g as agentIntent,c as agentUaList,q as armOfResult,O as attachMicroSignalDetectors,o as baselineResultFor,p as baselineSlots,h as classifiedAgents,m as deriveSessionSegment,i as detectDeviceClass,l as detectTimeOfDay,j as detectTrafficSource,R as grantConsent,S as init,Q as isDoNotTrackEnabled,e as matchedAgentToken,s as readSnapshot,k as referrerDomainFromReferer,u as renderPrePaintScript,b as sessionCookieName,n as toWireSlot,d as uaTokenMatch,t as writeSnapshot};
1
+ import{A as T,B as U,a as t,b as u,c as v,d as w,e as x,f as y,g as z,h as A,i as B,j as C,k as D,l as E,m as F,n as G,o as H,p as I,q as J,r as K,s as L,t as M,u as N,v as O,w as P,x as Q,y as R,z as S}from"./chunk-RL5B6M4G.mjs";import{b as a,c as b,d as c,e as d,f as e,g as f,h as g,i as h,j as i,k as j,l as k,m as l,n as m,o as n,p as o,r as p,s as q,t as r,u as s}from"./chunk-2NVSFI4V.mjs";import"./chunk-TMCGHANO.mjs";export{f as AGENT_INTENTS,A as BLOCK_ALIGNS,F as BLOCK_EMPHASES,I as BLOCK_FITS,z as BLOCK_GAPS,J as BLOCK_GRID_COLUMNS,K as BLOCK_HEADING_LEVELS,B as BLOCK_JUSTIFIES,H as BLOCK_RATIOS,C as BLOCK_SIZES,G as BLOCK_TEXT_ALIGNS,E as BLOCK_TONES,D as BLOCK_WEIGHTS,l as CLICK_ID_KEYS,a as LEGACY_SESSION_COOKIE_NAME,y as LOCAL_MODE_BANNER,O as MAX_BLOCK_ARMS,N as MAX_BLOCK_CHILDREN,M as MAX_BLOCK_DEPTH,L as MAX_BLOCK_NODES,P as MAX_BLOCK_TEXT_LEN,x as PROD_KEYLESS_ERROR,t as SNAPSHOT_STORAGE_KEY_PREFIX,R as _registerConsentUpgradeInit,g as agentIntent,c as agentUaList,s as armOfResult,Q as attachMicroSignalDetectors,q as baselineResultFor,r as baselineSlots,h as classifiedAgents,o as deriveSessionSegment,i as detectDeviceClass,n as detectTimeOfDay,j as detectTrafficSource,m as extractTrackedParams,T as grantConsent,U as init,S as isDoNotTrackEnabled,e as matchedAgentToken,u as readSnapshot,k as referrerDomainFromReferer,w as renderPrePaintScript,b as sessionCookieName,p as toWireSlot,d as uaTokenMatch,v as writeSnapshot};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -59,11 +59,41 @@ declare function classifiedAgents(): Record<AgentIntent, string[]>;
59
59
  declare function detectDeviceClass(userAgent: string): string;
60
60
  declare function detectTrafficSource(referrer: string, appOrigin?: string): string;
61
61
  declare function referrerDomainFromReferer(referrer: string): string | null;
62
+ /**
63
+ * Ad-platform click-ID query params worth keeping. An ALLOWLIST, unlike the
64
+ * `utm_` prefix match: unknown query keys here are unbounded-cardinality junk
65
+ * (session tokens, cache busters) that would bloat the sessions table, so only
66
+ * the IDs the major ad platforms actually append survive.
67
+ *
68
+ * gclid / gbraid / wbraid — Google Ads auto-tagging (search, YouTube, Display;
69
+ * gbraid/wbraid are the iOS-14 privacy variants)
70
+ * fbclid — Meta (Facebook + Instagram). Appended to EVERY outbound Meta
71
+ * click, paid and organic alike — it identifies the platform, never spend.
72
+ * ttclid — TikTok Ads
73
+ * msclkid — Microsoft Ads (Bing)
74
+ * twclid — X/Twitter Ads
75
+ * li_fat_id — LinkedIn Ads
76
+ */
77
+ declare const CLICK_ID_KEYS: readonly string[];
78
+ /**
79
+ * Splits a URL query into the attribution params the session upsert carries:
80
+ * every `utm_`-prefixed key, plus allowlisted ad click IDs (CLICK_ID_KEYS).
81
+ * Accepts a raw search string ("?a=b" or "a=b"), a URLSearchParams, or a
82
+ * Next.js `searchParams` object (whose values may be string arrays — the
83
+ * first occurrence wins, matching URLSearchParams iteration order).
84
+ * Node-safe: no DOM APIs.
85
+ */
86
+ declare function extractTrackedParams(search: string | URLSearchParams | Record<string, string | string[] | undefined>): {
87
+ utmParams: Record<string, string>;
88
+ clickIds: Record<string, string>;
89
+ };
62
90
  declare function detectTimeOfDay(d: Date): string;
63
91
  type SessionUpsertPayload = {
64
92
  sessionId: string;
65
93
  ephemeral: boolean;
66
94
  utmParams: Record<string, string>;
95
+ /** Allowlisted ad-platform click IDs from the landing URL (CLICK_ID_KEYS). */
96
+ clickIds: Record<string, string>;
67
97
  deviceClass: string;
68
98
  trafficSource: string;
69
99
  referrerDomain: string | null;
@@ -91,9 +121,10 @@ declare function buildSessionUpsertPayload(sessionId: string, opts?: {
91
121
  referer?: string;
92
122
  appOrigin?: string;
93
123
  utmParams?: Record<string, string>;
124
+ clickIds?: Record<string, string>;
94
125
  now?: Date;
95
126
  /** `navigator.webdriver` value from the browser, when available. */
96
127
  webdriver?: boolean;
97
128
  }): SessionUpsertPayload;
98
129
 
99
- export { AGENT_INTENTS as A, type SessionUpsertPayload as S, type AgentIntent as a, type SlotDeclInput as b, agentIntent as c, agentUaList as d, armOfResult as e, baselineResultFor as f, baselineSlots as g, buildSessionUpsertPayload as h, classifiedAgents as i, deriveSessionSegment as j, detectDeviceClass as k, detectTimeOfDay as l, detectTrafficSource as m, matchedAgentToken as n, referrerDomainFromReferer as r, toWireSlot as t, uaTokenMatch as u };
130
+ export { AGENT_INTENTS as A, CLICK_ID_KEYS as C, type SessionUpsertPayload as S, type AgentIntent as a, type SlotDeclInput as b, agentIntent as c, agentUaList as d, armOfResult as e, baselineResultFor as f, baselineSlots as g, buildSessionUpsertPayload as h, classifiedAgents as i, deriveSessionSegment as j, detectDeviceClass as k, detectTimeOfDay as l, detectTrafficSource as m, extractTrackedParams as n, matchedAgentToken as o, referrerDomainFromReferer as r, toWireSlot as t, uaTokenMatch as u };
@@ -59,11 +59,41 @@ declare function classifiedAgents(): Record<AgentIntent, string[]>;
59
59
  declare function detectDeviceClass(userAgent: string): string;
60
60
  declare function detectTrafficSource(referrer: string, appOrigin?: string): string;
61
61
  declare function referrerDomainFromReferer(referrer: string): string | null;
62
+ /**
63
+ * Ad-platform click-ID query params worth keeping. An ALLOWLIST, unlike the
64
+ * `utm_` prefix match: unknown query keys here are unbounded-cardinality junk
65
+ * (session tokens, cache busters) that would bloat the sessions table, so only
66
+ * the IDs the major ad platforms actually append survive.
67
+ *
68
+ * gclid / gbraid / wbraid — Google Ads auto-tagging (search, YouTube, Display;
69
+ * gbraid/wbraid are the iOS-14 privacy variants)
70
+ * fbclid — Meta (Facebook + Instagram). Appended to EVERY outbound Meta
71
+ * click, paid and organic alike — it identifies the platform, never spend.
72
+ * ttclid — TikTok Ads
73
+ * msclkid — Microsoft Ads (Bing)
74
+ * twclid — X/Twitter Ads
75
+ * li_fat_id — LinkedIn Ads
76
+ */
77
+ declare const CLICK_ID_KEYS: readonly string[];
78
+ /**
79
+ * Splits a URL query into the attribution params the session upsert carries:
80
+ * every `utm_`-prefixed key, plus allowlisted ad click IDs (CLICK_ID_KEYS).
81
+ * Accepts a raw search string ("?a=b" or "a=b"), a URLSearchParams, or a
82
+ * Next.js `searchParams` object (whose values may be string arrays — the
83
+ * first occurrence wins, matching URLSearchParams iteration order).
84
+ * Node-safe: no DOM APIs.
85
+ */
86
+ declare function extractTrackedParams(search: string | URLSearchParams | Record<string, string | string[] | undefined>): {
87
+ utmParams: Record<string, string>;
88
+ clickIds: Record<string, string>;
89
+ };
62
90
  declare function detectTimeOfDay(d: Date): string;
63
91
  type SessionUpsertPayload = {
64
92
  sessionId: string;
65
93
  ephemeral: boolean;
66
94
  utmParams: Record<string, string>;
95
+ /** Allowlisted ad-platform click IDs from the landing URL (CLICK_ID_KEYS). */
96
+ clickIds: Record<string, string>;
67
97
  deviceClass: string;
68
98
  trafficSource: string;
69
99
  referrerDomain: string | null;
@@ -91,9 +121,10 @@ declare function buildSessionUpsertPayload(sessionId: string, opts?: {
91
121
  referer?: string;
92
122
  appOrigin?: string;
93
123
  utmParams?: Record<string, string>;
124
+ clickIds?: Record<string, string>;
94
125
  now?: Date;
95
126
  /** `navigator.webdriver` value from the browser, when available. */
96
127
  webdriver?: boolean;
97
128
  }): SessionUpsertPayload;
98
129
 
99
- export { AGENT_INTENTS as A, type SessionUpsertPayload as S, type AgentIntent as a, type SlotDeclInput as b, agentIntent as c, agentUaList as d, armOfResult as e, baselineResultFor as f, baselineSlots as g, buildSessionUpsertPayload as h, classifiedAgents as i, deriveSessionSegment as j, detectDeviceClass as k, detectTimeOfDay as l, detectTrafficSource as m, matchedAgentToken as n, referrerDomainFromReferer as r, toWireSlot as t, uaTokenMatch as u };
130
+ export { AGENT_INTENTS as A, CLICK_ID_KEYS as C, type SessionUpsertPayload as S, type AgentIntent as a, type SlotDeclInput as b, agentIntent as c, agentUaList as d, armOfResult as e, baselineResultFor as f, baselineSlots as g, buildSessionUpsertPayload as h, classifiedAgents as i, deriveSessionSegment as j, detectDeviceClass as k, detectTimeOfDay as l, detectTrafficSource as m, extractTrackedParams as n, matchedAgentToken as o, referrerDomainFromReferer as r, toWireSlot as t, uaTokenMatch as u };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentientui/core",
3
- "version": "0.23.0",
3
+ "version": "0.25.0",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "sideEffects": false,
@@ -71,7 +71,7 @@
71
71
  "llms.txt"
72
72
  ],
73
73
  "dependencies": {
74
- "@sentientui/policy": "0.8.0"
74
+ "@sentientui/policy": "0.9.0"
75
75
  },
76
76
  "devDependencies": {
77
77
  "@types/node": "^22.10.2",
@@ -1,2 +0,0 @@
1
- import{a as fe,c as Ee,e as Ie,j as _e,k as Ce,l as Ae,m as Te,p as Oe,q as me,s as Re}from"./chunk-QNEYUJJJ.mjs";import{a as _,b as se}from"./chunk-TMCGHANO.mjs";function ye(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(e){}try{if(typeof crypto!="undefined"&&typeof crypto.getRandomValues=="function"){let e=new Uint8Array(16);crypto.getRandomValues(e),e[6]=e[6]&15|64,e[8]=e[8]&63|128;let n="";for(let s=0;s<16;s++)n+=e[s].toString(16).padStart(2,"0"),(s===3||s===5||s===7||s===9)&&(n+="-");return n}}catch(e){}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let n=Math.random()*16|0;return(e==="x"?n:n&3|8).toString(16)})}var ot="_snt_uid",st=365,he="_snt_uid";function rt(){return ye()}function $e(e){try{let n=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return n?decodeURIComponent(n[1]):null}catch(n){return null}}function it(e,n,s){try{document.cookie=`${e}=${encodeURIComponent(n)}; max-age=${s}; SameSite=strict; path=/`}catch(d){}}function Be(e){try{return localStorage.getItem(e)}catch(n){return null}}function We(e,n){try{return localStorage.setItem(e,n),!0}catch(s){return!1}}function je(e){try{return sessionStorage.getItem(e)}catch(n){return null}}function at(e,n){try{return sessionStorage.setItem(e,n),!0}catch(s){return!1}}function lt(e){try{sessionStorage.removeItem(e)}catch(n){}}function ct(e){try{return document.cookie=`${e}_probe=1; max-age=1; SameSite=strict; path=/`,document.cookie.indexOf(`${e}_probe=1`)!==-1}catch(n){return!1}}function dt(e){try{localStorage.removeItem(e)}catch(n){}}function ut(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(n){}}var pt={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function Se(e){var x,O,R,E,G,F,C;if(typeof window=="undefined")return pt;let n=fe(e==null?void 0:e.apiKey),s=(x=e==null?void 0:e.cookieName)!=null?x:Ee(e==null?void 0:e.apiKey),d=`${he}${n}`,f=`${he}_tomb${n}`,l=((O=e==null?void 0:e.cookieTTLDays)!=null?O:st)*24*60*60,i=v=>v&&v.length>0?v:null,u=()=>{var v,L;return n&&!(e!=null&&e.cookieName)&&Be(f)===null?(L=(v=i($e(ot)))!=null?v:i(Be(he)))!=null?L:i(je(he)):null},r=(C=(F=(G=(E=(R=i($e(s)))!=null?R:i(Be(d)))!=null?E:i(je(d)))!=null?G:u())!=null?F:i(e==null?void 0:e.ssrSessionId))!=null?C:rt();it(s,r,l);let t=We(d,r),o=ct(s),y=t?!1:at(d,r),h=!t&&!o&&!y;return{getSessionId:()=>r,isEphemeral:()=>h,destroy:()=>{r=null,ut(s),dt(d),lt(d),n&&!(e!=null&&e.cookieName)&&We(f,"1")}}}function X(e){return Math.min(6e4,1e3*2**Math.min(e,6))}function re(e){if(e.ok===!0)return"delivered";let{status:n}=e;return typeof n!="number"?"retry":n>=200&&n<300?"delivered":n>=400&&n<500&&n!==429?"dropped":"retry"}function ve(e,n){try{let s=localStorage.getItem(e);if(!s)return[];let d=JSON.parse(s);return Array.isArray(d)?(localStorage.removeItem(e),d.slice(-n)):[]}catch(s){return[]}}function Y(e,n,s){try{let d=(()=>{try{let a=localStorage.getItem(s);if(!a)return[];let l=JSON.parse(a);return Array.isArray(l)?l:[]}catch(a){return[]}})(),f=new Map;for(let a of d)f.set(a.id,a);for(let a of e)f.set(a.id,a);localStorage.setItem(s,JSON.stringify([...f.values()].slice(-n)))}catch(d){}}function we(e,n){try{let s=localStorage.getItem(n);if(!s)return;let d=JSON.parse(s);if(!Array.isArray(d))return;let f=new Set(e),a=d.filter(l=>!f.has(l.id));if(a.length===d.length)return;a.length===0?localStorage.removeItem(n):localStorage.setItem(n,JSON.stringify(a))}catch(s){}}var gt=500,ft=56*1024;function Le(e){return`_snt_retry_${e.slice(0,12)}`}var mt={push:()=>{},flush:()=>{},destroy:()=>{}};function He(e){var q,M,te;if(typeof window=="undefined")return mt;let n=(q=e.flushIntervalMs)!=null?q:5e3,s=(M=e.maxBatchSize)!=null?M:20,d=(te=e.maxRetrySize)!=null?te:100,f=e.ingestUrl,a=e.apiKey,l=Le(a),i=[],u=new Set,r=[],t=g=>{for(let k of g)o.delete(k),!u.has(k)&&(u.add(k),r.push(k));for(;r.length>gt;){let k=r.shift();k&&u.delete(k)}we(g,l)},o=new Set,y=()=>{for(;i.length>d;){let g=i.shift();g&&o.delete(g.id)}},h=g=>{u.has(g.id)||o.has(g.id)||(o.add(g.id),i.push(g),y())},x=g=>{for(let k of g)u.has(k.id)||(o.add(k.id),i.push(k));y()},O=ve(l,d);for(let g of O)h(g);let R=0,E=0,G=(g,k=!0)=>{if(g.length===0)return;let j=JSON.stringify(g),Z=g.map(Q=>Q.id),$;try{$=fetch(f,{method:"POST",keepalive:!0,body:j,headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`}})}catch(Q){Y(g,d,l),x(g),E++,R=Date.now()+X(E);return}let ae=Q=>{if(re(Q)!=="retry"){if(!Q.ok&&k){let ne=g.filter(z=>z.eventType!=="pageview");if(ne.length>0&&ne.length<g.length){t(g.filter(z=>z.eventType==="pageview").map(z=>z.id)),G(ne,!1);return}}t(Z),E=0,R=0;return}Y(g,d,l),x(g),E++,R=Date.now()+X(E)};$ instanceof Promise?$.then(ae).catch(()=>{Y(g,d,l),x(g),E++,R=Date.now()+X(E)}):ae($)},F=typeof TextEncoder!="undefined"?new TextEncoder:null,C=g=>F?F.encode(g).length:g.length,v=g=>{let k=[],j=2;for(let Z of g){let $=C(JSON.stringify(Z))+1;if(k.length>0&&j+$>ft||k.length>=s)break;k.push(Z),j+=$}return k},L=()=>{try{if(Date.now()<R)return;for(;i.length>0&&!(Date.now()<R);){let g=i.filter(j=>!u.has(j.id));if(i.length=0,g.length===0)break;let k=v(g);if(k.length===0)break;k.length<g.length&&i.push(...g.slice(k.length)),G(k)}}catch(g){}},m=!0,T=null;T=setInterval(()=>{m&&L()},n);let P=()=>{document.visibilityState==="hidden"&&L()},W=()=>{L()};return document.addEventListener("visibilitychange",P),window.addEventListener("pagehide",W),{push(g){h(g),i.length>=s&&L()},flush:L,destroy(){m=!1,T!==null&&(clearInterval(T),T=null),document.removeEventListener("visibilitychange",P),window.removeEventListener("pagehide",W),L()}}}var yt=200;function De(e){return`_snt_goal_retry_${e.slice(0,12)}`}var ht={send:()=>{},flush:()=>{},destroy:()=>{}};function Qe(e){var C,v,L;if(typeof window=="undefined")return ht;let n=(C=e.flushIntervalMs)!=null?C:5e3,s=(v=e.maxRetrySize)!=null?v:100,d=(L=e.maxPerFlush)!=null?L:5,f=De(e.apiKey),a=[],l=new Set,i=new Set,u=[],r=0,t=0,o=!1,y=m=>{for(l.delete(m.id),i.has(m.id)||(i.add(m.id),u.push(m.id));u.length>yt;){let T=u.shift();T&&i.delete(T)}we([m.id],f)},h=m=>{Y([m],s,f),!i.has(m.id)&&!l.has(m.id)&&(l.add(m.id),a.push(m)),Date.now()>=r&&(t++,r=Date.now()+X(t))},x=m=>{let T;try{T=fetch(e.url,{method:"POST",keepalive:!0,body:m.body,headers:e.headers})}catch(W){h(m);return}let P=W=>{var M;let q=re(W);if(q==="retry"){h(m);return}q==="dropped"&&((M=e.onDrop)==null||M.call(e,m,W.status)),y(m),t=0,r=0};T instanceof Promise?T.then(P).catch(()=>h(m)):P(T)},O=()=>{try{if(o||Date.now()<r)return;let m=0;for(;a.length>0&&m<d&&!(Date.now()<r);){let T=a.shift();l.delete(T.id),!i.has(T.id)&&(m++,x(T))}}catch(m){}},R=ve(f,s);for(let m of R)l.has(m.id)||(l.add(m.id),a.push(m));R.length>0&&Y(R,s,f);let E=setInterval(O,n),G=()=>{document.visibilityState==="hidden"&&O()},F=()=>O();return document.addEventListener("visibilitychange",G),window.addEventListener("pagehide",F),{send(m){if(!o&&!(i.has(m.id)||l.has(m.id))){if(Date.now()<r){Y([m],s,f),l.add(m.id),a.push(m);return}x(m)}},flush:O,destroy(){clearInterval(E),document.removeEventListener("visibilitychange",G),window.removeEventListener("pagehide",F),O(),o=!0}}}var St=1800*1e3;function ke(e,n){return`${encodeURIComponent(e)}:${encodeURIComponent(n)}`}function ze(e=St,n){let s=new Map,d=`_snt_asgn${fe(n)}_`,f=(r,t)=>`${d}${encodeURIComponent(r)}:${encodeURIComponent(t)}`,a=r=>{let t=r.slice(d.length),o=t.indexOf(":");if(o<0)return null;try{return{componentId:decodeURIComponent(t.slice(0,o)),segment:decodeURIComponent(t.slice(o+1))}}catch(y){return null}},l=()=>{try{let r=[];for(let t=0;t<localStorage.length;t++){let o=localStorage.key(t);o!=null&&o.startsWith(d)&&r.push(o)}return r}catch(r){return[]}},i=r=>r.assignedAt+(r.ttlMs&&r.ttlMs>0?r.ttlMs:e)<Date.now();return typeof window!="undefined"&&(()=>{for(let r of l())try{let t=localStorage.getItem(r);if(!t)continue;let o=JSON.parse(t);if(i(o)){localStorage.removeItem(r);continue}let y=a(r);if(!y)continue;s.set(ke(y.componentId,y.segment),o)}catch(t){}})(),{get(r,t){let o=s.get(ke(r,t));return o?i(o)?(s.delete(ke(r,t)),null):o:null},set(r,t,o){let y=ke(r,t);s.set(y,o);try{localStorage.setItem(f(r,t),JSON.stringify(o))}catch(h){}},clear(){s.clear();for(let r of l())try{localStorage.removeItem(r)}catch(t){}}}}var ie="_snt_snap:",vt=["low","medium","high"];function de(e){try{let n=localStorage.getItem(ie+e);if(!n)return null;let s=JSON.parse(n);return!s||typeof s!="object"||s.v!==1||typeof s.persona!="string"||typeof s.band!="string"||!vt.includes(s.band)||typeof s.slots!="object"||s.slots===null||Array.isArray(s.slots)||!(s.layoutOrder===null||Array.isArray(s.layoutOrder))||typeof s.savedAt!="number"||!(s.slotConfig===void 0||typeof s.slotConfig=="object"&&s.slotConfig!==null&&!Array.isArray(s.slotConfig))?null:s}catch(n){return null}}function ue(e,n){try{localStorage.setItem(ie+e,JSON.stringify(n))}catch(s){}}function wt(e){return"(function(){try{var r=localStorage.getItem("+JSON.stringify(ie+e).replace(/</g,"\\u003c")+');if(!r)return;var s=JSON.parse(r);if(!s||s.v!==1||typeof s.persona!=="string"||typeof s.band!=="string")return;var d=document.documentElement;if(d.hasAttribute("data-sentient-persona"))return;d.setAttribute("data-sentient-persona",s.persona);d.setAttribute("data-sentient-confidence",s.band);}catch(e){}})();'}import{confidenceBand as Ye}from"@sentientui/policy";import{confidenceBand as Pe}from"@sentientui/policy";var Me="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",Ve="[sentient] Local mode \u2014 decisions are simulated on-device and nothing is sent over the network. Add an API key to learn from real traffic.",Je=!1,be=!1;function kt(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(n){return}}function Xe(e){var r;let n=Se({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),s=(r=n.getSessionId())!=null?r:"local",d=kt(),f=import("@sentientui/core/local").then(t=>{let o=t;return o.LOCAL_ENGINE_AVAILABLE?(Je||(Je=!0,console.info(Ve)),o):(be||(be=!0,console.error(Me)),null)}).catch(()=>(be||(be=!0,console.error(Me)),null)),a=null,l={low:.15,medium:.5,high:.85},i=(()=>{var o;if(e.initialPersona)return _({},e.initialPersona);let t=de(e.apiKey||"local");return t?{persona:t.persona,confidence:(o=l[t.band])!=null?o:.15}:null})();function u(t){let o=document.documentElement;o.dataset.sentientPersona===void 0&&(o.dataset.sentientPersona=t.persona,o.dataset.sentientConfidence=Pe(t.confidence))}return{isLocal:!0,async decide(t){var h,x,O;let o=await f;if(!o)return null;let y=o.createLocalEngine({sessionId:s,forcedPersona:d}).decide(t);return a=se(_({},y),{layoutOrder:(x=(h=y.layoutOrder)!=null?h:a==null?void 0:a.layoutOrder)!=null?x:null,slots:_(_({},(O=a==null?void 0:a.slots)!=null?O:{}),y.slots)}),ue(e.apiKey||"local",{v:1,persona:a.persona,band:Pe(a.confidence),slots:a.slots,layoutOrder:a.layoutOrder,savedAt:Date.now()}),u(y),y},getSlotResult(t){var o,y,h;return(h=(y=a==null?void 0:a.slots[t])!=null?y:(o=e.initialSlots)==null?void 0:o[t])!=null?h:null},getPersona(){let t=a!=null?a:i;return t?{persona:t.persona,confidence:t.confidence,band:Pe(t.confidence)}:null},async assign(t,o){var x;let y=await f;return!y||!o||o.length===0?o!=null&&o[0]?{variantId:o[0],assignmentTtlMs:0}:null:{variantId:(x=y.createLocalEngine({sessionId:s,forcedPersona:d}).decide({components:[{id:t,variantIds:o}]}).assignments[t])!=null?x:o[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>n.destroy()}}var zt=["none","sm","md","lg"],Jt=["start","center","end","stretch"],Vt=["start","center","end","between"],Xt=["sm","md","lg"],Yt=["normal","medium","bold"],qt=["default","muted","accent"],Zt=["primary","secondary","ghost"],en=["left","center","right"],tn=["auto","square","landscape","wide"],nn=["cover","contain"],on=[2,3,4],sn=[2,3,4],rn=64,an=5,ln=12,cn=4,dn=500;function bt(e,n,s,d){let f=[];{let i=!1,u=[],r=()=>{if(i)return;let t=Date.now();for(u.push(t);u.length>0&&t-u[0]>500;)u.shift();u.length>=3&&(i=!0,e("rage_click"))};n.addEventListener("click",r),f.push(()=>n.removeEventListener("click",r))}{let a=!1,l=i=>{if(a||!(i.target instanceof Node)||!n.contains(i.target)&&n!==i.target)return;a=!0;let u=typeof window!="undefined"?window.getSelection():null,r=u?u.toString().length:0;e("text_copy",{selectionLength:r})};document.addEventListener("copy",l),f.push(()=>document.removeEventListener("copy",l))}{let a=!1,l=!1,i=null,u=()=>{i!==null&&(clearTimeout(i),i=null)},r=()=>{a||!l||(u(),i=setTimeout(()=>{!a&&l&&(a=!0,e("scroll_hesitation"))},3e3))},t=()=>{u(),r()},o=h=>{for(let x of h)l=x.intersectionRatio>.3,l?r():u()},y=new IntersectionObserver(o,{threshold:[.3]});y.observe(n),window.addEventListener("scroll",t,{passive:!0}),f.push(()=>{y.disconnect(),window.removeEventListener("scroll",t),u()})}if((d==null?void 0:d.tabLoss)!==!1){let a=!1,l=s!=null?s:Date.now(),i=()=>{if(a||document.visibilityState!=="hidden")return;let u=Date.now()-l;u<15e3&&(a=!0,e("tab_loss",{timeOnPage:u}))};document.addEventListener("visibilitychange",i),f.push(()=>document.removeEventListener("visibilitychange",i))}return()=>{for(let a of f)a()}}var qe="https://api.sentient-ui.com/v1/events",N=new Map,Ze=null;function Bn(e,n){let s=N.get(e);s&&s.upgrade&&(s.reinit=n)}function xt(e){return"value"in e||"currency"in e||"externalId"in e||"metadata"in e||"weight"in e||"stepIndex"in e}var Et=3;function Ke(){return ye()}function xe(){var e;if(typeof window!="undefined")return((e=window.location)==null?void 0:e.pathname)||void 0}function It(){let e=new WeakMap,n=new Map,s=!1,d=(i,u,r)=>{let t=i.get(u);return r===null?t?!0:(i.set(u,new Set),!1):t?t.has(r)?!0:(t.add(r),!1):(i.set(u,new Set([r])),!1)},f=typeof window!="undefined"&&"event"in window,a=()=>{if(!f)return;let i=window.event;return typeof Event=="function"&&i instanceof Event?i:void 0},l=()=>{if(f){Promise.resolve().then(()=>{s=!1,n.clear()});return}let i=!1,u=()=>{i||(i=!0,s=!1,n.clear())};if(setTimeout(u,0),typeof MessageChannel=="function"){let r=new MessageChannel;r.port1.onmessage=()=>{r.port1.close(),r.port2.close(),u()},r.port2.postMessage(0)}};return{firedBefore(i,u){let r=a();if(r){let o=e.get(r);return o||(o=new Map,e.set(r,o)),d(o,i,u)}let t=d(n,i,u);return!t&&!s&&(s=!0,l()),t}}}var et=new Set;function _t(e,n,s){let d=typeof window=="undefined"?null:window.history;if(!d)return()=>{};let f=!1,a,l=()=>{if(f)return;let r=xe();!r||r===a||(a=r,e.track({projectId:n,componentId:"__page__",eventType:"pageview",payload:{}}),s(`${n}:${r}`))},i=[];for(let r of["pushState","replaceState"]){let t=d[r],o=function(...y){let h=t.apply(this,y);return l(),h};d[r]=o,i.push([r,t,o])}window.addEventListener("popstate",l);let u=xe();return u&&et.has(`${n}:${u}`)?a=u:l(),()=>{if(!f){f=!0,window.removeEventListener("popstate",l);for(let[r,t,o]of i)d[r]===o&&(d[r]=t)}}}var pe={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,assign:()=>Promise.resolve(null),decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}};function Ct(){try{let e={},n=new URLSearchParams(window.location.search);for(let[s,d]of n)s.startsWith("utm_")&&(e[s]=d);return e}catch(e){return{}}}function tt(e){return e.replace(/\/events\/?$/,"")}function nt(){return typeof navigator!="undefined"&&navigator.globalPrivacyControl===!0?!0:[typeof navigator!="undefined"?navigator.doNotTrack:void 0,typeof window!="undefined"?window.doNotTrack:void 0,typeof navigator!="undefined"?navigator.msDoNotTrack:void 0].some(n=>n==="1"||n==="yes")}function Ln(e){var u;if(typeof window=="undefined")return;let n=e!=null?e:Ze;if(!n){console.warn("[sentient] grantConsent() called before init()");return}let s=N.get(n);if(!s){console.warn("[sentient] grantConsent() called before init()");return}let{config:d,upgrade:f,reinit:a}=s;if(!f){s.upgradeBlockedReason&&console.warn(s.upgradeBlockedReason);return}if(d.respectDoNotTrack!==!1&&nt())return;let l=(a!=null?a:Tt)(se(_({},d),{consent:!0}));f(l);let i=(u=N.get(n))==null?void 0:u.dispose;N.set(n,{config:se(_({},d),{consent:!0}),upgrade:null,dispose:i})}function At(e){var r;let n=e.preConsentBehavior==="statistical_winner",s=tt((r=e.ingestUrl)!=null?r:qe),d={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},f=new Map,a=new Map,l={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),assign(t,o,y){if(!n)return Promise.resolve(null);let h=f.get(t);return h?Promise.resolve(h):Ne(a,t,async()=>{try{let x=new URLSearchParams({componentId:t});for(let G of o!=null?o:[])x.append("variantIds[]",G);let O=await fetch(`${s}/winner?${x.toString()}`,{headers:d});if(!O.ok)return o!=null&&o[0]?{variantId:o[0],assignmentTtlMs:0}:null;let E={variantId:(await O.json()).variantId,assignmentTtlMs:0};return f.set(t,E),E}catch(x){return o!=null&&o[0]?{variantId:o[0],assignmentTtlMs:0}:null}})},decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}},i={track:t=>l.track(t),goal:((t,o,y,h)=>l.goal(t,o,y,h)),componentGoal:(t,o,y)=>l.componentGoal(t,o,y),identify:t=>l.identify(t),getAssignment:(t,o)=>l.getAssignment(t,o),assign:(t,o,y,h)=>l.assign(t,o,y,h),decide:t=>l.decide(t),getSlotResult:t=>l.getSlotResult(t),getPersona:()=>l.getPersona(),fetchWeights:()=>l.fetchWeights(),getGraph:()=>l.getGraph(),dispose:()=>l.dispose(),destroy:()=>l.destroy()};function u(t){l=t}return{proxy:i,setInner:u}}function Ne(e,n,s){let d=e.get(n);if(d)return d;let f=(async()=>{try{return await s()}finally{e.delete(n)}})();return e.set(n,f),f}function Tt(e){var k,j,Z,$,ae,Q,ne,z,Ge;if(typeof window=="undefined")return pe;Ze=e.apiKey||"local";let n=N.get(e.apiKey||"local");if(n!=null&&n.dispose)try{n.dispose()}catch(c){}let s=e.respectDoNotTrack!==!1&&nt(),d=e.consent===!1||s,f=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!f&&e.localMode!==!1)return N.set(e.apiKey||"local",{config:e,upgrade:null,upgradeBlockedReason:"[sentient] grantConsent(): this client is keyless/local \u2014 there is no hosted client to upgrade to. Configure a pk_ API key to enable tracking."}),d?pe:Xe(e);if(d){if(!e.apiKey||!e.apiKey.startsWith("pk_"))return e.preConsentBehavior==="statistical_winner"&&console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),N.set(e.apiKey||"local",{config:e,upgrade:null,upgradeBlockedReason:"[sentient] grantConsent(): the client was initialized with an invalid apiKey (expected a pk_ public key) \u2014 consent cannot enable tracking."}),pe;let{proxy:c,setInner:p}=At(e);return N.set(e.apiKey,{config:e,upgrade:s?null:p}),c}if(!e.apiKey||!e.apiKey.startsWith("pk_"))return console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),pe;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),pe;let a=(k=e.ingestUrl)!=null?k:qe,l=Date.now(),i=Se({ssrSessionId:e.ssrSessionId,apiKey:e.apiKey}),u=ze(void 0,e.apiKey),r=He({ingestUrl:a,apiKey:e.apiKey}),t=tt(a),o={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},y=new Set,h=Qe({url:`${t}/goals`,apiKey:e.apiKey,headers:o,onDrop:(c,p)=>{if(!e.debug){if(y.has(p))return;y.add(p)}console.warn(`[sentient] goal dropped (HTTP ${p}) \u2014 this will not be retried. `+(p===400?"The session was not found: call init() and let the session upsert complete before firing goals.":p===401||p===403?"Check the API key and that this origin is on the project allowlist.":"See the response status for the cause."),c)}}),x=_e((j=navigator.userAgent)!=null?j:""),O=window.location.origin,R=Ce((Z=document.referrer)!=null?Z:"",O),E=($=e.sessionSegment)!=null?$:`${x}:${R}`,G=new Map,F=new Map,C=new Map,v=null,L=c=>{for(let p of c)C.has(p.id)||C.set(p.id,me(p))};if(e.initialSlots)for(let[c,p]of Object.entries(e.initialSlots))C.set(c,p);let m=de(e.apiKey);if(m)for(let[c,p]of Object.entries(m.slots))C.has(c)||C.set(c,p);let T={low:.15,medium:.5,high:.85};if(e.initialPersona)v=_({},e.initialPersona);else{let c=document.documentElement.dataset;c.sentientPersona?v={persona:c.sentientPersona,confidence:(Q=T[(ae=c.sentientConfidence)!=null?ae:"low"])!=null?Q:.15}:m&&(v={persona:m.persona,confidence:(ne=T[m.band])!=null?ne:.15})}if(e.initialAssignments)for(let[c,p]of Object.entries(e.initialAssignments))u.set(c,E,{variantId:p,assignedAt:Date.now(),segment:E,confidence:1});let P=Promise.resolve(),W=i.getSessionId();if(W){let c=Ae((z=document.referrer)!=null?z:""),p=_(_(_({sessionId:W,deviceClass:x,trafficSource:R,referrerDomain:c,utmParams:Ct(),timeOfDay:Te(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:i.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||Ie((Ge=navigator.userAgent)!=null?Ge:"")},e.userId?{userId:e.userId}:{}),e.persona?{persona:e.persona}:{}),e.country?{country:e.country}:{}),S=async()=>{for(let I=0;;I++){try{let A=await fetch(`${t}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(p),headers:o});if(A.status===402){console.warn("[SentientUI] Session limit exceeded for this project. The bandit will stop learning until the limit resets. Upgrade at sentient-ui.com/pricing");return}if(A.ok||re(A)==="dropped")return}catch(A){}if(I>=Et){console.warn("[SentientUI] Could not register the session after retries. Conversions in this visit may not be recorded.");return}await new Promise(A=>setTimeout(A,X(I+1)))}};try{P=S()}catch(I){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:r});let q=It(),M=null,te=!1,g={goal(c,p={},S=1,I=0){var le,ce,oe,b,H,ge,B;let A=i.getSessionId();if(!A)return;let w=xt(p)?p:{metadata:p},K=[c,(le=w.externalId)!=null?le:"",(ce=w.stepIndex)!=null?ce:I,(oe=w.weight)!=null?oe:S].join("\0"),U=w.value!==void 0?`${w.value}\0${(b=w.currency)!=null?b:""}`:null;if(q.firedBefore(K,U)){e.debug&&console.log(`[sentient] goal("${c}") already recorded for this action \u2014 not sent twice`);return}let D=Ke(),J={sessionId:A,name:c,metadata:(H=w.metadata)!=null?H:{},weight:(ge=w.weight)!=null?ge:S,stepIndex:(B=w.stepIndex)!=null?B:I,goalId:D,value:w.value,currency:w.currency,externalId:w.externalId};e.debug&&console.log("[sentient] goal",J);let ee={id:D,body:JSON.stringify(J)};P.then(()=>h.send(ee))},componentGoal(c,p,S){var D,J,ee;let I=i.getSessionId();if(!I)return;let A=u.get(c,E),w=A?null:(D=C.get(c))!=null?D:null;if(!A&&w===null){e.debug&&console.warn(`[sentient] componentGoal("${c}"): no assignment or slot decision yet \u2014 render its <Adaptive>/adaptive hook or call assign()/decide() before recording a goal.`);return}let K=A?A.variantId:Re(w),U={id:Ke(),sessionId:I,projectId:e.apiKey,componentId:c,variantId:K,eventType:"goal_achieved",goalType:p,payload:_({reward:(J=S==null?void 0:S.reward)!=null?J:1,goalValue:S==null?void 0:S.value,currency:S==null?void 0:S.currency},(ee=S==null?void 0:S.metadata)!=null?ee:{}),timestamp:Date.now(),timeInSession:Date.now()-l,path:xe()};e.debug&&console.log("[sentient] componentGoal",U),P.then(()=>r.push(U))},identify(c){let p=i.getSessionId();p&&P.then(()=>{fetch(`${t}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:p,userId:c,ephemeral:i.isEphemeral()}),headers:o}).catch(()=>{})})},track(c){let p=i.getSessionId();if(!p)return;let S=se(_({path:xe()},c),{id:Ke(),sessionId:p,timestamp:Date.now(),timeInSession:Date.now()-l});e.debug&&console.log("[sentient] track",S),P.then(()=>r.push(S))},getAssignment(c,p){return u.get(c,p)},async assign(c,p,S,I){let A=i.getSessionId();if(!A)return null;let w=u.get(c,E);if(w&&(p!=null&&p.length||w.content!==void 0)){let K=w.ttlMs&&w.ttlMs>0?Math.max(0,w.assignedAt+w.ttlMs-Date.now()):0;return{variantId:w.variantId,assignmentTtlMs:K,content:w.content}}return Ne(G,c,async()=>{await P;try{let K={sessionId:A,componentId:c,variantIds:p};I!==void 0?K.agentDataByVariant=I:S!==void 0&&(K.agentData=S);let U=await fetch(`${t}/assign`,{method:"POST",body:JSON.stringify(K),headers:o});if(!U.ok)return null;let D=await U.json();return u.set(c,E,_({variantId:D.variantId,assignedAt:Date.now(),segment:E,confidence:1,content:D.content},D.assignmentTtlMs&&D.assignmentTtlMs>0?{ttlMs:D.assignmentTtlMs}:{})),D}catch(K){return null}})},async decide(c){var w,K;let p=i.getSessionId();if(!p)return null;let S=(w=c.slots)!=null?w:[],I={sessionId:p};c.sections&&c.sections.length>0&&(I.sections=c.sections.map(U=>({id:U}))),I.components=(K=c.components)!=null?K:[],S.length>0&&(I.slots=S.map(Oe)),c.slotsFrom==="registry"&&(I.slotsFrom="registry"),c.v&&(I.v=c.v),e.persona&&(I.persona=e.persona);let A=JSON.stringify(I);return Ne(F,A,async()=>{var U,D,J,ee,le,ce;await P;try{let oe=await fetch(`${t}/decide`,{method:"POST",body:A,headers:o});if(!oe.ok)return L(S),null;let b=await oe.json(),H={};for(let B of S){let V=(U=b.slots)==null?void 0:U[B.id];if(V!==void 0){H[B.id]=V,C.set(B.id,V);continue}let Ue=C.get(B.id);if(Ue!==void 0)H[B.id]=Ue;else{let Fe=me(B);H[B.id]=Fe,C.set(B.id,Fe)}}if(b.slots)for(let[B,V]of Object.entries(b.slots))B in H||(H[B]=V,C.set(B,V));let ge=v!=null&&v.persona!=="unknown";b.persona&&!(b.persona==="unknown"&&ge)?v={persona:b.persona,confidence:(D=b.confidence)!=null?D:0}:v||(v={persona:"unknown",confidence:0});for(let[B,V]of Object.entries((J=b.assignments)!=null?J:{}))u.set(B,E,{variantId:V,assignedAt:Date.now(),segment:E,confidence:1});return ue(e.apiKey,_(_({v:1,persona:v.persona,band:Ye(v.confidence),slots:Object.fromEntries(C),layoutOrder:(ee=b.layoutOrder)!=null?ee:null,savedAt:Date.now()},b.slotConfig?{slotConfig:b.slotConfig}:{}),b.palette?{palette:b.palette}:{})),_(_(_(_({layoutOrder:(le=b.layoutOrder)!=null?le:null,assignments:(ce=b.assignments)!=null?ce:{},slots:H,persona:v.persona,confidence:v.confidence},b.slotConfig?{slotConfig:b.slotConfig}:{}),b.goals?{goals:b.goals}:{}),b.sectionMap?{sectionMap:b.sectionMap}:{}),b.palette?{palette:b.palette}:{})}catch(oe){return L(S),null}})},getSlotResult(c){var p;return(p=C.get(c))!=null?p:null},getPersona(){return v?{persona:v.persona,confidence:v.confidence,band:Ye(v.confidence)}:null},async fetchWeights(){var c;try{let p=await fetch(`${t}/weights`,{headers:o});return p.ok?(c=(await p.json()).components)!=null?c:[]:[]}catch(p){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){var c;M==null||M(),te=!0,r.destroy(),h.destroy(),((c=N.get(e.apiKey))==null?void 0:c.dispose)===g.dispose&&N.delete(e.apiKey),e.debug&&console.log("[sentient] disposed")},destroy(){var c;M==null||M(),te=!0,r.destroy(),h.destroy(),i.destroy(),u.clear(),((c=N.get(e.apiKey))==null?void 0:c.dispose)===g.dispose&&N.delete(e.apiKey);try{localStorage.removeItem(ie+e.apiKey),localStorage.removeItem(Le(e.apiKey)),localStorage.removeItem(De(e.apiKey))}catch(p){}e.debug&&console.log("[sentient] destroyed")}};if(N.set(e.apiKey,{config:e,upgrade:null,dispose:g.dispose}),M=_t(g,e.apiKey,c=>{P.then(()=>{te||et.add(c)})}),e.debug){let c=window;c.__sentient&&(c.__sentient.client=g)}return g}export{ie as a,de as b,ue as c,wt as d,Me as e,Ve as f,zt as g,Jt as h,Vt as i,Xt as j,Yt as k,qt as l,Zt as m,en as n,tn as o,nn as p,on as q,sn as r,rn as s,an as t,ln as u,cn as v,dn as w,bt as x,Bn as y,nt as z,Ln as A,Tt as B};
2
- //# sourceMappingURL=chunk-2RH7I6AP.mjs.map