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

@toon-ui/core

v2.1.7

Published

Core parser, AST, validation, and protocol utilities for ToonUI.

Readme

@toon-ui/core

Server-safe protocol utilities for ToonUI.

ToonUI lets an LLM describe semantic UI inside chat. @toon-ui/core is the package that defines the allowed catalog, generates the model prompt, parses/validates ToonUI blocks, and converts UI interactions back into model-readable messages.

Install

pnpm add @toon-ui/core

Use this package when you are building the server/protocol side only. If you also need React rendering, install @toon-ui/react in the client package.

Quick start

import { createToonProtocol } from '@toon-ui/core';

const toon = createToonProtocol({
  components: ['text', 'card', 'form', 'field', 'button', 'confirm'],
});

const system = [
  'You are an assistant inside our product.',
  toon.prompt,
  'Available tools:',
  '- createProduct(name, price)',
].join('\n\n');

toon.prompt is generated from the active catalog. If your app does not enable chart, the prompt does not teach the model to emit chart.

Mental model

| API | Purpose | | --- | --- | | catalog | The ToonUI language subset your app allows. | | prompt | Model-facing instructions generated from that catalog. | | rules | Small runtime summary of enabled components and variants. | | events | Helpers for creating reply/submit interaction payloads. | | messages | Helpers for reinjecting interactions into chat state. |

Recommended server flow

import { createToonProtocol } from '@toon-ui/core';

const toon = createToonProtocol({
  components: ['text', 'alert', 'form', 'field', 'button'],
});

export async function POST(request: Request) {
  const { messages } = await request.json();

  return streamText({
    model,
    system: toon.prompt,
    messages,
  });
}

Then render the assistant output on the client with your registered components in @toon-ui/react.

Parse and validate model output

import { parseToonUI, validateToonUI, createToonProtocol } from '@toon-ui/core';

const toon = createToonProtocol({
  components: ['text', 'card', 'button'],
});

const source = `card "Next step":\n  text "Choose an action."\n  button primary "Continue" reply="continue"`;

const ast = parseToonUI(source);
const result = validateToonUI(ast, toon.catalog);

if (!result.ok) {
  console.error(result.errors);
}

Convert UI events into chat messages

const reply = toon.events.reply('show-products');

const content = toon.messages.toContent(reply);
const modelMessage = toon.messages.toModelMessage(reply);
const uiMessage = toon.messages.toUIMessage(reply);

For forms:

const submit = toon.events.submit('create_product', {
  name: 'Coca-Cola',
  price: 25.5,
});

const message = toon.messages.toModelMessage(submit);

These helpers keep user interactions machine-readable for the model while still preserving display-friendly content for your app.

Public API

| Export | Use it for | | --- | --- | | createToonProtocol() | Create the catalog-aware prompt plus event/message helpers. | | createToonCoreRuntime() | Create a protocol runtime with parser, validator, and block extraction. | | createRules() | Get enabled component/variant rules from a catalog. | | createToonCatalog() | Build the active catalog from official ToonUI component keys. | | TOON_CATALOG | Full official catalog definition. | | parseToonUI() | Parse one ToonUI block into an AST. | | validateToonUI() | Validate parsed nodes against the active catalog. | | extractToonBlocks() | Extract fenced toon-ui blocks from assistant markdown. | | extractToonSegments() | Split assistant markdown into markdown and ToonUI segments. | | createPrompt() and prompt helpers | Compose lower-level prompt sections when you need custom prompt assembly. | | Types | Catalog, node, payload, message, and runtime TypeScript types. |

Boundary

@toon-ui/core does not render UI and does not execute tools. It is safe to use on the server.

For React rendering, use @toon-ui/react.

Links

  • Documentation: https://toon-ui.dev/docs
  • Core API docs: https://toon-ui.dev/docs/packages/core
  • Playground: https://toon-ui.dev/playground