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

@notilens/langchain

v0.2.0

Published

NotiLens callback handler for LangChain.js — automatic run tracking, token metrics, and error alerting

Readme

@notilens/langchain

NotiLens callback handler for LangChain (JavaScript/TypeScript). Automatically tracks every chain, agent, LLM call, tool invocation, and retriever query — sending lifecycle events, token metrics, durations, and errors to NotiLens with zero manual instrumentation.

Installation

npm install @notilens/langchain @langchain/core

Quick start

import { NotiLensCallbackHandler } from '@notilens/langchain';

const handler = new NotiLensCallbackHandler({
  name:   'my-app',
  token:  'YOUR_TOKEN',    // or set NOTILENS_TOKEN env var
  secret: 'YOUR_SECRET',  // or set NOTILENS_SECRET env var
});

Attach to any chain, LLM, or agent executor — that's it:

// On a chain
const result = await chain.invoke(
  { input: '...' },
  { callbacks: [handler] }
);

// On an LLM
import { ChatOpenAI } from '@langchain/openai';
const llm = new ChatOpenAI({ model: 'gpt-4o', callbacks: [handler] });

// On an agent executor
await agentExecutor.invoke({ input: '...' }, { callbacks: [handler] });

What gets tracked automatically

| Event | NotiLens action | |---|---| | Chain starts | run.start() | | Chain completes | run.complete() | | Chain errors | run.fail(error) | | LLM / chat model called | run.progress("Calling gpt-4o with 3 messages…") | | LLM response received | run.metric(prompt_tokens, completion_tokens, total_tokens) + duration | | LLM timeout (> callTimeout) | run.timeout() | | LLM error | run.error() | | Agent uses a tool | run.loop("Agent step #N: using tool 'X'") + run.progress("Step N: using tool 'X'") | | Agent finishes | run.complete(output) | | Tool starts | run.progress("Running tool 'calculator'…") | | Tool completes | run.progress("Tool completed") | | Tool errors | run.error() | | Retriever starts | run.progress("Retrieving context for: …") | | Retriever returns docs | run.progress("Retrieved 5 documents") | | Retriever errors | run.error() |

Configuration

const handler = new NotiLensCallbackHandler({
  name:            'my-app',        // name shown in NotiLens
  token:           'YOUR_TOKEN',    // NotiLens topic token
  secret:          'YOUR_SECRET',   // NotiLens topic secret
  task:            'rag-pipeline',  // fixed task label (default: chain class name)
  callTimeout:     30,              // LLM seconds before timeout event fires (default: 30)
  sendOutput:      true,            // send final agent output as output.generated event (default: false)
  maxOutputLength: 2000,            // max characters of output to send (default: 2000)
});

Custom metrics & events

// Numeric values accumulate across calls; strings are replaced
handler.metric('cost_usd', 0.004);
handler.metric('cache_hits', 1);
handler.metric('model', 'gpt-4o');

// Fire a custom event with optional level and metadata
handler.track('cache.hit', 'Retrieved from vector cache');
handler.track('guardrail.triggered', 'Blocked unsafe output', { level: 'warning' });

// Send a rich notification with URLs and tags
handler.notify('report.ready', 'Summary complete', {
  downloadUrl: 'https://example.com/report.pdf',
  tags: 'langchain,rag',
});
handler.notify('result.image', 'Chart generated', {
  imageUrl: 'https://example.com/chart.png',
  openUrl:  'https://example.com/dashboard',
});

Note: Calling metric(), track(), or notify() when no chain is running logs a warning and does nothing:

[NotiLens] handler.metric('cost_usd', ...) called with no active run — ignoring.

Reusing an existing NotiLens instance

import { NotiLens } from '@notilens/notilens';
import { NotiLensCallbackHandler } from '@notilens/langchain';

const nl = NotiLens.init('my-app', { token: '...', secret: '...' });
const handler = new NotiLensCallbackHandler({ nlAgent: nl });

Environment variables

export NOTILENS_TOKEN="your_token"
export NOTILENS_SECRET="your_secret"
// Token and secret picked up automatically
const handler = new NotiLensCallbackHandler({ name: 'my-app' });