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

plato-sdk

v0.3.2

Published

JavaScript client for interacting with the Plato API

Readme

Plato JavaScript/TypeScript Client

A JavaScript/TypeScript client library for interacting with the Plato API. This library provides a simple interface for creating and managing browser automation environments.

Installation

npm install @plato-ai/client

Configuration

The client must be configured by passing options directly to the client constructor:

// Configure programmatically
const plato = new Plato('your_api_key', 'https://plato.so/api'); // API key is required, base URL is optional

Basic Usage

import { Plato } from 'plato-sdk';

async function main() {
  // Create a client instance with your API key
  const plato = new Plato('your_api_key');

  // Create a new environment
  const env = await plato.makeEnvironment('test-env');

  // Wait for the environment to be ready
  await env.waitForReady(60000); // timeout in ms (optional)

  // Get the CDP URL for browser automation
  const cdpUrl = await env.getCdpUrl();
  console.log('CDP URL:', cdpUrl);

  // Get the live view URL for visual monitoring
  const liveViewUrl = await env.getLiveViewUrl();
  console.log('Live View URL:', liveViewUrl);

  // Environment automatically sends heartbeats to keep it alive
  
  // When finished, close the environment - this also stops the heartbeats
  await env.close();
}

main().catch(console.error);

Playwright Integration

The library includes built-in support for Playwright browser automation:

import { Plato } from 'plato-sdk';
import { chromium } from 'playwright';

async function main() {
  // Create a client and environment
  const plato = new Plato('your_api_key');
  const env = await plato.makeEnvironment('playwright-test');
  
  // Wait for the environment to be ready
  await env.waitForReady();
  
  // Connect with Playwright using the built-in helper
  const { browser, context, page } = await env.connectWithPlaywright(chromium);
  
  // Use Playwright as normal
  await page.goto('https://example.com');
  await page.screenshot({ path: 'screenshot.png' });
  
  // Clean up
  await browser.close();
  await env.close();
}

main().catch(console.error);

Browser Usage

This library is compatible with browser environments. When using in a browser, simply import the package and provide your API key:

// In a browser environment
import { Plato } from 'plato-sdk';

// Create a client with your API key
const plato = new Plato('your_api_key');

// Use the client as normal
document.getElementById('createEnv').addEventListener('click', async () => {
  try {
    const env = await plato.makeEnvironment('browser-test');
    await env.waitForReady();
    const cdpUrl = await env.getCdpUrl();
    console.log('Environment ready with CDP URL:', cdpUrl);
  } catch (error) {
    console.error('Error:', error);
  }
});

Automatic Heartbeats

The environment automatically sends heartbeats to keep the environment alive, so you don't need to manually implement a heartbeat mechanism. When you call env.close(), the heartbeats are automatically stopped.

Advanced Usage

Environment Management

// Create an environment with custom configuration
const env = await plato.makeEnvironment('test-env');

// Check environment status
const status = await env.getStatus();
console.log('Environment Status:', status);

// Reset environment
await env.reset();

// Get environment state
const state = await env.getState();
console.log('Environment State:', state);

Worker Management

// Check if worker is ready
const workerStatus = await plato.getWorkerReady(env.id);
if (workerStatus.ready) {
  console.log('Worker is ready');
  console.log('Worker Public IP:', workerStatus.worker_public_ip);
}

// Heartbeats are sent automatically, you don't need to do this manually

Error Handling

The library includes built-in error handling with custom error types:

import { Plato, PlatoClientError } from '@plato-ai/client';

async function main() {
  try {
    const plato = new Plato('invalid_api_key');
    await plato.makeEnvironment('test-env');
  } catch (error) {
    if (error instanceof PlatoClientError) {
      console.error('Plato API Error:', error.message);
    } else {
      console.error('Unexpected error:', error);
    }
  }
}

Examples

Check out the examples directory for more detailed usage examples:

  • Basic environment creation and management
  • Browser automation with CDP
  • Worker management and monitoring
  • Error handling and recovery

API Reference

Plato

Main client class for interacting with the Plato API.

Constructor

  • constructor(apiKey: string, baseUrl?: string)

Methods

  • makeEnvironment(envId: string): Promise<PlatoEnvironment>
  • getJobStatus(jobId: string): Promise<any>
  • getCdpUrl(jobId: string): Promise<string>
  • closeEnvironment(jobId: string): Promise<any>
  • resetEnvironment(jobId: string, task?: PlatoTask): Promise<any>
  • getEnvironmentState(jobId: string): Promise<any>
  • getWorkerReady(jobId: string): Promise<WorkerReadyResponse>
  • getLiveViewUrl(jobId: string): Promise<string>
  • sendHeartbeat(jobId: string): Promise<any>

PlatoEnvironment

Class representing a Plato environment instance.

Methods

  • getStatus(): Promise<any>
  • getCdpUrl(): Promise<string>
  • close(): Promise<any>
  • reset(task?: PlatoTask): Promise<any>
  • getState(): Promise<any>
  • getLiveViewUrl(): Promise<string>
  • waitForReady(timeout?: number): Promise<void>
  • connectWithPlaywright(playwrightLib: any): Promise<{ browser, context, page }>

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT