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

@agent-assistant/sessions

v0.4.33

Published

Session lifecycle, storage, and affinity for Agent Assistant SDK

Readme

@agent-assistant/sessions

@agent-assistant/sessions owns assistant session continuity across surfaces and time. It provides spec-aligned session types, a session store factory, an in-memory adapter for local use and tests, and a small affinity helper for lookup-or-create flows.

Scope

This package owns:

  • session identity and lifecycle state
  • surface attachment and detachment
  • stale-session suspension and explicit expiry
  • metadata updates
  • affinity-based session reuse helpers

This package does not own:

  • memory retrieval or storage
  • routing policy decisions
  • surface protocol implementations
  • cloud storage implementations
  • product-specific rules

Install Shape

The package is TypeScript-first and builds to dist/.

import {
  InMemorySessionStoreAdapter,
  createSessionStore,
  defaultAffinityResolver,
  resolveSession,
} from '@agent-assistant/sessions';

Core API

createSessionStore(config)

Creates a SessionStore from an injected SessionStoreAdapter.

Supported operations:

  • create
  • get
  • find
  • touch
  • attachSurface
  • detachSurface
  • expire
  • sweepStale
  • updateMetadata

Default TTL is one hour if defaultTtlMs is not provided.

InMemorySessionStoreAdapter

Local adapter backed by an in-memory Map. It deep-clones reads and writes so callers cannot mutate stored session state accidentally. This is the default adapter to use for tests and isolated local execution.

defaultAffinityResolver(store)

Returns an AffinityResolver that prefers the most recently active or suspended session for a user, and prefers a matching attached surface when one is provided.

resolveSession(message, store, resolver)

Looks up an existing session through an affinity resolver and touches it when found. If no session is resolved, it creates a new one using the inbound userId, optional workspaceId, and surfaceId.

Example

import {
  InMemorySessionStoreAdapter,
  createSessionStore,
  defaultAffinityResolver,
  resolveSession,
} from '@agent-assistant/sessions';

const store = createSessionStore({
  adapter: new InMemorySessionStoreAdapter(),
  defaultTtlMs: 30 * 60 * 1000,
});

const resolver = defaultAffinityResolver(store);

const session = await resolveSession(
  {
    userId: 'user-123',
    workspaceId: 'workspace-456',
    surfaceId: 'web-thread-1',
  },
  store,
  resolver,
);

await store.attachSurface(session.id, 'slack-dm-99');
await store.updateMetadata(session.id, { locale: 'en-US' });

Core Integration

The store returned by createSessionStore is structurally compatible with core runtime registration:

runtime.register('sessions', store);

Core can then use store.get(sessionId) during emit and session lookup flows because returned sessions include attachedSurfaces.

Development

Run inside packages/sessions:

npm test
npm run build

SESSIONS_PACKAGE_IMPLEMENTED