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 🙏

© 2025 – Pkg Stats / Ryan Hefner

acp-js-sdk

v1.0.1

Published

Agent Communication Protocol SDK for JavaScript

Readme

Agent Communication Protocol SDK for JavaScript

A pure JavaScript SDK for communicating with Agent Communication Protocol (ACP) servers.

Features

  • Pure JavaScript - No TypeScript dependencies, works in any JavaScript environment
  • Universal - Works in Node.js, browsers, and edge runtimes
  • Streaming Support - Full support for Server-Sent Events streaming
  • Session Management - Built-in session handling
  • Lightweight - Minimal dependencies, maximum performance
  • Well Documented - Complete JSDoc documentation for IDE support

Installation

npm install acp-sdk-js

Or with other package managers:

yarn add acp-sdk-js
pnpm install acp-sdk-js

Quick Start

import { Client } from 'acp-sdk-js';

// Create a client
const client = new Client({ 
  baseUrl: 'http://localhost:8000' 
});

// Run an agent synchronously
const run = await client.runSync('echo', 'Hello, World!');
console.log(run.output);

// Run an agent with streaming
for await (const event of client.runStream('echo', 'Hello, World!')) {
  console.log('Event:', event);
}

API Reference

Client

Constructor

const client = new Client({
  baseUrl: 'http://localhost:8000',  // ACP server URL
  fetch: customFetch,                // Optional custom fetch implementation
  sessionId: 'my-session'            // Optional session ID
});

Methods

Basic Operations
  • ping() - Check server connectivity
  • agents() - Get list of available agents
  • agent(name) - Get specific agent manifest
Agent Execution
  • runSync(agentName, input) - Run agent synchronously
  • runAsync(agentName, input) - Run agent asynchronously
  • runStream(agentName, input, signal?) - Run agent with streaming
Run Management
  • runStatus(runId) - Get run status
  • runEvents(runId) - Get run events
  • runCancel(runId) - Cancel a run
Run Resumption
  • runResumeSync(runId, awaitResume) - Resume run synchronously
  • runResumeAsync(runId, awaitResume) - Resume run asynchronously
  • runResumeStream(runId, awaitResume, signal?) - Resume run with streaming
Session Management
  • withSession(callback, sessionId?) - Execute callback with specific session
  • getSessionId() - Get current session ID

Examples

Basic Agent Execution

import { Client } from 'acp-sdk-js';

const client = new Client({ baseUrl: 'http://localhost:8000' });

// Simple text input
const result = await client.runSync('echo', 'Hello!');
console.log(result.output);

// Complex input with multiple messages
const complexResult = await client.runSync('analyzer', [
  { type: 'text', content: 'Analyze this data:' },
  { type: 'text', content: 'Data: [1, 2, 3, 4, 5]' }
]);

Streaming Events

// Stream events from agent execution
for await (const event of client.runStream('long-running-agent', 'input')) {
  switch (event.type) {
    case 'start':
      console.log('Agent started');
      break;
    case 'message':
      console.log('Message:', event.data);
      break;
    case 'end':
      console.log('Agent completed');
      break;
    case 'error':
      console.error('Error:', event.error);
      break;
  }
}

Session Management

// Execute multiple operations within the same session
await client.withSession(async (sessionClient) => {
  const run1 = await sessionClient.runSync('agent1', 'input1');
  const run2 = await sessionClient.runSync('agent2', 'input2');
  
  // Both runs share the same session context
  console.log('Session ID:', sessionClient.getSessionId());
});

Error Handling

import { Client, ACPError, HTTPError, FetchError } from 'acp-sdk-js';

try {
  const result = await client.runSync('nonexistent-agent', 'input');
} catch (error) {
  if (error instanceof ACPError) {
    console.error('ACP Error:', error.code, error.message);
  } else if (error instanceof HTTPError) {
    console.error('HTTP Error:', error.status, error.statusText);
  } else if (error instanceof FetchError) {
    console.error('Network Error:', error.message);
  } else {
    console.error('Unknown Error:', error);
  }
}

Custom Fetch Implementation

// Use custom fetch for special requirements
const client = new Client({
  baseUrl: 'http://localhost:8000',
  fetch: async (url, options) => {
    // Add custom headers, authentication, etc.
    return fetch(url, {
      ...options,
      headers: {
        ...options.headers,
        'Authorization': 'Bearer ' + token,
        'X-Custom-Header': 'value'
      }
    });
  }
});

Cancellation

// Cancel streaming operations
const controller = new AbortController();

// Start streaming
const streamPromise = (async () => {
  for await (const event of client.runStream('agent', 'input', controller.signal)) {
    console.log(event);
  }
})();

// Cancel after 5 seconds
setTimeout(() => {
  controller.abort();
}, 5000);

try {
  await streamPromise;
} catch (error) {
  if (error.name === 'AbortError') {
    console.log('Stream was cancelled');
  }
}

Constants

The SDK exports useful constants:

import {
  RunModes,
  EventTypes,
  RunStatuses,
  MessageTypes,
  ErrorCodes
} from 'acp-sdk-js';

console.log(RunModes.SYNC);      // 'sync'
console.log(EventTypes.START);   // 'start'
console.log(RunStatuses.RUNNING); // 'running'

Additional Information

This SDK is actively maintained and welcomes contributions. For issues, feature requests, or questions, please open an issue on the repository or contact the maintainers.