PaceUI

  • Components
  • Blocks
  • Templates
  • Studio
  • Resources
Native AI
  • Introduction
Components
  • Browser Support
  • Response Renderer
  • Chat Header
  • Chat Messages
  • Chat Suggestions
  • Chat Input
Use Cases
  • Quick Chat
  • Follow Ups
Hooks
  • useBrowserSupport
  • useNativeAI
  1. Components
  2. Native AI
PreviousNext

useNativeAI

React hook for on-device Native AI completion and streaming.

Overview

The useNativeAI hook provides conversation state management, real-time streaming responses, and structured prompt querying using Google Chrome's built-in Gemini Nano model. It automatically manages adapter initialization, session state, token context tracking, and follow-up query parsing.

Installation

NPM
pnpm
Yarn
Bun
npm install npx shadcn@latest add @paceui/native-ai-use-native-ai

Usage

Here is an example of using useNativeAI in a custom component:

CustomChat.tsx
import { useState } from "react";
import { useNativeAI } from "@/hooks/native-ai/use-native-ai";

export function CustomChat() {
  const [input, setInput] = useState("");
  const { filteredMessages, isLoading, sendMessage, contextInfo, lastAnswers } = useNativeAI({
      initialSystemPrompt: "You are a helpful coding assistant.",
  });

  const handleSend = async () => {
      if (!input.trim()) return;
      const text = input;
      setInput("");
      await sendMessage({
          message: { role: "user", content: text }
      });
  };

  return (
      <div>
          <div className="messages">
              {filteredMessages.map((msg, i) => (
                  <div key={i} className={"message " + msg.role}>
                      <strong>{msg.role}: </strong> {msg.content}
                  </div>
              ))}
          </div>
          {contextInfo && (
              <div className="token-usage">
                  Token Usage: {contextInfo.used} / {contextInfo.window}
              </div>
          )}
          <input
              value={input}
              onChange={(e) => setInput(e.target.value)}
              disabled={isLoading}
          />
          <button onClick={handleSend} disabled={isLoading}>
              {isLoading ? "Generating..." : "Send"}
          </button>
      </div>
  );
}

API Reference

Parameters

OptionTypeDescriptionDefault
initialSystemPromptstringThe system prompt to initialize the model with."You are a helpful, concise AI assistant."
eagerLoadedbooleanIf true, initializes the AI model on mount.true
autoCancelOnNextPromptbooleanIf true, automatically cancels any active main message stream or side tasks when a new prompt arrives.true

Returns

PropertyTypeDescription
messagesMessage[]Complete conversation history including system messages.
filteredMessagesMessage[]Clean user/assistant messages suitable for UI rendering.
isLoadingbooleantrue if the model is currently generating a main chat response.
isTaskLoading(taskId?: string) => booleanReturns true if side tasks (or specific taskId) are evaluating.
loadingTasksRecord<string, boolean>Map of active loading tasks by task ID.
getTaskResult(taskId: string) => TaskResult | undefinedHelper to retrieve parsed task results by task ID.
clearTaskResults(taskId?: string) => voidHelper to clear all or specific task results.
isInitializingbooleantrue if the local model adapter is initializing.
status"loading" | "ready" | "lazy"Current status of the AI engine adapter.
sendMessage(args: { message: Message; tasks?: Task[] }) => Promise<void>Sends a message and optionally evaluates batch side tasks.
stop() => Promise<void>Aborts and stops active response generation and side tasks.
stopStream() => Promise<void>Alias for stop().
resetChat() => Promise<void>Resets conversation state back to initial system prompt.
reset() => Promise<void>Alias for resetChat().
taskResultsTaskResult[]Results generated from background side tasks.
contextInfo{ used: number; window: number } | nullInformation about current token usage and model context window.

Types

types.ts
export type UseNativeAIProps = UseNativeAICoreProps & {
  autoCancelOnNextPrompt?: boolean;
};

export type Message = {
  role: "system" | "user" | "assistant";
  content: string;
  custom?: boolean;
};

export type Task = {
  id: string;
  type: "single" | "multiple";
  prompt: string;
};

export type TaskResult = {
  id: string;
  value: string[] | string;
};
useBrowserSupport

PaceUI

Animated blocks, components, and templates for Next.js and TanStack Start. Built with Motion and shadcn - clean code you own.

GitHubTwitterDiscord

Products

BlocksComponentsTemplatesCraftsTanStack ChartsMCP ServerStarter KitsStyleX Components

Resources

DocumentationMotion ComponentsGSAP AnimationsNative AIBlogChangelog

Pricing & Account

PricingManage AccountLicensesAPI KeysAffiliate Program

Company

Contact UsDiscord CommunityPrivacy PolicyTerms of Service

© 2026 PaceUI. All rights reserved. Built by indie developer, Denish

PACEUI