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

@meldscience/message-bus

v0.3.1

Published

Message bus for coordinating conversations between participants

Readme

@meldscience/message-bus

A lightweight message bus for coordinating conversations between participants in Discord threads.

Installation

npm install @meldscience/message-bus

Core Concepts

Messages

Messages are the fundamental unit of communication. Each message has:

interface Message {
  id: string;                 // Unique message identifier
  from: string;              // Sender ID (e.g. Discord user ID)
  to: string[];              // Target participants (for @mentions)
  channelId: string;         // Discord channel or thread ID
  content: {
    type: 'text' | 'thought' | 'action';
    data: string | ActionData;
  };
  metadata?: {
    protocolId: string;      // Active protocol
    threadId?: string;       // For threaded conversations
    [key: string]: unknown;  // Protocol-specific metadata
  };
  timestamp: number;         // Unix timestamp
}

Protocols

Protocols define how messages are handled in specific conversation contexts. Each protocol:

  • Has a unique ID and metadata
  • Can process incoming messages
  • Can maintain thread-specific state
  • Receives lifecycle events (initialization, cleanup)
class MyProtocol extends BaseProtocol {
  constructor() {
    super(
      'my-protocol',         // Unique ID
      'My Protocol',         // Display name
      'Protocol description' // Description
    );
  }

  async onMessage(msg: Message): Promise<Message | null> {
    // Process message
    return msg;
  }
}

Message Bus

The message bus:

  • Routes messages between participants
  • Manages protocol registration
  • Handles thread lifecycle
  • Maintains thread state
const messageBus = new MessageBus(discordClient);

// Register protocols
await messageBus.registerProtocol(new QandAProtocol({
  id: 'qanda',
  allowedQuestioners: ['user1', 'user2'],
  toolPermissions: { /* ... */ }
}));

// Create thread with protocol
const threadId = await messageBus.createThread(channelId, 'qanda');

// Route message
await messageBus.routeMessage({
  id: 'msg1',
  from: 'user1',
  to: ['claude1'],
  channelId: threadId,
  content: {
    type: 'text',
    data: 'Hello Claude!'
  },
  timestamp: Date.now()
});

Built-in Protocols

Q&A Protocol

Manages question-and-answer interactions:

  • Controls who can ask questions
  • Manages tool permissions
  • Routes questions to appropriate participants
const qandaProtocol = new QandAProtocol({
  id: 'qanda',
  name: 'Q&A Protocol',
  description: 'Question and answer coordination',
  allowedQuestioners: ['user1', 'user2'],
  toolPermissions: {
    'role1': ['tool1', 'tool2']
  }
});

Meeting Protocol

Coordinates meetings in Discord threads:

  • Parses meeting goals from initial message
  • Manages participant roles
  • Tracks meeting state
const meetingProtocol = new MeetingProtocol();

Events

The message bus emits events for key operations:

messageBus.on('message', (msg: Message) => {
  // Handle message event
});

messageBus.on('threadCreate', ({ threadId, protocolId }) => {
  // Handle thread creation
});

messageBus.on('error', (error: Error) => {
  // Handle errors
});

Integration with mcp-discord

When integrating with mcp-discord, ensure:

  1. Messages include required fields:

    • id: Unique message identifier
    • timestamp: Unix timestamp
    • metadata.protocolId: Active protocol ID
  2. Protocol configuration uses the new constructor format:

    new QandAProtocol({
      id: 'protocol-id',      // Required
      name: 'Protocol Name',  // Optional
      description: '...',     // Optional
      // Protocol-specific config...
    });
  3. Use thread state management instead of config:

    // Set thread state
    await messageBus.setThreadState(threadId, {
      // Thread-specific state...
    });
    
    // Get thread state
    const state = await messageBus.getThreadState(threadId);
  4. Implement event handlers for better state management:

    messageBus.on('message', handleMessage);
    messageBus.on('threadCreate', handleThreadCreate);
    messageBus.on('error', handleError);

License

MIT