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

@centlu/agent-core

v1.1.17

Published

Core TypeScript types for Bun-based agents.

Downloads

4,700

Readme

Agent Core

Requires Bun 1.4.0 or later for native Temporal support.

Agent Events

See the frontend event integration guide for JSON shapes, rendering rules, and a multi-turn example.

AgentEvent is a hand-written contract shared by adapters, history stores, and listeners. Event IDs identify individual events. seq increases for the lifetime of an adapter instance, and timestamp records conversion time in Unix milliseconds.

Oh My Pi keeps the same runId across run.paused and run.resumed. A new Pi run after a terminal event gets a new ID. Disposing the adapter ends any still-open run as cancelled. Automatic retry events report scheduled attempts and their overall outcome. Manual and automatic context compaction report start and end, including skips and cancellations. Idle compaction has no runId.

Live message.ended carries the complete message content, messageId, and role. Assistant completions carry per-message usage in both the live and stored events. The manager discards message.delta events. Tool updates carry replaceable snapshots and use toolCallId to correlate concurrent calls.

AgentEventListener delivers complete messages, tool calls, progress, results, and lifecycle status through the listener's send queue.

Create the manager with createManagerBuilder(dir).build() for the single-process Node.js/Bun file-backed default, or compose custom adapters with .persistence(...), .lock(...), and .lockTimeout(...). See Persistence and Session Lock Adapter Contract for the Redis/MySQL adapter specification. Bind one listener per session with manager.bindListener(sessionId, listener). A duplicate bind leaves the current listener active and returns a no-op cleanup function. Call the returned function when the connection closes. The binding lasts until explicitly removed, including across submissions and session restarts. In a multi-Pod deployment, bind on the manager running the session or forward events from that Pod through the application.

History stores receive the original non-delta events. The payload of context.compaction.result carries sdk (AgentSdk.OhMyPi serializes as "oh-my-pi"), a summary when available, and opaque JSON entries for restoration. This event is stored without being delivered to listeners. Call await manager.loadHistory(sessionId) for read-only history playback through the manager's configured persistence; it automatically omits context.compaction.result and strips legacy payload.entries from context.compaction.ended. Listeners receive context.compaction.started and context.compaction.ended to display compaction status. Live delivery proceeds independently of history writes. The listener's seq orders live delivery within each binding and running session.

When the manager opens a session, it restores the latest compatible compaction snapshot and replays later message and tool events from the same session in append order. Oh My Pi reads payload.sdk and falls back to the legacy top-level sdk. It accepts "oh-my-pi" snapshots and legacy snapshots without sdk. It skips snapshots from other SDKs. Without a compatible snapshot, it reconstructs messages and tool results from the entire stored stream. A compaction snapshot contains retained entries, the summary when present, and any provider-native compaction data.

Compaction Configuration

The Oh My Pi adapter configures automatic compaction in src/agent/oh-my-pi/settings.ts. Each session tries eligible methods in this order: remote, handoff, shake, soft. The soft method is reported as context-full in events.

Custom MCP Configuration

Set SubmitRequest.options.mcpJsonPath to load a JSON file with an mcpServers object when the agent session starts. Absolute paths are used directly; relative paths such as config/mcp.json are resolved against SubmitRequest.options.cwd. If the path is omitted or empty, no MCP config is loaded. Only use a trusted config file: it can start local processes.

TurnConfig contains serializable model settings. Pass the API key separately as SubmitRequest.credentials.apiKey; SessionManager removes credentials before writing the resulting Submission to HistoryStore.

Session Skills

Create a manager with the chainable builder. Unset persistence defaults to local file storage when dir is provided and local memory otherwise:

const manager = createManagerBuilder("/absolute/path/to/data")
    .persistence(persistence) // optional: combined Persistence or { history?, pending?, life? }
    .lock(lock)               // optional: SessionLock (defaults to in-process mutex)
    .lockTimeout(5_000)       // optional: lock-wait timeout in ms
    .skill({
        skillsPath: "/absolute/path/to/skills",
        allowSkills: ["review", {"skill-a": "latest"}],
    })
    .build()

skillsPath is normally an absolute readable directory. If it is missing or unreadable, the manager emits a warning and uses an empty catalog; if skill is omitted, the catalog is empty. manager.getSkills() and manager.getSkill(name, path) expose the current catalog without requiring a session. When allowSkills is omitted, it defaults to "*": all flat skills and the latest version from each version group load. allowSkills accepts a selector string, an array of strings and/or objects, or an object mapping patterns to versions. A string uses pattern[:version]; an object uses the pattern as its key and version as its value. An omitted version, an empty version, or latest selects the highest version. An explicit version selects only that version. Empty arrays and objects select no skills.

Patterns match only the immediate directory name under skillsPath; frontmatter name is still used as the skill's loaded name, but does not participate in selection. * is the only wildcard, may appear anywhere in a pattern, and matches zero or more characters; other characters are literal and matching is case-sensitive. This lets the catalog loader filter unrelated directories before reading their skill files. Flat skills use <skillsPath>/<name>/SKILL.md; versioned skills use <skillsPath>/<group>/<version>/SKILL.md. Version directories must contain only numeric dot-separated segments such as 01, 1, 1.2, or 1.2.3. The filename must be exactly SKILL.md (uppercase). Versions are compared numerically by dot-separated segment, with missing segments treated as zero; numerically equal directory names use lexical order as a stable tie-breaker. An explicit version reads only its matching directory. latest tries version directories from highest to lowest in batches of four, choosing the highest valid skill in the first batch with a valid candidate; it proceeds to older batches only when the current batch has no valid skill. A group with one or more numeric version directories is versioned, so its own flat SKILL.md is never loaded; flat skills are loaded only when the group has no numeric version directories.

Each immediate directory activates at most one skill version. If multiple selectors match it, an explicit version outranks latest, a non-wildcard pattern outranks a wildcard pattern, and earlier selectors in array/object insertion order win remaining ties. Unmatched skills and selectors are skipped. To invoke a loaded skill, include its exact [$name](absolute-SKILL.md-path) mention in the prompt. Matching skills are added before the original prompt as numbered Markdown sections under a # Skills heading; the original prompt follows under # User Request. Unknown mentions remain unchanged and are ignored.

Active Sessions

await manager.getActiveSessions() returns the active {sessionId, ownerId} records from AgentLife, including other Pods when the adapter uses shared liveness records. The in-memory adapter supports this query. Custom adapters can implement AgentLife.getActiveSessions() using the same liveness rules as alive. The manager returns an empty list if the adapter omits this method.

Session Close

SessionManager.close(id) gracefully drains the session. A close from another Pod uses the shared HistoryStore pending queue and waits up to 30 seconds for disposal to finish or for the targeted owner to leave. It throws on timeout or if the owner reports a disposal failure.

For multi-Pod deployments, all managers must use the same pending queues and shared AgentLife liveness records. Store the ownerId passed to AgentLife.report, return it from alive, and implement release to clear the record when its owner matches. This scopes a close to the running instance even if the session is later reopened. A HistoryStore adapter must round-trip each PendingMessage variant under its session key, including the reply queues under the reserved @agent-core/close/ prefix. Adapters can expire close requests and replies using their expiresAt timestamps. Update all Pod versions and store adapters before routing cross-Pod close requests.

Run Lifetime and Queued Inputs

Each active run owns one agent instance and one run-scoped skill snapshot. The manager keeps the shared pending queue receiver active while that agent is working, so user-input operations with steer, followup, or aside modes are delivered as soon as they arrive without pausing streamed output. A session-close received from another Pod interrupts the agent, flushes history, disposes the run, and posts the close result to its reply queue. Calling manager.close(id) uses the same cleanup path for an early local interruption.

When the SDK becomes idle, the manager cancels its queue wait, acquires the per-session SessionLock, and performs its final pending-message recall. If messages exist for the active generation, it releases the lock and recreates the agent to process them; if the queue is empty, it holds the lock through draining, agent disposal, final history writes, and ownership release so submissions either become visible before the final recall or wait until release before starting the next owner. submit() returns once the message is durably enqueued (throwing SubmissionError on lock timeout or persistence failure without background enqueueing), and stale-generation pending records are ignored/removed on takeover. Call await manager.loadPending(sessionId) for a non-destructive snapshot of active queued Submission items (excluding internal close control messages and stale generations). See docs/persistence-contract.md for full persistence, CAS, fencing, and locking semantics. Subsequent input (including user-resume) creates a new agent, restores stored history, and invokes the adapter's normal SDK resume behavior for resume operations.

Skill Refresh and Failures

Skill catalogs are cached by normalized skillsPath and allowSkills, using a metadata fingerprint of directory entries and skill files. Manager skill queries and each new run refresh that fingerprint; unchanged metadata reuses the parsed catalog, while new version directories or changed SKILL.md files cause a reload. Malformed individual skills are skipped with warnings so they cannot prevent an agent from starting.