Skip to content

co-browser/assistant-ui-kontext-starter

Repository files navigation

assistant-ui + Kontext SDK Starter

Production-ready AI chatbot with personalized responses powered by assistant-ui and Kontext SDK.

Features

  • Beautiful UI built with assistant-ui composable primitives and shadcn/ui
  • Personalized AI responses tailored to each user via Gmail context
  • Production-ready with streaming, auto-scroll, and error handling
  • Privacy-first design with user-controlled data and one-click disconnect
  • Responsive design for desktop and mobile

Quick Start

Prerequisites

Installation

# Clone the repository
git clone https://github.com/co-browser/assistant-ui-kontext-starter
cd assistant-ui-kontext-starter

# Install dependencies
npm install

# Copy environment variables
cp .env.example .env.local

Configuration

  1. Add your API keys to .env.local:
# Kontext SDK
NEXT_PUBLIC_KONTEXT_API_KEY=ktextXXXXXXXXXXXXXXXX
KONTEXT_API_KEY=ktextXXXXXXXXXXXXXXXX

# OpenAI
OPENAI_API_KEY=sk-XXXXXXXXXXXXXXXXXX
  1. Configure allowed origins in your Kontext Dashboard:
    • Development: http://localhost:3000
    • Production: https://your-domain.com

Development

npm run dev

Open http://localhost:3000 to view the application.

How It Works

  1. Gmail Connection: Users authorize Gmail access through Kontext OAuth flow
  2. Context Processing: Kontext extracts relevant context from emails in the background
  3. Personalized Responses: AI responses are enhanced with user-specific context
  4. Privacy Control: Users can disconnect anytime, triggering complete data deletion

Focused Retrieval (userQuery)

  • What it does: Sends your latest message as userQuery so the backend retrieves turn-specific context (e.g., a clean, deduped list of projects/legal/docs) without changing your saved persona.
  • When to enable: Targeted asks like “List all my projects/legal/docs/visa” or “Give exhaustive details on …”.
  • When to disable: Open-ended chat, brainstorming, or when you want broader background context.
  • Signals: Response headers show X-Kontext-UserQuery: 1|0 and X-Kontext-TurnContext: 1|0 for quick validation.

Project Structure

├── app/
│   ├── api/chat/route.ts       # AI endpoint with Kontext integration
│   ├── assistant.tsx            # Main chat UI component
│   └── layout.tsx               # App layout with KontextProvider
├── components/
│   ├── kontext-provider.tsx    # Kontext SDK provider wrapper
│   ├── kontext-connect-button.tsx # Gmail connection interface
│   └── assistant-ui/            # Chat UI components
├── hooks/
│   └── useKontextCookie.tsx    # Cookie management for authentication
└── lib/
    └── kontext-store.ts         # Client-side state management

Customization

AI Provider

The starter is configured for OpenAI. To use another provider:

  1. Install the provider package:
npm install @ai-sdk/anthropic
  1. Update app/api/chat/route.ts:
import { anthropic } from "@ai-sdk/anthropic";

const result = streamText({
  model: anthropic("claude-3-sonnet"),
  messages: modelMessages,
});

Privacy Settings

Configure privacy levels in app/api/chat/route.ts:

const context = await persona.getContext({
  userId,
  task: 'chat',
  privacyLevel: 'strict', // Options: 'strict' | 'moderate' | 'none'
});

Styling

  • Tailwind CSS v4 with PostCSS. Core imports live in app/globals.css (@import "tailwindcss";).
  • Component styling follows shadcn/ui patterns in components/ui/*.
  • Customize theme tokens and CSS variables in app/globals.css.
  • PostCSS is configured in postcss.config.mjs.

Deployment

Vercel

Deploy with Vercel

Environment Variables

Configure these in your deployment platform:

Variable Description
NEXT_PUBLIC_KONTEXT_API_KEY Client-side Kontext API key
KONTEXT_API_KEY Server-side Kontext API key
OPENAI_API_KEY OpenAI API key

Other Platforms

This is a standard Next.js application and can be deployed to any platform that supports Node.js:

  • Railway
  • Render
  • AWS Amplify
  • Netlify
  • Self-hosted

Documentation

Support

License

MIT

Contributing

Contributions are welcome. Please submit pull requests with:

  • Clear description of changes
  • Updated documentation
  • Test coverage for new features

About

Production-ready AI chatbot with personalized responses powered by assistant-ui and Kontext SDK

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published