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

@awesome-ecs/ai

v0.32.1

Published

Extension of the @awesome-ecs framework with design-patterns useful for AI implementations.

Readme

Awesome ECS - AI Package

Overview

The AI package provides design patterns and abstractions for building intelligent AI systems within the ECS framework. It focuses on state machines rather than specific AI algorithms, allowing flexible composition of AI behaviors.

Key capabilities:

  • Finite State Machines (FSM) for behavior control
  • State transitions and state factories
  • Integration with core ECS entities and systems

Core Concepts

State Machine (src/abstract/state-machine.ts)

The State Machine pattern provides non-linear execution of system middlewares:

export interface IStateMachine<TEntity extends IEntity> {
  readonly currentState?: IState<TEntity>;
  readonly globalState?: IState<TEntity>;
  readonly previousState?: IState<TEntity>;

  setCurrentState(uid: StateUid): void;
  setGlobalState(uid: StateUid): void;
  changeState(uid: StateUid): void;
  revertState(): void;
  isInState(uid: StateUid): boolean;
  update(context: ISystemContext<TEntity>): void;
}

Key difference from Pipelines:

  • Pipelines execute middleware in a linear, ordered sequence
  • State Machines execute only the active state — non-linear, branched execution

State (src/abstract/state.ts)

States represent discrete behaviors that an entity can be in:

export interface IState<TEntity extends IEntity> {
  readonly uid: StateUid;

  enter?(context: ISystemContext<TEntity>): void;   // Called on transition in
  execute(context: ISystemContext<TEntity>): void;   // Called every frame while active
  exit?(context: ISystemContext<TEntity>): void;     // Called on transition out
}

State Factory (src/abstract/state-factory.ts)

Factory pattern for creating and managing states:

export interface IStateFactory<TEntity extends IEntity> {
  create(uid: StateUid): IState<TEntity>;
  get(uid: StateUid): IState<TEntity>;
}

Helpers (src/helpers/)

Utility functions for state machine construction and common state operations.

Usage Pattern

1. Define States

export enum CreatureState { idle = 'IDLE', moving = 'MOVING', attacking = 'ATTACKING' }

export class IdleState implements IState<CreatureEntity> {
  readonly uid = CreatureState.idle;

  execute(context: ISystemContext<CreatureEntity>): void {
    // Check conditions and transition if needed
    context.entity.stateMachine.changeState(CreatureState.attacking);
  }
}

export class MovingState implements IState<CreatureEntity> {
  readonly uid = CreatureState.moving;

  execute(context: ISystemContext<CreatureEntity>): void { /* movement logic */ }
  exit(context: ISystemContext<CreatureEntity>): void    { /* cleanup */        }
}

2. Create State Factory

export class CreatureStateFactory implements IStateFactory<CreatureEntity> {
  private states = new Map<StateUid, IState<CreatureEntity>>([
    [CreatureState.idle,      new IdleState()],
    [CreatureState.moving,    new MovingState()],
    [CreatureState.attacking, new AttackingState()],
  ]);

  create(uid: StateUid): IState<CreatureEntity> { return this.states.get(uid)!; }
  get(uid: StateUid):    IState<CreatureEntity> { return this.states.get(uid)!; }
}

3. Drive from a System Middleware

export class CreatureStateMachineSystem implements ISystemMiddleware<CreatureEntity> {
  action(context: ISystemContext<CreatureEntity>): void {
    context.entity.stateMachine.update(context);
  }
}

Register in the update phase of the creature module.

Package Structure

src/
├── abstract/   # IStateMachine, IState, IStateFactory interfaces
└── helpers/    # StateMachine implementation and utilities

When to Use State Machines

Good for:

  • Discrete entity behaviors (idle, moving, attacking)
  • Clear state transitions
  • Non-linear execution (not every frame doing everything)

Not ideal for:

  • Linear pipelines (use Pipelines instead)
  • Simple data transformations (use Systems instead)

Relationship to Other Packages

  • Uses: @awesome-ecs/abstract
  • Works with: @awesome-ecs/workers for offloading AI calculations to background threads