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

@yak-io/react

v0.8.0

Published

React SDK for embedding yak chatbot

Readme

@yak-io/react

React integration for the Yak embeddable chat widget. Provides YakProvider, YakWidget, useYak, and useYakToolEvent.

Installation

pnpm add @yak-io/react

For Next.js, use @yak-io/nextjs instead — it adds route scanning and server handler factories on top of this package.

Quickstart

1. Wrap your app with YakProvider

// src/App.tsx (or your root layout)
import { YakProvider, YakWidget } from "@yak-io/react";

export default function App({ children }: { children: React.ReactNode }) {
  return (
    <YakProvider
      appId={import.meta.env.VITE_YAK_APP_ID}
      theme={{ position: "bottom-right", colorMode: "system" }}
      getConfig={async () => {
        const res = await fetch("/api/yak");
        return res.json();
      }}
      onToolCall={async (name, args) => {
        const res = await fetch("/api/yak", {
          method: "POST",
          headers: { "Content-Type": "application/json" },
          body: JSON.stringify({ name, args }),
        });
        const data = await res.json();
        if (!data.ok) throw new Error(data.error);
        return data.result;
      }}
    >
      {children}
      <YakWidget />
    </YakProvider>
  );
}

2. Control the widget programmatically

import { useYak } from "@yak-io/react";

export function HelpButton() {
  const { open, openWithPrompt, isOpen } = useYak();

  return (
    <div>
      <button onClick={open}>Open Chat</button>
      <button onClick={() => openWithPrompt("How do I get started?")}>
        Get Help
      </button>
      {isOpen && <p>Chat is open</p>}
    </div>
  );
}

3. Invalidate data after tool calls

import { useYakToolEvent } from "@yak-io/react";

function TasksPage() {
  const [tasks, setTasks] = useState([]);

  // Re-fetch when the chatbot modifies tasks
  useYakToolEvent((event) => {
    if (event.ok && event.name.startsWith("tasks.")) {
      fetchTasks().then(setTasks);
    }
  });

  // ...
}

API Reference

YakProvider

Sets up context, initializes the widget, and delegates DOM rendering to @yak-io/javascript.

Props:

| Prop | Type | Required | Description | |------|------|----------|-------------| | appId | string | ✅ | Your Yak app ID | | children | ReactNode | ✅ | Your app content | | getConfig | ChatConfigProvider | — | Async function returning routes + tools config. Called when the widget opens. | | onToolCall | ToolCallHandler | — | Handle tool calls from the assistant | | onGraphQLSchemaCall | GraphQLSchemaHandler | — | Handle GraphQL schema tool calls | | onRESTSchemaCall | RESTSchemaHandler | — | Handle REST/OpenAPI schema tool calls | | theme | Theme | — | Widget theme (position, colorMode, colors) | | onRedirect | (path: string) => void | — | Custom navigation handler (defaults to window.location.assign) | | disableRestartButton | boolean | — | Hide the restart session button | | trigger | boolean \| TriggerButtonConfig | — | Built-in trigger button config (false by default — use <YakWidget> instead) |

YakWidget

Renders a fixed-position launcher button. Place it anywhere inside YakProvider.

Props:

| Prop | Type | Description | |------|------|-------------| | triggerLabel | string | Button label (default: "Ask with AI") | | position | WidgetPosition | Button position (default: "bottom-right") | | colorMode | "light" \| "dark" \| "system" | Color mode override | | lightButton | { background?, color?, border? } | Custom light mode button colors | | darkButton | { background?, color?, border? } | Custom dark mode button colors |

useYak()

Access the widget API from any component inside YakProvider.

const {
  isOpen,      // boolean — whether the widget is open
  isReady,     // boolean — whether the iframe is ready
  open,        // () => void
  close,       // () => void
  openWithPrompt, // (prompt: string) => void
  subscribeToToolEvents, // (handler) => () => void
} = useYak();

Throws if called outside YakProvider.

useYakToolEvent(handler)

Subscribe to tool call completion events. Automatically unsubscribes on unmount. Useful for cache invalidation when the chatbot modifies data.

useYakToolEvent((event) => {
  // event.name   — the tool name called ("tasks.list")
  // event.args   — arguments passed to the tool
  // event.ok     — whether the call succeeded
  // event.result — the result (if ok)
  // event.error  — error message (if not ok)
});

Logging

import { enableYakLogging, disableYakLogging, isYakLoggingEnabled } from "@yak-io/react";

enableYakLogging();    // Enable verbose SDK logs
disableYakLogging();   // Disable SDK logs
isYakLoggingEnabled(); // → boolean

Types

All key types are re-exported for convenience:

import type {
  ChatConfigProvider,
  ToolCallHandler,
  ToolCallEvent,
  GraphQLSchemaHandler,
  RESTSchemaHandler,
  Theme,
  ThemeColors,
  TriggerButtonConfig,
  WidgetPosition,
  SchemaSource,
  GraphQLSchemaSource,
  OpenAPISchemaSource,
} from "@yak-io/react";

License

Proprietary — see LICENSE file.