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

@dsanders11/electron-llm

v2.2.1

Published

A LanguageModel subclass for the Electron Prompt API powered by node-llama-cpp.

Readme

@electron/llm

Test npm version

A LanguageModel subclass for Electron's Prompt API, powered by node-llama-cpp. Load any GGUF model and serve it to renderers via the standard LanguageModel web API.

This module requires Electron with Prompt API support (see electron/electron#50659).

How It Works

Electron's Prompt API lets web content call LanguageModel.create() and model.prompt() just like in Chrome. Your Electron app decides what model handles the request by running a UtilityProcess that registers a LanguageModel subclass via localAIHandler.setPromptAPIHandler().

@electron/llm provides LlamaCppLanguageModel — a ready-made LanguageModel subclass that wires up node-llama-cpp so you don't have to write the boilerplate yourself. Subclass it, set modelPath, and you're done.

Import model classes and helpers from @electron/llm/prompt-api (for use inside a UtilityProcess).

Install

npm install @electron/llm

Quick Start

1. Create the utility process script

// ai-handler.js (runs in a UtilityProcess)
import { LlamaCppDownloadingLanguageModel, waitForMessage } from '@electron/llm/prompt-api';
import { localAIHandler } from 'electron/utility';
import path from 'node:path';

const { options } = await waitForMessage((msg) => msg.type === 'init');

class MyModel extends LlamaCppDownloadingLanguageModel {
  static modelUrl = 'https://huggingface.co/user/repo/resolve/main/model.gguf';
  static modelPath = path.join(options.userDataPath, 'model.gguf');
}

localAIHandler.setPromptAPIHandler(() => MyModel);

2. Register it in the main process

// main.js
import { app, BrowserWindow, utilityProcess, session } from 'electron';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

app.whenReady().then(() => {
  const child = utilityProcess.fork(path.join(__dirname, 'ai-handler.js'));
  child.postMessage({ type: 'init', options: { userDataPath: app.getPath('userData') } });

  const win = new BrowserWindow({
    webPreferences: {
      enableBlinkFeatures: 'AIPromptAPI',
    },
  });

  session.defaultSession.registerLocalAIHandler(child);
  win.loadFile('index.html');
});

3. Use the Prompt API in your renderer

<script>
  async function askAI() {
    const model = await LanguageModel.create();
    const response = await model.prompt('What is Electron?');
    document.getElementById('response').textContent = response;
  }
</script>
<button onclick="askAI()">Ask AI</button>
<p id="response"></p>

API

@electron/llm/prompt-api

waitForMessage(predicate): Promise<T>

Waits for a message on process.parentPort that satisfies the predicate. Returns the data of the first matching message; non-matching messages are ignored and the listener is removed after a match.

import { waitForMessage } from '@electron/llm/prompt-api';
const message = await waitForMessage((msg) => msg.type === 'init');

LlamaCppLanguageModel

A LanguageModel subclass that uses node-llama-cpp to run GGUF models locally.

static modelPath: string | null

Path to the GGUF model file. Must be set before the model can be created. Set this in your subclass:

class MyModel extends LlamaCppLanguageModel {
  static modelPath = '/absolute/path/to/model.gguf';
}

LlamaCppDownloadingLanguageModel

A subclass of LlamaCppLanguageModel that automatically downloads a GGUF model from a URL before creating a session. If the model file already exists on disk, the download is skipped.

static modelUrl: string | null

The URL to download the GGUF model from. Must be set before the model can be created.

static modelPath: string | null

Where to save the downloaded model. Must be set explicitly — use waitForMessage to receive the app's userData path from the main process and build a path:

import { LlamaCppDownloadingLanguageModel, waitForMessage } from '@electron/llm/prompt-api';
import path from 'node:path';

const { options } = await waitForMessage((msg) => msg.type === 'init');

class MyModel extends LlamaCppDownloadingLanguageModel {
  static modelUrl = 'https://huggingface.co/user/repo/resolve/main/phi-3.gguf';
  static modelPath = path.join(options.userDataPath, 'phi-3.gguf');
}

Testing

npm test              # run tests once
npm run test:watch    # watch mode
npm run test:coverage # with coverage