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

plugin-web-search

v0.1.9

Published

A plugin for powerful web search capabilities, providing efficient search query handling and result processing through a customizable API interface.

Readme

@elizaos/plugin-web-search

A plugin for powerful web search capabilities, providing efficient search query handling and result processing through a customizable API interface.

Overview

This plugin provides functionality to:

  • Execute web search queries with customizable parameters
  • Process and format search results
  • Handle search API authentication
  • Manage token limits and response sizes
  • Optimize query performance

Installation

pnpm install @elizaos/plugin-web-search

Configuration

The plugin requires the following environment variables:

TAVILY_API_KEY=your_api_key    # Required: API key for search service

Usage

Import and register the plugin in your Eliza configuration.

import { webSearchPlugin } from "@elizaos/plugin-web-search";

export default {
    plugins: [webSearchPlugin],
    // ... other configuration
};

Custom Usage If you want custom usage, for example, twitter-client to search the web before posting a tweet, you can also import the webSearchService and use it directly. Here's how you can do it:

// packages/client-twitter/src/post.ts
const webSearchService = new WebSearchService();
await webSearchService.initialize(runtime);
const latestNews = await webSearchService.search(
    "latest news on AI Agents",
    // searchOptions
);

const state = await this.runtime.composeState(
    {  } // memory,
    { // additional keys
        latestNews: latestNews,
    }
);

// Then modify the tweet template to include the {{latestNews}} and however you need

Features

Web Search

The plugin provides comprehensive web search capabilities:

import { webSearch } from "@elizaos/plugin-web-search";

// Execute a search query
const result = await webSearch.handler(
    runtime,
    {
        content: { text: "What is the latest news about AI?" },
    },
    state,
    {},
    callback
);

Token Management

// The plugin automatically handles token limits
const DEFAULT_MAX_WEB_SEARCH_TOKENS = 4000;

// Example of token-limited response
const response = MaxTokens(searchResult, DEFAULT_MAX_WEB_SEARCH_TOKENS);

Development

Building

pnpm run build

Testing

pnpm run test

Development Mode

pnpm run dev

Dependencies

  • @elizaos/core: Core Eliza functionality
  • js-tiktoken: Token counting and management
  • tsup: Build tool
  • Other standard dependencies listed in package.json

API Reference

Core Interfaces

interface Action {
    name: "WEB_SEARCH";
    similes: string[];
    description: string;
    validate: (runtime: IAgentRuntime, message: Memory) => Promise<boolean>;
    handler: (
        runtime: IAgentRuntime,
        message: Memory,
        state: State,
        options: any,
        callback: HandlerCallback
    ) => Promise<void>;
    examples: Array<Array<any>>;
}

interface SearchResult {
    title: string;
    url: string;
    answer?: string;
    results?: Array<{
        title: string;
        url: string;
    }>;
}

Plugin Methods

  • webSearch.handler: Main method for executing searches
  • generateWebSearch: Core search generation function
  • MaxTokens: Token limit management function
  • getTotalTokensFromString: Token counting utility

Common Issues/Troubleshooting

Issue: API Authentication Failures

  • Cause: Invalid or missing Tavily API key
  • Solution: Verify TAVILY_API_KEY environment variable

Issue: Token Limit Exceeded

  • Cause: Search results exceeding maximum token limit
  • Solution: Results are automatically truncated to fit within limits

Issue: Search Rate Limiting

  • Cause: Too many requests in short time
  • Solution: Implement proper request throttling

Security Best Practices

  • Store API keys securely using environment variables
  • Validate all search inputs
  • Implement proper error handling
  • Keep dependencies updated
  • Monitor API usage and rate limits
  • Use HTTPS for API communication

Example Usage

// Basic search
const searchQuery = "Latest developments in quantum computing";
const results = await generateWebSearch(searchQuery, runtime);

// With formatted response
if (results && results.results.length) {
    const formattedResponse = `${results.answer}\n\nFor more details, check out:\n${results.results
        .map(
            (result, index) => `${index + 1}. [${result.title}](${result.url})`
        )
        .join("\n")}`;
}

Configuration Options

Token Management

const DEFAULT_MODEL_ENCODING = "gpt-3.5-turbo";
const DEFAULT_MAX_WEB_SEARCH_TOKENS = 4000;

Search Actions

The plugin includes multiple search action similes:

  • SEARCH_WEB
  • INTERNET_SEARCH
  • LOOKUP
  • QUERY_WEB
  • FIND_ONLINE
  • And more...

Contributing

Contributions are welcome! Please see the CONTRIBUTING.md file for more information.

Credits

This plugin integrates with and builds upon several key technologies:

  • Tavily API: Advanced search and content analysis API
  • js-tiktoken: Token counting for API responses
  • Zod: TypeScript-first schema validation

Special thanks to:

  • The Eliza community for their contributions and feedback

For more information about the search capabilities and tools:

License

This plugin is part of the Eliza project. See the main project repository for license information.