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

@dyno-assistant/utils

v0.1.1

Published

Utility functions for Dyno Assistant tools

Readme

@openassistant/utils

Utility functions for OpenAssistant tools.

Installation

npm install @openassistant/utils

Usage

import { tool } from '@openassistant/utils';

// Define your tool
const myTool = tool({
  description: 'My tool description',
  parameters: z.object({
    // your parameters
  }),
  execute: async (args) => {
    // your implementation
  },
});

ConversationCache

The ConversationCache class provides conversation-scoped caching for ToolOutputManager instances, enabling persistent tool outputs across multiple requests within the same conversation while maintaining isolation between different conversations.

Conversation ID Generation

The cache uses a multi-strategy approach to generate unique conversation IDs:

  1. Message ID (Recommended): Uses message.id if available
  2. Conversation/Thread/Session IDs: Looks for conversationId, threadId, or sessionId properties
  3. Enhanced Message Content Hash: Combines first 3 messages with available metadata
    • Includes timestamps, user IDs, message positions, and total message count
    • Stability: Once 3+ messages exist, the ID remains stable across requests
    • Uniqueness: Enhanced with metadata to prevent collisions between different conversations
  4. Random ID: Last resort - generates random ID (cache won't persist across requests)

Recommended Message Structure:

interface RecommendedMessage {
  id: string;              // Unique message ID (preferred)
  role: string;
  content: string;
  conversationId?: string; // Alternative: conversation identifier
  threadId?: string;       // Alternative: thread identifier  
  sessionId?: string;      // Alternative: session identifier
  timestamp?: number;      // Helps with uniqueness in Strategy 3
  createdAt?: string;      // Helps with uniqueness in Strategy 3
  userId?: string;         // Helps with uniqueness in Strategy 3
}

Basic Usage

import { ConversationCache } from '@openassistant/utils';

// Create a conversation cache with default settings
const conversationCache = new ConversationCache();

// In your API route
export async function POST(req: Request) {
  const { messages } = await req.json();
  
  // Get conversation-scoped ToolOutputManager
  const { toolOutputManager, conversationId } = 
    await conversationCache.getToolOutputManagerForMessages(messages);
  
  // Use toolOutputManager for your tools...
}

Configuration Options

const conversationCache = new ConversationCache({
  maxConversations: 100,           // Max conversations in memory
  ttlMs: 1000 * 60 * 60 * 2,      // 2 hours TTL
  cleanupProbability: 0.1,         // 10% cleanup chance per request
  enableLogging: true,             // Enable debug logging (includes warnings)
});

Advanced Usage

// Generate conversation ID manually
const conversationId = conversationCache.generateConversationId(messages);

// Get ToolOutputManager for specific conversation
const toolOutputManager = await conversationCache.getToolOutputManager(conversationId);

// Get cache status for monitoring
const status = await conversationCache.getStatus();
console.log(status);
// {
//   totalConversations: 5,
//   conversations: [
//     { id: "a1b2c3d4", ageMinutes: 15, hasCache: true, toolOutputCount: 3 }
//   ],
//   config: { maxConversations: 100, ttlHours: 2, cleanupProbability: 0.1 }
// }

// Clear all conversations
conversationCache.clearAll();

Features

  • Data isolation: Prevents cache sharing between different users/conversations
  • Flexible ID generation: Multiple strategies for conversation identification
  • Automatic cleanup: Old conversations are removed based on TTL and max count
  • Memory efficient: Probabilistic cleanup avoids performance impact
  • Type-safe: Full TypeScript support with proper interfaces
  • Configurable: All settings can be customized
  • Persistent: Tool outputs persist across requests within same conversation (when using stable IDs)