@sentientui/core 0.42.0 → 0.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/chunk-MDLYXFGL.mjs +2 -0
- package/dist/chunk-MDLYXFGL.mjs.map +1 -0
- package/dist/chunk-OT77D5DV.mjs +2 -0
- package/dist/chunk-OT77D5DV.mjs.map +1 -0
- package/dist/{index-Bz4QCRmF.d.cts → index-CPjHmDZO.d.cts} +10 -2
- package/dist/{index-C36TXfry.d.ts → index-DnFJAMuK.d.ts} +10 -2
- package/dist/index-engagement.js.map +1 -1
- package/dist/index-engagement.mjs +1 -1
- package/dist/index-graph.d.cts +2 -2
- package/dist/index-graph.d.ts +2 -2
- package/dist/index-graph.js +1 -1
- package/dist/index-graph.js.map +1 -1
- package/dist/index-graph.mjs +1 -1
- package/dist/index-local.d.cts +1 -1
- package/dist/index-local.d.ts +1 -1
- package/dist/index-server.d.cts +37 -2
- package/dist/index-server.d.ts +37 -2
- package/dist/index-server.js +1 -1
- package/dist/index-server.js.map +1 -1
- package/dist/index-server.mjs +1 -1
- package/dist/index-server.mjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-3HMJERH4.mjs +0 -2
- package/dist/chunk-3HMJERH4.mjs.map +0 -1
- package/dist/chunk-QPJ6TL6L.mjs +0 -2
- package/dist/chunk-QPJ6TL6L.mjs.map +0 -1
package/dist/index-graph.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as v}from"./chunk-WKXD7KI3.mjs";import{a as _,g as O}from"./chunk-Z6ILOYBD.mjs";import{A as ze,B as He,C as Ve,D as Ye,E as We,F as Je,G as Xe,H as Qe,I as Ze,J as et,K as tt,O as se,P as M,Q as P,R as ae,T as D,d as ne,e as oe,f as re,m as Oe,n as Me,o as Pe,p as De,q as Ge,r as ke,s as $e,t as Le,u as je,v as Ue,w as Ke,x as Fe,y as Be,z as qe}from"./chunk-QPJ6TL6L.mjs";import{a as B,b as q,c as z,d as H}from"./chunk-JNQY3XNF.mjs";import"./chunk-LCYGZNFI.mjs";import"./chunk-BGZLWZUG.mjs";import"./chunk-EVF5PQ4U.mjs";import{i as V,j as Y,k as W,n as J,o as X,q as Q,r as Z,s as ee,t as te}from"./chunk-3HMJERH4.mjs";import{a as R,b as w,c as A}from"./chunk-WUFFNQHQ.mjs";import{a as I,b}from"./chunk-TMCGHANO.mjs";var G="_snt_graph_edges",ie={pricing:["features","faq"],features:["pricing"],faq:["pricing"],social_proof:["cta"],cta:["social_proof","hero","trust"],hero:["cta"],comparison:["pricing"],trust:["cta"]};function ce(e){var t;return(t=ie[e])!=null?t:[]}function de(e,t){try{let n=localStorage.getItem(e);return n?JSON.parse(n):t}catch(n){return t}}function pe(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch(n){}}var ue=new Set(["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"]);function le(e){return ue.has(e)?e:"generic"}function k(e){try{let t=new URL(e);return`${t.origin}${t.pathname}`}catch(t){return"/"}}function me(e,t,n){let a=`${e}:${t}:${n.join(",")}`,s=5381;for(let o=0;o<a.length;o++)s=(s<<5)+s+a.charCodeAt(o)&4294967295;return(s>>>0).toString(16).padStart(8,"0")}function $(e){let t=new Map,n=new Map,a=`_snt_graph_nodes${R(e==null?void 0:e.apiKey)}`,s=()=>{typeof window!="undefined"&&pe(a,[...t.values()])};if(typeof window!="undefined"){let o=de(a,[]);for(let i of o)t.set(i.componentId,i);try{localStorage.removeItem(G)}catch(i){}}return{addPageNode(o){t.set(o.componentId,o),s()},addStructuralEdge(o){let i=`${o.fromComponentId}->${o.toComponentId}`;n.set(i,o)},syncOnce(){var i,c;if(!(e!=null&&e.syncUrl)||typeof window=="undefined")return;let o=[...t.values()];if(o.length!==0)try{let l=new Map;for(let r of o){let d=(i=l.get(r.semanticType))!=null?i:[];d.push(r),l.set(r.semanticType,d)}let u=[],m=new Set;for(let r of o)for(let d of ce(r.semanticType)){let p=(c=l.get(d))!=null?c:[];for(let S of p){if(S.componentId===r.componentId)continue;let f=`semantic:${r.componentId}->${S.componentId}`;m.has(f)||(m.add(f),u.push({fromComponentId:r.componentId,toComponentId:S.componentId,type:"semantic",weight:.4,confidence:.9}))}}let g=new Set(o.map(r=>r.componentId));for(let r of n.values()){if(!g.has(r.fromComponentId)||!g.has(r.toComponentId))continue;let d=`structural:${r.fromComponentId}->${r.toComponentId}`;m.has(d)||(m.add(d),u.push({fromComponentId:r.fromComponentId,toComponentId:r.toComponentId,type:"structural",weight:r.weight,confidence:1}))}let h=b(I(I({pageUrl:k(window.location.href)},e.sessionId?{sessionId:e.sessionId}:{}),e.projectId?{projectId:e.projectId}:{}),{nodes:o.map(r=>{let d=le(r.semanticType);return{componentId:r.componentId,semanticType:d,answers:r.answers,contentHash:me(r.componentId,d,r.answers),prominenceScore:r.prominenceScore,depthInPage:r.depth}}),edges:u});fetch(e.syncUrl,{method:"POST",keepalive:!0,headers:I({"Content-Type":"application/json"},e.apiKey?{Authorization:`Bearer ${e.apiKey}`}:{}),body:JSON.stringify(h)}).catch(()=>{})}catch(l){}},snapshot(){return{pageNodes:[...t.values()],capturedAt:Date.now()}},destroy(){if(typeof window!="undefined")try{localStorage.removeItem(a),localStorage.removeItem(G)}catch(o){}}}}var fe=new Set(["SECTION","ARTICLE","MAIN","DIV","ASIDE"]),ge=200,he="h1, h2, h3",Se="[data-sentient-id], section[aria-label], article[aria-label], main[aria-label], aside[aria-label]",L=30,ye=1500,Ee={scan:async()=>({nodes:[],edges:[],scannedAt:0}),observe:()=>{},getProminenceScore:()=>0,destroy:()=>{}};function j(e,t,n){return n<=t?0:Math.max(0,Math.min(1,(e-t)/(n-t)))}function Ie(e){var t,n,a;try{let s=e;for(let o of Object.keys(s)){if(!o.startsWith("__reactFiber")&&!o.startsWith("__reactInternalInstance"))continue;let i=s[o],c=(a=(t=i==null?void 0:i.type)==null?void 0:t.displayName)!=null?a:(n=i==null?void 0:i.type)==null?void 0:n.name;if(c&&c.length>1)return c}}catch(s){}}function Ce(e){let t={};for(let n of Array.from(e.attributes))n.name.startsWith("data-")&&(t[n.name]=n.value);return t}var x=new Set(_);function be(e,t){let n=e.getAttribute("data-sentient-id"),a=n?t==null?void 0:t[n]:void 0;if(a&&x.has(a))return a;let s=e.getAttribute("data-sentient-type");if(s&&x.has(s))return s;let o=e.getAttribute("role");return o&&x.has(o)?o:O(e)}function Te(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e.charCodeAt(n)&4294967295;return(t>>>0).toString(16).padStart(8,"0")}function we(e){let t=[],n=e;for(;n;){let a=n.parentElement;if(!a){t.push(n.tagName.toLowerCase());break}let s=Array.prototype.indexOf.call(a.children,n);t.push(`${n.tagName.toLowerCase()}[${s}]`),n=a}return t.reverse().join("/")}function Ae(e){var n;let t=(n=e.getAttribute("data-sentient-id"))!=null?n:e.getAttribute("id");return t||`${e.tagName.toLowerCase()}-${Te(we(e))}`}function ve(e){let t=0,n=e.parentElement;for(;n;)t++,n=n.parentElement;return t}function N(e,t,n){var s,o,i,c;let a=e.querySelector(he);return{componentId:Ae(e),semanticType:be(e,n),ariaLabel:(s=e.getAttribute("aria-label"))!=null?s:void 0,headingText:(i=(o=a==null?void 0:a.textContent)==null?void 0:o.trim())!=null?i:void 0,isAboveFold:e.getBoundingClientRect().top<window.innerHeight,prominenceScore:t(e),depth:ve(e),reactComponentName:Ie(e),dataAttributes:Ce(e),locator:(c=v(e,e.ownerDocument))!=null?c:void 0}}function U(e){var o;let t=[],n=new Set,a="__root__",s=new Map;for(let[i,c]of e){let l=i.parentElement,u=a;for(;l;){if(e.has(l)){u=e.get(l);let g=e.get(i),h=`${u}->${g}`;!n.has(h)&&u!==g&&(n.add(h),t.push({fromComponentId:u,toComponentId:g,weight:.6}));break}l=l.parentElement}let m=(o=s.get(u))!=null?o:[];m.push(i),s.set(u,m)}for(let i of s.values()){if(i.length<2)continue;let c=i.length>L?i.slice(0,L):i;for(let l=0;l<c.length;l++)for(let u=l+1;u<c.length;u++){if(t.length>=ye)return t;let m=e.get(c[l]),g=e.get(c[u]);if(m===g)continue;let h=`${m}->${g}::sib`,r=`${g}->${m}::sib`;n.has(h)||(n.add(h),t.push({fromComponentId:m,toComponentId:g,weight:.3})),n.has(r)||(n.add(r),t.push({fromComponentId:g,toComponentId:m,weight:.3}))}}return t}function xe(e,t){let n=[],a=new Set,s=new Map;return document.querySelectorAll("[data-sentient-id]").forEach(c=>{if(c instanceof Element&&!a.has(c)){a.add(c);let l=N(c,e,t);n.push(l),s.set(c,l.componentId)}}),document.querySelectorAll("section, article, main, aside").forEach(c=>{if(!(c instanceof Element)||a.has(c))return;let l=c.hasAttribute("aria-label"),u=c.hasAttribute("data-sentient-id");if(!l&&!u)return;a.add(c);let m=N(c,e,t);n.push(m),s.set(c,m.componentId)}),{nodes:n,edges:U(s),elementToId:s}}function K(e={}){let{sectionTypes:t}=e;if(typeof window=="undefined")return Ee;let n=null,a=0,s=null,o=new Map,i=r=>{try{let d=window.getComputedStyle(r),p=parseFloat(d.fontSize)||12,S=parseFloat(d.zIndex)||0,f=r.getBoundingClientRect(),E=Math.max(f.top,0),y=window.innerHeight||1,C=1/(E/y+1),F=j(p,12,48)*.4+C*.4+j(S,0,100)*.2;return Math.max(0,Math.min(1,F))}catch(d){return .5}},c=()=>new Promise(r=>{let d=()=>{let{nodes:p,edges:S,elementToId:f}=xe(i,t);o.clear();for(let[E,y]of f)o.set(E,y);r({nodes:p,edges:S,scannedAt:Date.now()})};try{typeof requestIdleCallback=="function"?a=requestIdleCallback(d,{timeout:100}):d()}catch(p){d()}}),l=new Set,u=null,m=()=>{u=null;let r=[...l];l.clear();let d=[],p=new Set;for(let f of r){if(!f.isConnected)continue;let E=[];fe.has(f.tagName)&&(f.hasAttribute("data-sentient-id")||f.hasAttribute("aria-label"))&&E.push(f);try{f.querySelectorAll(Se).forEach(y=>E.push(y))}catch(y){}for(let y of E){if(o.has(y))continue;let C=N(y,i,t);d.push(C),p.add(C.componentId),o.set(y,C.componentId)}}if(d.length===0||!s)return;for(let f of[...o.keys()])f.isConnected||o.delete(f);let S=U(o).filter(f=>p.has(f.fromComponentId)||p.has(f.toComponentId));s({nodes:d,edges:S,addedAt:Date.now()})};return{scan:c,observe:r=>{s=r;try{n=new MutationObserver(d=>{for(let p of d)p.type==="childList"&&p.addedNodes.forEach(S=>{S instanceof Element&&l.add(S)});l.size>0&&u===null&&(u=setTimeout(m,ge))}),n.observe(document.body,{childList:!0,subtree:!0})}catch(d){}},getProminenceScore:i,destroy:()=>{if(n&&(n.disconnect(),n=null),u!==null&&clearTimeout(u),u=null,l.clear(),a&&typeof cancelIdleCallback=="function")try{cancelIdleCallback(a)}catch(r){}a=0,s=null,o.clear()}}}var Ne="https://api.sentient-ui.com/v1/events";function Re(e){var n;let t=a=>{try{let s=document.cookie.match(new RegExp(`(?:^|; )${a}=([^;]*)`));return s?decodeURIComponent(s[1]):void 0}catch(s){return}};return(n=e?t(A(e)):void 0)!=null?n:t(w)}var T=new Map;function _e(e){var r;let t=D(e),n=e.respectDoNotTrack!==!1&&P(),a=e.consent===!1||n,s=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_"),o=e.localMode===!0||!s;if(!e.graph||o||typeof window=="undefined")return t;if(a)return n||M(e.apiKey,d=>_e(d)),t;let i=T.get(e.apiKey);if(i)try{i()}catch(d){}let c=K({sectionTypes:e.sectionTypes}),l=(r=e.ingestUrl)!=null?r:Ne,u=$({syncUrl:l.replace(/\/events\/?$/,"/graph/sync"),apiKey:e.apiKey,projectId:e.apiKey,sessionId:Re(e.apiKey)});c.scan().then(d=>{for(let p of d.nodes)u.addPageNode({id:p.componentId,componentId:p.componentId,semanticType:p.semanticType,answers:e.captureDomText&&p.headingText?[p.headingText]:[],prominenceScore:p.prominenceScore,depth:p.depth});for(let p of d.edges)u.addStructuralEdge(p);u.syncOnce()});let m=null,g=()=>{m!==null&&clearTimeout(m),m=setTimeout(()=>{m=null,u.syncOnce()},500)};c.observe(d=>{for(let p of d.nodes)u.addPageNode({id:p.componentId,componentId:p.componentId,semanticType:p.semanticType,answers:e.captureDomText&&p.headingText?[p.headingText]:[],prominenceScore:p.prominenceScore,depth:p.depth});for(let p of d.edges)u.addStructuralEdge(p);g()});let h=()=>{m!==null&&(clearTimeout(m),m=null),c.destroy(),u.destroy(),T.get(e.apiKey)===h&&T.delete(e.apiKey)};return T.set(e.apiKey,h),b(I({},t),{getGraph:()=>u.snapshot(),dispose:()=>{h(),t.dispose()},destroy:()=>{h(),t.destroy()}})}export{Me as BLOCK_ALIGNS,$e as BLOCK_EMPHASES,Ue as BLOCK_FITS,Oe as BLOCK_GAPS,Ke as BLOCK_GRID_COLUMNS,Fe as BLOCK_HEADING_LEVELS,Pe as BLOCK_JUSTIFIES,ze as BLOCK_MAX_WIDTHS,qe as BLOCK_PADS,je as BLOCK_RATIOS,De as BLOCK_SIZES,Be as BLOCK_SURFACES,Le as BLOCK_TEXT_ALIGNS,ke as BLOCK_TONES,Ge as BLOCK_WEIGHTS,He as FORM_FIELD_KINDS,Ve as FORM_INPUT_TYPES,w as LEGACY_SESSION_COOKIE_NAME,Ze as MAX_BLOCK_ARMS,Qe as MAX_BLOCK_CHILDREN,Xe as MAX_BLOCK_DEPTH,Je as MAX_BLOCK_NODES,et as MAX_BLOCK_TEXT_LEN,Ye as MAX_FORM_FIELDS,We as MAX_FORM_SELECT_OPTIONS,B as SNAPSHOT_STORAGE_KEY_PREFIX,ne as STAGE_ATTRIBUTE,te as armOfResult,se as attachMicroSignalDetectors,Z as baselineResultFor,ee as baselineSlots,tt as containsFormBlock,X as deriveSessionSegment,V as detectDeviceClass,J as detectTimeOfDay,Y as detectTrafficSource,oe as exposedStage,ae as grantConsent,_e as init,P as isDoNotTrackEnabled,v as locatorFromElement,q as readSnapshot,W as referrerDomainFromReferer,H as renderPrePaintScript,k as sanitizePageUrl,A as sessionCookieName,re as setStageAttribute,Q as toWireSlot,z as writeSnapshot};
|
|
1
|
+
import{a as v}from"./chunk-WKXD7KI3.mjs";import{a as _,g as O}from"./chunk-Z6ILOYBD.mjs";import{A as ze,B as He,C as Ve,D as Ye,E as We,F as Je,G as Xe,H as Qe,I as Ze,J as et,K as tt,O as se,P as M,Q as P,R as ae,T as D,d as ne,e as oe,f as re,m as Oe,n as Me,o as Pe,p as De,q as Ge,r as ke,s as $e,t as Le,u as je,v as Ue,w as Ke,x as Fe,y as Be,z as qe}from"./chunk-OT77D5DV.mjs";import{a as B,b as q,c as z,d as H}from"./chunk-JNQY3XNF.mjs";import"./chunk-LCYGZNFI.mjs";import"./chunk-BGZLWZUG.mjs";import"./chunk-EVF5PQ4U.mjs";import{i as V,j as Y,k as W,n as J,o as X,q as Q,r as Z,s as ee,t as te}from"./chunk-MDLYXFGL.mjs";import{a as R,b as w,c as A}from"./chunk-WUFFNQHQ.mjs";import{a as I,b}from"./chunk-TMCGHANO.mjs";var G="_snt_graph_edges",ie={pricing:["features","faq"],features:["pricing"],faq:["pricing"],social_proof:["cta"],cta:["social_proof","hero","trust"],hero:["cta"],comparison:["pricing"],trust:["cta"]};function ce(e){var t;return(t=ie[e])!=null?t:[]}function de(e,t){try{let n=localStorage.getItem(e);return n?JSON.parse(n):t}catch(n){return t}}function pe(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch(n){}}var ue=new Set(["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"]);function le(e){return ue.has(e)?e:"generic"}function k(e){try{let t=new URL(e);return`${t.origin}${t.pathname}`}catch(t){return"/"}}function me(e,t,n){let a=`${e}:${t}:${n.join(",")}`,s=5381;for(let o=0;o<a.length;o++)s=(s<<5)+s+a.charCodeAt(o)&4294967295;return(s>>>0).toString(16).padStart(8,"0")}function $(e){let t=new Map,n=new Map,a=`_snt_graph_nodes${R(e==null?void 0:e.apiKey)}`,s=()=>{typeof window!="undefined"&&pe(a,[...t.values()])};if(typeof window!="undefined"){let o=de(a,[]);for(let i of o)t.set(i.componentId,i);try{localStorage.removeItem(G)}catch(i){}}return{addPageNode(o){t.set(o.componentId,o),s()},addStructuralEdge(o){let i=`${o.fromComponentId}->${o.toComponentId}`;n.set(i,o)},syncOnce(){var i,c;if(!(e!=null&&e.syncUrl)||typeof window=="undefined")return;let o=[...t.values()];if(o.length!==0)try{let l=new Map;for(let r of o){let d=(i=l.get(r.semanticType))!=null?i:[];d.push(r),l.set(r.semanticType,d)}let u=[],m=new Set;for(let r of o)for(let d of ce(r.semanticType)){let p=(c=l.get(d))!=null?c:[];for(let S of p){if(S.componentId===r.componentId)continue;let f=`semantic:${r.componentId}->${S.componentId}`;m.has(f)||(m.add(f),u.push({fromComponentId:r.componentId,toComponentId:S.componentId,type:"semantic",weight:.4,confidence:.9}))}}let g=new Set(o.map(r=>r.componentId));for(let r of n.values()){if(!g.has(r.fromComponentId)||!g.has(r.toComponentId))continue;let d=`structural:${r.fromComponentId}->${r.toComponentId}`;m.has(d)||(m.add(d),u.push({fromComponentId:r.fromComponentId,toComponentId:r.toComponentId,type:"structural",weight:r.weight,confidence:1}))}let h=b(I(I({pageUrl:k(window.location.href)},e.sessionId?{sessionId:e.sessionId}:{}),e.projectId?{projectId:e.projectId}:{}),{nodes:o.map(r=>{let d=le(r.semanticType);return{componentId:r.componentId,semanticType:d,answers:r.answers,contentHash:me(r.componentId,d,r.answers),prominenceScore:r.prominenceScore,depthInPage:r.depth}}),edges:u});fetch(e.syncUrl,{method:"POST",keepalive:!0,headers:I({"Content-Type":"application/json"},e.apiKey?{Authorization:`Bearer ${e.apiKey}`}:{}),body:JSON.stringify(h)}).catch(()=>{})}catch(l){}},snapshot(){return{pageNodes:[...t.values()],capturedAt:Date.now()}},destroy(){if(typeof window!="undefined")try{localStorage.removeItem(a),localStorage.removeItem(G)}catch(o){}}}}var fe=new Set(["SECTION","ARTICLE","MAIN","DIV","ASIDE"]),ge=200,he="h1, h2, h3",Se="[data-sentient-id], section[aria-label], article[aria-label], main[aria-label], aside[aria-label]",L=30,ye=1500,Ee={scan:async()=>({nodes:[],edges:[],scannedAt:0}),observe:()=>{},getProminenceScore:()=>0,destroy:()=>{}};function j(e,t,n){return n<=t?0:Math.max(0,Math.min(1,(e-t)/(n-t)))}function Ie(e){var t,n,a;try{let s=e;for(let o of Object.keys(s)){if(!o.startsWith("__reactFiber")&&!o.startsWith("__reactInternalInstance"))continue;let i=s[o],c=(a=(t=i==null?void 0:i.type)==null?void 0:t.displayName)!=null?a:(n=i==null?void 0:i.type)==null?void 0:n.name;if(c&&c.length>1)return c}}catch(s){}}function Ce(e){let t={};for(let n of Array.from(e.attributes))n.name.startsWith("data-")&&(t[n.name]=n.value);return t}var x=new Set(_);function be(e,t){let n=e.getAttribute("data-sentient-id"),a=n?t==null?void 0:t[n]:void 0;if(a&&x.has(a))return a;let s=e.getAttribute("data-sentient-type");if(s&&x.has(s))return s;let o=e.getAttribute("role");return o&&x.has(o)?o:O(e)}function Te(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e.charCodeAt(n)&4294967295;return(t>>>0).toString(16).padStart(8,"0")}function we(e){let t=[],n=e;for(;n;){let a=n.parentElement;if(!a){t.push(n.tagName.toLowerCase());break}let s=Array.prototype.indexOf.call(a.children,n);t.push(`${n.tagName.toLowerCase()}[${s}]`),n=a}return t.reverse().join("/")}function Ae(e){var n;let t=(n=e.getAttribute("data-sentient-id"))!=null?n:e.getAttribute("id");return t||`${e.tagName.toLowerCase()}-${Te(we(e))}`}function ve(e){let t=0,n=e.parentElement;for(;n;)t++,n=n.parentElement;return t}function N(e,t,n){var s,o,i,c;let a=e.querySelector(he);return{componentId:Ae(e),semanticType:be(e,n),ariaLabel:(s=e.getAttribute("aria-label"))!=null?s:void 0,headingText:(i=(o=a==null?void 0:a.textContent)==null?void 0:o.trim())!=null?i:void 0,isAboveFold:e.getBoundingClientRect().top<window.innerHeight,prominenceScore:t(e),depth:ve(e),reactComponentName:Ie(e),dataAttributes:Ce(e),locator:(c=v(e,e.ownerDocument))!=null?c:void 0}}function U(e){var o;let t=[],n=new Set,a="__root__",s=new Map;for(let[i,c]of e){let l=i.parentElement,u=a;for(;l;){if(e.has(l)){u=e.get(l);let g=e.get(i),h=`${u}->${g}`;!n.has(h)&&u!==g&&(n.add(h),t.push({fromComponentId:u,toComponentId:g,weight:.6}));break}l=l.parentElement}let m=(o=s.get(u))!=null?o:[];m.push(i),s.set(u,m)}for(let i of s.values()){if(i.length<2)continue;let c=i.length>L?i.slice(0,L):i;for(let l=0;l<c.length;l++)for(let u=l+1;u<c.length;u++){if(t.length>=ye)return t;let m=e.get(c[l]),g=e.get(c[u]);if(m===g)continue;let h=`${m}->${g}::sib`,r=`${g}->${m}::sib`;n.has(h)||(n.add(h),t.push({fromComponentId:m,toComponentId:g,weight:.3})),n.has(r)||(n.add(r),t.push({fromComponentId:g,toComponentId:m,weight:.3}))}}return t}function xe(e,t){let n=[],a=new Set,s=new Map;return document.querySelectorAll("[data-sentient-id]").forEach(c=>{if(c instanceof Element&&!a.has(c)){a.add(c);let l=N(c,e,t);n.push(l),s.set(c,l.componentId)}}),document.querySelectorAll("section, article, main, aside").forEach(c=>{if(!(c instanceof Element)||a.has(c))return;let l=c.hasAttribute("aria-label"),u=c.hasAttribute("data-sentient-id");if(!l&&!u)return;a.add(c);let m=N(c,e,t);n.push(m),s.set(c,m.componentId)}),{nodes:n,edges:U(s),elementToId:s}}function K(e={}){let{sectionTypes:t}=e;if(typeof window=="undefined")return Ee;let n=null,a=0,s=null,o=new Map,i=r=>{try{let d=window.getComputedStyle(r),p=parseFloat(d.fontSize)||12,S=parseFloat(d.zIndex)||0,f=r.getBoundingClientRect(),E=Math.max(f.top,0),y=window.innerHeight||1,C=1/(E/y+1),F=j(p,12,48)*.4+C*.4+j(S,0,100)*.2;return Math.max(0,Math.min(1,F))}catch(d){return .5}},c=()=>new Promise(r=>{let d=()=>{let{nodes:p,edges:S,elementToId:f}=xe(i,t);o.clear();for(let[E,y]of f)o.set(E,y);r({nodes:p,edges:S,scannedAt:Date.now()})};try{typeof requestIdleCallback=="function"?a=requestIdleCallback(d,{timeout:100}):d()}catch(p){d()}}),l=new Set,u=null,m=()=>{u=null;let r=[...l];l.clear();let d=[],p=new Set;for(let f of r){if(!f.isConnected)continue;let E=[];fe.has(f.tagName)&&(f.hasAttribute("data-sentient-id")||f.hasAttribute("aria-label"))&&E.push(f);try{f.querySelectorAll(Se).forEach(y=>E.push(y))}catch(y){}for(let y of E){if(o.has(y))continue;let C=N(y,i,t);d.push(C),p.add(C.componentId),o.set(y,C.componentId)}}if(d.length===0||!s)return;for(let f of[...o.keys()])f.isConnected||o.delete(f);let S=U(o).filter(f=>p.has(f.fromComponentId)||p.has(f.toComponentId));s({nodes:d,edges:S,addedAt:Date.now()})};return{scan:c,observe:r=>{s=r;try{n=new MutationObserver(d=>{for(let p of d)p.type==="childList"&&p.addedNodes.forEach(S=>{S instanceof Element&&l.add(S)});l.size>0&&u===null&&(u=setTimeout(m,ge))}),n.observe(document.body,{childList:!0,subtree:!0})}catch(d){}},getProminenceScore:i,destroy:()=>{if(n&&(n.disconnect(),n=null),u!==null&&clearTimeout(u),u=null,l.clear(),a&&typeof cancelIdleCallback=="function")try{cancelIdleCallback(a)}catch(r){}a=0,s=null,o.clear()}}}var Ne="https://api.sentient-ui.com/v1/events";function Re(e){var n;let t=a=>{try{let s=document.cookie.match(new RegExp(`(?:^|; )${a}=([^;]*)`));return s?decodeURIComponent(s[1]):void 0}catch(s){return}};return(n=e?t(A(e)):void 0)!=null?n:t(w)}var T=new Map;function _e(e){var r;let t=D(e),n=e.respectDoNotTrack!==!1&&P(),a=e.consent===!1||n,s=typeof e.apiKey=="string"&&e.apiKey.startsWith("pk_"),o=e.localMode===!0||!s;if(!e.graph||o||typeof window=="undefined")return t;if(a)return n||M(e.apiKey,d=>_e(d)),t;let i=T.get(e.apiKey);if(i)try{i()}catch(d){}let c=K({sectionTypes:e.sectionTypes}),l=(r=e.ingestUrl)!=null?r:Ne,u=$({syncUrl:l.replace(/\/events\/?$/,"/graph/sync"),apiKey:e.apiKey,projectId:e.apiKey,sessionId:Re(e.apiKey)});c.scan().then(d=>{for(let p of d.nodes)u.addPageNode({id:p.componentId,componentId:p.componentId,semanticType:p.semanticType,answers:e.captureDomText&&p.headingText?[p.headingText]:[],prominenceScore:p.prominenceScore,depth:p.depth});for(let p of d.edges)u.addStructuralEdge(p);u.syncOnce()});let m=null,g=()=>{m!==null&&clearTimeout(m),m=setTimeout(()=>{m=null,u.syncOnce()},500)};c.observe(d=>{for(let p of d.nodes)u.addPageNode({id:p.componentId,componentId:p.componentId,semanticType:p.semanticType,answers:e.captureDomText&&p.headingText?[p.headingText]:[],prominenceScore:p.prominenceScore,depth:p.depth});for(let p of d.edges)u.addStructuralEdge(p);g()});let h=()=>{m!==null&&(clearTimeout(m),m=null),c.destroy(),u.destroy(),T.get(e.apiKey)===h&&T.delete(e.apiKey)};return T.set(e.apiKey,h),b(I({},t),{getGraph:()=>u.snapshot(),dispose:()=>{h(),t.dispose()},destroy:()=>{h(),t.destroy()}})}export{Me as BLOCK_ALIGNS,$e as BLOCK_EMPHASES,Ue as BLOCK_FITS,Oe as BLOCK_GAPS,Ke as BLOCK_GRID_COLUMNS,Fe as BLOCK_HEADING_LEVELS,Pe as BLOCK_JUSTIFIES,ze as BLOCK_MAX_WIDTHS,qe as BLOCK_PADS,je as BLOCK_RATIOS,De as BLOCK_SIZES,Be as BLOCK_SURFACES,Le as BLOCK_TEXT_ALIGNS,ke as BLOCK_TONES,Ge as BLOCK_WEIGHTS,He as FORM_FIELD_KINDS,Ve as FORM_INPUT_TYPES,w as LEGACY_SESSION_COOKIE_NAME,Ze as MAX_BLOCK_ARMS,Qe as MAX_BLOCK_CHILDREN,Xe as MAX_BLOCK_DEPTH,Je as MAX_BLOCK_NODES,et as MAX_BLOCK_TEXT_LEN,Ye as MAX_FORM_FIELDS,We as MAX_FORM_SELECT_OPTIONS,B as SNAPSHOT_STORAGE_KEY_PREFIX,ne as STAGE_ATTRIBUTE,te as armOfResult,se as attachMicroSignalDetectors,Z as baselineResultFor,ee as baselineSlots,tt as containsFormBlock,X as deriveSessionSegment,V as detectDeviceClass,J as detectTimeOfDay,Y as detectTrafficSource,oe as exposedStage,ae as grantConsent,_e as init,P as isDoNotTrackEnabled,v as locatorFromElement,q as readSnapshot,W as referrerDomainFromReferer,H as renderPrePaintScript,k as sanitizePageUrl,A as sessionCookieName,re as setStageAttribute,Q as toWireSlot,z as writeSnapshot};
|
|
2
2
|
//# sourceMappingURL=index-graph.mjs.map
|
package/dist/index-local.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { f as DecideOutcome } from './index-
|
|
1
|
+
import { f as DecideOutcome } from './index-CPjHmDZO.cjs';
|
|
2
2
|
import { f as SlotDeclInput } from './session-meta-BqBaLZag.cjs';
|
|
3
3
|
import './style-vocabulary-Ba_g6_DD.cjs';
|
|
4
4
|
import './region-skeleton-BRIVB-qf.cjs';
|
package/dist/index-local.d.ts
CHANGED
package/dist/index-server.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { $ as SitePalette, a4 as StyleVocabulary } from './style-vocabulary-Ba_g6_DD.cjs';
|
|
2
|
-
import { e as SlotConfigEntry, f as SlotDeclInput } from './session-meta-BqBaLZag.cjs';
|
|
2
|
+
import { e as SlotConfigEntry, f as SlotDeclInput, a as AgentIntent } from './session-meta-BqBaLZag.cjs';
|
|
3
3
|
export { C as CLASSIC_CRAWLER_TOKENS, b as CLICK_ID_KEYS, d as SessionUpsertPayload, m as buildSessionUpsertPayload, o as deriveSessionSegment, p as detectDeviceClass, q as detectTimeOfDay, r as detectTrafficSource, s as extractTrackedParams, u as matchedCrawlerToken, w as referrerDomainFromReferer } from './session-meta-BqBaLZag.cjs';
|
|
4
4
|
import { c as RenderCaps } from './region-skeleton-BRIVB-qf.cjs';
|
|
5
5
|
import { SlotResult } from '@sentientui/policy';
|
|
@@ -323,6 +323,7 @@ declare function postAgentFetch(entry: {
|
|
|
323
323
|
path: string;
|
|
324
324
|
userAgent: string;
|
|
325
325
|
botName: string;
|
|
326
|
+
signatureAgent?: string | null;
|
|
326
327
|
}, opts: AgentCaptureOptions): void;
|
|
327
328
|
/**
|
|
328
329
|
* Log this request if its user agent is a known AI assistant or crawler.
|
|
@@ -346,4 +347,38 @@ type ConnectRequest = {
|
|
|
346
347
|
*/
|
|
347
348
|
declare function sentientAgentMiddleware(opts: Omit<AgentCaptureOptions, 'waitUntil' | 'source'>): (req: ConnectRequest, res: unknown, next: (err?: unknown) => void) => void;
|
|
348
349
|
|
|
349
|
-
|
|
350
|
+
/**
|
|
351
|
+
* Agents that drive a real, current Chrome and carry NO user-agent token —
|
|
352
|
+
* ChatGPT agent, Meta's Muse (59% of agent requests in HUMAN Security's
|
|
353
|
+
* October 2026 data), Browserbase sessions. A user-agent match can never see
|
|
354
|
+
* them; what they do send is Web Bot Auth's `Signature-Agent` header naming
|
|
355
|
+
* the key directory they sign with. Keyed by that directory's host.
|
|
356
|
+
*
|
|
357
|
+
* The header is matched, NOT cryptographically verified, so it is exactly as
|
|
358
|
+
* trustworthy as a user-agent token (anyone can send either). That is enough
|
|
359
|
+
* for observation, which is all this is used for. Unknown hosts return null:
|
|
360
|
+
* the header never becomes a free-text label in the dashboard.
|
|
361
|
+
*/
|
|
362
|
+
declare const SIGNED_AGENTS: Readonly<Record<string, string>>;
|
|
363
|
+
/** The agent a `Signature-Agent` header names, or null. Accepts the bare
|
|
364
|
+
* quoted form (`"https://chatgpt.com"`) and the dictionary form
|
|
365
|
+
* (`sig1="https://chatgpt.com"`). */
|
|
366
|
+
declare function matchedSignatureAgent(header: string | null | undefined): string | null;
|
|
367
|
+
/**
|
|
368
|
+
* AI fetchers that never execute JavaScript, so only a server sees them and
|
|
369
|
+
* the browser bundle need not carry them. Each from the vendor's own page:
|
|
370
|
+
* developers.openai.com/api/docs/bots, developers.google.com/crawling,
|
|
371
|
+
* developers.facebook.com/docs/sharing/webmasters/web-crawlers,
|
|
372
|
+
* developer.amazon.com/amazonbot.
|
|
373
|
+
*/
|
|
374
|
+
declare const SERVER_AGENT_INTENTS: Readonly<Record<string, AgentIntent>>;
|
|
375
|
+
/** The browser list first, then the server-only fetcher tokens. */
|
|
376
|
+
declare function matchedServerAgentToken(userAgent: string | null | undefined): string | null;
|
|
377
|
+
/** UA token first (the more specific name), then the signed-agent header. */
|
|
378
|
+
declare function identifyAgent(userAgent: string | null | undefined, signatureAgent?: string | null): string | null;
|
|
379
|
+
/** agentIntent for every name identifyAgent can return. */
|
|
380
|
+
declare function serverAgentIntent(botName: string | null): AgentIntent;
|
|
381
|
+
/** classifiedAgents over everything the server can name. */
|
|
382
|
+
declare function serverClassifiedAgents(): Record<AgentIntent, string[]>;
|
|
383
|
+
|
|
384
|
+
export { type AgentCaptureOptions, type CapturableRequest, type DecideResult, SERVER_AGENT_INTENTS, SERVER_GOAL_NAMESPACE, SIGNED_AGENTS, type ServerAssignConfig, type ServerAssignments, type ServerAssignmentsDetailed, SlotDeclInput, type TrackServerGoalOptions, captureAgentRequest, identifyAgent, matchedServerAgentToken, matchedSignatureAgent, postAgentFetch, preloadAssignments, preloadAssignmentsDetailed, preloadDecisions, readInternalToken, readSessionCookie, sentientAgentMiddleware, serverAgentIntent, serverClassifiedAgents, signUserId, trackServerGoal };
|
package/dist/index-server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { $ as SitePalette, a4 as StyleVocabulary } from './style-vocabulary-Ba_g6_DD.js';
|
|
2
|
-
import { e as SlotConfigEntry, f as SlotDeclInput } from './session-meta-D_kdNsaU.js';
|
|
2
|
+
import { e as SlotConfigEntry, f as SlotDeclInput, a as AgentIntent } from './session-meta-D_kdNsaU.js';
|
|
3
3
|
export { C as CLASSIC_CRAWLER_TOKENS, b as CLICK_ID_KEYS, d as SessionUpsertPayload, m as buildSessionUpsertPayload, o as deriveSessionSegment, p as detectDeviceClass, q as detectTimeOfDay, r as detectTrafficSource, s as extractTrackedParams, u as matchedCrawlerToken, w as referrerDomainFromReferer } from './session-meta-D_kdNsaU.js';
|
|
4
4
|
import { c as RenderCaps } from './region-skeleton-BRIVB-qf.js';
|
|
5
5
|
import { SlotResult } from '@sentientui/policy';
|
|
@@ -323,6 +323,7 @@ declare function postAgentFetch(entry: {
|
|
|
323
323
|
path: string;
|
|
324
324
|
userAgent: string;
|
|
325
325
|
botName: string;
|
|
326
|
+
signatureAgent?: string | null;
|
|
326
327
|
}, opts: AgentCaptureOptions): void;
|
|
327
328
|
/**
|
|
328
329
|
* Log this request if its user agent is a known AI assistant or crawler.
|
|
@@ -346,4 +347,38 @@ type ConnectRequest = {
|
|
|
346
347
|
*/
|
|
347
348
|
declare function sentientAgentMiddleware(opts: Omit<AgentCaptureOptions, 'waitUntil' | 'source'>): (req: ConnectRequest, res: unknown, next: (err?: unknown) => void) => void;
|
|
348
349
|
|
|
349
|
-
|
|
350
|
+
/**
|
|
351
|
+
* Agents that drive a real, current Chrome and carry NO user-agent token —
|
|
352
|
+
* ChatGPT agent, Meta's Muse (59% of agent requests in HUMAN Security's
|
|
353
|
+
* October 2026 data), Browserbase sessions. A user-agent match can never see
|
|
354
|
+
* them; what they do send is Web Bot Auth's `Signature-Agent` header naming
|
|
355
|
+
* the key directory they sign with. Keyed by that directory's host.
|
|
356
|
+
*
|
|
357
|
+
* The header is matched, NOT cryptographically verified, so it is exactly as
|
|
358
|
+
* trustworthy as a user-agent token (anyone can send either). That is enough
|
|
359
|
+
* for observation, which is all this is used for. Unknown hosts return null:
|
|
360
|
+
* the header never becomes a free-text label in the dashboard.
|
|
361
|
+
*/
|
|
362
|
+
declare const SIGNED_AGENTS: Readonly<Record<string, string>>;
|
|
363
|
+
/** The agent a `Signature-Agent` header names, or null. Accepts the bare
|
|
364
|
+
* quoted form (`"https://chatgpt.com"`) and the dictionary form
|
|
365
|
+
* (`sig1="https://chatgpt.com"`). */
|
|
366
|
+
declare function matchedSignatureAgent(header: string | null | undefined): string | null;
|
|
367
|
+
/**
|
|
368
|
+
* AI fetchers that never execute JavaScript, so only a server sees them and
|
|
369
|
+
* the browser bundle need not carry them. Each from the vendor's own page:
|
|
370
|
+
* developers.openai.com/api/docs/bots, developers.google.com/crawling,
|
|
371
|
+
* developers.facebook.com/docs/sharing/webmasters/web-crawlers,
|
|
372
|
+
* developer.amazon.com/amazonbot.
|
|
373
|
+
*/
|
|
374
|
+
declare const SERVER_AGENT_INTENTS: Readonly<Record<string, AgentIntent>>;
|
|
375
|
+
/** The browser list first, then the server-only fetcher tokens. */
|
|
376
|
+
declare function matchedServerAgentToken(userAgent: string | null | undefined): string | null;
|
|
377
|
+
/** UA token first (the more specific name), then the signed-agent header. */
|
|
378
|
+
declare function identifyAgent(userAgent: string | null | undefined, signatureAgent?: string | null): string | null;
|
|
379
|
+
/** agentIntent for every name identifyAgent can return. */
|
|
380
|
+
declare function serverAgentIntent(botName: string | null): AgentIntent;
|
|
381
|
+
/** classifiedAgents over everything the server can name. */
|
|
382
|
+
declare function serverClassifiedAgents(): Record<AgentIntent, string[]>;
|
|
383
|
+
|
|
384
|
+
export { type AgentCaptureOptions, type CapturableRequest, type DecideResult, SERVER_AGENT_INTENTS, SERVER_GOAL_NAMESPACE, SIGNED_AGENTS, type ServerAssignConfig, type ServerAssignments, type ServerAssignmentsDetailed, SlotDeclInput, type TrackServerGoalOptions, captureAgentRequest, identifyAgent, matchedServerAgentToken, matchedSignatureAgent, postAgentFetch, preloadAssignments, preloadAssignmentsDetailed, preloadDecisions, readInternalToken, readSessionCookie, sentientAgentMiddleware, serverAgentIntent, serverClassifiedAgents, signUserId, trackServerGoal };
|
package/dist/index-server.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var T=Object.defineProperty,ye=Object.defineProperties,pe=Object.getOwnPropertyDescriptor,he=Object.getOwnPropertyDescriptors,xe=Object.getOwnPropertyNames,z=Object.getOwnPropertySymbols;var Q=Object.prototype.hasOwnProperty,be=Object.prototype.propertyIsEnumerable;var X=(e,t,n)=>t in e?T(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,l=(e,t)=>{for(var n in t||(t={}))Q.call(t,n)&&X(e,n,t[n]);if(z)for(var n of z(t))be.call(t,n)&&X(e,n,t[n]);return e},R=(e,t)=>ye(e,he(t));var Se=(e,t)=>{for(var n in t)T(e,n,{get:t[n],enumerable:!0})},Ae=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of xe(t))!Q.call(e,r)&&r!==n&&T(e,r,{get:()=>t[r],enumerable:!(s=pe(t,r))||s.enumerable});return e};var we=e=>Ae(T({},"__esModule",{value:!0}),e);var $e={};Se($e,{CLASSIC_CRAWLER_TOKENS:()=>_,CLICK_ID_KEYS:()=>B,SERVER_GOAL_NAMESPACE:()=>W,buildSessionUpsertPayload:()=>C,captureAgentRequest:()=>J,deriveSessionSegment:()=>ee,detectDeviceClass:()=>$,detectTimeOfDay:()=>N,detectTrafficSource:()=>L,extractTrackedParams:()=>Z,matchedCrawlerToken:()=>D,postAgentFetch:()=>q,preloadAssignments:()=>ae,preloadAssignmentsDetailed:()=>H,preloadDecisions:()=>de,readInternalToken:()=>le,readSessionCookie:()=>ce,referrerDomainFromReferer:()=>M,sentientAgentMiddleware:()=>fe,signUserId:()=>ue,trackServerGoal:()=>ge});module.exports=we($e);var Ie=["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 ve(e){return P(e)!==null}function P(e){var n;if(!e)return null;let t=e.toLowerCase();return(n=Ie.find(s=>t.includes(s.toLowerCase())))!=null?n:null}var _=["Googlebot","Bingbot","DuckDuckBot","YandexBot","Baiduspider","Applebot","Slurp","facebookexternalhit","LinkedInBot","Twitterbot"];function D(e){var s;let t=P(e);if(t)return t;if(!e)return null;let n=e.toLowerCase();return(s=_.find(r=>n.includes(r.toLowerCase())))!=null?s:null}function $(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 L(e,t,n){if(!e)return"direct";try{let s=new URL(e);if(t)try{if(new URL(t).host===s.host)return"direct"}catch(i){}let r=s.hostname.toLowerCase();return n&&`.${r}`.endsWith(`.${n}`)?"direct":/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(r)?"search":/(^|\.)(twitter\.com|x\.com|facebook\.com|linkedin\.com|reddit\.com|t\.co)$/.test(r)?"social":"referral"}catch(s){return"direct"}}function M(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}var B=["gclid","gbraid","wbraid","fbclid","ttclid","msclkid","twclid","li_fat_id"];function Z(e){let t={},n={};try{let s=typeof e=="string"||e instanceof URLSearchParams?new URLSearchParams(e):Object.entries(e).flatMap(([r,i])=>{let o=Array.isArray(i)?i[0]:i;return o===void 0?[]:[[r,o]]});for(let[r,i]of s)r.startsWith("utm_")?r in t||(t[r]=i):B.includes(r)&&(r in n||(n[r]=i))}catch(s){}return{utmParams:t,clickIds:n}}function N(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function ee(e){let t=C("__segment__",e);return`${t.deviceClass}:${t.trafficSource}`}function C(e,t){var o,c,m,u,a,d,x,h;let n=(c=(o=t==null?void 0:t.userAgent)==null?void 0:o.trim())!=null?c:"",s=(u=(m=t==null?void 0:t.referer)==null?void 0:m.trim())!=null?u:"",r=(a=t==null?void 0:t.now)!=null?a:new Date,i=D(n);return l(l({sessionId:e,ephemeral:!1,utmParams:(d=t==null?void 0:t.utmParams)!=null?d:{},clickIds:(x=t==null?void 0:t.clickIds)!=null?x:{},deviceClass:n?$(n):"desktop",trafficSource:s?L(s,t==null?void 0:t.appOrigin):"direct",referrerDomain:M(s),timeOfDay:N(r),dayOfWeek:(h=["sun","mon","tue","wed","thu","fri","sat"][r.getDay()])!=null?h:"sun",automation:(t==null?void 0:t.webdriver)===!0||ve(n)},i?{agentToken:i}:{}),t!=null&&t.landingPath?{landingPath:t.landingPath.split(/[?#]/)[0]}:{})}function Ce(e){return e?`_${e.slice(0,12)}`:""}var j="_snt_uid";function te(e){return`${j}${Ce(e)}`}var ne="sentient_internal";var k=require("@sentientui/policy");function G(e){return l(l(l({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 K(e){let t=G(e);return(0,k.slotResultFor)(t,(0,k.slotBaselineArm)(t))}function re(e){let t={};for(let n of e)t[n.id]=K(n);return t}function V(e){return l(l({},e.internal===!0?{internal:!0}:{}),e.internalToken?{internalToken:e.internalToken}:{})}var Re="X-Sentient-Server-Key";function ie(e){let t={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`};return e.origin&&(t.Origin=e.origin),e.serverKey&&typeof window=="undefined"&&(t[Re]=e.serverKey),t}var oe=1e3;function E(e,t,n){let s=new AbortController,r=setTimeout(()=>s.abort(),n);return fetch(e,R(l({},t),{signal:s.signal})).finally(()=>clearTimeout(r))}async function ae(e,t,n){return(await H(e,t,n)).assignments}async function H(e,t,n,s){var a;if(n.doNotTrack)return{assignments:{},unified:[]};let r=(a=n.timeoutMs)!=null?a:oe,i=ie(n),o=l(l(l({},C(t,{userAgent:n.userAgent,referer:n.referer,utmParams:n.utmParams,clickIds:n.clickIds,appOrigin:n.origin,landingPath:n.landingPath})),n.persona?{persona:n.persona}:{}),V(n));try{let d=await E(`${n.baseUrl}/sessions`,{method:"POST",headers:i,body:JSON.stringify(o)},r);if(d.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");else if(!d.ok){let x=await d.json().catch(()=>({}));console.error(`[SentientUI] preloadAssignments: session upsert failed (${d.status})`,x)}}catch(d){console.error("[SentientUI] preloadAssignments: session upsert threw",d)}let c=await Promise.allSettled(e.map(async({id:d,variantIds:x})=>{let h=await E(`${n.baseUrl}/assign`,{method:"POST",headers:i,body:JSON.stringify(l({sessionId:t,componentId:d,variantIds:x},s!=null&&s.unified?{caps:{unified:!0}}:{}))},r);if(!h.ok){let b=await h.json().catch(()=>({}));return console.error(`[SentientUI] preloadAssignments: assign failed for "${d}" (${h.status})`,b),null}let p=await h.json();return{id:d,variantId:p.variantId,unified:(s==null?void 0:s.unified)===!0&&p.unified===!0}})),m={},u=[];for(let d of c)d.status==="fulfilled"&&d.value&&(d.value.unified?u.push(d.value.id):m[d.value.id]=d.value.variantId);return{assignments:m,unified:u}}function ce(e,t){var n,s,r,i;return(i=(r=t?(n=e.get(te(t)))==null?void 0:n.value:void 0)!=null?r:(s=e.get(j))==null?void 0:s.value)!=null?i:null}function le(e){var t;return((t=e.get(ne))==null?void 0:t.value)||void 0}async function de(e,t,n){var u,a,d,x,h,p,b,S,A,g,f,v;let s=(u=n.timeoutMs)!=null?u:oe,r=(a=e.slots)!=null?a:[],i=null;e.slotsFrom==="registry"&&(Array.isArray(e.registrySlotIds)?i=e.registrySlotIds:console.error("[SentientUI] preloadDecisions: slotsFrom: 'registry' needs registrySlotIds (the <Adaptive id>s this page renders). An unscoped registry decide records a trial for every published slot on every page; falling back to request mode."));let o={layoutOrder:(d=e.sections)!=null?d:[],assignments:{},slots:re(r),persona:"unknown",confidence:0};if(n.doNotTrack)return o;let c=ie(n),m=l(l(l({},C(t,{userAgent:n.userAgent,referer:n.referer,utmParams:n.utmParams,clickIds:n.clickIds,appOrigin:n.origin,landingPath:n.landingPath})),n.persona?{persona:n.persona}:{}),V(n));try{let I=await E(`${n.baseUrl}/sessions`,{method:"POST",headers:c,body:JSON.stringify(m)},s);if(!I.ok){let y=await I.json().catch(()=>({}));console.error(`[SentientUI] preloadDecisions: session upsert failed (${I.status})`,y)}}catch(I){console.error("[SentientUI] preloadDecisions: session upsert threw",I)}try{let I=await E(`${n.baseUrl}/decide`,{method:"POST",headers:c,body:JSON.stringify(l(l(l(l(l({sessionId:t,sections:((x=e.sections)!=null?x:[]).map(w=>({id:w})),components:e.components},r.length>0?{slots:r.map(G)}:{}),i!==null?{slotsFrom:"registry",registrySlotIds:i,bootstrap:!1,render:Object.fromEntries(i.map(w=>{var O,Y;return[w,(Y=(O=e.renderCaps)==null?void 0:O[w])!=null?Y:{forms:!0,compose:!0,ops:!1}]}))}:{}),n.persona?{persona:n.persona}:{}),V(n)),e.unifiedCaps?{caps:{unified:!0}}:{}))},s);if(!I.ok){let w=await I.json().catch(()=>({}));return console.error(`[SentientUI] preloadDecisions: decide failed (${I.status})`,w),o}let y=await I.json(),U={};for(let w of r)U[w.id]=(p=(h=y.slots)==null?void 0:h[w.id])!=null?p:K(w);for(let[w,O]of Object.entries((b=y.slots)!=null?b:{}))w in U||(U[w]=O);let me=y.slotConfig!==void 0&&typeof y.slotConfig=="object"&&y.slotConfig!==null&&!Array.isArray(y.slotConfig);return l(l(l(l(l(l({layoutOrder:(A=(S=y.layoutOrder)!=null?S:e.sections)!=null?A:[],assignments:(g=y.assignments)!=null?g:{},slots:U,persona:(f=y.persona)!=null?f:"unknown",confidence:(v=y.confidence)!=null?v:0},me?{slotConfig:y.slotConfig}:{}),y.palette?{palette:y.palette}:{}),y.vocabulary?{vocabulary:y.vocabulary}:{}),typeof y.stage=="string"?{stage:y.stage}:{}),typeof y.context=="string"?{context:y.context}:{}),e.unifiedCaps&&Array.isArray(y.unified)?{unified:y.unified.filter(w=>typeof w=="string")}:{})}catch(I){return console.error("[SentientUI] preloadDecisions: decide threw",I),o}}var W="3d8f5a21-7c64-4b19-8e0a-5f2c91d7b6e3";function ke(e){let t=(h,p)=>h<<p|h>>>32-p,n=e.length,s=new Uint8Array((n+8>>6)*64+64);s.set(e),s[n]=128;let r=new DataView(s.buffer);r.setUint32(s.length-8,Math.floor(n*8/4294967296)),r.setUint32(s.length-4,n*8>>>0);let i=1732584193,o=4023233417,c=2562383102,m=271733878,u=3285377520,a=new Array(80);for(let h=0;h<s.length;h+=64){for(let f=0;f<16;f++)a[f]=r.getUint32(h+f*4);for(let f=16;f<80;f++)a[f]=t(a[f-3]^a[f-8]^a[f-14]^a[f-16],1);let p=i,b=o,S=c,A=m,g=u;for(let f=0;f<80;f++){let[v,I]=f<20?[b&S|~b&A,1518500249]:f<40?[b^S^A,1859775393]:f<60?[b&S|b&A|S&A,2400959708]:[b^S^A,3395469782],y=t(p,5)+v+g+I+a[f]|0;g=A,A=S,S=t(b,30),b=p,p=y}i=i+p|0,o=o+b|0,c=c+S|0,m=m+A|0,u=u+g|0}let d=new Uint8Array(20),x=new DataView(d.buffer);return[i,o,c,m,u].forEach((h,p)=>x.setUint32(p*4,h>>>0)),d}async function Ue(e,t){var u;let n=t.replace(/-/g,""),s=new Uint8Array(16);for(let a=0;a<16;a++)s[a]=parseInt(n.slice(a*2,a*2+2),16);let r=new TextEncoder().encode(e),i=new Uint8Array(16+r.length);i.set(s,0),i.set(r,16);let o=(u=globalThis.crypto)==null?void 0:u.subtle,c=(o?new Uint8Array(await o.digest("SHA-1",i)):ke(i)).slice(0,16);c[6]=c[6]&15|80,c[8]=c[8]&63|128;let m=Array.from(c,a=>a.toString(16).padStart(2,"0")).join("");return`${m.slice(0,8)}-${m.slice(8,12)}-${m.slice(12,16)}-${m.slice(16,20)}-${m.slice(20,32)}`}var Oe=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function F(e){let t=e.length*8,n=new Uint8Array(Math.ceil((e.length+9)/64)*64);n.set(e),n[e.length]=128;let s=new DataView(n.buffer);s.setUint32(n.length-8,Math.floor(t/4294967296)),s.setUint32(n.length-4,t>>>0);let r=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),i=new Uint32Array(64),o=(u,a)=>u>>>a|u<<32-a;for(let u=0;u<n.length;u+=64){for(let g=0;g<16;g++)i[g]=s.getUint32(u+g*4);for(let g=16;g<64;g++){let f=o(i[g-15],7)^o(i[g-15],18)^i[g-15]>>>3,v=o(i[g-2],17)^o(i[g-2],19)^i[g-2]>>>10;i[g]=i[g-16]+f+i[g-7]+v|0}let[a,d,x,h,p,b,S,A]=[r[0],r[1],r[2],r[3],r[4],r[5],r[6],r[7]];for(let g=0;g<64;g++){let f=A+(o(p,6)^o(p,11)^o(p,25))+(p&b^~p&S)+Oe[g]+i[g]|0,v=(o(a,2)^o(a,13)^o(a,22))+(a&d^a&x^d&x)|0;A=S,S=b,b=p,p=h+f|0,h=x,x=d,d=a,a=f+v|0}r[0]=r[0]+a|0,r[1]=r[1]+d|0,r[2]=r[2]+x|0,r[3]=r[3]+h|0,r[4]=r[4]+p|0,r[5]=r[5]+b|0,r[6]=r[6]+S|0,r[7]=r[7]+A|0}let c=new Uint8Array(32),m=new DataView(c.buffer);return r.forEach((u,a)=>m.setUint32(a*4,u)),c}function Te(e,t){let n=new Uint8Array(64);n.set(e.length>64?F(e):e);let s=new Uint8Array(64+t.length),r=new Uint8Array(96);for(let i=0;i<64;i++)s[i]=n[i]^54,r[i]=n[i]^92;return s.set(t,64),r.set(F(s),64),F(r)}async function se(e,t){var c;let n=new TextEncoder,s=n.encode(e),r=n.encode(t),i=(c=globalThis.crypto)==null?void 0:c.subtle,o=i?new Uint8Array(await i.sign("HMAC",await i.importKey("raw",s,{name:"HMAC",hash:"SHA-256"},!1,["sign"]),r)):Te(s,r);return Array.from(o,m=>m.toString(16).padStart(2,"0")).join("")}async function ue(e,t,n){var i,o;if(typeof window!="undefined")return console.error("[SentientUI] signUserId is server-only: it needs the secret key. Compute the hash on your server and pass it to identify()."),"";let s=Math.floor(((i=n==null?void 0:n.now)!=null?i:Date.now())/1e3)+Math.min((o=n==null?void 0:n.ttlSeconds)!=null?o:86400,7*86400),r=await se(t,"sentient-identity-v1");return`v1.${s}.${await se(r,`${e}.${s}`)}`}var Pe="https://api.sentient-ui.com/v1",Ee=5e3;async function ge(e){var i,o;if(typeof window!="undefined")return console.error("[SentientUI] trackServerGoal is server-only: the secret key was not sent. Call it from a route handler, server action or webhook."),"failed";let t=e.sessionId?null:e.userId||null;if(!e.sessionId&&!t)return"skipped_no_visitor";if(e.name.includes(":"))return console.error('[SentientUI] trackServerGoal: goal names cannot contain ":" (nothing was sent).'),"failed";let n=(i=e.fetch)!=null?i:fetch,s=new AbortController,r;try{let c=new Promise((a,d)=>{var x;r=setTimeout(()=>{s.abort(),d(new Error("timeout"))},(x=e.timeoutMs)!=null?x:Ee)});c.catch(()=>{});let m=await Ue(t===null?`${e.sessionId}:${e.name}:${e.dedupeKey}`:`user:${e.serverKey}:${t}:${e.name}:${e.dedupeKey}`,W),u=await Promise.race([n(`${((o=e.apiBaseUrl)!=null?o:Pe).replace(/\/+$/,"")}/goals`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.serverKey}`},body:JSON.stringify(l(l(l(R(l({},t===null?{sessionId:e.sessionId}:{userId:t}),{name:e.name,goalId:m,externalId:e.dedupeKey}),e.value!==void 0?{value:e.value}:{}),e.currency!==void 0?{currency:e.currency}:{}),e.metadata!==void 0?{metadata:e.metadata}:{})),signal:s.signal}),c]);return u.ok?"recorded":t!==null&&u.status===404?(process.env.NODE_ENV!=="production"&&console.warn(`[SentientUI] trackServerGoal: no visit is linked to userId "${t}" yet, so "${e.name}" was not recorded. Identify the visitor in the browser first (<AdaptiveRoot userId>, or identify(userId, { userHash })) \u2014 once a project signs its identifies, only signed visits count.`),"skipped_no_visitor"):"failed"}catch(c){return"failed"}finally{r&&clearTimeout(r)}}var _e="https://api.sentient-ui.com/v1";function De(e){try{return new URL(e,"http://localhost").pathname||"/"}catch(t){return e.split(/[?#]/,1)[0]||"/"}}function q(e,t){var s,r,i,o;let n=(s=t.fetchImpl)!=null?s:typeof fetch=="function"?fetch:void 0;if(!(!n||!t.apiKey))try{let c=n(`${(r=t.baseUrl)!=null?r:_e}/crawler-events`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${t.apiKey}`},body:JSON.stringify({path:e.path,botName:e.botName,userAgent:e.userAgent,source:(i=t.source)!=null?i:"middleware"})}).catch(()=>{});(o=t.waitUntil)==null||o.call(t,c)}catch(c){}}function J(e,t){var r;let n="";try{n=(r=e.headers.get("user-agent"))!=null?r:""}catch(i){return!1}let s=P(n);return s?(q({path:De(e.url),userAgent:n,botName:s},t),!0):!1}function fe(e){return(t,n,s)=>{var r,i,o;try{let c=t.headers["user-agent"],m=Array.isArray(c)?(r=c[0])!=null?r:"":c!=null?c:"";J({url:(o=(i=t.originalUrl)!=null?i:t.url)!=null?o:"/",headers:{get:u=>u.toLowerCase()==="user-agent"?m:null}},R(l({},e),{source:"middleware"}))}catch(c){}s()}}0&&(module.exports={CLASSIC_CRAWLER_TOKENS,CLICK_ID_KEYS,SERVER_GOAL_NAMESPACE,buildSessionUpsertPayload,captureAgentRequest,deriveSessionSegment,detectDeviceClass,detectTimeOfDay,detectTrafficSource,extractTrackedParams,matchedCrawlerToken,postAgentFetch,preloadAssignments,preloadAssignmentsDetailed,preloadDecisions,readInternalToken,readSessionCookie,referrerDomainFromReferer,sentientAgentMiddleware,signUserId,trackServerGoal});
|
|
1
|
+
"use strict";var E=Object.defineProperty,Ce=Object.defineProperties,Re=Object.getOwnPropertyDescriptor,ve=Object.getOwnPropertyDescriptors,ke=Object.getOwnPropertyNames,re=Object.getOwnPropertySymbols;var ie=Object.prototype.hasOwnProperty,Ue=Object.prototype.propertyIsEnumerable;var se=(e,t,n)=>t in e?E(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,c=(e,t)=>{for(var n in t||(t={}))ie.call(t,n)&&se(e,n,t[n]);if(re)for(var n of re(t))Ue.call(t,n)&&se(e,n,t[n]);return e},R=(e,t)=>Ce(e,ve(t));var Te=(e,t)=>{for(var n in t)E(e,n,{get:t[n],enumerable:!0})},Ee=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ke(t))!ie.call(e,r)&&r!==n&&E(e,r,{get:()=>t[r],enumerable:!(s=Re(t,r))||s.enumerable});return e};var Oe=e=>Ee(E({},"__esModule",{value:!0}),e);var Ve={};Te(Ve,{CLASSIC_CRAWLER_TOKENS:()=>$,CLICK_ID_KEYS:()=>K,SERVER_AGENT_INTENTS:()=>D,SERVER_GOAL_NAMESPACE:()=>Y,SIGNED_AGENTS:()=>_,buildSessionUpsertPayload:()=>v,captureAgentRequest:()=>te,deriveSessionSegment:()=>ce,detectDeviceClass:()=>M,detectTimeOfDay:()=>F,detectTrafficSource:()=>B,extractTrackedParams:()=>ae,identifyAgent:()=>L,matchedCrawlerToken:()=>G,matchedServerAgentToken:()=>Q,matchedSignatureAgent:()=>X,postAgentFetch:()=>ee,preloadAssignments:()=>pe,preloadAssignmentsDetailed:()=>J,preloadDecisions:()=>xe,readInternalToken:()=>he,readSessionCookie:()=>ye,referrerDomainFromReferer:()=>j,sentientAgentMiddleware:()=>we,serverAgentIntent:()=>Z,serverClassifiedAgents:()=>Se,signUserId:()=>be,trackServerGoal:()=>Ae});module.exports=Oe(Ve);var N=["GPTBot","ChatGPT-User","OAI-SearchBot","ClaudeBot","Claude-User","Claude-SearchBot","Claude-Agent","PerplexityBot","Perplexity-User","Google-Agent","Google-Extended","Applebot-Extended","Meta-ExternalAgent","Bytespider","CCBot","Amazonbot","cohere-ai","Diffbot"];function Pe(e){return O(e)!==null}function O(e){var n;if(!e)return null;let t=e.toLowerCase();return(n=N.find(s=>t.includes(s.toLowerCase())))!=null?n:null}var $=["Googlebot","Bingbot","DuckDuckBot","YandexBot","Baiduspider","Applebot","Slurp","facebookexternalhit","LinkedInBot","Twitterbot"];function G(e){var s;let t=O(e);if(t)return t;if(!e)return null;let n=e.toLowerCase();return(s=$.find(r=>n.includes(r.toLowerCase())))!=null?s:null}var oe={GPTBot:"training","ChatGPT-User":"user","OAI-SearchBot":"search",ClaudeBot:"training","Claude-User":"user","Claude-SearchBot":"search","Claude-Agent":"user",PerplexityBot:"search","Perplexity-User":"user","Google-Agent":"user","Google-Extended":"training","Applebot-Extended":"training","Meta-ExternalAgent":"training",Bytespider:"training",CCBot:"training",Amazonbot:"other","cohere-ai":"training",Diffbot:"other"};function M(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 B(e,t,n){if(!e)return"direct";try{let s=new URL(e);if(t)try{if(new URL(t).host===s.host)return"direct"}catch(i){}let r=s.hostname.toLowerCase();return n&&`.${r}`.endsWith(`.${n}`)?"direct":/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(r)?"search":/(^|\.)(twitter\.com|x\.com|facebook\.com|linkedin\.com|reddit\.com|t\.co)$/.test(r)?"social":"referral"}catch(s){return"direct"}}function j(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}var K=["gclid","gbraid","wbraid","fbclid","ttclid","msclkid","twclid","li_fat_id"];function ae(e){let t={},n={};try{let s=typeof e=="string"||e instanceof URLSearchParams?new URLSearchParams(e):Object.entries(e).flatMap(([r,i])=>{let o=Array.isArray(i)?i[0]:i;return o===void 0?[]:[[r,o]]});for(let[r,i]of s)r.startsWith("utm_")?r in t||(t[r]=i):K.includes(r)&&(r in n||(n[r]=i))}catch(s){}return{utmParams:t,clickIds:n}}function F(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function ce(e){let t=v("__segment__",e);return`${t.deviceClass}:${t.trafficSource}`}function v(e,t){var o,l,g,d,a,u,x,h;let n=(l=(o=t==null?void 0:t.userAgent)==null?void 0:o.trim())!=null?l:"",s=(d=(g=t==null?void 0:t.referer)==null?void 0:g.trim())!=null?d:"",r=(a=t==null?void 0:t.now)!=null?a:new Date,i=G(n);return c(c({sessionId:e,ephemeral:!1,utmParams:(u=t==null?void 0:t.utmParams)!=null?u:{},clickIds:(x=t==null?void 0:t.clickIds)!=null?x:{},deviceClass:n?M(n):"desktop",trafficSource:s?B(s,t==null?void 0:t.appOrigin):"direct",referrerDomain:j(s),timeOfDay:F(r),dayOfWeek:(h=["sun","mon","tue","wed","thu","fri","sat"][r.getDay()])!=null?h:"sun",automation:(t==null?void 0:t.webdriver)===!0||Pe(n)},i?{agentToken:i}:{}),t!=null&&t.landingPath?{landingPath:t.landingPath.split(/[?#]/)[0]}:{})}function _e(e){return e?`_${e.slice(0,12)}`:""}var V="_snt_uid";function le(e){return`${V}${_e(e)}`}var ue="sentient_internal";var k=require("@sentientui/policy");function W(e){return c(c(c({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 z(e){let t=W(e);return(0,k.slotResultFor)(t,(0,k.slotBaselineArm)(t))}function de(e){let t={};for(let n of e)t[n.id]=z(n);return t}function q(e){return c(c({},e.internal===!0?{internal:!0}:{}),e.internalToken?{internalToken:e.internalToken}:{})}var De="X-Sentient-Server-Key";function fe(e){let t={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`};return e.origin&&(t.Origin=e.origin),e.serverKey&&typeof window=="undefined"&&(t[De]=e.serverKey),t}var me=1e3;function P(e,t,n){let s=new AbortController,r=setTimeout(()=>s.abort(),n);return fetch(e,R(c({},t),{signal:s.signal})).finally(()=>clearTimeout(r))}async function pe(e,t,n){return(await J(e,t,n)).assignments}async function J(e,t,n,s){var a;if(n.doNotTrack)return{assignments:{},unified:[]};let r=(a=n.timeoutMs)!=null?a:me,i=fe(n),o=c(c(c({},v(t,{userAgent:n.userAgent,referer:n.referer,utmParams:n.utmParams,clickIds:n.clickIds,appOrigin:n.origin,landingPath:n.landingPath})),n.persona?{persona:n.persona}:{}),q(n));try{let u=await P(`${n.baseUrl}/sessions`,{method:"POST",headers:i,body:JSON.stringify(o)},r);if(u.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");else if(!u.ok){let x=await u.json().catch(()=>({}));console.error(`[SentientUI] preloadAssignments: session upsert failed (${u.status})`,x)}}catch(u){console.error("[SentientUI] preloadAssignments: session upsert threw",u)}let l=await Promise.allSettled(e.map(async({id:u,variantIds:x})=>{let h=await P(`${n.baseUrl}/assign`,{method:"POST",headers:i,body:JSON.stringify(c({sessionId:t,componentId:u,variantIds:x},s!=null&&s.unified?{caps:{unified:!0}}:{}))},r);if(!h.ok){let b=await h.json().catch(()=>({}));return console.error(`[SentientUI] preloadAssignments: assign failed for "${u}" (${h.status})`,b),null}let y=await h.json();return{id:u,variantId:y.variantId,unified:(s==null?void 0:s.unified)===!0&&y.unified===!0}})),g={},d=[];for(let u of l)u.status==="fulfilled"&&u.value&&(u.value.unified?d.push(u.value.id):g[u.value.id]=u.value.variantId);return{assignments:g,unified:d}}function ye(e,t){var n,s,r,i;return(i=(r=t?(n=e.get(le(t)))==null?void 0:n.value:void 0)!=null?r:(s=e.get(V))==null?void 0:s.value)!=null?i:null}function he(e){var t;return((t=e.get(ue))==null?void 0:t.value)||void 0}async function xe(e,t,n){var d,a,u,x,h,y,b,A,S,f,m,C;let s=(d=n.timeoutMs)!=null?d:me,r=(a=e.slots)!=null?a:[],i=null;e.slotsFrom==="registry"&&(Array.isArray(e.registrySlotIds)?i=e.registrySlotIds:console.error("[SentientUI] preloadDecisions: slotsFrom: 'registry' needs registrySlotIds (the <Adaptive id>s this page renders). An unscoped registry decide records a trial for every published slot on every page; falling back to request mode."));let o={layoutOrder:(u=e.sections)!=null?u:[],assignments:{},slots:de(r),persona:"unknown",confidence:0};if(n.doNotTrack)return o;let l=fe(n),g=c(c(c({},v(t,{userAgent:n.userAgent,referer:n.referer,utmParams:n.utmParams,clickIds:n.clickIds,appOrigin:n.origin,landingPath:n.landingPath})),n.persona?{persona:n.persona}:{}),q(n));try{let I=await P(`${n.baseUrl}/sessions`,{method:"POST",headers:l,body:JSON.stringify(g)},s);if(!I.ok){let p=await I.json().catch(()=>({}));console.error(`[SentientUI] preloadDecisions: session upsert failed (${I.status})`,p)}}catch(I){console.error("[SentientUI] preloadDecisions: session upsert threw",I)}try{let I=await P(`${n.baseUrl}/decide`,{method:"POST",headers:l,body:JSON.stringify(c(c(c(c(c({sessionId:t,sections:((x=e.sections)!=null?x:[]).map(w=>({id:w})),components:e.components},r.length>0?{slots:r.map(W)}:{}),i!==null?{slotsFrom:"registry",registrySlotIds:i,bootstrap:!1,render:Object.fromEntries(i.map(w=>{var T,ne;return[w,(ne=(T=e.renderCaps)==null?void 0:T[w])!=null?ne:{forms:!0,compose:!0,ops:!1}]}))}:{}),n.persona?{persona:n.persona}:{}),q(n)),e.unifiedCaps?{caps:{unified:!0}}:{}))},s);if(!I.ok){let w=await I.json().catch(()=>({}));return console.error(`[SentientUI] preloadDecisions: decide failed (${I.status})`,w),o}let p=await I.json(),U={};for(let w of r)U[w.id]=(y=(h=p.slots)==null?void 0:h[w.id])!=null?y:z(w);for(let[w,T]of Object.entries((b=p.slots)!=null?b:{}))w in U||(U[w]=T);let Ie=p.slotConfig!==void 0&&typeof p.slotConfig=="object"&&p.slotConfig!==null&&!Array.isArray(p.slotConfig);return c(c(c(c(c(c({layoutOrder:(S=(A=p.layoutOrder)!=null?A:e.sections)!=null?S:[],assignments:(f=p.assignments)!=null?f:{},slots:U,persona:(m=p.persona)!=null?m:"unknown",confidence:(C=p.confidence)!=null?C:0},Ie?{slotConfig:p.slotConfig}:{}),p.palette?{palette:p.palette}:{}),p.vocabulary?{vocabulary:p.vocabulary}:{}),typeof p.stage=="string"?{stage:p.stage}:{}),typeof p.context=="string"?{context:p.context}:{}),e.unifiedCaps&&Array.isArray(p.unified)?{unified:p.unified.filter(w=>typeof w=="string")}:{})}catch(I){return console.error("[SentientUI] preloadDecisions: decide threw",I),o}}var Y="3d8f5a21-7c64-4b19-8e0a-5f2c91d7b6e3";function Le(e){let t=(h,y)=>h<<y|h>>>32-y,n=e.length,s=new Uint8Array((n+8>>6)*64+64);s.set(e),s[n]=128;let r=new DataView(s.buffer);r.setUint32(s.length-8,Math.floor(n*8/4294967296)),r.setUint32(s.length-4,n*8>>>0);let i=1732584193,o=4023233417,l=2562383102,g=271733878,d=3285377520,a=new Array(80);for(let h=0;h<s.length;h+=64){for(let m=0;m<16;m++)a[m]=r.getUint32(h+m*4);for(let m=16;m<80;m++)a[m]=t(a[m-3]^a[m-8]^a[m-14]^a[m-16],1);let y=i,b=o,A=l,S=g,f=d;for(let m=0;m<80;m++){let[C,I]=m<20?[b&A|~b&S,1518500249]:m<40?[b^A^S,1859775393]:m<60?[b&A|b&S|A&S,2400959708]:[b^A^S,3395469782],p=t(y,5)+C+f+I+a[m]|0;f=S,S=A,A=t(b,30),b=y,y=p}i=i+y|0,o=o+b|0,l=l+A|0,g=g+S|0,d=d+f|0}let u=new Uint8Array(20),x=new DataView(u.buffer);return[i,o,l,g,d].forEach((h,y)=>x.setUint32(y*4,h>>>0)),u}async function Ne(e,t){var d;let n=t.replace(/-/g,""),s=new Uint8Array(16);for(let a=0;a<16;a++)s[a]=parseInt(n.slice(a*2,a*2+2),16);let r=new TextEncoder().encode(e),i=new Uint8Array(16+r.length);i.set(s,0),i.set(r,16);let o=(d=globalThis.crypto)==null?void 0:d.subtle,l=(o?new Uint8Array(await o.digest("SHA-1",i)):Le(i)).slice(0,16);l[6]=l[6]&15|80,l[8]=l[8]&63|128;let g=Array.from(l,a=>a.toString(16).padStart(2,"0")).join("");return`${g.slice(0,8)}-${g.slice(8,12)}-${g.slice(12,16)}-${g.slice(16,20)}-${g.slice(20,32)}`}var $e=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function H(e){let t=e.length*8,n=new Uint8Array(Math.ceil((e.length+9)/64)*64);n.set(e),n[e.length]=128;let s=new DataView(n.buffer);s.setUint32(n.length-8,Math.floor(t/4294967296)),s.setUint32(n.length-4,t>>>0);let r=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),i=new Uint32Array(64),o=(d,a)=>d>>>a|d<<32-a;for(let d=0;d<n.length;d+=64){for(let f=0;f<16;f++)i[f]=s.getUint32(d+f*4);for(let f=16;f<64;f++){let m=o(i[f-15],7)^o(i[f-15],18)^i[f-15]>>>3,C=o(i[f-2],17)^o(i[f-2],19)^i[f-2]>>>10;i[f]=i[f-16]+m+i[f-7]+C|0}let[a,u,x,h,y,b,A,S]=[r[0],r[1],r[2],r[3],r[4],r[5],r[6],r[7]];for(let f=0;f<64;f++){let m=S+(o(y,6)^o(y,11)^o(y,25))+(y&b^~y&A)+$e[f]+i[f]|0,C=(o(a,2)^o(a,13)^o(a,22))+(a&u^a&x^u&x)|0;S=A,A=b,b=y,y=h+m|0,h=x,x=u,u=a,a=m+C|0}r[0]=r[0]+a|0,r[1]=r[1]+u|0,r[2]=r[2]+x|0,r[3]=r[3]+h|0,r[4]=r[4]+y|0,r[5]=r[5]+b|0,r[6]=r[6]+A|0,r[7]=r[7]+S|0}let l=new Uint8Array(32),g=new DataView(l.buffer);return r.forEach((d,a)=>g.setUint32(a*4,d)),l}function Ge(e,t){let n=new Uint8Array(64);n.set(e.length>64?H(e):e);let s=new Uint8Array(64+t.length),r=new Uint8Array(96);for(let i=0;i<64;i++)s[i]=n[i]^54,r[i]=n[i]^92;return s.set(t,64),r.set(H(s),64),H(r)}async function ge(e,t){var l;let n=new TextEncoder,s=n.encode(e),r=n.encode(t),i=(l=globalThis.crypto)==null?void 0:l.subtle,o=i?new Uint8Array(await i.sign("HMAC",await i.importKey("raw",s,{name:"HMAC",hash:"SHA-256"},!1,["sign"]),r)):Ge(s,r);return Array.from(o,g=>g.toString(16).padStart(2,"0")).join("")}async function be(e,t,n){var i,o;if(typeof window!="undefined")return console.error("[SentientUI] signUserId is server-only: it needs the secret key. Compute the hash on your server and pass it to identify()."),"";let s=Math.floor(((i=n==null?void 0:n.now)!=null?i:Date.now())/1e3)+Math.min((o=n==null?void 0:n.ttlSeconds)!=null?o:86400,7*86400),r=await ge(t,"sentient-identity-v1");return`v1.${s}.${await ge(r,`${e}.${s}`)}`}var Me="https://api.sentient-ui.com/v1",Be=5e3;async function Ae(e){var i,o;if(typeof window!="undefined")return console.error("[SentientUI] trackServerGoal is server-only: the secret key was not sent. Call it from a route handler, server action or webhook."),"failed";let t=e.sessionId?null:e.userId||null;if(!e.sessionId&&!t)return"skipped_no_visitor";if(e.name.includes(":"))return console.error('[SentientUI] trackServerGoal: goal names cannot contain ":" (nothing was sent).'),"failed";let n=(i=e.fetch)!=null?i:fetch,s=new AbortController,r;try{let l=new Promise((a,u)=>{var x;r=setTimeout(()=>{s.abort(),u(new Error("timeout"))},(x=e.timeoutMs)!=null?x:Be)});l.catch(()=>{});let g=await Ne(t===null?`${e.sessionId}:${e.name}:${e.dedupeKey}`:`user:${e.serverKey}:${t}:${e.name}:${e.dedupeKey}`,Y),d=await Promise.race([n(`${((o=e.apiBaseUrl)!=null?o:Me).replace(/\/+$/,"")}/goals`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.serverKey}`},body:JSON.stringify(c(c(c(R(c({},t===null?{sessionId:e.sessionId}:{userId:t}),{name:e.name,goalId:g,externalId:e.dedupeKey}),e.value!==void 0?{value:e.value}:{}),e.currency!==void 0?{currency:e.currency}:{}),e.metadata!==void 0?{metadata:e.metadata}:{})),signal:s.signal}),l]);return d.ok?"recorded":t!==null&&d.status===404?(process.env.NODE_ENV!=="production"&&console.warn(`[SentientUI] trackServerGoal: no visit is linked to userId "${t}" yet, so "${e.name}" was not recorded. Identify the visitor in the browser first (<AdaptiveRoot userId>, or identify(userId, { userHash })) \u2014 once a project signs its identifies, only signed visits count.`),"skipped_no_visitor"):"failed"}catch(l){return"failed"}finally{r&&clearTimeout(r)}}var _={"chatgpt.com":"ChatGPT agent","muse.ai":"Meta Muse","meta.com":"Meta Muse","agent.bot.goog":"Google-Agent","browserbase.com":"Browserbase"};function X(e){if(!e)return null;for(let t of e.slice(0,512).matchAll(/https:\/\/[^"\s,;/]+/g)){let n;try{n=new URL(t[0]).hostname.toLowerCase()}catch(r){continue}let s=Object.keys(_).find(r=>n===r||n.endsWith(`.${r}`));if(s)return _[s]}return null}var D={"OAI-AdsBot":"other","Google-CloudVertexBot":"other","meta-externalfetcher":"user","meta-webindexer":"search","Amzn-SearchBot":"search","Amzn-User":"user","ChatGPT agent":"user","Meta Muse":"user",Browserbase:"user"},je=["OAI-AdsBot","Google-CloudVertexBot","meta-externalfetcher","meta-webindexer","Amzn-SearchBot","Amzn-User"];function Q(e){var r;let t=e!=null?e:"",n=O(t);if(n||!t)return n;let s=t.toLowerCase();return(r=je.find(i=>s.includes(i.toLowerCase())))!=null?r:null}function L(e,t){var n;return(n=Q(e))!=null?n:X(t)}function Z(e){if(!e)return"other";let t=c(c({},oe),D),n=Object.keys(t).find(s=>s.toLowerCase()===e.toLowerCase());return n&&t[n]||"other"}function Se(){let e={user:[],search:[],training:[],other:[]};for(let t of[...N,...Object.keys(D)])e[Z(t)].push(t);return e}var Ke="https://api.sentient-ui.com/v1";function Fe(e){try{return new URL(e,"http://localhost").pathname||"/"}catch(t){return e.split(/[?#]/,1)[0]||"/"}}function ee(e,t){var s,r,i,o;let n=(s=t.fetchImpl)!=null?s:typeof fetch=="function"?fetch:void 0;if(!(!n||!t.apiKey))try{let l=n(`${(r=t.baseUrl)!=null?r:Ke}/crawler-events`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${t.apiKey}`},body:JSON.stringify(R(c({path:e.path,botName:e.botName,userAgent:e.userAgent},e.signatureAgent?{signatureAgent:e.signatureAgent.slice(0,512)}:{}),{source:(i=t.source)!=null?i:"middleware"}))}).catch(()=>{});(o=t.waitUntil)==null||o.call(t,l)}catch(l){}}function te(e,t){var i;let n="",s=null;try{n=(i=e.headers.get("user-agent"))!=null?i:"",s=e.headers.get("signature-agent")}catch(o){return!1}let r=L(n,s);return r?(ee({path:Fe(e.url),userAgent:n,botName:r,signatureAgent:s},t),!0):!1}function we(e){return(t,n,s)=>{var r,i;try{let o=l=>{var d;let g=t.headers[l];return(d=Array.isArray(g)?g[0]:g)!=null?d:null};te({url:(i=(r=t.originalUrl)!=null?r:t.url)!=null?i:"/",headers:{get:l=>o(l.toLowerCase())}},R(c({},e),{source:"middleware"}))}catch(o){}s()}}0&&(module.exports={CLASSIC_CRAWLER_TOKENS,CLICK_ID_KEYS,SERVER_AGENT_INTENTS,SERVER_GOAL_NAMESPACE,SIGNED_AGENTS,buildSessionUpsertPayload,captureAgentRequest,deriveSessionSegment,detectDeviceClass,detectTimeOfDay,detectTrafficSource,extractTrackedParams,identifyAgent,matchedCrawlerToken,matchedServerAgentToken,matchedSignatureAgent,postAgentFetch,preloadAssignments,preloadAssignmentsDetailed,preloadDecisions,readInternalToken,readSessionCookie,referrerDomainFromReferer,sentientAgentMiddleware,serverAgentIntent,serverClassifiedAgents,signUserId,trackServerGoal});
|
|
2
2
|
//# sourceMappingURL=index-server.js.map
|