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

@weaveai/react

v1.2.1

Published

React bindings for Weave framework - hooks and components for AI operations

Readme

Weave React

Rich React bindings for the Weave AI framework. Ship AI-driven features with first-class hooks, context, and UI components that share the same execution controllers used across every Weave integration.

Highlights

  • AI orchestration hooksuseAI, useGenerateAI, useClassifyAI, and friends expose budgeting, cost tracking, and error handling powered by the shared AIExecutionController.
  • Chat experiences out of the boxuseAIChat, AIChat, and the supporting UI helpers manage message persistence, streaming updates, and overflow policies.
  • Smart caching helpersuseCache combines the Weave cache manager with UI-friendly feedback so you can surface hits, misses, and savings inside your product.
  • Provider visibilityuseProviderRouting, ProviderSwitch, and ProviderEventFeed keep users informed as routing falls back between AI providers.

Installation

npm install @weaveai/core @weaveai/react
# or
yarn add @weaveai/core @weaveai/react

Quick Start

import { WeaveProvider, useGenerateAI } from '@weaveai/react';
import { Weave } from '@weaveai/core';

const weave = await Weave.createAsync({
  provider: { type: 'openai', apiKey: process.env.OPENAI_API_KEY! },
});

function HaikuGenerator() {
  const { generate, data, loading, cost } = useGenerateAI({
    onError: (error) => logError(error.message),
    trackCosts: true,
  });

  return (
    <div>
      <button
        onClick={() => generate('Write a haiku about cherry blossoms in spring.')}
        disabled={loading}
      >
        {loading ? 'Dreaming…' : 'Create haiku'}
      </button>

      {data && <pre>{data.data.text}</pre>}
      {cost && <small>Cost so far: ${cost.totalCost.toFixed(4)}</small>}
    </div>
  );
}

export function App() {
  return (
    <WeaveProvider weave={weave}>
      <HaikuGenerator />
    </WeaveProvider>
  );
}

Chat Experiences

import { useAIChat, AIChat } from '@weaveai/react';

function SupportAssistant() {
  const chat = useAIChat({
    systemPrompt: 'You are a friendly support agent. Answer concisely.',
    streaming: { enabled: true, renderer: 'markdown' },
    persistence: { localStorage: 'support-chat', autoSave: true },
    trackCosts: true,
    maxMessages: 40,
    onOverflow: 'summarize',
  });

  return <AIChat {...chat} title="Support Assistant" />;
}

Caching & Provider Routing

import { useCache, useProviderRouting, ProviderSwitch, ProviderEventFeed } from '@weaveai/react';
import { CacheConfig } from '@weaveai/core';
import { createUIRouter } from './router-factory';

const cacheConfig: CacheConfig = {
  enabled: true,
  strategy: 'semantic',
  ttl: 60 * 15,
  onCacheHit: ({ savings }) => console.log('Cache savings', savings),
};

function ProvidersPanel() {
  const router = createUIRouter(); // wraps UIAwareProviderRouter
  const routing = useProviderRouting({
    router,
    autoRefresh: true,
    refreshInterval: 5000,
  });

  return (
    <section>
      <ProviderSwitch
        providers={routing.providers}
        currentProvider={routing.currentProvider ?? undefined}
        onProviderSelect={routing.selectProvider}
      />
      <ProviderEventFeed events={routing.events} />
    </section>
  );
}

function CachedResponse({ prompt }: { prompt: string }) {
  const cache = useCache({
    cacheConfig,
    showNotification: true,
  });

  useEffect(() => {
    cache.queryCache(prompt).then((cached) => {
      if (!cached) {
        // run fresh AI call and then storeInCache(...)
      }
    });
  }, [prompt]);

  return null;
}

Examples

See the examples directory for runnable snippets that expand on the sections above:

  • haiku-generator.tsx – minimal useGenerateAI usage
  • support-chat.tsx – conversational UI with streaming
  • providers-panel.tsx – monitoring provider routing events
  • cache-check.ts – cache hits/misses with savings reporting

Each example is framework-agnostic and can be dropped into a Vite or CRA playground with the WeaveProvider configured. The shared controllers ensure behavior stays consistent with Vue, Angular, Svelte, and React Native bindings.

Further Reading