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/react

v0.3.1

Published

acpjs React hooks and Provider over @acpjs/client (headless, no UI).

Readme

@acpjs/react

React Provider + hooks for acpjs, built on @acpjs/client. Headless — no UI components, no state-library dependency. All reads go through useSyncExternalStore.

Install

pnpm add @acpjs/react @acpjs/client

ESM-only, node >= 24. Peer: react >= 19.

Usage

import { AcpProvider, usePermissionRequests, useSession } from '@acpjs/react'
import { AcpClientError } from '@acpjs/client'
import { client } from './acp-client.ts'

function App({ sessionId }: { sessionId: string }) {
  return (
    <AcpProvider client={client}>
      <Chat sessionId={sessionId} />
    </AcpProvider>
  )
}

function Chat({ sessionId }: { sessionId: string }) {
  const session = useSession(sessionId)
  const permissions = usePermissionRequests()
  if (!session) return null
  return (
    <>
      {session.state.messages.map((m, i) => (
        <p key={i}>{JSON.stringify(m.content)}</p>
      ))}
      <button
        onClick={() => void session.prompt([{ type: 'text', text: 'hi' }])}
      >
        Send
      </button>
      {permissions.map((r) => (
        <button
          key={r.requestId}
          onClick={() =>
            void r
              .respond({
                outcome: 'selected',
                optionId: r.options[0]?.optionId ?? '',
              })
              .catch((e) => {
                if (
                  e instanceof AcpClientError &&
                  e.code === 'acpjs/already-answered'
                )
                  return
                throw e
              })
          }
        >
          Allow
        </button>
      ))}
    </>
  )
}

Create the client once at module scope (not in a component — StrictMode double-invokes component bodies). In renderer use electronTransport(); in-process use createInProcessTransport(createHostEndpoint(host)).

Exports

Sealed surface (10 values, pinned by an API snapshot test):

  • <AcpProvider client={client}> — injects the client. Using any hook outside throws.
  • useAcpClient(): AcpClient
  • useAgent(agentId): AcpAgent | undefined
  • useAgents(): readonly AcpAgent[]
  • useSessions(): readonly AcpSession[]
  • useSession(sessionId): UseSessionResult | undefined — returns { sessionId, state, prompt, cancel, close, setMode, setConfigOption }; undefined until the client knows the session.
  • useConnectionStatus(): ConnectionStatusSnapshot
  • usePermissionRequests(): readonly PermissionRequest[]
  • useDiagnostics(): readonly DiagnosticEvent[]
  • shallowEqual(a, b): boolean — one-level structural compare for derived selectors.
  • Types: AcpProviderProps, UseSessionResult. Re-exported: SessionState, AgentSnapshot, SessionSnapshot, ConnectionStatusSnapshot, PermissionRequest, DiagnosticEvent.

Selecting a slice

Every read hook accepts an optional (selector, isEqual?). No selector → full snapshot. Default equality is Object.is; selector identity need not be stable (inline arrow is safe).

  • Whole top-level SessionState slices (messages, toolCalls, plan, connection, …) are reference-stable across unrelated updates (structural sharing) — selecting one needs no isEqual.
  • Pass shallowEqual the moment a selector derives/composes (s => ({ … }), filter/map/Object.values/slice):
const toolCalls = useSession('s', (s) => s.toolCalls)?.state // whole slice — Object.is is enough
const agentMsgs = useSession(
  's',
  (s) => s.messages.filter((m) => m.kind === 'agent'),
  shallowEqual,
)?.state // derived — needs shallowEqual

Key semantics

  • No tearing, no duplicate subscription under StrictMode/startTransition; unmount unsubscribes; references stable when nothing changes.
  • useSession(sessionId) does not accept undefined — pass '' as a placeholder while no session exists (client.sessions.get('') returns undefined), or conditionally render.
  • useAgent/useSession return undefined for unknown ids, then converge automatically via host projections.
  • Missing Provider throws a plain Error (not AcpClientError) — a usage error.
  • No SSR: no getServerSnapshot. Under Next.js App Router, components using hooks (including AcpProvider) must be in a 'use client' module.
  • Auth is not modeled; agent-side auth failures surface as agent errors.