@sentientui/policy 0.11.0 → 0.12.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 CHANGED
@@ -120,6 +120,32 @@ declare function candidateLayouts(sections: string[], sectionTypes: Map<string,
120
120
  */
121
121
  declare function hashLayout(order: string[]): string;
122
122
 
123
+ /** Learned Beta(alpha, beta) posterior for one arm. */
124
+ type ArmPosterior = {
125
+ arm: string;
126
+ alpha: number;
127
+ beta: number;
128
+ };
129
+ /**
130
+ * One draw from Beta(alpha, beta). Moved verbatim from apps/api/src/domain/bandit.ts.
131
+ *
132
+ * @param rand Uniform [0,1) source. Defaults to `Math.random`, which is
133
+ * NON-DETERMINISTIC. Pass a seeded PRNG when you need reproducible output
134
+ * (tests, replayable decisions, snapshotting) — otherwise results vary per call.
135
+ */
136
+ declare function sampleBeta(alpha: number, beta: number, rand?: () => number): number;
137
+ /**
138
+ * Thompson Sampling selection: samples Beta(alpha, beta) per arm and returns
139
+ * the argmax arm id, or null when no arms are given. Uncertain arms get
140
+ * explored; confident winners get exploited — same semantics as the legacy
141
+ * chooseVariant, generalized to arbitrary arm strings.
142
+ *
143
+ * @param rand Uniform [0,1) source. Defaults to `Math.random`, which is
144
+ * NON-DETERMINISTIC. Pass a seeded PRNG for reproducible selection (tests,
145
+ * replayable assignments) — otherwise the chosen arm varies per call.
146
+ */
147
+ declare function sampleArm(arms: ArmPosterior[], rand?: () => number): string | null;
148
+
123
149
  /** Learned Beta(alpha,beta) posterior for one candidate layout, keyed by hash. */
124
150
  type LearnedLayout = {
125
151
  layoutHash: string;
@@ -149,6 +175,28 @@ type LearnedLayout = {
149
175
  * pinned in place across every candidate; see `orderByArchetype`.
150
176
  */
151
177
  declare function chooseLayout(sections: string[], sectionTypes: Map<string, string>, _persona: string, learned: Map<string, LearnedLayout>, rand?: () => number, sectionRoles?: Map<string, SectionRole>): string[];
178
+ /** What `chooseLayoutDetailed` drew, and what it drew it from. */
179
+ type LayoutChoice = {
180
+ /** The served ordering (the authored order when nothing could be chosen). */
181
+ order: string[];
182
+ /** Hash of `order` — the arm id in `layout_weights` / `candidate_layouts`. */
183
+ chosenHash: string;
184
+ /** Every candidate hash the draw ran over, in candidate order. */
185
+ candidates: string[];
186
+ /** The posteriors the draw ran over, parallel to `candidates`. Provenance
187
+ * (migration 157) is computed from THESE, in the same call, because they
188
+ * move on every close-out pass and cannot be recovered afterwards. */
189
+ arms: ArmPosterior[];
190
+ };
191
+ /**
192
+ * `chooseLayout` plus the draw's provenance. Byte-identical selection — this
193
+ * is the same function with its inputs returned alongside the output, so the
194
+ * propensity a caller computes from `arms` describes the draw that produced
195
+ * `order` and nothing else. The propensity itself is not computed here: the
196
+ * deterministic quadrature lives in the API (`lib/beta.ts`
197
+ * `armSelectionProbabilities`), where the slot path already uses it.
198
+ */
199
+ declare function chooseLayoutDetailed(sections: string[], sectionTypes: Map<string, string>, _persona: string, learned: Map<string, LearnedLayout>, rand?: () => number, sectionRoles?: Map<string, SectionRole>): LayoutChoice;
152
200
 
153
201
  /**
154
202
  * Factored layout value model (spec 2026-09-04 §3a).
@@ -328,32 +376,6 @@ declare function factorCellsForTrial(arm: string, ctx: SlotFactorContext, person
328
376
  * parameters on a tail that prod does not currently have. */
329
377
  declare function visitLevel(visitCount: number | null | undefined): string | null;
330
378
 
331
- /** Learned Beta(alpha, beta) posterior for one arm. */
332
- type ArmPosterior = {
333
- arm: string;
334
- alpha: number;
335
- beta: number;
336
- };
337
- /**
338
- * One draw from Beta(alpha, beta). Moved verbatim from apps/api/src/domain/bandit.ts.
339
- *
340
- * @param rand Uniform [0,1) source. Defaults to `Math.random`, which is
341
- * NON-DETERMINISTIC. Pass a seeded PRNG when you need reproducible output
342
- * (tests, replayable decisions, snapshotting) — otherwise results vary per call.
343
- */
344
- declare function sampleBeta(alpha: number, beta: number, rand?: () => number): number;
345
- /**
346
- * Thompson Sampling selection: samples Beta(alpha, beta) per arm and returns
347
- * the argmax arm id, or null when no arms are given. Uncertain arms get
348
- * explored; confident winners get exploited — same semantics as the legacy
349
- * chooseVariant, generalized to arbitrary arm strings.
350
- *
351
- * @param rand Uniform [0,1) source. Defaults to `Math.random`, which is
352
- * NON-DETERMINISTIC. Pass a seeded PRNG for reproducible selection (tests,
353
- * replayable assignments) — otherwise the chosen arm varies per call.
354
- */
355
- declare function sampleArm(arms: ArmPosterior[], rand?: () => number): string | null;
356
-
357
379
  /** A slot declaration as sent on /v1/decide — exactly one of arms|dims. */
358
380
  type SlotDecl = {
359
381
  id: string;
@@ -744,4 +766,4 @@ declare function resolvePersona(input: {
744
766
  */
745
767
  declare function decisionPersona(label: string | null | undefined): string;
746
768
 
747
- export { type ArmPosterior, DEFAULT_PERSONA_VOCABULARY, EV_SHRINK_K, type EvArm, type FactoredSlotChoice, GLOBAL_FACTOR_LEVEL, GLOBAL_FACTOR_PERSONA, LAYOUT_ARCHETYPES, LAYOUT_ARCHETYPE_NAMES, LAYOUT_FACTOR_BUCKETS, type LayoutArchetype, type LayoutFactorCell, type LearnedLayout, PERSONA_KEY_RE, POOL_ALL, type PersonaResolution, type PersonaVocabularyMember, type PoolCells, type PoolCounts, RESERVED_PERSONA_KEYS, SHRINKAGE_M, SLOT_FACTORS, type SlotDecl, type SlotFactor, type SlotFactorCell, type SlotFactorContext, type SlotResult, UNKNOWN_PERSONA, UNKNOWN_PERSONA_DISPLAY, type ValueCell, type ValueCellRow, WEIGHTS_FALLBACK_PRIOR_PULLS, type WeightsFallbackArm, applyClusterHeuristic, broadestValueCell, candidateLayouts, canonicalArm, canonicalPersona, chooseLayout, chooseLayoutFactored, chooseSlotArmFactored, confidenceBand, decisionPersona, factorCellsForOrder, factorCellsForTrial, factorLevelsFor, fnv1a, hashLayout, layoutBucketOf, marginalArmKey, normalizeDeclaredPersona, orderByArchetype, parseArm, pickDeterministicArm, pickFromWeights, pooledPosterior, posteriorOfCounts, previewOrderForPersona, resolvePersona, sampleArm, sampleArmEv, sampleBeta, shrunkAvgValue, shrunkPosterior, slotBaselineArm, slotResultFor, validateSlotDecl, visitLevel, weightCellsFor };
769
+ export { type ArmPosterior, DEFAULT_PERSONA_VOCABULARY, EV_SHRINK_K, type EvArm, type FactoredSlotChoice, GLOBAL_FACTOR_LEVEL, GLOBAL_FACTOR_PERSONA, LAYOUT_ARCHETYPES, LAYOUT_ARCHETYPE_NAMES, LAYOUT_FACTOR_BUCKETS, type LayoutArchetype, type LayoutChoice, type LayoutFactorCell, type LearnedLayout, PERSONA_KEY_RE, POOL_ALL, type PersonaResolution, type PersonaVocabularyMember, type PoolCells, type PoolCounts, RESERVED_PERSONA_KEYS, SHRINKAGE_M, SLOT_FACTORS, type SlotDecl, type SlotFactor, type SlotFactorCell, type SlotFactorContext, type SlotResult, UNKNOWN_PERSONA, UNKNOWN_PERSONA_DISPLAY, type ValueCell, type ValueCellRow, WEIGHTS_FALLBACK_PRIOR_PULLS, type WeightsFallbackArm, applyClusterHeuristic, broadestValueCell, candidateLayouts, canonicalArm, canonicalPersona, chooseLayout, chooseLayoutDetailed, chooseLayoutFactored, chooseSlotArmFactored, confidenceBand, decisionPersona, factorCellsForOrder, factorCellsForTrial, factorLevelsFor, fnv1a, hashLayout, layoutBucketOf, marginalArmKey, normalizeDeclaredPersona, orderByArchetype, parseArm, pickDeterministicArm, pickFromWeights, pooledPosterior, posteriorOfCounts, previewOrderForPersona, resolvePersona, sampleArm, sampleArmEv, sampleBeta, shrunkAvgValue, shrunkPosterior, slotBaselineArm, slotResultFor, validateSlotDecl, visitLevel, weightCellsFor };
package/dist/index.d.ts CHANGED
@@ -120,6 +120,32 @@ declare function candidateLayouts(sections: string[], sectionTypes: Map<string,
120
120
  */
121
121
  declare function hashLayout(order: string[]): string;
122
122
 
123
+ /** Learned Beta(alpha, beta) posterior for one arm. */
124
+ type ArmPosterior = {
125
+ arm: string;
126
+ alpha: number;
127
+ beta: number;
128
+ };
129
+ /**
130
+ * One draw from Beta(alpha, beta). Moved verbatim from apps/api/src/domain/bandit.ts.
131
+ *
132
+ * @param rand Uniform [0,1) source. Defaults to `Math.random`, which is
133
+ * NON-DETERMINISTIC. Pass a seeded PRNG when you need reproducible output
134
+ * (tests, replayable decisions, snapshotting) — otherwise results vary per call.
135
+ */
136
+ declare function sampleBeta(alpha: number, beta: number, rand?: () => number): number;
137
+ /**
138
+ * Thompson Sampling selection: samples Beta(alpha, beta) per arm and returns
139
+ * the argmax arm id, or null when no arms are given. Uncertain arms get
140
+ * explored; confident winners get exploited — same semantics as the legacy
141
+ * chooseVariant, generalized to arbitrary arm strings.
142
+ *
143
+ * @param rand Uniform [0,1) source. Defaults to `Math.random`, which is
144
+ * NON-DETERMINISTIC. Pass a seeded PRNG for reproducible selection (tests,
145
+ * replayable assignments) — otherwise the chosen arm varies per call.
146
+ */
147
+ declare function sampleArm(arms: ArmPosterior[], rand?: () => number): string | null;
148
+
123
149
  /** Learned Beta(alpha,beta) posterior for one candidate layout, keyed by hash. */
124
150
  type LearnedLayout = {
125
151
  layoutHash: string;
@@ -149,6 +175,28 @@ type LearnedLayout = {
149
175
  * pinned in place across every candidate; see `orderByArchetype`.
150
176
  */
151
177
  declare function chooseLayout(sections: string[], sectionTypes: Map<string, string>, _persona: string, learned: Map<string, LearnedLayout>, rand?: () => number, sectionRoles?: Map<string, SectionRole>): string[];
178
+ /** What `chooseLayoutDetailed` drew, and what it drew it from. */
179
+ type LayoutChoice = {
180
+ /** The served ordering (the authored order when nothing could be chosen). */
181
+ order: string[];
182
+ /** Hash of `order` — the arm id in `layout_weights` / `candidate_layouts`. */
183
+ chosenHash: string;
184
+ /** Every candidate hash the draw ran over, in candidate order. */
185
+ candidates: string[];
186
+ /** The posteriors the draw ran over, parallel to `candidates`. Provenance
187
+ * (migration 157) is computed from THESE, in the same call, because they
188
+ * move on every close-out pass and cannot be recovered afterwards. */
189
+ arms: ArmPosterior[];
190
+ };
191
+ /**
192
+ * `chooseLayout` plus the draw's provenance. Byte-identical selection — this
193
+ * is the same function with its inputs returned alongside the output, so the
194
+ * propensity a caller computes from `arms` describes the draw that produced
195
+ * `order` and nothing else. The propensity itself is not computed here: the
196
+ * deterministic quadrature lives in the API (`lib/beta.ts`
197
+ * `armSelectionProbabilities`), where the slot path already uses it.
198
+ */
199
+ declare function chooseLayoutDetailed(sections: string[], sectionTypes: Map<string, string>, _persona: string, learned: Map<string, LearnedLayout>, rand?: () => number, sectionRoles?: Map<string, SectionRole>): LayoutChoice;
152
200
 
153
201
  /**
154
202
  * Factored layout value model (spec 2026-09-04 §3a).
@@ -328,32 +376,6 @@ declare function factorCellsForTrial(arm: string, ctx: SlotFactorContext, person
328
376
  * parameters on a tail that prod does not currently have. */
329
377
  declare function visitLevel(visitCount: number | null | undefined): string | null;
330
378
 
331
- /** Learned Beta(alpha, beta) posterior for one arm. */
332
- type ArmPosterior = {
333
- arm: string;
334
- alpha: number;
335
- beta: number;
336
- };
337
- /**
338
- * One draw from Beta(alpha, beta). Moved verbatim from apps/api/src/domain/bandit.ts.
339
- *
340
- * @param rand Uniform [0,1) source. Defaults to `Math.random`, which is
341
- * NON-DETERMINISTIC. Pass a seeded PRNG when you need reproducible output
342
- * (tests, replayable decisions, snapshotting) — otherwise results vary per call.
343
- */
344
- declare function sampleBeta(alpha: number, beta: number, rand?: () => number): number;
345
- /**
346
- * Thompson Sampling selection: samples Beta(alpha, beta) per arm and returns
347
- * the argmax arm id, or null when no arms are given. Uncertain arms get
348
- * explored; confident winners get exploited — same semantics as the legacy
349
- * chooseVariant, generalized to arbitrary arm strings.
350
- *
351
- * @param rand Uniform [0,1) source. Defaults to `Math.random`, which is
352
- * NON-DETERMINISTIC. Pass a seeded PRNG for reproducible selection (tests,
353
- * replayable assignments) — otherwise the chosen arm varies per call.
354
- */
355
- declare function sampleArm(arms: ArmPosterior[], rand?: () => number): string | null;
356
-
357
379
  /** A slot declaration as sent on /v1/decide — exactly one of arms|dims. */
358
380
  type SlotDecl = {
359
381
  id: string;
@@ -744,4 +766,4 @@ declare function resolvePersona(input: {
744
766
  */
745
767
  declare function decisionPersona(label: string | null | undefined): string;
746
768
 
747
- export { type ArmPosterior, DEFAULT_PERSONA_VOCABULARY, EV_SHRINK_K, type EvArm, type FactoredSlotChoice, GLOBAL_FACTOR_LEVEL, GLOBAL_FACTOR_PERSONA, LAYOUT_ARCHETYPES, LAYOUT_ARCHETYPE_NAMES, LAYOUT_FACTOR_BUCKETS, type LayoutArchetype, type LayoutFactorCell, type LearnedLayout, PERSONA_KEY_RE, POOL_ALL, type PersonaResolution, type PersonaVocabularyMember, type PoolCells, type PoolCounts, RESERVED_PERSONA_KEYS, SHRINKAGE_M, SLOT_FACTORS, type SlotDecl, type SlotFactor, type SlotFactorCell, type SlotFactorContext, type SlotResult, UNKNOWN_PERSONA, UNKNOWN_PERSONA_DISPLAY, type ValueCell, type ValueCellRow, WEIGHTS_FALLBACK_PRIOR_PULLS, type WeightsFallbackArm, applyClusterHeuristic, broadestValueCell, candidateLayouts, canonicalArm, canonicalPersona, chooseLayout, chooseLayoutFactored, chooseSlotArmFactored, confidenceBand, decisionPersona, factorCellsForOrder, factorCellsForTrial, factorLevelsFor, fnv1a, hashLayout, layoutBucketOf, marginalArmKey, normalizeDeclaredPersona, orderByArchetype, parseArm, pickDeterministicArm, pickFromWeights, pooledPosterior, posteriorOfCounts, previewOrderForPersona, resolvePersona, sampleArm, sampleArmEv, sampleBeta, shrunkAvgValue, shrunkPosterior, slotBaselineArm, slotResultFor, validateSlotDecl, visitLevel, weightCellsFor };
769
+ export { type ArmPosterior, DEFAULT_PERSONA_VOCABULARY, EV_SHRINK_K, type EvArm, type FactoredSlotChoice, GLOBAL_FACTOR_LEVEL, GLOBAL_FACTOR_PERSONA, LAYOUT_ARCHETYPES, LAYOUT_ARCHETYPE_NAMES, LAYOUT_FACTOR_BUCKETS, type LayoutArchetype, type LayoutChoice, type LayoutFactorCell, type LearnedLayout, PERSONA_KEY_RE, POOL_ALL, type PersonaResolution, type PersonaVocabularyMember, type PoolCells, type PoolCounts, RESERVED_PERSONA_KEYS, SHRINKAGE_M, SLOT_FACTORS, type SlotDecl, type SlotFactor, type SlotFactorCell, type SlotFactorContext, type SlotResult, UNKNOWN_PERSONA, UNKNOWN_PERSONA_DISPLAY, type ValueCell, type ValueCellRow, WEIGHTS_FALLBACK_PRIOR_PULLS, type WeightsFallbackArm, applyClusterHeuristic, broadestValueCell, candidateLayouts, canonicalArm, canonicalPersona, chooseLayout, chooseLayoutDetailed, chooseLayoutFactored, chooseSlotArmFactored, confidenceBand, decisionPersona, factorCellsForOrder, factorCellsForTrial, factorLevelsFor, fnv1a, hashLayout, layoutBucketOf, marginalArmKey, normalizeDeclaredPersona, orderByArchetype, parseArm, pickDeterministicArm, pickFromWeights, pooledPosterior, posteriorOfCounts, previewOrderForPersona, resolvePersona, sampleArm, sampleArmEv, sampleBeta, shrunkAvgValue, shrunkPosterior, slotBaselineArm, slotResultFor, validateSlotDecl, visitLevel, weightCellsFor };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var K=Object.defineProperty;var ye=Object.getOwnPropertyDescriptor;var ve=Object.getOwnPropertyNames,J=Object.getOwnPropertySymbols;var ee=Object.prototype.hasOwnProperty,Ae=Object.prototype.propertyIsEnumerable;var Q=(e,r,t)=>r in e?K(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,$=(e,r)=>{for(var t in r||(r={}))ee.call(r,t)&&Q(e,t,r[t]);if(J)for(var t of J(r))Ae.call(r,t)&&Q(e,t,r[t]);return e};var Se=(e,r)=>{for(var t in r)K(e,t,{get:r[t],enumerable:!0})},Ce=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of ve(r))!ee.call(e,o)&&o!==t&&K(e,o,{get:()=>r[o],enumerable:!(n=ye(r,o))||n.enumerable});return e};var _e=e=>Ce(K({},"__esModule",{value:!0}),e);var Xe={};Se(Xe,{DEFAULT_PERSONA_VOCABULARY:()=>be,EV_SHRINK_K:()=>ue,GLOBAL_FACTOR_LEVEL:()=>U,GLOBAL_FACTOR_PERSONA:()=>ae,LAYOUT_ARCHETYPES:()=>te,LAYOUT_ARCHETYPE_NAMES:()=>T,LAYOUT_FACTOR_BUCKETS:()=>Y,PERSONA_KEY_RE:()=>fe,POOL_ALL:()=>_,RESERVED_PERSONA_KEYS:()=>me,SHRINKAGE_M:()=>oe,SLOT_FACTORS:()=>Ie,UNKNOWN_PERSONA:()=>M,UNKNOWN_PERSONA_DISPLAY:()=>ke,WEIGHTS_FALLBACK_PRIOR_PULLS:()=>se,applyClusterHeuristic:()=>Re,broadestValueCell:()=>Fe,candidateLayouts:()=>N,canonicalArm:()=>W,canonicalPersona:()=>ge,chooseLayout:()=>we,chooseLayoutFactored:()=>Ke,chooseSlotArmFactored:()=>Te,confidenceBand:()=>Ye,decisionPersona:()=>Ze,factorCellsForOrder:()=>Ue,factorCellsForTrial:()=>Ve,factorLevelsFor:()=>G,fnv1a:()=>le,hashLayout:()=>I,layoutBucketOf:()=>j,marginalArmKey:()=>De,normalizeDeclaredPersona:()=>pe,orderByArchetype:()=>D,parseArm:()=>Z,pickDeterministicArm:()=>qe,pickFromWeights:()=>Oe,pooledPosterior:()=>Ee,posteriorOfCounts:()=>S,previewOrderForPersona:()=>ne,resolvePersona:()=>We,sampleArm:()=>H,sampleArmEv:()=>je,sampleBeta:()=>R,shrunkAvgValue:()=>ce,shrunkPosterior:()=>C,slotBaselineArm:()=>ie,slotResultFor:()=>He,validateSlotDecl:()=>Be,visitLevel:()=>$e,weightCellsFor:()=>Ne});module.exports=_e(Xe);var M="unknown",ke="Unknown";var Le=[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 P(e,r){return e>>>r|e<<32-r}function re(e){return(e>>>0).toString(16).padStart(8,"0")}function Pe(e){let r=new TextEncoder().encode(e),t=r.length,n=t*8,o=(t+8>>6)+1<<6,s=new Uint8Array(o);s.set(r),s[t]=128;let a=new DataView(s.buffer);a.setUint32(o-8,Math.floor(n/4294967296),!1),a.setUint32(o-4,n>>>0,!1);let l=1779033703,u=3144134277,f=1013904242,m=2773480762,y=1359893119,d=2600822924,b=528734635,c=1541459225,p=new Uint32Array(64);for(let A=0;A<o;A+=64){for(let g=0;g<16;g++)p[g]=a.getUint32(A+g*4,!1);for(let g=16;g<64;g++){let E=P(p[g-15],7)^P(p[g-15],18)^p[g-15]>>>3,F=P(p[g-2],17)^P(p[g-2],19)^p[g-2]>>>10;p[g]=p[g-16]+E+p[g-7]+F>>>0}let i=l,v=u,x=f,k=m,h=y,L=d,w=b,O=c;for(let g=0;g<64;g++){let E=P(h,6)^P(h,11)^P(h,25),F=h&L^~h&w,X=O+E+F+Le[g]+p[g]>>>0,de=P(i,2)^P(i,13)^P(i,22),xe=i&v^i&x^v&x,he=de+xe>>>0;O=w,w=L,L=h,h=k+X>>>0,k=x,x=v,v=i,i=X+he>>>0}l=l+i>>>0,u=u+v>>>0,f=f+x>>>0,m=m+k>>>0,y=y+h>>>0,d=d+L>>>0,b=b+w>>>0,c=c+O>>>0}return re(l)+re(u)}function I(e){return Pe(e.join("|"))}var te={conversion_led:["pricing","cta","hero","comparison","social_proof","trust","features","faq","navigation","generic"],evidence_led:["features","comparison","faq","hero","trust","social_proof","pricing","cta","navigation","generic"],price_led:["pricing","comparison","social_proof","trust","cta","hero","features","faq","navigation","generic"],discovery_led:["hero","features","social_proof","pricing","cta","trust","faq","comparison","navigation","generic"]},T=["conversion_led","evidence_led","price_led","discovery_led"];function D(e,r,t,n){let o=te[t];if(!o)return e;let s=o.indexOf("generic"),a=f=>{let m=o.indexOf(f);return m===-1?s:m},l=n?e.filter(f=>n.get(f)!=="structural"):[...e];if(l.sort((f,m)=>{var b,c;let y=(b=r.get(f))!=null?b:"generic",d=(c=r.get(m))!=null?c:"generic";return a(y)-a(d)}),!n)return l;let u=0;return e.map(f=>n.get(f)==="structural"?f:l[u++])}function Me(e){let r=2166136261;for(let t=0;t<e.length;t++)r^=e.charCodeAt(t),r=Math.imul(r,16777619)>>>0;return r>>>0}function ne(e,r,t,n){if(!t||t==="unknown")return e;let o=T[Me(t)%T.length];return D(e,r,o,n)}var Re=ne;function N(e,r,t){let n=new Map;n.set(I(e),[...e]);for(let o of T){let s=D(e,r,o,t),a=I(s);n.has(a)||n.set(a,s)}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 o,s;do{let l=Math.max(1e-15,r()),u=r();o=Math.sqrt(-2*Math.log(l))*Math.cos(2*Math.PI*u),s=1+n*o}while(s<=0);s=s*s*s;let a=r();if(a<1-.0331*o*o*o*o||Math.log(a)<.5*o*o+t*(1-s+Math.log(s)))return t*s}}function R(e,r,t=Math.random){let n=B(e,t),o=B(r,t),s=n+o;return s<=0?e/(e+r):n/s}function H(e,r=Math.random){if(e.length===0)return null;if(e.length===1)return e[0].arm;let t=e[0],n=R(t.alpha,t.beta,r);for(let o=1;o<e.length;o++){let s=e[o],a=R(s.alpha,s.beta,r);a>n&&(t=s,n=a)}return t.arm}function we(e,r,t,n,o=Math.random,s){var m,y;let a=N(e,r,s),l=[];for(let d of a.keys()){let b=n.get(d);l.push({arm:d,alpha:(m=b==null?void 0:b.alpha)!=null?m:1,beta:(y=b==null?void 0:b.beta)!=null?y:1})}let u=H(l,o),f=u?a.get(u):void 0;return f!=null?f:e}var oe=20;function C(e,r,t=20){let n=r.alpha+r.beta;if(n<=0||t<=0)return{alpha:e.alpha,beta:e.beta};let o=r.alpha/n,s=t*n/(n+t);return{alpha:e.alpha+s*o,beta:e.beta+s*(1-o)}}var se=5;function Oe(e,r){var n,o;let t=null;for(let s of e){if(!r.includes(s.variantId))continue;let a=(n=s.pulls)!=null?n:0,l=a>0?a*s.avgReward/(a+se):0;(!t||l>t.score)&&(t={variantId:s.variantId,score:l})}return(o=t==null?void 0:t.variantId)!=null?o:null}var _="__all__",V={exposures:0,conversions:0};function S(e){return{alpha:e.conversions+1,beta:Math.max(0,e.exposures-e.conversions)+1}}function Ee(e,r,t=20){var d,b,c,p;let n=(d=e.segment)!=null?d:V,o=(b=e.global)!=null?b:V,s=S(o),a=C(S(n),s,t);if(!r)return a;let l=(c=e.persona)!=null?c:V,u=(p=e.child)!=null?p:V,f=C(S(l),s,t),m=(n.exposures+1)/(n.exposures+l.exposures+2),y={alpha:m*a.alpha+(1-m)*f.alpha,beta:m*a.beta+(1-m)*f.beta};return C(S(u),y,t)}function Fe(e){var n,o;let r=null,t=-1;for(let s of e){let a=s.segment===_,l=s.persona===_,u=a&&l?3:a||l?2:1;u>t&&(t=u,r=s)}return{valueSum:(n=r==null?void 0:r.valueSum)!=null?n:0,valueCount:(o=r==null?void 0:r.valueCount)!=null?o:0}}function Ne(e,r){return r==="unknown"||r===_||r===""?[{segment:e,persona:_},{segment:_,persona:_}]:[{segment:e,persona:r},{segment:e,persona:_},{segment:_,persona:r},{segment:_,persona:_}]}var Y=4,ae="__global__";function j(e,r){return r<=0?0:Math.min(Y-1,Math.floor(e*Y/r))}function Ue(e,r){return e.map((t,n)=>{var o;return{parent:(o=r.get(t))!=null?o:"generic",bucket:j(n,e.length)}})}var q=(e,r)=>`${e}#${r}`;function Ke(e,r,t,n,o=Math.random,s){var A;let a=N(e,r,s),l=new Map,u=new Map,f=0,m=0;for(let i of n)i.persona===ae?(l.set(q(i.parent,i.bucket),i),f+=i.exposures,m+=i.conversions):i.persona===t&&u.set(q(i.parent,i.bucket),i);let y=S({exposures:f,conversions:m}),d=new Map,b=(i,v)=>{var E,F;let x=q(i,v),k=d.get(x);if(k!==void 0)return k;let h=l.get(x),L=C(S({exposures:(E=h==null?void 0:h.exposures)!=null?E:0,conversions:(F=h==null?void 0:h.conversions)!=null?F:0}),y),w=u.get(x),O=w?C(S({exposures:w.exposures,conversions:w.conversions}),L):L,g=R(O.alpha,O.beta,o);return d.set(x,g),g},c=null,p=-1/0;for(let i of a.values()){let v=0;for(let x=0;x<i.length;x++)v+=b((A=r.get(i[x]))!=null?A:"generic",j(x,i.length));v>p&&(p=v,c=i)}return c!=null?c:e}var U="__global__",Ie=["device","source","persona","visit"];function G(e){let r=[];return e.device&&r.push({factor:"device",level:e.device}),e.source&&r.push({factor:"source",level:e.source}),e.persona&&e.persona!==M&&r.push({factor:"persona",level:e.persona}),e.visit&&r.push({factor:"visit",level:e.visit}),r}var z=(e,r,t)=>`${e}\0${r}\0${t}`;function Te(e,r,t,n=Math.random){if(e.length===0)return null;if(e.length===1)return{arm:e[0],factorsUsed:0};let o=new Map,s=0,a=0;for(let c of t)o.set(z(c.arm,c.factor,c.level),c),c.level===U&&(s+=c.exposures,a+=c.conversions);let l=S({exposures:s,conversions:a}),u=G(r),f=new Map,m=c=>{var A,i;let p=o.get(z(c,"global",U));return C(S({exposures:(A=p==null?void 0:p.exposures)!=null?A:0,conversions:(i=p==null?void 0:p.conversions)!=null?i:0}),l)},y=(c,p,A)=>{let i=z(c,p,A),v=f.get(i);if(v!==void 0)return v;let x=m(c),k=o.get(i),h=k?C(S({exposures:k.exposures,conversions:k.conversions}),x):x,L=R(h.alpha,h.beta,n);return f.set(i,L),L},d=null,b=-1/0;for(let c of e){let p=u.length===0?y(c,"global",U):0;for(let{factor:A,level:i}of u)p+=y(c,A,i);p>b&&(b=p,d=c)}return d===null?null:{arm:d,factorsUsed:u.length}}function Ve(e,r,t){let n=Number.isFinite(t)?Math.max(0,Math.min(1,t)):0,o=[{arm:e,factor:"global",level:U,weight:1}];for(let{factor:s,level:a}of G(r))o.push({arm:e,factor:s,level:a,weight:s==="persona"?n:1});return o}function $e(e){return e==null||!Number.isFinite(e)||e<1?null:e>1?"returning":"new"}function W(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 o=t.slice(0,n);if(o in r)return null;r[o]=t.slice(n+1)}return r}function De(e,r){return`${e}=${r}`}function ie(e){var t,n,o;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 W(e.baseline);if(typeof e.baseline=="string")return e.baseline;let r={};for(let[s,a]of Object.entries((n=e.dims)!=null?n:{}))r[s]=(o=a[0])!=null?o:"";return W(r)}function Be(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 s=e.arms;if(s.length<2)return{ok:!1,reason:"arms requires at least 2 entries"};if(s.length>12)return{ok:!1,reason:"arms allows at most 12 entries"};if(new Set(s).size!==s.length)return{ok:!1,reason:"arms must be unique"};if(s.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(!s.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 o=1;for(let[s,a]of n){if(a.length<2)return{ok:!1,reason:`dim "${s}" requires at least 2 values`};if(a.length>6)return{ok:!1,reason:`dim "${s}" allows at most 6 values`};if(new Set(a).size!==a.length)return{ok:!1,reason:`dim "${s}" has duplicate values`};o*=a.length}if(o>64)return{ok:!1,reason:`declared space of ${o} 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 s=e.baseline,a=n.map(([u])=>u).sort(),l=Object.keys(s).sort();if(a.join(" ")!==l.join(" "))return{ok:!1,reason:"baseline must set every declared dim exactly once"};for(let[u,f]of n)if(!f.includes(s[u]))return{ok:!1,reason:`baseline value for dim "${u}" is not declared`}}return{ok:!0}}function He(e,r){var t,n;return e.dims!=null?(n=(t=Z(r))!=null?t:Z(ie(e)))!=null?n:{}:r}function le(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[le(`${e}:${r}`)%n.length]}function Ye(e){return e>=.3?e<.7?"medium":"high":"low"}var ue=20;function ce(e,r,t=ue){let n=e.valueCount>0?e.valueSum/e.valueCount:0;if(r<=0)return n;if(e.valueCount<=0)return r;let o=e.valueCount/(e.valueCount+t);return o*n+(1-o)*r}function je(e,r,t=Math.random){if(e.length===0)return null;if(e.length===1)return e[0].arm;let n=null,o=-1/0;for(let s of e){let a=R(s.alpha,s.beta,t)*ce(s,r);a>o&&(n=s,o=a)}return n.arm}var fe=/^[a-z0-9][a-z0-9_-]{0,31}$/;function pe(e){if(typeof e!="string")return null;let r=e.trim().toLowerCase();return r&&fe.test(r)?r:null}var me=["unknown","__all__"];function ge(e){var r;return(r=pe(e))!=null?r:M}var be=[],ze=64;function Ge(e){var t;let r=new Map;for(let n of e)if(n.status!=="retired"){r.set(n.key,n.key);for(let o of(t=n.aliases)!=null?t:[])me.includes(o)||r.set(o,n.key)}return r}function We(e,r=be){var l,u,f;let t=Ge(r),n=(l=e.inferredConfidence)!=null?l:0,o,s=(f=(u=e.declared)==null?void 0:u.trim().toLowerCase())!=null?f:"";if(s!==""){let m=t.get(s);if(m!==void 0)return{persona:m,source:"declared",confidence:1};o=s.slice(0,ze)}let a=ge(e.clusterLabel);return a!==M&&t.has(a)?$({persona:t.get(a),source:"inferred",confidence:n},o!==void 0&&{unrecognizedDeclared:o}):$({persona:M,source:"none",confidence:n},o!==void 0&&{unrecognizedDeclared:o})}function Ze(e){if(e==null)return M;let r=e.trim().toLowerCase();return r===""?M:r}0&&(module.exports={DEFAULT_PERSONA_VOCABULARY,EV_SHRINK_K,GLOBAL_FACTOR_LEVEL,GLOBAL_FACTOR_PERSONA,LAYOUT_ARCHETYPES,LAYOUT_ARCHETYPE_NAMES,LAYOUT_FACTOR_BUCKETS,PERSONA_KEY_RE,POOL_ALL,RESERVED_PERSONA_KEYS,SHRINKAGE_M,SLOT_FACTORS,UNKNOWN_PERSONA,UNKNOWN_PERSONA_DISPLAY,WEIGHTS_FALLBACK_PRIOR_PULLS,applyClusterHeuristic,broadestValueCell,candidateLayouts,canonicalArm,canonicalPersona,chooseLayout,chooseLayoutFactored,chooseSlotArmFactored,confidenceBand,decisionPersona,factorCellsForOrder,factorCellsForTrial,factorLevelsFor,fnv1a,hashLayout,layoutBucketOf,marginalArmKey,normalizeDeclaredPersona,orderByArchetype,parseArm,pickDeterministicArm,pickFromWeights,pooledPosterior,posteriorOfCounts,previewOrderForPersona,resolvePersona,sampleArm,sampleArmEv,sampleBeta,shrunkAvgValue,shrunkPosterior,slotBaselineArm,slotResultFor,validateSlotDecl,visitLevel,weightCellsFor});
1
+ "use strict";var I=Object.defineProperty;var ve=Object.getOwnPropertyDescriptor;var Ae=Object.getOwnPropertyNames,J=Object.getOwnPropertySymbols;var ee=Object.prototype.hasOwnProperty,Se=Object.prototype.propertyIsEnumerable;var Q=(e,r,t)=>r in e?I(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,V=(e,r)=>{for(var t in r||(r={}))ee.call(r,t)&&Q(e,t,r[t]);if(J)for(var t of J(r))Se.call(r,t)&&Q(e,t,r[t]);return e};var Ce=(e,r)=>{for(var t in r)I(e,t,{get:r[t],enumerable:!0})},_e=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of Ae(r))!ee.call(e,o)&&o!==t&&I(e,o,{get:()=>r[o],enumerable:!(n=ve(r,o))||n.enumerable});return e};var ke=e=>_e(I({},"__esModule",{value:!0}),e);var Je={};Ce(Je,{DEFAULT_PERSONA_VOCABULARY:()=>be,EV_SHRINK_K:()=>ce,GLOBAL_FACTOR_LEVEL:()=>K,GLOBAL_FACTOR_PERSONA:()=>ie,LAYOUT_ARCHETYPES:()=>te,LAYOUT_ARCHETYPE_NAMES:()=>D,LAYOUT_FACTOR_BUCKETS:()=>Y,PERSONA_KEY_RE:()=>pe,POOL_ALL:()=>_,RESERVED_PERSONA_KEYS:()=>ge,SHRINKAGE_M:()=>se,SLOT_FACTORS:()=>De,UNKNOWN_PERSONA:()=>P,UNKNOWN_PERSONA_DISPLAY:()=>Le,WEIGHTS_FALLBACK_PRIOR_PULLS:()=>ae,applyClusterHeuristic:()=>we,broadestValueCell:()=>Ne,candidateLayouts:()=>U,canonicalArm:()=>W,canonicalPersona:()=>de,chooseLayout:()=>Oe,chooseLayoutDetailed:()=>oe,chooseLayoutFactored:()=>Ie,chooseSlotArmFactored:()=>Te,confidenceBand:()=>je,decisionPersona:()=>Xe,factorCellsForOrder:()=>Ke,factorCellsForTrial:()=>Ve,factorLevelsFor:()=>G,fnv1a:()=>ue,hashLayout:()=>N,layoutBucketOf:()=>j,marginalArmKey:()=>He,normalizeDeclaredPersona:()=>me,orderByArchetype:()=>$,parseArm:()=>Z,pickDeterministicArm:()=>Ye,pickFromWeights:()=>Ee,pooledPosterior:()=>Fe,posteriorOfCounts:()=>S,previewOrderForPersona:()=>ne,resolvePersona:()=>Ze,sampleArm:()=>B,sampleArmEv:()=>ze,sampleBeta:()=>R,shrunkAvgValue:()=>fe,shrunkPosterior:()=>C,slotBaselineArm:()=>le,slotResultFor:()=>qe,validateSlotDecl:()=>Be,visitLevel:()=>$e,weightCellsFor:()=>Ue});module.exports=ke(Je);var P="unknown",Le="Unknown";var Me=[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 M(e,r){return e>>>r|e<<32-r}function re(e){return(e>>>0).toString(16).padStart(8,"0")}function Pe(e){let r=new TextEncoder().encode(e),t=r.length,n=t*8,o=(t+8>>6)+1<<6,s=new Uint8Array(o);s.set(r),s[t]=128;let a=new DataView(s.buffer);a.setUint32(o-8,Math.floor(n/4294967296),!1),a.setUint32(o-4,n>>>0,!1);let i=1779033703,u=3144134277,p=1013904242,m=2773480762,y=1359893119,d=2600822924,b=528734635,c=1541459225,f=new Uint32Array(64);for(let A=0;A<o;A+=64){for(let g=0;g<16;g++)f[g]=a.getUint32(A+g*4,!1);for(let g=16;g<64;g++){let E=M(f[g-15],7)^M(f[g-15],18)^f[g-15]>>>3,F=M(f[g-2],17)^M(f[g-2],19)^f[g-2]>>>10;f[g]=f[g-16]+E+f[g-7]+F>>>0}let l=i,v=u,x=p,k=m,h=y,L=d,w=b,O=c;for(let g=0;g<64;g++){let E=M(h,6)^M(h,11)^M(h,25),F=h&L^~h&w,X=O+E+F+Me[g]+f[g]>>>0,xe=M(l,2)^M(l,13)^M(l,22),he=l&v^l&x^v&x,ye=xe+he>>>0;O=w,w=L,L=h,h=k+X>>>0,k=x,x=v,v=l,l=X+ye>>>0}i=i+l>>>0,u=u+v>>>0,p=p+x>>>0,m=m+k>>>0,y=y+h>>>0,d=d+L>>>0,b=b+w>>>0,c=c+O>>>0}return re(i)+re(u)}function N(e){return Pe(e.join("|"))}var te={conversion_led:["pricing","cta","hero","comparison","social_proof","trust","features","faq","navigation","generic"],evidence_led:["features","comparison","faq","hero","trust","social_proof","pricing","cta","navigation","generic"],price_led:["pricing","comparison","social_proof","trust","cta","hero","features","faq","navigation","generic"],discovery_led:["hero","features","social_proof","pricing","cta","trust","faq","comparison","navigation","generic"]},D=["conversion_led","evidence_led","price_led","discovery_led"];function $(e,r,t,n){let o=te[t];if(!o)return e;let s=o.indexOf("generic"),a=p=>{let m=o.indexOf(p);return m===-1?s:m},i=n?e.filter(p=>n.get(p)!=="structural"):[...e];if(i.sort((p,m)=>{var b,c;let y=(b=r.get(p))!=null?b:"generic",d=(c=r.get(m))!=null?c:"generic";return a(y)-a(d)}),!n)return i;let u=0;return e.map(p=>n.get(p)==="structural"?p:i[u++])}function Re(e){let r=2166136261;for(let t=0;t<e.length;t++)r^=e.charCodeAt(t),r=Math.imul(r,16777619)>>>0;return r>>>0}function ne(e,r,t,n){if(!t||t==="unknown")return e;let o=D[Re(t)%D.length];return $(e,r,o,n)}var we=ne;function U(e,r,t){let n=new Map;n.set(N(e),[...e]);for(let o of D){let s=$(e,r,o,t),a=N(s);n.has(a)||n.set(a,s)}return n}function H(e,r){if(e<1)return H(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 o,s;do{let i=Math.max(1e-15,r()),u=r();o=Math.sqrt(-2*Math.log(i))*Math.cos(2*Math.PI*u),s=1+n*o}while(s<=0);s=s*s*s;let a=r();if(a<1-.0331*o*o*o*o||Math.log(a)<.5*o*o+t*(1-s+Math.log(s)))return t*s}}function R(e,r,t=Math.random){let n=H(e,t),o=H(r,t),s=n+o;return s<=0?e/(e+r):n/s}function B(e,r=Math.random){if(e.length===0)return null;if(e.length===1)return e[0].arm;let t=e[0],n=R(t.alpha,t.beta,r);for(let o=1;o<e.length;o++){let s=e[o],a=R(s.alpha,s.beta,r);a>n&&(t=s,n=a)}return t.arm}function Oe(e,r,t,n,o=Math.random,s){return oe(e,r,t,n,o,s).order}function oe(e,r,t,n,o=Math.random,s){var m,y;let a=U(e,r,s),i=[];for(let d of a.keys()){let b=n.get(d);i.push({arm:d,alpha:(m=b==null?void 0:b.alpha)!=null?m:1,beta:(y=b==null?void 0:b.beta)!=null?y:1})}let u=B(i,o),p=u?a.get(u):void 0;return u&&p?{order:p,chosenHash:u,candidates:i.map(d=>d.arm),arms:i}:{order:e,chosenHash:N(e),candidates:i.map(d=>d.arm),arms:i}}var se=20;function C(e,r,t=20){let n=r.alpha+r.beta;if(n<=0||t<=0)return{alpha:e.alpha,beta:e.beta};let o=r.alpha/n,s=t*n/(n+t);return{alpha:e.alpha+s*o,beta:e.beta+s*(1-o)}}var ae=5;function Ee(e,r){var n,o;let t=null;for(let s of e){if(!r.includes(s.variantId))continue;let a=(n=s.pulls)!=null?n:0,i=a>0?a*s.avgReward/(a+ae):0;(!t||i>t.score)&&(t={variantId:s.variantId,score:i})}return(o=t==null?void 0:t.variantId)!=null?o:null}var _="__all__",T={exposures:0,conversions:0};function S(e){return{alpha:e.conversions+1,beta:Math.max(0,e.exposures-e.conversions)+1}}function Fe(e,r,t=20){var d,b,c,f;let n=(d=e.segment)!=null?d:T,o=(b=e.global)!=null?b:T,s=S(o),a=C(S(n),s,t);if(!r)return a;let i=(c=e.persona)!=null?c:T,u=(f=e.child)!=null?f:T,p=C(S(i),s,t),m=(n.exposures+1)/(n.exposures+i.exposures+2),y={alpha:m*a.alpha+(1-m)*p.alpha,beta:m*a.beta+(1-m)*p.beta};return C(S(u),y,t)}function Ne(e){var n,o;let r=null,t=-1;for(let s of e){let a=s.segment===_,i=s.persona===_,u=a&&i?3:a||i?2:1;u>t&&(t=u,r=s)}return{valueSum:(n=r==null?void 0:r.valueSum)!=null?n:0,valueCount:(o=r==null?void 0:r.valueCount)!=null?o:0}}function Ue(e,r){return r==="unknown"||r===_||r===""?[{segment:e,persona:_},{segment:_,persona:_}]:[{segment:e,persona:r},{segment:e,persona:_},{segment:_,persona:r},{segment:_,persona:_}]}var Y=4,ie="__global__";function j(e,r){return r<=0?0:Math.min(Y-1,Math.floor(e*Y/r))}function Ke(e,r){return e.map((t,n)=>{var o;return{parent:(o=r.get(t))!=null?o:"generic",bucket:j(n,e.length)}})}var q=(e,r)=>`${e}#${r}`;function Ie(e,r,t,n,o=Math.random,s){var A;let a=U(e,r,s),i=new Map,u=new Map,p=0,m=0;for(let l of n)l.persona===ie?(i.set(q(l.parent,l.bucket),l),p+=l.exposures,m+=l.conversions):l.persona===t&&u.set(q(l.parent,l.bucket),l);let y=S({exposures:p,conversions:m}),d=new Map,b=(l,v)=>{var E,F;let x=q(l,v),k=d.get(x);if(k!==void 0)return k;let h=i.get(x),L=C(S({exposures:(E=h==null?void 0:h.exposures)!=null?E:0,conversions:(F=h==null?void 0:h.conversions)!=null?F:0}),y),w=u.get(x),O=w?C(S({exposures:w.exposures,conversions:w.conversions}),L):L,g=R(O.alpha,O.beta,o);return d.set(x,g),g},c=null,f=-1/0;for(let l of a.values()){let v=0;for(let x=0;x<l.length;x++)v+=b((A=r.get(l[x]))!=null?A:"generic",j(x,l.length));v>f&&(f=v,c=l)}return c!=null?c:e}var K="__global__",De=["device","source","persona","visit"];function G(e){let r=[];return e.device&&r.push({factor:"device",level:e.device}),e.source&&r.push({factor:"source",level:e.source}),e.persona&&e.persona!==P&&r.push({factor:"persona",level:e.persona}),e.visit&&r.push({factor:"visit",level:e.visit}),r}var z=(e,r,t)=>`${e}\0${r}\0${t}`;function Te(e,r,t,n=Math.random){if(e.length===0)return null;if(e.length===1)return{arm:e[0],factorsUsed:0};let o=new Map,s=0,a=0;for(let c of t)o.set(z(c.arm,c.factor,c.level),c),c.level===K&&(s+=c.exposures,a+=c.conversions);let i=S({exposures:s,conversions:a}),u=G(r),p=new Map,m=c=>{var A,l;let f=o.get(z(c,"global",K));return C(S({exposures:(A=f==null?void 0:f.exposures)!=null?A:0,conversions:(l=f==null?void 0:f.conversions)!=null?l:0}),i)},y=(c,f,A)=>{let l=z(c,f,A),v=p.get(l);if(v!==void 0)return v;let x=m(c),k=o.get(l),h=k?C(S({exposures:k.exposures,conversions:k.conversions}),x):x,L=R(h.alpha,h.beta,n);return p.set(l,L),L},d=null,b=-1/0;for(let c of e){let f=u.length===0?y(c,"global",K):0;for(let{factor:A,level:l}of u)f+=y(c,A,l);f>b&&(b=f,d=c)}return d===null?null:{arm:d,factorsUsed:u.length}}function Ve(e,r,t){let n=Number.isFinite(t)?Math.max(0,Math.min(1,t)):0,o=[{arm:e,factor:"global",level:K,weight:1}];for(let{factor:s,level:a}of G(r)){let i=s==="persona"?n:1;i!==0&&o.push({arm:e,factor:s,level:a,weight:i})}return o}function $e(e){return e==null||!Number.isFinite(e)||e<1?null:e>1?"returning":"new"}function W(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 o=t.slice(0,n);if(o in r)return null;r[o]=t.slice(n+1)}return r}function He(e,r){return`${e}=${r}`}function le(e){var t,n,o;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 W(e.baseline);if(typeof e.baseline=="string")return e.baseline;let r={};for(let[s,a]of Object.entries((n=e.dims)!=null?n:{}))r[s]=(o=a[0])!=null?o:"";return W(r)}function Be(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 s=e.arms;if(s.length<2)return{ok:!1,reason:"arms requires at least 2 entries"};if(s.length>12)return{ok:!1,reason:"arms allows at most 12 entries"};if(new Set(s).size!==s.length)return{ok:!1,reason:"arms must be unique"};if(s.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(!s.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 o=1;for(let[s,a]of n){if(a.length<2)return{ok:!1,reason:`dim "${s}" requires at least 2 values`};if(a.length>6)return{ok:!1,reason:`dim "${s}" allows at most 6 values`};if(new Set(a).size!==a.length)return{ok:!1,reason:`dim "${s}" has duplicate values`};o*=a.length}if(o>64)return{ok:!1,reason:`declared space of ${o} 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 s=e.baseline,a=n.map(([u])=>u).sort(),i=Object.keys(s).sort();if(a.join(" ")!==i.join(" "))return{ok:!1,reason:"baseline must set every declared dim exactly once"};for(let[u,p]of n)if(!p.includes(s[u]))return{ok:!1,reason:`baseline value for dim "${u}" is not declared`}}return{ok:!0}}function qe(e,r){var t,n;return e.dims!=null?(n=(t=Z(r))!=null?t:Z(le(e)))!=null?n:{}:r}function ue(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 Ye(e,r,t){if(t.length===0)throw new Error("pickDeterministicArm requires at least one arm");let n=[...t].sort();return n[ue(`${e}:${r}`)%n.length]}function je(e){return e>=.3?e<.7?"medium":"high":"low"}var ce=20;function fe(e,r,t=ce){let n=e.valueCount>0?e.valueSum/e.valueCount:0;if(r<=0)return n;if(e.valueCount<=0)return r;let o=e.valueCount/(e.valueCount+t);return o*n+(1-o)*r}function ze(e,r,t=Math.random){if(e.length===0)return null;if(e.length===1)return e[0].arm;let n=null,o=-1/0;for(let s of e){let a=R(s.alpha,s.beta,t)*fe(s,r);a>o&&(n=s,o=a)}return n.arm}var pe=/^[a-z0-9][a-z0-9_-]{0,31}$/;function me(e){if(typeof e!="string")return null;let r=e.trim().toLowerCase();return r&&pe.test(r)?r:null}var ge=["unknown","__all__"];function de(e){var r;return(r=me(e))!=null?r:P}var be=[],Ge=64;function We(e){var t;let r=new Map;for(let n of e)if(n.status!=="retired"){r.set(n.key,n.key);for(let o of(t=n.aliases)!=null?t:[])ge.includes(o)||r.set(o,n.key)}return r}function Ze(e,r=be){var i,u,p;let t=We(r),n=(i=e.inferredConfidence)!=null?i:0,o,s=(p=(u=e.declared)==null?void 0:u.trim().toLowerCase())!=null?p:"";if(s!==""){let m=t.get(s);if(m!==void 0)return{persona:m,source:"declared",confidence:1};o=s.slice(0,Ge)}let a=de(e.clusterLabel);return a!==P&&t.has(a)?V({persona:t.get(a),source:"inferred",confidence:n},o!==void 0&&{unrecognizedDeclared:o}):V({persona:P,source:"none",confidence:n},o!==void 0&&{unrecognizedDeclared:o})}function Xe(e){if(e==null)return P;let r=e.trim().toLowerCase();return r===""?P:r}0&&(module.exports={DEFAULT_PERSONA_VOCABULARY,EV_SHRINK_K,GLOBAL_FACTOR_LEVEL,GLOBAL_FACTOR_PERSONA,LAYOUT_ARCHETYPES,LAYOUT_ARCHETYPE_NAMES,LAYOUT_FACTOR_BUCKETS,PERSONA_KEY_RE,POOL_ALL,RESERVED_PERSONA_KEYS,SHRINKAGE_M,SLOT_FACTORS,UNKNOWN_PERSONA,UNKNOWN_PERSONA_DISPLAY,WEIGHTS_FALLBACK_PRIOR_PULLS,applyClusterHeuristic,broadestValueCell,candidateLayouts,canonicalArm,canonicalPersona,chooseLayout,chooseLayoutDetailed,chooseLayoutFactored,chooseSlotArmFactored,confidenceBand,decisionPersona,factorCellsForOrder,factorCellsForTrial,factorLevelsFor,fnv1a,hashLayout,layoutBucketOf,marginalArmKey,normalizeDeclaredPersona,orderByArchetype,parseArm,pickDeterministicArm,pickFromWeights,pooledPosterior,posteriorOfCounts,previewOrderForPersona,resolvePersona,sampleArm,sampleArmEv,sampleBeta,shrunkAvgValue,shrunkPosterior,slotBaselineArm,slotResultFor,validateSlotDecl,visitLevel,weightCellsFor});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{a as I}from"./chunk-HBG7RQ56.mjs";var R="unknown",ve="Unknown";var te=[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 k(e,r){return e>>>r|e<<32-r}function q(e){return(e>>>0).toString(16).padStart(8,"0")}function ne(e){let r=new TextEncoder().encode(e),t=r.length,n=t*8,o=(t+8>>6)+1<<6,s=new Uint8Array(o);s.set(r),s[t]=128;let a=new DataView(s.buffer);a.setUint32(o-8,Math.floor(n/4294967296),!1),a.setUint32(o-4,n>>>0,!1);let l=1779033703,u=3144134277,f=1013904242,m=2773480762,y=1359893119,d=2600822924,b=528734635,c=1541459225,p=new Uint32Array(64);for(let A=0;A<o;A+=64){for(let g=0;g<16;g++)p[g]=a.getUint32(A+g*4,!1);for(let g=16;g<64;g++){let E=k(p[g-15],7)^k(p[g-15],18)^p[g-15]>>>3,F=k(p[g-2],17)^k(p[g-2],19)^p[g-2]>>>10;p[g]=p[g-16]+E+p[g-7]+F>>>0}let i=l,v=u,x=f,C=m,h=y,_=d,M=b,O=c;for(let g=0;g<64;g++){let E=k(h,6)^k(h,11)^k(h,25),F=h&_^~h&M,H=O+E+F+te[g]+p[g]>>>0,Q=k(i,2)^k(i,13)^k(i,22),ee=i&v^i&x^v&x,re=Q+ee>>>0;O=M,M=_,_=h,h=C+H>>>0,C=x,x=v,v=i,i=H+re>>>0}l=l+i>>>0,u=u+v>>>0,f=f+x>>>0,m=m+C>>>0,y=y+h>>>0,d=d+_>>>0,b=b+M>>>0,c=c+O>>>0}return q(l)+q(u)}function T(e){return ne(e.join("|"))}var oe={conversion_led:["pricing","cta","hero","comparison","social_proof","trust","features","faq","navigation","generic"],evidence_led:["features","comparison","faq","hero","trust","social_proof","pricing","cta","navigation","generic"],price_led:["pricing","comparison","social_proof","trust","cta","hero","features","faq","navigation","generic"],discovery_led:["hero","features","social_proof","pricing","cta","trust","faq","comparison","navigation","generic"]},V=["conversion_led","evidence_led","price_led","discovery_led"];function Y(e,r,t,n){let o=oe[t];if(!o)return e;let s=o.indexOf("generic"),a=f=>{let m=o.indexOf(f);return m===-1?s:m},l=n?e.filter(f=>n.get(f)!=="structural"):[...e];if(l.sort((f,m)=>{var b,c;let y=(b=r.get(f))!=null?b:"generic",d=(c=r.get(m))!=null?c:"generic";return a(y)-a(d)}),!n)return l;let u=0;return e.map(f=>n.get(f)==="structural"?f:l[u++])}function se(e){let r=2166136261;for(let t=0;t<e.length;t++)r^=e.charCodeAt(t),r=Math.imul(r,16777619)>>>0;return r>>>0}function ae(e,r,t,n){if(!t||t==="unknown")return e;let o=V[se(t)%V.length];return Y(e,r,o,n)}var _e=ae;function N(e,r,t){let n=new Map;n.set(T(e),[...e]);for(let o of V){let s=Y(e,r,o,t),a=T(s);n.has(a)||n.set(a,s)}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 o,s;do{let l=Math.max(1e-15,r()),u=r();o=Math.sqrt(-2*Math.log(l))*Math.cos(2*Math.PI*u),s=1+n*o}while(s<=0);s=s*s*s;let a=r();if(a<1-.0331*o*o*o*o||Math.log(a)<.5*o*o+t*(1-s+Math.log(s)))return t*s}}function w(e,r,t=Math.random){let n=$(e,t),o=$(r,t),s=n+o;return s<=0?e/(e+r):n/s}function j(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 o=1;o<e.length;o++){let s=e[o],a=w(s.alpha,s.beta,r);a>n&&(t=s,n=a)}return t.arm}function Re(e,r,t,n,o=Math.random,s){var m,y;let a=N(e,r,s),l=[];for(let d of a.keys()){let b=n.get(d);l.push({arm:d,alpha:(m=b==null?void 0:b.alpha)!=null?m:1,beta:(y=b==null?void 0:b.beta)!=null?y:1})}let u=j(l,o),f=u?a.get(u):void 0;return f!=null?f:e}var z=20;function L(e,r,t=20){let n=r.alpha+r.beta;if(n<=0||t<=0)return{alpha:e.alpha,beta:e.beta};let o=r.alpha/n,s=t*n/(n+t);return{alpha:e.alpha+s*o,beta:e.beta+s*(1-o)}}var ie=5;function Oe(e,r){var n,o;let t=null;for(let s of e){if(!r.includes(s.variantId))continue;let a=(n=s.pulls)!=null?n:0,l=a>0?a*s.avgReward/(a+ie):0;(!t||l>t.score)&&(t={variantId:s.variantId,score:l})}return(o=t==null?void 0:t.variantId)!=null?o:null}var P="__all__",U={exposures:0,conversions:0};function S(e){return{alpha:e.conversions+1,beta:Math.max(0,e.exposures-e.conversions)+1}}function Ne(e,r,t=20){var d,b,c,p;let n=(d=e.segment)!=null?d:U,o=(b=e.global)!=null?b:U,s=S(o),a=L(S(n),s,t);if(!r)return a;let l=(c=e.persona)!=null?c:U,u=(p=e.child)!=null?p:U,f=L(S(l),s,t),m=(n.exposures+1)/(n.exposures+l.exposures+2),y={alpha:m*a.alpha+(1-m)*f.alpha,beta:m*a.beta+(1-m)*f.beta};return L(S(u),y,t)}function Ue(e){var n,o;let r=null,t=-1;for(let s of e){let a=s.segment===P,l=s.persona===P,u=a&&l?3:a||l?2:1;u>t&&(t=u,r=s)}return{valueSum:(n=r==null?void 0:r.valueSum)!=null?n:0,valueCount:(o=r==null?void 0:r.valueCount)!=null?o:0}}function Ke(e,r){return r==="unknown"||r===P||r===""?[{segment:e,persona:P},{segment:P,persona:P}]:[{segment:e,persona:r},{segment:e,persona:P},{segment:P,persona:r},{segment:P,persona:P}]}var G=4,le="__global__";function W(e,r){return r<=0?0:Math.min(G-1,Math.floor(e*G/r))}function Be(e,r){return e.map((t,n)=>{var o;return{parent:(o=r.get(t))!=null?o:"generic",bucket:W(n,e.length)}})}var D=(e,r)=>`${e}#${r}`;function He(e,r,t,n,o=Math.random,s){var A;let a=N(e,r,s),l=new Map,u=new Map,f=0,m=0;for(let i of n)i.persona===le?(l.set(D(i.parent,i.bucket),i),f+=i.exposures,m+=i.conversions):i.persona===t&&u.set(D(i.parent,i.bucket),i);let y=S({exposures:f,conversions:m}),d=new Map,b=(i,v)=>{var E,F;let x=D(i,v),C=d.get(x);if(C!==void 0)return C;let h=l.get(x),_=L(S({exposures:(E=h==null?void 0:h.exposures)!=null?E:0,conversions:(F=h==null?void 0:h.conversions)!=null?F:0}),y),M=u.get(x),O=M?L(S({exposures:M.exposures,conversions:M.conversions}),_):_,g=w(O.alpha,O.beta,o);return d.set(x,g),g},c=null,p=-1/0;for(let i of a.values()){let v=0;for(let x=0;x<i.length;x++)v+=b((A=r.get(i[x]))!=null?A:"generic",W(x,i.length));v>p&&(p=v,c=i)}return c!=null?c:e}var K="__global__",We=["device","source","persona","visit"];function Z(e){let r=[];return e.device&&r.push({factor:"device",level:e.device}),e.source&&r.push({factor:"source",level:e.source}),e.persona&&e.persona!==R&&r.push({factor:"persona",level:e.persona}),e.visit&&r.push({factor:"visit",level:e.visit}),r}var B=(e,r,t)=>`${e}\0${r}\0${t}`;function Ze(e,r,t,n=Math.random){if(e.length===0)return null;if(e.length===1)return{arm:e[0],factorsUsed:0};let o=new Map,s=0,a=0;for(let c of t)o.set(B(c.arm,c.factor,c.level),c),c.level===K&&(s+=c.exposures,a+=c.conversions);let l=S({exposures:s,conversions:a}),u=Z(r),f=new Map,m=c=>{var A,i;let p=o.get(B(c,"global",K));return L(S({exposures:(A=p==null?void 0:p.exposures)!=null?A:0,conversions:(i=p==null?void 0:p.conversions)!=null?i:0}),l)},y=(c,p,A)=>{let i=B(c,p,A),v=f.get(i);if(v!==void 0)return v;let x=m(c),C=o.get(i),h=C?L(S({exposures:C.exposures,conversions:C.conversions}),x):x,_=w(h.alpha,h.beta,n);return f.set(i,_),_},d=null,b=-1/0;for(let c of e){let p=u.length===0?y(c,"global",K):0;for(let{factor:A,level:i}of u)p+=y(c,A,i);p>b&&(b=p,d=c)}return d===null?null:{arm:d,factorsUsed:u.length}}function Xe(e,r,t){let n=Number.isFinite(t)?Math.max(0,Math.min(1,t)):0,o=[{arm:e,factor:"global",level:K,weight:1}];for(let{factor:s,level:a}of Z(r))o.push({arm:e,factor:s,level:a,weight:s==="persona"?n:1});return o}function Je(e){return e==null||!Number.isFinite(e)||e<1?null:e>1?"returning":"new"}function X(e){return Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("|")}function J(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 o=t.slice(0,n);if(o in r)return null;r[o]=t.slice(n+1)}return r}function er(e,r){return`${e}=${r}`}function ue(e){var t,n,o;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 X(e.baseline);if(typeof e.baseline=="string")return e.baseline;let r={};for(let[s,a]of Object.entries((n=e.dims)!=null?n:{}))r[s]=(o=a[0])!=null?o:"";return X(r)}function rr(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 s=e.arms;if(s.length<2)return{ok:!1,reason:"arms requires at least 2 entries"};if(s.length>12)return{ok:!1,reason:"arms allows at most 12 entries"};if(new Set(s).size!==s.length)return{ok:!1,reason:"arms must be unique"};if(s.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(!s.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 o=1;for(let[s,a]of n){if(a.length<2)return{ok:!1,reason:`dim "${s}" requires at least 2 values`};if(a.length>6)return{ok:!1,reason:`dim "${s}" allows at most 6 values`};if(new Set(a).size!==a.length)return{ok:!1,reason:`dim "${s}" has duplicate values`};o*=a.length}if(o>64)return{ok:!1,reason:`declared space of ${o} 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 s=e.baseline,a=n.map(([u])=>u).sort(),l=Object.keys(s).sort();if(a.join(" ")!==l.join(" "))return{ok:!1,reason:"baseline must set every declared dim exactly once"};for(let[u,f]of n)if(!f.includes(s[u]))return{ok:!1,reason:`baseline value for dim "${u}" is not declared`}}return{ok:!0}}function tr(e,r){var t,n;return e.dims!=null?(n=(t=J(r))!=null?t:J(ue(e)))!=null?n:{}:r}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 or(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 sr(e){return e>=.3?e<.7?"medium":"high":"low"}var fe=20;function pe(e,r,t=fe){let n=e.valueCount>0?e.valueSum/e.valueCount:0;if(r<=0)return n;if(e.valueCount<=0)return r;let o=e.valueCount/(e.valueCount+t);return o*n+(1-o)*r}function lr(e,r,t=Math.random){if(e.length===0)return null;if(e.length===1)return e[0].arm;let n=null,o=-1/0;for(let s of e){let a=w(s.alpha,s.beta,t)*pe(s,r);a>o&&(n=s,o=a)}return n.arm}var me=/^[a-z0-9][a-z0-9_-]{0,31}$/;function ge(e){if(typeof e!="string")return null;let r=e.trim().toLowerCase();return r&&me.test(r)?r:null}var be=["unknown","__all__"];function de(e){var r;return(r=ge(e))!=null?r:R}var xe=[],he=64;function ye(e){var t;let r=new Map;for(let n of e)if(n.status!=="retired"){r.set(n.key,n.key);for(let o of(t=n.aliases)!=null?t:[])be.includes(o)||r.set(o,n.key)}return r}function fr(e,r=xe){var l,u,f;let t=ye(r),n=(l=e.inferredConfidence)!=null?l:0,o,s=(f=(u=e.declared)==null?void 0:u.trim().toLowerCase())!=null?f:"";if(s!==""){let m=t.get(s);if(m!==void 0)return{persona:m,source:"declared",confidence:1};o=s.slice(0,he)}let a=de(e.clusterLabel);return a!==R&&t.has(a)?I({persona:t.get(a),source:"inferred",confidence:n},o!==void 0&&{unrecognizedDeclared:o}):I({persona:R,source:"none",confidence:n},o!==void 0&&{unrecognizedDeclared:o})}function pr(e){if(e==null)return R;let r=e.trim().toLowerCase();return r===""?R:r}export{xe as DEFAULT_PERSONA_VOCABULARY,fe as EV_SHRINK_K,K as GLOBAL_FACTOR_LEVEL,le as GLOBAL_FACTOR_PERSONA,oe as LAYOUT_ARCHETYPES,V as LAYOUT_ARCHETYPE_NAMES,G as LAYOUT_FACTOR_BUCKETS,me as PERSONA_KEY_RE,P as POOL_ALL,be as RESERVED_PERSONA_KEYS,z as SHRINKAGE_M,We as SLOT_FACTORS,R as UNKNOWN_PERSONA,ve as UNKNOWN_PERSONA_DISPLAY,ie as WEIGHTS_FALLBACK_PRIOR_PULLS,_e as applyClusterHeuristic,Ue as broadestValueCell,N as candidateLayouts,X as canonicalArm,de as canonicalPersona,Re as chooseLayout,He as chooseLayoutFactored,Ze as chooseSlotArmFactored,sr as confidenceBand,pr as decisionPersona,Be as factorCellsForOrder,Xe as factorCellsForTrial,Z as factorLevelsFor,ce as fnv1a,T as hashLayout,W as layoutBucketOf,er as marginalArmKey,ge as normalizeDeclaredPersona,Y as orderByArchetype,J as parseArm,or as pickDeterministicArm,Oe as pickFromWeights,Ne as pooledPosterior,S as posteriorOfCounts,ae as previewOrderForPersona,fr as resolvePersona,j as sampleArm,lr as sampleArmEv,w as sampleBeta,pe as shrunkAvgValue,L as shrunkPosterior,ue as slotBaselineArm,tr as slotResultFor,rr as validateSlotDecl,Je as visitLevel,Ke as weightCellsFor};
1
+ import{a as D}from"./chunk-HBG7RQ56.mjs";var R="unknown",Ae="Unknown";var te=[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 k(e,r){return e>>>r|e<<32-r}function q(e){return(e>>>0).toString(16).padStart(8,"0")}function ne(e){let r=new TextEncoder().encode(e),t=r.length,n=t*8,o=(t+8>>6)+1<<6,s=new Uint8Array(o);s.set(r),s[t]=128;let a=new DataView(s.buffer);a.setUint32(o-8,Math.floor(n/4294967296),!1),a.setUint32(o-4,n>>>0,!1);let i=1779033703,u=3144134277,p=1013904242,m=2773480762,y=1359893119,d=2600822924,b=528734635,c=1541459225,f=new Uint32Array(64);for(let A=0;A<o;A+=64){for(let g=0;g<16;g++)f[g]=a.getUint32(A+g*4,!1);for(let g=16;g<64;g++){let E=k(f[g-15],7)^k(f[g-15],18)^f[g-15]>>>3,F=k(f[g-2],17)^k(f[g-2],19)^f[g-2]>>>10;f[g]=f[g-16]+E+f[g-7]+F>>>0}let l=i,v=u,x=p,C=m,h=y,_=d,P=b,O=c;for(let g=0;g<64;g++){let E=k(h,6)^k(h,11)^k(h,25),F=h&_^~h&P,B=O+E+F+te[g]+f[g]>>>0,Q=k(l,2)^k(l,13)^k(l,22),ee=l&v^l&x^v&x,re=Q+ee>>>0;O=P,P=_,_=h,h=C+B>>>0,C=x,x=v,v=l,l=B+re>>>0}i=i+l>>>0,u=u+v>>>0,p=p+x>>>0,m=m+C>>>0,y=y+h>>>0,d=d+_>>>0,b=b+P>>>0,c=c+O>>>0}return q(i)+q(u)}function N(e){return ne(e.join("|"))}var oe={conversion_led:["pricing","cta","hero","comparison","social_proof","trust","features","faq","navigation","generic"],evidence_led:["features","comparison","faq","hero","trust","social_proof","pricing","cta","navigation","generic"],price_led:["pricing","comparison","social_proof","trust","cta","hero","features","faq","navigation","generic"],discovery_led:["hero","features","social_proof","pricing","cta","trust","faq","comparison","navigation","generic"]},T=["conversion_led","evidence_led","price_led","discovery_led"];function Y(e,r,t,n){let o=oe[t];if(!o)return e;let s=o.indexOf("generic"),a=p=>{let m=o.indexOf(p);return m===-1?s:m},i=n?e.filter(p=>n.get(p)!=="structural"):[...e];if(i.sort((p,m)=>{var b,c;let y=(b=r.get(p))!=null?b:"generic",d=(c=r.get(m))!=null?c:"generic";return a(y)-a(d)}),!n)return i;let u=0;return e.map(p=>n.get(p)==="structural"?p:i[u++])}function se(e){let r=2166136261;for(let t=0;t<e.length;t++)r^=e.charCodeAt(t),r=Math.imul(r,16777619)>>>0;return r>>>0}function ae(e,r,t,n){if(!t||t==="unknown")return e;let o=T[se(t)%T.length];return Y(e,r,o,n)}var ke=ae;function U(e,r,t){let n=new Map;n.set(N(e),[...e]);for(let o of T){let s=Y(e,r,o,t),a=N(s);n.has(a)||n.set(a,s)}return n}function V(e,r){if(e<1)return V(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 o,s;do{let i=Math.max(1e-15,r()),u=r();o=Math.sqrt(-2*Math.log(i))*Math.cos(2*Math.PI*u),s=1+n*o}while(s<=0);s=s*s*s;let a=r();if(a<1-.0331*o*o*o*o||Math.log(a)<.5*o*o+t*(1-s+Math.log(s)))return t*s}}function w(e,r,t=Math.random){let n=V(e,t),o=V(r,t),s=n+o;return s<=0?e/(e+r):n/s}function j(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 o=1;o<e.length;o++){let s=e[o],a=w(s.alpha,s.beta,r);a>n&&(t=s,n=a)}return t.arm}function Oe(e,r,t,n,o=Math.random,s){return ie(e,r,t,n,o,s).order}function ie(e,r,t,n,o=Math.random,s){var m,y;let a=U(e,r,s),i=[];for(let d of a.keys()){let b=n.get(d);i.push({arm:d,alpha:(m=b==null?void 0:b.alpha)!=null?m:1,beta:(y=b==null?void 0:b.beta)!=null?y:1})}let u=j(i,o),p=u?a.get(u):void 0;return u&&p?{order:p,chosenHash:u,candidates:i.map(d=>d.arm),arms:i}:{order:e,chosenHash:N(e),candidates:i.map(d=>d.arm),arms:i}}var z=20;function L(e,r,t=20){let n=r.alpha+r.beta;if(n<=0||t<=0)return{alpha:e.alpha,beta:e.beta};let o=r.alpha/n,s=t*n/(n+t);return{alpha:e.alpha+s*o,beta:e.beta+s*(1-o)}}var le=5;function Fe(e,r){var n,o;let t=null;for(let s of e){if(!r.includes(s.variantId))continue;let a=(n=s.pulls)!=null?n:0,i=a>0?a*s.avgReward/(a+le):0;(!t||i>t.score)&&(t={variantId:s.variantId,score:i})}return(o=t==null?void 0:t.variantId)!=null?o:null}var M="__all__",K={exposures:0,conversions:0};function S(e){return{alpha:e.conversions+1,beta:Math.max(0,e.exposures-e.conversions)+1}}function Ke(e,r,t=20){var d,b,c,f;let n=(d=e.segment)!=null?d:K,o=(b=e.global)!=null?b:K,s=S(o),a=L(S(n),s,t);if(!r)return a;let i=(c=e.persona)!=null?c:K,u=(f=e.child)!=null?f:K,p=L(S(i),s,t),m=(n.exposures+1)/(n.exposures+i.exposures+2),y={alpha:m*a.alpha+(1-m)*p.alpha,beta:m*a.beta+(1-m)*p.beta};return L(S(u),y,t)}function Ie(e){var n,o;let r=null,t=-1;for(let s of e){let a=s.segment===M,i=s.persona===M,u=a&&i?3:a||i?2:1;u>t&&(t=u,r=s)}return{valueSum:(n=r==null?void 0:r.valueSum)!=null?n:0,valueCount:(o=r==null?void 0:r.valueCount)!=null?o:0}}function De(e,r){return r==="unknown"||r===M||r===""?[{segment:e,persona:M},{segment:M,persona:M}]:[{segment:e,persona:r},{segment:e,persona:M},{segment:M,persona:r},{segment:M,persona:M}]}var G=4,ue="__global__";function W(e,r){return r<=0?0:Math.min(G-1,Math.floor(e*G/r))}function qe(e,r){return e.map((t,n)=>{var o;return{parent:(o=r.get(t))!=null?o:"generic",bucket:W(n,e.length)}})}var $=(e,r)=>`${e}#${r}`;function Ye(e,r,t,n,o=Math.random,s){var A;let a=U(e,r,s),i=new Map,u=new Map,p=0,m=0;for(let l of n)l.persona===ue?(i.set($(l.parent,l.bucket),l),p+=l.exposures,m+=l.conversions):l.persona===t&&u.set($(l.parent,l.bucket),l);let y=S({exposures:p,conversions:m}),d=new Map,b=(l,v)=>{var E,F;let x=$(l,v),C=d.get(x);if(C!==void 0)return C;let h=i.get(x),_=L(S({exposures:(E=h==null?void 0:h.exposures)!=null?E:0,conversions:(F=h==null?void 0:h.conversions)!=null?F:0}),y),P=u.get(x),O=P?L(S({exposures:P.exposures,conversions:P.conversions}),_):_,g=w(O.alpha,O.beta,o);return d.set(x,g),g},c=null,f=-1/0;for(let l of a.values()){let v=0;for(let x=0;x<l.length;x++)v+=b((A=r.get(l[x]))!=null?A:"generic",W(x,l.length));v>f&&(f=v,c=l)}return c!=null?c:e}var I="__global__",Xe=["device","source","persona","visit"];function Z(e){let r=[];return e.device&&r.push({factor:"device",level:e.device}),e.source&&r.push({factor:"source",level:e.source}),e.persona&&e.persona!==R&&r.push({factor:"persona",level:e.persona}),e.visit&&r.push({factor:"visit",level:e.visit}),r}var H=(e,r,t)=>`${e}\0${r}\0${t}`;function Je(e,r,t,n=Math.random){if(e.length===0)return null;if(e.length===1)return{arm:e[0],factorsUsed:0};let o=new Map,s=0,a=0;for(let c of t)o.set(H(c.arm,c.factor,c.level),c),c.level===I&&(s+=c.exposures,a+=c.conversions);let i=S({exposures:s,conversions:a}),u=Z(r),p=new Map,m=c=>{var A,l;let f=o.get(H(c,"global",I));return L(S({exposures:(A=f==null?void 0:f.exposures)!=null?A:0,conversions:(l=f==null?void 0:f.conversions)!=null?l:0}),i)},y=(c,f,A)=>{let l=H(c,f,A),v=p.get(l);if(v!==void 0)return v;let x=m(c),C=o.get(l),h=C?L(S({exposures:C.exposures,conversions:C.conversions}),x):x,_=w(h.alpha,h.beta,n);return p.set(l,_),_},d=null,b=-1/0;for(let c of e){let f=u.length===0?y(c,"global",I):0;for(let{factor:A,level:l}of u)f+=y(c,A,l);f>b&&(b=f,d=c)}return d===null?null:{arm:d,factorsUsed:u.length}}function Qe(e,r,t){let n=Number.isFinite(t)?Math.max(0,Math.min(1,t)):0,o=[{arm:e,factor:"global",level:I,weight:1}];for(let{factor:s,level:a}of Z(r)){let i=s==="persona"?n:1;i!==0&&o.push({arm:e,factor:s,level:a,weight:i})}return o}function er(e){return e==null||!Number.isFinite(e)||e<1?null:e>1?"returning":"new"}function X(e){return Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("|")}function J(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 o=t.slice(0,n);if(o in r)return null;r[o]=t.slice(n+1)}return r}function tr(e,r){return`${e}=${r}`}function ce(e){var t,n,o;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 X(e.baseline);if(typeof e.baseline=="string")return e.baseline;let r={};for(let[s,a]of Object.entries((n=e.dims)!=null?n:{}))r[s]=(o=a[0])!=null?o:"";return X(r)}function nr(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 s=e.arms;if(s.length<2)return{ok:!1,reason:"arms requires at least 2 entries"};if(s.length>12)return{ok:!1,reason:"arms allows at most 12 entries"};if(new Set(s).size!==s.length)return{ok:!1,reason:"arms must be unique"};if(s.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(!s.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 o=1;for(let[s,a]of n){if(a.length<2)return{ok:!1,reason:`dim "${s}" requires at least 2 values`};if(a.length>6)return{ok:!1,reason:`dim "${s}" allows at most 6 values`};if(new Set(a).size!==a.length)return{ok:!1,reason:`dim "${s}" has duplicate values`};o*=a.length}if(o>64)return{ok:!1,reason:`declared space of ${o} 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 s=e.baseline,a=n.map(([u])=>u).sort(),i=Object.keys(s).sort();if(a.join(" ")!==i.join(" "))return{ok:!1,reason:"baseline must set every declared dim exactly once"};for(let[u,p]of n)if(!p.includes(s[u]))return{ok:!1,reason:`baseline value for dim "${u}" is not declared`}}return{ok:!0}}function or(e,r){var t,n;return e.dims!=null?(n=(t=J(r))!=null?t:J(ce(e)))!=null?n:{}:r}function fe(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 ar(e,r,t){if(t.length===0)throw new Error("pickDeterministicArm requires at least one arm");let n=[...t].sort();return n[fe(`${e}:${r}`)%n.length]}function ir(e){return e>=.3?e<.7?"medium":"high":"low"}var pe=20;function me(e,r,t=pe){let n=e.valueCount>0?e.valueSum/e.valueCount:0;if(r<=0)return n;if(e.valueCount<=0)return r;let o=e.valueCount/(e.valueCount+t);return o*n+(1-o)*r}function cr(e,r,t=Math.random){if(e.length===0)return null;if(e.length===1)return e[0].arm;let n=null,o=-1/0;for(let s of e){let a=w(s.alpha,s.beta,t)*me(s,r);a>o&&(n=s,o=a)}return n.arm}var ge=/^[a-z0-9][a-z0-9_-]{0,31}$/;function de(e){if(typeof e!="string")return null;let r=e.trim().toLowerCase();return r&&ge.test(r)?r:null}var be=["unknown","__all__"];function xe(e){var r;return(r=de(e))!=null?r:R}var he=[],ye=64;function ve(e){var t;let r=new Map;for(let n of e)if(n.status!=="retired"){r.set(n.key,n.key);for(let o of(t=n.aliases)!=null?t:[])be.includes(o)||r.set(o,n.key)}return r}function mr(e,r=he){var i,u,p;let t=ve(r),n=(i=e.inferredConfidence)!=null?i:0,o,s=(p=(u=e.declared)==null?void 0:u.trim().toLowerCase())!=null?p:"";if(s!==""){let m=t.get(s);if(m!==void 0)return{persona:m,source:"declared",confidence:1};o=s.slice(0,ye)}let a=xe(e.clusterLabel);return a!==R&&t.has(a)?D({persona:t.get(a),source:"inferred",confidence:n},o!==void 0&&{unrecognizedDeclared:o}):D({persona:R,source:"none",confidence:n},o!==void 0&&{unrecognizedDeclared:o})}function gr(e){if(e==null)return R;let r=e.trim().toLowerCase();return r===""?R:r}export{he as DEFAULT_PERSONA_VOCABULARY,pe as EV_SHRINK_K,I as GLOBAL_FACTOR_LEVEL,ue as GLOBAL_FACTOR_PERSONA,oe as LAYOUT_ARCHETYPES,T as LAYOUT_ARCHETYPE_NAMES,G as LAYOUT_FACTOR_BUCKETS,ge as PERSONA_KEY_RE,M as POOL_ALL,be as RESERVED_PERSONA_KEYS,z as SHRINKAGE_M,Xe as SLOT_FACTORS,R as UNKNOWN_PERSONA,Ae as UNKNOWN_PERSONA_DISPLAY,le as WEIGHTS_FALLBACK_PRIOR_PULLS,ke as applyClusterHeuristic,Ie as broadestValueCell,U as candidateLayouts,X as canonicalArm,xe as canonicalPersona,Oe as chooseLayout,ie as chooseLayoutDetailed,Ye as chooseLayoutFactored,Je as chooseSlotArmFactored,ir as confidenceBand,gr as decisionPersona,qe as factorCellsForOrder,Qe as factorCellsForTrial,Z as factorLevelsFor,fe as fnv1a,N as hashLayout,W as layoutBucketOf,tr as marginalArmKey,de as normalizeDeclaredPersona,Y as orderByArchetype,J as parseArm,ar as pickDeterministicArm,Fe as pickFromWeights,Ke as pooledPosterior,S as posteriorOfCounts,ae as previewOrderForPersona,mr as resolvePersona,j as sampleArm,cr as sampleArmEv,w as sampleBeta,me as shrunkAvgValue,L as shrunkPosterior,ce as slotBaselineArm,or as slotResultFor,nr as validateSlotDecl,er as visitLevel,De as weightCellsFor};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentientui/policy",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "private": false,
5
5
  "description": "Pure decision-policy functions shared by the SentientUI API and the keyless local engine",
6
6
  "license": "MIT",