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

@tepa/provider-core

v0.1.1

Published

Base LLM provider with centralized retry logic and structured logging

Readme

@tepa/provider-core

Base LLM provider with centralized retry logic and structured per-call logging. All built-in providers (@tepa/provider-anthropic, @tepa/provider-openai, @tepa/provider-gemini) extend BaseLLMProvider from this package.

Install

npm install @tepa/provider-core

Base Provider Options

All providers that extend BaseLLMProvider accept these options:

const provider = new AnthropicProvider({
  maxRetries: 3, // retry attempts on transient failures (default: 3)
  retryBaseDelayMs: 1000, // base delay for exponential backoff (default: 1000)
  defaultLog: true, // enable file logging (default: true)
  logDir: ".tepa/logs", // directory for log files (default: ".tepa/logs")
  includeContent: false, // include full message content in logs (default: false)
});

Logging

Every LLM call is automatically logged as a structured LLMLogEntry containing provider name, status, duration, token usage, model, and a prompt preview.

Default File Logging

By default, logs are written as JSONL to .tepa/logs/llm-<timestamp>.jsonl. Each line is a JSON object:

{
  "timestamp": "2026-03-09T10:00:00.000Z",
  "provider": "anthropic",
  "status": "success",
  "durationMs": 1200,
  "attempt": 0,
  "request": {
    "model": "claude-sonnet-4-20250514",
    "messageCount": 3,
    "totalCharLength": 850,
    "promptPreview": "Generate a project plan...",
    "hasSystemPrompt": true
  },
  "response": {
    "text": "Here is the plan...",
    "tokensUsed": {
      "input": 200,
      "output": 150
    },
    "finishReason": "end_turn"
  }
}

You can customize the log directory or disable file logging entirely:

// Custom log directory
const provider = new AnthropicProvider({ logDir: "./my-logs" });

// Disable file logging
const provider = new AnthropicProvider({ defaultLog: false });

Custom Log Listeners

Use onLog() to add custom log listeners. This works alongside or instead of the default file logger:

// Add a listener alongside the default file logger
const provider = new AnthropicProvider();
provider.onLog((entry) => {
  myMetricsService.recordLatency(entry.durationMs);
});

Sending Logs to External Providers

To send logs to an external observability service (Prometheus, NewRelic, Datadog, etc.), disable the default file logger and register your own callback:

import { AnthropicProvider } from "@tepa/provider-anthropic";

const provider = new AnthropicProvider({ defaultLog: false });

provider.onLog((entry) => {
  newrelicClient.recordCustomEvent("LLMCall", {
    provider: entry.provider,
    model: entry.request.model,
    status: entry.status,
    durationMs: entry.durationMs,
    inputTokens: entry.response?.tokensUsed.input,
    outputTokens: entry.response?.tokensUsed.output,
    error: entry.error?.message,
  });
});

You can also register multiple listeners:

const provider = new AnthropicProvider({ defaultLog: false });

// Send metrics to Prometheus
provider.onLog((entry) => {
  llmDurationHistogram.observe({ provider: entry.provider }, entry.durationMs);
  if (entry.status === "error") llmErrorCounter.inc({ provider: entry.provider });
});

// Also log to console for local debugging
import { consoleLogCallback } from "@tepa/provider-core";
provider.onLog(consoleLogCallback);

Built-in Log Callbacks

| Export | Description | | ----------------------- | ------------------------------------------------------------- | | consoleLogCallback | Prints a human-readable summary to console.log | | createFileLogWriter() | Creates a JSONL file writer (used internally by defaultLog) |

Accessing Log History

All log entries are kept in memory and can be retrieved:

const entries = provider.getLogEntries(); // all entries as an array
const logFile = provider.getLogFilePath(); // path to JSONL file (if file logging enabled)

LLMLogEntry Shape

interface LLMLogEntry {
  timestamp: string;
  provider: string;
  status: "success" | "retry" | "error";
  durationMs: number;
  attempt: number;
  request: {
    model: string;
    messageCount: number;
    totalCharLength: number;
    promptPreview: string;
    hasSystemPrompt: boolean;
    hasTools?: boolean; // true when tool schemas were passed
    maxTokens?: number;
    temperature?: number;
    messages?: LLMMessage[]; // only when includeContent: true
    systemPrompt?: string; // only when includeContent: true
  };
  response?: {
    text: string;
    tokensUsed: { input: number; output: number };
    finishReason: string;
    toolUseCount?: number; // number of tool calls in the response
  };
  error?: {
    message: string;
    retryable: boolean;
  };
}

Extending BaseLLMProvider

To create a custom provider with built-in retry and logging support:

import { BaseLLMProvider, type BaseLLMProviderOptions } from "@tepa/provider-core";
import type { LLMMessage, LLMRequestOptions, LLMResponse } from "@tepa/types";

export class MyProvider extends BaseLLMProvider {
  protected readonly providerName = "my-provider";

  constructor(options?: BaseLLMProviderOptions) {
    super(options);
  }

  protected async doComplete(
    messages: LLMMessage[],
    options: LLMRequestOptions,
  ): Promise<LLMResponse> {
    // Call your LLM API here
    return { text: "...", tokensUsed: { input: 0, output: 0 }, finishReason: "end_turn" };
  }

  protected isRetryable(error: unknown): boolean {
    return false;
  }

  protected getRetryAfterMs(error: unknown): number | null {
    return null;
  }

  protected isRateLimitError(error: unknown): boolean {
    return false;
  }
}

Custom providers automatically get file logging, retry logic, and onLog() support.