Skip to content

Commit a4b9ade

Browse files
author
Märt Vaha
committed
initial commit
0 parents  commit a4b9ade

Some content is hidden

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

45 files changed

+4164
-0
lines changed

.cursor/rules/configuration.mdc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
description: Standards for managing configuration and environment variables
3+
globs: "*.yml,*.toml,.env.example"
4+
alwaysApply: false
5+
---
6+
- Document all configuration options
7+
- Use environment variables (.env file) for sensitive data
8+
- Keep configuration files organized and well-commented

.cursor/rules/fastapi.mdc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
description: Guidelines for FastAPI development and API design
3+
globs: "app/api/**/*.py"
4+
alwaysApply: false
5+
---
6+
- Use Pydantic models for request/response validation
7+
- Implement proper error handling and status codes
8+
- Keep route handlers clean and delegate business logic to services
9+
- Use dependency injection for services and database connections
10+
- Document API endpoints with OpenAPI/Swagger comments
11+
- API endpoints use a global prefix of '/v1'

.cursor/rules/global.mdc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
description: Global project rules
3+
globs:
4+
alwaysApply: true
5+
---
6+
- Project uses uv and pyproject.toml for deps management
7+
- Install deps with uv sync --all-extras
8+
- After making changes, run `pytest tests -v` or for specific test `pytest tests/{test} -v`
9+
- After making changes, verify that [endpoints.py](mdc:app/api/endpoints.py) still follows [librechat-code-interpreter-openapi.json](mdc:project/librechat-code-interpreter-openapi.json)

.cursor/rules/librechat-endpoints.mdc

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
---
2+
description: Librechat specific endpoints
3+
globs: "app/api/librechat.py"
4+
alwaysApply: false
5+
---
6+
## Base Path
7+
8+
All endpoints are prefixed with `/v1/librechat`
9+
10+
## Endpoints
11+
12+
### 1. Execute Code
13+
**Endpoint:** `POST /exec`
14+
15+
**Description:** Execute Python code in a secure sandbox environment
16+
17+
**Request Body:**
18+
```json
19+
{
20+
"lang": "py", // Only Python is supported
21+
"code": "string", // The code to execute
22+
"files": [ // Optional
23+
{
24+
"id": "string",
25+
"name": "string",
26+
"size": "number" // Optional, defaults to 0
27+
}
28+
]
29+
}
30+
```
31+
32+
**Response:**
33+
```json
34+
{
35+
"session_id": "string",
36+
"stdout": "string",
37+
"stderr": "string",
38+
"files": [ // Optional
39+
{
40+
"id": "string",
41+
"name": "string",
42+
"size": "number",
43+
"content_type": "string"
44+
}
45+
]
46+
}
47+
```
48+
49+
**Error Responses:**
50+
- `400`: Invalid request (unsupported language or invalid JSON)
51+
- `401`: Unauthorized
52+
- `422`: Validation error
53+
- `500`: Internal server error
54+
- `503`: Service unavailable
55+
56+
### 2. Upload Files
57+
**Endpoint:** `POST /upload`
58+
59+
**Request:**
60+
- Content-Type: `multipart/form-data`
61+
62+
**Parameters:**
63+
- `file`: File (required)
64+
- `entity_id`: String (optional, form field)
65+
66+
**Headers:**
67+
- `user-id`: String
68+
- `x-api-key`: String
69+
- `user-agent`: String
70+
71+
**Response:**
72+
```json
73+
{
74+
"message": "success",
75+
"session_id": "string",
76+
"files": [
77+
{
78+
"fileId": "string",
79+
"filename": "string"
80+
}
81+
]
82+
}
83+
```
84+
85+
**Error Responses:**
86+
- `400`: Bad request
87+
- `413`: File size too large
88+
89+
### 3. Download File
90+
**Endpoint:** `GET /download/{session_id}/{file_id}`
91+
92+
**Path Parameters:**
93+
- `session_id`: String (required)
94+
- `file_id`: String (required)
95+
96+
**Response:**
97+
- Streaming response of the file content
98+
99+
**Error Responses:**
100+
- `404`: File not found
101+
102+
### 4. List Files
103+
**Endpoint:** `GET /files/{session_id}`
104+
105+
**Path Parameters:**
106+
- `session_id`: String (required)
107+
108+
**Query Parameters:**
109+
- `detail`: String (optional)
110+
- When set to "summary", returns minimal file information
111+
112+
**Response:**
113+
```json
114+
[
115+
{
116+
"name": "session_id/fileId",
117+
"lastModified": "ISO-8601 timestamp",
118+
"type": "string", // Only included if detail != "summary"
119+
"size": "number" // Only included if detail != "summary"
120+
}
121+
]
122+
```
123+
124+
**Error Responses:**
125+
- `400`: Bad request
126+
127+
### 5. Delete File
128+
**Endpoint:** `DELETE /files/{session_id}/{file_id}`
129+
130+
**Path Parameters:**
131+
- `session_id`: String (required)
132+
- `file_id`: String (required)
133+
134+
**Response:**
135+
```json
136+
{
137+
"message": "success"
138+
}
139+
```
140+
141+
**Error Responses:**
142+
- `404`: File not found
143+
144+
## Notes
145+
146+
1. All file operations are session-based, requiring a valid session ID
147+
2. Maximum file upload size is configured in the application settings
148+
3. Only Python code execution is currently supported
149+
4. All endpoints may return standard HTTP error codes for common failure cases

.cursor/rules/project-structure.mdc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
description: Maintains consistent project organization and architecture
3+
globs: "app/**/*.py"
4+
alwaysApply: false
5+
---
6+
- Keep models in app/models/
7+
- Business logic belongs in app/services/
8+
- Shared functionality in app/shared/
9+
- Utility functions in app/utils/
10+
- API routes in app/api/

.cursor/rules/python-style.mdc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
description: Enforces Python best practices and coding standards
3+
globs: "*.py"
4+
alwaysApply: false
5+
---
6+
- Follow PEP 8 style guidelines
7+
- Use type hints for function parameters and return values
8+
- Document functions and classes using docstrings
9+
- Keep functions focused and single-purpose
10+
- Use meaningful variable and function names

.dockerignore

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Development environment
2+
.venv/
3+
.git/
4+
__pycache__/
5+
6+
# Project documentation
7+
ARCHITECTURE.md
8+
README.md
9+
10+
# Docker files
11+
Dockerfile
12+
.dockerignore
13+
compose.yml
14+
15+
# Environment and configuration
16+
.env
17+
.env.*
18+
!.env.example
19+
20+
# API documentation
21+
librechat-code-interpreter-openapi.json
22+
23+
# Editor
24+
.vscode/
25+
.idea/
26+
27+
# Python
28+
*.py[cod]
29+
*$py.class
30+
*.so
31+
.Python
32+
.pytest_cache/
33+
.coverage
34+
htmlcov/
35+
.tox/
36+
.nox/
37+
.hypothesis/
38+
.mypy_cache/
39+
40+
# IDE
41+
*.swp
42+
*.swo
43+
44+
# Git
45+
.gitignore
46+
47+
# Docker
48+
.dockerignore
49+
50+
# Project specific
51+
*.log
52+
.DS_Store
53+
node_modules/
54+
55+
# Build and dist
56+
dist/
57+
build/
58+
project
59+
*.egg-info/
60+
logs
61+
config
62+
uploads
63+
64+
# Cache
65+
.ruff_cache/
66+
.uv/

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# look at ./app/shared/config.py

.github/workflows/docker-build.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches: ['main']
6+
pull_request:
7+
branches: ['main']
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
13+
jobs:
14+
build-and-push:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Log in to the Container registry
25+
uses: docker/login-action@v3
26+
with:
27+
registry: ${{ env.REGISTRY }}
28+
username: ${{ github.actor }}
29+
password: ${{ secrets.GITHUB_TOKEN }}
30+
31+
- name: Extract metadata (tags, labels) for Docker
32+
id: meta
33+
uses: docker/metadata-action@v5
34+
with:
35+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
36+
tags: |
37+
type=sha,format=long
38+
type=ref,event=branch
39+
type=ref,event=pr
40+
type=semver,pattern={{version}}
41+
type=semver,pattern={{major}}.{{minor}}
42+
type=semver,pattern={{major}}
43+
44+
- name: Build and push Docker image
45+
uses: docker/build-push-action@v5
46+
with:
47+
context: .
48+
push: ${{ github.event_name != 'pull_request' }}
49+
tags: ${{ steps.meta.outputs.tags }}
50+
labels: ${{ steps.meta.outputs.labels }}

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# System files
2+
.DS_Store
3+
4+
# Python-generated files
5+
__pycache__/
6+
*.py[oc]
7+
build/
8+
dist/
9+
wheels/
10+
*.egg-info
11+
config
12+
uploads
13+
.pytest_cache
14+
logs
15+
project
16+
17+
# Virtual environments
18+
.venv
19+
20+
# Security related ignores
21+
.env

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.11

Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM ubuntu:24.04
2+
3+
# Copy uv directly from its image (correct path this time)
4+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
5+
6+
# Install required system dependencies for building Python packages
7+
RUN apt-get update && \
8+
apt-get install -y \
9+
gcc \
10+
python3-dev \
11+
libmagic1 \
12+
curl \
13+
&& rm -rf /var/lib/apt/lists/*
14+
15+
# Copy dependency files first
16+
COPY pyproject.toml uv.lock .python-version /app/
17+
WORKDIR /app
18+
19+
# Create virtual environment and install dependencies
20+
ENV PATH="/app/.venv/bin:$PATH"
21+
RUN uv sync --frozen --no-cache
22+
23+
# Copy the project files
24+
COPY . .
25+
26+
# Set default port using ARG and ENV
27+
ARG PORT=8000
28+
ENV PORT=${PORT}
29+
30+
# Default command (can be overridden in compose.yml)
31+
CMD /app/.venv/bin/fastapi run app/main.py --host 0.0.0.0 --port ${PORT}

0 commit comments

Comments
 (0)