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

@ai-gui/plugin-function

v0.29.2

Published

Function and calculus figures for AIGUI — curves, tangents, areas, Riemann sums, computed from an expression rather than from sampled points.

Readme

@ai-gui/plugin-function

Function and calculus figures for AIGUI. The model writes y = f(x) and an interval; the curve, its tangents, the area under it and its Riemann rectangles are computed here.

Install

pnpm add @ai-gui/plugin-function

No plotting library, no canvas, no runtime dependency beyond @ai-gui/core. The output is an SVG string.

Usage

import { fn } from "@ai-gui/plugin-function"
import { buildSystemPrompt } from "@ai-gui/core"

<AIRenderer plugins={[fn()]} />

// The model has no prior for this block, so the spec is what makes it usable at all.
const system = buildSystemPrompt({ registry, plugins: [fn()], locale: "zh-CN" })
f(x) = x² 在 x = 1 处的切线斜率为 2,切线方程 y = 2x − 1。

```function
{
  "plot": [{ "id": "f", "expr": "x^2", "domain": [-1.5, 2.5], "label": "y = x²" }],
  "marks": [
    { "tangent": { "of": "f", "at": 1 } },
    { "point": { "on": "f", "at": 1, "label": "P(1, 1)" } }
  ],
  "caption": "f(x) = x² 在 P(1,1) 处的切线"
}
```

Why the protocol looks like this

An expression, never sampled points. A model that plots the curve itself has put its own arithmetic into the picture, and a wrong point looks exactly like a right one. A definition containing points, data, values or samples is refused outright.

The slope is measured, not stated. tangent takes the point; the derivative is computed by central difference. An answer that mis-differentiates in its prose still draws the right line — and the k = … label on the figure comes from the same measurement, so the picture cannot contradict itself.

Every reference must resolve. A mark naming a curve no plot defines is refused rather than skipped, so a figure never silently omits the thing the answer is pointing at.

Intervals may be written the way a question states them. [0, "2*pi"] and ["-pi/2", "pi/2"] are constant expressions, evaluated by the same parser. Forcing 6.283185 is unnatural and is one more place for the model to do arithmetic.

The expression grammar

x is the only variable. Multiplication is always explicit (2*x, never 2x), powers use ^, and functions need brackets. Available: sin cos tan asin acos atan sinh cosh tanh exp ln log log2 sqrt abs sign floor ceil round, plus pi and e.

There is no eval anywhere: this is a recursive-descent parser over a fixed grammar with a fixed function table, looked up with Object.hasOwn so an expression cannot reach Object.prototype. A sign binds looser than a power, so -x^2 is negative — parsed the other way it is a different curve, and one that looks perfectly reasonable on screen.

Marks

| | | | --- | --- | | tangent | {"of":"f","at":1} — slope measured here | | area | {"of":"f","from":0,"to":2}, or {"between":["f","g"],…} | | riemann | {"of":"f","from":0,"to":1,"n":8,"rule":"left"\|"right"\|"mid"} | | point | {"on":"f","at":1,"label":"P"} | | asymptote | {"x":0} or {"y":1} | | derivative | {"of":"f"} — the curve of f′, sampled the same way f is |

Not in this version, and the prompt spec tells the model to explain them in prose or use ```chart instead: implicit curves, polar and parametric curves, surfaces, the complex plane, and the scatter of a sequence or distribution.

Options

  • width?, height? — figure size in CSS pixels, default 640 × 380.
  • samples? — points per curve, default 480.
  • maxCurves? — default 8. maxSourceBytes? — default 16 KiB.

Testing note

src/fixtures/ holds the twenty figures a model produced when given this plugin's prompt spec and twenty textbook questions. They are part of the test suite: a protocol change they stop parsing is one that breaks answers already being written.

See the root README for the full plugin list.