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

@cimulate/copilot-sdk

v3.10.1

Published

A lightweight API client SDK for Cimulate Copilot

Readme

Copilot Client SDK

Install

  • To install from NPM registry
npm install @cimulate/copilot-sdk

Configuration Options

| Option | Type | Default Value | Description | |-----------------|----------|-------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | apiKey | string | Required if apiToken is not used | The API key used for authentication. | | apiToken | string | Required if apiKey is not used | The API JWT token used for authentication. | | baseUrl | string | Required | The base URL of the Copilot API server. | | namespace | string | '/copilot' | The Socket.IO namespace for the connection. | | socketOptions | object | {path: "/api/v1/socket.io", autoConnect: false, transports: ["polling", "websocket"], upgrade: true, timeout: 10000,} | Additional SocketIO supported options can be passed in the configuration object. For more information, refer to the SocketIO documentation. |

Connection Modes

Default Mode

const client = new CimulateCopilot({
    apiKey: "your-api-key",
    baseUrl: "https://cimulate.copilot.url",
});

HTTP Long Polling Only Mode (No Websockets)

const client = new CimulateCopilot({
    apiKey: "your-api-key",
    baseUrl: "https://cimulate.copilot.url",
    namespace: "/copilot",
    socketOptions: {
        path: "/api/v1/socket.io",
        transports: ["polling"],
        upgrade: false,
        timeout: 10000,
    },
});

Using API Token for Authentication

const client = CimulateCopilot({
    apiToken: "your-api-token",
    baseUrl: "https://cimulate.copilot.url",
});

Example Usage

Default Usage

import { CimulateCopilot } from '@cimulate/copilot-sdk';

// Establish Connection
const client = new CimulateCopilot({
    apiKey: "your-api-key",
    baseUrl: "https://cimulate.copilot.url",
});

// Connect to the Copilot server
client.connect();

// Handle connection acknowledgment
client.on("connect_ack", function connectAck(data) {
  console.log("Connected: ", data);
});

// Handle errors
client.on("error", function handleError(err) {
  console.error("Error: ", err);
});

// Perform a search request
const search = await client.search({
  userPrompt: "What specifications should I consider for a budget gaming laptop?", 
  searchParams: {"query": "gaming laptops"}
});

// Print search acknowledgment
console.log("Search Acknowledgement: ", search.result);

// Perform a browse request
const browse = await client.browse({
  userPrompt: "What specifications should I consider for a budget gaming laptop?", 
  browseParams: {"categoryId": "gaming laptops"}
});

// Print browse acknowledgment
console.log("Browse Acknowledgement: ", browse.result);

// Perform a product view request
const productView = await client.productView({
  userPrompt: "What colors are available for this product?", 
  productId: "product-123"
});

// Print product view acknowledgment
console.log("Product View Acknowledgement: ", productView.result);

// Perform a Conversation Reset
const conversationReset = await client.conversationReset({});

// Print conversation reset acknowledgment
console.log("Conversation Reset Acknowledgement: ", conversationReset.result);

// Handler for listening to an event
const handleEvent = client.on("event_name", function handleEvent(data) {
  console.log("Event Data: ", data);
});

// Follow-up Example for listening to an event response
const followUp = client.on("follow_up", function followup(event) {
  if (event.eventSourceId == search.result.eventId) {
    event.suggestions.forEach((s) => console.log(s.displayText));
  }
});

// Client side disconnect
client.disconnect();

// Handle disconnect event
client.onDisconnect((reason) => {
    console.log("Disconnected:", reason);
});

Establishing Connection Automatically

import { CimulateCopilot } from '@cimulate/copilot-sdk';

// Establish Connection with autoConnect set to false
const client = new CimulateCopilot({
    apiKey: "your-api-key",
    baseUrl: "https://cimulate.copilot.url",
    socketOptions: {
      autoConnect: true,
    },
});

// Handle connection acknowledgment
client.on("connect_ack", function connectAck(data) {
  console.log("Connected: ", data);
});

Reconnecting to a Disconnected Session

import { CimulateCopilot } from '@cimulate/copilot-sdk';

// Establish Connection to an existing session
// Note: If session does not exists, a new session will be created.
const client = new CimulateCopilot({
    apiKey: "your-api-key",
    baseUrl: "https://cimulate.copilot.url",
    socketOptions: {
      transportOptions: {
        polling: {
          extraHeaders: {
            "x-cimulate-api-key": "api-123",
          },
        },
    },
});

// If connections gets disconnected, reconnect to the session
client.reconnect();

Defining Search Returned Fields Types

interface SearchReturnedFields {
  id: string,
  title: string,
  image_url: string,
  price: number,
}

// Instantiate client object
const client = new CimulateCopilot<SearchReturnedFields[]>({
  apiKey: "your-api-key",
  baseUrl: "https://cimulate.copilot.url",
});

Defining Browse Returned Fields Types

interface BrowseReturnedFields {
  id: string,
  title: string,
  image_url: string,
  price: number,
}

// Instantiate client object const client = new CimulateCopilot<BrowseReturnedFields[]>({ apiKey: "your-api-key", baseUrl: "https://cimulate.copilot.url", });

Handling Request Ack Failure

import { 
  CimulateCopilot,
  CimulateCopilotException,
} from "@cimulate/copilot-sdk";

const copilot = new CimulateCopilot({
  apiKey: "your-api-key",
  baseUrl: "https://cimulate.copilot.url",
});

try {
  const search = await copilot.search({
    searchParams: { query: "" },
  });
  console.log("Search request ack:", search.result);
} catch (error) {
  // Handles errors that occur during the search request acknowledgement
  if (error instanceof CimulateCopilotException) {
    console.error("Error received via event:", error);
  }
}

Notes

  • The apiKey is required to authenticate and establish the connection.
  • Ensure the baseUrl matches the appropriate Copilot API environment.
  • Set upgradeTransport: false if you want to restrict transport to the defined methods.
  • Adjust the timeout based on your network conditions.
  • The copilot search request will fail if the query is an empty payload "" and includeFacets is set to false. Ensure to provide a valid query string in the search request or set includeFacets to true.