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

@verydia/providers

v0.1.0

Published

LLM provider registry and abstractions for Verydia

Readme

@verydia/providers

Universal provider registry and adapter layer for LLM providers.

Overview

This package provides:

  • A unified ProviderAdapter interface for LLM providers
  • A ProviderRegistry for managing and resolving providers
  • Production-ready adapters for major LLM providers
  • Type-safe provider configuration and model resolution
  • Mock-based testing with no real API calls

Implemented Adapters

✅ OpenAI (openaiAdapter)

Full implementation with:

  • Chat completions
  • SSE streaming
  • Embeddings (text-embedding-3-small, text-embedding-3-large, etc.)
  • Tool/function calling
  • Configurable base URL, timeout, organization

✅ Anthropic (anthropicAdapter)

Full implementation with:

  • Chat completions (Claude 3.5 Sonnet, etc.)
  • SSE streaming
  • Tool calling (Claude's tool use format)
  • System message handling (Anthropic requirement)
  • Configurable API version

✅ Google Gemini (geminiAdapter)

Full implementation with:

  • Chat completions (Gemini 1.5 Flash, Pro, etc.)
  • SSE streaming
  • Embeddings
  • Function declarations for tool calling
  • Uses Google's generativelanguage API

✅ Mistral (mistralAdapter)

Full implementation with:

  • Chat completions (Mistral Large, Medium, Small)
  • SSE streaming
  • Embeddings
  • Tool/function calling
  • OpenAI-compatible API format

✅ Ollama (ollamaAdapter)

Full implementation with:

  • Chat completions (local models: Llama 2, Mistral, etc.)
  • Streaming
  • Embeddings
  • Configurable base URL (default: http://localhost:11434)
  • No API key required (local deployment)

⚠️ AWS Bedrock (bedrockAdapter)

Placeholder - Requires AWS SDK integration:

  • Throws clear error directing to Anthropic adapter or AWS SDK
  • Ready for future implementation with SigV4 signing

Key Concepts

ProviderAdapter Interface

Each provider implements the ProviderAdapter interface:

interface ProviderAdapter<C extends ProviderBaseConfig> {
  readonly kind: ProviderKind;
  resolveModelId(config: C, logicalModel: string): string;
  invokeChat(config: C, req: ProviderChatRequest): Promise<ProviderChatResult>;
  streamChat?(config: C, req: ProviderChatRequest): AsyncIterable<ProviderStreamChunk>;
  embedding?(config: C, req: ProviderEmbeddingRequest): Promise<ProviderEmbeddingResult>;
  toolCall?(config: C, req: ProviderToolCallRequest): Promise<ProviderToolCallResult>;
}

ProviderRegistry

The registry manages provider instances and resolves model references:

const registry = new ProviderRegistry();
registry.register(openaiConfig);

const result = await registry.invokeChat("openai:gpt-4", {
  messages: [{ role: "user", content: "Hello!" }]
});

Usage Examples

OpenAI

import { openaiAdapter, createOpenAIConfig } from "@verydia/providers";

const config = createOpenAIConfig({
  apiKey: process.env.OPENAI_API_KEY!,
  modelAliases: {
    "gpt-4o-mini": "gpt-4o-mini-2024-07-18"
  }
});

const result = await openaiAdapter.invokeChat(config, {
  model: "gpt-4o-mini",
  messages: [{ role: "user", content: "Hello!" }],
  temperature: 0.7
});

console.log(result.text);

Anthropic

import { anthropicAdapter, createAnthropicConfig } from "@verydia/providers";

const config = createAnthropicConfig({
  apiKey: process.env.ANTHROPIC_API_KEY!,
});

const result = await anthropicAdapter.invokeChat(config, {
  model: "claude-3-5-sonnet-20241022",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user", content: "Explain TypeScript." }
  ],
});

console.log(result.text);

Streaming

for await (const chunk of openaiAdapter.streamChat!(config, {
  model: "gpt-4o-mini",
  messages: [{ role: "user", content: "Tell me a story" }],
})) {
  process.stdout.write(chunk.delta);
  if (chunk.done) {
    console.log("\n[Stream complete]");
  }
}

Testing Strategy

All adapters use mock-based testing with no real API calls:

  • No network calls in tests: All HTTP requests are mocked
  • Fixture-based responses: Tests use pre-defined response fixtures
  • Type safety verification: Tests ensure correct type transformations
  • CI-safe: No API keys required, instant test execution

Example test structure:

describe("OpenAI Adapter", () => {
  it("should have correct type signature", () => {
    expect(openaiAdapter.kind).toBe("openai");
    expect(typeof openaiAdapter.invokeChat).toBe("function");
  });

  it("should resolve model aliases", () => {
    const config = createOpenAIConfig({
      apiKey: "test",
      modelAliases: { "gpt-4o-mini": "gpt-4o-mini-2024-07-18" }
    });
    
    const resolved = openaiAdapter.resolveModelId(config, "gpt-4o-mini");
    expect(resolved).toBe("gpt-4o-mini-2024-07-18");
  });
});

Architecture

@verydia/providers
├── src/
│   ├── types.ts              # Core interfaces
│   ├── index.ts              # ProviderRegistry
│   ├── builtinProviders.ts   # Default configs
│   └── adapters/
│       ├── index.ts          # Adapter exports
│       ├── openaiAdapter.ts  # OpenAI implementation
│       ├── anthropicAdapter.ts
│       ├── geminiAdapter.ts
│       ├── mistralAdapter.ts
│       ├── bedrockAdapter.ts
│       └── ollamaAdapter.ts
└── test/
    ├── providers.test.ts     # Registry tests
    └── openaiAdapter.test.ts # Adapter tests

For Contributors

Adding a New Provider

  1. Create src/adapters/yourProviderAdapter.ts
  2. Implement the ProviderAdapter interface
  3. Export from src/adapters/index.ts
  4. Add config creator function (e.g., createYourProviderConfig)
  5. Add tests in test/yourProviderAdapter.test.ts
  6. Update this README

Adapter Implementation Checklist

  • [ ] Implement invokeChat() (required)
  • [ ] Implement streamChat() if provider supports streaming
  • [ ] Implement embedding() if provider supports embeddings
  • [ ] Implement toolCall() if provider supports function calling
  • [ ] Add proper error handling and timeout support
  • [ ] Add cost estimation in usage metadata
  • [ ] Write mock-based tests (no real API calls)
  • [ ] Document provider-specific quirks

License

Apache-2.0