PAIPAI

@pai/storage-inmemory

Ephemeral in-process ThreadStore implementation.

Package: @pai/storage-inmemory

The simplest first-party ThreadStore implementation. All state lives in a JavaScript Map for the lifetime of the process. Nothing is persisted; threads disappear when the process exits.

Intended for:

  • unit tests that exercise the runtime against a real ThreadStore;
  • examples and demos;
  • short-lived scripts where durability is not required.

Not intended for production. Use @pai/storage-sqlite for transactional local persistence, @pai/storage-fs for simple JSON-file persistence, or a managed backend for shared deployments.

Quick start

import { createAgentRuntime } from "@pai/core";
import { createInMemoryThreadStore } from "@pai/storage-inmemory";

const runtime = createAgentRuntime({
  agent,
  scopeKey: (identity) => identity.workspaceId,
  storage: createInMemoryThreadStore(),
});

Options

type InMemoryThreadStoreOptions = {
  /** Override clock for tests. Defaults to `() => new Date()`. */
  now?: () => Date;

  /** Override thread-incarnation id generation for deterministic tests. */
  newThreadInstanceId?: () => string;
};

The store guarantees monotonic provider timestamps, full ThreadVersion compare-and-swap behavior, incarnation changes after delete/recreate, stable page tokens, and strict JSON validation within the process.

Conformance

createInMemoryThreadStore passes the full @pai/storage/test conformance suite. The package's own tests are wired through that suite:

import { createThreadStoreConformanceSuite } from "@pai/storage/test";
import { createInMemoryThreadStore } from "@pai/storage-inmemory";

createThreadStoreConformanceSuite({
  name: "createInMemoryThreadStore",
  createStore: () => createInMemoryThreadStore(),
});

On this page