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

@enclave-vm/broker

v2.12.0

Published

Tool broker and session management for the EnclaveJS streaming runtime

Readme

@enclave-vm/broker

npm version License TypeScript

Tool broker and session management for the EnclaveJS streaming runtime

The @enclave-vm/broker package provides server-side components for managing EnclaveJS sessions, routing tool calls, and handling the streaming protocol. It acts as the middleware between clients and the secure execution environment.

Features

  • Session Management: Create, manage, and clean up execution sessions
  • Tool Routing: Route tool calls to appropriate handlers with pattern matching
  • Access Control: Fine-grained tool permissions using glob patterns
  • Rate Limiting: Configurable rate limits per session
  • State Management: Track session state and tool call history
  • Middleware Support: Extensible middleware pipeline for tool calls

Installation

npm install @enclave-vm/broker
# or
yarn add @enclave-vm/broker
# or
pnpm add @enclave-vm/broker

Quick Start

import { Broker, createSession } from '@enclave-vm/broker';

// Create a broker with tool handlers
const broker = new Broker({
  tools: {
    'users:get': async (args) => {
      return { id: args.id, name: 'Alice' };
    },
    'users:list': async () => {
      return [
        { id: 1, name: 'Alice' },
        { id: 2, name: 'Bob' },
      ];
    },
  },
});

// Create a session
const session = await broker.createSession({
  allowedTools: ['users:*'], // Glob pattern for allowed tools
  timeout: 30000,
  maxToolCalls: 100,
});

// Handle incoming messages
session.on('tool_call', async (call) => {
  const result = await broker.executeToolCall(session.id, call);
  session.send({ type: 'tool_result', id: call.id, data: result });
});

Session Management

import { SessionManager } from '@enclave-vm/broker';

const manager = new SessionManager({
  maxConcurrentSessions: 100,
  sessionTimeout: 60000, // 1 minute
  cleanupInterval: 10000, // 10 seconds
});

// Create session
const session = await manager.create({
  userId: 'user_123',
  metadata: { source: 'api' },
});

// Get session
const retrieved = manager.get(session.id);

// List active sessions
const sessions = manager.list({ userId: 'user_123' });

// Destroy session
await manager.destroy(session.id);

Tool Routing

Route tool calls with pattern matching:

import { ToolRouter } from '@enclave-vm/broker';

const router = new ToolRouter();

// Register tools with glob patterns
router.register('db:*', {
  handler: async (name, args) => {
    const operation = name.split(':')[1];
    return await database[operation](args);
  },
  rateLimit: { maxCalls: 100, windowMs: 60000 },
});

router.register('api:external:*', {
  handler: async (name, args) => {
    return await externalApi.call(name, args);
  },
  requiresAuth: true,
});

// Execute tool call
const result = await router.execute('db:query', { sql: 'SELECT * FROM users' });

Access Control

import { AccessController } from '@enclave-vm/broker';

const access = new AccessController({
  defaultPolicy: 'deny',
  rules: [
    { pattern: 'public:*', allow: true },
    { pattern: 'admin:*', allow: false, unless: { role: 'admin' } },
    { pattern: 'user:*:read', allow: true },
    { pattern: 'user:*:write', allow: false, unless: { owner: true } },
  ],
});

// Check access
const canAccess = access.check('admin:delete', { role: 'user' }); // false
const canRead = access.check('user:profile:read', {}); // true

Middleware

Add middleware for cross-cutting concerns:

import { Broker } from '@enclave-vm/broker';

const broker = new Broker({
  middleware: [
    // Logging middleware
    async (call, next) => {
      console.log(`Tool call: ${call.name}`);
      const start = Date.now();
      const result = await next(call);
      console.log(`Completed in ${Date.now() - start}ms`);
      return result;
    },
    // Validation middleware
    async (call, next) => {
      if (!isValidArgs(call.name, call.args)) {
        throw new Error('Invalid arguments');
      }
      return next(call);
    },
  ],
  tools: {
    // ... tool handlers
  },
});

Rate Limiting

import { RateLimiter } from '@enclave-vm/broker';

const limiter = new RateLimiter({
  global: { maxCalls: 1000, windowMs: 60000 },
  perSession: { maxCalls: 100, windowMs: 60000 },
  perTool: {
    'expensive:*': { maxCalls: 10, windowMs: 60000 },
  },
});

// Check rate limit before execution
if (!limiter.allow(sessionId, toolName)) {
  throw new Error('Rate limit exceeded');
}

Related Packages

| Package | Description | | ------------------------------------------- | --------------------------------- | | @enclave-vm/types | Type definitions and Zod schemas | | @enclave-vm/stream | Streaming protocol implementation | | @enclave-vm/core | Secure execution environment | | @enclave-vm/client | Browser/Node.js client SDK | | @enclave-vm/runtime | Standalone runtime worker |

License

Apache-2.0