@bitte-ai/chat

中文文档
0.23.0发布于 2025/09/30MITTypeScriptESM + CJS近 30 天下载 2354

Bitte AI chat component

原始使用文档
文档目录24 节
  1. Introduction
  2. Quick Start
  3. Compatibility
  4. Wallet Integration
  5. NEAR Integration
  6. Using Next.js
  7. EVM Integration
  8. API Route Setup
  9. History API Route Setup
  10. Chat Components Overview
  11. Basic Chat Usage
  12. Standard Chat Setup
  13. NEAR Wallet Integration
  14. Widget Chat Usage
  15. Basic Widget Setup
  16. Custom Trigger Button
  17. Trigger Button Styling
  18. Component Props
  19. BitteAiChat Props
  20. BitteWidgetChat Props
  21. Available Agents
  22. Creating Custom Agents
  23. Styling
  24. Example Projects

Bitte AI Chat

Introduction

The Bitte AI Chat component is a React component that enables AI-powered chat interactions in your application. It supports both NEAR Protocol and EVM blockchain interactions through wallet integrations, allowing users to interact with smart contracts and perform transactions directly through the chat interface.

🔑 Before you begin, make sure you have:


Quick Start

  1. Configure Wallet Integration
  2. Setup the API Route
  3. Add the Chat Component or use as Widget

Compatibility

Our stable version (latest) currently supports React 18 Applications. We have a beta version that supports React 19 and Next.js 15 Applications.

We are working on support more frameworks like Vite React 19 in the mean time.

You can check an working Next.js example on our chat-boilerplate repo

Run on Stackblitz

Wallet Integration

We recommend installing the package using pnpm or yarn:

pnpm install @bitte-ai/chat

or

yarn add @bitte-ai/chat

if you are using npm and find issues, you can use the current command:

npm install @bitte-ai/chat --legacy-peer-deps

NEAR Integration

You can integrate with NEAR using either the NEAR Wallet Selector or a direct account connection. If you want to be able to send near transacitons through the chat you will need to define at least one of these

Using Next.js

Check our Next.js boilerplate repo. Currently turbopack builds arent working due to tailwind build issue.

Using Wallet Selector

  1. You need to wrap your application with BitteWalletContextProvider

  2. If you using Next.js you need to add "use client" on top of file

import { useEffect, useState } from "react"
import { useBitteWallet, Wallet } from "@bitte-ai/react";
import { BitteAiChat } from "@bitte-ai/chat";
import "@bitte-ai/chat/styles.css";


export default function Chat() {
  const { selector } = useBitteWallet();
  const [wallet, setWallet] = useState<Wallet>();

  useEffect(() => {
    const fetchWallet = async () => {
      const walletInstance = await selector.wallet();
      setWallet(walletInstance);
    };
    if (selector) fetchWallet();
  }, [selector]);

  return (
    <BitteAiChat
      agentId="your-agent-id"
      apiUrl="/api/chat"
      wallet={{ near: { wallet } }}
    />
  );
}

Using Direct Account

import { Account } from "near-api-js";
// get near account instance from near-api-js by instantiating a keypair
<BitteAiChat
  agentId="your-agent-id"
  apiUrl="/api/chat"
  wallet={{ near: { account: nearAccount } }}
/>

EVM Integration

EVM integration uses WalletConnect with wagmi hooks:


import { useSendTransaction, useAccount } from 'wagmi';

export default function Chat() {
  const { address } = useAccount();
  const { sendTransaction } = useSendTransaction();

  return (
    <BitteAiChat
      agentId="your-agent-id"
      apiUrl="/api/chat"
      wallet={{
        evm: {
          sendTransaction,
          address
        }
      }}
    />
  );
}

API Route Setup

Create an API route in your Next.js application to proxy requests to the Bitte API to not expose your key:

import type { NextRequest } from "next/server";

const { BITTE_API_KEY, BITTE_API_URL = "https://ai-runtime-446257178793.europe-west1.run.app/chat" } =
  process.env;

export const dynamic = "force-dynamic";
export const maxDuration = 60;

export const POST = async (req: NextRequest): Promise<Response> => {
  const requestInit: RequestInit & { duplex: "half" } = {
    method: "POST",
    body: req.body,
    headers: {
      Authorization: `Bearer ${BITTE_API_KEY}`,
    },
    duplex: "half",
  };

  const upstreamResponse = await fetch(BITTE_API_URL, requestInit);
  const headers = new Headers(upstreamResponse.headers);
  headers.delete("Content-Encoding");

  return new Response(upstreamResponse.body, {
    status: upstreamResponse.status,
    headers,
  });
};

History API Route Setup

Create an API route in your Next.js application that will allow your app if you want to save chat context when signing a transaction after getting redirected to the wallet.

import { type NextRequest, NextResponse } from 'next/server';

const { BITTE_API_KEY, BITTE_API_URL = 'https://ai-runtime-446257178793.europe-west1.run.app' } =
  process.env;

export const dynamic = 'force-dynamic';
export const maxDuration = 60;

export const GET = async (req: NextRequest): Promise<NextResponse> => {
  const { searchParams } = new URL(req.url);
  const id = searchParams.get('id');
  const url = `${BITTE_API_URL}/history?id=${id}`;

  const response = await fetch(url, {
    headers: {
      Authorization: `Bearer ${BITTE_API_KEY}`,
    },
  });

  const result = await response.json();

  return NextResponse.json(result);
};

Chat Components Overview

Bitte AI Chat provides two main components for different use cases:

  • BitteAiChat - Full-featured chat interface for embedding directly in your app pages
  • BitteWidgetChat - Floating chat widget that overlays your existing content

Basic Chat Usage

The BitteAiChat component provides a full-featured chat interface that can be embedded directly into your application pages.

Standard Chat Setup

import { BitteAiChat } from "@bitte-ai/chat";
import { useAccount, useSendTransaction } from 'wagmi';
import "@bitte-ai/chat/styles.css";

export default function ChatPage() {
  const { address } = useAccount();
  const { sendTransaction } = useSendTransaction();

  return (
    <div className="container mx-auto p-4">
      <h1>AI Assistant</h1>
      
      {/* Full-page chat interface */}
      <div style={{ height: '600px' }}>
        <BitteAiChat
          agentId="your-agent-id"
          apiUrl="/api/chat"
          historyApiUrl="/api/history"
          wallet={{
            evm: {
              sendTransaction,
              address
            }
          }}
          options={{
            agentName: "My AI Assistant",
            agentImage: "/agent-avatar.png",
            colors: {
              generalBackground: "#ffffff",
              messageBackground: "#f8fafc",
              textColor: "#1f2937",
              buttonColor: "#3b82f6",
              borderColor: "#e5e7eb"
            },
            customComponents: {
              welcomeMessageComponent: (
                <div>
                  <h2>Welcome to our AI Assistant!</h2>
                  <p>How can I help you today?</p>
                </div>
              )
            }
          }}
        />
      </div>
    </div>
  );
}

NEAR Wallet Integration

import { useEffect, useState } from "react";
import { useBitteWallet, Wallet } from "@bitte-ai/react";
import { BitteAiChat } from "@bitte-ai/chat";
import "@bitte-ai/chat/styles.css";

export default function Chat() {
  const { selector } = useBitteWallet();
  const [wallet, setWallet] = useState<Wallet>();

  useEffect(() => {
    const fetchWallet = async () => {
      const walletInstance = await selector.wallet();
      setWallet(walletInstance);
    };
    if (selector) fetchWallet();
  }, [selector]);

  return (
    <BitteAiChat
      agentId="your-agent-id"
      apiUrl="/api/chat"
      wallet={{ near: { wallet } }}
      options={{
        agentName: "NEAR Assistant",
        colors: {
          generalBackground: "#000000",
          textColor: "#ffffff"
        }
      }}
    />
  );
}

Widget Chat Usage

The BitteWidgetChat component provides a floating chat widget that can be embedded anywhere on your website. It includes a trigger button and a popup chat interface.

Basic Widget Setup

import { BitteWidgetChat } from "@bitte-ai/chat";
import { useAccount, useSendTransaction } from 'wagmi';
import "@bitte-ai/chat/styles.css";

export default function App() {
  const { address } = useAccount();
  const { sendTransaction } = useSendTransaction();

  return (
    <div>
      {/* Your existing app content */}
      <main>
        <h1>My App</h1>
        {/* Other content */}
      </main>
      
      {/* Widget Chat - floating at bottom right */}
      <BitteWidgetChat
        agentId="your-agent-id"
        apiUrl="/api/chat"
        historyApiUrl="/api/history"
        wallet={{
          evm: {
            sendTransaction,
            address
          }
        }}
        widget={{
          widgetWelcomePrompts: {
            title: "Hey there! 👋",
            description: "I'm your AI assistant. What would you like to do?",
            questions: [
              "What's my portfolio balance?",
              "Show me trending tokens",
              "How do I swap tokens?"
            ],
            actions: [
              "Check my wallet balance",
              "View recent transactions",
              "Help me with DeFi"
            ]
          },
          triggerButtonStyles: {
           backgroundColor: "#6366F1",
           logoColor: "#FFFFFF"
         }
        }}
        options={{
          agentName: "DeFi Assistant",
          agentImage: "/assistant-avatar.png"
        }}
      />
    </div>
  );
}

Custom Trigger Button

You can replace the default trigger button with your own component:

<BitteWidgetChat
  agentId="your-agent-id"
  apiUrl="/api/chat"
  wallet={{ /* wallet config */ }}
  widget={{
    customTriggerButton: (
      <div className="custom-chat-button">
        <ChatIcon />
        <span>Chat with us!</span>
      </div>
    )
  }}
/>

Trigger Button Styling

Customize the appearance of the trigger button:

widget={{
  triggerButtonStyles: {
    backgroundColor: "#1F2937", // Dark background
    logoColor: "#F3F4F6"        // Light logo color
  }
}}

Note: The widget position is fixed at bottom-right of the viewport and cannot be customized through props.

Component Props

BitteAiChat Props

interface BitteAiChatProps {
  agentId: string; // ID of the AI agent to use
  apiUrl: string; // Your API route path (e.g., "/api/chat")
  historyApiUrl?: string; // Your history API route to keep context when signing transactions
  wallet?: WalletOptions; // Wallet configuration
  apiKey?: string; // Optional API key for server-side requests
  messages?: Message[]; // Initial messages to display
  customToolComponents?: CustomToolComponent[]; // Custom tool components
  onChatLoaded?: () => void; // Callback when chat is loaded
  onMessageReceived?: (message: Message) => void; // Callback when message is received
  widget?: WidgetChatProps; // Widget-specific configuration
  isWidgetChat?: boolean; // Whether to render as widget
  options?: {
    agentName?: string; // Custom agent name
    agentImage?: string; // Custom agent image URL
    chatId?: string; // Custom chat ID
    prompt?: string; // Custom Initial prompt
    placeholderText?: string; // Custom placeholder text
    hideToolCall?: boolean; // Hide tool call UI (default: true for widget)
    localAgent?: {
      pluginId: string;
      accountId: string;
      spec: BitteOpenAPISpec;
    };
    colors?: ChatComponentColors;
    customComponents?: {
      welcomeMessageComponent?: React.JSX.Element;
      mobileInputExtraButton?: React.JSX.Element;
      messageContainer?: React.ComponentType<MessageGroupComponentProps>;
      chatContainer?: React.ComponentType<ChatContainerComponentProps>;
      inputContainer?: React.ComponentType<InputContainerProps>;
      sendButtonComponent?: React.ComponentType<SendButtonComponentProps>;
      loadingIndicator?: React.ComponentType<LoadingIndicatorComponentProps>;
    };
  };
}

BitteWidgetChat Props

The BitteWidgetChat component accepts all the same props as BitteAiChat plus widget-specific styling and behavior.

interface WidgetChatProps {
  // Welcome prompts configuration for widget
  widgetWelcomePrompts?: {
    title?: string; // Welcome title (default: "Hello")
    description?: string; // Welcome description
    questions?: string[]; // Array of suggested questions
    actions?: string[]; // Array of suggested actions
  };
  
  // Custom trigger button (replaces default Bitte logo)
  customTriggerButton?: React.ReactElement;
  
  // Trigger button styling
  triggerButtonStyles?: {
    backgroundColor?: string; // Background color (default: "#000000")
    logoColor?: string; // Logo color (default: "#ffffff")
  };
}

Available Agents

Agent registry

Creating Custom Agents

Make Agent

Styling

The component can be customized using the colors prop:

type ChatComponentColors = {
  generalBackground?: string; // Chat container background
  messageBackground?: string; // Message bubble background
  textColor?: string; // Text color
  buttonColor?: string; // Button color
  borderColor?: string; // Border color
};

Example Projects

版本与发布记录

@bitte-ai/chat 共发布 481 个版本,首次发布于 2025/01/13;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.23.0latest2025/09/301.1 年前
0.22.22025/09/221.1 年前
0.22.12025/09/151.1 年前
0.22.02025/09/151.1 年前
0.21.12025/09/081.2 年前
0.21.02025/09/041.2 年前

其他发布通道:beta → 0.2.1-beta,branch-beta → 0.1.0-main-beta-8b601de,branch → 0.1.0-main-8b601de,markdown-beta-support → 0.15.0-markdown-beta-support,markdown-beta-support-2 → 0.15.0-markdown-beta-support-1,cowswap-custom → 0.15.0-markdown-cow-swap。

关于 @bitte-ai/chat 的常见问题

@bitte-ai/chat 是什么?

Bitte AI chat component

如何安装 @bitte-ai/chat?

在项目目录运行 npm install @bitte-ai/chat,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18.0.0)、react-dom(^18.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bitte-ai/chat 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bitte-ai/chat 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@bitte-ai/chat 可以商用吗?

@bitte-ai/chat 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bitte-ai/chat 的下载量有多少?

根据 npm 官方下载统计,@bitte-ai/chat 在 2026/10/08 – 2026/11/06 这 30 天内被下载 2,354 次,日均约 78 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bitte-ai/chat 还在维护吗?

最新版本 0.23.0 发布于 2025/09/30(1.1 年前);至今共发布 481 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/01/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。