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

@acpjs/client

v0.5.1

Published

acpjs typed facade, reducer-driven snapshot+subscribe store, and in-process transport.

Downloads

50

Readme

@acpjs/client

Typed facade + reducer-driven snapshot/subscribe store for acpjs. Environment-neutral; talks to any host purely through the acpjs HostClientTransport contract. Replays the normalized event stream with the pure reducer into SessionState.

Install

pnpm add @acpjs/client

ESM-only, node >= 24 (also browser/renderer-safe).

Usage (in-process)

import {
  createAcpClient,
  createInProcessTransport,
  AcpClientError,
} from '@acpjs/client'
import { createAcpHost, createHostEndpoint } from '@acpjs/core'

const host = createAcpHost()
const client = createAcpClient({
  transport: createInProcessTransport(createHostEndpoint(host)),
})

const agent = await client.agents.spawn({
  id: 'my-agent',
  command: 'npx',
  args: ['some-acp-agent'],
})
const session = await agent.sessions.create({
  cwd: process.cwd(),
  mcpServers: [],
  additionalDirectories: [],
})
session.subscribe(() => render(session.getSnapshot()))

client.permissions.subscribe((requests) => {
  for (const r of requests) {
    r.respond({
      outcome: 'selected',
      optionId: r.options[0]?.optionId ?? '',
    }).catch((e) => {
      if (e instanceof AcpClientError && e.code === 'acpjs/already-answered')
        return
      throw e
    })
  }
})

await session.prompt([{ type: 'text', text: 'hello' }])
await client.dispose()
await host.dispose() // in-process: host lifetime is independent of the client

Exports

Closed surface (pinned by an API snapshot test): createAcpClient, createInProcessTransport, AcpClientError. Re-exports from @acpjs/protocol: reduce, createInitialSessionState, and types AcpjsSessionEvent, SessionState, SessionEventOptions.

  • Types: AcpClient, AcpAgent, AcpSession, AcpAgentSessions, AgentDefinition, ConnectionStatusSnapshot, CreateAcpClientOptions, CreateOrLoadSessionParams, ResumeSessionParams, PermissionRequest, PermissionListener, ChangeListener, SessionConfigValue, SessionEventOptions, SessionListParams. Plus re-exported AgentSnapshot, SessionSnapshot, DiagnosticEvent, PromptFinishedPayload, RequestPermissionOutcome, SessionConfigOption, ContentBlock, ListSessionsResponse.

createAcpClient({ transport }): AcpClient

  • client.agentsspawn(definition): Promise<AcpAgent>, get(agentId), getSnapshot(): readonly AcpAgent[], subscribe(cb), list(): Promise<readonly AgentSnapshot[]>, attach(agentId): Promise<AcpAgent> (unknown → acpjs/agent-exited), dispose(agentId): Promise<void> (idempotent).
  • client.sessionsget(sessionId), getSnapshot(): readonly AcpSession[], subscribe(cb), list(): Promise<readonly SessionSnapshot[]>, attach(sessionId): Promise<AcpSession> (unknown → acpjs/session-closed), restore(): Promise<readonly SessionSnapshot[]>.
  • client.permissionsgetSnapshot(): readonly PermissionRequest[], subscribe((requests) => …). Each request carries requestId/sessionId/toolCall/options and respond(outcome).
  • client.diagnosticsgetSnapshot(): readonly DiagnosticEvent[] (bounded 200, oldest evicted), subscribe(cb).
  • client.statusgetSnapshot(): ConnectionStatusSnapshot (connecting/connected/closed, optional error), subscribe(cb).
  • client.dispose() — closes the transport; afterwards every call rejects with acpjs/transport-closed.

AcpAgent

  • agentId (readonly), getSnapshot(): AgentSnapshot, subscribe(cb).
  • authenticate(methodId): Promise<void>, logout(): Promise<void> (gated on auth.logout).
  • sessions.create({ cwd, mcpServers, additionalDirectories }) / load(id, …) / list({ cursor?, cwd? }) / resume(id, …) / delete(id).

AcpSession

  • sessionId (readonly), getSnapshot(): SessionState, subscribe((state) => …).
  • onEvent((event) => …, options?): () => void — independent read-only tap on the normalized stream; { fromSeq: 0 } replays the full log then streams live; omit for live-only.
  • prompt(ContentBlock[]): Promise<PromptFinishedPayload>, cancel(), close(), setMode(modeId), setConfigOption(configId, value).

Key semantics

  • No raw send. No raw host-envelope send, no raw notification subscription, no store selector. For projections the single SessionState can't express, use session.onEvent (with reduce/createInitialSessionState re-exported for one-import projections).
  • State construction: transport delivers AcpjsEventreduce replays in seq order; duplicate seq ignored; late subscribers backfill via fromSeq to deeply equal state.
  • subscribe never calls back immediately — read the initial value via getSnapshot/get. Same for agents/sessions/status/permissions/diagnostics.
  • Reactive mirror: agent/session registries mirror the host stream — a session created by another endpoint appears via session-updated; a disposed agent leaves via agent-removed.
  • Handle lifecycle: a live session reuses one frozen handle across create/load/resume/attach; a closed/deleted handle is dropped, and a later reopen builds a new handle.
  • Permissions: sourced from host permission-updated projections; leaves the pending set on respond, acpjs/already-answered, or answered/superseded projection. Under multi-client race, acpjs/already-answered is the normal path — ignore it.
  • Errors: every error is AcpClientError (ErrorObject shape: code (acpjs/*), message, data?, retryable). Auth failures during create/load/resume/prompt reject with acpjs/agent-error and the original error in data.
  • Slash commands: no invokeCommand — invoke by writing a /-prefixed text block in the prompt: session.prompt([{ type: 'text', text: '/web query' }]).