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

@charivo/llm-client-remote

v0.0.1

Published

Remote LLM client for Charivo (calls server API)

Readme

@charivo/llm-client-remote

Remote HTTP LLM client for Charivo (client-side).

Features

  • 🔐 Secure - API keys stay on server
  • 🌐 HTTP-based - Works with any server endpoint
  • 🎯 Type-Safe - Full TypeScript support
  • 🔌 Flexible - Use any LLM provider on the backend

Installation

pnpm add @charivo/llm-client-remote @charivo/core

Usage

Client-side Setup

import { createRemoteLLMClient } from "@charivo/llm-client-remote";
import { createLLMManager } from "@charivo/llm-core";

const client = createRemoteLLMClient({
  apiEndpoint: "/api/chat" // Your server endpoint
});

const llmManager = createLLMManager(client);
llmManager.setCharacter({
  id: "assistant",
  name: "Hiyori",
  personality: "Cheerful and helpful"
});

const response = await llmManager.generateResponse({
  id: "1",
  content: "Hello!",
  timestamp: new Date(),
  type: "user"
});

Server-side Implementation (Required)

Use @charivo/llm-provider-openai for easy setup:

// app/api/chat/route.ts (Next.js)
import { NextRequest, NextResponse } from "next/server";
import { createOpenAILLMProvider } from "@charivo/llm-provider-openai";

const provider = createOpenAILLMProvider({
  apiKey: process.env.OPENAI_API_KEY!,
  model: "gpt-4"
});

export async function POST(request: NextRequest) {
  try {
    const { messages } = await request.json();
    const message = await provider.generateResponse(messages);
    
    return NextResponse.json({ success: true, message });
  } catch (error) {
    return NextResponse.json(
      { success: false, error: "Chat failed" },
      { status: 500 }
    );
  }
}

API Reference

Constructor

new RemoteLLMClient(config: RemoteLLMConfig)

Configuration Options

interface RemoteLLMConfig {
  /** Server API endpoint (default: "/api/chat") */
  apiEndpoint?: string;
  /** Request timeout in ms (default: 30000) */
  timeout?: number;
}

Methods

call(messages)

Send messages to the server and get a response.

const response = await client.call([
  { role: "user", content: "Hello!" },
  { role: "assistant", content: "Hi there!" },
  { role: "user", content: "How are you?" }
]);

Complete Example

Client (React)

import { Charivo } from "@charivo/core";
import { createLLMManager } from "@charivo/llm-core";
import { createRemoteLLMClient } from "@charivo/llm-client-remote";

function App() {
  const [charivo] = useState(() => {
    const charivo = new Charivo();
    
    const client = createRemoteLLMClient({
      apiEndpoint: "/api/chat"
    });
    const llmManager = createLLMManager(client);
    
    charivo.attachLLM(llmManager);
    charivo.setCharacter({
      id: "hiyori",
      name: "Hiyori",
      personality: "Cheerful AI assistant"
    });
    
    return charivo;
  });

  const handleSend = async (message: string) => {
    await charivo.userSay(message, "hiyori");
    console.log(response);
  };

  return <ChatUI onSend={handleSend} />;
}

Server (Next.js API Route)

// app/api/chat/route.ts
import { NextRequest, NextResponse } from "next/server";
import { createOpenAILLMProvider } from "@charivo/llm-provider-openai";

const provider = createOpenAILLMProvider({
  apiKey: process.env.OPENAI_API_KEY!,
  model: "gpt-4"
});

export async function POST(request: NextRequest) {
  const { messages } = await request.json();
  const message = await provider.generateResponse(messages);
  
  return NextResponse.json({ success: true, message });
}

Why Use Remote Client?

Security ✅

  • API keys never exposed to client
  • Server-side authentication
  • Rate limiting per user

Flexibility ✅

  • Switch LLM providers without client changes
  • Server-side prompt engineering
  • Response caching and optimization
  • Custom business logic

Cost Control ✅

  • Monitor and limit API usage
  • Implement quotas per user
  • Cache common responses
  • Optimize token usage

Error Handling

try {
  const response = await client.call(messages);
} catch (error) {
  if (error.response?.status === 429) {
    console.error("Rate limit exceeded");
  } else if (error.response?.status === 500) {
    console.error("Server error");
  } else {
    console.error("Chat failed:", error);
  }
}

Custom Backend

You can use any backend that returns a response:

// Your custom API
export async function POST(request: Request) {
  const { messages } = await request.json();
  
  // Call any LLM API (Anthropic, Cohere, etc.)
  const response = await yourLLMAPI.generateCompletion(messages);
  
  return Response.json({ success: true, message: response });
}

Related Packages

License

MIT