@zooly/nl-tools-srv turns a natural-language query and a caller-supplied tool list into ranked tools, filled arguments, and executed results. Jev shortlists, Needle 3 fills arguments locally (WASM), and Gemini 3.8 Flash runs only when required args are missing or Needle cannot load.
This package is server-only. It reads AI_GATEWAY_API_KEY and must not be imported from client code. The playground UI lives in @zooly/nl-tools-client.
@zooly/nl-tools-srvpackages/nl-tools/srv/admin/nl-tools in zooly-app (e-commerce fixture)query → Jev shortlist (top 5 + companions) → Needle 3 → Gemini fallback if needed
Needle 3 is about 35 MB of weights plus a 0.6 MB WASM engine, downloaded from Hugging Face into /tmp/cactus-needle on Vercel (or ~/.cache/cactus-needle locally). It does not run on the Edge runtime. The admin route uses runtime = "nodejs" and maxDuration = 60.
If WASM cannot instantiate, the result still includes a needle.error and Jev + Gemini continue.
import { handleNlQuery, isNlToolsConfigured } from "@zooly/nl-tools-srv";
const result = await handleNlQuery({
query: "cancel order 4821",
tools: [
{
name: "cancel_order",
description: "Cancel an open order.",
parameters: {
type: "object",
properties: { order_id: { type: "string" } },
required: ["order_id"],
},
companion: "list_orders",
execute: async ({ order_id }) => ({ cancelled: order_id }),
},
],
});
| Export | Purpose |
|---|---|
handleNlQuery({ query, tools, ... }) | Full pipeline. Tools are passed in — there is no built-in catalogue. |
isNlToolsConfigured() | True when AI_GATEWAY_API_KEY is set. |
@zooly/nl-tools-srv/fixtures/ecommerce | Optional mock shopper catalogue and handleEcommerceQuery used by the admin playground. |
name, description, parameters (JSON Schema) — what Jev and Needle seecompanion — extra list tool given to Gemini only (e.g. cancel_order → list_orders). Needle never sees it.execute — your function; the package never talks to product DBssystem — Needle facts (date, locale, user)noneDescription / jevInstructions — Jev refuse / ranking copytopK — default 5fallbackModel — default google/gemini-3.8-flashisNeedleFailure — override the default empty/placeholder-id heuristic| Variable | Required | Purpose |
|---|---|---|
AI_GATEWAY_API_KEY | yes | Jev evaluate + Gemini fallback via Vercel AI Gateway |
NEEDLE3_CACHE | no | Directory for WASM + weights. Defaults to /tmp/cactus-needle on Vercel |
NEEDLE3_CACT | no | Pre-downloaded needle3.cact path, skips the Hugging Face fetch |
Signed-in admins can hit /admin/nl-tools and run one shopper query against the e-commerce fixture. Do not batch the full 46-query demo on that page.
This package does not wire z-agent, merch, or stats. Those products import handleNlQuery and pass their own tools.