@sentientui/core 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-KZHVBFG7.mjs +1 -0
- package/dist/index-engagement.d.cts +35 -8
- package/dist/index-engagement.d.ts +35 -8
- package/dist/index-engagement.js +1 -1
- package/dist/index-engagement.mjs +1 -1
- package/dist/index-graph.js +1 -1
- package/dist/index-graph.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-LMHLAXPA.mjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var p=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],o=[["pricing",/\b(pricing|price|plans?|subscriptions?|per month|\/mo|tier)\b/i],["faq",/\b(faq|frequently asked|common questions?)\b/i],["comparison",/\b(compare|comparison|versus|vs\.)\b/i],["social_proof",/\b(testimonial|reviews?|trusted by|loved by|customers?|logos|rated|case stud)\b/i],["trust",/\b(security|guarantee|privacy|compliance|secure|gdpr|soc ?2|encrypt)\b/i],["features",/\b(features?|how it works|benefits?|capabilit|what you get)\b/i]],s=[["pricing",/(?:[$€£]\s?\d[\d,.]*\s*(?:\/|per\s)\s*(?:mo|month|yr|year|seat|user))|(?:\b(?:starter|basic|pro|growth|premium|enterprise)\b[^.]{0,60}[$€£]\s?\d)/i],["social_proof",/(?:★{2,})|(?:\b\d(?:\.\d)?\s*(?:out of|\/)\s*5\b)|(?:\brated\b)|(?:["“][^"”]{20,160}["”]\s*[—–-]\s*[A-Z][a-z]+)/],["trust",/\b(?:money[- ]back guarantee|refund(?:s)? within|encrypted|soc ?2|iso ?27001|gdpr[- ]compliant|cancel anytime)\b/i],["comparison",/\b(?:vs|versus)\b\.?[^.!?]{0,80}\b(?:compare|comparison|plans?|features?|alternative)\b|\bhow (?:we|it) compares?\b/i]];function a(e){var r;let t=e.querySelector("h1, h2, h3");return((r=t==null?void 0:t.textContent)!=null?r:"").slice(0,160)}function i(e){if(e.tag==="nav"||e.tag==="footer")return{type:"navigation",strength:"weak"};let t=`${e.idClass} ${e.headingText}`.toLowerCase();for(let[r,n]of o)if(n.test(t))return{type:r,strength:"strong"};for(let[r,n]of s)if(n.test(e.bodyText))return{type:r,strength:"strong"};return e.actionCount>=1&&e.textLength>0&&e.textLength<200?{type:"cta",strength:"weak"}:e.tag==="header"?{type:"hero",strength:"weak"}:/\b(hero|headline|banner)\b/i.test(t)?{type:"hero",strength:"weak"}:{type:"generic",strength:"weak"}}function c(e){var r,n;let t=((r=e.textContent)!=null?r:"").replace(/\s+/g," ").trim();return{tag:e.tagName.toLowerCase(),idClass:`${e.id} ${String((n=e.className)!=null?n:"")}`,headingText:a(e),bodyText:t.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:t.length}}function g(e){return i(c(e)).type}export{p as a,i as b,c,g as d};
|
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
type SemanticType = 'pricing' | 'hero' | 'social_proof' | 'cta' | 'features' | 'faq' | 'comparison' | 'trust' | 'navigation' | 'generic';
|
|
2
|
+
/** Canonical vocabulary — mirrors the graph_nodes semantic_type CHECK enum. */
|
|
3
|
+
declare const SEMANTIC_TYPES: readonly SemanticType[];
|
|
4
|
+
/** Environment-agnostic section features — buildable from a browser Element or
|
|
5
|
+
* a server-parsed node (node-html-parser). */
|
|
6
|
+
type SectionFeatures = {
|
|
7
|
+
tag: string;
|
|
8
|
+
idClass: string;
|
|
9
|
+
headingText: string;
|
|
10
|
+
bodyText: string;
|
|
11
|
+
actionCount: number;
|
|
12
|
+
textLength: number;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Pure classification over extracted features. `strong` = keyword or content
|
|
16
|
+
* evidence (trustable enough to auto-apply); `weak` = structural fallback
|
|
17
|
+
* (cta/hero/navigation/generic — capture-worthy but not persona evidence).
|
|
18
|
+
*/
|
|
19
|
+
declare function classifyFeatures(f: SectionFeatures): {
|
|
20
|
+
type: SemanticType;
|
|
21
|
+
strength: 'strong' | 'weak';
|
|
22
|
+
};
|
|
23
|
+
/** Feature extraction from a live DOM element (browser paths). */
|
|
24
|
+
declare function featuresFromElement(el: Element): SectionFeatures;
|
|
25
|
+
/** Classify a page section into a semantic type (never null — falls back to
|
|
26
|
+
* 'generic' so the caller can still capture attention on it). */
|
|
27
|
+
declare function classifySection(el: Element): SemanticType;
|
|
28
|
+
|
|
1
29
|
type CaptureClient = {
|
|
2
30
|
track(event: {
|
|
3
31
|
projectId: string;
|
|
@@ -19,14 +47,13 @@ type EngagementCaptureOptions = {
|
|
|
19
47
|
* keeps its per-component detectors and must not double-attach.
|
|
20
48
|
*/
|
|
21
49
|
microSignals?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Server-served section-map lookup (persona-coverage auto-classification):
|
|
52
|
+
* consulted after explicit `data-sentient-type` markup, before the local
|
|
53
|
+
* heuristic. Return null when the element has no served label.
|
|
54
|
+
*/
|
|
55
|
+
typeOf?: (el: Element) => SemanticType | null;
|
|
22
56
|
};
|
|
23
57
|
declare function startEngagementCapture(client: CaptureClient, opts: EngagementCaptureOptions): () => void;
|
|
24
58
|
|
|
25
|
-
|
|
26
|
-
/** Canonical vocabulary — mirrors the graph_nodes semantic_type CHECK enum. */
|
|
27
|
-
declare const SEMANTIC_TYPES: readonly SemanticType[];
|
|
28
|
-
/** Classify a page section into a semantic type (never null — falls back to
|
|
29
|
-
* 'generic' so the caller can still capture attention on it). */
|
|
30
|
-
declare function classifySection(el: Element): SemanticType;
|
|
31
|
-
|
|
32
|
-
export { type EngagementCaptureOptions, SEMANTIC_TYPES, type SemanticType, classifySection, startEngagementCapture };
|
|
59
|
+
export { type EngagementCaptureOptions, SEMANTIC_TYPES, type SectionFeatures, type SemanticType, classifyFeatures, classifySection, featuresFromElement, startEngagementCapture };
|
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
type SemanticType = 'pricing' | 'hero' | 'social_proof' | 'cta' | 'features' | 'faq' | 'comparison' | 'trust' | 'navigation' | 'generic';
|
|
2
|
+
/** Canonical vocabulary — mirrors the graph_nodes semantic_type CHECK enum. */
|
|
3
|
+
declare const SEMANTIC_TYPES: readonly SemanticType[];
|
|
4
|
+
/** Environment-agnostic section features — buildable from a browser Element or
|
|
5
|
+
* a server-parsed node (node-html-parser). */
|
|
6
|
+
type SectionFeatures = {
|
|
7
|
+
tag: string;
|
|
8
|
+
idClass: string;
|
|
9
|
+
headingText: string;
|
|
10
|
+
bodyText: string;
|
|
11
|
+
actionCount: number;
|
|
12
|
+
textLength: number;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Pure classification over extracted features. `strong` = keyword or content
|
|
16
|
+
* evidence (trustable enough to auto-apply); `weak` = structural fallback
|
|
17
|
+
* (cta/hero/navigation/generic — capture-worthy but not persona evidence).
|
|
18
|
+
*/
|
|
19
|
+
declare function classifyFeatures(f: SectionFeatures): {
|
|
20
|
+
type: SemanticType;
|
|
21
|
+
strength: 'strong' | 'weak';
|
|
22
|
+
};
|
|
23
|
+
/** Feature extraction from a live DOM element (browser paths). */
|
|
24
|
+
declare function featuresFromElement(el: Element): SectionFeatures;
|
|
25
|
+
/** Classify a page section into a semantic type (never null — falls back to
|
|
26
|
+
* 'generic' so the caller can still capture attention on it). */
|
|
27
|
+
declare function classifySection(el: Element): SemanticType;
|
|
28
|
+
|
|
1
29
|
type CaptureClient = {
|
|
2
30
|
track(event: {
|
|
3
31
|
projectId: string;
|
|
@@ -19,14 +47,13 @@ type EngagementCaptureOptions = {
|
|
|
19
47
|
* keeps its per-component detectors and must not double-attach.
|
|
20
48
|
*/
|
|
21
49
|
microSignals?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Server-served section-map lookup (persona-coverage auto-classification):
|
|
52
|
+
* consulted after explicit `data-sentient-type` markup, before the local
|
|
53
|
+
* heuristic. Return null when the element has no served label.
|
|
54
|
+
*/
|
|
55
|
+
typeOf?: (el: Element) => SemanticType | null;
|
|
22
56
|
};
|
|
23
57
|
declare function startEngagementCapture(client: CaptureClient, opts: EngagementCaptureOptions): () => void;
|
|
24
58
|
|
|
25
|
-
|
|
26
|
-
/** Canonical vocabulary — mirrors the graph_nodes semantic_type CHECK enum. */
|
|
27
|
-
declare const SEMANTIC_TYPES: readonly SemanticType[];
|
|
28
|
-
/** Classify a page section into a semantic type (never null — falls back to
|
|
29
|
-
* 'generic' so the caller can still capture attention on it). */
|
|
30
|
-
declare function classifySection(el: Element): SemanticType;
|
|
31
|
-
|
|
32
|
-
export { type EngagementCaptureOptions, SEMANTIC_TYPES, type SemanticType, classifySection, startEngagementCapture };
|
|
59
|
+
export { type EngagementCaptureOptions, SEMANTIC_TYPES, type SectionFeatures, type SemanticType, classifyFeatures, classifySection, featuresFromElement, startEngagementCapture };
|
package/dist/index-engagement.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var E=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames,B=Object.getOwnPropertySymbols;var F=Object.prototype.hasOwnProperty,V=Object.prototype.propertyIsEnumerable;var G=(t,e,n)=>e in t?E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,v=(t,e)=>{for(var n in e||(e={}))F.call(e,n)&&G(t,n,e[n]);if(B)for(var n of B(e))V.call(e,n)&&G(t,n,e[n]);return t};var z=(t,e)=>{for(var n in e)E(t,n,{get:e[n],enumerable:!0})},H=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let g of Q(e))!F.call(t,g)&&g!==n&&E(t,g,{get:()=>e[g],enumerable:!(i=q(e,g))||i.enumerable});return t};var X=t=>H(E({},"__esModule",{value:!0}),t);var Se={};z(Se,{SEMANTIC_TYPES:()=>x,classifyFeatures:()=>I,classifySection:()=>C,featuresFromElement:()=>A,startEngagementCapture:()=>J});module.exports=X(Se);var x=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Z=[["pricing",/\b(pricing|price|plans?|subscriptions?|per month|\/mo|tier)\b/i],["faq",/\b(faq|frequently asked|common questions?)\b/i],["comparison",/\b(compare|comparison|versus|vs\.)\b/i],["social_proof",/\b(testimonial|reviews?|trusted by|loved by|customers?|logos|rated|case stud)\b/i],["trust",/\b(security|guarantee|privacy|compliance|secure|gdpr|soc ?2|encrypt)\b/i],["features",/\b(features?|how it works|benefits?|capabilit|what you get)\b/i]],ee=[["pricing",/(?:[$€£]\s?\d[\d,.]*\s*(?:\/|per\s)\s*(?:mo|month|yr|year|seat|user))|(?:\b(?:starter|basic|pro|growth|premium|enterprise)\b[^.]{0,60}[$€£]\s?\d)/i],["social_proof",/(?:★{2,})|(?:\b\d(?:\.\d)?\s*(?:out of|\/)\s*5\b)|(?:\brated\b)|(?:["“][^"”]{20,160}["”]\s*[—–-]\s*[A-Z][a-z]+)/],["trust",/\b(?:money[- ]back guarantee|refund(?:s)? within|encrypted|soc ?2|iso ?27001|gdpr[- ]compliant|cancel anytime)\b/i],["comparison",/\b(?:vs|versus)\b\.?[^.!?]{0,80}\b(?:compare|comparison|plans?|features?|alternative)\b|\bhow (?:we|it) compares?\b/i]];function te(t){var n;let e=t.querySelector("h1, h2, h3");return((n=e==null?void 0:e.textContent)!=null?n:"").slice(0,160)}function I(t){if(t.tag==="nav"||t.tag==="footer")return{type:"navigation",strength:"weak"};let e=`${t.idClass} ${t.headingText}`.toLowerCase();for(let[n,i]of Z)if(i.test(e))return{type:n,strength:"strong"};for(let[n,i]of ee)if(i.test(t.bodyText))return{type:n,strength:"strong"};return t.actionCount>=1&&t.textLength>0&&t.textLength<200?{type:"cta",strength:"weak"}:t.tag==="header"?{type:"hero",strength:"weak"}:/\b(hero|headline|banner)\b/i.test(e)?{type:"hero",strength:"weak"}:{type:"generic",strength:"weak"}}function A(t){var n,i;let e=((n=t.textContent)!=null?n:"").replace(/\s+/g," ").trim();return{tag:t.tagName.toLowerCase(),idClass:`${t.id} ${String((i=t.className)!=null?i:"")}`,headingText:te(t),bodyText:e.slice(0,2e3),actionCount:t.querySelectorAll('a, button, [role="button"]').length,textLength:e.length}}function C(t){return I(A(t)).type}var k=require("@sentientui/policy");var me=require("@sentientui/policy");var re=require("@sentientui/policy");function T(t,e,n){var g;let i=[];{let a=!1,c=[],p=()=>{if(a)return;let f=Date.now();for(c.push(f);c.length>0&&f-c[0]>500;)c.shift();c.length>=3&&(a=!0,t("rage_click"))};e.addEventListener("click",p),i.push(()=>e.removeEventListener("click",p))}{let l=!1,u=a=>{if(l||!(a.target instanceof Node)||!e.contains(a.target)&&e!==a.target)return;l=!0;let c=typeof window!="undefined"?window.getSelection():null,p=c?c.toString().length:0;t("text_copy",{selectionLength:p})};document.addEventListener("copy",u),i.push(()=>document.removeEventListener("copy",u))}{let l=!1,u=!1,a=null,c=()=>{a!==null&&(clearTimeout(a),a=null)},p=()=>{l||!u||(c(),a=setTimeout(()=>{!l&&u&&(l=!0,t("scroll_hesitation"))},3e3))},f=()=>{c(),p()},m=b=>{for(let w of b)u=w.intersectionRatio>.3,u?p():c()};typeof process!="undefined"&&((g=process.env)==null?void 0:g.NODE_ENV)!=="production"&&(window.__lastIOCallback=m);let y=new IntersectionObserver(m,{threshold:[.3]});y.observe(e),window.addEventListener("scroll",f,{passive:!0}),i.push(()=>{y.disconnect(),window.removeEventListener("scroll",f),c()})}{let l=!1,u=n!=null?n:Date.now(),a=()=>{if(l||document.visibilityState!=="hidden")return;let c=Date.now()-u;c<15e3&&(l=!0,t("tab_loss",{timeOnPage:c}))};document.addEventListener("visibilitychange",a),i.push(()=>document.removeEventListener("visibilitychange",a))}return()=>{for(let l of i)l()}}function W(){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(e=>e==="1"||e==="yes")}var Y="section, header, footer, nav, main > div, [data-sentient-section]";function ye(t){var e;return((e=t.parentElement)==null?void 0:e.closest(Y))!=null}function he(t,e,n,i){try{fetch(`${e}/v1/section-map`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${t}`},body:JSON.stringify({pageUrl:n,sections:i})}).catch(()=>{})}catch(g){}}var _=()=>{};function J(t,e){var O,D,L,P,N,M,U,K,$;let n=(O=e.doc)!=null?O:typeof document!="undefined"?document:void 0;if(!n||typeof IntersectionObserver=="undefined"||W())return _;let i=(D=e.apiBase)!=null?D:"https://api.sentient-ui.com",g=Array.from(n.querySelectorAll(Y)).filter(o=>!ye(o));if(g.length===0)return _;let l=new Map,u=new Map,a=new Map;for(let o of g){let r=o.getAttribute("data-sentient-type"),s=r&&x.includes(r)?r:null,d=(P=s!=null?s:(L=e.typeOf)==null?void 0:L.call(e,o))!=null?P:C(o),S=`nc-${d}`;l.set(o,S),u.set(S,d),s?a.set(S,"markup"):a.has(S)||a.set(S,"auto")}let c=(K=(U=(M=(N=n.defaultView)!=null?N:typeof window!="undefined"?window:void 0)==null?void 0:M.location)==null?void 0:U.pathname)!=null?K:"/";he(e.apiKey,i,c,[...u.entries()].map(([o,r])=>{var s;return{componentId:o,semanticType:r,source:(s=a.get(o))!=null?s:"auto"}}));let p=new Map,f=o=>{let r=p.get(o);return r||(r={ms:0,scroll:0,enterAt:null,intersecting:!1},p.set(o,r)),r},m=new IntersectionObserver(o=>{for(let r of o){let s=l.get(r.target);if(!s)continue;let d=f(s);r.isIntersecting?(d.intersecting=!0,d.enterAt=Date.now(),r.intersectionRatio>d.scroll&&(d.scroll=r.intersectionRatio)):(d.intersecting=!1,d.enterAt!=null&&(d.ms+=Date.now()-d.enterAt,d.enterAt=null))}},{threshold:[0,.25,.5,.75,1]});for(let o of l.keys())m.observe(o);let y=()=>{let o=Date.now();for(let[r,s]of p)if(s.enterAt!=null&&(s.ms+=o-s.enterAt,s.enterAt=null),!(s.ms<=0)){try{t.track({projectId:e.apiKey,componentId:r,eventType:"dwell",payload:{dwell_time:Math.round(s.ms),scroll_depth:Number(s.scroll.toFixed(2))}})}catch(d){}s.ms=0}},b=()=>{if(n.hidden)y();else{let o=Date.now();for(let r of p.values())r.intersecting&&(r.enterAt=o)}},w=()=>{y();try{m.disconnect()}catch(o){}};n.addEventListener("visibilitychange",b);let h=($=n.defaultView)!=null?$:typeof window!="undefined"?window:void 0;h==null||h.addEventListener("pagehide",w);let R=[];if(e.microSignals)for(let[o,r]of l)R.push(T((s,d={})=>{try{t.track({projectId:e.apiKey,componentId:r,eventType:"micro_signal",payload:v({signalType:s},d)})}catch(S){}},o));return()=>{y(),n.removeEventListener("visibilitychange",b),h==null||h.removeEventListener("pagehide",w);for(let o of R)o();try{m.disconnect()}catch(o){}}}0&&(module.exports={SEMANTIC_TYPES,classifyFeatures,classifySection,featuresFromElement,startEngagementCapture});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as g,b as F,c as K,d as v}from"./chunk-KZHVBFG7.mjs";import{g as _,h as L}from"./chunk-CWUFS37B.mjs";import"./chunk-P5ZTJLZE.mjs";import{a as x}from"./chunk-HGGX55FR.mjs";var P="section, header, footer, nav, main > div, [data-sentient-section]";function R(s){var i;return((i=s.parentElement)==null?void 0:i.closest(P))!=null}function V(s,i,r,u){try{fetch(`${i}/v1/section-map`,{method:"POST",keepalive:!0,headers:{"content-type":"application/json",authorization:`Bearer ${s}`},body:JSON.stringify({pageUrl:r,sections:u})}).catch(()=>{})}catch(f){}}var h=()=>{};function $(s,i){var b,A,C,O,I,k,M,N,D;let r=(b=i.doc)!=null?b:typeof document!="undefined"?document:void 0;if(!r||typeof IntersectionObserver=="undefined"||L())return h;let u=(A=i.apiBase)!=null?A:"https://api.sentient-ui.com",f=Array.from(r.querySelectorAll(P)).filter(e=>!R(e));if(f.length===0)return h;let l=new Map,E=new Map,d=new Map;for(let e of f){let t=e.getAttribute("data-sentient-type"),n=t&&g.includes(t)?t:null,o=(O=n!=null?n:(C=i.typeOf)==null?void 0:C.call(i,e))!=null?O:v(e),a=`nc-${o}`;l.set(e,a),E.set(a,o),n?d.set(a,"markup"):d.has(a)||d.set(a,"auto")}let j=(N=(M=(k=(I=r.defaultView)!=null?I:typeof window!="undefined"?window:void 0)==null?void 0:k.location)==null?void 0:M.pathname)!=null?N:"/";V(i.apiKey,u,j,[...E.entries()].map(([e,t])=>{var n;return{componentId:e,semanticType:t,source:(n=d.get(e))!=null?n:"auto"}}));let p=new Map,B=e=>{let t=p.get(e);return t||(t={ms:0,scroll:0,enterAt:null,intersecting:!1},p.set(e,t)),t},m=new IntersectionObserver(e=>{for(let t of e){let n=l.get(t.target);if(!n)continue;let o=B(n);t.isIntersecting?(o.intersecting=!0,o.enterAt=Date.now(),t.intersectionRatio>o.scroll&&(o.scroll=t.intersectionRatio)):(o.intersecting=!1,o.enterAt!=null&&(o.ms+=Date.now()-o.enterAt,o.enterAt=null))}},{threshold:[0,.25,.5,.75,1]});for(let e of l.keys())m.observe(e);let y=()=>{let e=Date.now();for(let[t,n]of p)if(n.enterAt!=null&&(n.ms+=e-n.enterAt,n.enterAt=null),!(n.ms<=0)){try{s.track({projectId:i.apiKey,componentId:t,eventType:"dwell",payload:{dwell_time:Math.round(n.ms),scroll_depth:Number(n.scroll.toFixed(2))}})}catch(o){}n.ms=0}},S=()=>{if(r.hidden)y();else{let e=Date.now();for(let t of p.values())t.intersecting&&(t.enterAt=e)}},w=()=>{y();try{m.disconnect()}catch(e){}};r.addEventListener("visibilitychange",S);let c=(D=r.defaultView)!=null?D:typeof window!="undefined"?window:void 0;c==null||c.addEventListener("pagehide",w);let T=[];if(i.microSignals)for(let[e,t]of l)T.push(_((n,o={})=>{try{s.track({projectId:i.apiKey,componentId:t,eventType:"micro_signal",payload:x({signalType:n},o)})}catch(a){}},e));return()=>{y(),r.removeEventListener("visibilitychange",S),c==null||c.removeEventListener("pagehide",w);for(let e of T)e();try{m.disconnect()}catch(e){}}}export{g as SEMANTIC_TYPES,F as classifyFeatures,v as classifySection,K as featuresFromElement,$ as startEngagementCapture};
|
package/dist/index-graph.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var et=Object.create;var oe=Object.defineProperty,tt=Object.defineProperties,nt=Object.getOwnPropertyDescriptor,ot=Object.getOwnPropertyDescriptors,rt=Object.getOwnPropertyNames,De=Object.getOwnPropertySymbols,st=Object.getPrototypeOf,Pe=Object.prototype.hasOwnProperty,it=Object.prototype.propertyIsEnumerable;var Ne=(e,t,n)=>t in e?oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,b=(e,t)=>{for(var n in t||(t={}))Pe.call(t,n)&&Ne(e,n,t[n]);if(De)for(var n of De(t))it.call(t,n)&&Ne(e,n,t[n]);return e},j=(e,t)=>tt(e,ot(t));var at=(e,t)=>{for(var n in t)oe(e,n,{get:t[n],enumerable:!0})},Le=(e,t,n,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let d of rt(t))!Pe.call(e,d)&&d!==n&&oe(e,d,{get:()=>t[d],enumerable:!(c=nt(t,d))||c.enumerable});return e};var ct=(e,t,n)=>(n=e!=null?et(st(e)):{},Le(t||!e||!e.__esModule?oe(n,"default",{value:e,enumerable:!0}):n,e)),dt=e=>Le(oe({},"__esModule",{value:!0}),e);var en={};at(en,{deriveSessionSegment:()=>ve,detectDeviceClass:()=>W,detectTimeOfDay:()=>z,detectTrafficSource:()=>q,init:()=>Zt,referrerDomainFromReferer:()=>J});module.exports=dt(en);var lt="_snt_uid";var F="_snt_uid";function ut(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(t){}let e=()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0");return`${e()}-${e()}-${e()}-${e()}`}function gt(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function pt(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(c){}}function ft(e){try{return localStorage.getItem(e)}catch(t){return null}}function mt(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function yt(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function ht(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function St(e){try{sessionStorage.removeItem(e)}catch(t){}}function vt(e){try{return document.cookie=`${e}_probe=1; max-age=1; SameSite=strict; path=/`,/(?:^|; )_snt_uid_probe=1/.test(document.cookie)||document.cookie.indexOf(`${e}_probe=1`)!==-1}catch(t){return!1}}function bt(e){try{localStorage.removeItem(e)}catch(t){}}function Et(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var wt={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function ce(e){var a,l,g,y,f,m;if(typeof window=="undefined")return wt;let t=(a=e==null?void 0:e.cookieName)!=null?a:lt,c=((l=e==null?void 0:e.cookieTTLDays)!=null?l:365)*24*60*60,d=(m=(f=(y=(g=gt(t))!=null?g:ft(F))!=null?y:yt(F))!=null?f:e==null?void 0:e.ssrSessionId)!=null?m:ut();pt(t,d,c);let s=mt(F,d),o=vt(t),r=s?!1:ht(F,d),i=!s&&!o&&!r;return{getSessionId:()=>d,isEphemeral:()=>i,destroy:()=>{d=null,Et(t),bt(F),St(F)}}}function ye(e){return`_snt_retry_${e.slice(0,12)}`}var It={push:()=>{},flush:()=>{},destroy:()=>{}};function Ct(e,t){try{let n=localStorage.getItem(t);if(!n)return[];let c=JSON.parse(n);return Array.isArray(c)?(localStorage.removeItem(t),c.slice(-e)):[]}catch(n){return[]}}function me(e,t,n){try{let d=[...(()=>{try{let s=localStorage.getItem(n);if(!s)return[];let o=JSON.parse(s);return Array.isArray(o)?o:[]}catch(s){return[]}})(),...e].slice(-t);localStorage.setItem(n,JSON.stringify(d))}catch(c){}}function Me(e){var X,Z,ee;if(typeof window=="undefined")return It;let t=(X=e.flushIntervalMs)!=null?X:5e3,n=(Z=e.maxBatchSize)!=null?Z:20,c=(ee=e.maxRetrySize)!=null?ee:100,d=e.ingestUrl,s=e.apiKey,o=ye(s),r=[],i=new Set,a=[],l=h=>{for(let v of h)g.delete(v),!i.has(v)&&(i.add(v),a.push(v));for(;a.length>500;){let v=a.shift();v&&i.delete(v)}},g=new Set,y=h=>{i.has(h.id)||g.has(h.id)||(g.add(h.id),r.push(h))},f=Ct(c,o);for(let h of f)y(h);let m=0,E=0,I=h=>{if(h.length===0)return;let v=JSON.stringify(h),A=h.map(u=>u.id),O;try{O=fetch(d,{method:"POST",keepalive:!0,body:v,headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`}})}catch(u){me(h,c,o);for(let p of A)g.delete(p);E++,m=Date.now()+Math.min(6e4,1e3*2**Math.min(E,6));return}let L=u=>{if(u.ok||u.status>=400&&u.status<500&&u.status!==429){l(A),E=0,m=0;return}me(h,c,o);for(let p of A)g.delete(p);E++,m=Date.now()+Math.min(6e4,1e3*2**Math.min(E,6))};O instanceof Promise?O.then(L).catch(()=>{me(h,c,o);for(let u of A)g.delete(u);E++,m=Date.now()+Math.min(6e4,1e3*2**Math.min(E,6))}):L(O)},w=typeof TextEncoder!="undefined"?new TextEncoder:null,ae=h=>w?w.encode(h).length:h.length,G=h=>{let v=[],A=2;for(let O of h){let L=ae(JSON.stringify(O))+1;if(v.length>0&&A+L>57344||v.length>=n)break;v.push(O),A+=L}return v},N=()=>{try{if(Date.now()<m)return;for(;r.length>0;){let h=r.filter(A=>!i.has(A.id));if(r.length=0,h.length===0)break;let v=G(h);if(v.length===0)break;v.length<h.length&&r.push(...h.slice(v.length)),I(v)}}catch(h){}},R=!0,K=null;K=setInterval(()=>{R&&N()},t);let Q=()=>{document.visibilityState==="hidden"&&N()},V=()=>{N()};return document.addEventListener("visibilitychange",Q),window.addEventListener("beforeunload",V),{push(h){y(h),r.length>=n&&N()},flush:N,destroy(){R=!1,K!==null&&(clearInterval(K),K=null),document.removeEventListener("visibilitychange",Q),window.removeEventListener("beforeunload",V),N()}}}var Se="_snt_asgn_";function de(e,t){return`${e}:${t}`}function xt(e,t){return`${Se}${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function Ue(e){let t=e.slice(Se.length),n=t.indexOf(":");if(n<0)return null;try{return{componentId:decodeURIComponent(t.slice(0,n)),segment:decodeURIComponent(t.slice(n+1))}}catch(c){return null}}function he(){try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n!=null&&n.startsWith(Se)&&e.push(n)}return e}catch(e){return[]}}function Ge(e=18e5){let t=new Map,n=d=>d.assignedAt+e<Date.now();return typeof window!="undefined"&&(()=>{for(let d of he())try{let s=localStorage.getItem(d);if(!s)continue;let o=JSON.parse(s);if(n(o)){localStorage.removeItem(d);continue}let r=Ue(d);if(!r)continue;t.set(de(r.componentId,r.segment),o)}catch(s){}})(),{get(d,s){let o=t.get(de(d,s));return o?n(o)?(t.delete(de(d,s)),null):o:null},set(d,s,o){let r=de(d,s);t.set(r,o);try{localStorage.setItem(xt(d,s),JSON.stringify(o))}catch(i){}},invalidate(d){let s=`${d}:`;for(let o of[...t.keys()])o.startsWith(s)&&t.delete(o);for(let o of he()){let r=Ue(o);if((r==null?void 0:r.componentId)===d)try{localStorage.removeItem(o)}catch(i){}}},clear(){t.clear();for(let d of he())try{localStorage.removeItem(d)}catch(s){}}}}var Ke=["GPTBot","ChatGPT-User","OAI-SearchBot","ClaudeBot","Claude-User","Claude-SearchBot","PerplexityBot","Perplexity-User","Google-Extended","Applebot-Extended","Meta-ExternalAgent","Bytespider","CCBot","Amazonbot","cohere-ai","Diffbot"];function le(e){return $e(e)!==null}function $e(e){var n;if(!e)return null;let t=e.toLowerCase();return(n=Ke.find(c=>t.includes(c.toLowerCase())))!=null?n:null}function W(e){let t=e.toLowerCase();return/ipad|tablet|playbook|kindle|silk/.test(t)?"tablet":/mobi|iphone|ipod|android.*mobile|phone/.test(t)?"mobile":"desktop"}function q(e,t){if(!e)return"direct";try{let n=new URL(e);if(t)try{if(new URL(t).host===n.host)return"direct"}catch(d){}let c=n.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(c)?"search":/(^|\.)(twitter\.com|x\.com|facebook\.com|linkedin\.com|reddit\.com|t\.co)$/.test(c)?"social":"referral"}catch(n){return"direct"}}function J(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function z(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function ve(e){let t=At("__segment__",e);return`${t.deviceClass}:${t.trafficSource}`}function At(e,t){var s,o,r,i,a,l,g;let n=(o=(s=t==null?void 0:t.userAgent)==null?void 0:s.trim())!=null?o:"",c=(i=(r=t==null?void 0:t.referer)==null?void 0:r.trim())!=null?i:"",d=(a=t==null?void 0:t.now)!=null?a:new Date;return{sessionId:e,ephemeral:!1,utmParams:(l=t==null?void 0:t.utmParams)!=null?l:{},deviceClass:n?W(n):"desktop",trafficSource:c?q(c,t==null?void 0:t.appOrigin):"direct",referrerDomain:J(c),timeOfDay:z(d),dayOfWeek:(g=["sun","mon","tue","wed","thu","fri","sat"][d.getDay()])!=null?g:"sun",automation:(t==null?void 0:t.webdriver)===!0||le(n)}}var Y=require("@sentientui/policy");function ue(e){return b(b(b({id:e.id},e.arms?{arms:[...e.arms]}:{}),e.dims?{dims:Object.fromEntries(Object.entries(e.dims).map(([t,n])=>[t,[...n]]))}:{}),e.baseline!==void 0?{baseline:e.baseline}:{})}function ge(e){let t=ue(e);return(0,Y.slotResultFor)(t,(0,Y.slotBaselineArm)(t))}function be(e){return typeof e=="string"?e:(0,Y.canonicalArm)(e)}var re="_snt_snap:",_t=["low","medium","high"];function Ee(e){try{let t=localStorage.getItem(re+e);if(!t)return null;let n=JSON.parse(t);return!n||typeof n!="object"||n.v!==1||typeof n.persona!="string"||typeof n.band!="string"||!_t.includes(n.band)||typeof n.slots!="object"||n.slots===null||Array.isArray(n.slots)||!(n.layoutOrder===null||Array.isArray(n.layoutOrder))||typeof n.savedAt!="number"||!(n.slotConfig===void 0||typeof n.slotConfig=="object"&&n.slotConfig!==null&&!Array.isArray(n.slotConfig))?null:n}catch(t){return null}}function se(e,t){try{localStorage.setItem(re+e,JSON.stringify(t))}catch(n){}}var Ce=require("@sentientui/policy");var fe=require("@sentientui/policy");var we="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",je="[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.",Be=!1,pe=!1;function Tt(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(t){return}}function Fe(e){var r;let t=ce({ssrSessionId:e.ssrSessionId}),n=(r=t.getSessionId())!=null?r:"local",c=Tt(),d=import("@sentientui/core/local").then(i=>{let a=i;return a.LOCAL_ENGINE_AVAILABLE?(Be||(Be=!0,console.info(je)),a):(pe||(pe=!0,console.error(we)),null)}).catch(()=>(pe||(pe=!0,console.error(we)),null)),s=null;function o(i){let a=document.documentElement;a.dataset.sentientPersona===void 0&&(a.dataset.sentientPersona=i.persona,a.dataset.sentientConfidence=(0,fe.confidenceBand)(i.confidence))}return{isLocal:!0,async decide(i){var g,y,f;let a=await d;if(!a)return null;let l=a.createLocalEngine({sessionId:n,forcedPersona:c}).decide(i);return s=j(b({},l),{layoutOrder:(y=(g=l.layoutOrder)!=null?g:s==null?void 0:s.layoutOrder)!=null?y:null,slots:b(b({},(f=s==null?void 0:s.slots)!=null?f:{}),l.slots)}),se(e.apiKey||"local",{v:1,persona:s.persona,band:(0,fe.confidenceBand)(s.confidence),slots:s.slots,layoutOrder:s.layoutOrder,savedAt:Date.now()}),o(l),l},getSlotResult(i){var a,l,g;return(g=(l=s==null?void 0:s.slots[i])!=null?l:(a=e.initialSlots)==null?void 0:a[i])!=null?g:null},getPersona(){return s?{persona:s.persona,confidence:s.confidence,band:(0,fe.confidenceBand)(s.confidence)}:null},async assign(i,a){var y;let l=await d;return!l||!a||a.length===0?a!=null&&a[0]?{variantId:a[0],assignmentTtlMs:0}:null:{variantId:(y=l.createLocalEngine({sessionId:n,forcedPersona:c}).decide({components:[{id:i,variantIds:a}]}).assignments[i])!=null?y:a[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>t.destroy()}}var We="https://api.sentient-ui.com/v1/events",ie=new Map,Rt=null;function Ie(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(e){}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}var H={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 Ot(){try{let e={},t=new URLSearchParams(window.location.search);for(let[n,c]of t)n.startsWith("utm_")&&(e[n]=c);return e}catch(e){return{}}}function qe(e){return e.replace(/\/events\/?$/,"")}function xe(){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(t=>t==="1"||t==="yes")}function kt(e){var o;let t=qe((o=e.ingestUrl)!=null?o:We),n={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},c={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),async assign(r,i,a){try{let l=new URLSearchParams({componentId:r});for(let f of i!=null?i:[])l.append("variantIds[]",f);let g=await fetch(`${t}/winner?${l.toString()}`,{headers:n});return g.ok?{variantId:(await g.json()).variantId,assignmentTtlMs:0}:i!=null&&i[0]?{variantId:i[0],assignmentTtlMs:0}:null}catch(l){return i!=null&&i[0]?{variantId:i[0],assignmentTtlMs:0}:null}},decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}},d={track:r=>c.track(r),goal:(r,i,a,l)=>c.goal(r,i,a,l),componentGoal:(r,i,a)=>c.componentGoal(r,i,a),identify:r=>c.identify(r),getAssignment:(r,i)=>c.getAssignment(r,i),assign:(r,i,a,l)=>c.assign(r,i,a,l),decide:r=>c.decide(r),getSlotResult:r=>c.getSlotResult(r),getPersona:()=>c.getPersona(),fetchWeights:()=>c.fetchWeights(),getGraph:()=>c.getGraph(),dispose:()=>c.dispose(),destroy:()=>c.destroy()};function s(r){c=r}return{proxy:d,setInner:s}}function Je(e){var V,X,Z,ee,h,v,A,O,L;if(typeof window=="undefined")return H;Rt=e.apiKey;let t=e.respectDoNotTrack!==!1&&xe(),n=e.consent===!1||t,c=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!c&&e.localMode!==!1)return n?(ie.set(e.apiKey||"local",{config:e,upgrade:null}),H):(ie.set(e.apiKey||"local",{config:e,upgrade:null}),Fe(e));if(n){if(e.preConsentBehavior==="statistical_winner"){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."),H;let{proxy:u,setInner:p}=kt(e);return ie.set(e.apiKey,{config:e,upgrade:t?null:p}),u}return ie.set(e.apiKey,{config:e,upgrade:null}),H}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."),H;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),H;let d=(V=e.ingestUrl)!=null?V:We,s=Date.now(),o=ce({ssrSessionId:e.ssrSessionId}),r=Ge(),i=Me({ingestUrl:d,apiKey:e.apiKey}),a=qe(d),l={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},g=W((X=navigator.userAgent)!=null?X:""),y=typeof window!="undefined"?window.location.origin:void 0,f=q((Z=document.referrer)!=null?Z:"",y),m=(ee=e.sessionSegment)!=null?ee:`${g}:${f}`,E=new Map,I=new Map,w=null,ae=u=>{for(let p of u)I.has(p.id)||I.set(p.id,ge(p))};if(e.initialSlots)for(let[u,p]of Object.entries(e.initialSlots))I.set(u,p);let G=Ee(e.apiKey);if(G)for(let[u,p]of Object.entries(G.slots))I.has(u)||I.set(u,p);let N={low:.15,medium:.5,high:.85};if(e.initialPersona)w=b({},e.initialPersona);else{let u=document.documentElement.dataset;u.sentientPersona?w={persona:u.sentientPersona,confidence:(v=N[(h=u.sentientConfidence)!=null?h:"low"])!=null?v:.15}:G&&(w={persona:G.persona,confidence:(A=N[G.band])!=null?A:.15})}if(e.initialAssignments)for(let[u,p]of Object.entries(e.initialAssignments))r.set(u,m,{variantId:p,assignedAt:Date.now(),segment:m,confidence:1});let R=Promise.resolve(),K=o.getSessionId();if(K){let u=J((O=document.referrer)!=null?O:""),p=b(b({sessionId:K,deviceClass:g,trafficSource:f,referrerDomain:u,utmParams:Ot(),timeOfDay:z(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:o.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||le((L=navigator.userAgent)!=null?L:"")},e.userId?{userId:e.userId}:{}),e.country?{country:e.country}:{});try{R=fetch(`${a}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(p),headers:l}).then(S=>{S.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")}).catch(()=>{})}catch(S){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:i});let Q={goal(u,p={},S=1,k=0){let x=o.getSessionId();if(!x)return;let _=Ie();R.then(()=>{fetch(`${a}/goals`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:x,name:u,metadata:p,weight:S,stepIndex:k,goalId:_}),headers:l}).catch(()=>{})})},componentGoal(u,p,S){var D,U,P;let k=o.getSessionId();if(!k)return;let x=r.get(u,m),_=x?null:(D=I.get(u))!=null?D:null;if(!x&&_===null){e.debug&&console.warn(`[sentient] componentGoal("${u}"): no assignment or slot decision yet \u2014 render its <Adaptive>/adaptive hook or call assign()/decide() before recording a goal.`);return}let $=x?x.variantId:be(_),M={id:Ie(),sessionId:k,projectId:e.apiKey,componentId:u,variantId:$,eventType:"goal_achieved",goalType:p,payload:b({reward:(U=S==null?void 0:S.reward)!=null?U:1},(P=S==null?void 0:S.metadata)!=null?P:{}),timestamp:Date.now(),timeInSession:Date.now()-s};e.debug&&console.log("[sentient] componentGoal",M),R.then(()=>i.push(M))},identify(u){let p=o.getSessionId();p&&R.then(()=>{fetch(`${a}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:p,userId:u,ephemeral:o.isEphemeral()}),headers:l}).catch(()=>{})})},track(u){let p=o.getSessionId();if(!p)return;let S=j(b({},u),{id:Ie(),sessionId:p,timestamp:Date.now(),timeInSession:Date.now()-s});e.debug&&console.log("[sentient] track",S),R.then(()=>i.push(S))},getAssignment(u,p){return r.get(u,p)},async assign(u,p,S,k){let x=o.getSessionId();if(!x)return null;let _=r.get(u,m);if(_&&(p!=null&&p.length||_.content!==void 0))return{variantId:_.variantId,assignmentTtlMs:0,content:_.content};let $=E.get(u);if($)return $;let M=(async()=>{await R;try{let D={sessionId:x,componentId:u,variantIds:p};k!==void 0?D.agentDataByVariant=k:S!==void 0&&(D.agentData=S);let U=await fetch(`${a}/assign`,{method:"POST",body:JSON.stringify(D),headers:l});if(!U.ok)return null;let P=await U.json();return r.set(u,m,{variantId:P.variantId,assignedAt:Date.now(),segment:m,confidence:1,content:P.content}),P}catch(D){return null}finally{E.delete(u)}})();return E.set(u,M),M},async decide(u){var k,x,_,$,M,D,U,P,Re,Oe;let p=o.getSessionId();if(!p)return null;let S=(k=u.slots)!=null?k:[];await R;try{let B={sessionId:p};u.sections&&u.sections.length>0&&(B.sections=u.sections.map(T=>({id:T}))),B.components=(x=u.components)!=null?x:[],S.length>0&&(B.slots=S.map(ue)),u.slotsFrom==="registry"&&(B.slotsFrom="registry"),u.v&&(B.v=u.v);let ke=await fetch(`${a}/decide`,{method:"POST",body:JSON.stringify(B),headers:l});if(!ke.ok)return ae(S),null;let C=await ke.json(),te={};for(let T of S)te[T.id]=($=(_=C.slots)==null?void 0:_[T.id])!=null?$:ge(T);if(C.slots)for(let[T,ne]of Object.entries(C.slots))T in te||(te[T]=ne);for(let[T,ne]of Object.entries(te))I.set(T,ne);w={persona:(M=C.persona)!=null?M:"unknown",confidence:(D=C.confidence)!=null?D:0};for(let[T,ne]of Object.entries((U=C.assignments)!=null?U:{}))r.set(T,m,{variantId:ne,assignedAt:Date.now(),segment:m,confidence:1});return se(e.apiKey,b({v:1,persona:w.persona,band:(0,Ce.confidenceBand)(w.confidence),slots:Object.fromEntries(I),layoutOrder:(P=C.layoutOrder)!=null?P:null,savedAt:Date.now()},C.slotConfig?{slotConfig:C.slotConfig}:{})),b(b({layoutOrder:(Re=C.layoutOrder)!=null?Re:null,assignments:(Oe=C.assignments)!=null?Oe:{},slots:te,persona:w.persona,confidence:w.confidence},C.slotConfig?{slotConfig:C.slotConfig}:{}),C.goals?{goals:C.goals}:{})}catch(B){return ae(S),null}},getSlotResult(u){var p;return(p=I.get(u))!=null?p:null},getPersona(){return w?{persona:w.persona,confidence:w.confidence,band:(0,Ce.confidenceBand)(w.confidence)}:null},async fetchWeights(){var u;try{let p=await fetch(`${a}/weights`,{headers:l});return p.ok?(u=(await p.json()).components)!=null?u:[]:[]}catch(p){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){i.destroy(),e.debug&&console.log("[sentient] disposed")},destroy(){i.destroy(),o.destroy();try{localStorage.removeItem(re+e.apiKey),localStorage.removeItem(ye(e.apiKey))}catch(u){}e.debug&&console.log("[sentient] destroyed")}};if(ie.set(e.apiKey,{config:e,upgrade:null}),e.debug){let u=window;u.__sentient&&(u.__sentient.client=Q)}return Q}var ze=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Dt=[["pricing",/\b(pricing|price|plans?|subscriptions?|per month|\/mo|tier)\b/i],["faq",/\b(faq|frequently asked|common questions?)\b/i],["comparison",/\b(compare|comparison|versus|vs\.)\b/i],["social_proof",/\b(testimonial|reviews?|trusted by|loved by|customers?|logos|rated|case stud)\b/i],["trust",/\b(security|guarantee|privacy|compliance|secure|gdpr|soc ?2|encrypt)\b/i],["features",/\b(features?|how it works|benefits?|capabilit|what you get)\b/i]];function Nt(e){var n;let t=e.querySelector("h1, h2, h3");return((n=t==null?void 0:t.textContent)!=null?n:"").slice(0,160)}function Pt(e){var c;let t=e.querySelectorAll('a, button, [role="button"]').length,n=((c=e.textContent)!=null?c:"").trim().length;return t>=1&&n>0&&n<200}function Ye(e){let t=e.tagName.toLowerCase();if(t==="nav"||t==="footer")return"navigation";let n=`${e.id} ${e.className} ${Nt(e)}`.toLowerCase();for(let[c,d]of Dt)if(d.test(n))return c;return Pt(e)?"cta":t==="header"||/\b(hero|headline|banner)\b/i.test(n)?"hero":"generic"}var Lt=new Set(["SECTION","ARTICLE","MAIN","DIV"]),Mt="h1, h2, h3",Ut={scan:async()=>({nodes:[],edges:[],scannedAt:0}),observe:()=>{},getProminenceScore:()=>0,destroy:()=>{}};function Ae(e,t,n){return n<=t?0:Math.max(0,Math.min(1,(e-t)/(n-t)))}function Gt(e){var t,n,c;try{let d=e;for(let s of Object.keys(d)){if(!s.startsWith("__reactFiber")&&!s.startsWith("__reactInternalInstance"))continue;let o=d[s],r=(c=(t=o==null?void 0:o.type)==null?void 0:t.displayName)!=null?c:(n=o==null?void 0:o.type)==null?void 0:n.name;if(r&&r.length>1)return r}}catch(d){}}function Kt(e){let t={};for(let n of Array.from(e.attributes))n.name.startsWith("data-")&&(t[n.name]=n.value);return t}var He=new Set(ze);function $t(e){let t=e.getAttribute("data-sentient-type");if(t&&He.has(t))return t;let n=e.getAttribute("role");return n&&He.has(n)?n:Ye(e)}function Bt(e){var t,n;return(n=(t=e.getAttribute("data-sentient-id"))!=null?t:e.getAttribute("id"))!=null?n:e.tagName.toLowerCase()}function jt(e){let t=0,n=e.parentElement;for(;n;)t++,n=n.parentElement;return t}function _e(e,t){var c,d,s;let n=e.querySelector(Mt);return{componentId:Bt(e),semanticType:$t(e),ariaLabel:(c=e.getAttribute("aria-label"))!=null?c:void 0,headingText:(s=(d=n==null?void 0:n.textContent)==null?void 0:d.trim())!=null?s:void 0,isAboveFold:e.getBoundingClientRect().top<window.innerHeight,prominenceScore:t(e),depth:jt(e),reactComponentName:Gt(e),dataAttributes:Kt(e)}}function Qe(e){var s;let t=[],n=new Set,c="__root__",d=new Map;for(let[o,r]of e){let i=o.parentElement,a=c;for(;i;){if(e.has(i)){a=e.get(i);let g=e.get(o),y=`${a}->${g}`;!n.has(y)&&a!==g&&(n.add(y),t.push({fromComponentId:a,toComponentId:g,weight:.6}));break}i=i.parentElement}let l=(s=d.get(a))!=null?s:[];l.push(o),d.set(a,l)}for(let o of d.values())if(!(o.length<2))for(let r=0;r<o.length;r++)for(let i=r+1;i<o.length;i++){let a=e.get(o[r]),l=e.get(o[i]);if(a===l)continue;let g=`${a}->${l}::sib`,y=`${l}->${a}::sib`;n.has(g)||(n.add(g),t.push({fromComponentId:a,toComponentId:l,weight:.3})),n.has(y)||(n.add(y),t.push({fromComponentId:l,toComponentId:a,weight:.3}))}return t}function Ft(e){let t=[],n=new Set,c=new Map;return document.querySelectorAll("[data-sentient-id]").forEach(o=>{if(o instanceof Element&&!n.has(o)){n.add(o);let r=_e(o,e);t.push(r),c.set(o,r.componentId)}}),document.querySelectorAll("section, article, main, aside").forEach(o=>{if(!(o instanceof Element)||n.has(o))return;let r=o.hasAttribute("aria-label"),i=o.hasAttribute("data-sentient-id");if(!r&&!i)return;n.add(o);let a=_e(o,e);t.push(a),c.set(o,a.componentId)}),{nodes:t,edges:Qe(c)}}function Ve(){if(typeof window=="undefined")return Ut;let e=null,t=0,n=null,c=r=>{try{let i=window.getComputedStyle(r),a=parseFloat(i.fontSize)||12,l=parseFloat(i.zIndex)||0,g=r.getBoundingClientRect(),y=Math.max(g.top,0),f=window.innerHeight||1,m=1/(y/f+1),E=Ae(a,12,48)*.4+Ae(m,0,1)*.4+Ae(l,0,100)*.2;return Math.max(0,Math.min(1,E))}catch(i){return .5}};return{scan:()=>new Promise(r=>{let i=()=>{let{nodes:a,edges:l}=Ft(c);r({nodes:a,edges:l,scannedAt:Date.now()})};try{typeof requestIdleCallback=="function"?t=requestIdleCallback(i,{timeout:100}):i()}catch(a){i()}}),observe:r=>{n=r;try{e=new MutationObserver(i=>{let a=[],l=new Map;for(let g of i)g.type==="childList"&&g.addedNodes.forEach(y=>{if(!(y instanceof Element)||!Lt.has(y.tagName))return;let f=y.hasAttribute("data-sentient-id"),m=y.hasAttribute("aria-label");if(!f&&!m)return;let E=_e(y,c);a.push(E),l.set(y,E.componentId)});a.length>0&&n&&n({nodes:a,edges:Qe(l),addedAt:Date.now()})}),e.observe(document.body,{childList:!0,subtree:!0})}catch(i){}},getProminenceScore:c,destroy:()=>{if(e&&(e.disconnect(),e=null),t&&typeof cancelIdleCallback=="function")try{cancelIdleCallback(t)}catch(r){}t=0,n=null}}}var Te="_snt_graph_nodes",Xe="_snt_graph_edges",Wt={pricing:["features","faq"],features:["pricing"],faq:["pricing"],social_proof:["cta"],cta:["social_proof","hero","trust"],hero:["cta"],comparison:["pricing"],trust:["cta"]};function qt(e){var t;return(t=Wt[e])!=null?t:[]}function Jt(e,t){try{let n=localStorage.getItem(e);return n?JSON.parse(n):t}catch(n){return t}}function zt(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch(n){}}var Yt=new Set(["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"]);function Ht(e){return Yt.has(e)?e:"generic"}function Qt(e,t,n){let c=`${e}:${t}:${n.join(",")}`,d=5381;for(let s=0;s<c.length;s++)d=(d<<5)+d+c.charCodeAt(s)&4294967295;return(d>>>0).toString(16).padStart(8,"0")}function Ze(e){let t=new Map,n=new Map,c=()=>{typeof window!="undefined"&&zt(Te,[...t.values()])},d=s=>{var o;try{let r=JSON.parse(s);t.clear();for(let i of(o=r.pageNodes)!=null?o:[])t.set(i.componentId,i)}catch(r){}};if(typeof window!="undefined"){let s=Jt(Te,[]);for(let o of s)t.set(o.componentId,o);try{localStorage.removeItem(Xe)}catch(o){}}return{addPageNode(s){t.set(s.componentId,s),c()},addStructuralEdge(s){let o=`${s.fromComponentId}->${s.toComponentId}`;n.set(o,s)},syncOnce(){var o,r;if(!(e!=null&&e.syncUrl)||typeof window=="undefined")return;let s=[...t.values()];if(s.length!==0)try{let i=new Map;for(let f of s){let m=(o=i.get(f.semanticType))!=null?o:[];m.push(f),i.set(f.semanticType,m)}let a=[],l=new Set;for(let f of s)for(let m of qt(f.semanticType)){let E=(r=i.get(m))!=null?r:[];for(let I of E){if(I.componentId===f.componentId)continue;let w=`semantic:${f.componentId}->${I.componentId}`;l.has(w)||(l.add(w),a.push({fromComponentId:f.componentId,toComponentId:I.componentId,type:"semantic",weight:.4,confidence:.9}))}}let g=new Set(s.map(f=>f.componentId));for(let f of n.values()){if(!g.has(f.fromComponentId)||!g.has(f.toComponentId))continue;let m=`structural:${f.fromComponentId}->${f.toComponentId}`;l.has(m)||(l.add(m),a.push({fromComponentId:f.fromComponentId,toComponentId:f.toComponentId,type:"structural",weight:f.weight,confidence:1}))}let y={pageUrl:window.location.href,nodes:s.map(f=>{let m=Ht(f.semanticType);return{componentId:f.componentId,semanticType:m,answers:f.answers,contentHash:Qt(f.componentId,m,f.answers),prominenceScore:f.prominenceScore,depthInPage:f.depth}}),edges:a};fetch(e.syncUrl,{method:"POST",keepalive:!0,headers:b({"Content-Type":"application/json"},e.apiKey?{Authorization:`Bearer ${e.apiKey}`}:{}),body:JSON.stringify(y)}).catch(()=>{})}catch(i){}},snapshot(){return{pageNodes:[...t.values()],capturedAt:Date.now()}},serialize(){return JSON.stringify({pageNodes:[...t.values()]})},restore:d,destroy(){if(typeof window!="undefined")try{localStorage.removeItem(Te),localStorage.removeItem(Xe)}catch(s){}}}}var Vt="https://api.sentient-ui.com/v1/events";function Xt(){try{let e=document.cookie.match(/(?:^|; )_snt_uid=([^;]*)/);return e?decodeURIComponent(e[1]):void 0}catch(e){return}}function Zt(e){var a;let t=Je(e),n=e.respectDoNotTrack!==!1&&xe(),c=e.consent===!1||n;if(!e.graph||c||typeof window=="undefined")return t;let d=Ve(),s=(a=e.ingestUrl)!=null?a:Vt,o=Ze({syncUrl:s.replace(/\/events\/?$/,"/graph/sync"),apiKey:e.apiKey,projectId:e.apiKey,sessionId:Xt()});try{let l=localStorage.getItem("_snt_graph_nodes");l&&o.restore(JSON.stringify({pageNodes:JSON.parse(l)}))}catch(l){}d.scan().then(l=>{for(let g of l.nodes)o.addPageNode({id:g.componentId,componentId:g.componentId,semanticType:g.semanticType,answers:g.headingText?[g.headingText]:[],prominenceScore:g.prominenceScore,depth:g.depth});for(let g of l.edges)o.addStructuralEdge(g);o.syncOnce()});let r=null,i=()=>{r!==null&&clearTimeout(r),r=setTimeout(()=>{r=null,o.syncOnce()},500)};return d.observe(l=>{for(let g of l.nodes)o.addPageNode({id:g.componentId,componentId:g.componentId,semanticType:g.semanticType,answers:g.headingText?[g.headingText]:[],prominenceScore:g.prominenceScore,depth:g.depth});for(let g of l.edges)o.addStructuralEdge(g);i()}),j(b({},t),{getGraph:()=>o.snapshot(),dispose:()=>{r!==null&&clearTimeout(r),d.destroy(),o.destroy(),t.dispose()},destroy:()=>{r!==null&&clearTimeout(r),d.destroy(),o.destroy(),t.destroy()}})}0&&(module.exports={deriveSessionSegment,detectDeviceClass,detectTimeOfDay,detectTrafficSource,init,referrerDomainFromReferer});
|
|
1
|
+
"use strict";var et=Object.create;var oe=Object.defineProperty,tt=Object.defineProperties,nt=Object.getOwnPropertyDescriptor,ot=Object.getOwnPropertyDescriptors,rt=Object.getOwnPropertyNames,De=Object.getOwnPropertySymbols,st=Object.getPrototypeOf,Pe=Object.prototype.hasOwnProperty,it=Object.prototype.propertyIsEnumerable;var Ne=(e,t,n)=>t in e?oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,b=(e,t)=>{for(var n in t||(t={}))Pe.call(t,n)&&Ne(e,n,t[n]);if(De)for(var n of De(t))it.call(t,n)&&Ne(e,n,t[n]);return e},F=(e,t)=>tt(e,ot(t));var at=(e,t)=>{for(var n in t)oe(e,n,{get:t[n],enumerable:!0})},Le=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let d of rt(t))!Pe.call(e,d)&&d!==n&&oe(e,d,{get:()=>t[d],enumerable:!(a=nt(t,d))||a.enumerable});return e};var ct=(e,t,n)=>(n=e!=null?et(st(e)):{},Le(t||!e||!e.__esModule?oe(n,"default",{value:e,enumerable:!0}):n,e)),dt=e=>Le(oe({},"__esModule",{value:!0}),e);var nn={};at(nn,{deriveSessionSegment:()=>ve,detectDeviceClass:()=>W,detectTimeOfDay:()=>z,detectTrafficSource:()=>q,init:()=>tn,referrerDomainFromReferer:()=>J});module.exports=dt(nn);var lt="_snt_uid";var j="_snt_uid";function ut(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(t){}let e=()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0");return`${e()}-${e()}-${e()}-${e()}`}function gt(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function pt(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(a){}}function ft(e){try{return localStorage.getItem(e)}catch(t){return null}}function mt(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function yt(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function ht(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function St(e){try{sessionStorage.removeItem(e)}catch(t){}}function vt(e){try{return document.cookie=`${e}_probe=1; max-age=1; SameSite=strict; path=/`,/(?:^|; )_snt_uid_probe=1/.test(document.cookie)||document.cookie.indexOf(`${e}_probe=1`)!==-1}catch(t){return!1}}function bt(e){try{localStorage.removeItem(e)}catch(t){}}function Et(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var wt={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function ce(e){var c,l,g,y,f,m;if(typeof window=="undefined")return wt;let t=(c=e==null?void 0:e.cookieName)!=null?c:lt,a=((l=e==null?void 0:e.cookieTTLDays)!=null?l:365)*24*60*60,d=(m=(f=(y=(g=gt(t))!=null?g:ft(j))!=null?y:yt(j))!=null?f:e==null?void 0:e.ssrSessionId)!=null?m:ut();pt(t,d,a);let s=mt(j,d),o=vt(t),r=s?!1:ht(j,d),i=!s&&!o&&!r;return{getSessionId:()=>d,isEphemeral:()=>i,destroy:()=>{d=null,Et(t),bt(j),St(j)}}}function ye(e){return`_snt_retry_${e.slice(0,12)}`}var It={push:()=>{},flush:()=>{},destroy:()=>{}};function Ct(e,t){try{let n=localStorage.getItem(t);if(!n)return[];let a=JSON.parse(n);return Array.isArray(a)?(localStorage.removeItem(t),a.slice(-e)):[]}catch(n){return[]}}function me(e,t,n){try{let d=[...(()=>{try{let s=localStorage.getItem(n);if(!s)return[];let o=JSON.parse(s);return Array.isArray(o)?o:[]}catch(s){return[]}})(),...e].slice(-t);localStorage.setItem(n,JSON.stringify(d))}catch(a){}}function Me(e){var X,Z,ee;if(typeof window=="undefined")return It;let t=(X=e.flushIntervalMs)!=null?X:5e3,n=(Z=e.maxBatchSize)!=null?Z:20,a=(ee=e.maxRetrySize)!=null?ee:100,d=e.ingestUrl,s=e.apiKey,o=ye(s),r=[],i=new Set,c=[],l=h=>{for(let v of h)g.delete(v),!i.has(v)&&(i.add(v),c.push(v));for(;c.length>500;){let v=c.shift();v&&i.delete(v)}},g=new Set,y=h=>{i.has(h.id)||g.has(h.id)||(g.add(h.id),r.push(h))},f=Ct(a,o);for(let h of f)y(h);let m=0,E=0,I=h=>{if(h.length===0)return;let v=JSON.stringify(h),A=h.map(u=>u.id),k;try{k=fetch(d,{method:"POST",keepalive:!0,body:v,headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`}})}catch(u){me(h,a,o);for(let p of A)g.delete(p);E++,m=Date.now()+Math.min(6e4,1e3*2**Math.min(E,6));return}let L=u=>{if(u.ok||u.status>=400&&u.status<500&&u.status!==429){l(A),E=0,m=0;return}me(h,a,o);for(let p of A)g.delete(p);E++,m=Date.now()+Math.min(6e4,1e3*2**Math.min(E,6))};k instanceof Promise?k.then(L).catch(()=>{me(h,a,o);for(let u of A)g.delete(u);E++,m=Date.now()+Math.min(6e4,1e3*2**Math.min(E,6))}):L(k)},w=typeof TextEncoder!="undefined"?new TextEncoder:null,ae=h=>w?w.encode(h).length:h.length,G=h=>{let v=[],A=2;for(let k of h){let L=ae(JSON.stringify(k))+1;if(v.length>0&&A+L>57344||v.length>=n)break;v.push(k),A+=L}return v},N=()=>{try{if(Date.now()<m)return;for(;r.length>0;){let h=r.filter(A=>!i.has(A.id));if(r.length=0,h.length===0)break;let v=G(h);if(v.length===0)break;v.length<h.length&&r.push(...h.slice(v.length)),I(v)}}catch(h){}},R=!0,$=null;$=setInterval(()=>{R&&N()},t);let Q=()=>{document.visibilityState==="hidden"&&N()},V=()=>{N()};return document.addEventListener("visibilitychange",Q),window.addEventListener("beforeunload",V),{push(h){y(h),r.length>=n&&N()},flush:N,destroy(){R=!1,$!==null&&(clearInterval($),$=null),document.removeEventListener("visibilitychange",Q),window.removeEventListener("beforeunload",V),N()}}}var Se="_snt_asgn_";function de(e,t){return`${e}:${t}`}function xt(e,t){return`${Se}${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function Ue(e){let t=e.slice(Se.length),n=t.indexOf(":");if(n<0)return null;try{return{componentId:decodeURIComponent(t.slice(0,n)),segment:decodeURIComponent(t.slice(n+1))}}catch(a){return null}}function he(){try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n!=null&&n.startsWith(Se)&&e.push(n)}return e}catch(e){return[]}}function Ge(e=18e5){let t=new Map,n=d=>d.assignedAt+e<Date.now();return typeof window!="undefined"&&(()=>{for(let d of he())try{let s=localStorage.getItem(d);if(!s)continue;let o=JSON.parse(s);if(n(o)){localStorage.removeItem(d);continue}let r=Ue(d);if(!r)continue;t.set(de(r.componentId,r.segment),o)}catch(s){}})(),{get(d,s){let o=t.get(de(d,s));return o?n(o)?(t.delete(de(d,s)),null):o:null},set(d,s,o){let r=de(d,s);t.set(r,o);try{localStorage.setItem(xt(d,s),JSON.stringify(o))}catch(i){}},invalidate(d){let s=`${d}:`;for(let o of[...t.keys()])o.startsWith(s)&&t.delete(o);for(let o of he()){let r=Ue(o);if((r==null?void 0:r.componentId)===d)try{localStorage.removeItem(o)}catch(i){}}},clear(){t.clear();for(let d of he())try{localStorage.removeItem(d)}catch(s){}}}}var $e=["GPTBot","ChatGPT-User","OAI-SearchBot","ClaudeBot","Claude-User","Claude-SearchBot","PerplexityBot","Perplexity-User","Google-Extended","Applebot-Extended","Meta-ExternalAgent","Bytespider","CCBot","Amazonbot","cohere-ai","Diffbot"];function le(e){return Ke(e)!==null}function Ke(e){var n;if(!e)return null;let t=e.toLowerCase();return(n=$e.find(a=>t.includes(a.toLowerCase())))!=null?n:null}function W(e){let t=e.toLowerCase();return/ipad|tablet|playbook|kindle|silk/.test(t)?"tablet":/mobi|iphone|ipod|android.*mobile|phone/.test(t)?"mobile":"desktop"}function q(e,t){if(!e)return"direct";try{let n=new URL(e);if(t)try{if(new URL(t).host===n.host)return"direct"}catch(d){}let a=n.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(a)?"search":/(^|\.)(twitter\.com|x\.com|facebook\.com|linkedin\.com|reddit\.com|t\.co)$/.test(a)?"social":"referral"}catch(n){return"direct"}}function J(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function z(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function ve(e){let t=At("__segment__",e);return`${t.deviceClass}:${t.trafficSource}`}function At(e,t){var s,o,r,i,c,l,g;let n=(o=(s=t==null?void 0:t.userAgent)==null?void 0:s.trim())!=null?o:"",a=(i=(r=t==null?void 0:t.referer)==null?void 0:r.trim())!=null?i:"",d=(c=t==null?void 0:t.now)!=null?c:new Date;return{sessionId:e,ephemeral:!1,utmParams:(l=t==null?void 0:t.utmParams)!=null?l:{},deviceClass:n?W(n):"desktop",trafficSource:a?q(a,t==null?void 0:t.appOrigin):"direct",referrerDomain:J(a),timeOfDay:z(d),dayOfWeek:(g=["sun","mon","tue","wed","thu","fri","sat"][d.getDay()])!=null?g:"sun",automation:(t==null?void 0:t.webdriver)===!0||le(n)}}var Y=require("@sentientui/policy");function ue(e){return b(b(b({id:e.id},e.arms?{arms:[...e.arms]}:{}),e.dims?{dims:Object.fromEntries(Object.entries(e.dims).map(([t,n])=>[t,[...n]]))}:{}),e.baseline!==void 0?{baseline:e.baseline}:{})}function ge(e){let t=ue(e);return(0,Y.slotResultFor)(t,(0,Y.slotBaselineArm)(t))}function be(e){return typeof e=="string"?e:(0,Y.canonicalArm)(e)}var re="_snt_snap:",Tt=["low","medium","high"];function Ee(e){try{let t=localStorage.getItem(re+e);if(!t)return null;let n=JSON.parse(t);return!n||typeof n!="object"||n.v!==1||typeof n.persona!="string"||typeof n.band!="string"||!Tt.includes(n.band)||typeof n.slots!="object"||n.slots===null||Array.isArray(n.slots)||!(n.layoutOrder===null||Array.isArray(n.layoutOrder))||typeof n.savedAt!="number"||!(n.slotConfig===void 0||typeof n.slotConfig=="object"&&n.slotConfig!==null&&!Array.isArray(n.slotConfig))?null:n}catch(t){return null}}function se(e,t){try{localStorage.setItem(re+e,JSON.stringify(t))}catch(n){}}var Ce=require("@sentientui/policy");var fe=require("@sentientui/policy");var we="[sentient] No API key configured \u2014 nothing is being learned. Set NEXT_PUBLIC_SENTIENT_API_KEY or pass localMode: true for local development.",Fe="[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.",Be=!1,pe=!1;function _t(){var e;try{return(e=new URLSearchParams(window.location.search).get("sentient_persona"))!=null?e:void 0}catch(t){return}}function je(e){var r;let t=ce({ssrSessionId:e.ssrSessionId}),n=(r=t.getSessionId())!=null?r:"local",a=_t(),d=import("@sentientui/core/local").then(i=>{let c=i;return c.LOCAL_ENGINE_AVAILABLE?(Be||(Be=!0,console.info(Fe)),c):(pe||(pe=!0,console.error(we)),null)}).catch(()=>(pe||(pe=!0,console.error(we)),null)),s=null;function o(i){let c=document.documentElement;c.dataset.sentientPersona===void 0&&(c.dataset.sentientPersona=i.persona,c.dataset.sentientConfidence=(0,fe.confidenceBand)(i.confidence))}return{isLocal:!0,async decide(i){var g,y,f;let c=await d;if(!c)return null;let l=c.createLocalEngine({sessionId:n,forcedPersona:a}).decide(i);return s=F(b({},l),{layoutOrder:(y=(g=l.layoutOrder)!=null?g:s==null?void 0:s.layoutOrder)!=null?y:null,slots:b(b({},(f=s==null?void 0:s.slots)!=null?f:{}),l.slots)}),se(e.apiKey||"local",{v:1,persona:s.persona,band:(0,fe.confidenceBand)(s.confidence),slots:s.slots,layoutOrder:s.layoutOrder,savedAt:Date.now()}),o(l),l},getSlotResult(i){var c,l,g;return(g=(l=s==null?void 0:s.slots[i])!=null?l:(c=e.initialSlots)==null?void 0:c[i])!=null?g:null},getPersona(){return s?{persona:s.persona,confidence:s.confidence,band:(0,fe.confidenceBand)(s.confidence)}:null},async assign(i,c){var y;let l=await d;return!l||!c||c.length===0?c!=null&&c[0]?{variantId:c[0],assignmentTtlMs:0}:null:{variantId:(y=l.createLocalEngine({sessionId:n,forcedPersona:a}).decide({components:[{id:i,variantIds:c}]}).assignments[i])!=null?y:c[0],assignmentTtlMs:0}},track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>t.destroy()}}var We="https://api.sentient-ui.com/v1/events",ie=new Map,Rt=null;function Ie(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(e){}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}var H={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 kt(){try{let e={},t=new URLSearchParams(window.location.search);for(let[n,a]of t)n.startsWith("utm_")&&(e[n]=a);return e}catch(e){return{}}}function qe(e){return e.replace(/\/events\/?$/,"")}function xe(){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(t=>t==="1"||t==="yes")}function Ot(e){var o;let t=qe((o=e.ingestUrl)!=null?o:We),n={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},a={track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},getAssignment:()=>null,fetchWeights:()=>Promise.resolve([]),async assign(r,i,c){try{let l=new URLSearchParams({componentId:r});for(let f of i!=null?i:[])l.append("variantIds[]",f);let g=await fetch(`${t}/winner?${l.toString()}`,{headers:n});return g.ok?{variantId:(await g.json()).variantId,assignmentTtlMs:0}:i!=null&&i[0]?{variantId:i[0],assignmentTtlMs:0}:null}catch(l){return i!=null&&i[0]?{variantId:i[0],assignmentTtlMs:0}:null}},decide:()=>Promise.resolve(null),getSlotResult:()=>null,getPersona:()=>null,getGraph:()=>({pageNodes:[],capturedAt:0}),dispose:()=>{},destroy:()=>{}},d={track:r=>a.track(r),goal:(r,i,c,l)=>a.goal(r,i,c,l),componentGoal:(r,i,c)=>a.componentGoal(r,i,c),identify:r=>a.identify(r),getAssignment:(r,i)=>a.getAssignment(r,i),assign:(r,i,c,l)=>a.assign(r,i,c,l),decide:r=>a.decide(r),getSlotResult:r=>a.getSlotResult(r),getPersona:()=>a.getPersona(),fetchWeights:()=>a.fetchWeights(),getGraph:()=>a.getGraph(),dispose:()=>a.dispose(),destroy:()=>a.destroy()};function s(r){a=r}return{proxy:d,setInner:s}}function Je(e){var V,X,Z,ee,h,v,A,k,L;if(typeof window=="undefined")return H;Rt=e.apiKey;let t=e.respectDoNotTrack!==!1&&xe(),n=e.consent===!1||t,a=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_");if(e.localMode===!0||!a&&e.localMode!==!1)return n?(ie.set(e.apiKey||"local",{config:e,upgrade:null}),H):(ie.set(e.apiKey||"local",{config:e,upgrade:null}),je(e));if(n){if(e.preConsentBehavior==="statistical_winner"){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."),H;let{proxy:u,setInner:p}=Ot(e);return ie.set(e.apiKey,{config:e,upgrade:t?null:p}),u}return ie.set(e.apiKey,{config:e,upgrade:null}),H}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."),H;if(e.ingestUrl==="")return console.warn("[sentient] init() called with an empty ingestUrl. SDK disabled."),H;let d=(V=e.ingestUrl)!=null?V:We,s=Date.now(),o=ce({ssrSessionId:e.ssrSessionId}),r=Ge(),i=Me({ingestUrl:d,apiKey:e.apiKey}),c=qe(d),l={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},g=W((X=navigator.userAgent)!=null?X:""),y=typeof window!="undefined"?window.location.origin:void 0,f=q((Z=document.referrer)!=null?Z:"",y),m=(ee=e.sessionSegment)!=null?ee:`${g}:${f}`,E=new Map,I=new Map,w=null,ae=u=>{for(let p of u)I.has(p.id)||I.set(p.id,ge(p))};if(e.initialSlots)for(let[u,p]of Object.entries(e.initialSlots))I.set(u,p);let G=Ee(e.apiKey);if(G)for(let[u,p]of Object.entries(G.slots))I.has(u)||I.set(u,p);let N={low:.15,medium:.5,high:.85};if(e.initialPersona)w=b({},e.initialPersona);else{let u=document.documentElement.dataset;u.sentientPersona?w={persona:u.sentientPersona,confidence:(v=N[(h=u.sentientConfidence)!=null?h:"low"])!=null?v:.15}:G&&(w={persona:G.persona,confidence:(A=N[G.band])!=null?A:.15})}if(e.initialAssignments)for(let[u,p]of Object.entries(e.initialAssignments))r.set(u,m,{variantId:p,assignedAt:Date.now(),segment:m,confidence:1});let R=Promise.resolve(),$=o.getSessionId();if($){let u=J((k=document.referrer)!=null?k:""),p=b(b({sessionId:$,deviceClass:g,trafficSource:f,referrerDomain:u,utmParams:kt(),timeOfDay:z(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:o.isEphemeral(),automation:typeof navigator!="undefined"&&navigator.webdriver===!0||le((L=navigator.userAgent)!=null?L:"")},e.userId?{userId:e.userId}:{}),e.country?{country:e.country}:{});try{R=fetch(`${c}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(p),headers:l}).then(S=>{S.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")}).catch(()=>{})}catch(S){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:i});let Q={goal(u,p={},S=1,O=0){let x=o.getSessionId();if(!x)return;let T=Ie();R.then(()=>{fetch(`${c}/goals`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:x,name:u,metadata:p,weight:S,stepIndex:O,goalId:T}),headers:l}).catch(()=>{})})},componentGoal(u,p,S){var D,U,P;let O=o.getSessionId();if(!O)return;let x=r.get(u,m),T=x?null:(D=I.get(u))!=null?D:null;if(!x&&T===null){e.debug&&console.warn(`[sentient] componentGoal("${u}"): no assignment or slot decision yet \u2014 render its <Adaptive>/adaptive hook or call assign()/decide() before recording a goal.`);return}let K=x?x.variantId:be(T),M={id:Ie(),sessionId:O,projectId:e.apiKey,componentId:u,variantId:K,eventType:"goal_achieved",goalType:p,payload:b({reward:(U=S==null?void 0:S.reward)!=null?U:1},(P=S==null?void 0:S.metadata)!=null?P:{}),timestamp:Date.now(),timeInSession:Date.now()-s};e.debug&&console.log("[sentient] componentGoal",M),R.then(()=>i.push(M))},identify(u){let p=o.getSessionId();p&&R.then(()=>{fetch(`${c}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify({sessionId:p,userId:u,ephemeral:o.isEphemeral()}),headers:l}).catch(()=>{})})},track(u){let p=o.getSessionId();if(!p)return;let S=F(b({},u),{id:Ie(),sessionId:p,timestamp:Date.now(),timeInSession:Date.now()-s});e.debug&&console.log("[sentient] track",S),R.then(()=>i.push(S))},getAssignment(u,p){return r.get(u,p)},async assign(u,p,S,O){let x=o.getSessionId();if(!x)return null;let T=r.get(u,m);if(T&&(p!=null&&p.length||T.content!==void 0))return{variantId:T.variantId,assignmentTtlMs:0,content:T.content};let K=E.get(u);if(K)return K;let M=(async()=>{await R;try{let D={sessionId:x,componentId:u,variantIds:p};O!==void 0?D.agentDataByVariant=O:S!==void 0&&(D.agentData=S);let U=await fetch(`${c}/assign`,{method:"POST",body:JSON.stringify(D),headers:l});if(!U.ok)return null;let P=await U.json();return r.set(u,m,{variantId:P.variantId,assignedAt:Date.now(),segment:m,confidence:1,content:P.content}),P}catch(D){return null}finally{E.delete(u)}})();return E.set(u,M),M},async decide(u){var O,x,T,K,M,D,U,P,Re,ke;let p=o.getSessionId();if(!p)return null;let S=(O=u.slots)!=null?O:[];await R;try{let B={sessionId:p};u.sections&&u.sections.length>0&&(B.sections=u.sections.map(_=>({id:_}))),B.components=(x=u.components)!=null?x:[],S.length>0&&(B.slots=S.map(ue)),u.slotsFrom==="registry"&&(B.slotsFrom="registry"),u.v&&(B.v=u.v);let Oe=await fetch(`${c}/decide`,{method:"POST",body:JSON.stringify(B),headers:l});if(!Oe.ok)return ae(S),null;let C=await Oe.json(),te={};for(let _ of S)te[_.id]=(K=(T=C.slots)==null?void 0:T[_.id])!=null?K:ge(_);if(C.slots)for(let[_,ne]of Object.entries(C.slots))_ in te||(te[_]=ne);for(let[_,ne]of Object.entries(te))I.set(_,ne);w={persona:(M=C.persona)!=null?M:"unknown",confidence:(D=C.confidence)!=null?D:0};for(let[_,ne]of Object.entries((U=C.assignments)!=null?U:{}))r.set(_,m,{variantId:ne,assignedAt:Date.now(),segment:m,confidence:1});return se(e.apiKey,b({v:1,persona:w.persona,band:(0,Ce.confidenceBand)(w.confidence),slots:Object.fromEntries(I),layoutOrder:(P=C.layoutOrder)!=null?P:null,savedAt:Date.now()},C.slotConfig?{slotConfig:C.slotConfig}:{})),b(b({layoutOrder:(Re=C.layoutOrder)!=null?Re:null,assignments:(ke=C.assignments)!=null?ke:{},slots:te,persona:w.persona,confidence:w.confidence},C.slotConfig?{slotConfig:C.slotConfig}:{}),C.goals?{goals:C.goals}:{})}catch(B){return ae(S),null}},getSlotResult(u){var p;return(p=I.get(u))!=null?p:null},getPersona(){return w?{persona:w.persona,confidence:w.confidence,band:(0,Ce.confidenceBand)(w.confidence)}:null},async fetchWeights(){var u;try{let p=await fetch(`${c}/weights`,{headers:l});return p.ok?(u=(await p.json()).components)!=null?u:[]:[]}catch(p){return[]}},getGraph(){return{pageNodes:[],capturedAt:0}},dispose(){i.destroy(),e.debug&&console.log("[sentient] disposed")},destroy(){i.destroy(),o.destroy();try{localStorage.removeItem(re+e.apiKey),localStorage.removeItem(ye(e.apiKey))}catch(u){}e.debug&&console.log("[sentient] destroyed")}};if(ie.set(e.apiKey,{config:e,upgrade:null}),e.debug){let u=window;u.__sentient&&(u.__sentient.client=Q)}return Q}var ze=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],Dt=[["pricing",/\b(pricing|price|plans?|subscriptions?|per month|\/mo|tier)\b/i],["faq",/\b(faq|frequently asked|common questions?)\b/i],["comparison",/\b(compare|comparison|versus|vs\.)\b/i],["social_proof",/\b(testimonial|reviews?|trusted by|loved by|customers?|logos|rated|case stud)\b/i],["trust",/\b(security|guarantee|privacy|compliance|secure|gdpr|soc ?2|encrypt)\b/i],["features",/\b(features?|how it works|benefits?|capabilit|what you get)\b/i]],Nt=[["pricing",/(?:[$€£]\s?\d[\d,.]*\s*(?:\/|per\s)\s*(?:mo|month|yr|year|seat|user))|(?:\b(?:starter|basic|pro|growth|premium|enterprise)\b[^.]{0,60}[$€£]\s?\d)/i],["social_proof",/(?:★{2,})|(?:\b\d(?:\.\d)?\s*(?:out of|\/)\s*5\b)|(?:\brated\b)|(?:["“][^"”]{20,160}["”]\s*[—–-]\s*[A-Z][a-z]+)/],["trust",/\b(?:money[- ]back guarantee|refund(?:s)? within|encrypted|soc ?2|iso ?27001|gdpr[- ]compliant|cancel anytime)\b/i],["comparison",/\b(?:vs|versus)\b\.?[^.!?]{0,80}\b(?:compare|comparison|plans?|features?|alternative)\b|\bhow (?:we|it) compares?\b/i]];function Pt(e){var n;let t=e.querySelector("h1, h2, h3");return((n=t==null?void 0:t.textContent)!=null?n:"").slice(0,160)}function Lt(e){if(e.tag==="nav"||e.tag==="footer")return{type:"navigation",strength:"weak"};let t=`${e.idClass} ${e.headingText}`.toLowerCase();for(let[n,a]of Dt)if(a.test(t))return{type:n,strength:"strong"};for(let[n,a]of Nt)if(a.test(e.bodyText))return{type:n,strength:"strong"};return e.actionCount>=1&&e.textLength>0&&e.textLength<200?{type:"cta",strength:"weak"}:e.tag==="header"?{type:"hero",strength:"weak"}:/\b(hero|headline|banner)\b/i.test(t)?{type:"hero",strength:"weak"}:{type:"generic",strength:"weak"}}function Mt(e){var n,a;let t=((n=e.textContent)!=null?n:"").replace(/\s+/g," ").trim();return{tag:e.tagName.toLowerCase(),idClass:`${e.id} ${String((a=e.className)!=null?a:"")}`,headingText:Pt(e),bodyText:t.slice(0,2e3),actionCount:e.querySelectorAll('a, button, [role="button"]').length,textLength:t.length}}function Ye(e){return Lt(Mt(e)).type}var Ut=new Set(["SECTION","ARTICLE","MAIN","DIV"]),Gt="h1, h2, h3",$t={scan:async()=>({nodes:[],edges:[],scannedAt:0}),observe:()=>{},getProminenceScore:()=>0,destroy:()=>{}};function Ae(e,t,n){return n<=t?0:Math.max(0,Math.min(1,(e-t)/(n-t)))}function Kt(e){var t,n,a;try{let d=e;for(let s of Object.keys(d)){if(!s.startsWith("__reactFiber")&&!s.startsWith("__reactInternalInstance"))continue;let o=d[s],r=(a=(t=o==null?void 0:o.type)==null?void 0:t.displayName)!=null?a:(n=o==null?void 0:o.type)==null?void 0:n.name;if(r&&r.length>1)return r}}catch(d){}}function Bt(e){let t={};for(let n of Array.from(e.attributes))n.name.startsWith("data-")&&(t[n.name]=n.value);return t}var He=new Set(ze);function Ft(e){let t=e.getAttribute("data-sentient-type");if(t&&He.has(t))return t;let n=e.getAttribute("role");return n&&He.has(n)?n:Ye(e)}function jt(e){var t,n;return(n=(t=e.getAttribute("data-sentient-id"))!=null?t:e.getAttribute("id"))!=null?n:e.tagName.toLowerCase()}function Wt(e){let t=0,n=e.parentElement;for(;n;)t++,n=n.parentElement;return t}function Te(e,t){var a,d,s;let n=e.querySelector(Gt);return{componentId:jt(e),semanticType:Ft(e),ariaLabel:(a=e.getAttribute("aria-label"))!=null?a:void 0,headingText:(s=(d=n==null?void 0:n.textContent)==null?void 0:d.trim())!=null?s:void 0,isAboveFold:e.getBoundingClientRect().top<window.innerHeight,prominenceScore:t(e),depth:Wt(e),reactComponentName:Kt(e),dataAttributes:Bt(e)}}function Qe(e){var s;let t=[],n=new Set,a="__root__",d=new Map;for(let[o,r]of e){let i=o.parentElement,c=a;for(;i;){if(e.has(i)){c=e.get(i);let g=e.get(o),y=`${c}->${g}`;!n.has(y)&&c!==g&&(n.add(y),t.push({fromComponentId:c,toComponentId:g,weight:.6}));break}i=i.parentElement}let l=(s=d.get(c))!=null?s:[];l.push(o),d.set(c,l)}for(let o of d.values())if(!(o.length<2))for(let r=0;r<o.length;r++)for(let i=r+1;i<o.length;i++){let c=e.get(o[r]),l=e.get(o[i]);if(c===l)continue;let g=`${c}->${l}::sib`,y=`${l}->${c}::sib`;n.has(g)||(n.add(g),t.push({fromComponentId:c,toComponentId:l,weight:.3})),n.has(y)||(n.add(y),t.push({fromComponentId:l,toComponentId:c,weight:.3}))}return t}function qt(e){let t=[],n=new Set,a=new Map;return document.querySelectorAll("[data-sentient-id]").forEach(o=>{if(o instanceof Element&&!n.has(o)){n.add(o);let r=Te(o,e);t.push(r),a.set(o,r.componentId)}}),document.querySelectorAll("section, article, main, aside").forEach(o=>{if(!(o instanceof Element)||n.has(o))return;let r=o.hasAttribute("aria-label"),i=o.hasAttribute("data-sentient-id");if(!r&&!i)return;n.add(o);let c=Te(o,e);t.push(c),a.set(o,c.componentId)}),{nodes:t,edges:Qe(a)}}function Ve(){if(typeof window=="undefined")return $t;let e=null,t=0,n=null,a=r=>{try{let i=window.getComputedStyle(r),c=parseFloat(i.fontSize)||12,l=parseFloat(i.zIndex)||0,g=r.getBoundingClientRect(),y=Math.max(g.top,0),f=window.innerHeight||1,m=1/(y/f+1),E=Ae(c,12,48)*.4+Ae(m,0,1)*.4+Ae(l,0,100)*.2;return Math.max(0,Math.min(1,E))}catch(i){return .5}};return{scan:()=>new Promise(r=>{let i=()=>{let{nodes:c,edges:l}=qt(a);r({nodes:c,edges:l,scannedAt:Date.now()})};try{typeof requestIdleCallback=="function"?t=requestIdleCallback(i,{timeout:100}):i()}catch(c){i()}}),observe:r=>{n=r;try{e=new MutationObserver(i=>{let c=[],l=new Map;for(let g of i)g.type==="childList"&&g.addedNodes.forEach(y=>{if(!(y instanceof Element)||!Ut.has(y.tagName))return;let f=y.hasAttribute("data-sentient-id"),m=y.hasAttribute("aria-label");if(!f&&!m)return;let E=Te(y,a);c.push(E),l.set(y,E.componentId)});c.length>0&&n&&n({nodes:c,edges:Qe(l),addedAt:Date.now()})}),e.observe(document.body,{childList:!0,subtree:!0})}catch(i){}},getProminenceScore:a,destroy:()=>{if(e&&(e.disconnect(),e=null),t&&typeof cancelIdleCallback=="function")try{cancelIdleCallback(t)}catch(r){}t=0,n=null}}}var _e="_snt_graph_nodes",Xe="_snt_graph_edges",Jt={pricing:["features","faq"],features:["pricing"],faq:["pricing"],social_proof:["cta"],cta:["social_proof","hero","trust"],hero:["cta"],comparison:["pricing"],trust:["cta"]};function zt(e){var t;return(t=Jt[e])!=null?t:[]}function Yt(e,t){try{let n=localStorage.getItem(e);return n?JSON.parse(n):t}catch(n){return t}}function Ht(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch(n){}}var Qt=new Set(["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"]);function Vt(e){return Qt.has(e)?e:"generic"}function Xt(e,t,n){let a=`${e}:${t}:${n.join(",")}`,d=5381;for(let s=0;s<a.length;s++)d=(d<<5)+d+a.charCodeAt(s)&4294967295;return(d>>>0).toString(16).padStart(8,"0")}function Ze(e){let t=new Map,n=new Map,a=()=>{typeof window!="undefined"&&Ht(_e,[...t.values()])},d=s=>{var o;try{let r=JSON.parse(s);t.clear();for(let i of(o=r.pageNodes)!=null?o:[])t.set(i.componentId,i)}catch(r){}};if(typeof window!="undefined"){let s=Yt(_e,[]);for(let o of s)t.set(o.componentId,o);try{localStorage.removeItem(Xe)}catch(o){}}return{addPageNode(s){t.set(s.componentId,s),a()},addStructuralEdge(s){let o=`${s.fromComponentId}->${s.toComponentId}`;n.set(o,s)},syncOnce(){var o,r;if(!(e!=null&&e.syncUrl)||typeof window=="undefined")return;let s=[...t.values()];if(s.length!==0)try{let i=new Map;for(let f of s){let m=(o=i.get(f.semanticType))!=null?o:[];m.push(f),i.set(f.semanticType,m)}let c=[],l=new Set;for(let f of s)for(let m of zt(f.semanticType)){let E=(r=i.get(m))!=null?r:[];for(let I of E){if(I.componentId===f.componentId)continue;let w=`semantic:${f.componentId}->${I.componentId}`;l.has(w)||(l.add(w),c.push({fromComponentId:f.componentId,toComponentId:I.componentId,type:"semantic",weight:.4,confidence:.9}))}}let g=new Set(s.map(f=>f.componentId));for(let f of n.values()){if(!g.has(f.fromComponentId)||!g.has(f.toComponentId))continue;let m=`structural:${f.fromComponentId}->${f.toComponentId}`;l.has(m)||(l.add(m),c.push({fromComponentId:f.fromComponentId,toComponentId:f.toComponentId,type:"structural",weight:f.weight,confidence:1}))}let y={pageUrl:window.location.href,nodes:s.map(f=>{let m=Vt(f.semanticType);return{componentId:f.componentId,semanticType:m,answers:f.answers,contentHash:Xt(f.componentId,m,f.answers),prominenceScore:f.prominenceScore,depthInPage:f.depth}}),edges:c};fetch(e.syncUrl,{method:"POST",keepalive:!0,headers:b({"Content-Type":"application/json"},e.apiKey?{Authorization:`Bearer ${e.apiKey}`}:{}),body:JSON.stringify(y)}).catch(()=>{})}catch(i){}},snapshot(){return{pageNodes:[...t.values()],capturedAt:Date.now()}},serialize(){return JSON.stringify({pageNodes:[...t.values()]})},restore:d,destroy(){if(typeof window!="undefined")try{localStorage.removeItem(_e),localStorage.removeItem(Xe)}catch(s){}}}}var Zt="https://api.sentient-ui.com/v1/events";function en(){try{let e=document.cookie.match(/(?:^|; )_snt_uid=([^;]*)/);return e?decodeURIComponent(e[1]):void 0}catch(e){return}}function tn(e){var c;let t=Je(e),n=e.respectDoNotTrack!==!1&&xe(),a=e.consent===!1||n;if(!e.graph||a||typeof window=="undefined")return t;let d=Ve(),s=(c=e.ingestUrl)!=null?c:Zt,o=Ze({syncUrl:s.replace(/\/events\/?$/,"/graph/sync"),apiKey:e.apiKey,projectId:e.apiKey,sessionId:en()});try{let l=localStorage.getItem("_snt_graph_nodes");l&&o.restore(JSON.stringify({pageNodes:JSON.parse(l)}))}catch(l){}d.scan().then(l=>{for(let g of l.nodes)o.addPageNode({id:g.componentId,componentId:g.componentId,semanticType:g.semanticType,answers:g.headingText?[g.headingText]:[],prominenceScore:g.prominenceScore,depth:g.depth});for(let g of l.edges)o.addStructuralEdge(g);o.syncOnce()});let r=null,i=()=>{r!==null&&clearTimeout(r),r=setTimeout(()=>{r=null,o.syncOnce()},500)};return d.observe(l=>{for(let g of l.nodes)o.addPageNode({id:g.componentId,componentId:g.componentId,semanticType:g.semanticType,answers:g.headingText?[g.headingText]:[],prominenceScore:g.prominenceScore,depth:g.depth});for(let g of l.edges)o.addStructuralEdge(g);i()}),F(b({},t),{getGraph:()=>o.snapshot(),dispose:()=>{r!==null&&clearTimeout(r),d.destroy(),o.destroy(),t.dispose()},destroy:()=>{r!==null&&clearTimeout(r),d.destroy(),o.destroy(),t.destroy()}})}0&&(module.exports={deriveSessionSegment,detectDeviceClass,detectTimeOfDay,detectTrafficSource,init,referrerDomainFromReferer});
|
package/dist/index-graph.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as v,
|
|
1
|
+
import{a as v,d as w}from"./chunk-KZHVBFG7.mjs";import{h as N,j as T}from"./chunk-CWUFS37B.mjs";import{d as R,e as P,f as D,g as k,h as G}from"./chunk-P5ZTJLZE.mjs";import{a as h,b}from"./chunk-HGGX55FR.mjs";var $=new Set(["SECTION","ARTICLE","MAIN","DIV"]),L="h1, h2, h3",U={scan:async()=>({nodes:[],edges:[],scannedAt:0}),observe:()=>{},getProminenceScore:()=>0,destroy:()=>{}};function S(e,t,o){return o<=t?0:Math.max(0,Math.min(1,(e-t)/(o-t)))}function j(e){var t,o,g;try{let u=e;for(let s of Object.keys(u)){if(!s.startsWith("__reactFiber")&&!s.startsWith("__reactInternalInstance"))continue;let n=u[s],r=(g=(t=n==null?void 0:n.type)==null?void 0:t.displayName)!=null?g:(o=n==null?void 0:n.type)==null?void 0:o.name;if(r&&r.length>1)return r}}catch(u){}}function F(e){let t={};for(let o of Array.from(e.attributes))o.name.startsWith("data-")&&(t[o.name]=o.value);return t}var A=new Set(v);function K(e){let t=e.getAttribute("data-sentient-type");if(t&&A.has(t))return t;let o=e.getAttribute("role");return o&&A.has(o)?o:w(e)}function q(e){var t,o;return(o=(t=e.getAttribute("data-sentient-id"))!=null?t:e.getAttribute("id"))!=null?o:e.tagName.toLowerCase()}function z(e){let t=0,o=e.parentElement;for(;o;)t++,o=o.parentElement;return t}function I(e,t){var g,u,s;let o=e.querySelector(L);return{componentId:q(e),semanticType:K(e),ariaLabel:(g=e.getAttribute("aria-label"))!=null?g:void 0,headingText:(s=(u=o==null?void 0:o.textContent)==null?void 0:u.trim())!=null?s:void 0,isAboveFold:e.getBoundingClientRect().top<window.innerHeight,prominenceScore:t(e),depth:z(e),reactComponentName:j(e),dataAttributes:F(e)}}function _(e){var s;let t=[],o=new Set,g="__root__",u=new Map;for(let[n,r]of e){let i=n.parentElement,c=g;for(;i;){if(e.has(i)){c=e.get(i);let a=e.get(n),m=`${c}->${a}`;!o.has(m)&&c!==a&&(o.add(m),t.push({fromComponentId:c,toComponentId:a,weight:.6}));break}i=i.parentElement}let d=(s=u.get(c))!=null?s:[];d.push(n),u.set(c,d)}for(let n of u.values())if(!(n.length<2))for(let r=0;r<n.length;r++)for(let i=r+1;i<n.length;i++){let c=e.get(n[r]),d=e.get(n[i]);if(c===d)continue;let a=`${c}->${d}::sib`,m=`${d}->${c}::sib`;o.has(a)||(o.add(a),t.push({fromComponentId:c,toComponentId:d,weight:.3})),o.has(m)||(o.add(m),t.push({fromComponentId:d,toComponentId:c,weight:.3}))}return t}function B(e){let t=[],o=new Set,g=new Map;return document.querySelectorAll("[data-sentient-id]").forEach(n=>{if(n instanceof Element&&!o.has(n)){o.add(n);let r=I(n,e);t.push(r),g.set(n,r.componentId)}}),document.querySelectorAll("section, article, main, aside").forEach(n=>{if(!(n instanceof Element)||o.has(n))return;let r=n.hasAttribute("aria-label"),i=n.hasAttribute("data-sentient-id");if(!r&&!i)return;o.add(n);let c=I(n,e);t.push(c),g.set(n,c.componentId)}),{nodes:t,edges:_(g)}}function x(){if(typeof window=="undefined")return U;let e=null,t=0,o=null,g=r=>{try{let i=window.getComputedStyle(r),c=parseFloat(i.fontSize)||12,d=parseFloat(i.zIndex)||0,a=r.getBoundingClientRect(),m=Math.max(a.top,0),p=window.innerHeight||1,l=1/(m/p+1),f=S(c,12,48)*.4+S(l,0,1)*.4+S(d,0,100)*.2;return Math.max(0,Math.min(1,f))}catch(i){return .5}};return{scan:()=>new Promise(r=>{let i=()=>{let{nodes:c,edges:d}=B(g);r({nodes:c,edges:d,scannedAt:Date.now()})};try{typeof requestIdleCallback=="function"?t=requestIdleCallback(i,{timeout:100}):i()}catch(c){i()}}),observe:r=>{o=r;try{e=new MutationObserver(i=>{let c=[],d=new Map;for(let a of i)a.type==="childList"&&a.addedNodes.forEach(m=>{if(!(m instanceof Element)||!$.has(m.tagName))return;let p=m.hasAttribute("data-sentient-id"),l=m.hasAttribute("aria-label");if(!p&&!l)return;let f=I(m,g);c.push(f),d.set(m,f.componentId)});c.length>0&&o&&o({nodes:c,edges:_(d),addedAt:Date.now()})}),e.observe(document.body,{childList:!0,subtree:!0})}catch(i){}},getProminenceScore:g,destroy:()=>{if(e&&(e.disconnect(),e=null),t&&typeof cancelIdleCallback=="function")try{cancelIdleCallback(t)}catch(r){}t=0,o=null}}}var E="_snt_graph_nodes",O="_snt_graph_edges",H={pricing:["features","faq"],features:["pricing"],faq:["pricing"],social_proof:["cta"],cta:["social_proof","hero","trust"],hero:["cta"],comparison:["pricing"],trust:["cta"]};function J(e){var t;return(t=H[e])!=null?t:[]}function V(e,t){try{let o=localStorage.getItem(e);return o?JSON.parse(o):t}catch(o){return t}}function Y(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch(o){}}var W=new Set(["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"]);function Q(e){return W.has(e)?e:"generic"}function X(e,t,o){let g=`${e}:${t}:${o.join(",")}`,u=5381;for(let s=0;s<g.length;s++)u=(u<<5)+u+g.charCodeAt(s)&4294967295;return(u>>>0).toString(16).padStart(8,"0")}function M(e){let t=new Map,o=new Map,g=()=>{typeof window!="undefined"&&Y(E,[...t.values()])},u=s=>{var n;try{let r=JSON.parse(s);t.clear();for(let i of(n=r.pageNodes)!=null?n:[])t.set(i.componentId,i)}catch(r){}};if(typeof window!="undefined"){let s=V(E,[]);for(let n of s)t.set(n.componentId,n);try{localStorage.removeItem(O)}catch(n){}}return{addPageNode(s){t.set(s.componentId,s),g()},addStructuralEdge(s){let n=`${s.fromComponentId}->${s.toComponentId}`;o.set(n,s)},syncOnce(){var n,r;if(!(e!=null&&e.syncUrl)||typeof window=="undefined")return;let s=[...t.values()];if(s.length!==0)try{let i=new Map;for(let p of s){let l=(n=i.get(p.semanticType))!=null?n:[];l.push(p),i.set(p.semanticType,l)}let c=[],d=new Set;for(let p of s)for(let l of J(p.semanticType)){let f=(r=i.get(l))!=null?r:[];for(let y of f){if(y.componentId===p.componentId)continue;let C=`semantic:${p.componentId}->${y.componentId}`;d.has(C)||(d.add(C),c.push({fromComponentId:p.componentId,toComponentId:y.componentId,type:"semantic",weight:.4,confidence:.9}))}}let a=new Set(s.map(p=>p.componentId));for(let p of o.values()){if(!a.has(p.fromComponentId)||!a.has(p.toComponentId))continue;let l=`structural:${p.fromComponentId}->${p.toComponentId}`;d.has(l)||(d.add(l),c.push({fromComponentId:p.fromComponentId,toComponentId:p.toComponentId,type:"structural",weight:p.weight,confidence:1}))}let m={pageUrl:window.location.href,nodes:s.map(p=>{let l=Q(p.semanticType);return{componentId:p.componentId,semanticType:l,answers:p.answers,contentHash:X(p.componentId,l,p.answers),prominenceScore:p.prominenceScore,depthInPage:p.depth}}),edges:c};fetch(e.syncUrl,{method:"POST",keepalive:!0,headers:h({"Content-Type":"application/json"},e.apiKey?{Authorization:`Bearer ${e.apiKey}`}:{}),body:JSON.stringify(m)}).catch(()=>{})}catch(i){}},snapshot(){return{pageNodes:[...t.values()],capturedAt:Date.now()}},serialize(){return JSON.stringify({pageNodes:[...t.values()]})},restore:u,destroy(){if(typeof window!="undefined")try{localStorage.removeItem(E),localStorage.removeItem(O)}catch(s){}}}}var Z="https://api.sentient-ui.com/v1/events";function ee(){try{let e=document.cookie.match(/(?:^|; )_snt_uid=([^;]*)/);return e?decodeURIComponent(e[1]):void 0}catch(e){return}}function ce(e){var c;let t=T(e),o=e.respectDoNotTrack!==!1&&N(),g=e.consent===!1||o;if(!e.graph||g||typeof window=="undefined")return t;let u=x(),s=(c=e.ingestUrl)!=null?c:Z,n=M({syncUrl:s.replace(/\/events\/?$/,"/graph/sync"),apiKey:e.apiKey,projectId:e.apiKey,sessionId:ee()});try{let d=localStorage.getItem("_snt_graph_nodes");d&&n.restore(JSON.stringify({pageNodes:JSON.parse(d)}))}catch(d){}u.scan().then(d=>{for(let a of d.nodes)n.addPageNode({id:a.componentId,componentId:a.componentId,semanticType:a.semanticType,answers:a.headingText?[a.headingText]:[],prominenceScore:a.prominenceScore,depth:a.depth});for(let a of d.edges)n.addStructuralEdge(a);n.syncOnce()});let r=null,i=()=>{r!==null&&clearTimeout(r),r=setTimeout(()=>{r=null,n.syncOnce()},500)};return u.observe(d=>{for(let a of d.nodes)n.addPageNode({id:a.componentId,componentId:a.componentId,semanticType:a.semanticType,answers:a.headingText?[a.headingText]:[],prominenceScore:a.prominenceScore,depth:a.depth});for(let a of d.edges)n.addStructuralEdge(a);i()}),b(h({},t),{getGraph:()=>n.snapshot(),dispose:()=>{r!==null&&clearTimeout(r),u.destroy(),n.destroy(),t.dispose()},destroy:()=>{r!==null&&clearTimeout(r),u.destroy(),n.destroy(),t.destroy()}})}export{G as deriveSessionSegment,R as detectDeviceClass,k as detectTimeOfDay,P as detectTrafficSource,ce as init,D as referrerDomainFromReferer};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentientui/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"llms.txt"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@sentientui/policy": "0.
|
|
49
|
+
"@sentientui/policy": "0.3.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/node": "^22.10.2",
|
package/dist/chunk-LMHLAXPA.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var c=["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"],i=[["pricing",/\b(pricing|price|plans?|subscriptions?|per month|\/mo|tier)\b/i],["faq",/\b(faq|frequently asked|common questions?)\b/i],["comparison",/\b(compare|comparison|versus|vs\.)\b/i],["social_proof",/\b(testimonial|reviews?|trusted by|loved by|customers?|logos|rated|case stud)\b/i],["trust",/\b(security|guarantee|privacy|compliance|secure|gdpr|soc ?2|encrypt)\b/i],["features",/\b(features?|how it works|benefits?|capabilit|what you get)\b/i]];function a(e){var r;let t=e.querySelector("h1, h2, h3");return((r=t==null?void 0:t.textContent)!=null?r:"").slice(0,160)}function s(e){var n;let t=e.querySelectorAll('a, button, [role="button"]').length,r=((n=e.textContent)!=null?n:"").trim().length;return t>=1&&r>0&&r<200}function u(e){let t=e.tagName.toLowerCase();if(t==="nav"||t==="footer")return"navigation";let r=`${e.id} ${e.className} ${a(e)}`.toLowerCase();for(let[n,o]of i)if(o.test(r))return n;return s(e)?"cta":t==="header"||/\b(hero|headline|banner)\b/i.test(r)?"hero":"generic"}export{c as a,u as b};
|