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

@pocketflow/core

v0.3.0

Published

Core package for PocketFlow.js - A minimal LLM framework

Readme

PocketFlow.js

A minimal LLM workflow framework written in TypeScript. This is a port of PocketFlow from Python to TypeScript.

Features

  • 🚀 Simple and lightweight workflow framework
  • 🔌 Composable nodes and flows
  • 🔄 Support for retries and fallbacks
  • ⚡ Sequential and parallel batch processing
  • 🪝 Lifecycle hooks for logging, metrics, and debugging
  • 🎯 Type-safe with TypeScript generics

Installation

npm install @pocketflow/core

Quick Start

A workflow is built from nodes connected into a flow. Each node has three lifecycle methods:

  • prep(shared) — read from shared state, return input for exec
  • exec(prepRes) — do the work (e.g. call an LLM)
  • post(shared, prepRes, execRes) — write results to shared state, return an action string that decides which node runs next
import { Node, Flow } from "@pocketflow/core";

interface Shared {
  topic: string;
  outline?: string;
  essay?: string;
}

class WriteOutline extends Node<Shared> {
  async prep(shared: Shared) {
    return shared.topic;
  }
  async exec(topic: string) {
    return callLLM(`Write an outline about ${topic}`);
  }
  async post(shared: Shared, _prep: string, outline: string) {
    shared.outline = outline;
    return "default"; // action -> next node
  }
}

class WriteEssay extends Node<Shared> {
  async prep(shared: Shared) {
    return shared.outline;
  }
  async exec(outline: string) {
    return callLLM(`Write an essay from this outline:\n${outline}`);
  }
  async post(shared: Shared, _prep: string, essay: string) {
    shared.essay = essay;
  }
}

const outline = new WriteOutline();
const essay = new WriteEssay();
outline.connect(essay); // default transition

const shared: Shared = { topic: "TypeScript" };
await new Flow(outline).run(shared);
console.log(shared.essay);

Branching

post() returns an action string. Use transition(action).to(node) to branch:

review.transition("approved").to(publish);
review.transition("rejected").to(rewrite);
rewrite.connect(review); // loop back for another review

Self-loops are supported — a node can transition back to itself.

Retries and Fallbacks

Node takes maxRetries and wait (ms between attempts). If all retries fail, execFallback() is called:

class CallModel extends Node {
  constructor() {
    super(3, 1000); // 3 attempts, 1s between
  }
  async exec(prompt: string) {
    return callLLM(prompt);
  }
  async execFallback(prompt: string, err: unknown) {
    return "Sorry, the model is unavailable.";
  }
}

Batch Processing

BatchNode runs exec() once per item, sequentially. ParallelBatchNode runs items concurrently with a configurable limit:

import { ParallelBatchNode } from "@pocketflow/core";

class Summarize extends ParallelBatchNode {
  constructor() {
    super(1, 0, 5); // maxRetries, wait, concurrency
  }
  async prep(shared: any) {
    return shared.documents; // array of items
  }
  async exec(doc: string) {
    return callLLM(`Summarize: ${doc}`);
  }
  async post(shared: any, _prep: any, summaries: string[]) {
    shared.summaries = summaries; // results preserve input order
  }
}

BatchFlow runs an entire flow once per param set returned by its prep().

Lifecycle Hooks

Observe flow execution without touching node code:

const flow = new Flow(start, {
  onFlowStart: (shared) => console.log("flow started"),
  onNodeStart: (node) => console.log(`-> ${node.constructor.name}`),
  onNodeEnd: (node, action) => console.log(`<- ${node.constructor.name} (${action})`),
  onNodeError: (node, err) => console.error(`error in ${node.constructor.name}`, err),
  onFlowEnd: (shared) => console.log("flow finished"),
});

Visualization

The @pocketflow/viz package renders an interactive graph of your flow:

import { visualize } from "@pocketflow/viz";

await visualize(flow); // opens http://localhost:3000

API Summary

| Class | Purpose | |-------|---------| | BaseNode | Core lifecycle (prep/exec/post) and successor wiring | | Node | Adds retries, wait between attempts, and execFallback | | BatchNode | Runs exec per item, sequentially | | ParallelBatchNode | Runs exec per item, in parallel with a concurrency limit | | Flow | Orchestrates a node graph following returned actions | | BatchFlow | Runs a flow once per param set |

Examples

See the examples directory for complete, runnable examples.

Development

pnpm install
pnpm build   # build all packages
pnpm test    # run tests
pnpm lint    # lint all packages

License

MIT