@sentientui/core 0.40.2 → 0.41.1

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/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{A as Z,B as _,C as $,D as aa,E as ba,F as ca,G as da,H as ea,I as fa,J as ga,K as ha,L as la,M as ma,N as na,O as oa,P as pa,Q as qa,R as ra,S as sa,T as ta,a as i,b as j,c as k,d as C,e as D,f as E,g as F,h as G,i as H,j as I,k as J,l as K,m as L,n as M,o as N,p as O,q as P,r as Q,s as R,t as S,u as T,v as U,w as V,x as W,y as X,z as Y}from"./chunk-ZTQXHKHU.mjs";import{a as d,b as e,c as f,d as g,n as h}from"./chunk-FPOHOWJP.mjs";import{a as ia,b as ja,c as ka}from"./chunk-EVF5PQ4U.mjs";import{a as l,b as m,c as n,d as o,e as p,f as q,g as r,h as s,i as t,j as u,k as v,l as w,m as x,o as y,p as z,q as A,r as B}from"./chunk-NBDVEYI5.mjs";import{b as a,c as b,e as c}from"./chunk-J5EL7HKC.mjs";import"./chunk-TMCGHANO.mjs";export{o as AGENT_INTENTS,M as BLOCK_ALIGNS,R as BLOCK_EMPHASES,U as BLOCK_FITS,L as BLOCK_GAPS,V as BLOCK_GRID_COLUMNS,W as BLOCK_HEADING_LEVELS,N as BLOCK_JUSTIFIES,Z as BLOCK_MAX_WIDTHS,Y as BLOCK_PADS,T as BLOCK_RATIOS,O as BLOCK_SIZES,X as BLOCK_SURFACES,S as BLOCK_TEXT_ALIGNS,Q as BLOCK_TONES,P as BLOCK_WEIGHTS,u as CLICK_ID_KEYS,_ as FORM_FIELD_KINDS,$ as FORM_INPUT_TYPES,a as LEGACY_SESSION_COOKIE_NAME,G as LOCAL_MODE_BANNER,fa as MAX_BLOCK_ARMS,ea as MAX_BLOCK_CHILDREN,da as MAX_BLOCK_DEPTH,ca as MAX_BLOCK_NODES,ga as MAX_BLOCK_TEXT_LEN,aa as MAX_FORM_FIELDS,ba as MAX_FORM_SELECT_OPTIONS,ja as MAX_SKELETON_LEAVES,ia as MAX_SKELETON_NODES,ka as MAX_SKELETON_TEXT,H as PAGE_SCOPE_RE,F as PROD_KEYLESS_ERROR,la as REVEAL_MS,d as SNAPSHOT_STORAGE_KEY_PREFIX,C as STAGE_ATTRIBUTE,pa as _registerConsentUpgradeInit,p as agentIntent,l as agentUaList,k as applyNonce,B as armOfResult,oa as attachMicroSignalDetectors,z as baselineResultFor,A as baselineSlots,q as classifiedAgents,ha as containsFormBlock,j as cspNonce,x as deriveSessionSegment,r as detectDeviceClass,w as detectTimeOfDay,s as detectTrafficSource,D as exposedStage,v as extractTrackedParams,c as forgetGeneration,h as forgetVisitor,ra as grantConsent,ta as init,qa as isDoNotTrackEnabled,n as matchedAgentToken,K as normalizeUrlPattern,I as pageScopeMatches,e as readSnapshot,t as referrerDomainFromReferer,g as renderPrePaintScript,ma as resetRevealStyles,na as reveal,sa as routeKey,b as sessionCookieName,i as setCspNonce,E as setStageAttribute,y as toWireSlot,m as uaTokenMatch,J as urlMatches,f as writeSnapshot};
1
+ import{A as $,B as aa,C as ba,D as ca,E as da,F as ea,G as fa,H as ga,I as ha,J as ia,K as ja,L as na,M as oa,N as pa,O as qa,P as ra,Q as sa,R as ta,S as ua,T as va,a as i,b as j,c as k,d as E,e as F,f as G,g as H,h as I,i as J,j as K,k as L,l as M,m as N,n as O,o as P,p as Q,q as R,r as S,s as T,t as U,u as V,v as W,w as X,x as Y,y as Z,z as _}from"./chunk-KXA3X6T3.mjs";import{a as d,b as e,c as f,d as g,n as h}from"./chunk-FPOHOWJP.mjs";import{a as ka,b as la,c as ma}from"./chunk-EVF5PQ4U.mjs";import{a as l,b as m,c as n,d as o,e as p,f as q,g as r,h as s,i as t,j as u,k as v,l as w,m as x,n as y,o as z,q as A,r as B,s as C,t as D}from"./chunk-3HMJERH4.mjs";import{b as a,c as b,e as c}from"./chunk-J5EL7HKC.mjs";import"./chunk-TMCGHANO.mjs";export{q as AGENT_INTENTS,O as BLOCK_ALIGNS,T as BLOCK_EMPHASES,W as BLOCK_FITS,N as BLOCK_GAPS,X as BLOCK_GRID_COLUMNS,Y as BLOCK_HEADING_LEVELS,P as BLOCK_JUSTIFIES,$ as BLOCK_MAX_WIDTHS,_ as BLOCK_PADS,V as BLOCK_RATIOS,Q as BLOCK_SIZES,Z as BLOCK_SURFACES,U as BLOCK_TEXT_ALIGNS,S as BLOCK_TONES,R as BLOCK_WEIGHTS,o as CLASSIC_CRAWLER_TOKENS,w as CLICK_ID_KEYS,aa as FORM_FIELD_KINDS,ba as FORM_INPUT_TYPES,a as LEGACY_SESSION_COOKIE_NAME,I as LOCAL_MODE_BANNER,ha as MAX_BLOCK_ARMS,ga as MAX_BLOCK_CHILDREN,fa as MAX_BLOCK_DEPTH,ea as MAX_BLOCK_NODES,ia as MAX_BLOCK_TEXT_LEN,ca as MAX_FORM_FIELDS,da as MAX_FORM_SELECT_OPTIONS,la as MAX_SKELETON_LEAVES,ka as MAX_SKELETON_NODES,ma as MAX_SKELETON_TEXT,J as PAGE_SCOPE_RE,H as PROD_KEYLESS_ERROR,na as REVEAL_MS,d as SNAPSHOT_STORAGE_KEY_PREFIX,E as STAGE_ATTRIBUTE,ra as _registerConsentUpgradeInit,r as agentIntent,l as agentUaList,k as applyNonce,D as armOfResult,qa as attachMicroSignalDetectors,B as baselineResultFor,C as baselineSlots,s as classifiedAgents,ja as containsFormBlock,j as cspNonce,z as deriveSessionSegment,t as detectDeviceClass,y as detectTimeOfDay,u as detectTrafficSource,F as exposedStage,x as extractTrackedParams,c as forgetGeneration,h as forgetVisitor,ta as grantConsent,va as init,sa as isDoNotTrackEnabled,n as matchedAgentToken,p as matchedCrawlerToken,M as normalizeUrlPattern,K as pageScopeMatches,e as readSnapshot,v as referrerDomainFromReferer,g as renderPrePaintScript,oa as resetRevealStyles,pa as reveal,ua as routeKey,b as sessionCookieName,i as setCspNonce,G as setStageAttribute,A as toWireSlot,m as uaTokenMatch,L as urlMatches,f as writeSnapshot};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -142,6 +142,19 @@ declare const agentUaList: readonly string[];
142
142
  declare function uaTokenMatch(userAgent: string): boolean;
143
143
  /** The first known agent token found in the user-agent, or null. */
144
144
  declare function matchedAgentToken(userAgent: string): string | null;
145
+ /**
146
+ * Classic search / link-preview crawlers. DISPLAY-ONLY: these name a request in
147
+ * the dashboard but must never join `agentUaList`, which also sets `automation`
148
+ * (and so bandit exclusion) — a crawler that is merely named must not change
149
+ * how the session is scored.
150
+ */
151
+ declare const CLASSIC_CRAWLER_TOKENS: readonly string[];
152
+ /**
153
+ * Name the crawler behind a user-agent: AI-agent tokens first (so
154
+ * `Applebot-Extended` is not swallowed by the shorter `Applebot`), then the
155
+ * classic list. Returns the canonical spelling, or null.
156
+ */
157
+ declare function matchedCrawlerToken(userAgent: string): string | null;
145
158
  /**
146
159
  * Purpose category for an agent fetch, inferred from its published user-agent:
147
160
  * - `user` — a person asked an assistant to read the page, live (…-User UAs)
@@ -208,6 +221,9 @@ type SessionUpsertPayload = {
208
221
  * token. Probabilistic: a flag for metrics + bandit exclusion, never a gate.
209
222
  */
210
223
  automation: boolean;
224
+ /** Which crawler / AI assistant requested a server-rendered page (canonical
225
+ * token). Absent for ordinary browsers. Naming only — never sets `automation`. */
226
+ agentToken?: string;
211
227
  };
212
228
  /** Bandit segment key: `<device_class>:<traffic_source>`. */
213
229
  declare function deriveSessionSegment(opts?: {
@@ -232,4 +248,4 @@ declare function buildSessionUpsertPayload(sessionId: string, opts?: {
232
248
  landingPath?: string;
233
249
  }): SessionUpsertPayload;
234
250
 
235
- export { AGENT_INTENTS as A, CLICK_ID_KEYS as C, type DecisionSnapshot as D, SNAPSHOT_STORAGE_KEY_PREFIX as S, type AgentIntent as a, type CompoundLocator as b, type SessionUpsertPayload as c, type SlotConfigEntry as d, type SlotDeclInput as e, type SlotOps as f, agentIntent as g, agentUaList as h, armOfResult as i, baselineResultFor as j, baselineSlots as k, buildSessionUpsertPayload as l, classifiedAgents as m, deriveSessionSegment as n, detectDeviceClass as o, detectTimeOfDay as p, detectTrafficSource as q, extractTrackedParams as r, matchedAgentToken as s, readSnapshot as t, referrerDomainFromReferer as u, renderPrePaintScript as v, toWireSlot as w, uaTokenMatch as x, writeSnapshot as y };
251
+ export { AGENT_INTENTS as A, writeSnapshot as B, CLASSIC_CRAWLER_TOKENS as C, type DecisionSnapshot as D, SNAPSHOT_STORAGE_KEY_PREFIX as S, type AgentIntent as a, CLICK_ID_KEYS as b, type CompoundLocator as c, type SessionUpsertPayload as d, type SlotConfigEntry as e, type SlotDeclInput as f, type SlotOps as g, agentIntent as h, agentUaList as i, armOfResult as j, baselineResultFor as k, baselineSlots as l, buildSessionUpsertPayload as m, classifiedAgents as n, deriveSessionSegment as o, detectDeviceClass as p, detectTimeOfDay as q, detectTrafficSource as r, extractTrackedParams as s, matchedAgentToken as t, matchedCrawlerToken as u, readSnapshot as v, referrerDomainFromReferer as w, renderPrePaintScript as x, toWireSlot as y, uaTokenMatch as z };
@@ -142,6 +142,19 @@ declare const agentUaList: readonly string[];
142
142
  declare function uaTokenMatch(userAgent: string): boolean;
143
143
  /** The first known agent token found in the user-agent, or null. */
144
144
  declare function matchedAgentToken(userAgent: string): string | null;
145
+ /**
146
+ * Classic search / link-preview crawlers. DISPLAY-ONLY: these name a request in
147
+ * the dashboard but must never join `agentUaList`, which also sets `automation`
148
+ * (and so bandit exclusion) — a crawler that is merely named must not change
149
+ * how the session is scored.
150
+ */
151
+ declare const CLASSIC_CRAWLER_TOKENS: readonly string[];
152
+ /**
153
+ * Name the crawler behind a user-agent: AI-agent tokens first (so
154
+ * `Applebot-Extended` is not swallowed by the shorter `Applebot`), then the
155
+ * classic list. Returns the canonical spelling, or null.
156
+ */
157
+ declare function matchedCrawlerToken(userAgent: string): string | null;
145
158
  /**
146
159
  * Purpose category for an agent fetch, inferred from its published user-agent:
147
160
  * - `user` — a person asked an assistant to read the page, live (…-User UAs)
@@ -208,6 +221,9 @@ type SessionUpsertPayload = {
208
221
  * token. Probabilistic: a flag for metrics + bandit exclusion, never a gate.
209
222
  */
210
223
  automation: boolean;
224
+ /** Which crawler / AI assistant requested a server-rendered page (canonical
225
+ * token). Absent for ordinary browsers. Naming only — never sets `automation`. */
226
+ agentToken?: string;
211
227
  };
212
228
  /** Bandit segment key: `<device_class>:<traffic_source>`. */
213
229
  declare function deriveSessionSegment(opts?: {
@@ -232,4 +248,4 @@ declare function buildSessionUpsertPayload(sessionId: string, opts?: {
232
248
  landingPath?: string;
233
249
  }): SessionUpsertPayload;
234
250
 
235
- export { AGENT_INTENTS as A, CLICK_ID_KEYS as C, type DecisionSnapshot as D, SNAPSHOT_STORAGE_KEY_PREFIX as S, type AgentIntent as a, type CompoundLocator as b, type SessionUpsertPayload as c, type SlotConfigEntry as d, type SlotDeclInput as e, type SlotOps as f, agentIntent as g, agentUaList as h, armOfResult as i, baselineResultFor as j, baselineSlots as k, buildSessionUpsertPayload as l, classifiedAgents as m, deriveSessionSegment as n, detectDeviceClass as o, detectTimeOfDay as p, detectTrafficSource as q, extractTrackedParams as r, matchedAgentToken as s, readSnapshot as t, referrerDomainFromReferer as u, renderPrePaintScript as v, toWireSlot as w, uaTokenMatch as x, writeSnapshot as y };
251
+ export { AGENT_INTENTS as A, writeSnapshot as B, CLASSIC_CRAWLER_TOKENS as C, type DecisionSnapshot as D, SNAPSHOT_STORAGE_KEY_PREFIX as S, type AgentIntent as a, CLICK_ID_KEYS as b, type CompoundLocator as c, type SessionUpsertPayload as d, type SlotConfigEntry as e, type SlotDeclInput as f, type SlotOps as g, agentIntent as h, agentUaList as i, armOfResult as j, baselineResultFor as k, baselineSlots as l, buildSessionUpsertPayload as m, classifiedAgents as n, deriveSessionSegment as o, detectDeviceClass as p, detectTimeOfDay as q, detectTrafficSource as r, extractTrackedParams as s, matchedAgentToken as t, matchedCrawlerToken as u, readSnapshot as v, referrerDomainFromReferer as w, renderPrePaintScript as x, toWireSlot as y, uaTokenMatch as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentientui/core",
3
- "version": "0.40.2",
3
+ "version": "0.41.1",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -89,7 +89,7 @@
89
89
  "llms.txt"
90
90
  ],
91
91
  "dependencies": {
92
- "@sentientui/policy": "0.16.0"
92
+ "@sentientui/policy": "0.17.0"
93
93
  },
94
94
  "devDependencies": {
95
95
  "@iabtechlabtcf/core": "1.5.22",
@@ -1,2 +0,0 @@
1
- import{a as s}from"./chunk-TMCGHANO.mjs";var c=["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 y(t){return b(t)!==null}function b(t){var r;if(!t)return null;let e=t.toLowerCase();return(r=c.find(i=>e.includes(i.toLowerCase())))!=null?r:null}var h={GPTBot:"training","ChatGPT-User":"user","OAI-SearchBot":"search",ClaudeBot:"training","Claude-User":"user","Claude-SearchBot":"search",PerplexityBot:"search","Perplexity-User":"user","Google-Extended":"training","Applebot-Extended":"training","Meta-ExternalAgent":"training",Bytespider:"training",CCBot:"training",Amazonbot:"other","cohere-ai":"training",Diffbot:"other"};function U(t){if(!t)return"other";let e=c.find(r=>r.toLowerCase()===t.toLowerCase());return e&&h[e]||"other"}function B(){var e;let t={user:[],search:[],training:[],other:[]};for(let r of c)t[(e=h[r])!=null?e:"other"].push(r);return t}function x(t){let e=t.toLowerCase();return/ipad|tablet|playbook|kindle|silk/.test(e)?"tablet":/mobi|iphone|ipod|android.*mobile|phone/.test(e)?"mobile":"desktop"}function R(t,e,r){if(!t)return"direct";try{let i=new URL(t);if(e)try{if(new URL(e).host===i.host)return"direct"}catch(o){}let n=i.hostname.toLowerCase();return r&&`.${n}`.endsWith(`.${r}`)?"direct":/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(n)?"search":/(^|\.)(twitter\.com|x\.com|facebook\.com|linkedin\.com|reddit\.com|t\.co)$/.test(n)?"social":"referral"}catch(i){return"direct"}}function S(t){if(!t)return null;try{return new URL(t).hostname}catch(e){return null}}var P=["gclid","gbraid","wbraid","fbclid","ttclid","msclkid","twclid","li_fat_id"];function L(t){let e={},r={};try{let i=typeof t=="string"||t instanceof URLSearchParams?new URLSearchParams(t):Object.entries(t).flatMap(([n,o])=>{let a=Array.isArray(o)?o[0]:o;return a===void 0?[]:[[n,a]]});for(let[n,o]of i)n.startsWith("utm_")?n in e||(e[n]=o):P.includes(n)&&(n in r||(r[n]=o))}catch(i){}return{utmParams:e,clickIds:r}}function p(t){let e=t.getHours();return e<6?"night":e<12?"morning":e<18?"afternoon":"evening"}function O(t){let e=C("__segment__",t);return`${e.deviceClass}:${e.trafficSource}`}function C(t,e){var o,a,l,g,u,d,f,m;let r=(a=(o=e==null?void 0:e.userAgent)==null?void 0:o.trim())!=null?a:"",i=(g=(l=e==null?void 0:e.referer)==null?void 0:l.trim())!=null?g:"",n=(u=e==null?void 0:e.now)!=null?u:new Date;return s({sessionId:t,ephemeral:!1,utmParams:(d=e==null?void 0:e.utmParams)!=null?d:{},clickIds:(f=e==null?void 0:e.clickIds)!=null?f:{},deviceClass:r?x(r):"desktop",trafficSource:i?R(i,e==null?void 0:e.appOrigin):"direct",referrerDomain:S(i),timeOfDay:p(n),dayOfWeek:(m=["sun","mon","tue","wed","thu","fri","sat"][n.getDay()])!=null?m:"sun",automation:(e==null?void 0:e.webdriver)===!0||y(r)},e!=null&&e.landingPath?{landingPath:e.landingPath.split(/[?#]/)[0]}:{})}import{canonicalArm as A,slotBaselineArm as I,slotResultFor as k}from"@sentientui/policy";function w(t){return s(s(s({id:t.id},t.arms?{arms:[...t.arms]}:{}),t.dims?{dims:Object.fromEntries(Object.entries(t.dims).map(([e,r])=>[e,[...r]]))}:{}),t.baseline!==void 0?{baseline:t.baseline}:{})}function D(t){let e=w(t);return k(e,I(e))}function v(t){let e={};for(let r of t)e[r.id]=D(r);return e}function G(t){return typeof t=="string"?t:A(t)}export{c as a,y as b,b as c,h as d,U as e,B as f,x as g,R as h,S as i,P as j,L as k,p as l,O as m,C as n,w as o,D as p,v as q,G as r};
2
- //# sourceMappingURL=chunk-NBDVEYI5.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/session-meta.ts","../src/slots.ts"],"sourcesContent":["/** Session metadata helpers (browser + Node). No DOM APIs. */\n\n/**\n * Known AI-agent / crawler user-agent tokens. Matched case-insensitively as\n * substrings. This is maintained data — bot lists move monthly. Used both to\n * flag automation on sessions (agentic browsers that leak a token) and by the\n * server middleware / agent-feed route to identify crawler HTTP reads.\n */\nexport const agentUaList: readonly string[] = [\n 'GPTBot',\n 'ChatGPT-User',\n 'OAI-SearchBot',\n 'ClaudeBot',\n 'Claude-User',\n 'Claude-SearchBot',\n 'PerplexityBot',\n 'Perplexity-User',\n 'Google-Extended',\n 'Applebot-Extended',\n 'Meta-ExternalAgent',\n 'Bytespider',\n 'CCBot',\n 'Amazonbot',\n 'cohere-ai',\n 'Diffbot',\n];\n\n/** True when the user-agent contains a known AI-agent / crawler token. */\nexport function uaTokenMatch(userAgent: string): boolean {\n return matchedAgentToken(userAgent) !== null;\n}\n\n/** The first known agent token found in the user-agent, or null. */\nexport function matchedAgentToken(userAgent: string): string | null {\n if (!userAgent) return null;\n const s = userAgent.toLowerCase();\n return agentUaList.find((token) => s.includes(token.toLowerCase())) ?? null;\n}\n\n/**\n * Purpose category for an agent fetch, inferred from its published user-agent:\n * - `user` — a person asked an assistant to read the page, live (…-User UAs)\n * - `search` — indexing for an AI answer engine (…-SearchBot / SearchBot)\n * - `training` — model-training crawl (GPTBot, ClaudeBot, CCBot, …)\n * - `other` — not clearly AI, or an unknown/new token\n */\nexport type AgentIntent = 'user' | 'search' | 'training' | 'other';\n\n/** Intent per agent token. Maintained beside `agentUaList` — when you add or\n * rename a token above, set its intent here (a unit test enforces coverage). */\nexport const AGENT_INTENTS: Record<string, AgentIntent> = {\n 'GPTBot': 'training',\n 'ChatGPT-User': 'user',\n 'OAI-SearchBot': 'search',\n 'ClaudeBot': 'training',\n 'Claude-User': 'user',\n 'Claude-SearchBot': 'search',\n 'PerplexityBot': 'search',\n 'Perplexity-User': 'user',\n 'Google-Extended': 'training',\n 'Applebot-Extended': 'training',\n 'Meta-ExternalAgent': 'training',\n 'Bytespider': 'training',\n 'CCBot': 'training',\n 'Amazonbot': 'other',\n 'cohere-ai': 'training',\n 'Diffbot': 'other',\n};\n\n/** Intent for a matched bot token (case-insensitive); `other` for null/unknown. */\nexport function agentIntent(botName: string | null): AgentIntent {\n if (!botName) return 'other';\n const hit = agentUaList.find((t) => t.toLowerCase() === botName.toLowerCase());\n return (hit && AGENT_INTENTS[hit]) || 'other';\n}\n\n/** `agentUaList` grouped by intent — the \"which crawlers do you classify?\" reference. */\nexport function classifiedAgents(): Record<AgentIntent, string[]> {\n const out: Record<AgentIntent, string[]> = { user: [], search: [], training: [], other: [] };\n for (const t of agentUaList) out[AGENT_INTENTS[t] ?? 'other'].push(t);\n return out;\n}\n\nexport function detectDeviceClass(userAgent: string): string {\n const s = userAgent.toLowerCase();\n if (/ipad|tablet|playbook|kindle|silk/.test(s)) return 'tablet';\n if (/mobi|iphone|ipod|android.*mobile|phone/.test(s)) return 'mobile';\n return 'desktop';\n}\n\nexport function detectTrafficSource(referrer: string, appOrigin?: string, siteDomain?: string | null): string {\n if (!referrer) return 'direct';\n try {\n const refUrl = new URL(referrer);\n if (appOrigin) {\n try {\n if (new URL(appOrigin).host === refUrl.host) return 'direct';\n } catch {\n /* ignore invalid appOrigin */\n }\n }\n const host = refUrl.hostname.toLowerCase();\n // Another host of the same site (the shared cookie domain): example.com →\n // app.example.com is a page view inside the site, scored like one.\n if (siteDomain && `.${host}`.endsWith(`.${siteDomain}`)) return 'direct';\n if (/(^|\\.)(google|bing|duckduckgo|yahoo)\\./.test(host)) return 'search';\n // Anchor to the registrable domain (exact host or a subdomain of it) so\n // hosts like `x.company.com`, `t.company.io` or `linkedinsights.com` are not\n // misclassified as social by an unbounded substring match.\n if (/(^|\\.)(twitter\\.com|x\\.com|facebook\\.com|linkedin\\.com|reddit\\.com|t\\.co)$/.test(host)) return 'social';\n return 'referral';\n } catch {\n return 'direct';\n }\n}\n\nexport function referrerDomainFromReferer(referrer: string): string | null {\n if (!referrer) return null;\n try {\n return new URL(referrer).hostname;\n } catch {\n return null;\n }\n}\n\n/**\n * Ad-platform click-ID query params worth keeping. An ALLOWLIST, unlike the\n * `utm_` prefix match: unknown query keys here are unbounded-cardinality junk\n * (session tokens, cache busters) that would bloat the sessions table, so only\n * the IDs the major ad platforms actually append survive.\n *\n * gclid / gbraid / wbraid — Google Ads auto-tagging (search, YouTube, Display;\n * gbraid/wbraid are the iOS-14 privacy variants)\n * fbclid — Meta (Facebook + Instagram). Appended to EVERY outbound Meta\n * click, paid and organic alike — it identifies the platform, never spend.\n * ttclid — TikTok Ads\n * msclkid — Microsoft Ads (Bing)\n * twclid — X/Twitter Ads\n * li_fat_id — LinkedIn Ads\n */\nexport const CLICK_ID_KEYS: readonly string[] = [\n 'gclid',\n 'gbraid',\n 'wbraid',\n 'fbclid',\n 'ttclid',\n 'msclkid',\n 'twclid',\n 'li_fat_id',\n];\n\n/**\n * Splits a URL query into the attribution params the session upsert carries:\n * every `utm_`-prefixed key, plus allowlisted ad click IDs (CLICK_ID_KEYS).\n * Accepts a raw search string (\"?a=b\" or \"a=b\"), a URLSearchParams, or a\n * Next.js `searchParams` object (whose values may be string arrays — the\n * first occurrence wins, matching URLSearchParams iteration order).\n * Node-safe: no DOM APIs.\n */\nexport function extractTrackedParams(\n search: string | URLSearchParams | Record<string, string | string[] | undefined>,\n): { utmParams: Record<string, string>; clickIds: Record<string, string> } {\n const utmParams: Record<string, string> = {};\n const clickIds: Record<string, string> = {};\n try {\n const entries: Iterable<[string, string]> =\n typeof search === 'string' || search instanceof URLSearchParams\n ? new URLSearchParams(search)\n : Object.entries(search).flatMap(([k, v]): Array<[string, string]> => {\n const first = Array.isArray(v) ? v[0] : v;\n return first === undefined ? [] : [[k, first]];\n });\n for (const [k, v] of entries) {\n // First occurrence wins for duplicates — a repeated gclid in a mangled\n // URL must not let the later value silently replace the real one.\n if (k.startsWith('utm_')) {\n if (!(k in utmParams)) utmParams[k] = v;\n } else if (CLICK_ID_KEYS.includes(k)) {\n if (!(k in clickIds)) clickIds[k] = v;\n }\n }\n } catch {\n /* malformed input → empty attribution, never a throw at init() */\n }\n return { utmParams, clickIds };\n}\n\nexport function detectTimeOfDay(d: Date): string {\n const h = d.getHours();\n if (h < 6) return 'night';\n if (h < 12) return 'morning';\n if (h < 18) return 'afternoon';\n return 'evening';\n}\n\nexport type SessionUpsertPayload = {\n sessionId: string;\n ephemeral: boolean;\n utmParams: Record<string, string>;\n /** Allowlisted ad-platform click IDs from the landing URL (CLICK_ID_KEYS). */\n clickIds: Record<string, string>;\n deviceClass: string;\n trafficSource: string;\n /** Landing page path, no query string (arrival classification). */\n landingPath?: string;\n referrerDomain: string | null;\n timeOfDay: string;\n dayOfWeek: string;\n /**\n * True when this session is likely driven by automation — either\n * `navigator.webdriver` was set, or the user-agent carried a known agent\n * token. Probabilistic: a flag for metrics + bandit exclusion, never a gate.\n */\n automation: boolean;\n};\n\n/** Bandit segment key: `<device_class>:<traffic_source>`. */\nexport function deriveSessionSegment(opts?: {\n userAgent?: string;\n referer?: string;\n appOrigin?: string;\n}): string {\n const body = buildSessionUpsertPayload('__segment__', opts);\n return `${body.deviceClass}:${body.trafficSource}`;\n}\n\n/**\n * Builds a session upsert body aligned with the browser SDK so SSR assign uses\n * the same segment key (`device:source`) as the client after hydration.\n */\nexport function buildSessionUpsertPayload(\n sessionId: string,\n opts?: {\n userAgent?: string;\n referer?: string;\n appOrigin?: string;\n utmParams?: Record<string, string>;\n clickIds?: Record<string, string>;\n now?: Date;\n /** `navigator.webdriver` value from the browser, when available. */\n webdriver?: boolean;\n /** The landing page's path (no query string), when the caller knows it. */\n landingPath?: string;\n },\n): SessionUpsertPayload {\n const ua = opts?.userAgent?.trim() ?? '';\n const referer = opts?.referer?.trim() ?? '';\n const now = opts?.now ?? new Date();\n return {\n sessionId,\n ephemeral: false,\n utmParams: opts?.utmParams ?? {},\n clickIds: opts?.clickIds ?? {},\n deviceClass: ua ? detectDeviceClass(ua) : 'desktop',\n trafficSource: referer\n ? detectTrafficSource(referer, opts?.appOrigin)\n : 'direct',\n referrerDomain: referrerDomainFromReferer(referer),\n timeOfDay: detectTimeOfDay(now),\n dayOfWeek: ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'][now.getDay()] ?? 'sun',\n automation: opts?.webdriver === true || uaTokenMatch(ua),\n ...(opts?.landingPath ? { landingPath: opts.landingPath.split(/[?#]/)[0] } : {}),\n };\n}\n","/**\n * Slot declaration helpers shared by the browser client (decide) and the\n * server preload path. Pure wrappers over @sentientui/policy.\n */\nimport {\n canonicalArm,\n slotBaselineArm,\n slotResultFor,\n type SlotDecl,\n type SlotResult,\n} from '@sentientui/policy';\n\n/** SDK-facing slot declaration. `dims` accepts readonly arrays (`as const`). */\nexport type SlotDeclInput = {\n id: string;\n arms?: string[];\n dims?: Record<string, readonly string[]>;\n baseline?: string | Record<string, string>;\n};\n\nexport type { SlotResult };\n\n/**\n * Whitelists the wire fields of a slot declaration. Anything an SDK layer\n * attached (goal configs, refs, …) is stripped so it never reaches the zod\n * schema on the API. Also normalizes readonly arrays to mutable ones.\n */\nexport function toWireSlot(d: SlotDeclInput): SlotDecl {\n return {\n id: d.id,\n ...(d.arms ? { arms: [...d.arms] } : {}),\n ...(d.dims\n ? {\n dims: Object.fromEntries(\n Object.entries(d.dims).map(([dim, values]) => [dim, [...values]]),\n ),\n }\n : {}),\n ...(d.baseline !== undefined ? { baseline: d.baseline } : {}),\n };\n}\n\n/** The declared (or default first-declared) baseline result for a slot. */\nexport function baselineResultFor(d: SlotDeclInput): SlotResult {\n const decl = toWireSlot(d);\n return slotResultFor(decl, slotBaselineArm(decl));\n}\n\n/** Baseline results for a whole declaration list, keyed by slot id. */\nexport function baselineSlots(decls: SlotDeclInput[]): Record<string, SlotResult> {\n const out: Record<string, SlotResult> = {};\n for (const d of decls) out[d.id] = baselineResultFor(d);\n return out;\n}\n\n/**\n * Canonical arm string of a slot result: dims results encode as sorted\n * `dim=value` pairs joined with '|'; arms results are the arm id verbatim.\n */\nexport function armOfResult(result: SlotResult): string {\n return typeof result === 'string' ? result : canonicalArm(result);\n}\n"],"mappings":"yCAQO,IAAMA,EAAiC,CAC5C,SACA,eACA,gBACA,YACA,cACA,mBACA,gBACA,kBACA,kBACA,oBACA,qBACA,aACA,QACA,YACA,YACA,SACF,EAGO,SAASC,EAAaC,EAA4B,CACvD,OAAOC,EAAkBD,CAAS,IAAM,IAC1C,CAGO,SAASC,EAAkBD,EAAkC,CAjCpE,IAAAE,EAkCE,GAAI,CAACF,EAAW,OAAO,KACvB,IAAMG,EAAIH,EAAU,YAAY,EAChC,OAAOE,EAAAJ,EAAY,KAAMM,GAAUD,EAAE,SAASC,EAAM,YAAY,CAAC,CAAC,IAA3D,KAAAF,EAAgE,IACzE,CAaO,IAAMG,EAA6C,CACxD,OAAU,WACV,eAAgB,OAChB,gBAAiB,SACjB,UAAa,WACb,cAAe,OACf,mBAAoB,SACpB,cAAiB,SACjB,kBAAmB,OACnB,kBAAmB,WACnB,oBAAqB,WACrB,qBAAsB,WACtB,WAAc,WACd,MAAS,WACT,UAAa,QACb,YAAa,WACb,QAAW,OACb,EAGO,SAASC,EAAYC,EAAqC,CAC/D,GAAI,CAACA,EAAS,MAAO,QACrB,IAAMC,EAAMV,EAAY,KAAMW,GAAMA,EAAE,YAAY,IAAMF,EAAQ,YAAY,CAAC,EAC7E,OAAQC,GAAOH,EAAcG,CAAG,GAAM,OACxC,CAGO,SAASE,GAAkD,CA7ElE,IAAAR,EA8EE,IAAMS,EAAqC,CAAE,KAAM,CAAC,EAAG,OAAQ,CAAC,EAAG,S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,EAASZ,GAAA,YAAAA,EAAM,SAAS,EAC5C,SACJ,eAAgBd,EAA0B0B,CAAO,EACjD,UAAWhB,EAAgBiB,CAAG,EAC9B,WAAWH,EAAA,CAAC,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,KAAK,EAAEG,EAAI,OAAO,CAAC,IAA9D,KAAAH,EAAmE,MAC9E,YAAYV,GAAA,YAAAA,EAAM,aAAc,IAAQnC,EAAa8C,CAAE,GACnDX,GAAA,MAAAA,EAAM,YAAc,CAAE,YAAaA,EAAK,YAAY,MAAM,MAAM,EAAE,CAAC,CAAE,EAAI,CAAC,EAElF,CCnQA,OACE,gBAAAe,EACA,mBAAAC,EACA,iBAAAC,MAGK,qBAiBA,SAASC,EAAWC,EAA4B,CACrD,OAAOC,MAAA,CACL,GAAID,EAAE,IACFA,EAAE,KAAO,CAAE,KAAM,CAAC,GAAGA,EAAE,IAAI,CAAE,EAAI,CAAC,GAClCA,EAAE,KACF,CACE,KAAM,OAAO,YACX,OAAO,QAAQA,EAAE,IAAI,EAAE,IAAI,CAAC,CAACE,EAAKC,CAAM,IAAM,CAACD,EAAK,CAAC,GAAGC,CAAM,CAAC,CAAC,CAClE,CACF,EACA,CAAC,GACDH,EAAE,WAAa,OAAY,CAAE,SAAUA,EAAE,QAAS,EAAI,CAAC,EAE/D,CAGO,SAASI,EAAkBJ,EAA8B,CAC9D,IAAMK,EAAON,EAAWC,CAAC,EACzB,OAAOM,EAAcD,EAAME,EAAgBF,CAAI,CAAC,CAClD,CAGO,SAASG,EAAcC,EAAoD,CAChF,IAAMC,EAAkC,CAAC,EACzC,QAAWV,KAAKS,EAAOC,EAAIV,EAAE,EAAE,EAAII,EAAkBJ,CAAC,EACtD,OAAOU,CACT,CAMO,SAASC,EAAYC,EAA4B,CACtD,OAAO,OAAOA,GAAW,SAAWA,EAASC,EAAaD,CAAM,CAClE","names":["agentUaList","uaTokenMatch","userAgent","matchedAgentToken","_a","s","token","AGENT_INTENTS","agentIntent","botName","hit","t","classifiedAgents","out","detectDeviceClass","detectTrafficSource","referrer","appOrigin","siteDomain","refUrl","e","host","referrerDomainFromReferer","CLICK_ID_KEYS","extractTrackedParams","search","utmParams","clickIds","entries","k","v","first","detectTimeOfDay","d","h","deriveSessionSegment","opts","body","buildSessionUpsertPayload","sessionId","_b","_c","_d","_e","_f","_g","_h","ua","referer","now","__spreadValues","canonicalArm","slotBaselineArm","slotResultFor","toWireSlot","d","__spreadValues","dim","values","baselineResultFor","decl","slotResultFor","slotBaselineArm","baselineSlots","decls","out","armOfResult","result","canonicalArm"]}