@sentientui/policy 0.6.1 → 0.6.2
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.d.cts +18 -1
- package/dist/index.d.ts +18 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -321,6 +321,23 @@ declare function sampleArmEv(arms: EvArm[], reference: number, rand?: () => numb
|
|
|
321
321
|
* MUST stay in sync with the CHECK constraint in migration 113.
|
|
322
322
|
*/
|
|
323
323
|
declare const PERSONA_KEY_RE: RegExp;
|
|
324
|
+
/**
|
|
325
|
+
* Normalizes a persona value declared by the SDK, or returns null when it is
|
|
326
|
+
* not shaped like a persona key at all.
|
|
327
|
+
*
|
|
328
|
+
* The SDK docs all say "never a user id or email", and migration 113's CHECK
|
|
329
|
+
* keeps such a value out of `persona_set_members.key` — but the two ingest
|
|
330
|
+
* sinks added later (`sessions.declared_persona` and the unrecognized-value
|
|
331
|
+
* counter, which the Settings page renders verbatim) took whatever the browser
|
|
332
|
+
* sent. A customer wiring `persona={user.email}` therefore put real addresses
|
|
333
|
+
* in both, with no subject-erasure path out of the counter.
|
|
334
|
+
*
|
|
335
|
+
* Rejecting here loses nothing the nudge needs: a genuine typo like 'staff'
|
|
336
|
+
* still matches, so it is still counted and still offered as "add it?". Only
|
|
337
|
+
* values that could never BE a key — anything with '@', a space, uppercase, or
|
|
338
|
+
* over 32 characters — are refused.
|
|
339
|
+
*/
|
|
340
|
+
declare function normalizeDeclaredPersona(raw: string | null | undefined): string | null;
|
|
324
341
|
/**
|
|
325
342
|
* Keys no vocabulary member may claim. 'unknown' and '__all__' are structural
|
|
326
343
|
* in weightCellsFor / CONTRACTS §4; the plural forms are pre-069 legacy labels
|
|
@@ -387,4 +404,4 @@ declare function resolvePersona(input: {
|
|
|
387
404
|
*/
|
|
388
405
|
declare function decisionPersona(label: string | null | undefined): string;
|
|
389
406
|
|
|
390
|
-
export { type ArmPosterior, CLUSTER_PRIORITY, DEFAULT_PERSONA_VOCABULARY, EV_SHRINK_K, type EvArm, LEGACY_PERSONA_MAP, type LearnedLayout, PERSONAS, PERSONA_DISPLAY, PERSONA_KEY_RE, POOL_ALL, type Persona, type PersonaKey, type PersonaResolution, type PersonaVocabularyMember, type PoolCells, type PoolCounts, RESERVED_PERSONA_KEYS, SHRINKAGE_M, type SlotDecl, type SlotResult, UNKNOWN_PERSONA, type ValueCell, type ValueCellRow, applyClusterHeuristic, broadestValueCell, candidateLayouts, canonicalArm, canonicalPersona, chooseLayout, confidenceBand, decisionPersona, fnv1a, hashLayout, marginalArmKey, parseArm, pickDeterministicArm, pooledPosterior, posteriorOfCounts, resolvePersona, sampleArm, sampleArmEv, sampleBeta, shrunkAvgValue, shrunkPosterior, slotBaselineArm, slotResultFor, validateSlotDecl, weightCellsFor };
|
|
407
|
+
export { type ArmPosterior, CLUSTER_PRIORITY, DEFAULT_PERSONA_VOCABULARY, EV_SHRINK_K, type EvArm, LEGACY_PERSONA_MAP, type LearnedLayout, PERSONAS, PERSONA_DISPLAY, PERSONA_KEY_RE, POOL_ALL, type Persona, type PersonaKey, type PersonaResolution, type PersonaVocabularyMember, type PoolCells, type PoolCounts, RESERVED_PERSONA_KEYS, SHRINKAGE_M, type SlotDecl, type SlotResult, UNKNOWN_PERSONA, type ValueCell, type ValueCellRow, applyClusterHeuristic, broadestValueCell, candidateLayouts, canonicalArm, canonicalPersona, chooseLayout, confidenceBand, decisionPersona, fnv1a, hashLayout, marginalArmKey, normalizeDeclaredPersona, parseArm, pickDeterministicArm, pooledPosterior, posteriorOfCounts, resolvePersona, sampleArm, sampleArmEv, sampleBeta, shrunkAvgValue, shrunkPosterior, slotBaselineArm, slotResultFor, validateSlotDecl, weightCellsFor };
|
package/dist/index.d.ts
CHANGED
|
@@ -321,6 +321,23 @@ declare function sampleArmEv(arms: EvArm[], reference: number, rand?: () => numb
|
|
|
321
321
|
* MUST stay in sync with the CHECK constraint in migration 113.
|
|
322
322
|
*/
|
|
323
323
|
declare const PERSONA_KEY_RE: RegExp;
|
|
324
|
+
/**
|
|
325
|
+
* Normalizes a persona value declared by the SDK, or returns null when it is
|
|
326
|
+
* not shaped like a persona key at all.
|
|
327
|
+
*
|
|
328
|
+
* The SDK docs all say "never a user id or email", and migration 113's CHECK
|
|
329
|
+
* keeps such a value out of `persona_set_members.key` — but the two ingest
|
|
330
|
+
* sinks added later (`sessions.declared_persona` and the unrecognized-value
|
|
331
|
+
* counter, which the Settings page renders verbatim) took whatever the browser
|
|
332
|
+
* sent. A customer wiring `persona={user.email}` therefore put real addresses
|
|
333
|
+
* in both, with no subject-erasure path out of the counter.
|
|
334
|
+
*
|
|
335
|
+
* Rejecting here loses nothing the nudge needs: a genuine typo like 'staff'
|
|
336
|
+
* still matches, so it is still counted and still offered as "add it?". Only
|
|
337
|
+
* values that could never BE a key — anything with '@', a space, uppercase, or
|
|
338
|
+
* over 32 characters — are refused.
|
|
339
|
+
*/
|
|
340
|
+
declare function normalizeDeclaredPersona(raw: string | null | undefined): string | null;
|
|
324
341
|
/**
|
|
325
342
|
* Keys no vocabulary member may claim. 'unknown' and '__all__' are structural
|
|
326
343
|
* in weightCellsFor / CONTRACTS §4; the plural forms are pre-069 legacy labels
|
|
@@ -387,4 +404,4 @@ declare function resolvePersona(input: {
|
|
|
387
404
|
*/
|
|
388
405
|
declare function decisionPersona(label: string | null | undefined): string;
|
|
389
406
|
|
|
390
|
-
export { type ArmPosterior, CLUSTER_PRIORITY, DEFAULT_PERSONA_VOCABULARY, EV_SHRINK_K, type EvArm, LEGACY_PERSONA_MAP, type LearnedLayout, PERSONAS, PERSONA_DISPLAY, PERSONA_KEY_RE, POOL_ALL, type Persona, type PersonaKey, type PersonaResolution, type PersonaVocabularyMember, type PoolCells, type PoolCounts, RESERVED_PERSONA_KEYS, SHRINKAGE_M, type SlotDecl, type SlotResult, UNKNOWN_PERSONA, type ValueCell, type ValueCellRow, applyClusterHeuristic, broadestValueCell, candidateLayouts, canonicalArm, canonicalPersona, chooseLayout, confidenceBand, decisionPersona, fnv1a, hashLayout, marginalArmKey, parseArm, pickDeterministicArm, pooledPosterior, posteriorOfCounts, resolvePersona, sampleArm, sampleArmEv, sampleBeta, shrunkAvgValue, shrunkPosterior, slotBaselineArm, slotResultFor, validateSlotDecl, weightCellsFor };
|
|
407
|
+
export { type ArmPosterior, CLUSTER_PRIORITY, DEFAULT_PERSONA_VOCABULARY, EV_SHRINK_K, type EvArm, LEGACY_PERSONA_MAP, type LearnedLayout, PERSONAS, PERSONA_DISPLAY, PERSONA_KEY_RE, POOL_ALL, type Persona, type PersonaKey, type PersonaResolution, type PersonaVocabularyMember, type PoolCells, type PoolCounts, RESERVED_PERSONA_KEYS, SHRINKAGE_M, type SlotDecl, type SlotResult, UNKNOWN_PERSONA, type ValueCell, type ValueCellRow, applyClusterHeuristic, broadestValueCell, candidateLayouts, canonicalArm, canonicalPersona, chooseLayout, confidenceBand, decisionPersona, fnv1a, hashLayout, marginalArmKey, normalizeDeclaredPersona, parseArm, pickDeterministicArm, pooledPosterior, posteriorOfCounts, resolvePersona, sampleArm, sampleArmEv, sampleBeta, shrunkAvgValue, shrunkPosterior, slotBaselineArm, slotResultFor, validateSlotDecl, weightCellsFor };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var L=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var fe=Object.getOwnPropertyNames,T=Object.getOwnPropertySymbols;var X=Object.prototype.hasOwnProperty,me=Object.prototype.propertyIsEnumerable;var Z=(e,r,n)=>r in e?L(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n,$=(e,r)=>{for(var n in r||(r={}))X.call(r,n)&&Z(e,n,r[n]);if(T)for(var n of T(r))me.call(r,n)&&Z(e,n,r[n]);return e};var be=(e,r)=>{for(var n in r)L(e,n,{get:r[n],enumerable:!0})},pe=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of fe(r))!X.call(e,s)&&s!==n&&L(e,s,{get:()=>r[s],enumerable:!(t=ce(r,s))||t.enumerable});return e};var ge=e=>pe(L({},"__esModule",{value:!0}),e);var Oe={};be(Oe,{CLUSTER_PRIORITY:()=>Q,DEFAULT_PERSONA_VOCABULARY:()=>ae,EV_SHRINK_K:()=>te,LEGACY_PERSONA_MAP:()=>M,PERSONAS:()=>S,PERSONA_DISPLAY:()=>j,PERSONA_KEY_RE:()=>we,POOL_ALL:()=>g,RESERVED_PERSONA_KEYS:()=>se,SHRINKAGE_M:()=>re,UNKNOWN_PERSONA:()=>y,applyClusterHeuristic:()=>O,broadestValueCell:()=>Re,candidateLayouts:()=>z,canonicalArm:()=>G,canonicalPersona:()=>N,chooseLayout:()=>he,confidenceBand:()=>_e,decisionPersona:()=>Ne,fnv1a:()=>ne,hashLayout:()=>H,marginalArmKey:()=>ye,parseArm:()=>F,pickDeterministicArm:()=>ve,pooledPosterior:()=>ke,posteriorOfCounts:()=>C,resolvePersona:()=>Me,sampleArm:()=>Y,sampleArmEv:()=>Ce,sampleBeta:()=>v,shrunkAvgValue:()=>oe,shrunkPosterior:()=>_,slotBaselineArm:()=>ee,slotResultFor:()=>Ae,validateSlotDecl:()=>Pe,weightCellsFor:()=>Se});module.exports=ge(Oe);var S=["buyer","researcher","deal_seeker","browser"],y="unknown",j={buyer:"Buyer",researcher:"Researcher",deal_seeker:"Deal seeker",browser:"Browser",unknown:"Unknown"},M={buyers:"buyer",researchers:"researcher","deal-seekers":"deal_seeker",browsers:"browser",buyer:"buyer",researcher:"researcher",deal_seeker:"deal_seeker",browser:"browser"};function N(e){var n;if(e==null)return y;let r=e.trim().toLowerCase();return(n=M[r])!=null?n:y}var de=[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 d(e,r){return e>>>r|e<<32-r}function J(e){return(e>>>0).toString(16).padStart(8,"0")}function xe(e){let r=new TextEncoder().encode(e),n=r.length,t=n*8,s=(n+8>>6)+1<<6,o=new Uint8Array(s);o.set(r),o[n]=128;let a=new DataView(o.buffer);a.setUint32(s-8,Math.floor(t/4294967296),!1),a.setUint32(s-4,t>>>0,!1);let i=1779033703,u=3144134277,f=1013904242,c=2773480762,p=1359893119,m=2600822924,P=528734635,A=1541459225,b=new Uint32Array(64);for(let K=0;K<s;K+=64){for(let l=0;l<16;l++)b[l]=a.getUint32(K+l*4,!1);for(let l=16;l<64;l++){let q=d(b[l-15],7)^d(b[l-15],18)^b[l-15]>>>3,I=d(b[l-2],17)^d(b[l-2],19)^b[l-2]>>>10;b[l]=b[l-16]+q+b[l-7]+I>>>0}let x=i,k=u,R=f,V=c,h=p,w=m,E=P,U=A;for(let l=0;l<64;l++){let q=d(h,6)^d(h,11)^d(h,25),I=h&w^~h&E,W=U+q+I+de[l]+b[l]>>>0,ie=d(x,2)^d(x,13)^d(x,22),ue=x&k^x&R^k&R,le=ie+ue>>>0;U=E,E=w,w=h,h=V+W>>>0,V=R,R=k,k=x,x=W+le>>>0}i=i+x>>>0,u=u+k>>>0,f=f+R>>>0,c=c+V>>>0,p=p+h>>>0,m=m+w>>>0,P=P+E>>>0,A=A+U>>>0}return J(i)+J(u)}function H(e){return xe(e.join("|"))}var Q={buyer:["pricing","cta","hero","comparison","social_proof","trust","features","faq","navigation","generic"],researcher:["features","comparison","faq","hero","trust","social_proof","pricing","cta","navigation","generic"],deal_seeker:["pricing","comparison","social_proof","trust","cta","hero","features","faq","navigation","generic"],browser:["hero","features","social_proof","pricing","cta","trust","faq","comparison","navigation","generic"]};function O(e,r,n){let t=Q[n];if(!t)return e;let s=t.indexOf("generic"),o=a=>{let i=t.indexOf(a);return i===-1?s:i};return[...e].sort((a,i)=>{var c,p;let u=(c=r.get(a))!=null?c:"generic",f=(p=r.get(i))!=null?p:"generic";return o(u)-o(f)})}function z(e,r,n){let t=new Map;for(let s of[...S,n]){let o=O(e,r,s);t.set(H(o),o)}return t}function B(e,r){if(e<1)return B(1+e,r)*Math.pow(Math.max(1e-15,r()),1/e);let n=e-1/3,t=1/Math.sqrt(9*n);for(;;){let s,o;do{let i=Math.max(1e-15,r()),u=r();s=Math.sqrt(-2*Math.log(i))*Math.cos(2*Math.PI*u),o=1+t*s}while(o<=0);o=o*o*o;let a=r();if(a<1-.0331*s*s*s*s||Math.log(a)<.5*s*s+n*(1-o+Math.log(o)))return n*o}}function v(e,r,n=Math.random){let t=B(e,n),s=B(r,n),o=t+s;return o<=0?e/(e+r):t/o}function Y(e,r=Math.random){if(e.length===0)return null;if(e.length===1)return e[0].arm;let n=e[0],t=v(n.alpha,n.beta,r);for(let s=1;s<e.length;s++){let o=e[s],a=v(o.alpha,o.beta,r);a>t&&(n=o,t=a)}return n.arm}function he(e,r,n,t,s=Math.random){var f,c;let o=z(e,r,n),a=[];for(let p of o.keys()){let m=t.get(p);a.push({arm:p,alpha:(f=m==null?void 0:m.alpha)!=null?f:1,beta:(c=m==null?void 0:m.beta)!=null?c:1})}let i=Y(a,s),u=i?o.get(i):void 0;return u!=null?u:O(e,r,n)}function G(e){return Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("|")}function F(e){if(e.length===0)return null;let r={};for(let n of e.split("|")){let t=n.indexOf("=");if(t<=0||t!==n.lastIndexOf("=")||t===n.length-1)return null;let s=n.slice(0,t);if(s in r)return null;r[s]=n.slice(t+1)}return r}function ye(e,r){return`${e}=${r}`}function ee(e){var n,t,s;if(e.arms)return typeof e.baseline=="string"?e.baseline:(n=e.arms[0])!=null?n:"";if(e.baseline!==void 0&&typeof e.baseline=="object")return G(e.baseline);if(typeof e.baseline=="string")return e.baseline;let r={};for(let[o,a]of Object.entries((t=e.dims)!=null?t:{}))r[o]=(s=a[0])!=null?s:"";return G(r)}function Pe(e){let r=Array.isArray(e.arms),n=e.dims!=null;if(r&&n)return{ok:!1,reason:"declare exactly one of arms or dims (got both)"};if(!r&&!n)return{ok:!1,reason:"declare exactly one of arms or dims (got neither)"};if(r){let o=e.arms;if(o.length<2)return{ok:!1,reason:"arms requires at least 2 entries"};if(o.length>12)return{ok:!1,reason:"arms allows at most 12 entries"};if(new Set(o).size!==o.length)return{ok:!1,reason:"arms must be unique"};if(o.some(a=>a.includes("=")))return{ok:!1,reason:"enumerated arm ids may not contain '=' (reserved for dims encoding)"};if(e.baseline!==void 0){if(typeof e.baseline!="string")return{ok:!1,reason:"baseline for an arms slot must be a string"};if(!o.includes(e.baseline))return{ok:!1,reason:"baseline must be one of the declared arms"}}return{ok:!0}}let t=Object.entries(e.dims);if(t.length<1)return{ok:!1,reason:"dims requires at least 1 dimension"};if(t.length>4)return{ok:!1,reason:"dims allows at most 4 dimensions"};let s=1;for(let[o,a]of t){if(a.length<2)return{ok:!1,reason:`dim "${o}" requires at least 2 values`};if(a.length>6)return{ok:!1,reason:`dim "${o}" allows at most 6 values`};if(new Set(a).size!==a.length)return{ok:!1,reason:`dim "${o}" has duplicate values`};s*=a.length}if(s>64)return{ok:!1,reason:`declared space of ${s} combinations exceeds the 64 maximum`};if(e.baseline!==void 0){if(typeof e.baseline=="string")return{ok:!1,reason:"baseline for a dims slot must be a per-dim record"};let o=e.baseline,a=t.map(([u])=>u).sort(),i=Object.keys(o).sort();if(a.join(" ")!==i.join(" "))return{ok:!1,reason:"baseline must set every declared dim exactly once"};for(let[u,f]of t)if(!f.includes(o[u]))return{ok:!1,reason:`baseline value for dim "${u}" is not declared`}}return{ok:!0}}function Ae(e,r){var n,t;return e.dims!=null?(t=(n=F(r))!=null?n:F(ee(e)))!=null?t:{}:r}var re=20;function _(e,r,n=20){let t=r.alpha+r.beta;if(t<=0||n<=0)return{alpha:e.alpha,beta:e.beta};let s=r.alpha/t,o=n*t/(t+n);return{alpha:e.alpha+o*s,beta:e.beta+o*(1-s)}}var g="__all__",D={exposures:0,conversions:0};function C(e){return{alpha:e.conversions+1,beta:Math.max(0,e.exposures-e.conversions)+1}}function ke(e,r,n=20){var m,P,A,b;let t=(m=e.segment)!=null?m:D,s=(P=e.global)!=null?P:D,o=C(s),a=_(C(t),o,n);if(!r)return a;let i=(A=e.persona)!=null?A:D,u=(b=e.child)!=null?b:D,f=_(C(i),o,n),c=(t.exposures+1)/(t.exposures+i.exposures+2),p={alpha:c*a.alpha+(1-c)*f.alpha,beta:c*a.beta+(1-c)*f.beta};return _(C(u),p,n)}function Re(e){var t,s;let r=null,n=-1;for(let o of e){let a=o.segment===g,i=o.persona===g,u=a&&i?3:a||i?2:1;u>n&&(n=u,r=o)}return{valueSum:(t=r==null?void 0:r.valueSum)!=null?t:0,valueCount:(s=r==null?void 0:r.valueCount)!=null?s:0}}function Se(e,r){return r==="unknown"||r===g||r===""?[{segment:e,persona:g},{segment:g,persona:g}]:[{segment:e,persona:r},{segment:e,persona:g},{segment:g,persona:r},{segment:g,persona:g}]}function ne(e){let r=2166136261;for(let n=0;n<e.length;n++)r^=e.charCodeAt(n),r=r+((r<<1)+(r<<4)+(r<<7)+(r<<8)+(r<<24))>>>0;return r}function ve(e,r,n){if(n.length===0)throw new Error("pickDeterministicArm requires at least one arm");let t=[...n].sort();return t[ne(`${e}:${r}`)%t.length]}function _e(e){return e>=.3?e<.7?"medium":"high":"low"}var te=20;function oe(e,r,n=te){let t=e.valueCount>0?e.valueSum/e.valueCount:0;if(r<=0)return t;if(e.valueCount<=0)return r;let s=e.valueCount/(e.valueCount+n);return s*t+(1-s)*r}function Ce(e,r,n=Math.random){if(e.length===0)return null;if(e.length===1)return e[0].arm;let t=null,s=-1/0;for(let o of e){let a=v(o.alpha,o.beta,n)*oe(o,r);a>s&&(t=o,s=a)}return t.arm}var we=/^[a-z0-9][a-z0-9_-]{0,31}$/,se=["unknown","__all__","buyers","researchers","deal-seekers","browsers"],ae=S.map(e=>({key:e,displayName:j[e]})),Ee=64;function Le(e){var n;let r=new Map;for(let t of e)if(t.status!=="retired"){r.set(t.key,t.key);for(let s of(n=t.aliases)!=null?n:[])se.includes(s)||r.set(s,t.key)}return r}function Me(e,r=ae){var i,u,f;let n=Le(r),t=(i=e.inferredConfidence)!=null?i:0,s,o=(f=(u=e.declared)==null?void 0:u.trim().toLowerCase())!=null?f:"";if(o!==""){let c=n.get(o),p=c===void 0?n.get(N(o)):void 0,m=c!=null?c:p;if(m!==void 0)return{persona:m,source:"declared",confidence:1};s=o.slice(0,Ee)}let a=N(e.clusterLabel);return a!==y&&n.has(a)?$({persona:n.get(a),source:"inferred",confidence:t},s!==void 0&&{unrecognizedDeclared:s}):$({persona:y,source:"none",confidence:t},s!==void 0&&{unrecognizedDeclared:s})}function Ne(e){var n;if(e==null)return y;let r=e.trim().toLowerCase();return r===""?y:(n=M[r])!=null?n:r}0&&(module.exports={CLUSTER_PRIORITY,DEFAULT_PERSONA_VOCABULARY,EV_SHRINK_K,LEGACY_PERSONA_MAP,PERSONAS,PERSONA_DISPLAY,PERSONA_KEY_RE,POOL_ALL,RESERVED_PERSONA_KEYS,SHRINKAGE_M,UNKNOWN_PERSONA,applyClusterHeuristic,broadestValueCell,candidateLayouts,canonicalArm,canonicalPersona,chooseLayout,confidenceBand,decisionPersona,fnv1a,hashLayout,marginalArmKey,parseArm,pickDeterministicArm,pooledPosterior,posteriorOfCounts,resolvePersona,sampleArm,sampleArmEv,sampleBeta,shrunkAvgValue,shrunkPosterior,slotBaselineArm,slotResultFor,validateSlotDecl,weightCellsFor});
|
|
1
|
+
"use strict";var L=Object.defineProperty;var fe=Object.getOwnPropertyDescriptor;var me=Object.getOwnPropertyNames,T=Object.getOwnPropertySymbols;var X=Object.prototype.hasOwnProperty,pe=Object.prototype.propertyIsEnumerable;var Z=(e,r,n)=>r in e?L(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n,$=(e,r)=>{for(var n in r||(r={}))X.call(r,n)&&Z(e,n,r[n]);if(T)for(var n of T(r))pe.call(r,n)&&Z(e,n,r[n]);return e};var be=(e,r)=>{for(var n in r)L(e,n,{get:r[n],enumerable:!0})},ge=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of me(r))!X.call(e,s)&&s!==n&&L(e,s,{get:()=>r[s],enumerable:!(t=fe(r,s))||t.enumerable});return e};var de=e=>ge(L({},"__esModule",{value:!0}),e);var De={};be(De,{CLUSTER_PRIORITY:()=>Q,DEFAULT_PERSONA_VOCABULARY:()=>ie,EV_SHRINK_K:()=>te,LEGACY_PERSONA_MAP:()=>M,PERSONAS:()=>S,PERSONA_DISPLAY:()=>j,PERSONA_KEY_RE:()=>se,POOL_ALL:()=>g,RESERVED_PERSONA_KEYS:()=>ae,SHRINKAGE_M:()=>re,UNKNOWN_PERSONA:()=>y,applyClusterHeuristic:()=>O,broadestValueCell:()=>Se,candidateLayouts:()=>z,canonicalArm:()=>G,canonicalPersona:()=>N,chooseLayout:()=>ye,confidenceBand:()=>_e,decisionPersona:()=>Oe,fnv1a:()=>ne,hashLayout:()=>H,marginalArmKey:()=>Pe,normalizeDeclaredPersona:()=>Ee,parseArm:()=>F,pickDeterministicArm:()=>Ce,pooledPosterior:()=>Re,posteriorOfCounts:()=>_,resolvePersona:()=>Ne,sampleArm:()=>Y,sampleArmEv:()=>we,sampleBeta:()=>v,shrunkAvgValue:()=>oe,shrunkPosterior:()=>C,slotBaselineArm:()=>ee,slotResultFor:()=>ke,validateSlotDecl:()=>Ae,weightCellsFor:()=>ve});module.exports=de(De);var S=["buyer","researcher","deal_seeker","browser"],y="unknown",j={buyer:"Buyer",researcher:"Researcher",deal_seeker:"Deal seeker",browser:"Browser",unknown:"Unknown"},M={buyers:"buyer",researchers:"researcher","deal-seekers":"deal_seeker",browsers:"browser",buyer:"buyer",researcher:"researcher",deal_seeker:"deal_seeker",browser:"browser"};function N(e){var n;if(e==null)return y;let r=e.trim().toLowerCase();return(n=M[r])!=null?n:y}var xe=[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 d(e,r){return e>>>r|e<<32-r}function J(e){return(e>>>0).toString(16).padStart(8,"0")}function he(e){let r=new TextEncoder().encode(e),n=r.length,t=n*8,s=(n+8>>6)+1<<6,o=new Uint8Array(s);o.set(r),o[n]=128;let a=new DataView(o.buffer);a.setUint32(s-8,Math.floor(t/4294967296),!1),a.setUint32(s-4,t>>>0,!1);let i=1779033703,u=3144134277,f=1013904242,c=2773480762,b=1359893119,m=2600822924,P=528734635,A=1541459225,p=new Uint32Array(64);for(let K=0;K<s;K+=64){for(let l=0;l<16;l++)p[l]=a.getUint32(K+l*4,!1);for(let l=16;l<64;l++){let q=d(p[l-15],7)^d(p[l-15],18)^p[l-15]>>>3,I=d(p[l-2],17)^d(p[l-2],19)^p[l-2]>>>10;p[l]=p[l-16]+q+p[l-7]+I>>>0}let x=i,k=u,R=f,V=c,h=b,w=m,E=P,U=A;for(let l=0;l<64;l++){let q=d(h,6)^d(h,11)^d(h,25),I=h&w^~h&E,W=U+q+I+xe[l]+p[l]>>>0,ue=d(x,2)^d(x,13)^d(x,22),le=x&k^x&R^k&R,ce=ue+le>>>0;U=E,E=w,w=h,h=V+W>>>0,V=R,R=k,k=x,x=W+ce>>>0}i=i+x>>>0,u=u+k>>>0,f=f+R>>>0,c=c+V>>>0,b=b+h>>>0,m=m+w>>>0,P=P+E>>>0,A=A+U>>>0}return J(i)+J(u)}function H(e){return he(e.join("|"))}var Q={buyer:["pricing","cta","hero","comparison","social_proof","trust","features","faq","navigation","generic"],researcher:["features","comparison","faq","hero","trust","social_proof","pricing","cta","navigation","generic"],deal_seeker:["pricing","comparison","social_proof","trust","cta","hero","features","faq","navigation","generic"],browser:["hero","features","social_proof","pricing","cta","trust","faq","comparison","navigation","generic"]};function O(e,r,n){let t=Q[n];if(!t)return e;let s=t.indexOf("generic"),o=a=>{let i=t.indexOf(a);return i===-1?s:i};return[...e].sort((a,i)=>{var c,b;let u=(c=r.get(a))!=null?c:"generic",f=(b=r.get(i))!=null?b:"generic";return o(u)-o(f)})}function z(e,r,n){let t=new Map;for(let s of[...S,n]){let o=O(e,r,s);t.set(H(o),o)}return t}function B(e,r){if(e<1)return B(1+e,r)*Math.pow(Math.max(1e-15,r()),1/e);let n=e-1/3,t=1/Math.sqrt(9*n);for(;;){let s,o;do{let i=Math.max(1e-15,r()),u=r();s=Math.sqrt(-2*Math.log(i))*Math.cos(2*Math.PI*u),o=1+t*s}while(o<=0);o=o*o*o;let a=r();if(a<1-.0331*s*s*s*s||Math.log(a)<.5*s*s+n*(1-o+Math.log(o)))return n*o}}function v(e,r,n=Math.random){let t=B(e,n),s=B(r,n),o=t+s;return o<=0?e/(e+r):t/o}function Y(e,r=Math.random){if(e.length===0)return null;if(e.length===1)return e[0].arm;let n=e[0],t=v(n.alpha,n.beta,r);for(let s=1;s<e.length;s++){let o=e[s],a=v(o.alpha,o.beta,r);a>t&&(n=o,t=a)}return n.arm}function ye(e,r,n,t,s=Math.random){var f,c;let o=z(e,r,n),a=[];for(let b of o.keys()){let m=t.get(b);a.push({arm:b,alpha:(f=m==null?void 0:m.alpha)!=null?f:1,beta:(c=m==null?void 0:m.beta)!=null?c:1})}let i=Y(a,s),u=i?o.get(i):void 0;return u!=null?u:O(e,r,n)}function G(e){return Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("|")}function F(e){if(e.length===0)return null;let r={};for(let n of e.split("|")){let t=n.indexOf("=");if(t<=0||t!==n.lastIndexOf("=")||t===n.length-1)return null;let s=n.slice(0,t);if(s in r)return null;r[s]=n.slice(t+1)}return r}function Pe(e,r){return`${e}=${r}`}function ee(e){var n,t,s;if(e.arms)return typeof e.baseline=="string"?e.baseline:(n=e.arms[0])!=null?n:"";if(e.baseline!==void 0&&typeof e.baseline=="object")return G(e.baseline);if(typeof e.baseline=="string")return e.baseline;let r={};for(let[o,a]of Object.entries((t=e.dims)!=null?t:{}))r[o]=(s=a[0])!=null?s:"";return G(r)}function Ae(e){let r=Array.isArray(e.arms),n=e.dims!=null;if(r&&n)return{ok:!1,reason:"declare exactly one of arms or dims (got both)"};if(!r&&!n)return{ok:!1,reason:"declare exactly one of arms or dims (got neither)"};if(r){let o=e.arms;if(o.length<2)return{ok:!1,reason:"arms requires at least 2 entries"};if(o.length>12)return{ok:!1,reason:"arms allows at most 12 entries"};if(new Set(o).size!==o.length)return{ok:!1,reason:"arms must be unique"};if(o.some(a=>a.includes("=")))return{ok:!1,reason:"enumerated arm ids may not contain '=' (reserved for dims encoding)"};if(e.baseline!==void 0){if(typeof e.baseline!="string")return{ok:!1,reason:"baseline for an arms slot must be a string"};if(!o.includes(e.baseline))return{ok:!1,reason:"baseline must be one of the declared arms"}}return{ok:!0}}let t=Object.entries(e.dims);if(t.length<1)return{ok:!1,reason:"dims requires at least 1 dimension"};if(t.length>4)return{ok:!1,reason:"dims allows at most 4 dimensions"};let s=1;for(let[o,a]of t){if(a.length<2)return{ok:!1,reason:`dim "${o}" requires at least 2 values`};if(a.length>6)return{ok:!1,reason:`dim "${o}" allows at most 6 values`};if(new Set(a).size!==a.length)return{ok:!1,reason:`dim "${o}" has duplicate values`};s*=a.length}if(s>64)return{ok:!1,reason:`declared space of ${s} combinations exceeds the 64 maximum`};if(e.baseline!==void 0){if(typeof e.baseline=="string")return{ok:!1,reason:"baseline for a dims slot must be a per-dim record"};let o=e.baseline,a=t.map(([u])=>u).sort(),i=Object.keys(o).sort();if(a.join(" ")!==i.join(" "))return{ok:!1,reason:"baseline must set every declared dim exactly once"};for(let[u,f]of t)if(!f.includes(o[u]))return{ok:!1,reason:`baseline value for dim "${u}" is not declared`}}return{ok:!0}}function ke(e,r){var n,t;return e.dims!=null?(t=(n=F(r))!=null?n:F(ee(e)))!=null?t:{}:r}var re=20;function C(e,r,n=20){let t=r.alpha+r.beta;if(t<=0||n<=0)return{alpha:e.alpha,beta:e.beta};let s=r.alpha/t,o=n*t/(t+n);return{alpha:e.alpha+o*s,beta:e.beta+o*(1-s)}}var g="__all__",D={exposures:0,conversions:0};function _(e){return{alpha:e.conversions+1,beta:Math.max(0,e.exposures-e.conversions)+1}}function Re(e,r,n=20){var m,P,A,p;let t=(m=e.segment)!=null?m:D,s=(P=e.global)!=null?P:D,o=_(s),a=C(_(t),o,n);if(!r)return a;let i=(A=e.persona)!=null?A:D,u=(p=e.child)!=null?p:D,f=C(_(i),o,n),c=(t.exposures+1)/(t.exposures+i.exposures+2),b={alpha:c*a.alpha+(1-c)*f.alpha,beta:c*a.beta+(1-c)*f.beta};return C(_(u),b,n)}function Se(e){var t,s;let r=null,n=-1;for(let o of e){let a=o.segment===g,i=o.persona===g,u=a&&i?3:a||i?2:1;u>n&&(n=u,r=o)}return{valueSum:(t=r==null?void 0:r.valueSum)!=null?t:0,valueCount:(s=r==null?void 0:r.valueCount)!=null?s:0}}function ve(e,r){return r==="unknown"||r===g||r===""?[{segment:e,persona:g},{segment:g,persona:g}]:[{segment:e,persona:r},{segment:e,persona:g},{segment:g,persona:r},{segment:g,persona:g}]}function ne(e){let r=2166136261;for(let n=0;n<e.length;n++)r^=e.charCodeAt(n),r=r+((r<<1)+(r<<4)+(r<<7)+(r<<8)+(r<<24))>>>0;return r}function Ce(e,r,n){if(n.length===0)throw new Error("pickDeterministicArm requires at least one arm");let t=[...n].sort();return t[ne(`${e}:${r}`)%t.length]}function _e(e){return e>=.3?e<.7?"medium":"high":"low"}var te=20;function oe(e,r,n=te){let t=e.valueCount>0?e.valueSum/e.valueCount:0;if(r<=0)return t;if(e.valueCount<=0)return r;let s=e.valueCount/(e.valueCount+n);return s*t+(1-s)*r}function we(e,r,n=Math.random){if(e.length===0)return null;if(e.length===1)return e[0].arm;let t=null,s=-1/0;for(let o of e){let a=v(o.alpha,o.beta,n)*oe(o,r);a>s&&(t=o,s=a)}return t.arm}var se=/^[a-z0-9][a-z0-9_-]{0,31}$/;function Ee(e){if(typeof e!="string")return null;let r=e.trim().toLowerCase();return r&&se.test(r)?r:null}var ae=["unknown","__all__","buyers","researchers","deal-seekers","browsers"],ie=S.map(e=>({key:e,displayName:j[e]})),Le=64;function Me(e){var n;let r=new Map;for(let t of e)if(t.status!=="retired"){r.set(t.key,t.key);for(let s of(n=t.aliases)!=null?n:[])ae.includes(s)||r.set(s,t.key)}return r}function Ne(e,r=ie){var i,u,f;let n=Me(r),t=(i=e.inferredConfidence)!=null?i:0,s,o=(f=(u=e.declared)==null?void 0:u.trim().toLowerCase())!=null?f:"";if(o!==""){let c=n.get(o),b=c===void 0?n.get(N(o)):void 0,m=c!=null?c:b;if(m!==void 0)return{persona:m,source:"declared",confidence:1};s=o.slice(0,Le)}let a=N(e.clusterLabel);return a!==y&&n.has(a)?$({persona:n.get(a),source:"inferred",confidence:t},s!==void 0&&{unrecognizedDeclared:s}):$({persona:y,source:"none",confidence:t},s!==void 0&&{unrecognizedDeclared:s})}function Oe(e){var n;if(e==null)return y;let r=e.trim().toLowerCase();return r===""?y:(n=M[r])!=null?n:r}0&&(module.exports={CLUSTER_PRIORITY,DEFAULT_PERSONA_VOCABULARY,EV_SHRINK_K,LEGACY_PERSONA_MAP,PERSONAS,PERSONA_DISPLAY,PERSONA_KEY_RE,POOL_ALL,RESERVED_PERSONA_KEYS,SHRINKAGE_M,UNKNOWN_PERSONA,applyClusterHeuristic,broadestValueCell,candidateLayouts,canonicalArm,canonicalPersona,chooseLayout,confidenceBand,decisionPersona,fnv1a,hashLayout,marginalArmKey,normalizeDeclaredPersona,parseArm,pickDeterministicArm,pooledPosterior,posteriorOfCounts,resolvePersona,sampleArm,sampleArmEv,sampleBeta,shrunkAvgValue,shrunkPosterior,slotBaselineArm,slotResultFor,validateSlotDecl,weightCellsFor});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var re=Object.defineProperty;var H=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable;var z=(e,r,n)=>r in e?re(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n,V=(e,r)=>{for(var n in r||(r={}))ne.call(r,n)&&z(e,n,r[n]);if(H)for(var n of H(r))te.call(r,n)&&z(e,n,r[n]);return e};var _=["buyer","researcher","deal_seeker","browser"],y="unknown",B={buyer:"Buyer",researcher:"Researcher",deal_seeker:"Deal seeker",browser:"Browser",unknown:"Unknown"},U={buyers:"buyer",researchers:"researcher","deal-seekers":"deal_seeker",browsers:"browser",buyer:"buyer",researcher:"researcher",deal_seeker:"deal_seeker",browser:"browser"};function q(e){var n;if(e==null)return y;let r=e.trim().toLowerCase();return(n=U[r])!=null?n:y}var oe=[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 g(e,r){return e>>>r|e<<32-r}function Y(e){return(e>>>0).toString(16).padStart(8,"0")}function se(e){let r=new TextEncoder().encode(e),n=r.length,t=n*8,s=(n+8>>6)+1<<6,o=new Uint8Array(s);o.set(r),o[n]=128;let a=new DataView(o.buffer);a.setUint32(s-8,Math.floor(t/4294967296),!1),a.setUint32(s-4,t>>>0,!1);let i=1779033703,u=3144134277,f=1013904242,c=2773480762,p=1359893119,m=2600822924,P=528734635,A=1541459225,b=new Uint32Array(64);for(let M=0;M<s;M+=64){for(let l=0;l<16;l++)b[l]=a.getUint32(M+l*4,!1);for(let l=16;l<64;l++){let D=g(b[l-15],7)^g(b[l-15],18)^b[l-15]>>>3,K=g(b[l-2],17)^g(b[l-2],19)^b[l-2]>>>10;b[l]=b[l-16]+D+b[l-7]+K>>>0}let x=i,k=u,R=f,N=c,h=p,S=m,v=P,O=A;for(let l=0;l<64;l++){let D=g(h,6)^g(h,11)^g(h,25),K=h&S^~h&v,j=O+D+K+oe[l]+b[l]>>>0,J=g(x,2)^g(x,13)^g(x,22),Q=x&k^x&R^k&R,ee=J+Q>>>0;O=v,v=S,S=h,h=N+j>>>0,N=R,R=k,k=x,x=j+ee>>>0}i=i+x>>>0,u=u+k>>>0,f=f+R>>>0,c=c+N>>>0,p=p+h>>>0,m=m+S>>>0,P=P+v>>>0,A=A+O>>>0}return Y(i)+Y(u)}function G(e){return se(e.join("|"))}var ae={buyer:["pricing","cta","hero","comparison","social_proof","trust","features","faq","navigation","generic"],researcher:["features","comparison","faq","hero","trust","social_proof","pricing","cta","navigation","generic"],deal_seeker:["pricing","comparison","social_proof","trust","cta","hero","features","faq","navigation","generic"],browser:["hero","features","social_proof","pricing","cta","trust","faq","comparison","navigation","generic"]};function I(e,r,n){let t=ae[n];if(!t)return e;let s=t.indexOf("generic"),o=a=>{let i=t.indexOf(a);return i===-1?s:i};return[...e].sort((a,i)=>{var c,p;let u=(c=r.get(a))!=null?c:"generic",f=(p=r.get(i))!=null?p:"generic";return o(u)-o(f)})}function F(e,r,n){let t=new Map;for(let s of[..._,n]){let o=I(e,r,s);t.set(G(o),o)}return t}function $(e,r){if(e<1)return $(1+e,r)*Math.pow(Math.max(1e-15,r()),1/e);let n=e-1/3,t=1/Math.sqrt(9*n);for(;;){let s,o;do{let i=Math.max(1e-15,r()),u=r();s=Math.sqrt(-2*Math.log(i))*Math.cos(2*Math.PI*u),o=1+t*s}while(o<=0);o=o*o*o;let a=r();if(a<1-.0331*s*s*s*s||Math.log(a)<.5*s*s+n*(1-o+Math.log(o)))return n*o}}function C(e,r,n=Math.random){let t=$(e,n),s=$(r,n),o=t+s;return o<=0?e/(e+r):t/o}function W(e,r=Math.random){if(e.length===0)return null;if(e.length===1)return e[0].arm;let n=e[0],t=C(n.alpha,n.beta,r);for(let s=1;s<e.length;s++){let o=e[s],a=C(o.alpha,o.beta,r);a>t&&(n=o,t=a)}return n.arm}function Se(e,r,n,t,s=Math.random){var f,c;let o=F(e,r,n),a=[];for(let p of o.keys()){let m=t.get(p);a.push({arm:p,alpha:(f=m==null?void 0:m.alpha)!=null?f:1,beta:(c=m==null?void 0:m.beta)!=null?c:1})}let i=W(a,s),u=i?o.get(i):void 0;return u!=null?u:I(e,r,n)}function T(e){return Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("|")}function Z(e){if(e.length===0)return null;let r={};for(let n of e.split("|")){let t=n.indexOf("=");if(t<=0||t!==n.lastIndexOf("=")||t===n.length-1)return null;let s=n.slice(0,t);if(s in r)return null;r[s]=n.slice(t+1)}return r}function _e(e,r){return`${e}=${r}`}function ie(e){var n,t,s;if(e.arms)return typeof e.baseline=="string"?e.baseline:(n=e.arms[0])!=null?n:"";if(e.baseline!==void 0&&typeof e.baseline=="object")return T(e.baseline);if(typeof e.baseline=="string")return e.baseline;let r={};for(let[o,a]of Object.entries((t=e.dims)!=null?t:{}))r[o]=(s=a[0])!=null?s:"";return T(r)}function Ce(e){let r=Array.isArray(e.arms),n=e.dims!=null;if(r&&n)return{ok:!1,reason:"declare exactly one of arms or dims (got both)"};if(!r&&!n)return{ok:!1,reason:"declare exactly one of arms or dims (got neither)"};if(r){let o=e.arms;if(o.length<2)return{ok:!1,reason:"arms requires at least 2 entries"};if(o.length>12)return{ok:!1,reason:"arms allows at most 12 entries"};if(new Set(o).size!==o.length)return{ok:!1,reason:"arms must be unique"};if(o.some(a=>a.includes("=")))return{ok:!1,reason:"enumerated arm ids may not contain '=' (reserved for dims encoding)"};if(e.baseline!==void 0){if(typeof e.baseline!="string")return{ok:!1,reason:"baseline for an arms slot must be a string"};if(!o.includes(e.baseline))return{ok:!1,reason:"baseline must be one of the declared arms"}}return{ok:!0}}let t=Object.entries(e.dims);if(t.length<1)return{ok:!1,reason:"dims requires at least 1 dimension"};if(t.length>4)return{ok:!1,reason:"dims allows at most 4 dimensions"};let s=1;for(let[o,a]of t){if(a.length<2)return{ok:!1,reason:`dim "${o}" requires at least 2 values`};if(a.length>6)return{ok:!1,reason:`dim "${o}" allows at most 6 values`};if(new Set(a).size!==a.length)return{ok:!1,reason:`dim "${o}" has duplicate values`};s*=a.length}if(s>64)return{ok:!1,reason:`declared space of ${s} combinations exceeds the 64 maximum`};if(e.baseline!==void 0){if(typeof e.baseline=="string")return{ok:!1,reason:"baseline for a dims slot must be a per-dim record"};let o=e.baseline,a=t.map(([u])=>u).sort(),i=Object.keys(o).sort();if(a.join(" ")!==i.join(" "))return{ok:!1,reason:"baseline must set every declared dim exactly once"};for(let[u,f]of t)if(!f.includes(o[u]))return{ok:!1,reason:`baseline value for dim "${u}" is not declared`}}return{ok:!0}}function we(e,r){var n,t;return e.dims!=null?(t=(n=Z(r))!=null?n:Z(ie(e)))!=null?t:{}:r}var X=20;function w(e,r,n=20){let t=r.alpha+r.beta;if(t<=0||n<=0)return{alpha:e.alpha,beta:e.beta};let s=r.alpha/t,o=n*t/(t+n);return{alpha:e.alpha+o*s,beta:e.beta+o*(1-s)}}var d="__all__",E={exposures:0,conversions:0};function L(e){return{alpha:e.conversions+1,beta:Math.max(0,e.exposures-e.conversions)+1}}function Ne(e,r,n=20){var m,P,A,b;let t=(m=e.segment)!=null?m:E,s=(P=e.global)!=null?P:E,o=L(s),a=w(L(t),o,n);if(!r)return a;let i=(A=e.persona)!=null?A:E,u=(b=e.child)!=null?b:E,f=w(L(i),o,n),c=(t.exposures+1)/(t.exposures+i.exposures+2),p={alpha:c*a.alpha+(1-c)*f.alpha,beta:c*a.beta+(1-c)*f.beta};return w(L(u),p,n)}function Oe(e){var t,s;let r=null,n=-1;for(let o of e){let a=o.segment===d,i=o.persona===d,u=a&&i?3:a||i?2:1;u>n&&(n=u,r=o)}return{valueSum:(t=r==null?void 0:r.valueSum)!=null?t:0,valueCount:(s=r==null?void 0:r.valueCount)!=null?s:0}}function De(e,r){return r==="unknown"||r===d||r===""?[{segment:e,persona:d},{segment:d,persona:d}]:[{segment:e,persona:r},{segment:e,persona:d},{segment:d,persona:r},{segment:d,persona:d}]}function ue(e){let r=2166136261;for(let n=0;n<e.length;n++)r^=e.charCodeAt(n),r=r+((r<<1)+(r<<4)+(r<<7)+(r<<8)+(r<<24))>>>0;return r}function Ve(e,r,n){if(n.length===0)throw new Error("pickDeterministicArm requires at least one arm");let t=[...n].sort();return t[ue(`${e}:${r}`)%t.length]}function Ue(e){return e>=.3?e<.7?"medium":"high":"low"}var le=20;function ce(e,r,n=le){let t=e.valueCount>0?e.valueSum/e.valueCount:0;if(r<=0)return t;if(e.valueCount<=0)return r;let s=e.valueCount/(e.valueCount+n);return s*t+(1-s)*r}function $e(e,r,n=Math.random){if(e.length===0)return null;if(e.length===1)return e[0].arm;let t=null,s=-1/0;for(let o of e){let a=C(o.alpha,o.beta,n)*ce(o,r);a>s&&(t=o,s=a)}return t.arm}var ze=/^[a-z0-9][a-z0-9_-]{0,31}$/,fe=["unknown","__all__","buyers","researchers","deal-seekers","browsers"],me=_.map(e=>({key:e,displayName:B[e]})),be=64;function pe(e){var n;let r=new Map;for(let t of e)if(t.status!=="retired"){r.set(t.key,t.key);for(let s of(n=t.aliases)!=null?n:[])fe.includes(s)||r.set(s,t.key)}return r}function Be(e,r=me){var i,u,f;let n=pe(r),t=(i=e.inferredConfidence)!=null?i:0,s,o=(f=(u=e.declared)==null?void 0:u.trim().toLowerCase())!=null?f:"";if(o!==""){let c=n.get(o),p=c===void 0?n.get(q(o)):void 0,m=c!=null?c:p;if(m!==void 0)return{persona:m,source:"declared",confidence:1};s=o.slice(0,be)}let a=q(e.clusterLabel);return a!==y&&n.has(a)?V({persona:n.get(a),source:"inferred",confidence:t},s!==void 0&&{unrecognizedDeclared:s}):V({persona:y,source:"none",confidence:t},s!==void 0&&{unrecognizedDeclared:s})}function Ye(e){var n;if(e==null)return y;let r=e.trim().toLowerCase();return r===""?y:(n=U[r])!=null?n:r}export{ae as CLUSTER_PRIORITY,me as DEFAULT_PERSONA_VOCABULARY,le as EV_SHRINK_K,U as LEGACY_PERSONA_MAP,_ as PERSONAS,B as PERSONA_DISPLAY,ze as PERSONA_KEY_RE,d as POOL_ALL,fe as RESERVED_PERSONA_KEYS,X as SHRINKAGE_M,y as UNKNOWN_PERSONA,I as applyClusterHeuristic,Oe as broadestValueCell,F as candidateLayouts,T as canonicalArm,q as canonicalPersona,Se as chooseLayout,Ue as confidenceBand,Ye as decisionPersona,ue as fnv1a,G as hashLayout,_e as marginalArmKey,Z as parseArm,Ve as pickDeterministicArm,Ne as pooledPosterior,L as posteriorOfCounts,Be as resolvePersona,W as sampleArm,$e as sampleArmEv,C as sampleBeta,ce as shrunkAvgValue,w as shrunkPosterior,ie as slotBaselineArm,we as slotResultFor,Ce as validateSlotDecl,De as weightCellsFor};
|
|
1
|
+
var re=Object.defineProperty;var H=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable;var z=(e,r,n)=>r in e?re(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n,V=(e,r)=>{for(var n in r||(r={}))ne.call(r,n)&&z(e,n,r[n]);if(H)for(var n of H(r))te.call(r,n)&&z(e,n,r[n]);return e};var C=["buyer","researcher","deal_seeker","browser"],y="unknown",B={buyer:"Buyer",researcher:"Researcher",deal_seeker:"Deal seeker",browser:"Browser",unknown:"Unknown"},U={buyers:"buyer",researchers:"researcher","deal-seekers":"deal_seeker",browsers:"browser",buyer:"buyer",researcher:"researcher",deal_seeker:"deal_seeker",browser:"browser"};function q(e){var n;if(e==null)return y;let r=e.trim().toLowerCase();return(n=U[r])!=null?n:y}var oe=[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 g(e,r){return e>>>r|e<<32-r}function Y(e){return(e>>>0).toString(16).padStart(8,"0")}function se(e){let r=new TextEncoder().encode(e),n=r.length,t=n*8,s=(n+8>>6)+1<<6,o=new Uint8Array(s);o.set(r),o[n]=128;let a=new DataView(o.buffer);a.setUint32(s-8,Math.floor(t/4294967296),!1),a.setUint32(s-4,t>>>0,!1);let i=1779033703,u=3144134277,f=1013904242,c=2773480762,b=1359893119,m=2600822924,P=528734635,A=1541459225,p=new Uint32Array(64);for(let M=0;M<s;M+=64){for(let l=0;l<16;l++)p[l]=a.getUint32(M+l*4,!1);for(let l=16;l<64;l++){let D=g(p[l-15],7)^g(p[l-15],18)^p[l-15]>>>3,K=g(p[l-2],17)^g(p[l-2],19)^p[l-2]>>>10;p[l]=p[l-16]+D+p[l-7]+K>>>0}let x=i,k=u,R=f,N=c,h=b,S=m,v=P,O=A;for(let l=0;l<64;l++){let D=g(h,6)^g(h,11)^g(h,25),K=h&S^~h&v,j=O+D+K+oe[l]+p[l]>>>0,J=g(x,2)^g(x,13)^g(x,22),Q=x&k^x&R^k&R,ee=J+Q>>>0;O=v,v=S,S=h,h=N+j>>>0,N=R,R=k,k=x,x=j+ee>>>0}i=i+x>>>0,u=u+k>>>0,f=f+R>>>0,c=c+N>>>0,b=b+h>>>0,m=m+S>>>0,P=P+v>>>0,A=A+O>>>0}return Y(i)+Y(u)}function G(e){return se(e.join("|"))}var ae={buyer:["pricing","cta","hero","comparison","social_proof","trust","features","faq","navigation","generic"],researcher:["features","comparison","faq","hero","trust","social_proof","pricing","cta","navigation","generic"],deal_seeker:["pricing","comparison","social_proof","trust","cta","hero","features","faq","navigation","generic"],browser:["hero","features","social_proof","pricing","cta","trust","faq","comparison","navigation","generic"]};function I(e,r,n){let t=ae[n];if(!t)return e;let s=t.indexOf("generic"),o=a=>{let i=t.indexOf(a);return i===-1?s:i};return[...e].sort((a,i)=>{var c,b;let u=(c=r.get(a))!=null?c:"generic",f=(b=r.get(i))!=null?b:"generic";return o(u)-o(f)})}function F(e,r,n){let t=new Map;for(let s of[...C,n]){let o=I(e,r,s);t.set(G(o),o)}return t}function $(e,r){if(e<1)return $(1+e,r)*Math.pow(Math.max(1e-15,r()),1/e);let n=e-1/3,t=1/Math.sqrt(9*n);for(;;){let s,o;do{let i=Math.max(1e-15,r()),u=r();s=Math.sqrt(-2*Math.log(i))*Math.cos(2*Math.PI*u),o=1+t*s}while(o<=0);o=o*o*o;let a=r();if(a<1-.0331*s*s*s*s||Math.log(a)<.5*s*s+n*(1-o+Math.log(o)))return n*o}}function _(e,r,n=Math.random){let t=$(e,n),s=$(r,n),o=t+s;return o<=0?e/(e+r):t/o}function W(e,r=Math.random){if(e.length===0)return null;if(e.length===1)return e[0].arm;let n=e[0],t=_(n.alpha,n.beta,r);for(let s=1;s<e.length;s++){let o=e[s],a=_(o.alpha,o.beta,r);a>t&&(n=o,t=a)}return n.arm}function ve(e,r,n,t,s=Math.random){var f,c;let o=F(e,r,n),a=[];for(let b of o.keys()){let m=t.get(b);a.push({arm:b,alpha:(f=m==null?void 0:m.alpha)!=null?f:1,beta:(c=m==null?void 0:m.beta)!=null?c:1})}let i=W(a,s),u=i?o.get(i):void 0;return u!=null?u:I(e,r,n)}function T(e){return Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("|")}function Z(e){if(e.length===0)return null;let r={};for(let n of e.split("|")){let t=n.indexOf("=");if(t<=0||t!==n.lastIndexOf("=")||t===n.length-1)return null;let s=n.slice(0,t);if(s in r)return null;r[s]=n.slice(t+1)}return r}function _e(e,r){return`${e}=${r}`}function ie(e){var n,t,s;if(e.arms)return typeof e.baseline=="string"?e.baseline:(n=e.arms[0])!=null?n:"";if(e.baseline!==void 0&&typeof e.baseline=="object")return T(e.baseline);if(typeof e.baseline=="string")return e.baseline;let r={};for(let[o,a]of Object.entries((t=e.dims)!=null?t:{}))r[o]=(s=a[0])!=null?s:"";return T(r)}function we(e){let r=Array.isArray(e.arms),n=e.dims!=null;if(r&&n)return{ok:!1,reason:"declare exactly one of arms or dims (got both)"};if(!r&&!n)return{ok:!1,reason:"declare exactly one of arms or dims (got neither)"};if(r){let o=e.arms;if(o.length<2)return{ok:!1,reason:"arms requires at least 2 entries"};if(o.length>12)return{ok:!1,reason:"arms allows at most 12 entries"};if(new Set(o).size!==o.length)return{ok:!1,reason:"arms must be unique"};if(o.some(a=>a.includes("=")))return{ok:!1,reason:"enumerated arm ids may not contain '=' (reserved for dims encoding)"};if(e.baseline!==void 0){if(typeof e.baseline!="string")return{ok:!1,reason:"baseline for an arms slot must be a string"};if(!o.includes(e.baseline))return{ok:!1,reason:"baseline must be one of the declared arms"}}return{ok:!0}}let t=Object.entries(e.dims);if(t.length<1)return{ok:!1,reason:"dims requires at least 1 dimension"};if(t.length>4)return{ok:!1,reason:"dims allows at most 4 dimensions"};let s=1;for(let[o,a]of t){if(a.length<2)return{ok:!1,reason:`dim "${o}" requires at least 2 values`};if(a.length>6)return{ok:!1,reason:`dim "${o}" allows at most 6 values`};if(new Set(a).size!==a.length)return{ok:!1,reason:`dim "${o}" has duplicate values`};s*=a.length}if(s>64)return{ok:!1,reason:`declared space of ${s} combinations exceeds the 64 maximum`};if(e.baseline!==void 0){if(typeof e.baseline=="string")return{ok:!1,reason:"baseline for a dims slot must be a per-dim record"};let o=e.baseline,a=t.map(([u])=>u).sort(),i=Object.keys(o).sort();if(a.join(" ")!==i.join(" "))return{ok:!1,reason:"baseline must set every declared dim exactly once"};for(let[u,f]of t)if(!f.includes(o[u]))return{ok:!1,reason:`baseline value for dim "${u}" is not declared`}}return{ok:!0}}function Ee(e,r){var n,t;return e.dims!=null?(t=(n=Z(r))!=null?n:Z(ie(e)))!=null?t:{}:r}var X=20;function w(e,r,n=20){let t=r.alpha+r.beta;if(t<=0||n<=0)return{alpha:e.alpha,beta:e.beta};let s=r.alpha/t,o=n*t/(t+n);return{alpha:e.alpha+o*s,beta:e.beta+o*(1-s)}}var d="__all__",E={exposures:0,conversions:0};function L(e){return{alpha:e.conversions+1,beta:Math.max(0,e.exposures-e.conversions)+1}}function Oe(e,r,n=20){var m,P,A,p;let t=(m=e.segment)!=null?m:E,s=(P=e.global)!=null?P:E,o=L(s),a=w(L(t),o,n);if(!r)return a;let i=(A=e.persona)!=null?A:E,u=(p=e.child)!=null?p:E,f=w(L(i),o,n),c=(t.exposures+1)/(t.exposures+i.exposures+2),b={alpha:c*a.alpha+(1-c)*f.alpha,beta:c*a.beta+(1-c)*f.beta};return w(L(u),b,n)}function De(e){var t,s;let r=null,n=-1;for(let o of e){let a=o.segment===d,i=o.persona===d,u=a&&i?3:a||i?2:1;u>n&&(n=u,r=o)}return{valueSum:(t=r==null?void 0:r.valueSum)!=null?t:0,valueCount:(s=r==null?void 0:r.valueCount)!=null?s:0}}function Ke(e,r){return r==="unknown"||r===d||r===""?[{segment:e,persona:d},{segment:d,persona:d}]:[{segment:e,persona:r},{segment:e,persona:d},{segment:d,persona:r},{segment:d,persona:d}]}function ue(e){let r=2166136261;for(let n=0;n<e.length;n++)r^=e.charCodeAt(n),r=r+((r<<1)+(r<<4)+(r<<7)+(r<<8)+(r<<24))>>>0;return r}function Ue(e,r,n){if(n.length===0)throw new Error("pickDeterministicArm requires at least one arm");let t=[...n].sort();return t[ue(`${e}:${r}`)%t.length]}function qe(e){return e>=.3?e<.7?"medium":"high":"low"}var le=20;function ce(e,r,n=le){let t=e.valueCount>0?e.valueSum/e.valueCount:0;if(r<=0)return t;if(e.valueCount<=0)return r;let s=e.valueCount/(e.valueCount+n);return s*t+(1-s)*r}function je(e,r,n=Math.random){if(e.length===0)return null;if(e.length===1)return e[0].arm;let t=null,s=-1/0;for(let o of e){let a=_(o.alpha,o.beta,n)*ce(o,r);a>s&&(t=o,s=a)}return t.arm}var fe=/^[a-z0-9][a-z0-9_-]{0,31}$/;function Be(e){if(typeof e!="string")return null;let r=e.trim().toLowerCase();return r&&fe.test(r)?r:null}var me=["unknown","__all__","buyers","researchers","deal-seekers","browsers"],pe=C.map(e=>({key:e,displayName:B[e]})),be=64;function ge(e){var n;let r=new Map;for(let t of e)if(t.status!=="retired"){r.set(t.key,t.key);for(let s of(n=t.aliases)!=null?n:[])me.includes(s)||r.set(s,t.key)}return r}function Ye(e,r=pe){var i,u,f;let n=ge(r),t=(i=e.inferredConfidence)!=null?i:0,s,o=(f=(u=e.declared)==null?void 0:u.trim().toLowerCase())!=null?f:"";if(o!==""){let c=n.get(o),b=c===void 0?n.get(q(o)):void 0,m=c!=null?c:b;if(m!==void 0)return{persona:m,source:"declared",confidence:1};s=o.slice(0,be)}let a=q(e.clusterLabel);return a!==y&&n.has(a)?V({persona:n.get(a),source:"inferred",confidence:t},s!==void 0&&{unrecognizedDeclared:s}):V({persona:y,source:"none",confidence:t},s!==void 0&&{unrecognizedDeclared:s})}function Ge(e){var n;if(e==null)return y;let r=e.trim().toLowerCase();return r===""?y:(n=U[r])!=null?n:r}export{ae as CLUSTER_PRIORITY,pe as DEFAULT_PERSONA_VOCABULARY,le as EV_SHRINK_K,U as LEGACY_PERSONA_MAP,C as PERSONAS,B as PERSONA_DISPLAY,fe as PERSONA_KEY_RE,d as POOL_ALL,me as RESERVED_PERSONA_KEYS,X as SHRINKAGE_M,y as UNKNOWN_PERSONA,I as applyClusterHeuristic,De as broadestValueCell,F as candidateLayouts,T as canonicalArm,q as canonicalPersona,ve as chooseLayout,qe as confidenceBand,Ge as decisionPersona,ue as fnv1a,G as hashLayout,_e as marginalArmKey,Be as normalizeDeclaredPersona,Z as parseArm,Ue as pickDeterministicArm,Oe as pooledPosterior,L as posteriorOfCounts,Ye as resolvePersona,W as sampleArm,je as sampleArmEv,_ as sampleBeta,ce as shrunkAvgValue,w as shrunkPosterior,ie as slotBaselineArm,Ee as slotResultFor,we as validateSlotDecl,Ke as weightCellsFor};
|