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

memoir-npc

v0.1.2

Published

Give AI game NPCs persistent, long-term memory across sessions. A thin, typed bridge over Supermemory Local.

Readme

 ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄ ▄▄▄▄▄▄▄
 █ ▄ ▄ █ █ ▄▄▄▄█ █ ▄ ▄ █ █ ▄▄▄ █   █   █ ▄▄▄ █
 █ █ █ █ █ ▄▄▄█▄ █ █ █ █ █ █▄█ █   █   █ ▄ ▄▄█
 █▄█▀█▄█ █▄▄▄▄▄█ █▄█▀█▄█ █▄▄▄▄▄█ █▄▄▄█ █▄█▄▄▄█

Memoir

npm version MIT License Engine

Memoir is a high-speed, developer-centric Narrative AI Framework built directly on top of the Supermemory AI memory engine. It gives AI game NPCs persistent, long-term memory across sessions by wrapping Supermemory Local (a self-hosted memory engine) and supplying advanced character guardrail systems.

Install it, configure your character locks, and every NPC in your game remembers every player interaction and stays perfectly in character, with no manual database schema or prompt engineering.


Features Overview

  • Persistent Context Memory: Automatically saves NPC-Player interactions. NPCs recall quest choices, player items, and history across scenes.
  • Persona Locking via Tags: Lock your NPCs into rigid psychological profiles (archetype, attachment style, stubbornness, tone) using system envelopes.
  • Proximity Gossip Network: Interconnect NPC memory databases. When the player tells a secret to one character, it can leak as a rumor to neighboring NPCs automatically.
  • Structured Chat Driver: Intercepts LLM calls, recalls context, checks locks, generates dialogues, parses emotion/action tags, and updates the database in a single step.
  • Resilient Auto-Retries: Automated one-time retry (300ms delay) for transient connection drops and timeouts.

Installation

npm install memoir-npc

Prerequisites

Memoir requires Supermemory Local running on your machine. Start it in your terminal:

npx supermemory local

It runs at http://localhost:6767 by default. See Supermemory's documentation for full setup instructions.


Core Usage

1. Initialize and Define Personas

import { Memoir } from "memoir-npc";

// Initialize Memoir pointing to local Supermemory and Gemini
const memoir = new Memoir({
  supermemoryApiKey: "your_supermemory_api_key",
  geminiApiKey: "your_gemini_api_key",
  supermemoryBaseUrl: "http://localhost:6767"
});

// Configure psychological guardrails for a character
memoir.lockPersona("mom_npc", {
  archetype: "protective_parent",
  attachmentStyle: "anxious",
  stubbornness: "high",
  tone: "warm but strict",
  description: "Caring mother who hates screens and wants the player home early."
});

memoir.lockPersona("guard_npc", {
  archetype: "corrupt_guard",
  stubbornness: "high",
  tone: "cynical"
});

2. Configure the Proximity Gossip Network

Establish connection paths and leak probabilities between NPC containers:

// If the player tells a secret to Mom, she might leak it to the Guard
memoir.createSocialLink("mom_npc", "guard_npc", {
  relationship: "neighbors",
  leakChance: 0.7
});

3. Handle Dialogues with Structured Output

Use the chat method to query memory, check guardrails, call the LLM, evaluate actions, and save the interaction automatically:

const npc = memoir.npc("mom_npc");

const response = await npc.chat("player-1", "I am leaving for the hackathon.");

console.log(response.text);   // In-character speech (e.g. "Come back early!")
console.log(response.emote);  // Extracted emotion (e.g. "worried")
console.log(response.action); // Action tag (e.g. "none")

Technical Architecture

Here is the data loop orchestration between your game code, Memoir SDK, and the Supermemory database engine during runtime:

+-----------------------------------------------------------------+
|                        YOUR GAME ENGINE                         |
|      (Dialogue Loops, Quest Handlers, NPC AI controllers)       |
+---------------+---------------------------------+---------------+
                |                                 ^
                | 1. chat(playerId, input)        | 4. Returns:
                |    (Triggers LLM generation)    |    { text, emote, action }
                v                                 |
+-------------------------------------------------+---------------+
|                         MEMOIR SDK                              |
|                                                                 |
|  +--------------------+                    +----------------+   |
|  |  NpcHandle Scoper  |                    | Persona Engine |   |
|  |  (Tag: npc:${id})  |                    |  (Guardrails)  |   |
|  +--------+-----------+                    +-------+--------+   |
|           |                                        |            |
|           | 2. query database                      | 3. run LLM |
|           v                                        v            |
|  +--------------------+                    +----------------+   |
|  | Supermemory Client |                    | Gemini Client  |   |
|  +--------+-----------+                    +----------------+   |
|           |                                                     |
+-----------|-----------------------------------------------------+
            v
+-----------------------------------------------------------------+
|                        SUPERMEMORY LOCAL                        |
|           (Vector Database, Graph Store, SQLite)                |
+-----------------------------------------------------------------+

API Reference

new Memoir(config: MemoirConfig)

Creates a new Memoir context instance.

  • supermemoryApiKey: string - API token for Supermemory Local.
  • geminiApiKey?: string - API key for Gemini models.
  • supermemoryBaseUrl?: string - Base path of your Supermemory server (defaults to http://localhost:6767).
  • requestTimeoutMs?: number - Request timeout limit (default: 5000ms).
  • strict?: boolean - If true, throws errors rather than degrading gracefully on network failure.

memoir.lockPersona(npcId: string, config: PersonaConfig)

Binds rigid psychological constraints to an NPC.

  • archetype: string - Core role profile.
  • attachmentStyle?: string - Psychological attachment type.
  • stubbornness?: string - Character resistance level.
  • tone?: string - Speech style.

memoir.createSocialLink(npcIdA: string, npcIdB: string, options: { relationship: string, leakChance: number })

Binds two NPCs in a social network gossip connection. When interactions are saved to npcIdA, a processed rumor will be generated and saved to npcIdB according to the leakChance rate.

npc.chat(playerId: string, playerInput: string): Promise<ChatResponse>

Queries memories, generates dialogues in-character, extracts emotions/actions, saves interactions to databases, and executes gossip propagation in a single invocation.

  • playerId: string - Unique user ID.
  • playerInput: string - Player dialogue string.
  • Returns: Promise<{ text: string, emote: string, action: string }>

License

MIT