@sentientui/policy 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.cts +52 -1
- package/dist/index.d.ts +52 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -142,6 +142,57 @@ declare function shrunkPosterior(persona: {
|
|
|
142
142
|
beta: number;
|
|
143
143
|
};
|
|
144
144
|
|
|
145
|
+
/** Sentinel segment/persona value for marginal and global weight rows. */
|
|
146
|
+
declare const POOL_ALL = "__all__";
|
|
147
|
+
type PoolCounts = {
|
|
148
|
+
exposures: number;
|
|
149
|
+
conversions: number;
|
|
150
|
+
};
|
|
151
|
+
type PoolCells = {
|
|
152
|
+
/** (segment, persona) — the specific serving context */
|
|
153
|
+
child?: PoolCounts;
|
|
154
|
+
/** (segment, '__all__') — persona-agnostic marginal (legacy variant rows) */
|
|
155
|
+
segment?: PoolCounts;
|
|
156
|
+
/** ('__all__', persona) — segment-agnostic marginal (legacy slot rows) */
|
|
157
|
+
persona?: PoolCounts;
|
|
158
|
+
/** ('__all__', '__all__') — global */
|
|
159
|
+
global?: PoolCounts;
|
|
160
|
+
};
|
|
161
|
+
/** Pinned formulas: alpha = conversions + 1; beta = max(0, exposures − conversions) + 1. */
|
|
162
|
+
declare function posteriorOfCounts(c: PoolCounts): {
|
|
163
|
+
alpha: number;
|
|
164
|
+
beta: number;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Hierarchical partial pooling over (segment, persona), built by nesting the
|
|
168
|
+
* pinned one-axis shrinkage (shrunkPosterior, m = SHRINKAGE_M):
|
|
169
|
+
*
|
|
170
|
+
* segLevel = shrink(segment ← global)
|
|
171
|
+
* perLevel = shrink(persona ← global) (persona axis, when known)
|
|
172
|
+
* parent = evidence-weighted blend of segLevel and perLevel
|
|
173
|
+
* final = shrink(child ← parent)
|
|
174
|
+
*
|
|
175
|
+
* personaKnown=false consults ONLY segment+global — this is the invariant that
|
|
176
|
+
* keeps unknown-persona traffic on exactly the segment-marginal policy.
|
|
177
|
+
* Every cell is optional; an absent cell contributes Beta(1,1)-with-0-evidence,
|
|
178
|
+
* which is what lets the same function reproduce the legacy variant (segment-only)
|
|
179
|
+
* and legacy slot (persona-only) behaviors on day one after migration.
|
|
180
|
+
*/
|
|
181
|
+
declare function pooledPosterior(cells: PoolCells, personaKnown: boolean, m?: number): {
|
|
182
|
+
alpha: number;
|
|
183
|
+
beta: number;
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Write-side cell expansion: which weight rows one trial/credit must bump.
|
|
187
|
+
* Unknown persona bumps ONLY the segment marginal + global — no 'unknown'
|
|
188
|
+
* child or persona-marginal rows exist (unknown traffic serves the segment
|
|
189
|
+
* marginal, so that is where its evidence must live).
|
|
190
|
+
*/
|
|
191
|
+
declare function weightCellsFor(segment: string, persona: string): Array<{
|
|
192
|
+
segment: string;
|
|
193
|
+
persona: string;
|
|
194
|
+
}>;
|
|
195
|
+
|
|
145
196
|
/**
|
|
146
197
|
* FNV-1a 32-bit hash. Same algorithm (offset basis, prime-by-shifts, >>> 0)
|
|
147
198
|
* as the private hashUnit in apps/api/src/domain/holdout.ts — parity is
|
|
@@ -163,4 +214,4 @@ declare function pickDeterministicArm(sessionId: string, slotId: string, arms: s
|
|
|
163
214
|
*/
|
|
164
215
|
declare function confidenceBand(c: number): 'low' | 'medium' | 'high';
|
|
165
216
|
|
|
166
|
-
export { type ArmPosterior, CLUSTER_PRIORITY, LEGACY_PERSONA_MAP, type LearnedLayout, PERSONAS, PERSONA_DISPLAY, type Persona, type PersonaKey, SHRINKAGE_M, type SlotDecl, type SlotResult, UNKNOWN_PERSONA, applyClusterHeuristic, candidateLayouts, canonicalArm, canonicalPersona, chooseLayout, confidenceBand, fnv1a, hashLayout, marginalArmKey, parseArm, pickDeterministicArm, sampleArm, sampleBeta, shrunkPosterior, slotBaselineArm, slotResultFor, validateSlotDecl };
|
|
217
|
+
export { type ArmPosterior, CLUSTER_PRIORITY, LEGACY_PERSONA_MAP, type LearnedLayout, PERSONAS, PERSONA_DISPLAY, POOL_ALL, type Persona, type PersonaKey, type PoolCells, type PoolCounts, SHRINKAGE_M, type SlotDecl, type SlotResult, UNKNOWN_PERSONA, applyClusterHeuristic, candidateLayouts, canonicalArm, canonicalPersona, chooseLayout, confidenceBand, fnv1a, hashLayout, marginalArmKey, parseArm, pickDeterministicArm, pooledPosterior, posteriorOfCounts, sampleArm, sampleBeta, shrunkPosterior, slotBaselineArm, slotResultFor, validateSlotDecl, weightCellsFor };
|
package/dist/index.d.ts
CHANGED
|
@@ -142,6 +142,57 @@ declare function shrunkPosterior(persona: {
|
|
|
142
142
|
beta: number;
|
|
143
143
|
};
|
|
144
144
|
|
|
145
|
+
/** Sentinel segment/persona value for marginal and global weight rows. */
|
|
146
|
+
declare const POOL_ALL = "__all__";
|
|
147
|
+
type PoolCounts = {
|
|
148
|
+
exposures: number;
|
|
149
|
+
conversions: number;
|
|
150
|
+
};
|
|
151
|
+
type PoolCells = {
|
|
152
|
+
/** (segment, persona) — the specific serving context */
|
|
153
|
+
child?: PoolCounts;
|
|
154
|
+
/** (segment, '__all__') — persona-agnostic marginal (legacy variant rows) */
|
|
155
|
+
segment?: PoolCounts;
|
|
156
|
+
/** ('__all__', persona) — segment-agnostic marginal (legacy slot rows) */
|
|
157
|
+
persona?: PoolCounts;
|
|
158
|
+
/** ('__all__', '__all__') — global */
|
|
159
|
+
global?: PoolCounts;
|
|
160
|
+
};
|
|
161
|
+
/** Pinned formulas: alpha = conversions + 1; beta = max(0, exposures − conversions) + 1. */
|
|
162
|
+
declare function posteriorOfCounts(c: PoolCounts): {
|
|
163
|
+
alpha: number;
|
|
164
|
+
beta: number;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Hierarchical partial pooling over (segment, persona), built by nesting the
|
|
168
|
+
* pinned one-axis shrinkage (shrunkPosterior, m = SHRINKAGE_M):
|
|
169
|
+
*
|
|
170
|
+
* segLevel = shrink(segment ← global)
|
|
171
|
+
* perLevel = shrink(persona ← global) (persona axis, when known)
|
|
172
|
+
* parent = evidence-weighted blend of segLevel and perLevel
|
|
173
|
+
* final = shrink(child ← parent)
|
|
174
|
+
*
|
|
175
|
+
* personaKnown=false consults ONLY segment+global — this is the invariant that
|
|
176
|
+
* keeps unknown-persona traffic on exactly the segment-marginal policy.
|
|
177
|
+
* Every cell is optional; an absent cell contributes Beta(1,1)-with-0-evidence,
|
|
178
|
+
* which is what lets the same function reproduce the legacy variant (segment-only)
|
|
179
|
+
* and legacy slot (persona-only) behaviors on day one after migration.
|
|
180
|
+
*/
|
|
181
|
+
declare function pooledPosterior(cells: PoolCells, personaKnown: boolean, m?: number): {
|
|
182
|
+
alpha: number;
|
|
183
|
+
beta: number;
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Write-side cell expansion: which weight rows one trial/credit must bump.
|
|
187
|
+
* Unknown persona bumps ONLY the segment marginal + global — no 'unknown'
|
|
188
|
+
* child or persona-marginal rows exist (unknown traffic serves the segment
|
|
189
|
+
* marginal, so that is where its evidence must live).
|
|
190
|
+
*/
|
|
191
|
+
declare function weightCellsFor(segment: string, persona: string): Array<{
|
|
192
|
+
segment: string;
|
|
193
|
+
persona: string;
|
|
194
|
+
}>;
|
|
195
|
+
|
|
145
196
|
/**
|
|
146
197
|
* FNV-1a 32-bit hash. Same algorithm (offset basis, prime-by-shifts, >>> 0)
|
|
147
198
|
* as the private hashUnit in apps/api/src/domain/holdout.ts — parity is
|
|
@@ -163,4 +214,4 @@ declare function pickDeterministicArm(sessionId: string, slotId: string, arms: s
|
|
|
163
214
|
*/
|
|
164
215
|
declare function confidenceBand(c: number): 'low' | 'medium' | 'high';
|
|
165
216
|
|
|
166
|
-
export { type ArmPosterior, CLUSTER_PRIORITY, LEGACY_PERSONA_MAP, type LearnedLayout, PERSONAS, PERSONA_DISPLAY, type Persona, type PersonaKey, SHRINKAGE_M, type SlotDecl, type SlotResult, UNKNOWN_PERSONA, applyClusterHeuristic, candidateLayouts, canonicalArm, canonicalPersona, chooseLayout, confidenceBand, fnv1a, hashLayout, marginalArmKey, parseArm, pickDeterministicArm, sampleArm, sampleBeta, shrunkPosterior, slotBaselineArm, slotResultFor, validateSlotDecl };
|
|
217
|
+
export { type ArmPosterior, CLUSTER_PRIORITY, LEGACY_PERSONA_MAP, type LearnedLayout, PERSONAS, PERSONA_DISPLAY, POOL_ALL, type Persona, type PersonaKey, type PoolCells, type PoolCounts, SHRINKAGE_M, type SlotDecl, type SlotResult, UNKNOWN_PERSONA, applyClusterHeuristic, candidateLayouts, canonicalArm, canonicalPersona, chooseLayout, confidenceBand, fnv1a, hashLayout, marginalArmKey, parseArm, pickDeterministicArm, pooledPosterior, posteriorOfCounts, sampleArm, sampleBeta, shrunkPosterior, slotBaselineArm, slotResultFor, validateSlotDecl, weightCellsFor };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var O=Object.defineProperty,se=Object.defineProperties,ae=Object.getOwnPropertyDescriptor,ie=Object.getOwnPropertyDescriptors,ue=Object.getOwnPropertyNames,F=Object.getOwnPropertySymbols;var V=Object.prototype.hasOwnProperty,ce=Object.prototype.propertyIsEnumerable;var T=(e,r,t)=>r in e?O(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,v=(e,r)=>{for(var t in r||(r={}))V.call(r,t)&&T(e,t,r[t]);if(F)for(var t of F(r))ce.call(r,t)&&T(e,t,r[t]);return e},L=(e,r)=>se(e,ie(r));var le=(e,r)=>{for(var t in r)O(e,t,{get:r[t],enumerable:!0})},fe=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of ue(r))!V.call(e,s)&&s!==t&&O(e,s,{get:()=>r[s],enumerable:!(n=ae(r,s))||n.enumerable});return e};var be=e=>fe(O({},"__esModule",{value:!0}),e);var Re={};le(Re,{CLUSTER_PRIORITY:()=>Q,LEGACY_PERSONA_MAP:()=>Z,PERSONAS:()=>j,PERSONA_DISPLAY:()=>me,POOL_ALL:()=>p,SHRINKAGE_M:()=>ee,UNKNOWN_PERSONA:()=>S,applyClusterHeuristic:()=>N,candidateLayouts:()=>H,canonicalArm:()=>z,canonicalPersona:()=>xe,chooseLayout:()=>de,confidenceBand:()=>we,fnv1a:()=>re,hashLayout:()=>U,marginalArmKey:()=>he,parseArm:()=>W,pickDeterministicArm:()=>Se,pooledPosterior:()=>ke,posteriorOfCounts:()=>R,sampleArm:()=>G,sampleBeta:()=>B,shrunkPosterior:()=>w,slotBaselineArm:()=>X,slotResultFor:()=>Pe,validateSlotDecl:()=>ye,weightCellsFor:()=>Ae});module.exports=be(Re);var j=["buyer","researcher","deal_seeker","browser"],S="unknown",me={buyer:"Buyer",researcher:"Researcher",deal_seeker:"Deal seeker",browser:"Browser",unknown:"Unknown"},Z={buyers:"buyer",researchers:"researcher","deal-seekers":"deal_seeker",browsers:"browser",buyer:"buyer",researcher:"researcher",deal_seeker:"deal_seeker",browser:"browser"};function xe(e){var t;if(e==null)return S;let r=e.trim().toLowerCase();return(t=Z[r])!=null?t:S}var pe=[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 x(e,r){return e>>>r|e<<32-r}function J(e){return(e>>>0).toString(16).padStart(8,"0")}function ge(e){let r=new TextEncoder().encode(e),t=r.length,n=t*8,s=(t+8>>6)+1<<6,o=new Uint8Array(s);o.set(r),o[t]=128;let a=new DataView(o.buffer);a.setUint32(s-8,Math.floor(n/4294967296),!1),a.setUint32(s-4,n>>>0,!1);let c=1779033703,i=3144134277,l=1013904242,m=2773480762,g=1359893119,b=2600822924,y=528734635,P=1541459225,f=new Uint32Array(64);for(let C=0;C<s;C+=64){for(let u=0;u<16;u++)f[u]=a.getUint32(C+u*4,!1);for(let u=16;u<64;u++){let D=x(f[u-15],7)^x(f[u-15],18)^f[u-15]>>>3,$=x(f[u-2],17)^x(f[u-2],19)^f[u-2]>>>10;f[u]=f[u-16]+D+f[u-7]+$>>>0}let d=c,k=i,A=l,E=m,h=g,M=b,_=y,q=P;for(let u=0;u<64;u++){let D=x(h,6)^x(h,11)^x(h,25),$=h&M^~h&_,Y=q+D+$+pe[u]+f[u]>>>0,te=x(d,2)^x(d,13)^x(d,22),ne=d&k^d&A^k&A,oe=te+ne>>>0;q=_,_=M,M=h,h=E+Y>>>0,E=A,A=k,k=d,d=Y+oe>>>0}c=c+d>>>0,i=i+k>>>0,l=l+A>>>0,m=m+E>>>0,g=g+h>>>0,b=b+M>>>0,y=y+_>>>0,P=P+q>>>0}return J(c)+J(i)}function U(e){return ge(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 N(e,r,t){let n=t===S?void 0:Q[t];return n?[...e].sort((s,o)=>{var i,l;let a=(i=r.get(s))!=null?i:"generic",c=(l=r.get(o))!=null?l:"generic";return n.indexOf(a)-n.indexOf(c)}):e}function H(e,r,t){let n=new Map;for(let s of[...j,t]){let o=N(e,r,s);n.set(U(o),o)}return n}function I(e,r){if(e<1)return I(1+e,r)*Math.pow(Math.max(1e-15,r()),1/e);let t=e-1/3,n=1/Math.sqrt(9*t);for(;;){let s,o;do{let c=Math.max(1e-15,r()),i=r();s=Math.sqrt(-2*Math.log(c))*Math.cos(2*Math.PI*i),o=1+n*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+t*(1-o+Math.log(o)))return t*o}}function B(e,r,t=Math.random){let n=I(e,t),s=I(r,t),o=n+s;return o<=0?e/(e+r):n/o}function G(e,r=Math.random){if(e.length===0)return null;if(e.length===1)return e[0].arm;let t=e[0],n=B(t.alpha,t.beta,r);for(let s=1;s<e.length;s++){let o=e[s],a=B(o.alpha,o.beta,r);a>n&&(t=o,n=a)}return t.arm}function de(e,r,t,n,s=Math.random){var l,m;let o=H(e,r,t),a=[];for(let g of o.keys()){let b=n.get(g);a.push({arm:g,alpha:(l=b==null?void 0:b.alpha)!=null?l:1,beta:(m=b==null?void 0:b.beta)!=null?m:1})}let c=G(a,s),i=c?o.get(c):void 0;return i!=null?i:N(e,r,t)}function z(e){return Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("|")}function W(e){if(e.length===0)return null;let r={};for(let t of e.split("|")){let n=t.indexOf("=");if(n<=0||n!==t.lastIndexOf("=")||n===t.length-1)return null;let s=t.slice(0,n);if(s in r)return null;r[s]=t.slice(n+1)}return r}function he(e,r){return`${e}=${r}`}function X(e){var t,n,s;if(e.arms)return typeof e.baseline=="string"?e.baseline:(t=e.arms[0])!=null?t:"";if(e.baseline!==void 0&&typeof e.baseline=="object")return z(e.baseline);if(typeof e.baseline=="string")return e.baseline;let r={};for(let[o,a]of Object.entries((n=e.dims)!=null?n:{}))r[o]=(s=a[0])!=null?s:"";return z(r)}function ye(e){let r=Array.isArray(e.arms),t=e.dims!=null;if(r&&t)return{ok:!1,reason:"declare exactly one of arms or dims (got both)"};if(!r&&!t)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(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 n=Object.entries(e.dims);if(n.length<1)return{ok:!1,reason:"dims requires at least 1 dimension"};if(n.length>4)return{ok:!1,reason:"dims allows at most 4 dimensions"};let s=1;for(let[o,a]of n){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=n.map(([i])=>i).sort(),c=Object.keys(o).sort();if(a.join(" ")!==c.join(" "))return{ok:!1,reason:"baseline must set every declared dim exactly once"};for(let[i,l]of n)if(!l.includes(o[i]))return{ok:!1,reason:`baseline value for dim "${i}" is not declared`}}return{ok:!0}}function Pe(e,r){var t,n;return e.dims!=null?(n=(t=W(r))!=null?t:W(X(e)))!=null?n:{}:r}var ee=20;function w(e,r,t=20){let n=t/(t+e.exposures);return{alpha:e.alpha+n*r.alpha,beta:e.beta+n*r.beta}}var p="__all__",K={exposures:0,conversions:0};function R(e){return{alpha:e.conversions+1,beta:Math.max(0,e.exposures-e.conversions)+1}}function ke(e,r,t=20){var b,y,P,f;let n=(b=e.segment)!=null?b:K,s=(y=e.global)!=null?y:K,o=R(s),a=w(L(v({},R(n)),{exposures:n.exposures}),o,t);if(!r)return a;let c=(P=e.persona)!=null?P:K,i=(f=e.child)!=null?f:K,l=w(L(v({},R(c)),{exposures:c.exposures}),o,t),m=(n.exposures+1)/(n.exposures+c.exposures+2),g={alpha:m*a.alpha+(1-m)*l.alpha,beta:m*a.beta+(1-m)*l.beta};return w(L(v({},R(i)),{exposures:i.exposures}),g,t)}function Ae(e,r){return r==="unknown"||r===p?[{segment:e,persona:p},{segment:p,persona:p}]:[{segment:e,persona:r},{segment:e,persona:p},{segment:p,persona:r},{segment:p,persona:p}]}function re(e){let r=2166136261;for(let t=0;t<e.length;t++)r^=e.charCodeAt(t),r=r+((r<<1)+(r<<4)+(r<<7)+(r<<8)+(r<<24))>>>0;return r}function Se(e,r,t){if(t.length===0)throw new Error("pickDeterministicArm requires at least one arm");let n=[...t].sort();return n[re(`${e}:${r}`)%n.length]}function we(e){return e>=.3?e<.7?"medium":"high":"low"}0&&(module.exports={CLUSTER_PRIORITY,LEGACY_PERSONA_MAP,PERSONAS,PERSONA_DISPLAY,POOL_ALL,SHRINKAGE_M,UNKNOWN_PERSONA,applyClusterHeuristic,candidateLayouts,canonicalArm,canonicalPersona,chooseLayout,confidenceBand,fnv1a,hashLayout,marginalArmKey,parseArm,pickDeterministicArm,pooledPosterior,posteriorOfCounts,sampleArm,sampleBeta,shrunkPosterior,slotBaselineArm,slotResultFor,validateSlotDecl,weightCellsFor});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var X=Object.defineProperty,ee=Object.defineProperties;var re=Object.getOwnPropertyDescriptors;var U=Object.getOwnPropertySymbols;var te=Object.prototype.hasOwnProperty,ne=Object.prototype.propertyIsEnumerable;var H=(e,r,t)=>r in e?X(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,R=(e,r)=>{for(var t in r||(r={}))te.call(r,t)&&H(e,t,r[t]);if(U)for(var t of U(r))ne.call(r,t)&&H(e,t,r[t]);return e},M=(e,r)=>ee(e,re(r));var I=["buyer","researcher","deal_seeker","browser"],_="unknown",fe={buyer:"Buyer",researcher:"Researcher",deal_seeker:"Deal seeker",browser:"Browser",unknown:"Unknown"},oe={buyers:"buyer",researchers:"researcher","deal-seekers":"deal_seeker",browsers:"browser",buyer:"buyer",researcher:"researcher",deal_seeker:"deal_seeker",browser:"browser"};function be(e){var t;if(e==null)return _;let r=e.trim().toLowerCase();return(t=oe[r])!=null?t:_}var se=[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 x(e,r){return e>>>r|e<<32-r}function B(e){return(e>>>0).toString(16).padStart(8,"0")}function ae(e){let r=new TextEncoder().encode(e),t=r.length,n=t*8,s=(t+8>>6)+1<<6,o=new Uint8Array(s);o.set(r),o[t]=128;let a=new DataView(o.buffer);a.setUint32(s-8,Math.floor(n/4294967296),!1),a.setUint32(s-4,n>>>0,!1);let c=1779033703,i=3144134277,l=1013904242,m=2773480762,p=1359893119,b=2600822924,y=528734635,P=1541459225,f=new Uint32Array(64);for(let N=0;N<s;N+=64){for(let u=0;u<16;u++)f[u]=a.getUint32(N+u*4,!1);for(let u=16;u<64;u++){let E=x(f[u-15],7)^x(f[u-15],18)^f[u-15]>>>3,q=x(f[u-2],17)^x(f[u-2],19)^f[u-2]>>>10;f[u]=f[u-16]+E+f[u-7]+q>>>0}let g=c,k=i,A=l,K=m,d=p,S=b,w=y,C=P;for(let u=0;u<64;u++){let E=x(d,6)^x(d,11)^x(d,25),q=d&S^~d&w,j=C+E+q+se[u]+f[u]>>>0,Z=x(g,2)^x(g,13)^x(g,22),J=g&k^g&A^k&A,Q=Z+J>>>0;C=w,w=S,S=d,d=K+j>>>0,K=A,A=k,k=g,g=j+Q>>>0}c=c+g>>>0,i=i+k>>>0,l=l+A>>>0,m=m+K>>>0,p=p+d>>>0,b=b+S>>>0,y=y+w>>>0,P=P+C>>>0}return B(c)+B(i)}function G(e){return ae(e.join("|"))}var ie={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 D(e,r,t){let n=t===_?void 0:ie[t];return n?[...e].sort((s,o)=>{var i,l;let a=(i=r.get(s))!=null?i:"generic",c=(l=r.get(o))!=null?l:"generic";return n.indexOf(a)-n.indexOf(c)}):e}function z(e,r,t){let n=new Map;for(let s of[...I,t]){let o=D(e,r,s);n.set(G(o),o)}return n}function $(e,r){if(e<1)return $(1+e,r)*Math.pow(Math.max(1e-15,r()),1/e);let t=e-1/3,n=1/Math.sqrt(9*t);for(;;){let s,o;do{let c=Math.max(1e-15,r()),i=r();s=Math.sqrt(-2*Math.log(c))*Math.cos(2*Math.PI*i),o=1+n*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+t*(1-o+Math.log(o)))return t*o}}function W(e,r,t=Math.random){let n=$(e,t),s=$(r,t),o=n+s;return o<=0?e/(e+r):n/o}function Y(e,r=Math.random){if(e.length===0)return null;if(e.length===1)return e[0].arm;let t=e[0],n=W(t.alpha,t.beta,r);for(let s=1;s<e.length;s++){let o=e[s],a=W(o.alpha,o.beta,r);a>n&&(t=o,n=a)}return t.arm}function ke(e,r,t,n,s=Math.random){var l,m;let o=z(e,r,t),a=[];for(let p of o.keys()){let b=n.get(p);a.push({arm:p,alpha:(l=b==null?void 0:b.alpha)!=null?l:1,beta:(m=b==null?void 0:b.beta)!=null?m:1})}let c=Y(a,s),i=c?o.get(c):void 0;return i!=null?i:D(e,r,t)}function F(e){return Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("|")}function T(e){if(e.length===0)return null;let r={};for(let t of e.split("|")){let n=t.indexOf("=");if(n<=0||n!==t.lastIndexOf("=")||n===t.length-1)return null;let s=t.slice(0,n);if(s in r)return null;r[s]=t.slice(n+1)}return r}function Se(e,r){return`${e}=${r}`}function ue(e){var t,n,s;if(e.arms)return typeof e.baseline=="string"?e.baseline:(t=e.arms[0])!=null?t:"";if(e.baseline!==void 0&&typeof e.baseline=="object")return F(e.baseline);if(typeof e.baseline=="string")return e.baseline;let r={};for(let[o,a]of Object.entries((n=e.dims)!=null?n:{}))r[o]=(s=a[0])!=null?s:"";return F(r)}function we(e){let r=Array.isArray(e.arms),t=e.dims!=null;if(r&&t)return{ok:!1,reason:"declare exactly one of arms or dims (got both)"};if(!r&&!t)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(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 n=Object.entries(e.dims);if(n.length<1)return{ok:!1,reason:"dims requires at least 1 dimension"};if(n.length>4)return{ok:!1,reason:"dims allows at most 4 dimensions"};let s=1;for(let[o,a]of n){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=n.map(([i])=>i).sort(),c=Object.keys(o).sort();if(a.join(" ")!==c.join(" "))return{ok:!1,reason:"baseline must set every declared dim exactly once"};for(let[i,l]of n)if(!l.includes(o[i]))return{ok:!1,reason:`baseline value for dim "${i}" is not declared`}}return{ok:!0}}function Re(e,r){var t,n;return e.dims!=null?(n=(t=T(r))!=null?t:T(ue(e)))!=null?n:{}:r}var V=20;function O(e,r,t=20){let n=t/(t+e.exposures);return{alpha:e.alpha+n*r.alpha,beta:e.beta+n*r.beta}}var h="__all__",v={exposures:0,conversions:0};function L(e){return{alpha:e.conversions+1,beta:Math.max(0,e.exposures-e.conversions)+1}}function ve(e,r,t=20){var b,y,P,f;let n=(b=e.segment)!=null?b:v,s=(y=e.global)!=null?y:v,o=L(s),a=O(M(R({},L(n)),{exposures:n.exposures}),o,t);if(!r)return a;let c=(P=e.persona)!=null?P:v,i=(f=e.child)!=null?f:v,l=O(M(R({},L(c)),{exposures:c.exposures}),o,t),m=(n.exposures+1)/(n.exposures+c.exposures+2),p={alpha:m*a.alpha+(1-m)*l.alpha,beta:m*a.beta+(1-m)*l.beta};return O(M(R({},L(i)),{exposures:i.exposures}),p,t)}function Le(e,r){return r==="unknown"||r===h?[{segment:e,persona:h},{segment:h,persona:h}]:[{segment:e,persona:r},{segment:e,persona:h},{segment:h,persona:r},{segment:h,persona:h}]}function ce(e){let r=2166136261;for(let t=0;t<e.length;t++)r^=e.charCodeAt(t),r=r+((r<<1)+(r<<4)+(r<<7)+(r<<8)+(r<<24))>>>0;return r}function Ce(e,r,t){if(t.length===0)throw new Error("pickDeterministicArm requires at least one arm");let n=[...t].sort();return n[ce(`${e}:${r}`)%n.length]}function Ee(e){return e>=.3?e<.7?"medium":"high":"low"}export{ie as CLUSTER_PRIORITY,oe as LEGACY_PERSONA_MAP,I as PERSONAS,fe as PERSONA_DISPLAY,h as POOL_ALL,V as SHRINKAGE_M,_ as UNKNOWN_PERSONA,D as applyClusterHeuristic,z as candidateLayouts,F as canonicalArm,be as canonicalPersona,ke as chooseLayout,Ee as confidenceBand,ce as fnv1a,G as hashLayout,Se as marginalArmKey,T as parseArm,Ce as pickDeterministicArm,ve as pooledPosterior,L as posteriorOfCounts,Y as sampleArm,W as sampleBeta,O as shrunkPosterior,ue as slotBaselineArm,Re as slotResultFor,we as validateSlotDecl,Le as weightCellsFor};
|