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

chat-flow-ardymalihi

v3.0.7

Published

Production-ready conversation orchestration library with intent detection and workflow integration

Readme

Chat-Flow

A production-ready conversation orchestration library with intent detection and workflow integration.

npm version License: MIT

Features

  • 🎯 Intent Detection - AI-powered intent classification with confidence scoring
  • 💬 Session Management - Persistent conversation sessions with Redis or in-memory storage
  • 🔄 Workflow Integration - Seamless integration with workflow engines (Zapier, N8N, etc.)
  • 🤖 LLM Adapters - Support for multiple LLM providers (Gemini, OpenAI, etc.)
  • 🏗️ Clean Architecture - Ports & Adapters pattern for maximum flexibility
  • 📊 Type-Safe - Full TypeScript support with comprehensive type definitions
  • Well-Tested - Comprehensive test coverage
  • 🔧 Configurable - Flexible configuration system

Installation

npm install @your-org/chat-flow

Quick Start

import {
    Orchestrator,
    GeminiLLMAdapter,
    RedisRepository,
    IntentService,
    IntentRepository,
    IntentMatcher,
    MockWorkflowAdapter
} from '@your-org/chat-flow';

// Initialize adapters
const llm = new GeminiLLMAdapter(process.env.GOOGLE_AI_API_KEY!);
const repository = new RedisRepository('redis://localhost:6379');
const intentRepo = new IntentRepository(repository);
const intentMatcher = new IntentMatcher(llm);
const intentService = new IntentService(intentRepo, intentMatcher);
const workflow = new MockWorkflowAdapter();

// Create orchestrator with custom config
const orchestrator = new Orchestrator(
    repository,
    llm,
    intentService,
    workflow,
    {
        intent: {
            confidenceThreshold: 0.7,
            maxIntents: 5,
            cacheTTL: 300
        }
    }
);

// Create a session
const session = await orchestrator.createSession(
    'session-123',
    'TEXT',
    'You are a helpful travel assistant'
);

// Handle user messages
const { messages, metadata } = await orchestrator.handleMessage(
    session.sessionId,
    'I want to book a flight to Paris'
);

console.log('Assistant:', messages[0].content);
console.log('Intent detected:', metadata.intent);
console.log('Confidence:', metadata.confidence);

Core Concepts

Session Management

Sessions maintain conversation state and history:

const session = await orchestrator.createSession(
    'unique-session-id',
    'TEXT', // or 'VOICE'
    'Your agent prompt here'
);

Intent Detection

Automatically detect user intents with confidence scoring:

// Define intents
const intents = [
    {
        name: 'BOOK_FLIGHT',
        description: 'User wants to book a flight',
        required_fields: [
            { name: 'destination', type: 'string' },
            { name: 'date', type: 'string' }
        ]
    }
];

await intentRepo.upsertIntents(intents);

Workflow Integration

Execute workflows when intents are detected:

class CustomWorkflowAdapter implements IWorkflowAdapter {
    async executeWorkflow(workflowId: string, context: any): Promise<WorkflowResult> {
        // Your workflow execution logic
        return {
            success: true,
            data: { /* workflow results */ }
        };
    }
}

Configuration

Customize behavior with configuration options:

const config = {
    session: {
        ttl: 3600,              // Session TTL in seconds
        maxHistoryLength: 100   // Max messages to keep
    },
    intent: {
        confidenceThreshold: 0.6,  // Minimum confidence (0-1)
        maxIntents: 5,             // Max intents to return
        cacheTTL: 300              // Cache TTL in seconds
    },
    llm: {
        model: 'gemini-2.0-flash-lite',
        temperature: 0.7,
        maxTokens: 1000,
        timeout: 30000
    },
    workflow: {
        timeout: 60000,
        retries: 3,
        retryDelay: 1000
    },
    logging: {
        enabled: true,
        level: 'info',
        timestamps: true
    }
};

const orchestrator = new Orchestrator(repo, llm, intent, workflow, config);

Error Handling

Chat-Flow provides typed errors for better error handling:

import {
    SessionNotFoundError,
    IntentDetectionError,
    WorkflowExecutionError,
    LLMError
} from '@your-org/chat-flow';

try {
    await orchestrator.handleMessage(sessionId, message);
} catch (error) {
    if (error instanceof SessionNotFoundError) {
        console.error('Session not found:', error.details.sessionId);
    } else if (error instanceof IntentDetectionError) {
        console.error('Intent detection failed:', error.message);
    }
}

Architecture

Chat-Flow follows Clean Architecture principles:

┌─────────────────────────────────────────┐
│         Application Layer               │
│  (Orchestrator, ConversationSession)    │
└─────────────────────────────────────────┘
                  ↓
┌─────────────────────────────────────────┐
│           Ports (Interfaces)            │
│  (IRepository, ILLMAdapter, etc.)       │
└─────────────────────────────────────────┘
                  ↓
┌─────────────────────────────────────────┐
│        Adapters (Implementations)       │
│  (RedisRepository, GeminiLLMAdapter)    │
└─────────────────────────────────────────┘

Testing

Note: We prioritize Unit and Integration tests over ad-hoc scripts. Please check CONTRIBUTING.md for our testing policy.

# Run tests
npm test

# Run tests with coverage
npm run test:coverage

# Run tests in watch mode
npm run test:watch

Development

# Install dependencies
npm install

# Build
npm run build

# Run linter
npm run lint

# Format code
npm run format

# Run demo
npm run demo

Examples

See the /examples directory for more usage examples:

  • Basic chat implementation
  • Custom intent detection
  • Workflow integration
  • Custom adapters

API Documentation

For detailed API documentation, see API.md.

Contributing

Contributions are welcome! Please read CONTRIBUTING.md for details.

License

MIT © [Your Organization]

Support