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

@ai-digital-factory/state-flow-client

v0.2.0

Published

Browser client host for State Flow: in-memory client instances for the life of the page, and history reported to State Flow Cloud.

Readme

@ai-digital-factory/state-flow-client

The browser host for client Flows (<Flow runs="client">, ADR 0097, 0100, 0104, 0108). Client instances live in memory for the life of the page; lasting truth lives in server Flows.

import { createClientHost } from "@ai-digital-factory/state-flow-client";
import loanRequest from "@acme/client-handlers/loan-request";

const host = createClientHost({
  // Optional: report this page's Flow histories to State Flow Cloud.
  cloud: { url: "https://cloud.example.com", publishableKey: "sfp_…" },
});
const flow = await host.createFlow(loanRequest, {
  applicationId: () => "loan:A-17",
  // The application's own route to the server Flow (ADR 0108).
  submitApplication: (request) => api.submitApplication(request),
});
// A Flow with an inputSchema also takes `input`, validated and kept with the instance (ADR 0102).
const form = await flow.ensureInstance({ instanceId: "loan-form:A-17" });
// Same builder as the server (ADR 0107).
const submitted = await form
  .when("amount")
  .transition("submit-request")
  .tags({ traceId: crypto.randomUUID() }) // typed by the package's tags.ts (ADR 0108)
  .payload({ amount: 25000 })
  .run({
    "invalid-payload": () => "Some values are not valid.",
    otherwise: (refusal) =>
      refusal.kind === "retry"
        ? "Please try again."
        : "That did not go through.",
  });
  • Typed registration: createFlow takes a compiled client module from state-flow compile and dependencies implementing its interfaces; a durable module or missing dependencies do not compile. Instances, scopes (instance.scope(...)), snapshots, data, payloads and refusal handlers keep the compiled types.
  • Page-lifetime instances (ADR 0104): nothing is saved in the browser. ensureInstance creates the instance in this page or returns the one the page holds; a reload or another tab starts fresh. Choose the start State from lasting truth (a server Flow, the application's database) in resolveStartState, through the Flow's dependencies, and give server instances a business identity (application:A-17) so a repeated submit after a reload reaches the same server instance instead of creating another.
  • The network is the application's (ADR 0108): an effect reaches a server Flow through whatever the application gives it as a dependency: its own route, tRPC, a queue. Effects receive context.executionId (an idempotency key) and context.tags to carry along: the server dispatches with .tags(...), so State Flow Cloud finds both histories by the same tag. When the application learns of a server change (polling, push, focus), it dispatches the browser Transition itself. Type routes with PayloadOf, ResultOf and RefusalOf from @ai-digital-factory/state-flow-runtime, imported with import type.
  • No retries: effects are plain async functions; a failure leaves the source State committed.
  • Tags (ADR 0108): a package declares in src/tags.ts the labels its calls carry (tagsSchema, string fields). ensureInstance({ tags }) and .tags(...) on a dispatch take them, typed and required as the schema says; every callback of the work the call starts receives them as context.tags, the history records them and Cloud finds instances by them. They are reported unredacted, so never put personal or secret values in them.
  • Refusal kinds: every refusal carries kind: retry (the same request may be sent again), rejected or failed.
  • Reported history: with cloud, every dispatch and how it ended is reported to State Flow Cloud with the web application's publishable key, each entry with a stable ID and the release of its Flow model (a digest of the model's content), so retries never duplicate or reorder history and a model is never replaced. The host sends each model with its first report and flushes small batches when the page is hidden. Reports are best effort: entries still queued when the page goes away are lost. Secret fields (secretField) are never recorded; private fields (privateField) stay in the browser and are redacted before reporting. Without cloud, nothing leaves the browser. A secret application key (sfk_…) is refused.

React bindings live in @ai-digital-factory/state-flow-react.