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

@fenwei/needle-ai-provider

v0.1.1

Published

Vercel AI SDK provider for local Needle 2 inference

Readme

@fenwei/needle-ai-provider

A Vercel AI SDK language-model provider for running Needle 2 locally through @fenwei/needle.js.

bun add ai @fenwei/needle-ai-provider @fenwei/needle.js

Basic use

import { generateText } from "ai";
import { createNeedleProvider } from "@fenwei/needle-ai-provider";

const needle = createNeedleProvider({
  weights: "download",
  backend: "cpu",
});

const result = await generateText({
  model: needle("needle-2"),
  prompt: "Explain what a tool-calling model does.",
});

console.log(result.text);
await needle.dispose();

Needle 2 is primarily a tool-calling model. Raw text generation is available for AI SDK compatibility, but tool mode is the intended path.

Tool loop

import {
  generateText,
  jsonSchema,
  stepCountIs,
  tool,
} from "ai";
import { createNeedleProvider } from "@fenwei/needle-ai-provider";

const needle = createNeedleProvider({ weights: "download" });

const result = await generateText({
  model: needle(),
  prompt: "What's the weather in Lagos?",
  stopWhen: stepCountIs(4),
  tools: {
    get_weather: tool({
      description: "Get the current weather for a city",
      inputSchema: jsonSchema<{ city: string }>({
        type: "object",
        properties: { city: { type: "string" } },
        required: ["city"],
      }),
      execute: async ({ city }) => ({ city, temperature: 27, sky: "clear" }),
    }),
  },
});

console.log(result.toolCalls);
console.log(result.toolResults);
console.log(result.text);

The provider maps AI SDK function tools to Needle's byte-constrained JSON Schema grammar. Tool calls are returned as standard AI SDK tool-call content. On the next AI SDK step, the provider deterministically replays the conversation into a fresh Needle session and feeds the tool results back to the model.

Streaming

import { streamText } from "ai";

const result = streamText({
  model: needle(),
  prompt: "Hello",
});

for await (const chunk of result.textStream) {
  process.stdout.write(chunk);
}

The current provider emits an AI SDK-compatible buffered stream after local inference completes. Raw needle.js generation can provide token callbacks when token-by-token display is required.

Structured output

AI SDK JSON response formats are implemented as a synthetic Needle extraction tool. Calls with a JSON schema return the extracted arguments as JSON text.

Configuration

createNeedleProvider() accepts the normal NeedleModel.load() settings:

const needle = createNeedleProvider({
  weights: "./models/needle2.cact",
  backend: "typegpu",
  backendOptions: { device },
  agentOptions: {
    prefixSinkTokens: 160,
    maximumRetrievedTools: 5,
  },
});

A preloaded model can be shared:

const needle = createNeedleProvider({
  model,
  disposeModel: false,
});

Call provider.dispose() to release a model loaded by the provider. Caller-owned models are retained unless disposeModel: true is specified.

Per-call Needle options can be supplied through AI SDK provider options under the needle key:

providerOptions: {
  needle: {
    reasoningTokens: 128,
    prefixSinkTokens: 160,
    maxCallsPerTurn: 4,
    toolTokenBudget: 180,
    maximumRetrievedTools: 5,
  },
}

Unsupported AI SDK settings are returned through the standard warnings field. The provider implements the AI SDK v7 LanguageModelV4 and ProviderV4 contracts.