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

jsx-agent

v0.0.7

Published

**JSX Agent** lets you build AI agents with **stateful and reactive JSX components**. Inspired by React, it lets you focus on designing the agent's behavior declaratively, without worrying about the underlying execution.

Readme

JSX Agent

JSX Agent lets you build AI agents with stateful and reactive JSX components. Inspired by React, it lets you focus on designing the agent's behavior declaratively, without worrying about the underlying execution.

Here's how it works:

  1. You define prompts as a function of state with JSX
  2. The LLM updates state through "event handlers"
  3. The next message automatically renders based on updated state

🚧 Work in Progress: This library is still in its early stages. Expect breaking changes. Contributions and feedback are welcome!

Getting started

npm install jsx-agent

Install AI SDK as well for easy integration with LLMs:

npm install ai

Next, in your tsconfig.json, specify the jsx import source:

{
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "jsx-agent"
  }
}

Build an LLM interface

Let's build a simple number guessing game using JSX Agent.

The AI will guess a number between 1 and 100, and we'll use state to track its attempts.

import { Action, SystemPrompt, terminate, useState } from "jsx-agent";
import { z } from "zod";

type Input = {
  number: number;
};

export function NumberGame() {
  // the number AI has to guess is provided as input when running the agent
  const { number } = useInput<Input>();
  const [guess, setGuess] = useState<number | null>(null);

  const text = !guess
    ? "Guess a number"
    : guess < number
    ? `Your guess is lower than the number`
    : `Your guess is higher than the number`;

  return (
    <>
      {/* Provide AI with system prompt */}
      <SystemPrompt>
        You are supposed to guess a number between 1 and 100. Good luck!
      </SystemPrompt>

      {/* Display AI's guess in JSX */}
      <x-guess>{text}</x-guess>

      {/* AI can trigger this action to submit a new guess */}
      <Action
        name="guessANumber"
        description="Pick a number that is your next guess"
        parameters={z.object({ number: z.number() })}
        execute={({ number: nextGuess }) => {
          if (nextGuess === number) {
            terminate();
            setGuess(null);
          } else {
            setGuess(nextGuess);
          }
        }}
      />
    </>
  );
}

The content of SystemPrompt will automatically be hoisted to the system prompt, similarly to the behavior of Head in React. The Action element becomes a tool that the LLM can make use of.

The x-guess element becomes part of the current user prompt and compiles to

<guess>
Guess a number
</guess>

When the AI submits a guess, the state updates, and a new prompt is rendered reflecting the AI's response:

<guess>
Your guess is higher than the number
</guess>

To run it, simply create an agent with createAgent and a model from AI SDK:

import { createAgent } from "jsx-agent";
import { openai } from "@ai-sdk/openai";

const agent = createAgent<Input>({
  prompt: <NumberGame />,
  model: openai("gpt-4o"),
  maxSteps: 20,
});

// the argument provided here is picked up by `useInput`
await agent.run({ number: 34 });

When the agent terminates, you can call agent.run again with a new number. It will continue from where it left off and render the next message using the new input from the useInput hook.

Async Resources

Your JSX components can be asynchronous, which makes it easy to integrate your app with APIs or the file system:

async function Directory() {
  const files = await getFilePaths();

  return (
    <x-files>
      {files.map((path) => (
        <x-file>{path}</x-file>
      ))}
    </x-files>
  );
}

async function FileContent({ path }: { path: string }) {
  const content = await readFile(path);

  return (
    <>
      <x-file-path>{path}</x-file-path>
      <x-file-content>{content}</x-file-content>
    </>
  );
}

These can then be consumed like ordinary JSX components (see next section).

Routing

With stateful components you can easily build an LLM interface that the LLM can navigate through to obtain a specific goal.

We can use the file components from above to create a simple application that lets the LLM navigate through files in a directory.

import { Action, SystemPrompt, terminate, useState } from "jsx-agent";
import { z } from "zod";

async function FileSearchApp({ request }: { request: string }) {
  const [path, setPath] = useState<string | null>(null);

  return (
    <>
      <SystemPrompt>
        You are a file assistant. Your goal is to help find the file that best
        matches the user's request. Navigate the directory, open relevant files,
        and identify the correct one based on its contents. Once you find the
        correct file, report its path. The user's request: {request}
      </SystemPrompt>
      {path ? <FileContent path={path} /> : <Directory />}
      <Action
        name="openFile"
        description="Open the file"
        parameters={z.object({ path: z.string() })}
        execute={({ path }) => {
          setPath(path);
        }}
      />
      <Action
        name="returnFilePath"
        description="Respond with the path of the correct file"
        parameters={z.object({ path: z.string() })}
        execute={({ path }) => {
          terminate(path);
        }}
      />
    </>
  );
}

Note that the terminate function takes an argument. This will be the return value of agent.run():

const agent = createAgent<string>({
  prompt: <FileSearchApp request="..." />,
  model: openai("gpt-4o"),
});

const filePath = await agent.run();