Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

29 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

local-chat.ras.sh

πŸ’¬ Local-first AI chat using Chrome's built-in AI. Conversations run entirely in your browser and stay on your device.

Overview

A privacy-first chat interface powered by Chrome's built-in Prompt API (Gemini Nano). All inference happens locally on your device - your conversations never leave your browser.

Supported browsers:

  • Chrome 128+ (with Prompt API enabled)
  • Edge 128+ (with Prompt API enabled)

Features

  • 100% Local - All AI inference runs directly in your browser using Chrome's built-in Prompt API
  • Complete Privacy - Zero external API calls, no data collection
  • Smart Suggestions - Get contextual follow-up questions generated with structured outputs
  • Streaming Responses - Real-time AI responses as they generate
  • Modern UI - Clean, responsive interface built with Radix UI components
  • File Upload Support - Attach files to your conversations

Tech Stack

Quick Start

# Install dependencies
pnpm install

# Start development server
pnpm dev

Open http://localhost:3000 in Chrome 128+ with Prompt API enabled.

How It Works

This app uses Chrome's built-in Prompt API to run the Gemini Nano language model entirely in your browser. On first use, the model will be downloaded and cached locally.

All processing happens on your device using Chrome's optimized inference engine. The AI SDK handles streaming responses and structured outputs (for generating suggestions). No data is sent to external servers. State management is handled by Zustand, with suggestions stored separately from the main chat state.

Project Structure

src/
β”œβ”€β”€ routes/
β”‚   β”œβ”€β”€ __root.tsx              # Root layout with providers
β”‚   └── index.tsx               # Main chat interface
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ ai-elements/            # AI-specific components
β”‚   β”‚   β”œβ”€β”€ conversation.tsx    # Conversation container
β”‚   β”‚   β”œβ”€β”€ message.tsx         # Individual message display
β”‚   β”‚   β”œβ”€β”€ prompt-input.tsx    # Prompt input with file upload
β”‚   β”‚   β”œβ”€β”€ response.tsx        # AI response with markdown
β”‚   β”‚   └── suggestion.tsx      # Suggestion chips
β”‚   β”œβ”€β”€ ui/                     # Radix UI components
β”‚   β”‚   β”œβ”€β”€ button.tsx          # Button variants
β”‚   β”‚   β”œβ”€β”€ dialog.tsx          # Dialog/modal
β”‚   β”‚   β”œβ”€β”€ input.tsx           # Input field
β”‚   β”‚   └── ...                 # Other UI primitives
β”‚   β”œβ”€β”€ chat-empty-state.tsx    # Empty state with starter prompts
β”‚   β”œβ”€β”€ chat-input.tsx          # Message input with suggestions
β”‚   β”œβ”€β”€ chat-messages.tsx       # Message list with scroll
β”‚   β”œβ”€β”€ header.tsx              # App header with controls
β”‚   β”œβ”€β”€ footer.tsx              # App footer with links
β”‚   β”œβ”€β”€ file-upload.tsx         # File upload handling
β”‚   β”œβ”€β”€ model-download-banner.tsx  # Download progress banner
β”‚   └── browser-unsupported-dialog.tsx  # Browser check dialog
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ client-side-chat-transport.ts  # Prompt API transport for AI SDK
β”‚   β”œβ”€β”€ types.ts                # Shared type definitions
β”‚   β”œβ”€β”€ utils.ts                # Utility functions (cn, etc)
β”‚   └── seo.ts                  # SEO metadata
β”œβ”€β”€ stores/
β”‚   └── suggestions-store.ts    # Zustand store for suggestions
β”œβ”€β”€ hooks/
β”‚   β”œβ”€β”€ use-browser-ai-support.ts  # Check Prompt API availability
β”‚   └── use-mobile.ts           # Mobile detection hook
└── types/
    └── ui-message.ts           # Extended UI message types

Scripts

Command Description
pnpm dev Start Vite development server
pnpm build Build for production
pnpm preview Preview production build
pnpm check-types TypeScript type checking
pnpm check Lint code with Ultracite (Biome wrapper)
pnpm fix Auto-fix linting issues (with --unsafe flag)

Browser Requirements

This app requires Chrome's built-in Prompt API:

  • Chrome 128+ - With Prompt API enabled (chrome://flags/#prompt-api-for-gemini-nano)
  • Edge 128+ - With Prompt API enabled (edge://flags/#prompt-api-for-gemini-nano)

If your browser doesn't support the Prompt API, you'll see a warning dialog on the chat interface. The app checks for support using the doesBrowserSupportBuiltInAI() function from @built-in-ai/core.

To enable the Prompt API:

  1. Open chrome://flags/#prompt-api-for-gemini-nano
  2. Set to "Enabled"
  3. Restart Chrome

Privacy & Data

  • No external servers - All processing happens in your browser
  • No data collection - Your conversations are never logged or sent anywhere
  • No persistence - Messages are kept in memory only (refresh to clear)
  • Local model caching - Downloaded models are cached by the browser

Key Implementation Details

Custom Chat Transport

The app implements a custom ClientSideChatTransport class (src/lib/client-side-chat-transport.ts:36) that integrates Chrome's Prompt API with the AI SDK. Key features:

  • Model availability checking - Checks if Gemini Nano is available, downloadable, or needs to be downloaded
  • Progress tracking - Monitors model download progress and displays a banner
  • Structured outputs - Uses streamObject() to generate both responses and suggestions in a single request
  • Abort handling - Properly handles request cancellation and cleanup

State Management

  • Zustand store (src/stores/suggestions-store.ts:9) - Manages AI-generated follow-up suggestions separately from chat state
  • AI SDK useChat - Handles message state, streaming, and lifecycle

UI Components

  • Radix UI primitives - Accessible, unstyled components (buttons, dialogs, inputs, etc.)
  • Class Variance Authority - Type-safe component variants
  • Tailwind CSS 4 - Latest version with Vite plugin
  • Sonner - Toast notifications for errors and system messages

License

MIT License - see LICENSE for details.

About

πŸ’¬ Local-first AI chat using Chrome's built-in AI. Conversations run entirely in your browser and stay on your device.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages