Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ DATABASE_URL="file:./dev.db"
# PostgreSQL (recommended for production / 生产推荐)
# DATABASE_URL="postgresql://user:password@localhost:5432/ose"

# --- Encryption / 加密 ---
# Required to save user-provided AI API keys. Without this key, the API will
# reject attempts to store API keys (HTTP 503).
# 存储用户 AI API Key 时必须设置。未设置时,保存 API Key 的请求会返回 503 错误。
# Generate with: openssl rand -base64 32
# 使用 openssl rand -base64 32 生成
# WARNING: Back this up. If lost, all stored user API keys become unreadable and
# users must re-enter them.
# 警告:请备份此值。丢失后已存储的用户 API Key 将无法解密,用户需重新输入。
OSE_ENCRYPTION_KEY=

# --- Authentication / 认证 ---
# Generate with: openssl rand -base64 32
# 使用 openssl rand -base64 32 生成
Expand Down
5 changes: 3 additions & 2 deletions .env.tauri
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Tauri 桌面版配置
NEXTAUTH_URL=http://localhost:19898
NEXTAUTH_SECRET=ose-desktop-secret-change-me
AUTH_URL=http://localhost:19898
AUTH_SECRET=ose-desktop-secret-change-me
# AUTH_SECRET and NEXTAUTH_SECRET are generated at runtime and injected by the
# Tauri sidecar startup code. For `tauri dev`, set them in a local .env.local
# file (which is gitignored).
2 changes: 1 addition & 1 deletion .github/workflows/android-apk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
node-version: '22'
cache: npm

- name: Setup Java
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- uses: actions/checkout@v6
- uses: actions/setup-node@v4
with:
node-version: '20'
node-version: '22'
cache: 'npm'
- run: npm ci
- run: npm run format:check || echo "Formatting drift found; run npm run format locally."
Expand All @@ -43,7 +43,7 @@ jobs:
- uses: actions/checkout@v6
- uses: actions/setup-node@v4
with:
node-version: '20'
node-version: '22'
cache: 'npm'
- run: npm ci
- run: npm run lint
Expand All @@ -54,7 +54,7 @@ jobs:
- uses: actions/checkout@v6
- uses: actions/setup-node@v4
with:
node-version: '20'
node-version: '22'
cache: 'npm'
- run: npm ci
- run: npx prisma generate --schema src/prisma/schema.prisma
Expand All @@ -67,7 +67,7 @@ jobs:
- uses: actions/checkout@v6
- uses: actions/setup-node@v4
with:
node-version: '20'
node-version: '22'
cache: 'npm'
- run: npm ci
- run: npx prisma generate --schema src/prisma/schema.prisma
Expand All @@ -80,7 +80,7 @@ jobs:
- uses: actions/checkout@v6
- uses: actions/setup-node@v4
with:
node-version: '20'
node-version: '22'
cache: 'npm'
- run: npm ci
- run: npx prisma generate --schema src/prisma/schema.prisma
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
node-version: '22'
cache: npm

- name: Setup Rust
Expand Down Expand Up @@ -166,7 +166,7 @@ jobs:
OSE Windows Portable

1. Keep OSE.exe, portable.ini, and the resources directory together.
2. Node.js 20+ must be installed and available in PATH.
2. Node.js 22+ must be installed and available in PATH.
3. User data is stored in the system app data directory.
4. The bundled Next.js standalone server lives in resources/binaries/standalone.
"@ | Set-Content -Path (Join-Path $portableDir 'README.txt') -Encoding UTF8
Expand Down Expand Up @@ -265,7 +265,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
node-version: '22'
cache: npm

- name: Setup Java
Expand Down Expand Up @@ -399,5 +399,5 @@ jobs:
- Linux: `OSE-${{ github.ref_name }}-Linux-x86_64.AppImage`, `.deb`, or `.rpm`
- Android: `OSE-${{ github.ref_name }}-Android.apk`

Windows portable builds require Node.js 20+ in PATH because the Next.js standalone server is launched locally.
Windows portable builds require Node.js 22+ in PATH because the Next.js standalone server is launched locally.
files: release-assets/*
2 changes: 1 addition & 1 deletion .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- uses: actions/checkout@v6
- uses: actions/setup-node@v4
with:
node-version: '20'
node-version: '22'
cache: 'npm'
- run: npm ci
- run: npm audit --omit=dev --audit-level=high
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tauri-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: '20'
node-version: '22'
cache: npm

- uses: dtolnay/rust-toolchain@stable
Expand Down
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20
22
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20
22
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Thank you for your interest in OSE. We are building an open, self-hostable, AI-p

Prerequisites:

- Node.js 20 recommended, Node.js 18+ supported by the project metadata.
- Node.js 20+ supported by the project metadata; Node.js 22 LTS is recommended.
- npm 10+.
- Git.
- Optional: Rust toolchain for Tauri desktop builds.
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:25-alpine AS base
FROM node:22-alpine AS base

FROM base AS deps
WORKDIR /app
Expand Down
46 changes: 40 additions & 6 deletions docs/desktop-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ OSE uses Tauri for desktop packaging on Windows, Linux, and macOS.

## Prerequisites

- Node.js 20 (build host).
- Node.js 22 LTS (build host).
- npm.
- Rust toolchain.
- Tauri system dependencies for your platform.
Expand Down Expand Up @@ -36,14 +36,14 @@ npm run tauri:build

### Bundling Node.js (no system Node.js required at runtime)

By default the desktop installer relies on the user having Node.js 20+ on `PATH`. To produce a self-contained installer that ships its own Node.js:
By default the desktop installer relies on the user having Node.js 22+ on `PATH`. To produce a self-contained installer that ships its own Node.js:

```bash
BUNDLE_NODE=1 npm run tauri:prepare
npm run tauri:build
```

`BUNDLE_NODE=1` downloads the official Node.js binary for the build host's platform/architecture and places it under `src-tauri/binaries/standalone/runtime/`. The Tauri app prefers this binary over `PATH` at runtime. Override the version with `BUNDLED_NODE_VERSION=v20.18.1` (or any other Node.js dist tag) if needed.
`BUNDLE_NODE=1` downloads the official Node.js binary for the build host's platform/architecture and places it under `src-tauri/binaries/standalone/runtime/`. The Tauri app prefers this binary over `PATH` at runtime. Override the version with `BUNDLED_NODE_VERSION=v22.15.0` (or any other Node.js dist tag) if needed.

> **Cross-compilation note**: the bundled Node.js matches the build host. To ship for a different OS/arch, run `tauri:prepare` on that platform (e.g. via CI matrix builds).

Expand Down Expand Up @@ -140,9 +140,43 @@ In production desktop mode, Tauri:
1. Selects an available local port.
2. Creates an app data directory.
3. Sets `DATABASE_URL` to the local SQLite database.
4. Starts `node start.js` — preferring the bundled `runtime/node[.exe]` when present, otherwise `node` from `PATH`.
5. Polls `/api/ai/status` until the Next.js server is ready.
6. Navigates the WebView to `http://127.0.0.1:<port>`.
4. Resolves or generates a per-install auth secret (see [Auth Secret](#auth-secret) below).
5. Starts `node start.js` — preferring the bundled `runtime/node[.exe]` when present, otherwise `node` from `PATH`.
6. Polls `/api/ai/status` until the Next.js server is ready.
7. Navigates the WebView to `http://127.0.0.1:<port>`.

## Auth Secret

Each desktop installation generates a unique auth secret on first launch. The secret is used to sign Auth.js / NextAuth session tokens and is never shared between installs.

### Storage location

The secret is stored in a file named `auth.secret` inside the app data directory:

- **Windows**: `%AppData%\com.ose.softwareexam\auth.secret`
- **macOS**: `~/Library/Application Support/com.ose.softwareexam/auth.secret`
- **Linux**: `~/.local/share/com.ose.softwareexam/auth.secret`

### Format and permissions

The file contains a 44-character Base64 string derived from 32 cryptographically random bytes. On Unix-like systems the file is created with `0600` (owner read/write only) permissions set at creation time, with no intermediate world-readable state.

### Secret reuse across restarts

On subsequent launches the app reads the existing `auth.secret` file and reuses the value. If the file is missing or empty, a new secret is generated automatically.

### Impact of deleting the file

Deleting `auth.secret` causes a new secret to be generated on the next launch. All existing sessions become invalid (users are signed out), but no study data is lost.

### Development mode

For `tauri dev`, `AUTH_SECRET` and `NEXTAUTH_SECRET` are **not** injected automatically. Set them in a local `.env.local` file (which is gitignored):

```env
AUTH_SECRET=any-local-dev-value
NEXTAUTH_SECRET=any-local-dev-value
```

## Portable Zip (Windows)

Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This guide walks you from a clean machine to a running OSE development server.

## Prerequisites

- Node.js 18+; Node.js 20 is recommended.
- Node.js 20+; Node.js 22 LTS is recommended.
- npm 10+.
- Git.
- Optional: Rust and the Tauri prerequisites if you want to build the desktop app.
Expand Down
38 changes: 37 additions & 1 deletion docs/self-hosting.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ Minimum production environment:
DATABASE_URL=file:/data/ose.db
NEXTAUTH_URL=https://your-domain.example
NEXTAUTH_SECRET=replace-with-openssl-rand-base64-32
OSE_ENCRYPTION_KEY=replace-with-openssl-rand-base64-32
```

`OSE_ENCRYPTION_KEY` is required to allow users to save their AI API keys. Without it, the settings API returns HTTP 503 when a user tries to store a key. Generate it with:

```bash
openssl rand -base64 32
```

Optional AI variables can be added to `.env` or the Compose environment section.
Expand All @@ -40,7 +47,7 @@ npx prisma migrate deploy

## VPS Manual Deployment

Install Node.js 20, clone the repository, then:
Install Node.js 22 LTS, clone the repository, then:

```bash
npm ci
Expand Down Expand Up @@ -132,3 +139,32 @@ explicit request/body model > saved user setting > DEFAULT_<PROVIDER>_MODEL env
```

This means a user's saved model preference always wins, and the env override only applies when no model has been saved by the user.

## Encryption Key (`OSE_ENCRYPTION_KEY`)

User-provided AI API keys (e.g. Anthropic, OpenAI, Gemini, custom provider) are encrypted at rest using AES-256-GCM before being written to the database. The `OSE_ENCRYPTION_KEY` environment variable supplies the 32-byte key.

**Generating the key:**

```bash
openssl rand -base64 32
```

**Behavior without the key:**

- Saving a new API key via the settings page returns HTTP 503 and the key is not persisted.
- Any legacy plaintext keys already in the database are treated as unconfigured until you set the key and they are migrated.

**Lazy migration of existing plaintext keys:**

If you upgrade from a deployment that stored keys in plaintext, existing `apiKey` / `imageApiKey` values are automatically encrypted on first use once `OSE_ENCRYPTION_KEY` is set. The plaintext column is cleared immediately after encryption. No manual migration step is required.

**Key rotation:**

1. Add a migration script that re-encrypts all stored keys with the new key.
2. Replace `OSE_ENCRYPTION_KEY` in your environment with the new value.
3. If you rotate without re-encrypting, users will need to re-enter their API keys.

**Backup:**

Back up `OSE_ENCRYPTION_KEY` separately from the database. Losing the key makes all stored user API keys permanently unreadable.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"self-hosted"
],
"engines": {
"node": ">=18.0.0"
"node": ">=20.0.0"
},
"scripts": {
"dev": "next dev",
Expand Down
2 changes: 1 addition & 1 deletion scripts/prepare-sidecar.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ async function main() {
} else {
fs.rmSync(runtimeTarget, { recursive: true, force: true });
console.log(
'Using PATH Node.js mode. Install Node.js 20+ on target machines, or set BUNDLE_NODE=1 to ship a bundled runtime.'
'Using PATH Node.js mode. Install Node.js 22+ on target machines, or set BUNDLE_NODE=1 to ship a bundled runtime.'
);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ crate-type = ["staticlib", "cdylib", "rlib"]
tauri-build = { version = "2", features = [] }

[dependencies]
base64 = "0.22"
getrandom = "0.2"
portpicker = "0.1"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
Expand Down
Loading
Loading