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

@kapaai/agent-react

v0.1.2

Published

Kapa Agent Framework — React components and hooks for building AI agents with chat UI, tool cards, theming, and streaming

Readme

Kapa Agent Framework — React

npm version

Build in-product AI agents powered by your knowledge base — with a ready-made chat UI, custom tools, theming, and streaming.

What is Kapa Agent Framework?

The Kapa Agent Framework lets you embed an AI agent in your product that can answer questions from your knowledge base and take actions through custom tools. The agent runs a multi-turn loop: it streams responses, calls tools (with optional user approval), and continues until it has a final answer.

@kapaai/agent-react provides React components and hooks on top of @kapaai/agent-core. Use the built-in UI for a complete chat experience, or use only the hooks to build a fully custom interface.

Installation

npm install @kapaai/agent-core @kapaai/agent-react

For type-safe tool definitions with Zod (optional):

npm install zod zod-to-json-schema

Quick Start

import { createToolHelper } from "@kapaai/agent-core";
import { AgentProvider, AgentChat } from "@kapaai/agent-react";
import { z } from "zod";

const tool = createToolHelper<{ api: ApiClient }>();

function App() {
  return (
    <AgentProvider
      getSessionToken={async () => {
        const res = await fetch("/api/session", { method: "POST" });
        return res.json();
      }}
      projectId="your-project-id"
      integrationId="your-integration-id"
      tools={[
        tool({
          name: "search_orders",
          description: "Search customer orders",
          parameters: z.object({ query: z.string() }),
          execute: async ({ query }, ctx) => ctx.api.searchOrders(query),
        }),
      ]}
      context={{ api: myApiClient }}
      theme={{ accentColor: "#2563eb", colorScheme: "dark" }}
    >
      <div style={{ height: 600 }}>
        <AgentChat
          branding={{
            title: "Support Agent",
            examplePrompts: ["What are my recent orders?"],
          }}
        />
      </div>
    </AgentProvider>
  );
}

Features

  • Ready-made chat UI — Full chat panel with messages, tool cards, sources, and streaming out of the box
  • Headless mode — Use only useAgentChat() hook to build a completely custom UI
  • Custom tools — Define tools with Zod schemas for type-safe argument inference
  • Generative UI — Tools can render custom React components per execution state via render prop
  • Human-in-the-loop — Tools can require user approval before execution
  • Theming — Accent color, dark/light mode, font, border radius — all configurable
  • Slide-in panelAgentPanel component for drawer-style chat
  • Analytics events — Optional onEvent callback for monitoring agent interactions
  • Session management — Automatic token refresh and 401 retry (via agent-core)

Headless Usage

Use only the hooks to build your own chat interface — no SDK components required:

import { AgentProvider, useAgentChat } from "@kapaai/agent-react";

const ChatUI = () => {
  const {
    messages,
    isStreaming,
    sendMessage,
    approveToolCall,
    rejectToolCall,
  } = useAgentChat();

  // Render your own UI using messages array.
  // Each assistant message has a blocks array with text and tool_calls blocks.
};

Custom Tool Rendering

Tools can provide a render function for custom inline UI based on execution state:

tool({
  name: "get_usage",
  description: "Get API usage for the current billing period",
  parameters: z.object({}),
  execute: async (_args, ctx) => ctx.api.getUsage(),
  render: ({ status, result }) => {
    if (status === "executing") return <p>Loading...</p>;
    if (status === "completed") return <UsageChart data={result} />;
    return null; // fall back to default tool card
  },
});

Tools that need user confirmation before execution:

tool({
  name: "delete_project",
  description: "Delete a project",
  parameters: z.object({ projectId: z.string() }),
  needsApproval: true,
  execute: async ({ projectId }, ctx) => ctx.api.deleteProject(projectId),
});

Theming

<AgentProvider
  theme={{
    accentColor: "#2563eb", // any hex — generates a 10-shade palette
    colorScheme: "dark",    // 'dark' | 'light' | 'auto'
    radius: "soft",         // 'sharp' | 'soft' | 'round' | 'pill'
    fontSize: 14,           // base font size in px
    fontFamily: "Inter, system-ui, sans-serif",
  }}
>

Toggle the color scheme at runtime:

import { useAgentColorScheme } from "@kapaai/agent-react";

const { colorScheme, toggleColorScheme } = useAgentColorScheme();

Slide-in Panel

import { AgentPanel } from "@kapaai/agent-react";

<AgentPanel
  open={isOpen}
  onClose={() => setIsOpen(false)}
  width={480}
  top={60}
  branding={{ title: "Help" }}
/>;

Analytics Events

<AgentProvider
  onEvent={(event) => {
    analytics.track(`agent_${event.type}`, event.data);
  }}
>

Events: message_sent, response_completed, response_error, generation_stopped, tool_executed, tool_approved, tool_denied, conversation_reset, panel_opened, panel_closed.

Authentication

Session tokens are created server-side using your Kapa API key, then passed to the agent via getSessionToken. The API key never reaches the browser.

Browser → Your backend → POST /agent/v1/projects/{id}/agent/sessions/ (with API key)
Browser ← session token
Browser → Kapa API → POST /agent/v1/projects/{id}/agent/chat/ (with session token)

Resources

  • Documentation — Full setup guide, API reference, and integration patterns
  • Examples — Runnable examples (React, Next.js, headless React, vanilla JS)
  • @kapaai/agent-core — Headless core package (peer dependency)