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

@ngriffin_uk/polychat-ai-functions

v0.2.0

Published

Typed AI interaction primitives for Polychat: text and structured generation, lists, extraction, classification, media generation, transcription, retrieval and guardrails over the provider library

Readme

@ngriffin_uk/polychat-ai-functions

Task-shaped AI functions over a ProviderRuntime: text generation and structured output, plus list, extract, classify, score, summarise, and is, calibrated decisions through decide, provider-neutral reranking, media generation and transcription, and search, research, and guard retrieval. Hosts call these instead of building provider requests by hand.

import { createAiFunctions } from "@ngriffin_uk/polychat-ai-functions";

const ai = createAiFunctions(providerRuntime);

const title = await ai.generateText({
  prompt: "Name this thread",
  model: "claude-haiku-4-5",
  env,
});
const labels = await ai.classify({
  input: text,
  labels: ["bug", "feature"],
  env,
});
const { object } = await ai.generateObject({ prompt, schema, env });
const image = await ai.image({ prompt: "a parrot on a perch", env, user });

complete returns the text alongside the provider's id, logId, citations and usage when it reports them, plus the raw response. generateObject requests a JSON schema response, asks for strict mode only when every property is required, and validates the parsed result against the Zod schema.

defineFunctions turns a map of { name: { input shape, output shape } } into typed callables backed by generateObject. template gives a tagged template that renders into generateText. Media functions route to the provider named on the request, then to the host default for that category.

Decisions

decide sends a state and a map of typed questions to the account's decision model (Jev, then Workers AI Clef Flash or Clef, then OpenAI GPT-6 Luna when getAuxiliaryDecisionModel resolves one) and returns answers typed by question id. tryDecide returns null instead of throwing when no decision model is available, which is how hot paths gate work without depending on provider availability. choice, score and noul build questions.

Pin Clef explicitly with provider: "workers-ai" and model: "@cf/cloudflare/clef", or select @cf/cloudflare/clef-flash for latency-sensitive decisions. Workers AI needs the host's AI binding and uses the same text and structured-state questions as Jev. Embedded images and video are not exposed by this decision contract.

Pass a catalogue decision model ID without provider to resolve its provider automatically. The Decide tool exposes these models in its Decision model selector; choose Automatic to retain the account's default selection. Enter Questions as a JSON object and State as plain text, a JSON object or a JSON array. The form parses structured inputs before submission and flags invalid JSON beside the field.

defineDecisionPolicy gives repeated hot-path judgements a stable key, versioned questions and a deterministic evaluator. evaluateDecisionPolicy applies a valid recommendation and returns a receipt without copying the state, questions or provider errors into it. Missing, failed or invalid decisions retain the caller's fallback. A policy result is evidence for its caller and never grants tool or data authority.

import { choice, noul } from "@ngriffin_uk/polychat-ai-functions";

const result = await ai.decide({
  env,
  user,
  state: { message },
  questions: {
    urgent: noul("Does `message` convey urgency?"),
    team: choice("Which team should handle `message`?", ["billing", "technical", "sales"]),
  },
});

result.answers.urgent.noul; // 0.97
result.answers.team.choice; // "billing"

classify, score and is use the decision model when one resolves and fall back to generateObject on the chat model otherwise, so callers get calibrated probabilities when a decision provider is configured.

Reranking

rerank orders typed documents against a query through the first-class reranking capability. By default the host selects the first accessible model in the reranking lineup; callers may pin an accessible reranking model and provider. The caller supplies toText to create the provider input, and results retain each original document and index alongside its relevance score.

const ranking = await ai.rerank({
  env,
  user,
  query: "parrots",
  documents: candidates,
  toText: (candidate) => `${candidate.title}\n${candidate.content}`,
});

const rankedCandidates = ranking.results.map(({ document }) => document);

Provider-specific tuning stays out of retrieval callers. To choose a different registered reranker, pass its catalogue reference through the same Interface:

const ranking = await ai.rerank({
  env,
  user,
  model: "rerank-v4.0-pro",
  provider: "cohere",
  query,
  documents: candidates,
  toText,
});

tryRerank returns null when no reranking model is available. It does not hide provider failures or choose how reranking combines with an existing retrieval order; callers own that baseline and fallback policy.