Skip to content

Commit 1e8002b

Browse files
committed
initial commit. migrated from LangConnect-Client
0 parents  commit 1e8002b

File tree

159 files changed

+36192
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+36192
-0
lines changed

.dockerignore

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Git
2+
.git
3+
.gitignore
4+
.github
5+
6+
# Docker
7+
.dockerignore
8+
Dockerfile
9+
docker-compose.yml
10+
11+
# Python
12+
__pycache__/
13+
*.py[cod]
14+
*$py.class
15+
*.so
16+
.Python
17+
env/
18+
build/
19+
develop-eggs/
20+
dist/
21+
downloads/
22+
eggs/
23+
.eggs/
24+
lib/
25+
lib64/
26+
parts/
27+
sdist/
28+
var/
29+
*.egg-info/
30+
.installed.cfg
31+
*.egg
32+
33+
# Virtual Environment
34+
venv/
35+
.env
36+
.venv
37+
ENV/
38+
39+
# IDE
40+
.idea/
41+
.vscode/
42+
*.swp
43+
*.swo
44+
45+
# OS
46+
.DS_Store
47+
.DS_Store?
48+
._*
49+
.Spotlight-V100
50+
.Trashes
51+
ehthumbs.db
52+
Thumbs.db

.env.example

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# API key for the embeddings model. Defaults to OpenAI embeddings
2+
OPENAI_API_KEY=
3+
4+
# PostgreSQL configuration
5+
POSTGRES_HOST=teddynote
6+
POSTGRES_PORT=5432
7+
POSTGRES_USER=teddynote
8+
POSTGRES_PASSWORD=teddynote
9+
POSTGRES_DB=teddynote_db
10+
11+
# CORS configuration. Must be a JSON array of strings
12+
ALLOW_ORIGINS=["*"]
13+
14+
# Testing mode (set to true for simple authentication)
15+
IS_TESTING=false
16+
17+
# For production authentication (optional)
18+
SUPABASE_URL=
19+
# This must be the service role key
20+
SUPABASE_KEY=
21+
22+
# API configuration
23+
API_BASE_URL=http://localhost:8080
24+
25+
# MCP SSE Server configuration
26+
SSE_PORT=8765
27+
# To use MCP servers, you need to provide a valid Supabase JWT access token
28+
# You can get this token after signing in through the Streamlit UI
29+
SUPABASE_JWT_SECRET=

.gitignore

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
.vs/
2+
.vscode/
3+
.idea/
4+
.claude/
5+
.pnpm-store/
6+
CLAUDE.md
7+
8+
# Byte-compiled / optimized / DLL files
9+
__pycache__/
10+
*.py[cod]
11+
*$py.class
12+
13+
# C extensions
14+
*.so
15+
16+
# Swp files
17+
*.swp
18+
19+
# Distribution / packaging
20+
.Python
21+
build/
22+
develop-eggs/
23+
dist/
24+
downloads/
25+
eggs/
26+
.eggs/
27+
lib64/
28+
parts/
29+
sdist/
30+
var/
31+
wheels/
32+
pip-wheel-metadata/
33+
share/python-wheels/
34+
*.egg-info/
35+
.installed.cfg
36+
*.egg
37+
MANIFEST
38+
39+
# Google GitHub Actions credentials files created by:
40+
# https://github.com/google-github-actions/auth
41+
#
42+
# That action recommends adding this gitignore to prevent accidentally committing keys.
43+
gha-creds-*.json
44+
45+
# PyInstaller
46+
# Usually these files are written by a python script from a template
47+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
48+
*.manifest
49+
*.spec
50+
51+
# Installer logs
52+
pip-log.txt
53+
pip-delete-this-directory.txt
54+
55+
# Unit test / coverage reports
56+
htmlcov/
57+
.tox/
58+
.nox/
59+
.coverage
60+
.coverage.*
61+
.cache
62+
nosetests.xml
63+
coverage.xml
64+
*.cover
65+
*.py,cover
66+
.hypothesis/
67+
.pytest_cache/
68+
.codspeed/
69+
70+
# Translations
71+
*.mo
72+
*.pot
73+
74+
# Django stuff:
75+
*.log
76+
local_settings.py
77+
db.sqlite3
78+
db.sqlite3-journal
79+
80+
# Flask stuff:
81+
instance/
82+
.webassets-cache
83+
84+
# Scrapy stuff:
85+
.scrapy
86+
87+
# Sphinx documentation
88+
docs/_build/
89+
docs/docs/_build/
90+
91+
# PyBuilder
92+
target/
93+
94+
# Jupyter Notebook
95+
.ipynb_checkpoints
96+
notebooks/
97+
98+
# IPython
99+
profile_default/
100+
ipython_config.py
101+
102+
# pyenv
103+
.python-version
104+
105+
# pipenv
106+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
107+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
108+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
109+
# install all needed dependencies.
110+
#Pipfile.lock
111+
112+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
113+
__pypackages__/
114+
115+
# Celery stuff
116+
celerybeat-schedule
117+
celerybeat.pid
118+
119+
# SageMath parsed files
120+
*.sage.py
121+
122+
# Environments
123+
.env
124+
.envrc
125+
.venv*
126+
venv*
127+
env/
128+
ENV/
129+
env.bak/
130+
131+
# Spyder project settings
132+
.spyderproject
133+
.spyproject
134+
135+
# Rope project settings
136+
.ropeproject
137+
138+
# mkdocs documentation
139+
/site
140+
141+
# mypy
142+
.mypy_cache/
143+
.mypy_cache_test/
144+
.dmypy.json
145+
dmypy.json
146+
147+
# Pyre type checker
148+
.pyre/
149+
150+
# macOS display setting files
151+
.DS_Store
152+
153+
# Wandb directory
154+
wandb/
155+
156+
# asdf tool versions
157+
.tool-versions
158+
/.ruff_cache/
159+
160+
node_modules
161+
_dist
162+
163+
prof
164+
virtualenv/
165+
166+
# MCP configuration with sensitive data
167+
mcp/mcp_config.json

AUTH_README.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Supabase Authentication Setup
2+
3+
This document explains how to use Supabase authentication with LangConnect.
4+
5+
## Prerequisites
6+
7+
1. Supabase project with URL and anon key configured in `.env`:
8+
```
9+
SUPABASE_URL=https://your-project.supabase.co
10+
SUPABASE_KEY=your-anon-key
11+
```
12+
13+
2. Set `IS_TESTING=false` in your `.env` file to enable authentication
14+
15+
## API Endpoints
16+
17+
### Authentication Endpoints
18+
19+
- **POST /auth/signup** - Create a new user account
20+
```json
21+
{
22+
"email": "user@example.com",
23+
"password": "password123"
24+
}
25+
```
26+
27+
- **POST /auth/signin** - Sign in with existing account
28+
```json
29+
{
30+
"email": "user@example.com",
31+
"password": "password123"
32+
}
33+
```
34+
35+
- **POST /auth/signout** - Sign out (client-side cleanup)
36+
37+
- **POST /auth/refresh** - Refresh access token
38+
```json
39+
{
40+
"refresh_token": "your-refresh-token"
41+
}
42+
```
43+
44+
- **GET /auth/me** - Get current user info (requires authentication)
45+
46+
### Response Format
47+
48+
Successful authentication returns:
49+
```json
50+
{
51+
"access_token": "jwt-token",
52+
"refresh_token": "refresh-token",
53+
"user_id": "user-uuid",
54+
"email": "user@example.com"
55+
}
56+
```
57+
58+
## Using Authentication
59+
60+
### In API Requests
61+
62+
Include the access token in the Authorization header:
63+
```
64+
Authorization: Bearer your-access-token
65+
```
66+
67+
### In Streamlit App
68+
69+
The Streamlit app (`Main.py`) now includes:
70+
- Sign in/Sign up forms
71+
- Automatic token management
72+
- Session persistence
73+
- Sign out functionality
74+
75+
### Testing Authentication
76+
77+
Run the test script:
78+
```bash
79+
python test_supabase_auth.py
80+
```
81+
82+
This will test:
83+
1. User signup
84+
2. User signin
85+
3. Authenticated API requests
86+
4. Getting current user info
87+
88+
## Security Notes
89+
90+
1. The `SUPABASE_KEY` in `.env` should be the **anon** key, not the service role key
91+
2. Tokens expire after a certain period - use the refresh endpoint to get new tokens
92+
3. All API endpoints (except /health and /auth/*) require authentication when `IS_TESTING=false`
93+
94+
## Authentication Persistence
95+
96+
### Keeping Login State After Page Refresh
97+
98+
The Streamlit app supports two methods to persist authentication:
99+
100+
1. **Automatic File-Based Storage** (Default)
101+
- Authentication tokens are automatically saved to `~/.langconnect_auth_cache`
102+
- Tokens remain valid for 7 days
103+
- Automatically loads on app restart
104+
105+
2. **Environment Variables** (Optional)
106+
- Add these to your `.env` file:
107+
```
108+
LANGCONNECT_TOKEN=your-access-token
109+
LANGCONNECT_EMAIL=your-email@example.com
110+
```
111+
- Useful for development or shared environments
112+
113+
### Security Notes
114+
- The auth cache file is stored in your home directory
115+
- Tokens expire after 7 days for security
116+
- Use environment variables only in secure environments
117+
118+
## Important Notes
119+
120+
### Email Confirmation
121+
122+
By default, Supabase requires email confirmation for new signups. When a user signs up:
123+
1. They will receive a confirmation email
124+
2. They must click the link in the email to confirm their account
125+
3. Only then can they sign in
126+
127+
To disable email confirmation (for testing only):
128+
1. Go to your Supabase project dashboard
129+
2. Navigate to Authentication → Settings
130+
3. Under "Email Auth" disable "Confirm email"
131+
132+
### Testing with Docker
133+
134+
When running with Docker Compose, ensure `IS_TESTING=false` in docker-compose.yml to enable authentication.
135+
136+
## Troubleshooting
137+
138+
- **"Authentication endpoints are disabled in testing mode"** - Set `IS_TESTING=false` in `.env` or docker-compose.yml
139+
- **"Email not confirmed"** - Check your email for confirmation link, or disable email confirmation in Supabase dashboard
140+
- **"Invalid token or user not found"** - Check that your token is valid and not expired
141+
- **Connection errors** - Verify SUPABASE_URL and SUPABASE_KEY are correct

0 commit comments

Comments
 (0)