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

@nestjs/ai

v0.0.2

Published

Language models for NestJS: model calls with timeouts, retries and fallbacks, structured output, tools and agents, and streaming to the browser.

Readme

Description

Language models for Nest: named models through dependency injection, model calls with timeouts, retries and fallback models (run on @nestjs/resilience policies, or your own), budgets and usage events, structured output validated by a schema, the application's own provider methods as agent functions its agents call (through Nest's guards, interceptors, pipes and exception filters, as the user the agent acts for), answers streamed to the browser on Express, Fastify and the Node adapter, and durable agent runs on @nestjs/workflows (@nestjs/ai/workflows) that survive restarts and wait for a person's approval. You write an agent function with @AgentFunction(), and the model is offered it as a tool; a method can be an MCP tool too, served by @nestjs/mcp, with its @Tool() stacked on it. Embedding models have their own named registry, dependency injection, resilient single and batch calls, and usage events. Comes with fake language and embedding models for tests. Built on the AI SDK (ai) and its provider packages.

Installation

$ npm i --save @nestjs/ai @nestjs/resilience ai @ai-sdk/anthropic zod

Any @ai-sdk/* provider package works (@ai-sdk/openai, @ai-sdk/google, ...). Zod 4.2 or later for the schemas; any other Standard Schema library that produces JSON Schema works too. Node.js 22 or later.

Each major version of @nestjs/ai supports one major version of the AI SDK: this one, ai 7.

Quick Start

Register the models, and call them:

import { anthropic } from '@ai-sdk/anthropic';
import { Injectable, Module } from '@nestjs/common';
import { AgentFunction, AiModule, AiService, type AgentFunctionContext } from '@nestjs/ai';
import * as z from 'zod';

@Injectable()
export class OrdersTools {
  constructor(private readonly orders: OrdersService) {}

  @AgentFunction({
    name: 'find-order',
    description: 'Find an order by its id',
    inputSchema: z.object({ orderId: z.string() }),
  })
  find({ orderId }: { orderId: string }, ctx: AgentFunctionContext) {
    return this.orders.findFor(ctx.request?.user, orderId);
  }
}

@Injectable()
export class SupportService {
  constructor(private readonly ai: AiService) {}

  async answer(question: string, request: unknown) {
    const { text } = await this.ai.generateText({
      prompt: question,
      tools: ['find-order'],
      caller: { request },
    });
    return text;
  }
}

@Module({
  imports: [
    AiModule.forRoot({
      models: {
        default: anthropic('claude-opus-5-5'),
        fast: anthropic('claude-haiku-5-5'),
      },
      defaults: { timeout: '30s', retry: { attempts: 3 } },
    }),
  ],
  providers: [OrdersService, OrdersTools, SupportService],
})
export class AppModule {}

A method that MCP clients call too also carries @nestjs/mcp's @Tool(), with options of its own: the two decorators don't read each other's, and one schema constant serves both. generateObject({ schema }) answers a typed object, and streamText() an answer a controller sends to the browser with pipeUIMessageStreamToResponse(res), as the AI SDK's useChat() reads it. Agent function calls run through the guards, interceptors, pipes and filters of the class and the method, with the context type 'ai', so AiExecutionContext reads them in enhancers (on a method with both decorators, they see 'mcp' for MCP clients' calls), and @nestjs/authentication (0.1.4 or later) and @nestjs/authorization (0.1.2 or later) authenticate and authorize them. @nestjs/ai/testing has FakeModel, which answers with text, tool calls, objects or errors, without a network.

The sample is a cat store: it triages support emails, and runs a chat assistant that calls the same find-order method its MCP server serves. npm run build && npx tsc -p sample/tsconfig.json, then node sample/dist/main.js (with ANTHROPIC_API_KEY set, Claude answers; without it, fake models do).

Read Overview to get started and for the module's options, Models for retries, timeouts, fallback models and budgets, Tools for agent functions, the call context, guards and authorization, Agents for the agent loop, streaming to the browser and durable runs, and Testing for the fake model.

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Nest is MIT licensed.