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

@astratra/ai

v1.0.2

Published

Generic AI provider routing, tool registry, and agent loop utilities for Astratra.

Readme

@astratra/ai

Routing IA multi-provider générique, registre d'outils et une boucle d'agent minimale à tool-calling. Dépend de @astratra/core.

Ce package ne fournit volontairement aucun catalogue de modèles, aucun SDK provider, aucun outil métier — tout ça vient du projet consommateur. Ce qu'il fournit, c'est le mécanisme durement acquis : suivi de quota, ordre de fallback, cooldown/dégradation, et une petite boucle d'orchestration d'agent.

Routeur de providers

const { createProviderRouter } = require('@astratra/ai');

const router = createProviderRouter({
  redisUrl: process.env.REDIS_URL,  // optionnel — quotas atomiques partagés entre instances
  intentRouting: {
    summarize: { preferred: ['fast-model'] }
  },
  providers: [
    {
      id: 'mon-provider-llm',
      models: [{ id: 'fast-model', rpm: 30, rpd: 1000, tpd: 200000, complexity: ['simple', 'medium'] }],
      call: async (prompt, ctx, model) => monClient.complete(model.id, prompt)
    }
  ]
});

const reponse = await router.ask('Résume ceci.', { complexity: 'simple', estimatedTokens: 200 });
router.getStats();  // usage RPM/RPD/TPD par "providerId:modelId", état cooldown/dégradé
router.stop();      // arrête le timer de reset minuit et ferme le lien Redis, s'il existe

Les providers sont essayés dans l'ordre du tableau que vous fournissez — l'ordre de fallback est votre décision, pas figé dans le package. Les quotas RPM/RPD/TPD, le cooldown après 429 avec jitter et la dégradation après échecs répétés sont suivis par couple providerId:modelId. Avec redisUrl, la réservation des quotas est atomique entre instances avant l'appel du provider. Sans Redis, ou si Redis devient indisponible, le routeur continue avec des compteurs RAM locaux : ce repli ne peut pas garantir un quota distribué. Les compteurs journaliers se réinitialisent automatiquement à minuit.

Registre d'outils

const { createToolRegistry } = require('@astratra/ai');

const registry = createToolRegistry();
registry.register({
  name: 'get_patient_record',
  description: "Récupère le dossier d'un patient par son id",
  type: 'read',
  roles: ['doctor', 'admin'],
  params: { patientId: 'string' },
  handler: async ({ patientId }, ctx) => patientStore.findById(patientId)
});

Vide par défaut — aucun outil pré-enregistré. registry.formatToolsForPrompt(role) formate en texte les outils visibles pour un rôle donné, à injecter dans un prompt système.

Boucle d'agent

const { runAgentLoop } = require('@astratra/ai');

const reponse = await runAgentLoop({
  prompt: 'Quel est le solde du patient X ?',
  ctx: { tenantId: 'clinic-1' },
  registry,
  router,
  userRole: 'doctor',
  maxSteps: 5
});

Parse <tool_call name="...">{...json...}</tool_call> dans la réponse du modèle, exécute l'outil correspondant enregistré (refuse si le rôle n'y a pas accès), réinjecte le résultat sous forme de <tool_result>, et boucle jusqu'à une réponse finale ou maxSteps atteint.

Périmètre V0 — volontairement exclu : streaming token par token, gestion d'images/vision, et confirmation humaine avant l'exécution d'un outil sensible. Ce sont de vraies fonctionnalités non triviales dont une boucle d'agent de production a besoin, mais les porter fidèlement a été jugé trop ambitieux pour cette première version du package. À construire dans votre propre boucle, ou à couvrir dans un futur spec.

Tests

npm test --workspace @astratra/ai