A complete chat application powered by Snowflake Cortex Agents via the REST API. This project demonstrates how to integrate the reusable simple-chat-interface package and chatServer.js backend module into a production-ready application with authentication, threading, and more.
Note: This repository is heavily based on the wonderful Snowflake-Labs repository
This repository contains:
- Reusable React Package (
packages/simple-chat-interface/) - Drop-in chat components - Reusable Backend Module (
server/chatServer.js) - Express router for Cortex Agents API - Sample Application - Complete demo app showing how to integrate both
- Node.js >= 18.0.0
- npm >= 9.0.0
- Snowflake Account with:
- Access to Snowflake Intelligence
- At least one Cortex Agent created (Guide)
- Personal Access Token (PAT) or OAuth configured
- Clone the repository
git clone <repository-url>
cd awesome-custom-cortex-agents-rest-api-react-app- Install dependencies
npm installThis installs dependencies for:
- The main sample application
- The
simple-chat-interfacepackage
- Configure environment variables
Backend Configuration:
cp env.backend.example .envEdit .env and configure:
# Snowflake Connection
SNOWFLAKE_HOST=your-account.snowflakecomputing.com
SNOWFLAKE_DATABASE=your_database
SNOWFLAKE_SCHEMA=your_schema
# Authentication Mode: "PAT" or "OAUTH"
AUTH_MODE=PAT
# PAT Mode: Provide your Personal Access Token
SNOWFLAKE_PAT=your_pat_token
# OAuth Mode: Provide these (if using OAUTH)
# IDP_LOGIN_URL=https://your-idp.com/oauth/authorize
# IDP_TOKEN_URL=https://your-idp.com/oauth/token
# OAUTH_CLIENT_ID=your_client_id
# OAUTH_CLIENT_SECRET=your_client_secret
# OAUTH_REDIRECT_URI=http://localhost:3001/auth/callback
# CORS (optional, defaults to http://localhost:3000)
ALLOWED_ORIGINS=http://localhost:3000
# Server Port (optional, defaults to 3001)
PORT=3001Frontend Configuration:
cp env.frontend.example .env.localEdit .env.local and configure:
# Backend API URL
REACT_APP_BACKEND_URL=http://localhost:3001
# Authentication Mode: must match backend AUTH_MODE
REACT_APP_AUTH_MODE=PAT
# OAuth Mode: Provide login URL (if using OAUTH)
# REACT_APP_OAUTH_LOGIN_URL=http://localhost:3001/auth/login
# Application Name (for thread tracking)
REACT_APP_APPLICATION_NAME=dash_desai- Start the application
npm run start:allThis starts:
- Frontend on http://localhost:3000
- Backend on http://localhost:3001
This application supports two authentication modes:
- All users share the same Personal Access Token
- Best for: Prototypes, demos, internal tools
- Configuration: Set
AUTH_MODE=PATin both frontend and backend
- Each user authenticates with an external Identity Provider
- Each user gets their own Snowflake access token
- Best for: Production applications with user-specific access
- Configuration: Set
AUTH_MODE=OAUTHin both frontend and backend
To switch modes:
# Backend
AUTH_MODE=PAT npm run start:server
# Frontend
REACT_APP_AUTH_MODE=PAT npm startAdd the chat interface to your existing React app:
npm install ./packages/simple-chat-interfaceimport { FloatingChatInterface, ChatThemeProvider } from '@chat-overlay/simple-chat-interface';
function App() {
return (
<ChatThemeProvider>
<YourExistingApp />
<FloatingChatInterface backendUrl="http://localhost:3001" />
</ChatThemeProvider>
);
}See packages/simple-chat-interface/README.md for full documentation.
Add the chat server to your existing Express app:
- Copy
server/chatServer.jsto your project - Integrate it:
const { createChatRouter } = require('./chatServer');
const chatRouter = createChatRouter({
snowflakeHost: process.env.SNOWFLAKE_HOST,
snowflakeDatabase: process.env.SNOWFLAKE_DATABASE,
snowflakeSchema: process.env.SNOWFLAKE_SCHEMA,
getAuthToken: (req) => process.env.SNOWFLAKE_PAT // or your auth logic
});
app.use('/api', chatRouter);See server/CHAT_SERVER_README.md for full documentation.
- π€ Multi-Agent Support - Switch between different Cortex Agents
- π§΅ Thread Management - Create, list, and revisit conversation threads
- π Thinking Visualization - See the agent's reasoning process (optional)
- π Chart Support - Automatic visualization with Vega-Lite
- π£οΈ Voice Input - Speech-to-text for hands-free interaction
- π¨ Dark/Light Themes - Automatic theme switching
- π Dual Auth Modes - PAT or OAuth, configurable without code changes
- π± Responsive Design - Works on desktop, tablet, and mobile
- βΏ Accessible - WCAG 2.1 compliant
.
βββ packages/simple-chat-interface/ # Reusable React chat package
β βββ src/
β β βββ components/ # React components
β β βββ hooks/ # Custom hooks
β β βββ services/ # API services
β β βββ index.ts # Package exports
β βββ README.md # Package documentation
β
βββ server/
β βββ chatServer.js # Reusable Express router module
β βββ server.js # Sample application server
β βββ CHAT_SERVER_README.md # Backend integration docs
β
βββ src/ # Sample application frontend
β βββ components/ # App-specific components
β βββ contexts/ # React contexts (Auth, Theme)
β βββ pages/ # Login, OAuth callback pages
β βββ services/ # Auth service
β βββ index.tsx # App entry point
β
βββ .env # Backend config (gitignored)
βββ .env.local # Frontend config (gitignored)
βββ env.backend.example # Backend config template
βββ env.frontend.example # Frontend config template
βββ README.md # This file
npm startnpm run start:servernpm run buildREACT_APP_BACKEND_URL=https://your-api.com npm run build1. Cannot connect to backend
- Ensure backend is running:
npm run start:server - Check
REACT_APP_BACKEND_URLin.env.local
2. HTTP 401 Unauthorized
- PAT Mode: Verify
SNOWFLAKE_PATin.envis valid and not expired - OAuth Mode: Check OAuth configuration and token refresh logic
3. HTTP 400 Bad Request
- Verify
SNOWFLAKE_DATABASEandSNOWFLAKE_SCHEMAexist - Ensure you have access to them in Snowflake
4. HTTP 404 Agent Not Found
- Check that agents exist in your database/schema
- Agent names are case-sensitive
5. Thread panel not appearing
- Only available in
FloatingChatInterface - Click the history icon (π) in the chat input area
6. Voice input not working
- Requires Chrome, Edge, or Safari (not Firefox)
- Must grant microphone permissions
- HTTPS required in production
7. Port already in use
# Kill frontend (port 3000)
lsof -ti:3000 | xargs kill -9
# Kill backend (port 3001)
lsof -ti:3001 | xargs kill -9- Frontend Package Documentation
- Backend Module Documentation
- Snowflake Cortex Agents Docs
- Cortex Agents REST API
MIT
For questions, comments, or feedback, reach out to Dash DesAI.
Made with βοΈ using Snowflake Cortex