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

@reaatech/confidence-router-core

v0.1.1

Published

Core types, config, and decision engine for confidence-router

Readme

@reaatech/confidence-router-core

npm version License: MIT CI

Status: Pre-1.0 — APIs may change in minor versions. Pin to a specific version in production.

Core type definitions, error classes, configuration utilities, and the DecisionEngine for the confidence-router ecosystem. This package is the single source of truth for all type shapes used throughout @reaatech/confidence-router-*.

Installation

npm install @reaatech/confidence-router-core
# or
pnpm add @reaatech/confidence-router-core

Feature Overview

  • All public type definitionsPrediction, ClassificationResult, RoutingDecision, RouterConfig, Classifier interface, and more
  • Typed error classRouterError with enumerated RouterErrorType codes for every failure mode
  • DecisionEngine — pure-function threshold evaluator that scores confidence against route/clarify/fallback boundaries
  • Configuration utilitiesDEFAULT_CONFIG, validateConfig, mergeConfig with built-in sanity checks
  • Dependency injection interfacesRouterInterface, ClassifierRegistryInterface, LanguageManagerInterface, PromptGeneratorInterface, ConfidenceRouterDeps
  • Zero runtime dependencies — lightweight and tree-shakeable
  • Dual ESM/CJS output — works with import and require

Quick Start

import { DecisionEngine, mergeConfig, RouterError, RouterErrorType } from "@reaatech/confidence-router-core";

const engine = new DecisionEngine(
  mergeConfig({ routeThreshold: 0.8, fallbackThreshold: 0.3, clarificationEnabled: true })
);

const decision = engine.decide({
  predictions: [
    { label: "book_flight", confidence: 0.92 },
    { label: "check_status", confidence: 0.08 },
  ],
});

console.log(decision.type); // "ROUTE"

API Reference

Types

| Export | Description | |--------|-------------| | Prediction | { label: string; confidence: number; metadata?: Record<string, unknown> } | | ClassificationResult | { predictions: Prediction[]; metadata?: ... } | | RoutingDecision | { type: DecisionType; confidence?, target?, prompt?, options?, metadata? } | | RouterConfig | All configuration fields: routeThreshold, fallbackThreshold, clarificationEnabled, clarificationLanguages?, maxClarificationOptions?, etc. | | DecisionType | Union: "ROUTE" \| "CLARIFY" \| "FALLBACK" | | Classifier | Interface: name, type, enabled, priority, classify(input, context?), validate?() | | LanguageConfig | { code, name, nativeName, direction, clarificationTemplates, formatting } | | EvaluationDataset | { examples: LabeledExample[]; metadata? } | | LabeledExample | { input, expectedLabel, expectedDecision?, predictions?, context? } | | EvaluationMetrics | { accuracy, precision, recall, f1Score, confusionMatrix, decisionsByType } | | OptimizedThresholds | { routeThreshold, fallbackThreshold, score, metrics } | | FallbackHandler | (classification: ClassificationResult) => RoutingDecision |

Errors

All errors extend the standard Error class and carry a type discriminator.

| Class | Type Enum | When | |-------|-----------|------| | RouterError | (varies) | Base class for all routing errors | | RouterErrorType.CONFIGURATION_ERROR | — | Invalid configuration | | RouterErrorType.CLASSIFICATION_ERROR | — | Invalid classifier output | | RouterErrorType.LANGUAGE_NOT_SUPPORTED | — | Unknown language code | | RouterErrorType.THRESHOLD_INVALID | — | Threshold out of [0, 1] range | | RouterErrorType.CLASSIFIER_NOT_FOUND | — | Named classifier not registered | | RouterErrorType.DATASET_INVALID | — | Evaluation dataset invalid |

import { RouterError, RouterErrorType } from "@reaatech/confidence-router-core";

throw new RouterError(
  RouterErrorType.THRESHOLD_INVALID,
  "routeThreshold must be between 0 and 1",
  { detail: "extra context" }
);

DecisionEngine

import { DecisionEngine } from "@reaatech/confidence-router-core";

| Method | Returns | Description | |--------|---------|-------------| | decide(classification) | RoutingDecision | Evaluates top prediction confidence against configured thresholds | | evaluateThresholds(score) | DecisionType | Maps a raw confidence score to ROUTE, CLARIFY, or FALLBACK |

Configuration Utilities

| Export | Description | |--------|-------------| | DEFAULT_CONFIG | Default RouterConfig (routeThreshold: 0.8, fallbackThreshold: 0.3, clarificationEnabled: true) | | validateConfig(config) | Throws RouterError if thresholds are invalid or maxClarificationOptions < 2 | | mergeConfig(partial?) | Merges a partial config with defaults |

Dependency Injection Interfaces

| Interface | Methods | |-----------|---------| | RouterInterface | decide(), getConfig(), updateConfig() | | ClassifierRegistryInterface | register(), get(), classify(), getFallbackChain() | | LanguageManagerInterface | getLanguage(), addLanguage(), hasLanguage(), getSupportedLanguages() | | PromptGeneratorInterface | generate(predictions, languageCode, customTemplate?, maxOptions?) | | ConfidenceRouterDeps | { languageManager?, promptGenerator?, classifierRegistry? } |

Usage with Dependency Injection

The ConfidenceRouterDeps interface allows callers to inject custom implementations:

import type { ConfidenceRouterDeps } from "@reaatech/confidence-router-core";

const deps: ConfidenceRouterDeps = {
  languageManager: new CustomLanguageManager(),
  promptGenerator: new CustomPromptGenerator(lm),
  classifierRegistry: new CustomRegistry(),
};

Decision Logic

score >= routeThreshold    →  ROUTE
score <  fallbackThreshold  →  FALLBACK
otherwise (clarify enabled)  →  CLARIFY
otherwise                    →  FALLBACK

Related Packages

License

MIT