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/pi-provider-needle

v0.1.1

Published

pi-ai provider and pi extension for local Needle 2 inference

Readme

@fenwei/pi-provider-needle

A native @earendil-works/pi-ai provider for local Needle 2 inference, plus an installable pi extension.

pi-ai library

bun add @earendil-works/pi-ai @fenwei/pi-provider-needle @fenwei/needle.js
import { createModels, Type, type Context, type Tool } from "@earendil-works/pi-ai";
import { createNeedlePiProvider } from "@fenwei/pi-provider-needle";

const provider = createNeedlePiProvider({
  weights: "download",
  backend: "cpu",
});

const models = createModels();
models.setProvider(provider);

const model = models.getModel("needle", "needle-2")!;
const tools: Tool[] = [
  {
    name: "get_weather",
    description: "Get current weather for a city",
    parameters: Type.Object({ city: Type.String() }),
  },
];
const context: Context = {
  systemPrompt: "Use the available local tools.",
  messages: [{ role: "user", content: "Weather in Lagos?", timestamp: Date.now() }],
  tools,
};

const first = await models.completeSimple(model, context);
context.messages.push(first);

for (const block of first.content) {
  if (block.type !== "toolCall") continue;

  const result = { city: block.arguments.city, temperature: 27, sky: "clear" };
  context.messages.push({
    role: "toolResult",
    toolCallId: block.id,
    toolName: block.name,
    content: [{ type: "text", text: JSON.stringify(result) }],
    isError: false,
    timestamp: Date.now(),
  });
}

if (first.stopReason === "toolUse") {
  const final = await models.completeSimple(model, context);
  console.log(final.content);
}

await provider.dispose();

The provider exposes one zero-cost model:

| Provider | Model | API | Context | Output | | --- | --- | --- | ---: | ---: | | needle | needle-2 | needle-local | 2,048 | 512 |

It emits the standard pi-ai event protocol: start, buffered thinking/text/tool-call content events, and done or error. Inference errors and aborts become normal pi-ai error messages rather than rejected streams.

Install in pi

The package includes a pi extension manifest:

pi install npm:@fenwei/pi-provider-needle
pi --provider needle --model needle-2

The first inference downloads and caches the official model. Configure the extension with environment variables:

# Use a local or tuned archive instead of downloading the base model
export NEEDLE_MODEL_PATH=/path/to/needle2.cact

# cpu (default), typegpu, or auto
export NEEDLE_BACKEND=cpu

pi --provider needle --model needle-2

The extension registers the complete native pi-ai provider with pi.registerProvider(). It releases the loaded model on session_shutdown, including reload, session replacement, and quit.

Needle 2 has a 2,048-token context and is a compact tool-selection model, not a general-purpose coding LLM. For a practical demo, activate a small, clearly described tool set.

Configuration

createNeedlePiProvider() accepts all NeedleModel.load() options plus:

  • model / disposeModel — reuse a preloaded model and control ownership
  • agentOptions — defaults for constrained tool calling
  • providerId, providerName, modelId, modelName — catalogue identity overrides

Reasoning levels map to local reasoning-token caps:

| pi level | Tokens | | --- | ---: | | minimal | 32 | | low | 64 | | medium | 128 | | high | 256 | | xhigh | 384 | | max | 512 |

Use createNeedlePiApi() when you need only the ProviderStreams implementation, or createNeedlePiModel() when composing a custom provider.