@sentientui/policy 0.3.3 → 0.4.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 +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -228,4 +228,14 @@ declare function pickDeterministicArm(sessionId: string, slotId: string, arms: s
|
|
|
228
228
|
*/
|
|
229
229
|
declare function confidenceBand(c: number): 'low' | 'medium' | 'high';
|
|
230
230
|
|
|
231
|
-
|
|
231
|
+
/** = MIN_VALUED_CONVERSIONS: cells earn their own voice at ~20 valued orders. */
|
|
232
|
+
declare const EV_SHRINK_K = 20;
|
|
233
|
+
type ValueCell = {
|
|
234
|
+
valueSum: number;
|
|
235
|
+
valueCount: number;
|
|
236
|
+
};
|
|
237
|
+
declare function shrunkAvgValue(cell: ValueCell, reference: number, k?: number): number;
|
|
238
|
+
type EvArm = ArmPosterior & ValueCell;
|
|
239
|
+
declare function sampleArmEv(arms: EvArm[], reference: number, rand?: () => number): string | null;
|
|
240
|
+
|
|
241
|
+
export { type ArmPosterior, CLUSTER_PRIORITY, EV_SHRINK_K, type EvArm, 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, type ValueCell, applyClusterHeuristic, candidateLayouts, canonicalArm, canonicalPersona, chooseLayout, confidenceBand, fnv1a, hashLayout, marginalArmKey, parseArm, pickDeterministicArm, pooledPosterior, posteriorOfCounts, sampleArm, sampleArmEv, sampleBeta, shrunkAvgValue, shrunkPosterior, slotBaselineArm, slotResultFor, validateSlotDecl, weightCellsFor };
|
package/dist/index.d.ts
CHANGED
|
@@ -228,4 +228,14 @@ declare function pickDeterministicArm(sessionId: string, slotId: string, arms: s
|
|
|
228
228
|
*/
|
|
229
229
|
declare function confidenceBand(c: number): 'low' | 'medium' | 'high';
|
|
230
230
|
|
|
231
|
-
|
|
231
|
+
/** = MIN_VALUED_CONVERSIONS: cells earn their own voice at ~20 valued orders. */
|
|
232
|
+
declare const EV_SHRINK_K = 20;
|
|
233
|
+
type ValueCell = {
|
|
234
|
+
valueSum: number;
|
|
235
|
+
valueCount: number;
|
|
236
|
+
};
|
|
237
|
+
declare function shrunkAvgValue(cell: ValueCell, reference: number, k?: number): number;
|
|
238
|
+
type EvArm = ArmPosterior & ValueCell;
|
|
239
|
+
declare function sampleArmEv(arms: EvArm[], reference: number, rand?: () => number): string | null;
|
|
240
|
+
|
|
241
|
+
export { type ArmPosterior, CLUSTER_PRIORITY, EV_SHRINK_K, type EvArm, 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, type ValueCell, applyClusterHeuristic, candidateLayouts, canonicalArm, canonicalPersona, chooseLayout, confidenceBand, fnv1a, hashLayout, marginalArmKey, parseArm, pickDeterministicArm, pooledPosterior, posteriorOfCounts, sampleArm, sampleArmEv, sampleBeta, shrunkAvgValue, shrunkPosterior, slotBaselineArm, slotResultFor, validateSlotDecl, weightCellsFor };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var M=Object.defineProperty,ie=Object.defineProperties,ue=Object.getOwnPropertyDescriptor,ce=Object.getOwnPropertyDescriptors,le=Object.getOwnPropertyNames,Y=Object.getOwnPropertySymbols;var T=Object.prototype.hasOwnProperty,fe=Object.prototype.propertyIsEnumerable;var F=(e,r,t)=>r in e?M(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,O=(e,r)=>{for(var t in r||(r={}))T.call(r,t)&&F(e,t,r[t]);if(Y)for(var t of Y(r))fe.call(r,t)&&F(e,t,r[t]);return e},E=(e,r)=>ie(e,ce(r));var me=(e,r)=>{for(var t in r)M(e,t,{get:r[t],enumerable:!0})},be=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of le(r))!T.call(e,s)&&s!==t&&M(e,s,{get:()=>r[s],enumerable:!(n=ue(r,s))||n.enumerable});return e};var pe=e=>be(M({},"__esModule",{value:!0}),e);var Ce={};me(Ce,{CLUSTER_PRIORITY:()=>Q,EV_SHRINK_K:()=>te,LEGACY_PERSONA_MAP:()=>Z,PERSONAS:()=>H,PERSONA_DISPLAY:()=>xe,POOL_ALL:()=>g,SHRINKAGE_M:()=>ee,UNKNOWN_PERSONA:()=>v,applyClusterHeuristic:()=>N,candidateLayouts:()=>U,canonicalArm:()=>G,canonicalPersona:()=>ge,chooseLayout:()=>ye,confidenceBand:()=>Re,fnv1a:()=>re,hashLayout:()=>I,marginalArmKey:()=>Pe,parseArm:()=>z,pickDeterministicArm:()=>we,pooledPosterior:()=>ve,posteriorOfCounts:()=>R,sampleArm:()=>V,sampleArmEv:()=>_e,sampleBeta:()=>S,shrunkAvgValue:()=>ne,shrunkPosterior:()=>w,slotBaselineArm:()=>X,slotResultFor:()=>Ae,validateSlotDecl:()=>ke,weightCellsFor:()=>Se});module.exports=pe(Ce);var H=["buyer","researcher","deal_seeker","browser"],v="unknown",xe={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 ge(e){var t;if(e==null)return v;let r=e.trim().toLowerCase();return(t=Z[r])!=null?t:v}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 x(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),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 u=1779033703,c=3144134277,m=1013904242,l=2773480762,p=1359893119,b=2600822924,y=528734635,P=1541459225,f=new Uint32Array(64);for(let L=0;L<s;L+=64){for(let i=0;i<16;i++)f[i]=a.getUint32(L+i*4,!1);for(let i=16;i<64;i++){let $=x(f[i-15],7)^x(f[i-15],18)^f[i-15]>>>3,j=x(f[i-2],17)^x(f[i-2],19)^f[i-2]>>>10;f[i]=f[i-16]+$+f[i-7]+j>>>0}let d=u,k=c,A=m,q=l,h=p,_=b,C=y,D=P;for(let i=0;i<64;i++){let $=x(h,6)^x(h,11)^x(h,25),j=h&_^~h&C,W=D+$+j+de[i]+f[i]>>>0,oe=x(d,2)^x(d,13)^x(d,22),se=d&k^d&A^k&A,ae=oe+se>>>0;D=C,C=_,_=h,h=q+W>>>0,q=A,A=k,k=d,d=W+ae>>>0}u=u+d>>>0,c=c+k>>>0,m=m+A>>>0,l=l+q>>>0,p=p+h>>>0,b=b+_>>>0,y=y+C>>>0,P=P+D>>>0}return J(u)+J(c)}function I(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 N(e,r,t){let n=t===v?void 0:Q[t];if(!n)return e;let s=n.indexOf("generic"),o=a=>{let u=n.indexOf(a);return u===-1?s:u};return[...e].sort((a,u)=>{var l,p;let c=(l=r.get(a))!=null?l:"generic",m=(p=r.get(u))!=null?p:"generic";return o(c)-o(m)})}function U(e,r,t){let n=new Map;for(let s of[...H,t]){let o=N(e,r,s);n.set(I(o),o)}return n}function B(e,r){if(e<1)return B(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 u=Math.max(1e-15,r()),c=r();s=Math.sqrt(-2*Math.log(u))*Math.cos(2*Math.PI*c),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 S(e,r,t=Math.random){let n=B(e,t),s=B(r,t),o=n+s;return o<=0?e/(e+r):n/o}function V(e,r=Math.random){if(e.length===0)return null;if(e.length===1)return e[0].arm;let t=e[0],n=S(t.alpha,t.beta,r);for(let s=1;s<e.length;s++){let o=e[s],a=S(o.alpha,o.beta,r);a>n&&(t=o,n=a)}return t.arm}function ye(e,r,t,n,s=Math.random){var m,l;let o=U(e,r,t),a=[];for(let p of o.keys()){let b=n.get(p);a.push({arm:p,alpha:(m=b==null?void 0:b.alpha)!=null?m:1,beta:(l=b==null?void 0:b.beta)!=null?l:1})}let u=V(a,s),c=u?o.get(u):void 0;return c!=null?c:N(e,r,t)}function G(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 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 Pe(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 G(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 G(r)}function ke(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(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 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(([c])=>c).sort(),u=Object.keys(o).sort();if(a.join(" ")!==u.join(" "))return{ok:!1,reason:"baseline must set every declared dim exactly once"};for(let[c,m]of n)if(!m.includes(o[c]))return{ok:!1,reason:`baseline value for dim "${c}" is not declared`}}return{ok:!0}}function Ae(e,r){var t,n;return e.dims!=null?(n=(t=z(r))!=null?t:z(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 g="__all__",K={exposures:0,conversions:0};function R(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:K,s=(y=e.global)!=null?y:K,o=R(s),a=w(E(O({},R(n)),{exposures:n.exposures}),o,t);if(!r)return a;let u=(P=e.persona)!=null?P:K,c=(f=e.child)!=null?f:K,m=w(E(O({},R(u)),{exposures:u.exposures}),o,t),l=(n.exposures+1)/(n.exposures+u.exposures+2),p={alpha:l*a.alpha+(1-l)*m.alpha,beta:l*a.beta+(1-l)*m.beta};return w(E(O({},R(c)),{exposures:c.exposures}),p,t)}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 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 we(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 Re(e){return e>=.3?e<.7?"medium":"high":"low"}var te=20;function ne(e,r,t=te){let n=e.valueCount>0?e.valueSum/e.valueCount:0;if(r<=0)return n;if(e.valueCount<=0)return r;let s=e.valueCount/(e.valueCount+t);return s*n+(1-s)*r}function _e(e,r,t=Math.random){if(e.length===0)return null;if(e.length===1)return e[0].arm;let n=null,s=-1/0;for(let o of e){let a=S(o.alpha,o.beta,t)*ne(o,r);a>s&&(n=o,s=a)}return n.arm}0&&(module.exports={CLUSTER_PRIORITY,EV_SHRINK_K,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,sampleArmEv,sampleBeta,shrunkAvgValue,shrunkPosterior,slotBaselineArm,slotResultFor,validateSlotDecl,weightCellsFor});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var X=Object.defineProperty,ee=Object.defineProperties;var re=Object.getOwnPropertyDescriptors;var
|
|
1
|
+
var X=Object.defineProperty,ee=Object.defineProperties;var re=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var te=Object.prototype.hasOwnProperty,ne=Object.prototype.propertyIsEnumerable;var U=(e,r,t)=>r in e?X(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,w=(e,r)=>{for(var t in r||(r={}))te.call(r,t)&&U(e,t,r[t]);if(I)for(var t of I(r))ne.call(r,t)&&U(e,t,r[t]);return e},R=(e,r)=>ee(e,re(r));var B=["buyer","researcher","deal_seeker","browser"],_="unknown",be={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 pe(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 V(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 u=1779033703,c=3144134277,m=1013904242,l=2773480762,p=1359893119,b=2600822924,y=528734635,P=1541459225,f=new Uint32Array(64);for(let N=0;N<s;N+=64){for(let i=0;i<16;i++)f[i]=a.getUint32(N+i*4,!1);for(let i=16;i<64;i++){let q=x(f[i-15],7)^x(f[i-15],18)^f[i-15]>>>3,D=x(f[i-2],17)^x(f[i-2],19)^f[i-2]>>>10;f[i]=f[i-16]+q+f[i-7]+D>>>0}let g=u,k=c,A=m,K=l,d=p,v=b,S=y,L=P;for(let i=0;i<64;i++){let q=x(d,6)^x(d,11)^x(d,25),D=d&v^~d&S,H=L+q+D+se[i]+f[i]>>>0,Z=x(g,2)^x(g,13)^x(g,22),J=g&k^g&A^k&A,Q=Z+J>>>0;L=S,S=v,v=d,d=K+H>>>0,K=A,A=k,k=g,g=H+Q>>>0}u=u+g>>>0,c=c+k>>>0,m=m+A>>>0,l=l+K>>>0,p=p+d>>>0,b=b+v>>>0,y=y+S>>>0,P=P+L>>>0}return V(u)+V(c)}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 $(e,r,t){let n=t===_?void 0:ie[t];if(!n)return e;let s=n.indexOf("generic"),o=a=>{let u=n.indexOf(a);return u===-1?s:u};return[...e].sort((a,u)=>{var l,p;let c=(l=r.get(a))!=null?l:"generic",m=(p=r.get(u))!=null?p:"generic";return o(c)-o(m)})}function z(e,r,t){let n=new Map;for(let s of[...B,t]){let o=$(e,r,s);n.set(G(o),o)}return n}function j(e,r){if(e<1)return j(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 u=Math.max(1e-15,r()),c=r();s=Math.sqrt(-2*Math.log(u))*Math.cos(2*Math.PI*c),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 C(e,r,t=Math.random){let n=j(e,t),s=j(r,t),o=n+s;return o<=0?e/(e+r):n/o}function W(e,r=Math.random){if(e.length===0)return null;if(e.length===1)return e[0].arm;let t=e[0],n=C(t.alpha,t.beta,r);for(let s=1;s<e.length;s++){let o=e[s],a=C(o.alpha,o.beta,r);a>n&&(t=o,n=a)}return t.arm}function ve(e,r,t,n,s=Math.random){var m,l;let o=z(e,r,t),a=[];for(let p of o.keys()){let b=n.get(p);a.push({arm:p,alpha:(m=b==null?void 0:b.alpha)!=null?m:1,beta:(l=b==null?void 0:b.beta)!=null?l:1})}let u=W(a,s),c=u?o.get(u):void 0;return c!=null?c:$(e,r,t)}function Y(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 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 we(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 Y(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 Y(r)}function Re(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(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 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(([c])=>c).sort(),u=Object.keys(o).sort();if(a.join(" ")!==u.join(" "))return{ok:!1,reason:"baseline must set every declared dim exactly once"};for(let[c,m]of n)if(!m.includes(o[c]))return{ok:!1,reason:`baseline value for dim "${c}" is not declared`}}return{ok:!0}}function _e(e,r){var t,n;return e.dims!=null?(n=(t=F(r))!=null?t:F(ue(e)))!=null?n:{}:r}var T=20;function M(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__",O={exposures:0,conversions:0};function E(e){return{alpha:e.conversions+1,beta:Math.max(0,e.exposures-e.conversions)+1}}function Ee(e,r,t=20){var b,y,P,f;let n=(b=e.segment)!=null?b:O,s=(y=e.global)!=null?y:O,o=E(s),a=M(R(w({},E(n)),{exposures:n.exposures}),o,t);if(!r)return a;let u=(P=e.persona)!=null?P:O,c=(f=e.child)!=null?f:O,m=M(R(w({},E(u)),{exposures:u.exposures}),o,t),l=(n.exposures+1)/(n.exposures+u.exposures+2),p={alpha:l*a.alpha+(1-l)*m.alpha,beta:l*a.beta+(1-l)*m.beta};return M(R(w({},E(c)),{exposures:c.exposures}),p,t)}function Ne(e,r){return r==="unknown"||r===h||r===""?[{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 qe(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 De(e){return e>=.3?e<.7?"medium":"high":"low"}var le=20;function fe(e,r,t=le){let n=e.valueCount>0?e.valueSum/e.valueCount:0;if(r<=0)return n;if(e.valueCount<=0)return r;let s=e.valueCount/(e.valueCount+t);return s*n+(1-s)*r}function He(e,r,t=Math.random){if(e.length===0)return null;if(e.length===1)return e[0].arm;let n=null,s=-1/0;for(let o of e){let a=C(o.alpha,o.beta,t)*fe(o,r);a>s&&(n=o,s=a)}return n.arm}export{ie as CLUSTER_PRIORITY,le as EV_SHRINK_K,oe as LEGACY_PERSONA_MAP,B as PERSONAS,be as PERSONA_DISPLAY,h as POOL_ALL,T as SHRINKAGE_M,_ as UNKNOWN_PERSONA,$ as applyClusterHeuristic,z as candidateLayouts,Y as canonicalArm,pe as canonicalPersona,ve as chooseLayout,De as confidenceBand,ce as fnv1a,G as hashLayout,we as marginalArmKey,F as parseArm,qe as pickDeterministicArm,Ee as pooledPosterior,E as posteriorOfCounts,W as sampleArm,He as sampleArmEv,C as sampleBeta,fe as shrunkAvgValue,M as shrunkPosterior,ue as slotBaselineArm,_e as slotResultFor,Re as validateSlotDecl,Ne as weightCellsFor};
|