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

@distri/react

v0.2.7

Published

React hooks and components for Distri Framework

Readme

@distri/react

React components and hooks for building chat applications with DistriJS.

Installation

npm install @distri/react @distri/core

Basic Usage

import React from 'react';
import { DistriProvider, EmbeddableChat, useAgent } from '@distri/react';

function App() {
  const { agent } = useAgent({ agentId: 'assistant' });

  return (
    <DistriProvider config={{ baseUrl: 'http://localhost:8080/v1' }}>
      <EmbeddableChat 
        agent={agent}
        placeholder="Ask me anything..."
      />
    </DistriProvider>
  );
}

Auth Tokens

For cloud auth, pass both access and refresh tokens to the provider. The client will auto-refresh when the access token expires and call onTokenRefresh so you can persist the updated tokens.

import React from 'react';
import { DistriProvider } from '@distri/react';

const accessToken = '<access-token>';
const refreshToken = '<refresh-token>';

export function App() {
  return (
    <DistriProvider
      config={{
        baseUrl: 'http://localhost:8080/v1',
        accessToken,
        refreshToken,
        onTokenRefresh: ({ accessToken, refreshToken }) => {
          // Persist refreshed tokens here (localStorage, cookies, etc.)
        },
      }}
    >
      {/* ... */}
    </DistriProvider>
  );
}

Using Built-in Tools

DistriJS provides built-in tools that render as React components within chat messages:

import React, { useEffect } from 'react';
import { 
  DistriProvider, 
  EmbeddableChat, 
  useAgent,
  createBuiltinTools
} from '@distri/react';

function App() {
  const { agent } = useAgent({ agentId: 'assistant' });

  useEffect(() => {
    if (agent) {
      // Register all built-in tools
      const builtinTools = createBuiltinTools();
      builtinTools.forEach(tool => agent.registerTool(tool));
    }
  }, [agent]);

  return (
    <DistriProvider config={{ baseUrl: 'http://localhost:8080/v1' }}>
      <EmbeddableChat 
        agent={agent}
        placeholder="Ask me anything..."
      />
    </DistriProvider>
  );
}

Available Built-in Tools

Approval Tool

Shows an interactive approval dialog within the chat:

import { createApprovalTool } from '@distri/react';

const approvalTool = createApprovalTool();
agent.registerTool(approvalTool);

When called by the agent, it renders an interactive component with "Approve" and "Deny" buttons right in the chat.

Toast Tool

Shows toast notifications and displays confirmation in chat:

import { createToastTool } from '@distri/react';

const toastTool = createToastTool();
agent.registerTool(toastTool);

When called, it shows a toast notification and displays the confirmation in the chat message.

How Built-in Tools Work

  1. Register the tool with your agent like any other tool
  2. Agent calls the tool during conversation
  3. React component renders in the chat message showing the tool's UI
  4. User interacts with the component (approve/deny, etc.)
  5. Tool completes and returns result to the agent
  6. Tool results are automatically sent via streaming to the agent when all pending tools are complete
  7. Conversation continues with the agent having all tool results

Tool Call State Management

The new useToolCallState hook provides clean, organized tool call management:

import { useToolCallState } from '@distri/react';

const toolState = useToolCallState({
  onAllToolsCompleted: (toolResults) => {
    // Automatically triggered when all tools finish
    console.log('All tools completed:', toolResults);
  }
});

// Easy state management methods
toolState.addToolCall(toolCall);
toolState.setToolCallRunning(toolCallId);
toolState.completeToolCall(toolCallId, result, success);
toolState.setToolCallError(toolCallId, error);

// Query methods
const status = toolState.getToolCallStatus(toolCallId);
const hasPending = toolState.hasPendingToolCalls();

Key Features:

  • Automatic Tool Result Sending: When all tool calls are completed, results are automatically sent via streaming to the agent
  • Streaming Integration: Reuses the same streaming logic as regular messages for consistency
  • Clean State Updates: Friendlier methods like setToolCallRunning(), completeToolCall()
  • Centralized State: All tool call state in one place with toolCallStates Map
  • Status Tracking: Each tool call maintains pending, running, completed, error, user_action_required states
  • Tool Retriggering: Tool calls can be retriggered or cancelled through the state management
  • Completion Callbacks: onAllToolsCompleted triggers when no pending tools remain

Custom Tools

You can create your own tools with custom React components:

const customTool = {
  name: 'my_custom_tool',
  description: 'Does something custom',
  parameters: {
    type: 'object',
    properties: {
      input: { type: 'string' }
    }
  },
  handler: async (input: { input: string }) => {
    // Your custom logic here
    return { result: `Processed: ${input.input}` };
  }
};

agent.registerTool(customTool);

Then add a custom renderer in MessageComponents.tsx:

{toolCall.toolCall.tool_name === 'my_custom_tool' && (
  <MyCustomToolComponent
    toolCall={toolCall.toolCall}
    onComplete={(result, success, error) => {
      onCompleteTool?.(toolCall.toolCall.tool_call_id, result, success, error);
    }}
    status={toolCall.status}
  />
)}

Components

  • EmbeddableChat - Complete chat interface with built-in tool rendering
  • FullChat - Full-page chat with sidebar
  • AgentSelect - Dropdown for selecting agents
  • ChatInput - Message input component

Hooks

  • useAgent - Manage a single agent
  • useAgentDefinitions - List available agents
  • useChat - Chat functionality with automatic tool call state management
  • useThreads - Thread management
  • useTools - Tool registration and management