npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@sentientui/policy

v0.3.3

Published

Pure decision-policy functions shared by the SentientUI API and the keyless local engine

Readme

@sentientui/policy

Pure decision-policy functions shared by the SentientUI API and the keyless local engine. This package is the single source of truth for how a decision is made — Thompson sampling, empirical-Bayes pooling/shrinkage, arm encoding, slot validation, and layout selection — so the server and the on-device engine always agree.

Everything here is a pure function: no I/O, no global state, no side effects. Randomized functions take an injectable rand: () => number (uniform [0,1)) so results are fully reproducible when you pass a seeded PRNG. The default is Math.random, which is non-deterministic — pass a seed for tests or replayable decisions.

What's inside

Bandit / Thompson sampling (bandit.ts)

  • sampleBeta(alpha, beta, rand?) — one draw from Beta(alpha, beta) (Marsaglia–Tsang gamma method).
  • sampleArm(arms, rand?) — Thompson-samples each arm's Beta posterior and returns the argmax arm id (or null for no arms).

Empirical-Bayes pooling & shrinkage (shrinkage.ts, pooling.ts)

  • shrunkPosterior(persona, pooled, m?) — one-axis read-time shrinkage; cells are born warm (w = m / (m + exposures)) and detach as their own data accumulates. SHRINKAGE_M is the default strength.
  • posteriorOfCounts({ exposures, conversions })Beta posterior from raw counts (alpha = conversions + 1, beta = max(0, exposures − conversions) + 1).
  • pooledPosterior(cells, personaKnown, m?) — hierarchical partial pooling over (segment, persona); reproduces legacy segment-only and persona-only behavior when only those cells are present. POOL_ALL is the __all__ sentinel for marginal/global rows.
  • weightCellsFor(...) — the write-side counterpart: which weight rows a single trial/credit must bump.

Arm encoding & slot validation (arm-encoding.ts)

  • canonicalArm(values) / parseArm(arm) — stable string encoding of a multi-dimensional arm and its inverse.
  • marginalArmKey(dim, value), slotBaselineArm(decl), slotResultFor(decl, arm) — arm helpers for a slot declaration.
  • validateSlotDecl(decl) — structural validation of a SlotDecl, returning { ok: true } or { ok: false, reason }.

Layout selection (layout-heuristics.ts, choose-layout.ts, hash.ts)

  • candidateLayouts(sections, sectionTypes, persona) — the candidate section orderings for a persona.
  • applyClusterHeuristic(sections, sectionTypes, persona) — the persona's heuristic ordering (CLUSTER_PRIORITY), used as the fallback.
  • chooseLayout(sections, sectionTypes, persona, learned, rand?) — Thompson-samples the learned layout posteriors over the candidates, falling back to the heuristic.
  • hashLayout(order) — stable hash of a section order (the layoutHash key).

Personas (personas.ts)

  • PERSONAS, PersonaKey, UNKNOWN_PERSONA, PERSONA_DISPLAY — the canonical persona set and display names.
  • canonicalPersona(label) — normalize an arbitrary/legacy label to a PersonaKey.

Deterministic helpers (deterministic.ts)

  • fnv1a(input) — FNV-1a hash.
  • pickDeterministicArm(sessionId, slotId, arms) — hash-based, seed-free arm pick (stable per session/slot).
  • confidenceBand(c) — map a [0,1] confidence to 'low' | 'medium' | 'high'.

Usage

import { sampleArm, posteriorOfCounts } from '@sentientui/policy';

// Thompson-sample the arm to serve from each arm's Beta posterior.
const arms = [
  { arm: 'control', ...posteriorOfCounts({ exposures: 200, conversions: 20 }) },
  { arm: 'variant_b', ...posteriorOfCounts({ exposures: 180, conversions: 27 }) },
];

const chosen = sampleArm(arms); // e.g. 'variant_b' — uses Math.random

// Pass a seeded PRNG for reproducible selection (tests, replayable decisions):
const chosenSeeded = sampleArm(arms, mySeededRng);
import { chooseLayout, hashLayout, type LearnedLayout } from '@sentientui/policy';

const learned = new Map<string, LearnedLayout>(); // from your layout_weights store
const order = chooseLayout(sections, sectionTypes, 'buyer', learned);
const key = hashLayout(order);

License

MIT