@sentientui/policy 0.6.2 → 0.7.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 +36 -1
- package/dist/index.d.ts +36 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -187,6 +187,41 @@ declare function shrunkPosterior(cell: {
|
|
|
187
187
|
alpha: number;
|
|
188
188
|
beta: number;
|
|
189
189
|
};
|
|
190
|
+
/**
|
|
191
|
+
* Pseudo-count for the weights-fallback prior below — the number of imaginary
|
|
192
|
+
* pulls at reward ZERO mixed into every arm's mean. Large enough to sink a
|
|
193
|
+
* lucky 1-pull arm, small enough to be negligible once an arm has real traffic.
|
|
194
|
+
*
|
|
195
|
+
* Deliberately NOT `SHRINKAGE_M`. This constant shipped as 5 in the React
|
|
196
|
+
* SDK's degraded fallback and the pick is serving behaviour: raising it to 20
|
|
197
|
+
* (or adopting `shrunkPosterior`'s parent-mass damping) would change which
|
|
198
|
+
* variant renders for visitors whose `/assign` hasn't resolved, and that
|
|
199
|
+
* requires a replay before it ships. Moved here (audit REACT-14) so the
|
|
200
|
+
* formula is single-sourced, not to change it.
|
|
201
|
+
*/
|
|
202
|
+
declare const WEIGHTS_FALLBACK_PRIOR_PULLS = 5;
|
|
203
|
+
/** One arm as published on the SDK weights feed (`/v1/weights`). */
|
|
204
|
+
type WeightsFallbackArm = {
|
|
205
|
+
variantId: string;
|
|
206
|
+
pulls?: number | null;
|
|
207
|
+
avgReward: number;
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Degraded-fallback selection from cached bandit weights, used by the SDKs
|
|
211
|
+
* only while the server assignment hasn't resolved. Ranks arms by a posterior
|
|
212
|
+
* mean shrunk toward a zero prior — `pulls·avgReward / (pulls + PRIOR)` — so a
|
|
213
|
+
* lucky small-sample arm (e.g. 1 pull at avgReward 1.0) can't outrank a
|
|
214
|
+
* well-sampled one (500 pulls at 0.2). With equal pulls the shrinkage is
|
|
215
|
+
* monotonic in avgReward, preserving plain "highest avgReward wins" behavior.
|
|
216
|
+
*
|
|
217
|
+
* This is NOT the pinned read-side shrinkage (`shrunkPosterior`): the prior
|
|
218
|
+
* mean here is a constant 0, not a parent posterior, and the pseudo-count is
|
|
219
|
+
* the fixed `WEIGHTS_FALLBACK_PRIOR_PULLS`, undamped — the weights feed
|
|
220
|
+
* carries no parent to shrink toward. Zero-pull arms score 0, tying with (not
|
|
221
|
+
* beating) an all-losses arm; ties keep the first arm in weights order
|
|
222
|
+
* (strict `>` comparison — callers rely on that determinism).
|
|
223
|
+
*/
|
|
224
|
+
declare function pickFromWeights(variants: readonly WeightsFallbackArm[], variantIds: readonly string[]): string | null;
|
|
190
225
|
|
|
191
226
|
/** Sentinel segment/persona value for marginal and global weight rows. */
|
|
192
227
|
declare const POOL_ALL = "__all__";
|
|
@@ -404,4 +439,4 @@ declare function resolvePersona(input: {
|
|
|
404
439
|
*/
|
|
405
440
|
declare function decisionPersona(label: string | null | undefined): string;
|
|
406
441
|
|
|
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 };
|
|
442
|
+
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, WEIGHTS_FALLBACK_PRIOR_PULLS, type WeightsFallbackArm, applyClusterHeuristic, broadestValueCell, candidateLayouts, canonicalArm, canonicalPersona, chooseLayout, confidenceBand, decisionPersona, fnv1a, hashLayout, marginalArmKey, normalizeDeclaredPersona, parseArm, pickDeterministicArm, pickFromWeights, pooledPosterior, posteriorOfCounts, resolvePersona, sampleArm, sampleArmEv, sampleBeta, shrunkAvgValue, shrunkPosterior, slotBaselineArm, slotResultFor, validateSlotDecl, weightCellsFor };
|
package/dist/index.d.ts
CHANGED
|
@@ -187,6 +187,41 @@ declare function shrunkPosterior(cell: {
|
|
|
187
187
|
alpha: number;
|
|
188
188
|
beta: number;
|
|
189
189
|
};
|
|
190
|
+
/**
|
|
191
|
+
* Pseudo-count for the weights-fallback prior below — the number of imaginary
|
|
192
|
+
* pulls at reward ZERO mixed into every arm's mean. Large enough to sink a
|
|
193
|
+
* lucky 1-pull arm, small enough to be negligible once an arm has real traffic.
|
|
194
|
+
*
|
|
195
|
+
* Deliberately NOT `SHRINKAGE_M`. This constant shipped as 5 in the React
|
|
196
|
+
* SDK's degraded fallback and the pick is serving behaviour: raising it to 20
|
|
197
|
+
* (or adopting `shrunkPosterior`'s parent-mass damping) would change which
|
|
198
|
+
* variant renders for visitors whose `/assign` hasn't resolved, and that
|
|
199
|
+
* requires a replay before it ships. Moved here (audit REACT-14) so the
|
|
200
|
+
* formula is single-sourced, not to change it.
|
|
201
|
+
*/
|
|
202
|
+
declare const WEIGHTS_FALLBACK_PRIOR_PULLS = 5;
|
|
203
|
+
/** One arm as published on the SDK weights feed (`/v1/weights`). */
|
|
204
|
+
type WeightsFallbackArm = {
|
|
205
|
+
variantId: string;
|
|
206
|
+
pulls?: number | null;
|
|
207
|
+
avgReward: number;
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Degraded-fallback selection from cached bandit weights, used by the SDKs
|
|
211
|
+
* only while the server assignment hasn't resolved. Ranks arms by a posterior
|
|
212
|
+
* mean shrunk toward a zero prior — `pulls·avgReward / (pulls + PRIOR)` — so a
|
|
213
|
+
* lucky small-sample arm (e.g. 1 pull at avgReward 1.0) can't outrank a
|
|
214
|
+
* well-sampled one (500 pulls at 0.2). With equal pulls the shrinkage is
|
|
215
|
+
* monotonic in avgReward, preserving plain "highest avgReward wins" behavior.
|
|
216
|
+
*
|
|
217
|
+
* This is NOT the pinned read-side shrinkage (`shrunkPosterior`): the prior
|
|
218
|
+
* mean here is a constant 0, not a parent posterior, and the pseudo-count is
|
|
219
|
+
* the fixed `WEIGHTS_FALLBACK_PRIOR_PULLS`, undamped — the weights feed
|
|
220
|
+
* carries no parent to shrink toward. Zero-pull arms score 0, tying with (not
|
|
221
|
+
* beating) an all-losses arm; ties keep the first arm in weights order
|
|
222
|
+
* (strict `>` comparison — callers rely on that determinism).
|
|
223
|
+
*/
|
|
224
|
+
declare function pickFromWeights(variants: readonly WeightsFallbackArm[], variantIds: readonly string[]): string | null;
|
|
190
225
|
|
|
191
226
|
/** Sentinel segment/persona value for marginal and global weight rows. */
|
|
192
227
|
declare const POOL_ALL = "__all__";
|
|
@@ -404,4 +439,4 @@ declare function resolvePersona(input: {
|
|
|
404
439
|
*/
|
|
405
440
|
declare function decisionPersona(label: string | null | undefined): string;
|
|
406
441
|
|
|
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 };
|
|
442
|
+
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, WEIGHTS_FALLBACK_PRIOR_PULLS, type WeightsFallbackArm, applyClusterHeuristic, broadestValueCell, candidateLayouts, canonicalArm, canonicalPersona, chooseLayout, confidenceBand, decisionPersona, fnv1a, hashLayout, marginalArmKey, normalizeDeclaredPersona, parseArm, pickDeterministicArm, pickFromWeights, 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 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});
|
|
1
|
+
"use strict";var L=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames,T=Object.getOwnPropertySymbols;var X=Object.prototype.hasOwnProperty,be=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))be.call(r,n)&&Z(e,n,r[n]);return e};var ge=(e,r)=>{for(var n in r)L(e,n,{get:r[n],enumerable:!0})},de=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of pe(r))!X.call(e,s)&&s!==n&&L(e,s,{get:()=>r[s],enumerable:!(t=me(r,s))||t.enumerable});return e};var xe=e=>de(L({},"__esModule",{value:!0}),e);var Ke={};ge(Ke,{CLUSTER_PRIORITY:()=>Q,DEFAULT_PERSONA_VOCABULARY:()=>ue,EV_SHRINK_K:()=>oe,LEGACY_PERSONA_MAP:()=>M,PERSONAS:()=>R,PERSONA_DISPLAY:()=>H,PERSONA_KEY_RE:()=>ae,POOL_ALL:()=>g,RESERVED_PERSONA_KEYS:()=>ie,SHRINKAGE_M:()=>re,UNKNOWN_PERSONA:()=>y,WEIGHTS_FALLBACK_PRIOR_PULLS:()=>ne,applyClusterHeuristic:()=>N,broadestValueCell:()=>_e,candidateLayouts:()=>z,canonicalArm:()=>Y,canonicalPersona:()=>O,chooseLayout:()=>Pe,confidenceBand:()=>Ee,decisionPersona:()=>De,fnv1a:()=>te,hashLayout:()=>j,marginalArmKey:()=>Ae,normalizeDeclaredPersona:()=>Me,parseArm:()=>F,pickDeterministicArm:()=>we,pickFromWeights:()=>Re,pooledPosterior:()=>Se,posteriorOfCounts:()=>C,resolvePersona:()=>Ie,sampleArm:()=>G,sampleArmEv:()=>Le,sampleBeta:()=>S,shrunkAvgValue:()=>se,shrunkPosterior:()=>_,slotBaselineArm:()=>ee,slotResultFor:()=>ve,validateSlotDecl:()=>ke,weightCellsFor:()=>Ce});module.exports=xe(Ke);var R=["buyer","researcher","deal_seeker","browser"],y="unknown",H={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 O(e){var n;if(e==null)return y;let r=e.trim().toLowerCase();return(n=M[r])!=null?n:y}var he=[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 ye(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 D=0;D<s;D+=64){for(let l=0;l<16;l++)p[l]=a.getUint32(D+l*4,!1);for(let l=16;l<64;l++){let U=d(p[l-15],7)^d(p[l-15],18)^p[l-15]>>>3,q=d(p[l-2],17)^d(p[l-2],19)^p[l-2]>>>10;p[l]=p[l-16]+U+p[l-7]+q>>>0}let x=i,k=u,v=f,K=c,h=b,w=m,E=P,V=A;for(let l=0;l<64;l++){let U=d(h,6)^d(h,11)^d(h,25),q=h&w^~h&E,W=V+U+q+he[l]+p[l]>>>0,le=d(x,2)^d(x,13)^d(x,22),ce=x&k^x&v^k&v,fe=le+ce>>>0;V=E,E=w,w=h,h=K+W>>>0,K=v,v=k,k=x,x=W+fe>>>0}i=i+x>>>0,u=u+k>>>0,f=f+v>>>0,c=c+K>>>0,b=b+h>>>0,m=m+w>>>0,P=P+E>>>0,A=A+V>>>0}return J(i)+J(u)}function j(e){return ye(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,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[...R,n]){let o=N(e,r,s);t.set(j(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 S(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 G(e,r=Math.random){if(e.length===0)return null;if(e.length===1)return e[0].arm;let n=e[0],t=S(n.alpha,n.beta,r);for(let s=1;s<e.length;s++){let o=e[s],a=S(o.alpha,o.beta,r);a>t&&(n=o,t=a)}return n.arm}function Pe(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=G(a,s),u=i?o.get(i):void 0;return u!=null?u:N(e,r,n)}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 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 Ae(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 Y(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 Y(r)}function ke(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 ve(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 ne=5;function Re(e,r){var t,s;let n=null;for(let o of e){if(!r.includes(o.variantId))continue;let a=(t=o.pulls)!=null?t:0,i=a>0?a*o.avgReward/(a+ne):0;(!n||i>n.score)&&(n={variantId:o.variantId,score:i})}return(s=n==null?void 0:n.variantId)!=null?s:null}var g="__all__",I={exposures:0,conversions:0};function C(e){return{alpha:e.conversions+1,beta:Math.max(0,e.exposures-e.conversions)+1}}function Se(e,r,n=20){var m,P,A,p;let t=(m=e.segment)!=null?m:I,s=(P=e.global)!=null?P:I,o=C(s),a=_(C(t),o,n);if(!r)return a;let i=(A=e.persona)!=null?A:I,u=(p=e.child)!=null?p:I,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 _e(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 Ce(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 te(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 we(e,r,n){if(n.length===0)throw new Error("pickDeterministicArm requires at least one arm");let t=[...n].sort();return t[te(`${e}:${r}`)%t.length]}function Ee(e){return e>=.3?e<.7?"medium":"high":"low"}var oe=20;function se(e,r,n=oe){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 Le(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=S(o.alpha,o.beta,n)*se(o,r);a>s&&(t=o,s=a)}return t.arm}var ae=/^[a-z0-9][a-z0-9_-]{0,31}$/;function Me(e){if(typeof e!="string")return null;let r=e.trim().toLowerCase();return r&&ae.test(r)?r:null}var ie=["unknown","__all__","buyers","researchers","deal-seekers","browsers"],ue=R.map(e=>({key:e,displayName:H[e]})),Oe=64;function Ne(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:[])ie.includes(s)||r.set(s,t.key)}return r}function Ie(e,r=ue){var i,u,f;let n=Ne(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(O(o)):void 0,m=c!=null?c:b;if(m!==void 0)return{persona:m,source:"declared",confidence:1};s=o.slice(0,Oe)}let a=O(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 De(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,WEIGHTS_FALLBACK_PRIOR_PULLS,applyClusterHeuristic,broadestValueCell,candidateLayouts,canonicalArm,canonicalPersona,chooseLayout,confidenceBand,decisionPersona,fnv1a,hashLayout,marginalArmKey,normalizeDeclaredPersona,parseArm,pickDeterministicArm,pickFromWeights,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 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};
|
|
1
|
+
var re=Object.defineProperty;var j=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,K=(e,r)=>{for(var n in r||(r={}))ne.call(r,n)&&z(e,n,r[n]);if(j)for(var n of j(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"},V={buyers:"buyer",researchers:"researcher","deal-seekers":"deal_seeker",browsers:"browser",buyer:"buyer",researcher:"researcher",deal_seeker:"deal_seeker",browser:"browser"};function U(e){var n;if(e==null)return y;let r=e.trim().toLowerCase();return(n=V[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 G(e){return(e>>>0).toString(16).padStart(8,"0")}function se(e){let r=new TextEncoder().encode(e),n=r.length,o=n*8,s=(n+8>>6)+1<<6,t=new Uint8Array(s);t.set(r),t[n]=128;let a=new DataView(t.buffer);a.setUint32(s-8,Math.floor(o/4294967296),!1),a.setUint32(s-4,o>>>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 I=g(p[l-15],7)^g(p[l-15],18)^p[l-15]>>>3,D=g(p[l-2],17)^g(p[l-2],19)^p[l-2]>>>10;p[l]=p[l-16]+I+p[l-7]+D>>>0}let x=i,k=u,v=f,O=c,h=b,R=m,S=P,N=A;for(let l=0;l<64;l++){let I=g(h,6)^g(h,11)^g(h,25),D=h&R^~h&S,H=N+I+D+oe[l]+p[l]>>>0,J=g(x,2)^g(x,13)^g(x,22),Q=x&k^x&v^k&v,ee=J+Q>>>0;N=S,S=R,R=h,h=O+H>>>0,O=v,v=k,k=x,x=H+ee>>>0}i=i+x>>>0,u=u+k>>>0,f=f+v>>>0,c=c+O>>>0,b=b+h>>>0,m=m+R>>>0,P=P+S>>>0,A=A+N>>>0}return G(i)+G(u)}function Y(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 q(e,r,n){let o=ae[n];if(!o)return e;let s=o.indexOf("generic"),t=a=>{let i=o.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 t(u)-t(f)})}function F(e,r,n){let o=new Map;for(let s of[..._,n]){let t=q(e,r,s);o.set(Y(t),t)}return o}function $(e,r){if(e<1)return $(1+e,r)*Math.pow(Math.max(1e-15,r()),1/e);let n=e-1/3,o=1/Math.sqrt(9*n);for(;;){let s,t;do{let i=Math.max(1e-15,r()),u=r();s=Math.sqrt(-2*Math.log(i))*Math.cos(2*Math.PI*u),t=1+o*s}while(t<=0);t=t*t*t;let a=r();if(a<1-.0331*s*s*s*s||Math.log(a)<.5*s*s+n*(1-t+Math.log(t)))return n*t}}function C(e,r,n=Math.random){let o=$(e,n),s=$(r,n),t=o+s;return t<=0?e/(e+r):o/t}function W(e,r=Math.random){if(e.length===0)return null;if(e.length===1)return e[0].arm;let n=e[0],o=C(n.alpha,n.beta,r);for(let s=1;s<e.length;s++){let t=e[s],a=C(t.alpha,t.beta,r);a>o&&(n=t,o=a)}return n.arm}function _e(e,r,n,o,s=Math.random){var f,c;let t=F(e,r,n),a=[];for(let b of t.keys()){let m=o.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?t.get(i):void 0;return u!=null?u:q(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 o=n.indexOf("=");if(o<=0||o!==n.lastIndexOf("=")||o===n.length-1)return null;let s=n.slice(0,o);if(s in r)return null;r[s]=n.slice(o+1)}return r}function we(e,r){return`${e}=${r}`}function ie(e){var n,o,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[t,a]of Object.entries((o=e.dims)!=null?o:{}))r[t]=(s=a[0])!=null?s:"";return T(r)}function Ee(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 t=e.arms;if(t.length<2)return{ok:!1,reason:"arms requires at least 2 entries"};if(t.length>12)return{ok:!1,reason:"arms allows at most 12 entries"};if(new Set(t).size!==t.length)return{ok:!1,reason:"arms must be unique"};if(t.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(!t.includes(e.baseline))return{ok:!1,reason:"baseline must be one of the declared arms"}}return{ok:!0}}let o=Object.entries(e.dims);if(o.length<1)return{ok:!1,reason:"dims requires at least 1 dimension"};if(o.length>4)return{ok:!1,reason:"dims allows at most 4 dimensions"};let s=1;for(let[t,a]of o){if(a.length<2)return{ok:!1,reason:`dim "${t}" requires at least 2 values`};if(a.length>6)return{ok:!1,reason:`dim "${t}" allows at most 6 values`};if(new Set(a).size!==a.length)return{ok:!1,reason:`dim "${t}" 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 t=e.baseline,a=o.map(([u])=>u).sort(),i=Object.keys(t).sort();if(a.join(" ")!==i.join(" "))return{ok:!1,reason:"baseline must set every declared dim exactly once"};for(let[u,f]of o)if(!f.includes(t[u]))return{ok:!1,reason:`baseline value for dim "${u}" is not declared`}}return{ok:!0}}function Le(e,r){var n,o;return e.dims!=null?(o=(n=Z(r))!=null?n:Z(ie(e)))!=null?o:{}:r}var X=20;function w(e,r,n=20){let o=r.alpha+r.beta;if(o<=0||n<=0)return{alpha:e.alpha,beta:e.beta};let s=r.alpha/o,t=n*o/(o+n);return{alpha:e.alpha+t*s,beta:e.beta+t*(1-s)}}var ue=5;function Oe(e,r){var o,s;let n=null;for(let t of e){if(!r.includes(t.variantId))continue;let a=(o=t.pulls)!=null?o:0,i=a>0?a*t.avgReward/(a+ue):0;(!n||i>n.score)&&(n={variantId:t.variantId,score:i})}return(s=n==null?void 0:n.variantId)!=null?s:null}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 De(e,r,n=20){var m,P,A,p;let o=(m=e.segment)!=null?m:E,s=(P=e.global)!=null?P:E,t=L(s),a=w(L(o),t,n);if(!r)return a;let i=(A=e.persona)!=null?A:E,u=(p=e.child)!=null?p:E,f=w(L(i),t,n),c=(o.exposures+1)/(o.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 Ke(e){var o,s;let r=null,n=-1;for(let t of e){let a=t.segment===d,i=t.persona===d,u=a&&i?3:a||i?2:1;u>n&&(n=u,r=t)}return{valueSum:(o=r==null?void 0:r.valueSum)!=null?o:0,valueCount:(s=r==null?void 0:r.valueCount)!=null?s:0}}function Ve(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 le(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 qe(e,r,n){if(n.length===0)throw new Error("pickDeterministicArm requires at least one arm");let o=[...n].sort();return o[le(`${e}:${r}`)%o.length]}function $e(e){return e>=.3?e<.7?"medium":"high":"low"}var ce=20;function fe(e,r,n=ce){let o=e.valueCount>0?e.valueSum/e.valueCount:0;if(r<=0)return o;if(e.valueCount<=0)return r;let s=e.valueCount/(e.valueCount+n);return s*o+(1-s)*r}function ze(e,r,n=Math.random){if(e.length===0)return null;if(e.length===1)return e[0].arm;let o=null,s=-1/0;for(let t of e){let a=C(t.alpha,t.beta,n)*fe(t,r);a>s&&(o=t,s=a)}return o.arm}var me=/^[a-z0-9][a-z0-9_-]{0,31}$/;function Ye(e){if(typeof e!="string")return null;let r=e.trim().toLowerCase();return r&&me.test(r)?r:null}var pe=["unknown","__all__","buyers","researchers","deal-seekers","browsers"],be=_.map(e=>({key:e,displayName:B[e]})),ge=64;function de(e){var n;let r=new Map;for(let o of e)if(o.status!=="retired"){r.set(o.key,o.key);for(let s of(n=o.aliases)!=null?n:[])pe.includes(s)||r.set(s,o.key)}return r}function Fe(e,r=be){var i,u,f;let n=de(r),o=(i=e.inferredConfidence)!=null?i:0,s,t=(f=(u=e.declared)==null?void 0:u.trim().toLowerCase())!=null?f:"";if(t!==""){let c=n.get(t),b=c===void 0?n.get(U(t)):void 0,m=c!=null?c:b;if(m!==void 0)return{persona:m,source:"declared",confidence:1};s=t.slice(0,ge)}let a=U(e.clusterLabel);return a!==y&&n.has(a)?K({persona:n.get(a),source:"inferred",confidence:o},s!==void 0&&{unrecognizedDeclared:s}):K({persona:y,source:"none",confidence:o},s!==void 0&&{unrecognizedDeclared:s})}function We(e){var n;if(e==null)return y;let r=e.trim().toLowerCase();return r===""?y:(n=V[r])!=null?n:r}export{ae as CLUSTER_PRIORITY,be as DEFAULT_PERSONA_VOCABULARY,ce as EV_SHRINK_K,V as LEGACY_PERSONA_MAP,_ as PERSONAS,B as PERSONA_DISPLAY,me as PERSONA_KEY_RE,d as POOL_ALL,pe as RESERVED_PERSONA_KEYS,X as SHRINKAGE_M,y as UNKNOWN_PERSONA,ue as WEIGHTS_FALLBACK_PRIOR_PULLS,q as applyClusterHeuristic,Ke as broadestValueCell,F as candidateLayouts,T as canonicalArm,U as canonicalPersona,_e as chooseLayout,$e as confidenceBand,We as decisionPersona,le as fnv1a,Y as hashLayout,we as marginalArmKey,Ye as normalizeDeclaredPersona,Z as parseArm,qe as pickDeterministicArm,Oe as pickFromWeights,De as pooledPosterior,L as posteriorOfCounts,Fe as resolvePersona,W as sampleArm,ze as sampleArmEv,C as sampleBeta,fe as shrunkAvgValue,w as shrunkPosterior,ie as slotBaselineArm,Le as slotResultFor,Ee as validateSlotDecl,Ve as weightCellsFor};
|