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

@nvdigitalsolutions/nvoos-slash-commands

v0.1.0-alpha.3

Published

Slash command system with fuzzy-search autocomplete and execution engine - Extracted from NV Open Operator System

Readme

@nvdigitalsolutions/nvoos-slash-commands

Slash command system with fuzzy-search autocomplete and a resilient execution engine — extracted from the NV Open Operator System WordPress plugin.

Zero external dependencies. Uses only standard browser APIs (Fetch, DOM, localStorage).

Why this package?

Slash commands are the fastest way for users to trigger AI actions inside a chat UI. This package gives you:

  1. CommandAutocomplete — a fuzzy-search dropdown that appears when the user types /, supports keyboard navigation (↑ ↓ Enter Tab Escape), and calls your API to retrieve the command list.
  2. SlashCommandsHandler — intercepts form submission, executes commands via REST API with a 30-second timeout, correlation ID tracking for debugging, screen-reader announcements, and a CustomEvent bridge so your chat layer can react.

Installation

npm install @nvdigitalsolutions/nvoos-slash-commands

Quick Start

Framework-agnostic (zero config in WordPress)

import { createSlashCommands } from '@nvdigitalsolutions/nvoos-slash-commands';

// Auto-initialises when the DOM is ready. Reads window.mcpAiData for endpoints.
const handler = createSlashCommands();

Explicit config (any environment)

import { SlashCommandsHandler, CommandAutocomplete } from '@nvdigitalsolutions/nvoos-slash-commands';

// 1. Configure module-level defaults (shared by all instances)
SlashCommandsHandler.configure({
  nonce: 'your-auth-nonce',
  slashCommandEndpoint: 'https://your-api.com/slash-commands/execute',
  slashCommandListEndpoint: 'https://your-api.com/slash-commands/list',
});

// 2. Create and initialise the handler (attaches to the first matching form input)
const handler = new SlashCommandsHandler();
handler.init();

// 3. Optionally attach autocomplete to a specific input element
const input = document.querySelector('#chat-input');
const autocomplete = new CommandAutocomplete(input);
autocomplete.init();

API

SlashCommandsHandler

static configure(config)

Set module-level defaults before constructing any instance.

SlashCommandsHandler.configure({
  nonce: 'wp-nonce-value',
  slashCommandEndpoint: 'https://example.com/wp-json/mcp-ai/v1/slash-commands',
  slashCommandListEndpoint: 'https://example.com/wp-json/mcp-ai/v1/slash-commands/list',
});

new SlashCommandsHandler(config?)

Construct an instance, optionally overriding the module config for this instance only.

handler.init()

Attach to the chat input and form found in the DOM. Safe to call multiple times (no-op after first successful init). Retries up to 50 times at 100 ms intervals if mcpAiData is not yet available.

handler.executeCommand(command)

Execute a slash command string programmatically (e.g. '/summarize last 5 messages'). Returns a Promise.

handler.fetchCommands()

Returns a Promise that resolves to the list of available commands from the API. Results are cached for 5 minutes.

handler.announceToScreenReader(message)

Inject an accessible aria-live announcement into the page.


CommandAutocomplete

new CommandAutocomplete(inputElement)

Attach a fuzzy-search dropdown to a text input or textarea.

autocomplete.init()

Create the dropdown element, load the command list, and attach event listeners.

autocomplete.show(inputValue)

Filter commands matching inputValue and display the dropdown.

autocomplete.hide()

Hide the dropdown and clean up listeners.

autocomplete.isVisible()

Returns true if the dropdown is currently visible.

autocomplete.handleKeyDown(e)

Call this from your own keydown listener to delegate keyboard navigation. Returns true if the event was consumed.

autocomplete.destroy()

Remove all event listeners and detach the dropdown element from the DOM.


createSlashCommands(config?)

Convenience factory that constructs a SlashCommandsHandler, wires it up to the DOM, and returns it. Handles DOMContentLoaded timing automatically.

const handler = createSlashCommands({ nonce: 'abc', slashCommandEndpoint: '/api/execute' });

Listening for command events

The handler dispatches a slash-command-event CustomEvent on window after each execution:

window.addEventListener('slash-command-event', (e) => {
  const { type, data } = e.detail;
  if (type === 'command-executed') {
    console.log('Command result:', data.result);
  }
});

Command list API contract

slashCommandListEndpoint must return:

{
  "commands": [
    { "name": "summarize", "description": "Summarise the conversation", "aliases": ["sum"] },
    { "name": "translate", "description": "Translate to another language" }
  ]
}

TypeScript

Full TypeScript definitions included:

import type { SlashCommand, SlashCommandsConfig } from '@nvdigitalsolutions/nvoos-slash-commands';

License

MIT — NV Digital Solutions