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

@sisu-ai/mw-control-flow

v12.0.0

Published

Express branching, routing, loops, and graphs in agent pipelines with explicit middleware control flow.

Readme

@sisu-ai/mw-control-flow

Express branching, routing, loops, and graphs in agent pipelines with explicit middleware control flow.

Tests CodeQL License Downloads PRs Welcome

Setup

npm i @sisu-ai/mw-control-flow

Documentation

Discover what you can do through examples or documentation. Check it out at https://github.com/finger-gun/sisu

API

  • sequence([a,b,c]): Run middlewares in order as one unit. Good for composing small steps into a named phase.
  • branch(pred, onTrue, onFalse?): Classic if/else routing. Pred is (ctx) => boolean.
  • switchCase(select, routes, fallback?): Route by key (ctx) => string to a middleware from routes.
  • loopWhile(pred, body, { max }): While-loop; evaluates pred(ctx) before each iteration.
  • loopUntil(done, body, { max }): Do-while; runs body at least once until done(ctx) returns true.
  • parallel([a,b], merge?): Fork the same ctx through branches concurrently, then merge(ctx, results).
  • graph(nodes, edges, start): Small DAG runner. Each node has an id and run(ctx, next). edges decide traversal.

Usage

import { sequence, branch, switchCase, loopUntil } from '@sisu-ai/mw-control-flow';

const decide = async (c, next) => { c.state.intent = c.input?.match(/tools/i) ? 'tool' : 'chat'; await next(); };
const toolFlow = sequence([/* tool loop */]);
const chatFlow = sequence([/* plain chat */]);

const app = new Agent()
  .use(decide)
  .use(switchCase(c => String(c.state.intent), { tool: toolFlow, chat: chatFlow }, chatFlow));

Branch

Use branch when a boolean predicate cleanly splits flow.

import { branch, sequence } from '@sisu-ai/mw-control-flow';

const playful = sequence([/* witty system prompt + generate */]);
const practical = sequence([/* pragmatic system prompt + generate */]);

app.use(branch(c => /joke|humor/i.test(c.input ?? ''), playful, practical));

switchCase

Route by an intent or mode string computed from context.

import { switchCase, sequence } from '@sisu-ai/mw-control-flow';

const classify = async (c, next) => { c.state.intent = /weather/.test(c.input ?? '') ? 'tool' : 'chat'; await next(); };
const toolPipeline = sequence([/* register tools, toolCalling, etc. */]);
const chatPipeline = sequence([/* plain completion */]);

app.use(classify).use(switchCase(c => c.state.intent, { tool: toolPipeline, chat: chatPipeline }, chatPipeline));

loopUntil / loopWhile

Iterate a sub-pipeline while a condition holds (with a safety cap).

import { loopUntil, sequence } from '@sisu-ai/mw-control-flow';

const decideIfMore = async (c, next) => { c.state.more = c.messages.at(-1)?.role === 'tool'; await next(); };
const body = sequence([/* toolCalling */ decideIfMore]);
app.use(loopUntil(c => !c.state.more, body, { max: 6 }));

graph

Encode multi-step flows as nodes + conditional edges (DAG). Good for “classify → handle → polish” shapes.

import { graph, type Node, type Edge } from '@sisu-ai/mw-control-flow';

const nodes: Node[] = [
  { id: 'classify', run: async (c, next) => { c.state.intent = pickIntent(c.input); await next(); } },
  { id: 'draft',    run: async (c) => {/* generate a plan */} },
  { id: 'chat',     run: async (c) => {/* simple completion */} },
  { id: 'polish',   run: async (c) => {/* refine output */} },
];
const edges: Edge[] = [
  { from: 'classify', to: 'draft', when: c => c.state.intent === 'draft' },
  { from: 'classify', to: 'chat',  when: c => c.state.intent !== 'draft' },
  { from: 'draft', to: 'polish' },
  { from: 'chat',  to: 'polish' },
];
app.use(graph(nodes, edges, 'classify'));

Notes

  • Keep node bodies small and reuse regular middlewares inside graph nodes where possible.
  • Prefer switchCase/branch for simple splits; reach for graph when you have 3+ phases or need to rejoin branches.

Community & Support

Discover what you can do through examples or documentation. Check it out at https://github.com/finger-gun/sisu. Example projects live under examples/ in the repo.


Documentation

CorePackage docs · Error types

AdaptersOpenAI · Anthropic · Ollama

Anthropichello · control-flow · stream · weather

Ollamahello · stream · vision · weather · web-search

OpenAIhello · weather · stream · vision · reasoning · react · control-flow · branch · parallel · graph · orchestration · orchestration-adaptive · guardrails · error-handling · rag-chroma · web-search · web-fetch · wikipedia · terminal · github-projects · server · aws-s3 · azure-blob


Contributing

We build Sisu in the open. Contributions welcome.

Contributing Guide · Report a Bug · Request a Feature · Code of Conduct


Star on GitHub if Sisu helps you build better agents.

Quiet, determined, relentlessly useful.

Apache 2.0 License