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

@lyndonkl/gemma-webworker-wrapper

v0.1.8

Published

A TypeScript wrapper for the MediaPipe Gemma model

Readme

@lyndonkl/gemma-worker-wrapper

A TypeScript wrapper for the MediaPipe Gemma model, providing a simple interface for chat interactions and conversation management.

Installation

npm install @lyndonkl/gemma-worker-wrapper @mediapipe/tasks-genai

Requirements

  • Modern browser with WebAssembly support
  • Sufficient memory for model loading
  • CORS-enabled server for serving model files

Usage

import { GemmaWrapper } from '@lyndonkl/gemma';

async function main() {
  // Initialize the wrapper
  const gemma = await GemmaWrapper.create({
    systemMessage: 'You are a helpful assistant',
    modelAssetPath: '/path/to/gemma-2b-it-gpu-int4.bin' // Optional, defaults to '/assets/gemma-2b-it-gpu-int4.bin'
  });
  
  // Send a message and get response
  const response = await gemma.invoke('Hello, how are you?');
  console.log(response);

  // Get conversation history
  const history = gemma.getMessageHistory();
  
  // Clear conversation history
  gemma.clearHistory();
  
  // Update system message
  gemma.setSystemMessage('You are a coding assistant');
}

Worker Configuration

The package uses a Web Worker to run the Gemma model. Due to the MediaPipe library's use of importScripts(), the worker must be configured as a classic worker (not an ES module worker). Here's how to set it up:

  1. Copy the worker file to your public directory:
mkdir -p public/worker
cp node_modules/@lyndonkl/gemma-webworker-wrapper/dist/worker.js public/worker/
  1. If you're using a bundler (like Vite, webpack, etc.), configure it to:

    • Bundle the worker file as a single file
    • Use IIFE (Immediately Invoked Function Expression) format
    • Exclude the worker from module transformation
  2. Update your worker URL in the GemmaWrapper options:

const gemma = await GemmaWrapper.create({
  workerUrl: '/worker/worker.js',  // Path relative to your public directory
  systemMessage: 'You are a helpful assistant'
});

React Integration

import { useState, useEffect } from 'react';
import { GemmaWrapper } from '@lyndonkl/gemma-worker-wrapper';

function ChatComponent() {
  const [gemma, setGemma] = useState<GemmaWrapper | null>(null);
  const [response, setResponse] = useState('');

  useEffect(() => {
    async function initGemma() {
      const wrapper = await GemmaWrapper.create({
        workerUrl: '/worker/worker.js',  // Path to your worker file
        systemMessage: 'You are a helpful assistant'
      });
      setGemma(wrapper);
    }
    initGemma();
  }, []);

  async function handleSubmit(message: string) {
    if (!gemma) return;
    const response = await gemma.invoke(message);
    setResponse(response);
  }

  // ... rest of component
}

API Reference

GemmaWrapper

The main class for interacting with the Gemma model.

Constructor Options

type GemmaWrapperOptions = {
  systemMessage?: string;      // Initial system message
  modelAssetPath?: string;    // Path to model file
  maxTokens?: number;         // Maximum tokens to generate
  topK?: number;             // Top-k sampling parameter
  temperature?: number;      // Temperature for sampling
  randomSeed?: number;       // Random seed for generation
  workerUrl?: string;        // Path to the worker file
};

Methods

  • invoke(message: string): Promise<string> - Send a message and get response
  • getMessageHistory(): Message[] - Get conversation history
  • clearHistory(): void - Clear conversation history
  • setSystemMessage(message: string): void - Update system message

Troubleshooting

  • "Failed to load fileset": Ensure WASM files are accessible and CORS is configured
  • "Model not initialized": Wait for initialization to complete before calling invoke
  • "Failed to load model": Verify model path and file accessibility
  • "importScripts is not defined": Ensure the worker is configured as a classic worker, not an ES module worker
  • "Worker failed to load": Check that the worker file is accessible and served with the correct MIME type

License

MIT