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-core

v0.1.2

Published

Kapa Agent Framework — core TypeScript library for building AI agents with tool calling, streaming, and session management

Readme

Kapa Agent Framework — Core

npm version

Build in-product AI agents powered by your knowledge base — with custom tools, streaming, and human-in-the-loop approval.

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-core is the headless core — pure TypeScript, no UI framework dependencies. It works in browsers, Node.js, and edge runtimes.

Installation

npm install @kapaai/agent-core

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

npm install zod zod-to-json-schema

Quick Start

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

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

const agent = new Agent({
  projectId: "your-project-id",
  integrationId: "your-integration-id",
  getSessionToken: async () => {
    const res = await fetch("/api/session", { method: "POST" });
    return res.json();
  },
  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 },
  onMessagesChange: (messages) => renderUI(messages),
  onStreamingChange: (streaming) => toggleSpinner(streaming),
});

await agent.sendMessage("What are my recent orders?");

Features

  • Streaming — Token-by-token response streaming with onMessagesChange callbacks
  • Custom tools — Define tools with Zod schemas for type-safe argument inference
  • Human-in-the-loop — Tools can require user approval before execution
  • Session management — Automatic token refresh and 401 retry
  • Analytics events — Optional onEvent callback for monitoring agent interactions
  • Framework-agnostic — Pure TypeScript, works with any UI framework or none at all

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 (vanilla JS, React, Next.js)
  • @kapaai/agent-react — React components and hooks built on top of this package