mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-09-26 13:45:16 -07:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5b29ce8c6a | ||
|
|
2c1e0f90a7 | ||
|
|
25602555b1 | ||
|
|
9b0e024d3b | ||
|
|
9a8425f401 | ||
|
|
376afad852 |
+1
-2
@@ -8,8 +8,7 @@ tauri/
|
||||
landing/
|
||||
docs/
|
||||
mlx-test/
|
||||
scripts/*
|
||||
!scripts/rocm-entrypoint.sh
|
||||
scripts/
|
||||
|
||||
# Dependencies & build artifacts (rebuilt in Docker)
|
||||
node_modules/
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
package.json text eol=lf
|
||||
scripts/*.sh text eol=lf
|
||||
@@ -340,64 +340,3 @@ jobs:
|
||||
name: voicebox-server-cuda-windows
|
||||
path: backend/dist/voicebox-server-cuda/
|
||||
retention-days: 7
|
||||
|
||||
build-rocm-windows:
|
||||
runs-on: windows-latest
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
# ROCm wheels are cp312-cp312-specific — build_binary.py --rocm enforces this.
|
||||
python-version: "3.12"
|
||||
cache: "pip"
|
||||
|
||||
- name: Install Python dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install pyinstaller
|
||||
pip install -r backend/requirements.txt
|
||||
pip install --no-deps chatterbox-tts
|
||||
pip install --no-deps hume-tada
|
||||
|
||||
- name: Build ROCm server binary (onedir)
|
||||
shell: bash
|
||||
working-directory: backend
|
||||
# build_binary.py --rocm pulls the official AMD Radeon torch + rocm_sdk
|
||||
# wheels (rocm-rel-7.2.1) itself when ROCm torch is not already present,
|
||||
# then restores the dev torch afterwards.
|
||||
run: python build_binary.py --rocm
|
||||
|
||||
- name: Package into server core + ROCm libs archives
|
||||
shell: bash
|
||||
run: |
|
||||
python scripts/package_rocm.py \
|
||||
backend/dist/voicebox-server-rocm/ \
|
||||
--output release-assets/ \
|
||||
--rocm-libs-version rocm7.2-v1 \
|
||||
--torch-compat ">=2.9.0,<2.10.0"
|
||||
|
||||
- name: Upload archives to GitHub Release
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: |
|
||||
release-assets/voicebox-server-rocm.tar.gz
|
||||
release-assets/voicebox-server-rocm.tar.gz.sha256
|
||||
release-assets/rocm-libs-rocm7.2-v1.tar.gz
|
||||
release-assets/rocm-libs-rocm7.2-v1.tar.gz.sha256
|
||||
release-assets/rocm-libs.json
|
||||
draft: true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Upload onedir as workflow artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: voicebox-server-rocm-windows
|
||||
path: backend/dist/voicebox-server-rocm/
|
||||
retention-days: 7
|
||||
|
||||
BIN
Binary file not shown.
@@ -5,17 +5,6 @@
|
||||
|
||||
# Changelog
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Linux
|
||||
|
||||
- **ROCm setup works on Linux AMD systems.** Docker ROCm builds now keep PyTorch
|
||||
on the ROCm wheel index during dependency installation, so later installs do
|
||||
not replace it with CUDA wheels. The ROCm compose overlay no longer assumes
|
||||
Ubuntu render/video group IDs; the container joins the groups that own the GPU
|
||||
device nodes at startup. Native Linux setup now picks ROCm wheels for AMD GPUs
|
||||
and CUDA wheels for NVIDIA GPUs before installing backend dependencies.
|
||||
|
||||
## [0.5.0] - 2026-04-22
|
||||
|
||||
**The Capture release.** Voicebox stops being just a voice-cloning studio and becomes a full AI voice studio. Hold a key anywhere on your machine, speak, release — the transcript lands in the focused text field. Flip the primitive around and any MCP-aware agent — Claude Code, Cursor, Spacebot — speaks back through an on-screen pill in one of your cloned voices. A local LLM sits between the two, so transcripts come out clean and voice profiles can carry a personality that reshapes what the agent says before it gets spoken.
|
||||
|
||||
+1
-1
@@ -91,7 +91,7 @@ On Windows, to build with CUDA support for local testing:
|
||||
just build-local # Build CPU + CUDA server binaries + Tauri installer
|
||||
```
|
||||
|
||||
This builds the CPU sidecar (bundled with the app), the CUDA binary (placed in `%APPDATA%/sh.voicebox.app/backends/` for runtime GPU switching), and the installable Tauri app.
|
||||
This builds the CPU sidecar (bundled with the app), the CUDA binary (placed in `%APPDATA%/com.voicebox.app/backends/` for runtime GPU switching), and the installable Tauri app.
|
||||
|
||||
Creates platform-specific installers (`.dmg`, `.msi`, `.AppImage`) in `tauri/src-tauri/target/release/bundle/`.
|
||||
|
||||
|
||||
+9
-39
@@ -1,15 +1,8 @@
|
||||
# ============================================================
|
||||
# Voicebox — Local TTS Server with Web UI
|
||||
# Voicebox — Local TTS Server with Web UI (CPU)
|
||||
# 3-stage build: Frontend → Python deps → Runtime
|
||||
#
|
||||
# Build variants:
|
||||
# CPU (default): docker compose up --build
|
||||
# ROCm (AMD GPU): docker compose -f docker-compose.yml -f docker-compose.rocm.yml up --build
|
||||
# ============================================================
|
||||
|
||||
# Top-level ARG so it is visible to all stages.
|
||||
ARG PYTORCH_VARIANT=cpu
|
||||
|
||||
# === Stage 1: Build frontend ===
|
||||
FROM oven/bun:1 AS frontend
|
||||
|
||||
@@ -20,11 +13,8 @@ COPY package.json bun.lock CHANGELOG.md ./
|
||||
COPY app/ ./app/
|
||||
COPY web/ ./web/
|
||||
|
||||
# Normalize line endings first (a Windows CRLF checkout would otherwise
|
||||
# defeat the `-z 's/,\n ]/…/'` match below, since it's LF-anchored), then
|
||||
# strip workspaces not needed for web build, and fix trailing comma
|
||||
RUN sed -i 's/\r$//' package.json && \
|
||||
sed -i '/"tauri"/d; /"landing"/d' package.json && \
|
||||
# Strip workspaces not needed for web build, and fix trailing comma
|
||||
RUN sed -i '/"tauri"/d; /"landing"/d' package.json && \
|
||||
sed -i -z 's/,\n ]/\n ]/' package.json
|
||||
RUN bun install --no-save
|
||||
# Build frontend (skip tsc — upstream has pre-existing type errors)
|
||||
@@ -34,9 +24,6 @@ RUN cd web && bunx --bun vite build
|
||||
# === Stage 2: Build Python dependencies ===
|
||||
FROM python:3.11-slim AS backend-builder
|
||||
|
||||
# Re-declare ARG inside the stage (Docker scoping requirement).
|
||||
ARG PYTORCH_VARIANT=cpu
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
@@ -47,19 +34,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
RUN pip install --no-cache-dir --upgrade pip
|
||||
|
||||
COPY backend/requirements.txt .
|
||||
|
||||
# ROCm wheel index. Default 6.3 (RDNA1/2/3); set ROCM_VERSION=7.2 for RDNA4.
|
||||
ARG ROCM_VERSION=6.3
|
||||
|
||||
# For ROCm, make the PyTorch ROCm index primary so every install below resolves
|
||||
# torch to ROCm wheels instead of the default CUDA build.
|
||||
RUN if [ "$PYTORCH_VARIANT" = "rocm" ]; then \
|
||||
pip install --no-cache-dir --prefix=/install \
|
||||
--index-url "https://download.pytorch.org/whl/rocm${ROCM_VERSION}" \
|
||||
torch torchaudio && \
|
||||
printf '[global]\nindex-url = https://download.pytorch.org/whl/rocm%s\nextra-index-url = https://pypi.org/simple\n' "$ROCM_VERSION" > /etc/pip.conf; \
|
||||
fi
|
||||
|
||||
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
|
||||
RUN pip install --no-cache-dir --prefix=/install --no-deps chatterbox-tts
|
||||
RUN pip install --no-cache-dir --prefix=/install --no-deps hume-tada
|
||||
@@ -70,17 +44,16 @@ RUN pip install --no-cache-dir --prefix=/install \
|
||||
# === Stage 3: Runtime ===
|
||||
FROM python:3.11-slim
|
||||
|
||||
# Create non-root user; the entrypoint joins GPU device groups at runtime.
|
||||
# Create non-root user for security
|
||||
RUN groupadd -r voicebox && \
|
||||
useradd -r -g voicebox -m -s /bin/bash voicebox
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install only runtime system dependencies (gosu drops root in the entrypoint)
|
||||
# Install only runtime system dependencies
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
ffmpeg \
|
||||
curl \
|
||||
gosu \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Copy installed Python packages from builder stage
|
||||
@@ -96,6 +69,9 @@ COPY --from=frontend --chown=voicebox:voicebox /build/web/dist /app/frontend/
|
||||
RUN mkdir -p /app/data/generations /app/data/profiles /app/data/cache \
|
||||
&& chown -R voicebox:voicebox /app/data
|
||||
|
||||
# Switch to non-root user
|
||||
USER voicebox
|
||||
|
||||
# Expose the API port
|
||||
EXPOSE 17493
|
||||
|
||||
@@ -103,11 +79,5 @@ EXPOSE 17493
|
||||
HEALTHCHECK --interval=30s --timeout=10s --retries=3 --start-period=60s \
|
||||
CMD curl -f http://localhost:17493/health || exit 1
|
||||
|
||||
# Entrypoint joins GPU groups then drops to the voicebox user.
|
||||
# Normalize CRLF (a Windows checkout otherwise leaves the shebang as
|
||||
# `#!/bin/sh\r`, which Linux can't resolve — reported as a misleading
|
||||
# "no such file or directory" even though the file exists).
|
||||
COPY --chmod=755 scripts/rocm-entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||
RUN sed -i 's/\r$//' /usr/local/bin/entrypoint.sh
|
||||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
||||
# Start the FastAPI server
|
||||
CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "17493"]
|
||||
|
||||
@@ -270,8 +270,7 @@ Use cases: agent dev loops (dictate a question, hear the answer in a cloned voic
|
||||
| Platform | Backend | Notes |
|
||||
| ------------------------ | -------------- | ---------------------------------------------- |
|
||||
| macOS (Apple Silicon) | MLX (Metal) | 4-5x faster via Neural Engine |
|
||||
| Windows (NVIDIA) | PyTorch (CUDA) | Auto-downloads CUDA binary from within the app |
|
||||
| Linux (NVIDIA) | PyTorch (CUDA) | Use a local/remote Python backend with CUDA PyTorch |
|
||||
| Windows / Linux (NVIDIA) | PyTorch (CUDA) | Auto-downloads CUDA binary from within the app |
|
||||
| Linux (AMD) | PyTorch (ROCm) | Auto-configures HSA_OVERRIDE_GFX_VERSION |
|
||||
| Windows (any GPU) | DirectML | Universal Windows GPU support |
|
||||
| Intel Arc | IPEX/XPU | Intel discrete GPU acceleration |
|
||||
|
||||
@@ -139,7 +139,7 @@ export function EngineModelSelector({ form, compact, selectedProfile }: EngineMo
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
</FormControl>
|
||||
<SelectContent side={compact ? 'top' : undefined}>
|
||||
<SelectContent>
|
||||
{availableOptions.map((opt) => (
|
||||
<SelectItem key={opt.value} value={opt.value} className={itemClass}>
|
||||
{opt.label}
|
||||
|
||||
@@ -555,7 +555,7 @@ export function FloatingGenerateBox({
|
||||
<SelectTrigger className="h-8 text-xs bg-card border-border rounded-full hover:bg-background/50 transition-all w-full">
|
||||
<SelectValue placeholder={t('generation.voiceSelector.placeholder')} />
|
||||
</SelectTrigger>
|
||||
<SelectContent side="top">
|
||||
<SelectContent>
|
||||
{profiles?.map((profile) => (
|
||||
<SelectItem key={profile.id} value={profile.id} className="text-xs">
|
||||
{profile.name}
|
||||
@@ -582,7 +582,7 @@ export function FloatingGenerateBox({
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
</FormControl>
|
||||
<SelectContent side="top">
|
||||
<SelectContent>
|
||||
{engineLangs.map((lang) => (
|
||||
<SelectItem key={lang.value} value={lang.value} className="text-xs">
|
||||
{lang.label}
|
||||
@@ -610,7 +610,7 @@ export function FloatingGenerateBox({
|
||||
<SelectTrigger className="h-8 text-xs bg-card border-border rounded-full hover:bg-background/50 transition-all">
|
||||
<SelectValue placeholder={t('generation.effects.none')} />
|
||||
</SelectTrigger>
|
||||
<SelectContent side="top">
|
||||
<SelectContent>
|
||||
<SelectItem value="none" className="text-xs">
|
||||
{t('generation.effects.none')}
|
||||
</SelectItem>
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Progress } from '@/components/ui/progress';
|
||||
import { apiClient } from '@/lib/api/client';
|
||||
import type { CudaDownloadProgress, RocmDownloadProgress } from '@/lib/api/types';
|
||||
import type { CudaDownloadProgress } from '@/lib/api/types';
|
||||
import { useServerHealth } from '@/lib/hooks/useServer';
|
||||
import { usePlatform } from '@/platform/PlatformContext';
|
||||
import { useServerStore } from '@/stores/serverStore';
|
||||
@@ -21,9 +21,6 @@ export function GpuAcceleration() {
|
||||
const [restartPhase, setRestartPhase] = useState<RestartPhase>('idle');
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [downloadProgress, setDownloadProgress] = useState<CudaDownloadProgress | null>(null);
|
||||
const [rocmDownloadProgress, setRocmDownloadProgress] = useState<RocmDownloadProgress | null>(
|
||||
null,
|
||||
);
|
||||
const healthPollRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
||||
|
||||
// Query CUDA backend status
|
||||
@@ -39,26 +36,10 @@ export function GpuAcceleration() {
|
||||
enabled: !!health, // Only fetch when backend is reachable
|
||||
});
|
||||
|
||||
// Query ROCm backend status
|
||||
const {
|
||||
data: rocmStatus,
|
||||
isLoading: _rocmStatusLoading,
|
||||
refetch: refetchRocmStatus,
|
||||
} = useQuery({
|
||||
queryKey: ['rocm-status', serverUrl],
|
||||
queryFn: () => apiClient.getRocmStatus(),
|
||||
refetchInterval: (query) => (query.state.status === 'pending' ? false : 10000),
|
||||
retry: 1,
|
||||
enabled: !!health, // Only fetch when backend is reachable
|
||||
});
|
||||
|
||||
// Derived state
|
||||
const isCurrentlyCuda = health?.backend_variant === 'cuda';
|
||||
const isCurrentlyRocm = health?.backend_variant === 'rocm';
|
||||
const cudaAvailable = cudaStatus?.available ?? false;
|
||||
const cudaDownloading = cudaStatus?.downloading ?? false;
|
||||
const rocmAvailable = rocmStatus?.available ?? false;
|
||||
const rocmDownloading = rocmStatus?.downloading ?? false;
|
||||
|
||||
// Clean up health poll on unmount
|
||||
useEffect(() => {
|
||||
@@ -70,7 +51,7 @@ export function GpuAcceleration() {
|
||||
};
|
||||
}, []);
|
||||
|
||||
// SSE progress tracking during CUDA download
|
||||
// SSE progress tracking during download
|
||||
useEffect(() => {
|
||||
if (!cudaDownloading || !serverUrl) {
|
||||
return;
|
||||
@@ -107,43 +88,6 @@ export function GpuAcceleration() {
|
||||
};
|
||||
}, [cudaDownloading, serverUrl, refetchCudaStatus]);
|
||||
|
||||
// SSE progress tracking during ROCm download
|
||||
useEffect(() => {
|
||||
if (!rocmDownloading || !serverUrl) {
|
||||
return;
|
||||
}
|
||||
|
||||
const eventSource = new EventSource(`${serverUrl}/backend/rocm-progress`);
|
||||
|
||||
eventSource.onmessage = (event) => {
|
||||
try {
|
||||
const data = JSON.parse(event.data) as RocmDownloadProgress;
|
||||
setRocmDownloadProgress(data);
|
||||
|
||||
if (data.status === 'complete') {
|
||||
eventSource.close();
|
||||
setRocmDownloadProgress(null);
|
||||
refetchRocmStatus();
|
||||
} else if (data.status === 'error') {
|
||||
eventSource.close();
|
||||
setError(data.error || 'Download failed');
|
||||
setRocmDownloadProgress(null);
|
||||
refetchRocmStatus();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error parsing ROCm progress event:', e);
|
||||
}
|
||||
};
|
||||
|
||||
eventSource.onerror = () => {
|
||||
eventSource.close();
|
||||
};
|
||||
|
||||
return () => {
|
||||
eventSource.close();
|
||||
};
|
||||
}, [rocmDownloading, serverUrl, refetchRocmStatus]);
|
||||
|
||||
// Start aggressive health polling during restart
|
||||
const startHealthPolling = useCallback(() => {
|
||||
if (healthPollRef.current) return;
|
||||
@@ -169,7 +113,7 @@ export function GpuAcceleration() {
|
||||
}, 1000);
|
||||
}, [queryClient]);
|
||||
|
||||
const handleDownloadCuda = async () => {
|
||||
const handleDownload = async () => {
|
||||
setError(null);
|
||||
try {
|
||||
await apiClient.downloadCudaBackend();
|
||||
@@ -184,21 +128,6 @@ export function GpuAcceleration() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleDownloadRocm = async () => {
|
||||
setError(null);
|
||||
try {
|
||||
await apiClient.downloadRocmBackend();
|
||||
refetchRocmStatus();
|
||||
} catch (e: unknown) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to start download';
|
||||
if (msg.includes('already downloaded')) {
|
||||
refetchRocmStatus();
|
||||
} else {
|
||||
setError(msg);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleRestart = async () => {
|
||||
setError(null);
|
||||
setRestartPhase('stopping');
|
||||
@@ -225,17 +154,18 @@ export function GpuAcceleration() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleSwitchToCpuFromCuda = async () => {
|
||||
const handleSwitchToCpu = async () => {
|
||||
// To switch to CPU: delete the CUDA binary, then restart.
|
||||
// start_server always prefers CUDA if present, so we must remove it first.
|
||||
setError(null);
|
||||
setRestartPhase('stopping');
|
||||
|
||||
try {
|
||||
// Tell Rust launcher to skip GPU binary detection on next start.
|
||||
// We cannot delete an active .exe on Windows, so we override instead.
|
||||
await platform.lifecycle.setBackendOverride('cpu');
|
||||
await apiClient.deleteCudaBackend();
|
||||
setRestartPhase('waiting');
|
||||
startHealthPolling();
|
||||
await platform.lifecycle.restartServer();
|
||||
// Invoke resolved — server is likely ready
|
||||
if (healthPollRef.current) {
|
||||
clearInterval(healthPollRef.current);
|
||||
healthPollRef.current = null;
|
||||
@@ -254,36 +184,7 @@ export function GpuAcceleration() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleSwitchToCpuFromRocm = async () => {
|
||||
setError(null);
|
||||
setRestartPhase('stopping');
|
||||
|
||||
try {
|
||||
// Tell Rust launcher to skip GPU binary detection on next start.
|
||||
// We cannot delete an active .exe on Windows, so we override instead.
|
||||
await platform.lifecycle.setBackendOverride('cpu');
|
||||
setRestartPhase('waiting');
|
||||
startHealthPolling();
|
||||
await platform.lifecycle.restartServer();
|
||||
if (healthPollRef.current) {
|
||||
clearInterval(healthPollRef.current);
|
||||
healthPollRef.current = null;
|
||||
}
|
||||
setRestartPhase('ready');
|
||||
queryClient.invalidateQueries();
|
||||
setTimeout(() => setRestartPhase('idle'), 2000);
|
||||
} catch (e: unknown) {
|
||||
setRestartPhase('idle');
|
||||
if (healthPollRef.current) {
|
||||
clearInterval(healthPollRef.current);
|
||||
healthPollRef.current = null;
|
||||
}
|
||||
setError(e instanceof Error ? e.message : 'Failed to switch to CPU');
|
||||
refetchRocmStatus();
|
||||
}
|
||||
};
|
||||
|
||||
const handleDeleteCuda = async () => {
|
||||
const handleDelete = async () => {
|
||||
setError(null);
|
||||
try {
|
||||
await apiClient.deleteCudaBackend();
|
||||
@@ -293,16 +194,6 @@ export function GpuAcceleration() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleDeleteRocm = async () => {
|
||||
setError(null);
|
||||
try {
|
||||
await apiClient.deleteRocmBackend();
|
||||
refetchRocmStatus();
|
||||
} catch (e: unknown) {
|
||||
setError(e instanceof Error ? e.message : 'Failed to delete ROCm backend');
|
||||
}
|
||||
};
|
||||
|
||||
const formatBytes = (bytes: number): string => {
|
||||
if (bytes === 0) return '0 B';
|
||||
const k = 1024;
|
||||
@@ -314,7 +205,7 @@ export function GpuAcceleration() {
|
||||
// Don't render until health data is available
|
||||
if (!health) return null;
|
||||
|
||||
// If the system already has native GPU (MPS, ROCm active, etc.), only show info - no download needed
|
||||
// If the system already has native GPU (MPS, etc.), only show info - no CUDA needed
|
||||
const hasNativeGpu =
|
||||
health.gpu_available &&
|
||||
!isCurrentlyCuda &&
|
||||
@@ -350,6 +241,8 @@ export function GpuAcceleration() {
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Native GPU detected - no CUDA download needed */}
|
||||
|
||||
{/* Currently running CUDA - show switch back to CPU */}
|
||||
{isCurrentlyCuda && platform.metadata.isTauri && (
|
||||
<>
|
||||
@@ -368,12 +261,7 @@ export function GpuAcceleration() {
|
||||
Running with CUDA GPU acceleration. Switch back to CPU if needed (you can
|
||||
re-download later).
|
||||
</p>
|
||||
<Button
|
||||
onClick={handleSwitchToCpuFromCuda}
|
||||
variant="outline"
|
||||
className="w-full"
|
||||
size="sm"
|
||||
>
|
||||
<Button onClick={handleSwitchToCpu} variant="outline" className="w-full" size="sm">
|
||||
<RotateCw className="h-4 w-4 mr-2" />
|
||||
Switch to CPU Backend
|
||||
</Button>
|
||||
@@ -388,207 +276,39 @@ export function GpuAcceleration() {
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Currently running ROCm - show switch back to CPU */}
|
||||
{isCurrentlyRocm && platform.metadata.isTauri && (
|
||||
{/* CUDA download/manage section - show when no native GPU and not currently running CUDA */}
|
||||
{!hasNativeGpu && !isCurrentlyCuda && (
|
||||
<>
|
||||
{restartPhase !== 'idle' ? (
|
||||
<div className="flex items-center gap-2 p-3 rounded-lg bg-primary/5 border">
|
||||
<Loader2 className="h-4 w-4 animate-spin" />
|
||||
<span className="text-sm">
|
||||
{restartPhase === 'stopping' && 'Stopping server...'}
|
||||
{restartPhase === 'waiting' && 'Restarting server...'}
|
||||
{restartPhase === 'ready' && 'Server restarted successfully!'}
|
||||
</span>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Running with ROCm GPU acceleration for AMD. Switch back to CPU if needed (you can
|
||||
re-download later).
|
||||
</p>
|
||||
<Button
|
||||
onClick={handleSwitchToCpuFromRocm}
|
||||
variant="outline"
|
||||
className="w-full"
|
||||
size="sm"
|
||||
>
|
||||
<RotateCw className="h-4 w-4 mr-2" />
|
||||
Switch to CPU Backend
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
{error && (
|
||||
<div className="flex items-center gap-2 text-sm text-destructive">
|
||||
<AlertCircle className="h-4 w-4 shrink-0" />
|
||||
<span>{error}</span>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Backend download/manage sections - show when no native GPU and not currently running GPU */}
|
||||
{!hasNativeGpu && !isCurrentlyCuda && !isCurrentlyRocm && (
|
||||
<>
|
||||
{/* CUDA Section */}
|
||||
<div className="space-y-4">
|
||||
<div className="text-sm font-medium">NVIDIA (CUDA)</div>
|
||||
|
||||
{/* CUDA Download progress */}
|
||||
{cudaDownloading && downloadProgress && (
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-between text-sm">
|
||||
<div className="flex items-center gap-2">
|
||||
<Loader2 className="h-4 w-4 animate-spin" />
|
||||
<span>
|
||||
{downloadProgress.filename ||
|
||||
(cudaAvailable
|
||||
? 'Updating CUDA backend...'
|
||||
: 'Downloading CUDA backend...')}
|
||||
</span>
|
||||
</div>
|
||||
{downloadProgress.total > 0 && (
|
||||
<span className="text-muted-foreground">
|
||||
{downloadProgress.progress.toFixed(1)}%
|
||||
</span>
|
||||
)}
|
||||
{/* Download progress (manual download or auto-update) */}
|
||||
{cudaDownloading && downloadProgress && (
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-between text-sm">
|
||||
<div className="flex items-center gap-2">
|
||||
<Loader2 className="h-4 w-4 animate-spin" />
|
||||
<span>
|
||||
{downloadProgress.filename ||
|
||||
(cudaAvailable
|
||||
? 'Updating CUDA backend...'
|
||||
: 'Downloading CUDA backend...')}
|
||||
</span>
|
||||
</div>
|
||||
{downloadProgress.total > 0 && (
|
||||
<>
|
||||
<Progress value={downloadProgress.progress} className="h-2" />
|
||||
<div className="text-xs text-muted-foreground">
|
||||
{formatBytes(downloadProgress.current)} /{' '}
|
||||
{formatBytes(downloadProgress.total)}
|
||||
</div>
|
||||
</>
|
||||
<span className="text-muted-foreground">
|
||||
{downloadProgress.progress.toFixed(1)}%
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* CUDA Actions */}
|
||||
{restartPhase === 'idle' && !cudaDownloading && (
|
||||
<div className="space-y-2">
|
||||
{!cudaAvailable && (
|
||||
<div className="space-y-3">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Download the CUDA backend (~2.4 GB) for NVIDIA GPU acceleration. Requires an
|
||||
NVIDIA GPU with CUDA support.
|
||||
</p>
|
||||
<Button onClick={handleDownloadCuda} className="w-full" size="sm">
|
||||
<Download className="h-4 w-4 mr-2" />
|
||||
Download CUDA Backend
|
||||
</Button>
|
||||
{downloadProgress.total > 0 && (
|
||||
<>
|
||||
<Progress value={downloadProgress.progress} className="h-2" />
|
||||
<div className="text-xs text-muted-foreground">
|
||||
{formatBytes(downloadProgress.current)} /{' '}
|
||||
{formatBytes(downloadProgress.total)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{cudaAvailable && platform.metadata.isTauri && (
|
||||
<div className="space-y-3">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
CUDA backend is downloaded and ready. Restart the server to enable GPU
|
||||
acceleration.
|
||||
</p>
|
||||
<Button onClick={handleRestart} className="w-full" size="sm">
|
||||
<RotateCw className="h-4 w-4 mr-2" />
|
||||
Switch to CUDA Backend
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{cudaAvailable && (
|
||||
<Button
|
||||
onClick={handleDeleteCuda}
|
||||
variant="ghost"
|
||||
className="w-full text-muted-foreground hover:text-destructive"
|
||||
size="sm"
|
||||
>
|
||||
<Trash2 className="h-4 w-4 mr-2" />
|
||||
Remove CUDA Backend
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Divider */}
|
||||
<div className="border-t" />
|
||||
|
||||
{/* ROCm Section */}
|
||||
<div className="space-y-4">
|
||||
<div className="text-sm font-medium">AMD (ROCm)</div>
|
||||
|
||||
{/* ROCm Download progress */}
|
||||
{rocmDownloading && rocmDownloadProgress && (
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-between text-sm">
|
||||
<div className="flex items-center gap-2">
|
||||
<Loader2 className="h-4 w-4 animate-spin" />
|
||||
<span>
|
||||
{rocmDownloadProgress.filename ||
|
||||
(rocmAvailable
|
||||
? 'Updating ROCm backend...'
|
||||
: 'Downloading ROCm backend...')}
|
||||
</span>
|
||||
</div>
|
||||
{rocmDownloadProgress.total > 0 && (
|
||||
<span className="text-muted-foreground">
|
||||
{rocmDownloadProgress.progress.toFixed(1)}%
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{rocmDownloadProgress.total > 0 && (
|
||||
<>
|
||||
<Progress value={rocmDownloadProgress.progress} className="h-2" />
|
||||
<div className="text-xs text-muted-foreground">
|
||||
{formatBytes(rocmDownloadProgress.current)} /{' '}
|
||||
{formatBytes(rocmDownloadProgress.total)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ROCm Actions */}
|
||||
{restartPhase === 'idle' && !rocmDownloading && (
|
||||
<div className="space-y-2">
|
||||
{!rocmAvailable && (
|
||||
<div className="space-y-3">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Download the ROCm backend (~2-3 GB) for AMD GPU acceleration. Requires an
|
||||
AMD Radeon GPU with ROCm support.
|
||||
</p>
|
||||
<Button onClick={handleDownloadRocm} className="w-full" size="sm">
|
||||
<Download className="h-4 w-4 mr-2" />
|
||||
Download AMD ROCm Backend
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{rocmAvailable && platform.metadata.isTauri && (
|
||||
<div className="space-y-3">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
ROCm backend is downloaded and ready. Restart the server to enable AMD GPU
|
||||
acceleration.
|
||||
</p>
|
||||
<Button onClick={handleRestart} className="w-full" size="sm">
|
||||
<RotateCw className="h-4 w-4 mr-2" />
|
||||
Switch to ROCm Backend
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{rocmAvailable && (
|
||||
<Button
|
||||
onClick={handleDeleteRocm}
|
||||
variant="ghost"
|
||||
className="w-full text-muted-foreground hover:text-destructive"
|
||||
size="sm"
|
||||
>
|
||||
<Trash2 className="h-4 w-4 mr-2" />
|
||||
Remove ROCm Backend
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Restart in progress */}
|
||||
{restartPhase !== 'idle' && (
|
||||
@@ -609,6 +329,52 @@ export function GpuAcceleration() {
|
||||
<span>{error}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Actions */}
|
||||
{restartPhase === 'idle' && !cudaDownloading && (
|
||||
<div className="space-y-2">
|
||||
{/* Not downloaded yet - show download button */}
|
||||
{!cudaAvailable && (
|
||||
<div className="space-y-3">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Download the CUDA backend (~2.4 GB) for NVIDIA GPU acceleration. Requires an
|
||||
NVIDIA GPU with CUDA support.
|
||||
</p>
|
||||
<Button onClick={handleDownload} className="w-full" size="sm">
|
||||
<Download className="h-4 w-4 mr-2" />
|
||||
Download CUDA Backend
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Downloaded but not active - show switch button */}
|
||||
{cudaAvailable && platform.metadata.isTauri && (
|
||||
<div className="space-y-3">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
CUDA backend is downloaded and ready. Restart the server to enable GPU
|
||||
acceleration.
|
||||
</p>
|
||||
<Button onClick={handleRestart} className="w-full" size="sm">
|
||||
<RotateCw className="h-4 w-4 mr-2" />
|
||||
Switch to CUDA Backend
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Delete option when downloaded (and not active) */}
|
||||
{cudaAvailable && (
|
||||
<Button
|
||||
onClick={handleDelete}
|
||||
variant="ghost"
|
||||
className="w-full text-muted-foreground "
|
||||
size="sm"
|
||||
>
|
||||
<Trash2 className="h-4 w-4 mr-2" />
|
||||
Remove CUDA Backend
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</CardContent>
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { Cloud, Loader2 } from 'lucide-react';
|
||||
import { Cloud, Copy, Loader2, RefreshCw, ShieldCheck } from 'lucide-react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { useToast } from '@/components/ui/use-toast';
|
||||
import { apiClient } from '@/lib/api/client';
|
||||
import { SettingRow, SettingSection } from './SettingRow';
|
||||
@@ -9,6 +18,13 @@ import { SettingRow, SettingSection } from './SettingRow';
|
||||
// "Log in with browser" device pairing. The backend opens the system browser
|
||||
// and completes the code exchange; here we just kick it off and poll status
|
||||
// until the link goes live. The API key never touches the frontend.
|
||||
//
|
||||
// Once linked, the encrypted-backup rows drive the sync identity flows: this
|
||||
// device registers as an encryption device, and either mints the account's
|
||||
// master key (first device — the recovery phrase is force-displayed exactly
|
||||
// once) or waits to be provisioned by another device / restored from the
|
||||
// phrase. All crypto happens in the local backend; this UI only ever sees the
|
||||
// phrase, and only at mint time.
|
||||
export function CloudSection() {
|
||||
const { toast } = useToast();
|
||||
const queryClient = useQueryClient();
|
||||
@@ -33,22 +49,6 @@ export function CloudSection() {
|
||||
}
|
||||
}, [connected, polling, status?.device_name, toast]);
|
||||
|
||||
// Give up after two minutes so an abandoned browser flow doesn't leave the
|
||||
// button stuck on "Waiting for browser…". The backend state stays valid for
|
||||
// ten, so the user can simply start again.
|
||||
useEffect(() => {
|
||||
if (!polling) return;
|
||||
const timeoutId = window.setTimeout(() => {
|
||||
setPolling(false);
|
||||
toast({
|
||||
title: 'Sign-in timed out',
|
||||
description: 'The browser sign-in was not completed. Try again.',
|
||||
variant: 'destructive',
|
||||
});
|
||||
}, 120_000);
|
||||
return () => window.clearTimeout(timeoutId);
|
||||
}, [polling, toast]);
|
||||
|
||||
const startLogin = useMutation({
|
||||
mutationFn: () => apiClient.startCloudLogin(),
|
||||
onSuccess: () => {
|
||||
@@ -70,10 +70,10 @@ export function CloudSection() {
|
||||
mutationFn: () => apiClient.disconnectCloud(),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['cloud-status'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['cloud-sync-status'] });
|
||||
toast({
|
||||
title: 'Disconnected',
|
||||
description:
|
||||
'This device is no longer linked. The key stays valid until revoked in your account.',
|
||||
description: 'This device is no longer linked. The key stays valid until revoked in your account.',
|
||||
});
|
||||
},
|
||||
onError: (error: Error) =>
|
||||
@@ -105,10 +105,7 @@ export function CloudSection() {
|
||||
variant="outline"
|
||||
>
|
||||
{disconnect.isPending ? (
|
||||
<>
|
||||
<Loader2 className="h-3.5 w-3.5 mr-1.5 animate-spin" />
|
||||
Disconnecting…
|
||||
</>
|
||||
<Loader2 className="h-3.5 w-3.5 animate-spin" />
|
||||
) : (
|
||||
'Disconnect'
|
||||
)}
|
||||
@@ -131,6 +128,8 @@ export function CloudSection() {
|
||||
}
|
||||
/>
|
||||
|
||||
{connected && <BackupRows />}
|
||||
|
||||
{connected && (
|
||||
<SettingRow
|
||||
title="Manage"
|
||||
@@ -138,7 +137,7 @@ export function CloudSection() {
|
||||
>
|
||||
<a
|
||||
className="text-sm text-accent hover:underline"
|
||||
href={status?.dashboard_url ?? 'https://voicebox.sh/account'}
|
||||
href="https://voicebox.sh/account"
|
||||
rel="noopener noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
@@ -149,3 +148,230 @@ export function CloudSection() {
|
||||
</SettingSection>
|
||||
);
|
||||
}
|
||||
|
||||
function BackupRows() {
|
||||
const { toast } = useToast();
|
||||
const queryClient = useQueryClient();
|
||||
const [phrase, setPhrase] = useState<string | null>(null);
|
||||
const [phraseCopied, setPhraseCopied] = useState(false);
|
||||
const [restoreInput, setRestoreInput] = useState('');
|
||||
|
||||
const { data: sync } = useQuery({
|
||||
queryKey: ['cloud-sync-status'],
|
||||
queryFn: () => apiClient.getCloudSyncStatus(),
|
||||
});
|
||||
|
||||
const refreshSync = () => queryClient.invalidateQueries({ queryKey: ['cloud-sync-status'] });
|
||||
|
||||
const setup = useMutation({
|
||||
mutationFn: () => apiClient.setupCloudSync(),
|
||||
onSuccess: (result) => {
|
||||
refreshSync();
|
||||
if (result.recovery_phrase) {
|
||||
// First device: the phrase exists only in this response. Force-display
|
||||
// it; the dialog can only be dismissed by confirming.
|
||||
setPhraseCopied(false);
|
||||
setPhrase(result.recovery_phrase);
|
||||
}
|
||||
},
|
||||
onError: (error: Error) =>
|
||||
toast({ title: 'Could not enable backup', description: error.message, variant: 'destructive' }),
|
||||
});
|
||||
|
||||
const adopt = useMutation({
|
||||
mutationFn: () => apiClient.adoptCloudSync(),
|
||||
onSuccess: (result) => {
|
||||
refreshSync();
|
||||
if (result.status === 'ready') {
|
||||
toast({ title: 'Backup enabled', description: 'This device received its encryption key.' });
|
||||
} else {
|
||||
toast({
|
||||
title: 'Not approved yet',
|
||||
description: 'Approve this device from another synced device, then check again.',
|
||||
});
|
||||
}
|
||||
},
|
||||
onError: (error: Error) =>
|
||||
toast({ title: 'Could not check', description: error.message, variant: 'destructive' }),
|
||||
});
|
||||
|
||||
const restore = useMutation({
|
||||
mutationFn: (recoveryPhrase: string) => apiClient.restoreCloudSync(recoveryPhrase),
|
||||
onSuccess: () => {
|
||||
refreshSync();
|
||||
setRestoreInput('');
|
||||
toast({ title: 'Backup restored', description: 'Your encryption key was recovered. Syncing is ready.' });
|
||||
},
|
||||
onError: (error: Error) =>
|
||||
toast({ title: 'Could not restore', description: error.message, variant: 'destructive' }),
|
||||
});
|
||||
|
||||
const run = useMutation({
|
||||
mutationFn: () => apiClient.runCloudSync(),
|
||||
onSuccess: (report) => {
|
||||
refreshSync();
|
||||
const pushed = report.pushed + report.pushed_deletes;
|
||||
const pulled = report.pulled + report.pulled_deletes;
|
||||
toast({
|
||||
title: 'Sync complete',
|
||||
description:
|
||||
pushed === 0 && pulled === 0
|
||||
? 'Everything is already up to date.'
|
||||
: `Backed up ${pushed} ${pushed === 1 ? 'item' : 'items'}, received ${pulled}.`,
|
||||
});
|
||||
},
|
||||
onError: (error: Error) =>
|
||||
toast({ title: 'Sync failed', description: error.message, variant: 'destructive' }),
|
||||
});
|
||||
|
||||
const state = sync?.status ?? 'unregistered';
|
||||
|
||||
return (
|
||||
<>
|
||||
{state === 'unregistered' && (
|
||||
<SettingRow
|
||||
title="Encrypted backup"
|
||||
description="Back up captures, generations, and voice profiles — encrypted on this device before anything is uploaded."
|
||||
action={
|
||||
<Button disabled={setup.isPending} onClick={() => setup.mutate()} size="sm">
|
||||
{setup.isPending ? (
|
||||
<Loader2 className="h-3.5 w-3.5 animate-spin" />
|
||||
) : (
|
||||
<>
|
||||
<ShieldCheck className="h-3.5 w-3.5 mr-1.5" />
|
||||
Enable backup
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
{state === 'awaiting_provision' && (
|
||||
<>
|
||||
<SettingRow
|
||||
title="Waiting for encryption key"
|
||||
description="This account already has a backup. Approve this device from another synced device, or restore with your recovery phrase below."
|
||||
action={
|
||||
<Button disabled={adopt.isPending} onClick={() => adopt.mutate()} size="sm" variant="outline">
|
||||
{adopt.isPending ? (
|
||||
<Loader2 className="h-3.5 w-3.5 animate-spin" />
|
||||
) : (
|
||||
<>
|
||||
<RefreshCw className="h-3.5 w-3.5 mr-1.5" />
|
||||
Check again
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
<SettingRow
|
||||
title="Restore with recovery phrase"
|
||||
description="The 12 words you wrote down when you first enabled backup."
|
||||
action={
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
className="w-72"
|
||||
onChange={(e) => setRestoreInput(e.target.value)}
|
||||
placeholder="correct horse battery staple …"
|
||||
value={restoreInput}
|
||||
/>
|
||||
<Button
|
||||
disabled={restore.isPending || restoreInput.trim().split(/\s+/).length < 12}
|
||||
onClick={() => restore.mutate(restoreInput)}
|
||||
size="sm"
|
||||
>
|
||||
{restore.isPending ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : 'Restore'}
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
{state === 'ready' && (
|
||||
<SettingRow
|
||||
title="Encrypted backup"
|
||||
description="On — content is encrypted on this device before upload. The server can never read it."
|
||||
action={
|
||||
<Button disabled={run.isPending} onClick={() => run.mutate()} size="sm">
|
||||
{run.isPending ? (
|
||||
<>
|
||||
<Loader2 className="h-3.5 w-3.5 mr-1.5 animate-spin" />
|
||||
Syncing…
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<RefreshCw className="h-3.5 w-3.5 mr-1.5" />
|
||||
Sync now
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
<RecoveryPhraseDialog
|
||||
copied={phraseCopied}
|
||||
onConfirm={() => setPhrase(null)}
|
||||
onCopy={() => {
|
||||
if (phrase) {
|
||||
navigator.clipboard?.writeText(phrase);
|
||||
setPhraseCopied(true);
|
||||
}
|
||||
}}
|
||||
phrase={phrase}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// The one moment the recovery phrase exists outside the backend. Deliberately
|
||||
// hard to dismiss: no overlay/escape close, only the explicit confirmation.
|
||||
function RecoveryPhraseDialog({
|
||||
phrase,
|
||||
copied,
|
||||
onCopy,
|
||||
onConfirm,
|
||||
}: {
|
||||
phrase: string | null;
|
||||
copied: boolean;
|
||||
onCopy: () => void;
|
||||
onConfirm: () => void;
|
||||
}) {
|
||||
return (
|
||||
<Dialog onOpenChange={() => {}} open={phrase !== null}>
|
||||
<DialogContent className="max-w-lg [&>button]:hidden">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Write down your recovery phrase</DialogTitle>
|
||||
<DialogDescription>
|
||||
These 12 words are the only way to restore your backup if you lose all your devices.
|
||||
They are never sent to the server and will not be shown again.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="grid grid-cols-3 gap-2 py-2">
|
||||
{(phrase ?? '').split(' ').map((word, index) => (
|
||||
<div
|
||||
className="rounded-md border border-border bg-muted/40 px-2.5 py-1.5 text-sm"
|
||||
// Position is the identity here — BIP39 phrases can repeat words.
|
||||
// biome-ignore lint/suspicious/noArrayIndexKey: static list, never reordered
|
||||
key={index}
|
||||
>
|
||||
<span className="mr-1.5 text-muted-foreground tabular-nums">{index + 1}.</span>
|
||||
{word}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<DialogFooter className="gap-2 sm:justify-between">
|
||||
<Button onClick={onCopy} size="sm" type="button" variant="outline">
|
||||
<Copy className="h-3.5 w-3.5 mr-1.5" />
|
||||
{copied ? 'Copied' : 'Copy'}
|
||||
</Button>
|
||||
<Button onClick={onConfirm} size="sm" type="button">
|
||||
I've written it down
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Progress } from '@/components/ui/progress';
|
||||
import { apiClient } from '@/lib/api/client';
|
||||
import type { CudaDownloadProgress, RocmDownloadProgress, HealthResponse } from '@/lib/api/types';
|
||||
import type { CudaDownloadProgress, HealthResponse } from '@/lib/api/types';
|
||||
import { useServerHealth } from '@/lib/hooks/useServer';
|
||||
import { usePlatform } from '@/platform/PlatformContext';
|
||||
import { useServerStore } from '@/stores/serverStore';
|
||||
@@ -50,10 +50,7 @@ function GpuInfoCard({ health }: { health: HealthResponse }) {
|
||||
: null;
|
||||
const gpuBackend = hasGpu ? health.gpu_type!.replace(/\s*\(.+\)$/, '') : null;
|
||||
const isApple = gpuBackend === 'MPS' || gpuBackend === 'Metal';
|
||||
const showBackendVariant =
|
||||
health.backend_variant &&
|
||||
health.backend_variant !== 'cpu' &&
|
||||
health.backend_variant.toLowerCase() !== gpuBackend?.toLowerCase();
|
||||
const showBackendVariant = health.backend_variant && health.backend_variant !== 'cpu';
|
||||
|
||||
return (
|
||||
<div className="rounded-lg border border-border/60 p-4">
|
||||
@@ -118,14 +115,10 @@ export function GpuPage() {
|
||||
|
||||
const [restartPhase, setRestartPhase] = useState<RestartPhase>('idle');
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [cudaStreaming, setCudaStreaming] = useState(false);
|
||||
const [rocmStreaming, setRocmStreaming] = useState(false);
|
||||
const [downloadProgress, setDownloadProgress] = useState<CudaDownloadProgress | null>(null);
|
||||
const [rocmDownloadProgress, setRocmDownloadProgress] = useState<RocmDownloadProgress | null>(
|
||||
null,
|
||||
);
|
||||
const healthPollRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
||||
|
||||
// Hold the latest `t` in a ref so the CUDA progress SSE effect below doesn't
|
||||
// tear down and reconnect the EventSource every time the language changes.
|
||||
const tRef = useRef(t);
|
||||
useEffect(() => {
|
||||
tRef.current = t;
|
||||
@@ -143,27 +136,9 @@ export function GpuPage() {
|
||||
enabled: !!health,
|
||||
});
|
||||
|
||||
const {
|
||||
data: rocmStatus,
|
||||
isLoading: _rocmStatusLoading,
|
||||
refetch: refetchRocmStatus,
|
||||
} = useQuery({
|
||||
queryKey: ['rocm-status', serverUrl],
|
||||
queryFn: () => apiClient.getRocmStatus(),
|
||||
refetchInterval: (query) => (query.state.status === 'pending' ? false : 10000),
|
||||
retry: 1,
|
||||
enabled: !!health,
|
||||
});
|
||||
|
||||
const isCurrentlyCuda = health?.backend_variant === 'cuda';
|
||||
const isCurrentlyRocm = health?.backend_variant === 'rocm';
|
||||
const cudaAvailable = cudaStatus?.available ?? false;
|
||||
const cudaDownloading = cudaStatus?.downloading ?? false;
|
||||
const rocmAvailable = rocmStatus?.available ?? false;
|
||||
const rocmDownloading = rocmStatus?.downloading ?? false;
|
||||
// The ROCm backend only applies to AMD GPUs on Windows. Show the section when
|
||||
// the backend detects applicable hardware, or it is already downloaded/active.
|
||||
const supportsRocm = (health?.supports_rocm ?? false) || rocmAvailable || isCurrentlyRocm;
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
@@ -175,7 +150,7 @@ export function GpuPage() {
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if ((!cudaDownloading && !cudaStreaming) || !serverUrl) return;
|
||||
if (!cudaDownloading || !serverUrl) return;
|
||||
|
||||
const eventSource = new EventSource(`${serverUrl}/backend/cuda-progress`);
|
||||
|
||||
@@ -187,13 +162,11 @@ export function GpuPage() {
|
||||
if (data.status === 'complete') {
|
||||
eventSource.close();
|
||||
setDownloadProgress(null);
|
||||
setCudaStreaming(false);
|
||||
refetchCudaStatus();
|
||||
} else if (data.status === 'error') {
|
||||
eventSource.close();
|
||||
setError(data.error || tRef.current('settings.gpu.errors.downloadFailed'));
|
||||
setDownloadProgress(null);
|
||||
setCudaStreaming(false);
|
||||
refetchCudaStatus();
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -203,50 +176,12 @@ export function GpuPage() {
|
||||
|
||||
eventSource.onerror = () => {
|
||||
eventSource.close();
|
||||
setCudaStreaming(false);
|
||||
};
|
||||
|
||||
return () => {
|
||||
eventSource.close();
|
||||
};
|
||||
}, [cudaDownloading, cudaStreaming, serverUrl, refetchCudaStatus]);
|
||||
|
||||
useEffect(() => {
|
||||
if ((!rocmDownloading && !rocmStreaming) || !serverUrl) return;
|
||||
|
||||
const eventSource = new EventSource(`${serverUrl}/backend/rocm-progress`);
|
||||
|
||||
eventSource.onmessage = (event) => {
|
||||
try {
|
||||
const data = JSON.parse(event.data) as RocmDownloadProgress;
|
||||
setRocmDownloadProgress(data);
|
||||
|
||||
if (data.status === 'complete') {
|
||||
eventSource.close();
|
||||
setRocmDownloadProgress(null);
|
||||
setRocmStreaming(false);
|
||||
refetchRocmStatus();
|
||||
} else if (data.status === 'error') {
|
||||
eventSource.close();
|
||||
setError(data.error || tRef.current('settings.gpu.errors.downloadFailed'));
|
||||
setRocmDownloadProgress(null);
|
||||
setRocmStreaming(false);
|
||||
refetchRocmStatus();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error parsing ROCm progress event:', e);
|
||||
}
|
||||
};
|
||||
|
||||
eventSource.onerror = () => {
|
||||
eventSource.close();
|
||||
setRocmStreaming(false);
|
||||
};
|
||||
|
||||
return () => {
|
||||
eventSource.close();
|
||||
};
|
||||
}, [rocmDownloading, rocmStreaming, serverUrl, refetchRocmStatus]);
|
||||
}, [cudaDownloading, serverUrl, refetchCudaStatus]);
|
||||
|
||||
const clearHealthPolling = useCallback(() => {
|
||||
if (healthPollRef.current) {
|
||||
@@ -289,11 +224,10 @@ export function GpuPage() {
|
||||
[platform, startHealthPolling, clearHealthPolling],
|
||||
);
|
||||
|
||||
const handleDownloadCuda = async () => {
|
||||
const handleDownload = async () => {
|
||||
setError(null);
|
||||
try {
|
||||
await apiClient.downloadCudaBackend();
|
||||
setCudaStreaming(true);
|
||||
refetchCudaStatus();
|
||||
} catch (e: unknown) {
|
||||
const msg = e instanceof Error ? e.message : t('settings.gpu.errors.downloadStart');
|
||||
@@ -305,64 +239,28 @@ export function GpuPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleDownloadRocm = async () => {
|
||||
const handleRestart = async () => {
|
||||
setError(null);
|
||||
try {
|
||||
await apiClient.downloadRocmBackend();
|
||||
setRocmStreaming(true);
|
||||
refetchRocmStatus();
|
||||
await restartServerWithPolling(t('settings.gpu.errors.restartFailed'));
|
||||
} catch (e: unknown) {
|
||||
const msg = e instanceof Error ? e.message : t('settings.gpu.errors.downloadStart');
|
||||
if (msg.includes('already downloaded')) {
|
||||
refetchRocmStatus();
|
||||
} else {
|
||||
setError(msg);
|
||||
}
|
||||
setError(e instanceof Error ? e.message : t('settings.gpu.errors.restartFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const handleSwitchToCpu = async () => {
|
||||
setError(null);
|
||||
setRestartPhase('stopping');
|
||||
try {
|
||||
await platform.lifecycle.setBackendOverride('cpu');
|
||||
await apiClient.deleteCudaBackend();
|
||||
await restartServerWithPolling(t('settings.gpu.errors.switchCpu'));
|
||||
} catch (e: unknown) {
|
||||
setRestartPhase('idle');
|
||||
setError(e instanceof Error ? e.message : t('settings.gpu.errors.switchCpu'));
|
||||
refetchCudaStatus();
|
||||
refetchRocmStatus();
|
||||
}
|
||||
};
|
||||
|
||||
const handleSwitchToCuda = async () => {
|
||||
setError(null);
|
||||
setRestartPhase('stopping');
|
||||
try {
|
||||
await platform.lifecycle.setBackendOverride('cuda');
|
||||
await restartServerWithPolling(t('settings.gpu.errors.restartFailed'));
|
||||
} catch (e: unknown) {
|
||||
setRestartPhase('idle');
|
||||
setError(e instanceof Error ? e.message : t('settings.gpu.errors.restartFailed'));
|
||||
refetchCudaStatus();
|
||||
}
|
||||
};
|
||||
|
||||
const handleSwitchToRocm = async () => {
|
||||
setError(null);
|
||||
setRestartPhase('stopping');
|
||||
try {
|
||||
await platform.lifecycle.setBackendOverride('rocm');
|
||||
await restartServerWithPolling(t('settings.gpu.errors.restartFailed'));
|
||||
} catch (e: unknown) {
|
||||
setRestartPhase('idle');
|
||||
setError(e instanceof Error ? e.message : t('settings.gpu.errors.restartFailed'));
|
||||
refetchRocmStatus();
|
||||
}
|
||||
};
|
||||
|
||||
const handleDeleteCuda = async () => {
|
||||
const handleDelete = async () => {
|
||||
setError(null);
|
||||
try {
|
||||
await apiClient.deleteCudaBackend();
|
||||
@@ -372,16 +270,6 @@ export function GpuPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleDeleteRocm = async () => {
|
||||
setError(null);
|
||||
try {
|
||||
await apiClient.deleteRocmBackend();
|
||||
refetchRocmStatus();
|
||||
} catch (e: unknown) {
|
||||
setError(e instanceof Error ? e.message : t('settings.gpu.errors.deleteRocm'));
|
||||
}
|
||||
};
|
||||
|
||||
const formatBytes = (bytes: number): string => {
|
||||
if (bytes === 0) return '0 B';
|
||||
const k = 1024;
|
||||
@@ -395,7 +283,6 @@ export function GpuPage() {
|
||||
const hasNativeGpu =
|
||||
health.gpu_available &&
|
||||
!isCurrentlyCuda &&
|
||||
!isCurrentlyRocm &&
|
||||
health.gpu_type &&
|
||||
!health.gpu_type.includes('CUDA');
|
||||
|
||||
@@ -403,188 +290,33 @@ export function GpuPage() {
|
||||
<div className="space-y-8 max-w-2xl">
|
||||
<GpuInfoCard health={health} />
|
||||
|
||||
{!hasNativeGpu && !isCurrentlyCuda && !isCurrentlyRocm && (
|
||||
<>
|
||||
<SettingSection
|
||||
title={t('settings.gpu.cuda.title')}
|
||||
description={t('settings.gpu.cuda.description')}
|
||||
>
|
||||
{cudaDownloading && downloadProgress && (
|
||||
<SettingRow title={t('settings.gpu.cuda.downloading')}>
|
||||
<div className="space-y-1.5">
|
||||
<Progress value={downloadProgress.progress} className="h-2" />
|
||||
<div className="flex items-center justify-between text-xs text-muted-foreground">
|
||||
<span>
|
||||
{downloadProgress.filename ||
|
||||
(cudaAvailable
|
||||
? t('settings.gpu.cuda.updating')
|
||||
: t('settings.gpu.cuda.downloadingShort'))}
|
||||
</span>
|
||||
<span>
|
||||
{downloadProgress.total > 0
|
||||
? `${formatBytes(downloadProgress.current)} / ${formatBytes(downloadProgress.total)}`
|
||||
: `${downloadProgress.progress.toFixed(1)}%`}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</SettingRow>
|
||||
)}
|
||||
|
||||
{restartPhase !== 'idle' && (
|
||||
<SettingRow
|
||||
title={
|
||||
restartPhase === 'ready'
|
||||
? t('settings.gpu.restart.ready')
|
||||
: restartPhase === 'waiting'
|
||||
? t('settings.gpu.restart.waiting')
|
||||
: t('settings.gpu.restart.stopping')
|
||||
}
|
||||
action={<Loader2 className="h-4 w-4 animate-spin text-muted-foreground" />}
|
||||
/>
|
||||
)}
|
||||
|
||||
{error && (
|
||||
<SettingRow title={t('common.error')}>
|
||||
<div className="flex items-center gap-2 text-sm text-destructive">
|
||||
<AlertCircle className="h-4 w-4 shrink-0" />
|
||||
<span>{error}</span>
|
||||
</div>
|
||||
</SettingRow>
|
||||
)}
|
||||
|
||||
{restartPhase === 'idle' && !cudaDownloading && (
|
||||
<>
|
||||
{!cudaAvailable && !isCurrentlyCuda && (
|
||||
<SettingRow
|
||||
title={t('settings.gpu.download.title')}
|
||||
description={t('settings.gpu.download.description')}
|
||||
action={
|
||||
<Button onClick={handleDownloadCuda} size="sm">
|
||||
<Download className="h-3.5 w-3.5 mr-1.5" />
|
||||
{t('settings.gpu.download.button')}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
{cudaAvailable && !isCurrentlyCuda && platform.metadata.isTauri && (
|
||||
<SettingRow
|
||||
title={t('settings.gpu.switchToCuda.title')}
|
||||
description={t('settings.gpu.switchToCuda.description')}
|
||||
action={
|
||||
<Button onClick={handleSwitchToCuda} size="sm">
|
||||
<RotateCw className="h-3.5 w-3.5 mr-1.5" />
|
||||
{t('settings.gpu.switchToCuda.button')}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
{cudaAvailable && !isCurrentlyCuda && (
|
||||
<SettingRow
|
||||
title={t('settings.gpu.remove.title')}
|
||||
description={t('settings.gpu.remove.description')}
|
||||
action={
|
||||
<Button
|
||||
onClick={handleDeleteCuda}
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="text-muted-foreground hover:text-destructive"
|
||||
>
|
||||
<Trash2 className="h-3.5 w-3.5 mr-1.5" />
|
||||
{t('settings.gpu.remove.button')}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</SettingSection>
|
||||
|
||||
{supportsRocm && (
|
||||
<SettingSection
|
||||
title={t('settings.gpu.rocm.title')}
|
||||
description={t('settings.gpu.rocm.description')}
|
||||
>
|
||||
{rocmDownloading && rocmDownloadProgress && (
|
||||
<SettingRow title={t('settings.gpu.rocm.downloading')}>
|
||||
<div className="space-y-1.5">
|
||||
<Progress value={rocmDownloadProgress.progress} className="h-2" />
|
||||
<div className="flex items-center justify-between text-xs text-muted-foreground">
|
||||
<span>
|
||||
{rocmDownloadProgress.filename ||
|
||||
(rocmAvailable
|
||||
? t('settings.gpu.rocm.updating')
|
||||
: t('settings.gpu.rocm.downloadingShort'))}
|
||||
</span>
|
||||
<span>
|
||||
{rocmDownloadProgress.total > 0
|
||||
? `${formatBytes(rocmDownloadProgress.current)} / ${formatBytes(rocmDownloadProgress.total)}`
|
||||
: `${rocmDownloadProgress.progress.toFixed(1)}%`}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</SettingRow>
|
||||
)}
|
||||
|
||||
{restartPhase === 'idle' && !rocmDownloading && (
|
||||
<>
|
||||
{!rocmAvailable && !isCurrentlyRocm && (
|
||||
<SettingRow
|
||||
title={t('settings.gpu.downloadRocm.title')}
|
||||
description={t('settings.gpu.downloadRocm.description')}
|
||||
action={
|
||||
<Button onClick={handleDownloadRocm} size="sm">
|
||||
<Download className="h-3.5 w-3.5 mr-1.5" />
|
||||
{t('settings.gpu.downloadRocm.button')}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
{rocmAvailable && !isCurrentlyRocm && platform.metadata.isTauri && (
|
||||
<SettingRow
|
||||
title={t('settings.gpu.switchToRocm.title')}
|
||||
description={t('settings.gpu.switchToRocm.description')}
|
||||
action={
|
||||
<Button onClick={handleSwitchToRocm} size="sm">
|
||||
<RotateCw className="h-3.5 w-3.5 mr-1.5" />
|
||||
{t('settings.gpu.switchToRocm.button')}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
{rocmAvailable && !isCurrentlyRocm && (
|
||||
<SettingRow
|
||||
title={t('settings.gpu.removeRocm.title')}
|
||||
description={t('settings.gpu.removeRocm.description')}
|
||||
action={
|
||||
<Button
|
||||
onClick={handleDeleteRocm}
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="text-muted-foreground hover:text-destructive"
|
||||
>
|
||||
<Trash2 className="h-3.5 w-3.5 mr-1.5" />
|
||||
{t('settings.gpu.removeRocm.button')}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</SettingSection>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
{(isCurrentlyCuda || isCurrentlyRocm) && platform.metadata.isTauri && (
|
||||
{!hasNativeGpu && !isCurrentlyCuda && (
|
||||
<SettingSection
|
||||
title={isCurrentlyCuda ? t('settings.gpu.cuda.activeTitle') : t('settings.gpu.rocm.activeTitle')}
|
||||
description={t('settings.gpu.activeBackend.description')}
|
||||
title={t('settings.gpu.cuda.title')}
|
||||
description={t('settings.gpu.cuda.description')}
|
||||
>
|
||||
{restartPhase !== 'idle' ? (
|
||||
{cudaDownloading && downloadProgress && (
|
||||
<SettingRow title={t('settings.gpu.cuda.downloading')}>
|
||||
<div className="space-y-1.5">
|
||||
<Progress value={downloadProgress.progress} className="h-2" />
|
||||
<div className="flex items-center justify-between text-xs text-muted-foreground">
|
||||
<span>
|
||||
{downloadProgress.filename ||
|
||||
(cudaAvailable
|
||||
? t('settings.gpu.cuda.updating')
|
||||
: t('settings.gpu.cuda.downloadingShort'))}
|
||||
</span>
|
||||
<span>
|
||||
{downloadProgress.total > 0
|
||||
? `${formatBytes(downloadProgress.current)} / ${formatBytes(downloadProgress.total)}`
|
||||
: `${downloadProgress.progress.toFixed(1)}%`}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</SettingRow>
|
||||
)}
|
||||
|
||||
{restartPhase !== 'idle' && (
|
||||
<SettingRow
|
||||
title={
|
||||
restartPhase === 'ready'
|
||||
@@ -595,18 +327,8 @@ export function GpuPage() {
|
||||
}
|
||||
action={<Loader2 className="h-4 w-4 animate-spin text-muted-foreground" />}
|
||||
/>
|
||||
) : (
|
||||
<SettingRow
|
||||
title={t('settings.gpu.switchToCpu.title')}
|
||||
description={t('settings.gpu.switchToCpu.description')}
|
||||
action={
|
||||
<Button onClick={handleSwitchToCpu} variant="outline" size="sm">
|
||||
<RotateCw className="h-3.5 w-3.5 mr-1.5" />
|
||||
{t('settings.gpu.switchToCpu.button')}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
{error && (
|
||||
<SettingRow title={t('common.error')}>
|
||||
<div className="flex items-center gap-2 text-sm text-destructive">
|
||||
@@ -615,6 +337,67 @@ export function GpuPage() {
|
||||
</div>
|
||||
</SettingRow>
|
||||
)}
|
||||
|
||||
{restartPhase === 'idle' && !cudaDownloading && (
|
||||
<>
|
||||
{!cudaAvailable && !isCurrentlyCuda && (
|
||||
<SettingRow
|
||||
title={t('settings.gpu.download.title')}
|
||||
description={t('settings.gpu.download.description')}
|
||||
action={
|
||||
<Button onClick={handleDownload} size="sm">
|
||||
<Download className="h-3.5 w-3.5 mr-1.5" />
|
||||
{t('settings.gpu.download.button')}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
{cudaAvailable && !isCurrentlyCuda && platform.metadata.isTauri && (
|
||||
<SettingRow
|
||||
title={t('settings.gpu.switchToCuda.title')}
|
||||
description={t('settings.gpu.switchToCuda.description')}
|
||||
action={
|
||||
<Button onClick={handleRestart} size="sm">
|
||||
<RotateCw className="h-3.5 w-3.5 mr-1.5" />
|
||||
{t('settings.gpu.switchToCuda.button')}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
{isCurrentlyCuda && platform.metadata.isTauri && (
|
||||
<SettingRow
|
||||
title={t('settings.gpu.switchToCpu.title')}
|
||||
description={t('settings.gpu.switchToCpu.description')}
|
||||
action={
|
||||
<Button onClick={handleSwitchToCpu} variant="outline" size="sm">
|
||||
<RotateCw className="h-3.5 w-3.5 mr-1.5" />
|
||||
{t('settings.gpu.switchToCpu.button')}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
{cudaAvailable && !isCurrentlyCuda && (
|
||||
<SettingRow
|
||||
title={t('settings.gpu.remove.title')}
|
||||
description={t('settings.gpu.remove.description')}
|
||||
action={
|
||||
<Button
|
||||
onClick={handleDelete}
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="text-muted-foreground "
|
||||
>
|
||||
<Trash2 className="h-3.5 w-3.5 mr-1.5" />
|
||||
{t('settings.gpu.remove.button')}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</SettingSection>
|
||||
)}
|
||||
|
||||
|
||||
@@ -2,25 +2,15 @@ import i18n from 'i18next';
|
||||
import LanguageDetector from 'i18next-browser-languagedetector';
|
||||
import { initReactI18next } from 'react-i18next';
|
||||
import en from './locales/en/translation.json';
|
||||
import es from './locales/es/translation.json';
|
||||
import fr from './locales/fr/translation.json';
|
||||
import it from './locales/it/translation.json';
|
||||
import ja from './locales/ja/translation.json';
|
||||
import ko from './locales/ko/translation.json';
|
||||
import ptBR from './locales/pt-BR/translation.json';
|
||||
import zhCN from './locales/zh-CN/translation.json';
|
||||
import zhTW from './locales/zh-TW/translation.json';
|
||||
|
||||
export const SUPPORTED_LANGUAGES = [
|
||||
{ code: 'en', label: 'English' },
|
||||
{ code: 'es', label: 'Español' },
|
||||
{ code: 'pt-BR', label: 'Português (Brasil)' },
|
||||
{ code: 'ja', label: '日本語' },
|
||||
{ code: 'ko', label: '한국어' },
|
||||
{ code: 'zh-CN', label: '简体中文' },
|
||||
{ code: 'zh-TW', label: '繁體中文' },
|
||||
{ code: 'fr', label: 'Français' },
|
||||
{ code: 'it', label: 'Italiano' },
|
||||
] as const;
|
||||
|
||||
export type LanguageCode = (typeof SUPPORTED_LANGUAGES)[number]['code'];
|
||||
@@ -31,14 +21,9 @@ i18n
|
||||
.init({
|
||||
resources: {
|
||||
en: { translation: en },
|
||||
es: { translation: es },
|
||||
'pt-BR': { translation: ptBR },
|
||||
ja: { translation: ja },
|
||||
ko: { translation: ko },
|
||||
'zh-CN': { translation: zhCN },
|
||||
'zh-TW': { translation: zhTW },
|
||||
fr: { translation: fr },
|
||||
it: { translation: it },
|
||||
},
|
||||
fallbackLng: 'en',
|
||||
supportedLngs: SUPPORTED_LANGUAGES.map((l) => l.code),
|
||||
|
||||
@@ -760,13 +760,8 @@
|
||||
}
|
||||
},
|
||||
"general": {
|
||||
"docs": {
|
||||
"title": "Read the Docs"
|
||||
},
|
||||
"discord": {
|
||||
"title": "Join the Discord",
|
||||
"subtitle": "Get help & share voices"
|
||||
},
|
||||
"docs": { "title": "Read the Docs" },
|
||||
"discord": { "title": "Join the Discord", "subtitle": "Get help & share voices" },
|
||||
"serverUrl": {
|
||||
"title": "Server URL",
|
||||
"description": "The address of your voicebox backend server.",
|
||||
@@ -1096,15 +1091,11 @@
|
||||
"active": "Active",
|
||||
"cuda": {
|
||||
"title": "CUDA Backend",
|
||||
"activeTitle": "CUDA Backend Active",
|
||||
"description": "NVIDIA GPU acceleration via a downloadable CUDA backend.",
|
||||
"downloading": "Downloading CUDA backend…",
|
||||
"downloadingShort": "Downloading…",
|
||||
"updating": "Updating…"
|
||||
},
|
||||
"activeBackend": {
|
||||
"description": "GPU acceleration is currently enabled."
|
||||
},
|
||||
"restart": {
|
||||
"ready": "Server restarted successfully",
|
||||
"waiting": "Restarting server…",
|
||||
@@ -1122,9 +1113,10 @@
|
||||
},
|
||||
"switchToCpu": {
|
||||
"title": "Switch to CPU backend",
|
||||
"description": "Disable GPU acceleration. You can re-download the GPU backend later.",
|
||||
"description": "Disable GPU acceleration. You can re-download CUDA later.",
|
||||
"button": "Switch"
|
||||
}, "remove": {
|
||||
},
|
||||
"remove": {
|
||||
"title": "Remove CUDA backend",
|
||||
"description": "Delete the downloaded CUDA binary to free disk space.",
|
||||
"button": "Remove"
|
||||
@@ -1134,33 +1126,9 @@
|
||||
"downloadStart": "Failed to start download",
|
||||
"restartFailed": "Restart failed",
|
||||
"switchCpu": "Failed to switch to CPU",
|
||||
"deleteCuda": "Failed to delete CUDA backend",
|
||||
"deleteRocm": "Failed to delete ROCm backend"
|
||||
"deleteCuda": "Failed to delete CUDA backend"
|
||||
},
|
||||
"footer": "Voicebox automatically detects and uses the best available GPU on your system. On Apple Silicon Macs, the MLX backend runs natively on the Neural Engine and GPU via Metal Performance Shaders (MPS), with no additional setup required. On Windows, you can download optional CUDA (NVIDIA) or ROCm (AMD) backends for hardware-accelerated inference. Intel XPU and DirectML are also supported where available through PyTorch. When no GPU is detected, Voicebox falls back to CPU — all engines still work, just slower.",
|
||||
"rocm": {
|
||||
"title": "AMD ROCm Backend",
|
||||
"activeTitle": "ROCm Backend Active",
|
||||
"description": "AMD GPU acceleration via a downloadable ROCm backend.",
|
||||
"downloading": "Downloading ROCm backend…",
|
||||
"downloadingShort": "Downloading…",
|
||||
"updating": "Updating…"
|
||||
},
|
||||
"downloadRocm": {
|
||||
"title": "Download AMD ROCm backend",
|
||||
"description": "~2-3 GB download. Requires an AMD Radeon GPU with ROCm support.",
|
||||
"button": "Download"
|
||||
},
|
||||
"switchToRocm": {
|
||||
"title": "Switch to ROCm backend",
|
||||
"description": "ROCm backend is downloaded and ready. Restart to enable.",
|
||||
"button": "Restart"
|
||||
},
|
||||
"removeRocm": {
|
||||
"title": "Remove ROCm backend",
|
||||
"description": "Delete the downloaded ROCm binary to free disk space.",
|
||||
"button": "Remove"
|
||||
}
|
||||
"footer": "Voicebox automatically detects and uses the best available GPU on your system. On Apple Silicon Macs, the MLX backend runs natively on the Neural Engine and GPU via Metal Performance Shaders (MPS), with no additional setup required. On Windows and Linux with NVIDIA GPUs, you can download an optional CUDA backend for hardware-accelerated inference. AMD ROCm, Intel XPU, and DirectML are also supported where available through PyTorch. When no GPU is detected, Voicebox falls back to CPU — all engines still work, just slower."
|
||||
},
|
||||
"logs": {
|
||||
"title": "Server Logs",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+29
-18
@@ -20,7 +20,6 @@ import type {
|
||||
PresetVoice,
|
||||
PersonalityTextResponse,
|
||||
ProfileSampleResponse,
|
||||
RocmStatus,
|
||||
StoryCreate,
|
||||
StoryDetailResponse,
|
||||
StoryItemBatchUpdate,
|
||||
@@ -53,6 +52,9 @@ import type {
|
||||
MCPClientBindingUpsert,
|
||||
CloudLoginStartResponse,
|
||||
CloudStatus,
|
||||
CloudSyncRunResponse,
|
||||
CloudSyncSetupResponse,
|
||||
CloudSyncStatus,
|
||||
} from './types';
|
||||
|
||||
function formatErrorDetail(detail: unknown, fallback: string): string {
|
||||
@@ -696,23 +698,6 @@ class ApiClient {
|
||||
});
|
||||
}
|
||||
|
||||
// ROCm Backend Management
|
||||
async getRocmStatus(): Promise<RocmStatus> {
|
||||
return this.request<RocmStatus>('/backend/rocm-status');
|
||||
}
|
||||
|
||||
async downloadRocmBackend(): Promise<{ message: string; progress_key: string }> {
|
||||
return this.request<{ message: string; progress_key: string }>('/backend/download-rocm', {
|
||||
method: 'POST',
|
||||
});
|
||||
}
|
||||
|
||||
async deleteRocmBackend(): Promise<{ message: string }> {
|
||||
return this.request<{ message: string }>('/backend/rocm', {
|
||||
method: 'DELETE',
|
||||
});
|
||||
}
|
||||
|
||||
// Stories
|
||||
async listStories(): Promise<StoryResponse[]> {
|
||||
return this.request<StoryResponse[]>('/stories');
|
||||
@@ -955,6 +940,32 @@ class ApiClient {
|
||||
async disconnectCloud(): Promise<CloudStatus> {
|
||||
return this.request<CloudStatus>('/cloud/disconnect', { method: 'POST' });
|
||||
}
|
||||
|
||||
// Encrypted backup & sync. setupCloudSync registers this install as an
|
||||
// encryption device — when it returns a recovery_phrase, this device just
|
||||
// minted the account key and the phrase must be force-displayed once.
|
||||
async getCloudSyncStatus(): Promise<CloudSyncStatus> {
|
||||
return this.request<CloudSyncStatus>('/cloud/sync/status');
|
||||
}
|
||||
|
||||
async setupCloudSync(): Promise<CloudSyncSetupResponse> {
|
||||
return this.request<CloudSyncSetupResponse>('/cloud/sync/setup', { method: 'POST' });
|
||||
}
|
||||
|
||||
async restoreCloudSync(phrase: string): Promise<CloudSyncStatus> {
|
||||
return this.request<CloudSyncStatus>('/cloud/sync/restore', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ phrase }),
|
||||
});
|
||||
}
|
||||
|
||||
async adoptCloudSync(): Promise<CloudSyncStatus> {
|
||||
return this.request<CloudSyncStatus>('/cloud/sync/adopt', { method: 'POST' });
|
||||
}
|
||||
|
||||
async runCloudSync(): Promise<CloudSyncRunResponse> {
|
||||
return this.request<CloudSyncRunResponse>('/cloud/sync/run', { method: 'POST' });
|
||||
}
|
||||
}
|
||||
|
||||
export const apiClient = new ApiClient();
|
||||
|
||||
@@ -9,7 +9,7 @@ export type ModelStatus = {
|
||||
model_name: string;
|
||||
display_name: string;
|
||||
downloaded: boolean;
|
||||
downloading?: boolean; // True if download is in progress
|
||||
downloading?: boolean; // True if download is in progress
|
||||
size_mb?: number | null;
|
||||
loaded?: boolean;
|
||||
};
|
||||
|
||||
+26
-27
@@ -269,8 +269,7 @@ export interface HealthResponse {
|
||||
gpu_type?: string;
|
||||
vram_used_mb?: number;
|
||||
backend_type?: string;
|
||||
backend_variant?: string; // "cpu", "cuda", or "rocm"
|
||||
supports_rocm?: boolean; // AMD GPU on Windows — the ROCm backend is applicable
|
||||
backend_variant?: string; // "cpu" or "cuda"
|
||||
}
|
||||
|
||||
export interface CudaDownloadProgress {
|
||||
@@ -287,34 +286,11 @@ export interface CudaDownloadProgress {
|
||||
export interface CudaStatus {
|
||||
available: boolean; // CUDA binary exists on disk
|
||||
active: boolean; // Currently running the CUDA binary
|
||||
binary_path: string | null;
|
||||
cuda_libs_version: string | null;
|
||||
download_supported: boolean; // Platform has a matching release asset
|
||||
unsupported_reason: string | null;
|
||||
binary_path?: string;
|
||||
downloading: boolean; // Download in progress
|
||||
download_progress?: CudaDownloadProgress;
|
||||
}
|
||||
|
||||
export interface RocmDownloadProgress {
|
||||
model_name: string;
|
||||
current: number;
|
||||
total: number;
|
||||
progress: number;
|
||||
filename?: string;
|
||||
status: 'downloading' | 'extracting' | 'complete' | 'error';
|
||||
timestamp: string;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export interface RocmStatus {
|
||||
available: boolean; // ROCm binary exists on disk
|
||||
active: boolean; // Currently running the ROCm binary
|
||||
binary_path?: string;
|
||||
rocm_libs_version?: string;
|
||||
downloading: boolean; // Download in progress
|
||||
download_progress?: RocmDownloadProgress;
|
||||
}
|
||||
|
||||
export interface ModelProgress {
|
||||
model_name: string;
|
||||
current: number;
|
||||
@@ -558,5 +534,28 @@ export interface CloudStatus {
|
||||
account_user_id: string | null;
|
||||
key_prefix: string | null;
|
||||
connected_at: string | null;
|
||||
dashboard_url: string;
|
||||
}
|
||||
|
||||
export type CloudSyncState = 'unregistered' | 'awaiting_provision' | 'ready';
|
||||
|
||||
export interface CloudSyncStatus {
|
||||
status: CloudSyncState;
|
||||
device_id: string | null;
|
||||
sync_cursor: number;
|
||||
}
|
||||
|
||||
export interface CloudSyncSetupResponse {
|
||||
status: CloudSyncState;
|
||||
device_id: string | null;
|
||||
/** Present exactly once, when this device minted the account's key
|
||||
* material. Must be force-displayed and never persisted. */
|
||||
recovery_phrase: string | null;
|
||||
}
|
||||
|
||||
export interface CloudSyncRunResponse {
|
||||
pushed: number;
|
||||
pushed_deletes: number;
|
||||
pulled: number;
|
||||
pulled_deletes: number;
|
||||
cursor: number;
|
||||
}
|
||||
|
||||
@@ -47,14 +47,12 @@ export function useExportGeneration() {
|
||||
mutationFn: async ({ generationId, text }: { generationId: string; text: string }) => {
|
||||
const blob = await apiClient.exportGeneration(generationId);
|
||||
|
||||
// Create safe filename from text. Append a short id so exports of
|
||||
// similarly-worded generations don't collide on the same filename
|
||||
// (the first 30 chars are frequently identical).
|
||||
// Create safe filename from text
|
||||
const safeText = text
|
||||
.substring(0, 30)
|
||||
.replace(/[^a-z0-9]/gi, '-')
|
||||
.toLowerCase();
|
||||
const filename = `generation-${safeText}-${generationId.substring(0, 8)}.voicebox.zip`;
|
||||
const filename = `generation-${safeText}.voicebox.zip`;
|
||||
|
||||
await platform.filesystem.saveFile(filename, blob, [
|
||||
{
|
||||
@@ -75,14 +73,12 @@ export function useExportGenerationAudio() {
|
||||
mutationFn: async ({ generationId, text }: { generationId: string; text: string }) => {
|
||||
const blob = await apiClient.exportGenerationAudio(generationId);
|
||||
|
||||
// Create safe filename from text. Append a short id so exports of
|
||||
// similarly-worded generations don't collide on the same filename
|
||||
// (the first 30 chars are frequently identical).
|
||||
// Create safe filename from text
|
||||
const safeText = text
|
||||
.substring(0, 30)
|
||||
.replace(/[^a-z0-9]/gi, '-')
|
||||
.toLowerCase();
|
||||
const filename = `${safeText}-${generationId.substring(0, 8)}.wav`;
|
||||
const filename = `${safeText}.wav`;
|
||||
|
||||
await platform.filesystem.saveFile(filename, blob, [
|
||||
{
|
||||
|
||||
+15
-20
@@ -1,5 +1,5 @@
|
||||
import { formatDistance } from 'date-fns';
|
||||
import { es, fr, ja, zhCN, zhTW } from 'date-fns/locale';
|
||||
import { ja, zhCN, zhTW } from 'date-fns/locale';
|
||||
import i18n from '@/i18n';
|
||||
|
||||
export function formatDuration(seconds: number): string {
|
||||
@@ -10,43 +10,38 @@ export function formatDuration(seconds: number): string {
|
||||
|
||||
function getDateLocale() {
|
||||
switch (i18n.language) {
|
||||
case 'es':
|
||||
return es;
|
||||
case 'ja':
|
||||
return ja;
|
||||
case 'zh-CN':
|
||||
return zhCN;
|
||||
case 'zh-TW':
|
||||
return zhTW;
|
||||
case 'fr':
|
||||
return fr;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
// Backend timestamps are naive UTC — append `Z` so JS doesn't parse a
|
||||
// timezone-less date-time string as local time.
|
||||
function parseServerDate(date: string | Date): Date {
|
||||
if (typeof date !== 'string') {
|
||||
return date;
|
||||
}
|
||||
const dateStr = date.trim();
|
||||
if (!dateStr.includes('Z') && !dateStr.match(/[+-]\d{2}:\d{2}$/)) {
|
||||
return new Date(`${dateStr}Z`);
|
||||
}
|
||||
return new Date(dateStr);
|
||||
}
|
||||
|
||||
export function formatDate(date: string | Date): string {
|
||||
return formatDistance(parseServerDate(date), new Date(), {
|
||||
let dateObj: Date;
|
||||
if (typeof date === 'string') {
|
||||
const dateStr = date.trim();
|
||||
if (!dateStr.includes('Z') && !dateStr.match(/[+-]\d{2}:\d{2}$/)) {
|
||||
dateObj = new Date(`${dateStr}Z`);
|
||||
} else {
|
||||
dateObj = new Date(dateStr);
|
||||
}
|
||||
} else {
|
||||
dateObj = date;
|
||||
}
|
||||
|
||||
return formatDistance(dateObj, new Date(), {
|
||||
addSuffix: true,
|
||||
locale: getDateLocale(),
|
||||
}).replace(/^about /i, '');
|
||||
}
|
||||
|
||||
export function formatAbsoluteDate(date: string | Date): string {
|
||||
const dateObj = parseServerDate(date);
|
||||
const dateObj = typeof date === 'string' ? new Date(date) : date;
|
||||
return dateObj.toLocaleString(i18n.language, {
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
|
||||
@@ -60,7 +60,6 @@ export interface PlatformLifecycle {
|
||||
stopServer(): Promise<void>;
|
||||
restartServer(modelsDir?: string | null): Promise<string>;
|
||||
setKeepServerRunning(keep: boolean): Promise<void>;
|
||||
setBackendOverride(backend?: string | null): Promise<void>;
|
||||
setupWindowCloseHandler(): Promise<void>;
|
||||
subscribeToServerLogs(callback: (entry: ServerLogEntry) => void): () => void;
|
||||
onServerReady?: () => void;
|
||||
|
||||
+1
-63
@@ -3,8 +3,6 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
from contextlib import asynccontextmanager
|
||||
from pathlib import Path
|
||||
@@ -38,67 +36,9 @@ logging.basicConfig(
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# An empty HSA_OVERRIDE_GFX_VERSION poisons the ROCm HSA runtime. It is
|
||||
# treated as "force-empty" and no GPU is detected, even natively supported
|
||||
# ones (e.g. gfx1201 / RX 9070 on ROCm 7.2). docker-compose can't
|
||||
# conditionally omit an env var, so we clean it up here before torch loads.
|
||||
if not os.environ.get("HSA_OVERRIDE_GFX_VERSION"):
|
||||
os.environ.pop("HSA_OVERRIDE_GFX_VERSION", None)
|
||||
|
||||
# AMD GPU environment variables must be set before torch import
|
||||
# Only set HSA_OVERRIDE_GFX_VERSION for older GPUs that need it.
|
||||
# RDNA 3+ (gfx1100+) and RDNA 4 (gfx1200+) are natively supported by ROCm
|
||||
# and the override can cause suboptimal performance or errors.
|
||||
if not os.environ.get("HSA_OVERRIDE_GFX_VERSION"):
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["rocminfo"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=5,
|
||||
)
|
||||
if result.returncode == 0:
|
||||
# Collect all GPUs found in rocminfo output
|
||||
gfx_versions = []
|
||||
for line in result.stdout.splitlines():
|
||||
line_lower = line.lower()
|
||||
if "gfx" in line_lower:
|
||||
match = re.search(r"(gfx\d+)", line_lower)
|
||||
if match:
|
||||
gfx_versions.append(match.group(1))
|
||||
|
||||
if gfx_versions:
|
||||
# Check if any GPU needs the override (RDNA 2 and older)
|
||||
# Use the oldest GPU (lowest gfx number) for the decision
|
||||
try:
|
||||
gfx_nums = []
|
||||
for v in gfx_versions:
|
||||
m = re.search(r"\d+", v)
|
||||
if m:
|
||||
gfx_nums.append(int(m.group()))
|
||||
if gfx_nums:
|
||||
oldest_num = min(gfx_nums)
|
||||
oldest_gfx = gfx_versions[gfx_nums.index(oldest_num)]
|
||||
if oldest_num < 1100:
|
||||
os.environ["HSA_OVERRIDE_GFX_VERSION"] = "10.3.0"
|
||||
logger.info(
|
||||
"AMD GPU detected (%s), setting HSA_OVERRIDE_GFX_VERSION=10.3.0 for compatibility. All GPUs: %s",
|
||||
oldest_gfx,
|
||||
", ".join(gfx_versions),
|
||||
)
|
||||
else:
|
||||
logger.info(
|
||||
"AMD GPU detected (%s), native ROCm support available, skipping HSA_OVERRIDE_GFX_VERSION. All GPUs: %s",
|
||||
oldest_gfx,
|
||||
", ".join(gfx_versions),
|
||||
)
|
||||
except (ValueError, AttributeError) as e:
|
||||
logger.info("Could not parse GPU version from rocminfo output: %s", e)
|
||||
except (FileNotFoundError, subprocess.TimeoutExpired, Exception) as e:
|
||||
logger.info(
|
||||
"Could not detect AMD GPU via rocminfo, skipping automatic HSA_OVERRIDE_GFX_VERSION configuration: %s",
|
||||
e,
|
||||
)
|
||||
os.environ["HSA_OVERRIDE_GFX_VERSION"] = "10.3.0"
|
||||
if not os.environ.get("MIOPEN_LOG_LEVEL"):
|
||||
os.environ["MIOPEN_LOG_LEVEL"] = "4"
|
||||
|
||||
@@ -333,10 +273,8 @@ async def _run_startup(application: FastAPI) -> None:
|
||||
logger.warning("GPU COMPATIBILITY: %s", _cuda_warning)
|
||||
|
||||
from .services.cuda import check_and_update_cuda_binary
|
||||
from .services.rocm import check_and_update_rocm_binary
|
||||
|
||||
create_background_task(check_and_update_cuda_binary())
|
||||
create_background_task(check_and_update_rocm_binary())
|
||||
|
||||
try:
|
||||
progress_manager = get_progress_manager()
|
||||
|
||||
@@ -56,7 +56,6 @@ class ModelConfig:
|
||||
model_size: str = "default"
|
||||
size_mb: int = 0
|
||||
needs_trim: bool = False
|
||||
retries_runaway: bool = False
|
||||
supports_instruct: bool = False
|
||||
languages: list[str] = field(default_factory=lambda: ["en"])
|
||||
|
||||
@@ -233,10 +232,6 @@ def _get_qwen_model_configs() -> list[ModelConfig]:
|
||||
repo_1_7b = "Qwen/Qwen3-TTS-12Hz-1.7B-Base"
|
||||
repo_0_6b = "Qwen/Qwen3-TTS-12Hz-0.6B-Base"
|
||||
|
||||
# mlx-audio can continue after an EOS miss with silence followed by
|
||||
# codec noise. Retry only the affected text as smaller chunks.
|
||||
retries_runaway = backend_type == "mlx"
|
||||
|
||||
return [
|
||||
ModelConfig(
|
||||
model_name="qwen-tts-1.7B",
|
||||
@@ -245,7 +240,6 @@ def _get_qwen_model_configs() -> list[ModelConfig]:
|
||||
hf_repo_id=repo_1_7b,
|
||||
model_size="1.7B",
|
||||
size_mb=3500,
|
||||
retries_runaway=retries_runaway,
|
||||
supports_instruct=False, # Base model drops instruct silently
|
||||
languages=["zh", "en", "ja", "ko", "de", "fr", "ru", "pt", "es", "it"],
|
||||
),
|
||||
@@ -256,7 +250,6 @@ def _get_qwen_model_configs() -> list[ModelConfig]:
|
||||
hf_repo_id=repo_0_6b,
|
||||
model_size="0.6B",
|
||||
size_mb=1200,
|
||||
retries_runaway=retries_runaway,
|
||||
supports_instruct=False,
|
||||
languages=["zh", "en", "ja", "ko", "de", "fr", "ru", "pt", "es", "it"],
|
||||
),
|
||||
@@ -511,14 +504,6 @@ def engine_needs_trim(engine: str) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def engine_retries_runaway(engine: str) -> bool:
|
||||
"""Whether unstable output should be retried in smaller chunks."""
|
||||
for cfg in get_tts_model_configs():
|
||||
if cfg.engine == engine:
|
||||
return cfg.retries_runaway
|
||||
return False
|
||||
|
||||
|
||||
def engine_has_model_sizes(engine: str) -> bool:
|
||||
"""Whether this engine supports multiple model sizes (only Qwen currently)."""
|
||||
configs = [c for c in get_tts_model_configs() if c.engine == engine]
|
||||
|
||||
@@ -138,11 +138,6 @@ def check_cuda_compatibility() -> tuple[bool, str | None]:
|
||||
if not torch.cuda.is_available():
|
||||
return True, None
|
||||
|
||||
# ROCm/HIP uses the cuda frontend but has different architecture names (gfx*).
|
||||
# Skip NVIDIA-specific compute capability checks on AMD hardware.
|
||||
if hasattr(torch.version, "hip") and torch.version.hip:
|
||||
return True, None
|
||||
|
||||
major, minor = torch.cuda.get_device_capability(0)
|
||||
capability = f"{major}.{minor}"
|
||||
device_name = torch.cuda.get_device_name(0)
|
||||
|
||||
@@ -146,15 +146,7 @@ class HumeTadaBackend:
|
||||
)
|
||||
|
||||
# Determine dtype — use bf16 on CUDA/XPU for ~50% memory savings
|
||||
# On ROCm/AMD, torch.cuda.is_bf16_supported() works via the HIP abstraction,
|
||||
# but we wrap it defensively in case an older build lacks the symbol.
|
||||
_bf16_ok = False
|
||||
if device == "cuda":
|
||||
try:
|
||||
_bf16_ok = torch.cuda.is_bf16_supported()
|
||||
except Exception:
|
||||
_bf16_ok = False
|
||||
if _bf16_ok:
|
||||
if device == "cuda" and torch.cuda.is_bf16_supported():
|
||||
model_dtype = torch.bfloat16
|
||||
elif device == "xpu":
|
||||
# Intel Arc (Alchemist+) supports bf16 natively
|
||||
@@ -248,13 +240,9 @@ class HumeTadaBackend:
|
||||
audio = audio.T # (samples, channels) -> (channels, samples)
|
||||
audio = audio.to(device)
|
||||
|
||||
# Encode with forced alignment.
|
||||
# Must run under inference_mode: encoder params still require
|
||||
# grad by default, and an autograd graph across the DAC/Snake
|
||||
# stack can balloon VRAM far past the model footprint (#890).
|
||||
# Encode with forced alignment
|
||||
text_arg = [reference_text] if reference_text else None
|
||||
with torch.inference_mode():
|
||||
prompt = self.encoder(audio, text=text_arg, sample_rate=sr)
|
||||
prompt = self.encoder(audio, text=text_arg, sample_rate=sr)
|
||||
|
||||
# Serialize EncoderOutput to a dict of CPU tensors for caching
|
||||
prompt_dict = {}
|
||||
|
||||
@@ -96,16 +96,11 @@ KOKORO_VOICES = [
|
||||
("pf_dora", "Dora", "female", "pt"),
|
||||
("pm_alex", "Alex", "male", "pt"),
|
||||
("pm_santa", "Santa", "male", "pt"),
|
||||
# Chinese female
|
||||
# Chinese
|
||||
("zf_xiaobei", "Xiaobei", "female", "zh"),
|
||||
("zf_xiaoni", "Xiaoni", "female", "zh"),
|
||||
("zf_xiaoxiao", "Xiaoxiao", "female", "zh"),
|
||||
("zf_xiaoyi", "Xiaoyi", "female", "zh"),
|
||||
# Chinese male
|
||||
("zm_yunjian", "Yunjian", "male", "zh"),
|
||||
("zm_yunxi", "Yunxi", "male", "zh"),
|
||||
("zm_yunxia", "Yunxia", "male", "zh"),
|
||||
("zm_yunyang", "Yunyang", "male", "zh"),
|
||||
]
|
||||
|
||||
# Map our ISO language codes to Kokoro lang_code characters
|
||||
|
||||
@@ -19,6 +19,7 @@ from .base import (
|
||||
manual_seed,
|
||||
model_load_progress,
|
||||
)
|
||||
from ..utils.hf_offline_patch import force_offline_if_cached
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -102,19 +103,15 @@ class PyTorchQwenLLMBackend:
|
||||
|
||||
with model_load_progress(progress_model_name, is_cached):
|
||||
logger.info("Loading Qwen3 %s on %s...", model_size, self.device)
|
||||
# Loads run with the process's default HF_HUB_OFFLINE state.
|
||||
# Forcing offline for cached models flips process-global state
|
||||
# and silently switches every concurrent download/load on other
|
||||
# threads to offline mode (issue #841) — the same regression
|
||||
# removed app-wide in #524/#530.
|
||||
self.tokenizer = AutoTokenizer.from_pretrained(repo)
|
||||
dtype = torch.float16 if self.device in ("cuda", "mps") else torch.float32
|
||||
self.model = AutoModelForCausalLM.from_pretrained(
|
||||
repo,
|
||||
dtype=dtype,
|
||||
)
|
||||
self.model.to(self.device)
|
||||
self.model.eval()
|
||||
with force_offline_if_cached(is_cached, progress_model_name):
|
||||
self.tokenizer = AutoTokenizer.from_pretrained(repo)
|
||||
dtype = torch.float16 if self.device in ("cuda", "mps") else torch.float32
|
||||
self.model = AutoModelForCausalLM.from_pretrained(
|
||||
repo,
|
||||
dtype=dtype,
|
||||
)
|
||||
self.model.to(self.device)
|
||||
self.model.eval()
|
||||
|
||||
self._current_model_size = model_size
|
||||
self.model_size = model_size
|
||||
@@ -226,8 +223,8 @@ class MLXQwenLLMBackend:
|
||||
|
||||
with model_load_progress(progress_model_name, is_cached):
|
||||
logger.info("Loading Qwen3 %s via MLX...", model_size)
|
||||
# See the PyTorch loader comment — no offline forcing (issue #841).
|
||||
loaded = mlx_load(repo)
|
||||
with force_offline_if_cached(is_cached, progress_model_name):
|
||||
loaded = mlx_load(repo)
|
||||
|
||||
# mlx_lm.load returns (model, tokenizer) by default and
|
||||
# (model, tokenizer, config) when return_config=True.
|
||||
|
||||
+54
-252
@@ -22,34 +22,24 @@ def is_apple_silicon():
|
||||
return platform.system() == "Darwin" and platform.machine() == "arm64"
|
||||
|
||||
|
||||
def build_server(cuda=False, rocm=False):
|
||||
def build_server(cuda=False):
|
||||
"""Build Python server as standalone binary.
|
||||
|
||||
Args:
|
||||
cuda: If True, build with CUDA support and name the binary
|
||||
voicebox-server-cuda instead of voicebox-server.
|
||||
rocm: If True, build with ROCm support and name the binary
|
||||
voicebox-server-rocm instead of voicebox-server.
|
||||
"""
|
||||
if cuda and rocm:
|
||||
raise ValueError("Cannot build with both CUDA and ROCm support")
|
||||
|
||||
backend_dir = Path(__file__).parent
|
||||
|
||||
if rocm:
|
||||
binary_name = "voicebox-server-rocm"
|
||||
elif cuda:
|
||||
binary_name = "voicebox-server-cuda"
|
||||
else:
|
||||
binary_name = "voicebox-server"
|
||||
binary_name = "voicebox-server-cuda" if cuda else "voicebox-server"
|
||||
|
||||
# PyInstaller arguments
|
||||
# CUDA and ROCm builds use --onedir so we can split the output into two archives:
|
||||
# CUDA builds use --onedir so we can split the output into two archives:
|
||||
# 1. Server core (~200-400MB) — versioned with the app
|
||||
# 2. GPU libs (~2GB) — versioned independently (only redownloaded on
|
||||
# GPU toolkit / torch major version changes)
|
||||
# 2. CUDA libs (~2GB) — versioned independently (only redownloaded on
|
||||
# CUDA toolkit / torch major version changes)
|
||||
# CPU builds remain --onefile for simplicity.
|
||||
pack_mode = "--onedir" if (cuda or rocm) else "--onefile"
|
||||
pack_mode = "--onedir" if cuda else "--onefile"
|
||||
args = [
|
||||
"server.py", # Use server.py as entry point instead of main.py
|
||||
pack_mode,
|
||||
@@ -330,77 +320,22 @@ def build_server(cuda=False, rocm=False):
|
||||
]
|
||||
)
|
||||
|
||||
if sys.version_info >= (3, 13):
|
||||
args.extend(["--hidden-import", "audioop"])
|
||||
|
||||
# Add CUDA/ROCm-specific hidden imports
|
||||
if cuda or rocm:
|
||||
variant = "ROCm" if rocm else "CUDA"
|
||||
logger.info("Building with %s support", variant)
|
||||
gpu_hidden = [
|
||||
"--hidden-import",
|
||||
"torch.cuda",
|
||||
]
|
||||
# cudnn is NVIDIA-specific; ROCm uses MIOpen under the abstraction layer
|
||||
if cuda:
|
||||
gpu_hidden.extend(
|
||||
[
|
||||
"--hidden-import",
|
||||
"torch.backends.cudnn",
|
||||
]
|
||||
)
|
||||
args.extend(gpu_hidden)
|
||||
|
||||
if rocm:
|
||||
# rocm_sdk imports its backend packages dynamically via
|
||||
# importlib.import_module(py_package_name), which PyInstaller's
|
||||
# static analyzer cannot see. We must collect them explicitly —
|
||||
# otherwise only the pure-python rocm_sdk wrapper ships and
|
||||
# rocm_sdk.find_libraries crashes with UnboundLocalError at boot.
|
||||
#
|
||||
# The backend packages also contain the HIP/MIOpen/hipBLAS DLLs
|
||||
# under bin/ (plus ~750 MB of tensile kernel files under
|
||||
# bin/rocblas/library and bin/hipblaslt/library) — collect-all
|
||||
# walks the tree recursively so both DLLs and kernel data are
|
||||
# bundled. See rocm_sdk/_dist_info.py for the package mapping.
|
||||
# Add CUDA-specific hidden imports
|
||||
if cuda:
|
||||
logger.info("Building with CUDA support")
|
||||
args.extend(
|
||||
[
|
||||
"--collect-all",
|
||||
"rocm_sdk",
|
||||
"--collect-all",
|
||||
"_rocm_sdk_core",
|
||||
"--collect-all",
|
||||
"_rocm_sdk_libraries_custom",
|
||||
"--collect-all",
|
||||
"rocm_sdk_core",
|
||||
"--collect-all",
|
||||
"rocm_sdk_libraries_custom",
|
||||
"--hidden-import",
|
||||
"_rocm_sdk_core",
|
||||
"torch.cuda",
|
||||
"--hidden-import",
|
||||
"_rocm_sdk_libraries_custom",
|
||||
"--hidden-import",
|
||||
"rocm_sdk_core",
|
||||
"--hidden-import",
|
||||
"rocm_sdk_libraries_custom",
|
||||
"--copy-metadata",
|
||||
"rocm",
|
||||
"--copy-metadata",
|
||||
"rocm-sdk-core",
|
||||
"--copy-metadata",
|
||||
"rocm-sdk-libraries-custom",
|
||||
# Repair rocm_sdk.find_libraries (masks UnboundLocalError
|
||||
# with a readable ModuleNotFoundError on missing backends).
|
||||
"--runtime-hook",
|
||||
"pyi_rth_rocm_sdk.py",
|
||||
"torch.backends.cudnn",
|
||||
]
|
||||
)
|
||||
|
||||
# Exclude NVIDIA CUDA packages from non-CUDA builds to keep binary small.
|
||||
# When building from a venv with CUDA torch installed, PyInstaller would
|
||||
# bundle ~3GB of NVIDIA shared libraries. We exclude both the Python
|
||||
# modules and the binary DLLs. This applies to CPU and ROCm builds.
|
||||
if not cuda:
|
||||
else:
|
||||
# Exclude NVIDIA CUDA packages from CPU-only builds to keep binary small.
|
||||
# When building from a venv with CUDA torch installed, PyInstaller would
|
||||
# bundle ~3GB of NVIDIA shared libraries. We exclude both the Python
|
||||
# modules and the binary DLLs.
|
||||
nvidia_packages = [
|
||||
"nvidia",
|
||||
"nvidia.cublas",
|
||||
@@ -419,8 +354,8 @@ def build_server(cuda=False, rocm=False):
|
||||
for pkg in nvidia_packages:
|
||||
args.extend(["--exclude-module", pkg])
|
||||
|
||||
# Add MLX-specific imports if building on Apple Silicon (never for GPU builds)
|
||||
if is_apple_silicon() and not cuda and not rocm:
|
||||
# Add MLX-specific imports if building on Apple Silicon (never for CUDA builds)
|
||||
if is_apple_silicon() and not cuda:
|
||||
logger.info("Building for Apple Silicon - including MLX dependencies")
|
||||
args.extend(
|
||||
[
|
||||
@@ -464,7 +399,7 @@ def build_server(cuda=False, rocm=False):
|
||||
"mlx_lm",
|
||||
]
|
||||
)
|
||||
elif not cuda and not rocm:
|
||||
elif not cuda:
|
||||
logger.info("Building for non-Apple Silicon platform - PyTorch only")
|
||||
|
||||
dist_dir = str(backend_dir / "dist")
|
||||
@@ -485,128 +420,43 @@ def build_server(cuda=False, rocm=False):
|
||||
os.chdir(backend_dir)
|
||||
|
||||
# For CPU builds on Windows, ensure we're using CPU-only torch.
|
||||
# If CUDA or ROCm torch is installed (local dev), swap to CPU torch before
|
||||
# building, then restore afterwards. This prevents PyInstaller from bundling
|
||||
# GPU libraries into the CPU binary.
|
||||
restore_torch = None
|
||||
# If CUDA torch is installed (local dev), swap to CPU torch before building,
|
||||
# then restore CUDA torch after. This prevents PyInstaller from bundling
|
||||
# ~3GB of CUDA DLLs into the CPU binary.
|
||||
restore_cuda = False
|
||||
if not cuda and platform.system() == "Windows":
|
||||
import subprocess
|
||||
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-c", "import torch; print(torch.version.cuda or '')"], capture_output=True, text=True
|
||||
)
|
||||
has_cuda_torch = bool(result.stdout.strip())
|
||||
if has_cuda_torch:
|
||||
logger.info("CUDA torch detected — installing CPU torch for CPU build...")
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-m",
|
||||
"pip",
|
||||
"install",
|
||||
"torch",
|
||||
"torchvision",
|
||||
"torchaudio",
|
||||
"--index-url",
|
||||
"https://download.pytorch.org/whl/cpu",
|
||||
"--force-reinstall",
|
||||
"-q",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
restore_cuda = True
|
||||
|
||||
# Run PyInstaller
|
||||
try:
|
||||
if not cuda and not rocm and platform.system() == "Windows":
|
||||
import subprocess
|
||||
|
||||
cuda_result = subprocess.run(
|
||||
[sys.executable, "-c", "import torch; print(torch.version.cuda or '')"], capture_output=True, text=True
|
||||
)
|
||||
rocm_result = subprocess.run(
|
||||
[sys.executable, "-c", "import torch; print(torch.version.hip or '')"], capture_output=True, text=True
|
||||
)
|
||||
|
||||
if cuda_result.stdout.strip():
|
||||
restore_torch = "cuda"
|
||||
logger.info("CUDA torch detected — installing CPU torch for CPU build...")
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-m",
|
||||
"pip",
|
||||
"install",
|
||||
"torch",
|
||||
"torchvision",
|
||||
"torchaudio",
|
||||
"--index-url",
|
||||
"https://download.pytorch.org/whl/cpu",
|
||||
"--force-reinstall",
|
||||
"--no-deps",
|
||||
"-q",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
elif rocm_result.stdout.strip():
|
||||
restore_torch = "rocm"
|
||||
logger.info("ROCm torch detected — installing CPU torch for CPU build...")
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-m",
|
||||
"pip",
|
||||
"install",
|
||||
"torch",
|
||||
"torchvision",
|
||||
"torchaudio",
|
||||
"--index-url",
|
||||
"https://download.pytorch.org/whl/cpu",
|
||||
"--force-reinstall",
|
||||
"--no-deps",
|
||||
"-q",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
|
||||
# For ROCm builds on Windows, ensure ROCm torch is installed.
|
||||
if rocm and platform.system() == "Windows":
|
||||
import subprocess
|
||||
|
||||
if sys.implementation.name != "cpython" or sys.version_info[:2] != (3, 12):
|
||||
raise RuntimeError(
|
||||
"ROCm wheels are cp312-cp312-specific; "
|
||||
f"got {sys.implementation.name} {sys.version.split()[0]}. "
|
||||
"Use CPython 3.12 to build the ROCm binary."
|
||||
)
|
||||
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-c", "import torch; print(torch.version.hip or '')"], capture_output=True, text=True
|
||||
)
|
||||
has_rocm_torch = bool(result.stdout.strip())
|
||||
if not has_rocm_torch:
|
||||
logger.info("ROCm torch not detected — installing ROCm torch for ROCm build...")
|
||||
|
||||
# Determine what to restore BEFORE overwriting the environment
|
||||
cuda_result = subprocess.run(
|
||||
[sys.executable, "-c", "import torch; print(torch.version.cuda or '')"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
if cuda_result.stdout.strip():
|
||||
restore_torch = "cuda"
|
||||
else:
|
||||
restore_torch = "cpu"
|
||||
|
||||
# Now overwrite the environment safely
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-m",
|
||||
"pip",
|
||||
"install",
|
||||
"https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/rocm_sdk_core-7.2.1-py3-none-win_amd64.whl",
|
||||
"https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/rocm_sdk_devel-7.2.1-py3-none-win_amd64.whl",
|
||||
"https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/rocm_sdk_libraries_custom-7.2.1-py3-none-win_amd64.whl",
|
||||
"https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/rocm-7.2.1.tar.gz",
|
||||
"--no-deps",
|
||||
"-q",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-m",
|
||||
"pip",
|
||||
"install",
|
||||
"https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/torch-2.9.1%2Brocm7.2.1-cp312-cp312-win_amd64.whl",
|
||||
"https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/torchaudio-2.9.1%2Brocm7.2.1-cp312-cp312-win_amd64.whl",
|
||||
"https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/torchvision-0.24.1%2Brocm7.2.1-cp312-cp312-win_amd64.whl",
|
||||
"--force-reinstall",
|
||||
"--no-deps",
|
||||
"-q",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
|
||||
# Run PyInstaller
|
||||
PyInstaller.__main__.run(args)
|
||||
finally:
|
||||
# Restore torch if we swapped it out (even on build failure)
|
||||
if restore_torch == "cuda":
|
||||
# Restore CUDA torch if we swapped it out (even on build failure)
|
||||
if restore_cuda:
|
||||
logger.info("Restoring CUDA torch...")
|
||||
import subprocess
|
||||
|
||||
@@ -622,52 +472,10 @@ def build_server(cuda=False, rocm=False):
|
||||
"--index-url",
|
||||
"https://download.pytorch.org/whl/cu128",
|
||||
"--force-reinstall",
|
||||
"--no-deps",
|
||||
"-q",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
elif restore_torch == "rocm":
|
||||
logger.info("Restoring ROCm torch...")
|
||||
import subprocess
|
||||
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-m",
|
||||
"pip",
|
||||
"install",
|
||||
"https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/torch-2.9.1%2Brocm7.2.1-cp312-cp312-win_amd64.whl",
|
||||
"https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/torchaudio-2.9.1%2Brocm7.2.1-cp312-cp312-win_amd64.whl",
|
||||
"https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/torchvision-0.24.1%2Brocm7.2.1-cp312-cp312-win_amd64.whl",
|
||||
"--force-reinstall",
|
||||
"--no-deps",
|
||||
"-q",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
elif restore_torch == "cpu":
|
||||
logger.info("Restoring CPU torch...")
|
||||
import subprocess
|
||||
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-m",
|
||||
"pip",
|
||||
"install",
|
||||
"torch",
|
||||
"torchvision",
|
||||
"torchaudio",
|
||||
"--index-url",
|
||||
"https://download.pytorch.org/whl/cpu",
|
||||
"--force-reinstall",
|
||||
"--no-deps",
|
||||
"-q",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
|
||||
|
||||
logger.info("Binary built in %s", backend_dir / "dist" / binary_name)
|
||||
|
||||
@@ -769,11 +577,6 @@ if __name__ == "__main__":
|
||||
action="store_true",
|
||||
help="Build CUDA-enabled binary (voicebox-server-cuda)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--rocm",
|
||||
action="store_true",
|
||||
help="Build ROCm-enabled binary (voicebox-server-rocm) for AMD GPUs",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--shim",
|
||||
action="store_true",
|
||||
@@ -783,5 +586,4 @@ if __name__ == "__main__":
|
||||
if cli_args.shim:
|
||||
build_shim()
|
||||
else:
|
||||
build_server(cuda=cli_args.cuda, rocm=cli_args.rocm)
|
||||
|
||||
build_server(cuda=cli_args.cuda)
|
||||
|
||||
@@ -80,11 +80,6 @@ def resolve_storage_path(path: str | Path | None) -> Path | None:
|
||||
return None
|
||||
|
||||
stored_path = Path(path)
|
||||
# Empty paths (e.g. failed generations) must not resolve to the data
|
||||
# dir itself, which exists and would defeat the callers' 404 guards.
|
||||
# Path("") is truthy, so check parts rather than the raw value.
|
||||
if not stored_path.parts:
|
||||
return None
|
||||
if stored_path.is_absolute():
|
||||
rebased_path = _path_relative_to_any_data_dir(stored_path)
|
||||
if rebased_path is not None:
|
||||
|
||||
@@ -12,6 +12,7 @@ from .models import (
|
||||
CaptureSettings,
|
||||
ChannelDeviceMapping,
|
||||
CloudSettings,
|
||||
CloudSyncState,
|
||||
EffectPreset,
|
||||
Generation,
|
||||
GenerationSettings,
|
||||
@@ -34,6 +35,7 @@ __all__ = [
|
||||
"CaptureSettings",
|
||||
"ChannelDeviceMapping",
|
||||
"CloudSettings",
|
||||
"CloudSyncState",
|
||||
"EffectPreset",
|
||||
"Generation",
|
||||
"GenerationSettings",
|
||||
|
||||
@@ -43,6 +43,7 @@ def run_migrations(engine) -> None:
|
||||
_migrate_generation_versions(engine, inspector, tables)
|
||||
_migrate_capture_settings(engine, inspector, tables)
|
||||
_migrate_mcp_bindings(engine, inspector, tables)
|
||||
_migrate_cloud_settings(engine, inspector, tables)
|
||||
_normalize_storage_paths(engine, tables)
|
||||
|
||||
|
||||
@@ -283,6 +284,19 @@ def _migrate_mcp_bindings(engine, inspector, tables: set[str]) -> None:
|
||||
)
|
||||
|
||||
|
||||
def _migrate_cloud_settings(engine, inspector, tables: set[str]) -> None:
|
||||
"""Add the cloud sync columns: ``sync_device_id`` (the server-assigned id
|
||||
from registering this install as an encryption-capable sync device) and
|
||||
``sync_cursor`` (highest applied seq from the sync feed)."""
|
||||
if "cloud_settings" not in tables:
|
||||
return
|
||||
columns = _get_columns(inspector, "cloud_settings")
|
||||
if "sync_device_id" not in columns:
|
||||
_add_column(engine, "cloud_settings", "sync_device_id VARCHAR", "sync_device_id")
|
||||
if "sync_cursor" not in columns:
|
||||
_add_column(engine, "cloud_settings", "sync_cursor INTEGER NOT NULL DEFAULT 0", "sync_cursor")
|
||||
|
||||
|
||||
def _supports_drop_column(engine) -> bool:
|
||||
"""Whether ``ALTER TABLE … DROP COLUMN`` is supported by the dialect +
|
||||
runtime. Non-SQLite dialects (Postgres, MySQL) have supported it for
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
from datetime import datetime
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import Column, String, Integer, Float, DateTime, Text, ForeignKey, Boolean, JSON
|
||||
from sqlalchemy import Column, String, Integer, Float, DateTime, Text, ForeignKey, Boolean, JSON, UniqueConstraint
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
||||
from ..utils.capture_chords import (
|
||||
@@ -253,9 +253,45 @@ class CloudSettings(Base):
|
||||
device_name = Column(String, nullable=True)
|
||||
account_user_id = Column(String, nullable=True)
|
||||
connected_at = Column(DateTime, nullable=True)
|
||||
# Server-assigned sync device id (device table on the cloud side). Set when
|
||||
# this install registers as an encryption-capable device; the matching
|
||||
# X25519 private key lives in the OS keychain (services/cloud_keys.py).
|
||||
sync_device_id = Column(String, nullable=True)
|
||||
# Highest server seq this install has applied from the sync feed.
|
||||
sync_cursor = Column(Integer, nullable=False, default=0)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
|
||||
class CloudSyncState(Base):
|
||||
"""Per-entity sync bookkeeping for cloud backup (one row per synced object).
|
||||
|
||||
Envelopes are randomized (fresh content key + nonce per encryption), so the
|
||||
ciphertext hash changes on every re-encrypt even when the content didn't.
|
||||
To keep the server's changed-hash dedup working, this table remembers what
|
||||
was last uploaded: the plaintext fingerprints (to detect real local edits)
|
||||
and the ciphertext hashes the server currently holds (to re-declare
|
||||
unchanged blobs without re-encrypting or re-uploading them).
|
||||
"""
|
||||
|
||||
__tablename__ = "cloud_sync_state"
|
||||
__table_args__ = (UniqueConstraint("kind", "client_id", name="uq_cloud_sync_state_kind_client"),)
|
||||
|
||||
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
||||
kind = Column(String, nullable=False) # capture | generation | profile | settings
|
||||
client_id = Column(String, nullable=False) # the local entity id
|
||||
server_object_id = Column(String, nullable=True)
|
||||
# Client-bumped LWW version (object.version on the server).
|
||||
version = Column(Integer, nullable=False, default=1)
|
||||
# SHA-256 of the canonical plaintext record JSON at last push/pull.
|
||||
record_fingerprint = Column(String, nullable=True)
|
||||
# SHA-256 + size of the record ciphertext the server currently holds.
|
||||
record_hash = Column(String, nullable=True)
|
||||
record_size = Column(Integer, nullable=False, default=0)
|
||||
# Per-asset bookkeeping, JSON: {clientAssetId: {role, fingerprint, hash, size}}
|
||||
assets_json = Column(Text, nullable=False, default="{}")
|
||||
last_synced_at = Column(DateTime, nullable=True)
|
||||
|
||||
|
||||
class MCPClientBinding(Base):
|
||||
"""Per-MCP-client settings (voice profile, engine, personality default).
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import base64 as b64
|
||||
import logging
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from typing import Any, Literal
|
||||
from typing import Any
|
||||
|
||||
from fastmcp import FastMCP
|
||||
|
||||
@@ -49,7 +49,6 @@ def register_tools(mcp: FastMCP) -> None:
|
||||
engine: str | None = None,
|
||||
personality: bool | None = None,
|
||||
language: str | None = None,
|
||||
model_size: Literal["1.7B", "0.6B", "1B", "3B"] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""Speak ``text`` in a voice profile.
|
||||
|
||||
@@ -62,12 +61,6 @@ def register_tools(mcp: FastMCP) -> None:
|
||||
LLM before TTS. When omitted, the per-client binding's
|
||||
``default_personality`` flag decides; when that is unset, the
|
||||
default is plain TTS.
|
||||
|
||||
``model_size`` selects a model variant for engines that ship more
|
||||
than one — ``qwen`` and ``qwen_custom_voice`` accept "1.7B" (default)
|
||||
or "0.6B"; ``tada`` accepts "1B" or "3B". Other engines ignore it.
|
||||
Omit to use the engine default. Requesting a smaller variant (e.g.
|
||||
"0.6B") is faster and avoids reloading a heavier model between calls.
|
||||
"""
|
||||
from ..database.models import MCPClientBinding
|
||||
|
||||
@@ -106,7 +99,6 @@ def register_tools(mcp: FastMCP) -> None:
|
||||
engine=resolved_engine,
|
||||
language=language,
|
||||
personality=use_persona,
|
||||
model_size=model_size,
|
||||
db=db,
|
||||
)
|
||||
finally:
|
||||
@@ -236,23 +228,18 @@ async def _speak(
|
||||
engine: str | None,
|
||||
language: str | None,
|
||||
personality: bool,
|
||||
model_size: str | None = None,
|
||||
db,
|
||||
) -> dict[str, Any]:
|
||||
"""Delegate to POST /generate — the route handles personality-rewrite
|
||||
internally when ``personality=true`` and the profile has a prompt."""
|
||||
from ..routes.generations import generate_speech
|
||||
|
||||
# model_size=None is intentional: generate_speech normalizes it to the
|
||||
# engine default (see routes/generations.py), so an omitted size behaves
|
||||
# exactly like the REST /generate endpoint with no model_size in the body.
|
||||
req = models.GenerationRequest(
|
||||
profile_id=profile_id,
|
||||
text=text,
|
||||
language=language or "en",
|
||||
engine=engine,
|
||||
personality=personality,
|
||||
model_size=model_size,
|
||||
)
|
||||
generation = await generate_speech(req, db)
|
||||
return _speak_response(generation, profile_name, source="mcp")
|
||||
|
||||
+39
-3
@@ -442,8 +442,7 @@ class HealthResponse(BaseModel):
|
||||
gpu_type: Optional[str] = None # GPU type (CUDA, MPS, or None)
|
||||
vram_used_mb: Optional[float] = None
|
||||
backend_type: Optional[str] = None # Backend type (mlx or pytorch)
|
||||
backend_variant: Optional[str] = None # Binary variant (cpu, cuda, or rocm)
|
||||
supports_rocm: bool = False # AMD GPU on Windows — the ROCm backend is applicable
|
||||
backend_variant: Optional[str] = None # Binary variant (cpu or cuda)
|
||||
gpu_compatibility_warning: Optional[str] = None # Warning if GPU arch unsupported
|
||||
|
||||
|
||||
@@ -814,4 +813,41 @@ class CloudStatusResponse(BaseModel):
|
||||
account_user_id: Optional[str] = None
|
||||
key_prefix: Optional[str] = None
|
||||
connected_at: Optional[datetime] = None
|
||||
dashboard_url: str
|
||||
|
||||
|
||||
class CloudSyncSetupResponse(BaseModel):
|
||||
"""Result of registering this install as a sync device.
|
||||
|
||||
``recovery_phrase`` is present exactly once, when this device minted the
|
||||
account's key material (first device). The UI must force-display it and
|
||||
never persist it. When absent, the account already has key material and
|
||||
this device is awaiting provisioning (wrapped key from an existing device,
|
||||
or a recovery-phrase restore)."""
|
||||
|
||||
status: str # unregistered | awaiting_provision | ready
|
||||
device_id: Optional[str] = None
|
||||
recovery_phrase: Optional[str] = None
|
||||
|
||||
|
||||
class CloudSyncStatusResponse(BaseModel):
|
||||
"""Sync identity + progress for the settings UI."""
|
||||
|
||||
status: str # unregistered | awaiting_provision | ready
|
||||
device_id: Optional[str] = None
|
||||
sync_cursor: int = 0
|
||||
|
||||
|
||||
class CloudRestoreRequest(BaseModel):
|
||||
"""Recovery-phrase restore on a fresh device."""
|
||||
|
||||
phrase: str
|
||||
|
||||
|
||||
class CloudSyncRunResponse(BaseModel):
|
||||
"""Outcome of one push+pull sync pass."""
|
||||
|
||||
pushed: int
|
||||
pushed_deletes: int
|
||||
pulled: int
|
||||
pulled_deletes: int
|
||||
cursor: int
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
"""
|
||||
Runtime hook: repair rocm_sdk.find_libraries under PyInstaller.
|
||||
|
||||
rocm_sdk 7.2.x ships a find_libraries() with a latent bug: when the
|
||||
backend package (_rocm_sdk_core / _rocm_sdk_libraries_{target}) cannot
|
||||
be imported, the except clause records the miss but falls through to
|
||||
`py_root = Path(py_module.__file__).parent`, where py_module was never
|
||||
assigned. This surfaces as UnboundLocalError instead of the intended
|
||||
ModuleNotFoundError, masking the real cause.
|
||||
|
||||
Frozen apps trip this because rocm_sdk imports the backend packages
|
||||
dynamically via importlib, which PyInstaller's static analyzer cannot
|
||||
see. We re-collect those packages in build_binary.py; this hook is
|
||||
defense-in-depth: it replaces find_libraries with a corrected version
|
||||
so any future missing-package case surfaces a readable error.
|
||||
"""
|
||||
|
||||
|
||||
def _patch_rocm_sdk():
|
||||
try:
|
||||
import rocm_sdk
|
||||
from rocm_sdk import _dist_info
|
||||
except ModuleNotFoundError as e:
|
||||
if e.name not in {"rocm_sdk", "rocm_sdk._dist_info"}:
|
||||
raise
|
||||
return
|
||||
|
||||
import importlib
|
||||
import platform
|
||||
from pathlib import Path
|
||||
|
||||
def find_libraries(*shortnames):
|
||||
paths = []
|
||||
missing_extras = set()
|
||||
is_windows = platform.system() == "Windows"
|
||||
for shortname in shortnames:
|
||||
try:
|
||||
lib_entry = _dist_info.ALL_LIBRARIES[shortname]
|
||||
except KeyError:
|
||||
raise ModuleNotFoundError(f"Unknown rocm library '{shortname}'") from None
|
||||
|
||||
if is_windows and not lib_entry.dll_pattern:
|
||||
continue
|
||||
|
||||
package = lib_entry.package
|
||||
target_family = None
|
||||
if package.is_target_specific:
|
||||
target_family = _dist_info.determine_target_family()
|
||||
py_package_name = package.get_py_package_name(target_family)
|
||||
try:
|
||||
py_module = importlib.import_module(py_package_name)
|
||||
except ModuleNotFoundError as e:
|
||||
if e.name != py_package_name:
|
||||
raise
|
||||
missing_extras.add(package.logical_name)
|
||||
continue
|
||||
|
||||
py_root = Path(py_module.__file__).parent
|
||||
if is_windows:
|
||||
relpath = py_root / lib_entry.windows_relpath
|
||||
entry_pattern = lib_entry.dll_pattern
|
||||
else:
|
||||
relpath = py_root / lib_entry.posix_relpath
|
||||
entry_pattern = lib_entry.so_pattern
|
||||
matching_paths = sorted(relpath.glob(entry_pattern))
|
||||
if len(matching_paths) == 0:
|
||||
raise FileNotFoundError(
|
||||
f"Could not find rocm library '{shortname}' at path "
|
||||
f"'{relpath},' no match for pattern '{entry_pattern}'"
|
||||
)
|
||||
paths.append(matching_paths[0])
|
||||
|
||||
if missing_extras:
|
||||
raise ModuleNotFoundError(
|
||||
f"Missing required rocm backend packages: "
|
||||
f"{', '.join(sorted(missing_extras))}. The frozen build did "
|
||||
f"not bundle _rocm_sdk_core / _rocm_sdk_libraries_<target>. "
|
||||
f"Check build_binary.py --collect-all flags."
|
||||
)
|
||||
return paths
|
||||
|
||||
rocm_sdk.find_libraries = find_libraries
|
||||
|
||||
|
||||
_patch_rocm_sdk()
|
||||
@@ -16,8 +16,7 @@ miniaudio>=1.59
|
||||
# mlx_audio.stt.load) works fine on transformers 4.57.x in practice.
|
||||
#
|
||||
# Install it via `pip install --no-deps mlx-audio==0.4.1` after this file
|
||||
# (see .github/workflows/release.yml and the setup-python recipe in the
|
||||
# justfile). Most other mlx-audio runtime deps
|
||||
# (see .github/workflows/release.yml). Most other mlx-audio runtime deps
|
||||
# (huggingface_hub, librosa, mlx-lm, numba, numpy, protobuf, pyloudnorm,
|
||||
# sounddevice, tqdm) are already in requirements.txt or pulled in by
|
||||
# other engines.
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
--extra-index-url https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/
|
||||
torch==2.9.1+rocm7.2.1
|
||||
torchaudio==2.9.1+rocm7.2.1
|
||||
torchvision==0.24.1+rocm7.2.1
|
||||
@@ -7,6 +7,12 @@ pydantic>=2.5.0
|
||||
sqlalchemy>=2.0.0
|
||||
alembic>=1.13.0
|
||||
|
||||
# Cloud backup/sync E2E encryption (services/cloud_crypto.py); keyring stores
|
||||
# the device key + master key in the OS keychain (services/cloud_keys.py)
|
||||
pynacl>=1.5.0
|
||||
mnemonic>=0.21
|
||||
keyring>=25
|
||||
|
||||
# ML models
|
||||
torch>=2.2.0
|
||||
transformers>=4.36.0,<=4.57.6
|
||||
@@ -53,7 +59,6 @@ en_core_web_sm @ https://github.com/explosion/spacy-models/releases/download/en_
|
||||
unidic-lite>=1.0.8
|
||||
|
||||
# Audio processing
|
||||
audioop-lts>=0.2.1; python_version >= "3.13"
|
||||
librosa>=0.10.0
|
||||
soundfile>=0.12.0
|
||||
numpy>=1.24.0,<2.0
|
||||
|
||||
@@ -20,7 +20,6 @@ def register_routers(app: FastAPI) -> None:
|
||||
from .settings import router as settings_router
|
||||
from .tasks import router as tasks_router
|
||||
from .cuda import router as cuda_router
|
||||
from .rocm import router as rocm_router
|
||||
from .speak import router as speak_router
|
||||
from .mcp_bindings import router as mcp_bindings_router
|
||||
from .events import router as events_router
|
||||
@@ -41,7 +40,6 @@ def register_routers(app: FastAPI) -> None:
|
||||
app.include_router(settings_router)
|
||||
app.include_router(tasks_router)
|
||||
app.include_router(cuda_router)
|
||||
app.include_router(rocm_router)
|
||||
app.include_router(speak_router)
|
||||
app.include_router(mcp_bindings_router)
|
||||
app.include_router(events_router)
|
||||
|
||||
@@ -34,7 +34,7 @@ async def get_version_audio(version_id: str, db: Session = Depends(get_db)):
|
||||
raise HTTPException(status_code=404, detail="Version not found")
|
||||
|
||||
audio_path = config.resolve_storage_path(version.audio_path)
|
||||
if audio_path is None or not audio_path.is_file():
|
||||
if audio_path is None or not audio_path.exists():
|
||||
raise HTTPException(status_code=404, detail="Audio file not found")
|
||||
|
||||
return FileResponse(
|
||||
@@ -52,13 +52,8 @@ async def get_audio(generation_id: str, db: Session = Depends(get_db)):
|
||||
raise HTTPException(status_code=404, detail="Generation not found")
|
||||
|
||||
audio_path = config.resolve_storage_path(generation.audio_path)
|
||||
if audio_path is None or not audio_path.is_file():
|
||||
detail = (
|
||||
"Generation failed; no audio available"
|
||||
if generation.status == "failed"
|
||||
else "Audio file not found"
|
||||
)
|
||||
raise HTTPException(status_code=404, detail=detail)
|
||||
if audio_path is None or not audio_path.exists():
|
||||
raise HTTPException(status_code=404, detail="Audio file not found")
|
||||
|
||||
return FileResponse(
|
||||
audio_path,
|
||||
@@ -77,7 +72,7 @@ async def get_sample_audio(sample_id: str, db: Session = Depends(get_db)):
|
||||
raise HTTPException(status_code=404, detail="Sample not found")
|
||||
|
||||
audio_path = config.resolve_storage_path(sample.audio_path)
|
||||
if audio_path is None or not audio_path.is_file():
|
||||
if audio_path is None or not audio_path.exists():
|
||||
raise HTTPException(status_code=404, detail="Audio file not found")
|
||||
|
||||
return FileResponse(
|
||||
|
||||
+89
-9
@@ -1,4 +1,4 @@
|
||||
"""Voicebox Cloud device login routes.
|
||||
"""Voicebox Cloud routes: device login + encrypted backup/sync.
|
||||
|
||||
The browser-based pairing flow:
|
||||
1. POST /cloud/login/start — opens the browser to the cloud authorize page.
|
||||
@@ -6,17 +6,31 @@ The browser-based pairing flow:
|
||||
the backend exchanges it for an API key.
|
||||
3. GET /cloud/status — the UI polls this to learn when it connected.
|
||||
4. POST /cloud/disconnect — forget the local credential.
|
||||
|
||||
Sync, once logged in:
|
||||
5. POST /cloud/sync/setup — register as an encryption device; on a keyless
|
||||
account this mints the master key and returns
|
||||
the recovery phrase (shown exactly once).
|
||||
6. POST /cloud/sync/restore — recover the master key from the phrase.
|
||||
7. POST /cloud/sync/adopt — pick up a wrapped key another device provisioned.
|
||||
8. GET /cloud/sync/status — identity state + cursor.
|
||||
9. POST /cloud/sync/run — one full push+pull pass.
|
||||
"""
|
||||
|
||||
import socket
|
||||
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||
from fastapi.responses import HTMLResponse
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .. import models
|
||||
from ..database import get_db
|
||||
from ..services import cloud as cloud_service
|
||||
from ..database import CloudSettings as DBCloudSettings, get_db
|
||||
from ..services import cloud as cloud_service, cloud_account, cloud_sync
|
||||
from ..services.cloud_account import CloudAccountError
|
||||
from ..services.cloud_api import CloudApiError
|
||||
from ..services.cloud_crypto import CloudCryptoError
|
||||
from ..services.cloud_keys import CloudKeyStoreError
|
||||
from ..services.cloud_sync import CloudSyncError
|
||||
|
||||
router = APIRouter(prefix="/cloud", tags=["cloud"])
|
||||
|
||||
@@ -44,11 +58,7 @@ async def cloud_callback(
|
||||
ok, message = await cloud_service.handle_callback(db, code=code, state=state)
|
||||
heading = "You're connected" if ok else "Couldn't connect"
|
||||
accent = "#16a34a" if ok else "#dc2626"
|
||||
sub = (
|
||||
"Voicebox is now linked to your account. You can close this tab and return to the app."
|
||||
if ok
|
||||
else message
|
||||
)
|
||||
sub = "Voicebox is now linked to your account. You can close this tab and return to the app." if ok else message
|
||||
html = f"""<!doctype html>
|
||||
<html lang="en"><head><meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
@@ -73,3 +83,73 @@ async def cloud_status(db: Session = Depends(get_db)):
|
||||
async def cloud_disconnect(db: Session = Depends(get_db)):
|
||||
cloud_service.disconnect(db)
|
||||
return models.CloudStatusResponse(**cloud_service.get_status(db))
|
||||
|
||||
|
||||
# ─── Encrypted backup & sync ─────────────────────────────────────────────
|
||||
|
||||
_SYNC_ERRORS = (CloudAccountError, CloudApiError, CloudCryptoError, CloudKeyStoreError, CloudSyncError)
|
||||
|
||||
|
||||
def _sync_status(db: Session) -> models.CloudSyncStatusResponse:
|
||||
identity = cloud_account.identity_status(db)
|
||||
row = db.query(DBCloudSettings).filter(DBCloudSettings.id == 1).first()
|
||||
return models.CloudSyncStatusResponse(
|
||||
status=identity.status,
|
||||
device_id=identity.device_id,
|
||||
sync_cursor=(row.sync_cursor or 0) if row else 0,
|
||||
)
|
||||
|
||||
|
||||
@router.post("/sync/setup", response_model=models.CloudSyncSetupResponse)
|
||||
async def cloud_sync_setup(db: Session = Depends(get_db)):
|
||||
try:
|
||||
phrase = await cloud_account.setup_device(db)
|
||||
identity = cloud_account.identity_status(db)
|
||||
except _SYNC_ERRORS as err:
|
||||
raise HTTPException(status_code=400, detail=str(err)) from err
|
||||
return models.CloudSyncSetupResponse(
|
||||
status=identity.status,
|
||||
device_id=identity.device_id,
|
||||
recovery_phrase=phrase,
|
||||
)
|
||||
|
||||
|
||||
@router.post("/sync/restore", response_model=models.CloudSyncStatusResponse)
|
||||
async def cloud_sync_restore(body: models.CloudRestoreRequest, db: Session = Depends(get_db)):
|
||||
try:
|
||||
await cloud_account.restore_with_phrase(db, body.phrase)
|
||||
except _SYNC_ERRORS as err:
|
||||
raise HTTPException(status_code=400, detail=str(err)) from err
|
||||
return _sync_status(db)
|
||||
|
||||
|
||||
@router.post("/sync/adopt", response_model=models.CloudSyncStatusResponse)
|
||||
async def cloud_sync_adopt(db: Session = Depends(get_db)):
|
||||
try:
|
||||
await cloud_account.adopt_wrapped_key(db)
|
||||
except _SYNC_ERRORS as err:
|
||||
raise HTTPException(status_code=400, detail=str(err)) from err
|
||||
return _sync_status(db)
|
||||
|
||||
|
||||
@router.get("/sync/status", response_model=models.CloudSyncStatusResponse)
|
||||
async def cloud_sync_status(db: Session = Depends(get_db)):
|
||||
try:
|
||||
return _sync_status(db)
|
||||
except CloudAccountError:
|
||||
return models.CloudSyncStatusResponse(status="unregistered", device_id=None, sync_cursor=0)
|
||||
|
||||
|
||||
@router.post("/sync/run", response_model=models.CloudSyncRunResponse)
|
||||
async def cloud_sync_run(db: Session = Depends(get_db)):
|
||||
try:
|
||||
report = await cloud_sync.run_sync(db)
|
||||
except _SYNC_ERRORS as err:
|
||||
raise HTTPException(status_code=400, detail=str(err)) from err
|
||||
return models.CloudSyncRunResponse(
|
||||
pushed=report.pushed,
|
||||
pushed_deletes=report.pushed_deletes,
|
||||
pulled=report.pulled,
|
||||
pulled_deletes=report.pulled_deletes,
|
||||
cursor=report.cursor,
|
||||
)
|
||||
|
||||
@@ -26,10 +26,6 @@ async def download_cuda_backend():
|
||||
"""Download the CUDA backend binary."""
|
||||
from ..services import cuda
|
||||
|
||||
unsupported_reason = cuda.get_cuda_download_unsupported_reason()
|
||||
if unsupported_reason:
|
||||
raise HTTPException(status_code=409, detail=unsupported_reason)
|
||||
|
||||
if cuda.get_cuda_binary_path() is not None:
|
||||
raise HTTPException(status_code=409, detail="CUDA backend already downloaded")
|
||||
|
||||
|
||||
@@ -321,13 +321,7 @@ async def stream_speech(
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""Generate speech and stream the WAV audio directly without saving to disk."""
|
||||
from ..backends import (
|
||||
engine_needs_trim,
|
||||
engine_retries_runaway,
|
||||
ensure_model_cached_or_raise,
|
||||
get_tts_backend_for_engine,
|
||||
load_engine_model,
|
||||
)
|
||||
from ..backends import get_tts_backend_for_engine, ensure_model_cached_or_raise, load_engine_model, engine_needs_trim
|
||||
|
||||
profile = await profiles.get_profile(data.profile_id, db)
|
||||
if not profile:
|
||||
@@ -353,15 +347,10 @@ async def stream_speech(
|
||||
from ..utils.chunked_tts import generate_chunked
|
||||
|
||||
trim_fn = None
|
||||
runaway_detector = None
|
||||
if engine_needs_trim(engine):
|
||||
from ..utils.audio import trim_tts_output
|
||||
|
||||
trim_fn = trim_tts_output
|
||||
if engine_retries_runaway(engine):
|
||||
from ..utils.audio import has_tts_runaway
|
||||
|
||||
runaway_detector = has_tts_runaway
|
||||
|
||||
audio, sample_rate = await generate_chunked(
|
||||
tts_model,
|
||||
@@ -373,7 +362,6 @@ async def stream_speech(
|
||||
max_chunk_chars=data.max_chunk_chars,
|
||||
crossfade_ms=data.crossfade_ms,
|
||||
trim_fn=trim_fn,
|
||||
runaway_detector=runaway_detector,
|
||||
)
|
||||
|
||||
effects_chain_config = None
|
||||
|
||||
@@ -13,7 +13,7 @@ from sqlalchemy.orm import Session
|
||||
from .. import config, models
|
||||
from ..services import tts
|
||||
from ..database import get_db
|
||||
from ..utils.platform_detect import get_backend_type, is_amd_gpu_windows
|
||||
from ..utils.platform_detect import get_backend_type
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -103,10 +103,7 @@ async def health():
|
||||
|
||||
gpu_type = None
|
||||
if has_cuda:
|
||||
if hasattr(torch.version, "hip") and torch.version.hip:
|
||||
gpu_type = f"ROCm ({torch.cuda.get_device_name(0)})"
|
||||
else:
|
||||
gpu_type = f"CUDA ({torch.cuda.get_device_name(0)})"
|
||||
gpu_type = f"CUDA ({torch.cuda.get_device_name(0)})"
|
||||
elif has_mps:
|
||||
gpu_type = "MPS (Apple Silicon)"
|
||||
elif backend_type == "mlx":
|
||||
@@ -167,15 +164,6 @@ async def health():
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
default_variant = "cpu"
|
||||
if has_cuda:
|
||||
if hasattr(torch.version, "hip") and torch.version.hip:
|
||||
default_variant = "rocm"
|
||||
else:
|
||||
default_variant = "cuda"
|
||||
elif has_xpu:
|
||||
default_variant = "xpu"
|
||||
|
||||
return models.HealthResponse(
|
||||
status="healthy",
|
||||
model_loaded=model_loaded,
|
||||
@@ -185,8 +173,10 @@ async def health():
|
||||
gpu_type=gpu_type,
|
||||
vram_used_mb=vram_used,
|
||||
backend_type=backend_type,
|
||||
backend_variant=os.environ.get("VOICEBOX_BACKEND_VARIANT", default_variant),
|
||||
supports_rocm=is_amd_gpu_windows(),
|
||||
backend_variant=os.environ.get(
|
||||
"VOICEBOX_BACKEND_VARIANT",
|
||||
"cuda" if torch.cuda.is_available() else ("xpu" if has_xpu else "cpu"),
|
||||
),
|
||||
gpu_compatibility_warning=gpu_compat_warning,
|
||||
)
|
||||
|
||||
|
||||
@@ -151,9 +151,7 @@ async def export_generation(
|
||||
safe_text = "".join(c for c in generation.text[:30] if c.isalnum() or c in (" ", "-", "_")).strip()
|
||||
if not safe_text:
|
||||
safe_text = "generation"
|
||||
# Append a short id so exports of similarly-worded generations don't collide
|
||||
# on the same filename (the first 30 chars are frequently identical).
|
||||
filename = f"generation-{safe_text}-{generation_id[:8]}.voicebox.zip"
|
||||
filename = f"generation-{safe_text}.voicebox.zip"
|
||||
|
||||
return StreamingResponse(
|
||||
io.BytesIO(zip_bytes),
|
||||
@@ -182,9 +180,7 @@ async def export_generation_audio(
|
||||
safe_text = "".join(c for c in generation.text[:30] if c.isalnum() or c in (" ", "-", "_")).strip()
|
||||
if not safe_text:
|
||||
safe_text = "generation"
|
||||
# Append a short id so exports of similarly-worded generations don't collide
|
||||
# on the same filename (the first 30 chars are frequently identical).
|
||||
filename = f"{safe_text}-{generation_id[:8]}.wav"
|
||||
filename = f"{safe_text}.wav"
|
||||
|
||||
return FileResponse(
|
||||
audio_path,
|
||||
|
||||
@@ -231,10 +231,7 @@ async def get_model_status():
|
||||
backend_type = get_backend_type()
|
||||
task_manager = get_task_manager()
|
||||
|
||||
# Pending only — an errored task stays in the active list for the
|
||||
# error/retry UI, but reporting it as "downloading" here would mask
|
||||
# the model's real cache state until the app restarts (issue #925).
|
||||
active_download_names = {task.model_name for task in task_manager.get_pending_downloads()}
|
||||
active_download_names = {task.model_name for task in task_manager.get_active_downloads()}
|
||||
|
||||
try:
|
||||
from huggingface_hub import scan_cache_dir
|
||||
|
||||
@@ -232,7 +232,7 @@ async def upload_profile_avatar(
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""Upload or update avatar image for a profile."""
|
||||
with tempfile.NamedTemporaryFile(delete=False, suffix=Path(file.filename or "").suffix) as tmp:
|
||||
with tempfile.NamedTemporaryFile(delete=False, suffix=Path(file.filename).suffix) as tmp:
|
||||
content = await file.read()
|
||||
tmp.write(content)
|
||||
tmp_path = tmp.name
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
"""ROCm backend management endpoints."""
|
||||
|
||||
import logging
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi.responses import StreamingResponse
|
||||
|
||||
from ..services.task_queue import create_background_task
|
||||
from ..utils.progress import get_progress_manager
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@router.get("/backend/rocm-status")
|
||||
async def get_rocm_status():
|
||||
"""Get ROCm backend download/availability status."""
|
||||
from ..services import rocm
|
||||
|
||||
return rocm.get_rocm_status()
|
||||
|
||||
|
||||
@router.post("/backend/download-rocm")
|
||||
async def download_rocm_backend():
|
||||
"""Download the ROCm backend binary."""
|
||||
from ..services import rocm
|
||||
|
||||
progress_manager = get_progress_manager()
|
||||
existing = progress_manager.get_progress(rocm.PROGRESS_KEY)
|
||||
if existing and existing.get("status") in {"downloading", "extracting"}:
|
||||
raise HTTPException(status_code=409, detail="ROCm backend download already in progress")
|
||||
|
||||
async def _download():
|
||||
try:
|
||||
await rocm.download_rocm_binary()
|
||||
except Exception as e:
|
||||
logger.error("ROCm download failed: %s", e)
|
||||
|
||||
create_background_task(_download())
|
||||
return {"message": "ROCm backend download started", "progress_key": rocm.PROGRESS_KEY}
|
||||
|
||||
|
||||
@router.delete("/backend/rocm")
|
||||
async def delete_rocm_backend():
|
||||
"""Delete the downloaded ROCm backend binary."""
|
||||
from ..services import rocm
|
||||
|
||||
if rocm.is_rocm_active():
|
||||
raise HTTPException(
|
||||
status_code=409,
|
||||
detail="Cannot delete ROCm backend while it is active. Switch to CPU first.",
|
||||
)
|
||||
|
||||
deleted = await rocm.delete_rocm_binary()
|
||||
if not deleted:
|
||||
raise HTTPException(status_code=404, detail="No ROCm backend found to delete")
|
||||
|
||||
return {"message": "ROCm backend deleted"}
|
||||
|
||||
|
||||
@router.get("/backend/rocm-progress")
|
||||
async def get_rocm_download_progress():
|
||||
"""Get ROCm backend download progress via Server-Sent Events."""
|
||||
progress_manager = get_progress_manager()
|
||||
|
||||
async def event_generator():
|
||||
async for event in progress_manager.subscribe("rocm-backend"):
|
||||
yield event
|
||||
|
||||
return StreamingResponse(
|
||||
event_generator(),
|
||||
media_type="text/event-stream",
|
||||
headers={
|
||||
"Cache-Control": "no-cache",
|
||||
"Connection": "keep-alive",
|
||||
"X-Accel-Buffering": "no",
|
||||
},
|
||||
)
|
||||
@@ -15,10 +15,6 @@ router = APIRouter()
|
||||
|
||||
UPLOAD_CHUNK_SIZE = 1024 * 1024 # 1MB
|
||||
|
||||
# Same set profiles.py accepts for voice samples. librosa picks its decoder from the
|
||||
# file extension, so the temp file has to keep the uploaded one.
|
||||
ALLOWED_AUDIO_EXTS = {".wav", ".mp3", ".m4a", ".ogg", ".flac", ".aac", ".webm", ".opus"}
|
||||
|
||||
|
||||
@router.post("/transcribe", response_model=models.TranscriptionResponse)
|
||||
async def transcribe_audio(
|
||||
@@ -27,33 +23,18 @@ async def transcribe_audio(
|
||||
model: str | None = Form(None),
|
||||
):
|
||||
"""Transcribe audio file to text."""
|
||||
uploaded_ext = Path(file.filename or "").suffix.lower()
|
||||
file_suffix = uploaded_ext if uploaded_ext in ALLOWED_AUDIO_EXTS else ".wav"
|
||||
|
||||
with tempfile.NamedTemporaryFile(suffix=file_suffix, delete=False) as tmp:
|
||||
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp:
|
||||
while chunk := await file.read(UPLOAD_CHUNK_SIZE):
|
||||
tmp.write(chunk)
|
||||
tmp_path = tmp.name
|
||||
|
||||
stt_path = tmp_path
|
||||
try:
|
||||
from ..utils.audio import load_audio, save_audio
|
||||
from ..utils.audio import load_audio
|
||||
from ..backends import WHISPER_HF_REPOS
|
||||
|
||||
audio, sr = await asyncio.to_thread(load_audio, tmp_path)
|
||||
duration = len(audio) / sr
|
||||
|
||||
# The STT backend (mlx_audio.stt -> miniaudio) only decodes
|
||||
# WAV/FLAC/MP3/Vorbis, so browser recordings uploaded as WebM/Opus
|
||||
# fail with "unsupported file format" (issue: web-mode dictation).
|
||||
# librosa already decoded the file above (it falls back to
|
||||
# audioread/ffmpeg for exotic containers), so re-encode that PCM to a
|
||||
# temp WAV and hand *that* to Whisper. WAV inputs pass through
|
||||
# unchanged.
|
||||
if file_suffix != ".wav":
|
||||
stt_path = f"{tmp_path}.stt.wav"
|
||||
await asyncio.to_thread(save_audio, audio, stt_path, sr)
|
||||
|
||||
whisper_model = transcribe.get_whisper_model()
|
||||
model_size = model if model else whisper_model.model_size
|
||||
|
||||
@@ -88,7 +69,7 @@ async def transcribe_audio(
|
||||
},
|
||||
)
|
||||
|
||||
text = await whisper_model.transcribe(stt_path, language, model_size)
|
||||
text = await whisper_model.transcribe(tmp_path, language, model_size)
|
||||
|
||||
return models.TranscriptionResponse(
|
||||
text=text,
|
||||
@@ -101,5 +82,3 @@ async def transcribe_audio(
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
finally:
|
||||
Path(tmp_path).unlink(missing_ok=True)
|
||||
if stt_path != tmp_path:
|
||||
Path(stt_path).unlink(missing_ok=True)
|
||||
|
||||
+10
-13
@@ -7,7 +7,6 @@ absolute imports instead of relative imports.
|
||||
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
|
||||
# On Windows with --noconsole (PyInstaller), sys.stdout/stderr are None.
|
||||
# They can also be broken file objects in some edge cases.
|
||||
@@ -48,17 +47,6 @@ if "--version" in sys.argv:
|
||||
print(f"voicebox-server {__version__}")
|
||||
sys.exit(0)
|
||||
|
||||
# Detect backend variant from binary name BEFORE importing backend modules
|
||||
# so that env-var guards in app.py (e.g. HSA_OVERRIDE_GFX_VERSION) fire at import time.
|
||||
_binary_name = os.path.basename(sys.executable).lower()
|
||||
if re.search(r"voicebox-server-rocm(\.exe)?$", _binary_name):
|
||||
os.environ["VOICEBOX_BACKEND_VARIANT"] = "rocm"
|
||||
elif re.search(r"voicebox-server-cuda(\.exe)?$", _binary_name):
|
||||
os.environ["VOICEBOX_BACKEND_VARIANT"] = "cuda"
|
||||
else:
|
||||
os.environ.setdefault("VOICEBOX_BACKEND_VARIANT", "cpu")
|
||||
|
||||
|
||||
import logging
|
||||
|
||||
# Set up logging FIRST, before any imports that might fail
|
||||
@@ -272,7 +260,16 @@ if __name__ == "__main__":
|
||||
if args.parent_pid is not None and args.parent_pid <= 0:
|
||||
parser.error("--parent-pid must be a positive integer")
|
||||
|
||||
logger.info(f"Backend variant: {os.environ.get('VOICEBOX_BACKEND_VARIANT', 'cpu').upper()}")
|
||||
# Detect backend variant from binary name
|
||||
# voicebox-server-cuda → sets VOICEBOX_BACKEND_VARIANT=cuda
|
||||
import os
|
||||
binary_name = os.path.basename(sys.executable).lower()
|
||||
if "cuda" in binary_name:
|
||||
os.environ["VOICEBOX_BACKEND_VARIANT"] = "cuda"
|
||||
logger.info("Backend variant: CUDA")
|
||||
else:
|
||||
os.environ["VOICEBOX_BACKEND_VARIANT"] = "cpu"
|
||||
logger.info("Backend variant: CPU")
|
||||
|
||||
# Register parent watchdog to start after server is fully ready
|
||||
if args.parent_pid is not None:
|
||||
|
||||
@@ -19,7 +19,6 @@ import webbrowser
|
||||
from urllib.parse import urlencode
|
||||
|
||||
import httpx
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .. import config
|
||||
@@ -42,15 +41,6 @@ def _prune() -> None:
|
||||
_pending.pop(state, None)
|
||||
|
||||
|
||||
def _json_dict(response: httpx.Response) -> dict | None:
|
||||
"""Parsed JSON body, or None when it isn't a JSON object."""
|
||||
try:
|
||||
payload = response.json()
|
||||
except ValueError:
|
||||
return None
|
||||
return payload if isinstance(payload, dict) else None
|
||||
|
||||
|
||||
def _consume_state(state: str) -> bool:
|
||||
"""Validate and single-use-consume a pending state."""
|
||||
_prune()
|
||||
@@ -94,10 +84,7 @@ async def handle_callback(db: Session, code: str, state: str) -> tuple[bool, str
|
||||
if exchanged.status_code != 200:
|
||||
logger.warning("cloud exchange rejected code: %s", exchanged.status_code)
|
||||
return False, "Could not complete sign-in — the code was rejected."
|
||||
payload = _json_dict(exchanged)
|
||||
if payload is None:
|
||||
logger.warning("cloud exchange returned a non-JSON payload")
|
||||
return False, "Voicebox Cloud returned an unexpected response."
|
||||
payload = exchanged.json()
|
||||
api_key = payload.get("key")
|
||||
device_name = payload.get("label")
|
||||
if not api_key:
|
||||
@@ -111,9 +98,7 @@ async def handle_callback(db: Session, code: str, state: str) -> tuple[bool, str
|
||||
if me.status_code != 200:
|
||||
logger.warning("minted key failed verification: %s", me.status_code)
|
||||
return False, "Sign-in succeeded but the key could not be verified."
|
||||
# The 200 above proves the key works; the user id is best-effort.
|
||||
data = (_json_dict(me) or {}).get("data")
|
||||
account_user_id = data.get("userId") if isinstance(data, dict) else None
|
||||
account_user_id = (me.json().get("data") or {}).get("userId")
|
||||
except httpx.HTTPError:
|
||||
logger.exception("network error during cloud exchange")
|
||||
return False, "Could not reach Voicebox Cloud. Check your connection and try again."
|
||||
@@ -128,14 +113,8 @@ def _get_or_create_row(db: Session) -> DBCloudSettings:
|
||||
if row is None:
|
||||
row = DBCloudSettings(id=SINGLETON_ID)
|
||||
db.add(row)
|
||||
try:
|
||||
db.commit()
|
||||
except IntegrityError:
|
||||
# Another request created the singleton concurrently.
|
||||
db.rollback()
|
||||
row = db.query(DBCloudSettings).filter(DBCloudSettings.id == SINGLETON_ID).one()
|
||||
else:
|
||||
db.refresh(row)
|
||||
db.commit()
|
||||
db.refresh(row)
|
||||
return row
|
||||
|
||||
|
||||
@@ -162,7 +141,6 @@ def get_status(db: Session) -> dict:
|
||||
"account_user_id": row.account_user_id if connected else None,
|
||||
"key_prefix": key_prefix,
|
||||
"connected_at": row.connected_at if connected else None,
|
||||
"dashboard_url": f"{config.get_cloud_web_url()}/account",
|
||||
}
|
||||
|
||||
|
||||
@@ -171,7 +149,6 @@ def disconnect(db: Session) -> None:
|
||||
revoked from the account dashboard — surface that in the UI."""
|
||||
row = _get_or_create_row(db)
|
||||
row.api_key = None
|
||||
row.device_name = None
|
||||
row.account_user_id = None
|
||||
row.connected_at = None
|
||||
db.commit()
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
"""
|
||||
Cloud sync identity: the Master Key lifecycle across devices.
|
||||
|
||||
Ties together the pieces below into the flows from the cloud design doc §9
|
||||
(first device, add-a-device, recovery). The server participates only as a
|
||||
mailbox for ciphertext — every wrap/unwrap here happens locally.
|
||||
|
||||
- ``cloud_crypto`` — the primitives (MK, recovery phrase, sealed boxes)
|
||||
- ``cloud_keys`` — OS-keychain persistence of the private key + MK
|
||||
- ``cloud_api`` — the bearer-key HTTP client
|
||||
- ``CloudSettings`` — the local row holding the API key + sync device id
|
||||
|
||||
Flows:
|
||||
- **First device** (``setup_device`` on a keyless account): generate MK, wrap
|
||||
it under a fresh recovery phrase → escrow to the server, wrap it to our own
|
||||
device key, keep MK in the keychain. Returns the phrase for one-time display.
|
||||
- **New device on an existing account** (``setup_device`` when the account has
|
||||
key material): register and wait — an existing device provisions us
|
||||
(``provision_device`` there, ``adopt_wrapped_key`` here), or the user types
|
||||
the recovery phrase (``restore_with_phrase``).
|
||||
"""
|
||||
|
||||
import base64
|
||||
import logging
|
||||
from dataclasses import dataclass
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .. import config
|
||||
from ..database import CloudSettings as DBCloudSettings
|
||||
from . import cloud_crypto, cloud_keys
|
||||
from .cloud_api import CloudApiClient
|
||||
from .cloud_crypto import RecoveryWrap
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CloudAccountError(Exception):
|
||||
"""The identity flow cannot proceed (not connected, no escrow, bad phrase…)."""
|
||||
|
||||
|
||||
def _b64e(raw: bytes) -> str:
|
||||
return base64.b64encode(raw).decode("ascii")
|
||||
|
||||
|
||||
def _b64d(encoded: str) -> bytes:
|
||||
return base64.b64decode(encoded)
|
||||
|
||||
|
||||
def _settings(db: Session) -> DBCloudSettings:
|
||||
row = db.query(DBCloudSettings).filter(DBCloudSettings.id == 1).first()
|
||||
if row is None or not row.api_key or not row.account_user_id:
|
||||
raise CloudAccountError("not connected to Voicebox Cloud — log in first")
|
||||
return row
|
||||
|
||||
|
||||
def _client(row: DBCloudSettings) -> CloudApiClient:
|
||||
return CloudApiClient(config.get_cloud_api_url(), row.api_key)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class SyncIdentity:
|
||||
# "unregistered" — logged in, but not yet a sync device
|
||||
# "awaiting_provision" — registered, waiting for a wrapped MK or the phrase
|
||||
# "ready" — MK in the keychain, sync can run
|
||||
status: str
|
||||
device_id: str | None
|
||||
|
||||
|
||||
def identity_status(db: Session) -> SyncIdentity:
|
||||
row = _settings(db)
|
||||
if not row.sync_device_id:
|
||||
return SyncIdentity(status="unregistered", device_id=None)
|
||||
has_mk = cloud_keys.load_secret(row.account_user_id, cloud_keys.MASTER_KEY) is not None
|
||||
return SyncIdentity(status="ready" if has_mk else "awaiting_provision", device_id=row.sync_device_id)
|
||||
|
||||
|
||||
async def setup_device(db: Session) -> str | None:
|
||||
"""Register this install as a sync device.
|
||||
|
||||
On a keyless account this is first-device setup: mints MK + the recovery
|
||||
escrow and returns the phrase — the caller must display it exactly once and
|
||||
never persist it. On an account with existing key material it returns None
|
||||
and the device waits in ``awaiting_provision``.
|
||||
"""
|
||||
row = _settings(db)
|
||||
if row.sync_device_id:
|
||||
raise CloudAccountError("this install is already registered as a sync device")
|
||||
|
||||
private_key, public_key = cloud_crypto.generate_device_keypair()
|
||||
async with _client(row) as client:
|
||||
registered = await client.register_device(row.device_name or "Voicebox Desktop", _b64e(public_key))
|
||||
device_id = registered["deviceId"]
|
||||
|
||||
# Persist the private key before anything can depend on it; a crash
|
||||
# after registration leaves a provisionable device, never a locked one.
|
||||
cloud_keys.store_secret(row.account_user_id, cloud_keys.DEVICE_PRIVATE_KEY, private_key)
|
||||
row.sync_device_id = device_id
|
||||
db.commit()
|
||||
|
||||
if registered["accountHasKey"]:
|
||||
logger.info("registered sync device %s; awaiting MK provisioning", device_id)
|
||||
return None
|
||||
|
||||
master_key = cloud_crypto.generate_master_key()
|
||||
phrase = cloud_crypto.generate_recovery_phrase()
|
||||
escrow = cloud_crypto.wrap_master_key_with_phrase(master_key, phrase)
|
||||
await client.put_account_key(_b64e(escrow.wrapped_key), _b64e(escrow.kdf_salt), escrow.kdf_params)
|
||||
await client.put_wrapped_key(device_id, _b64e(cloud_crypto.wrap_master_key_for_device(master_key, public_key)))
|
||||
cloud_keys.store_secret(row.account_user_id, cloud_keys.MASTER_KEY, master_key)
|
||||
logger.info("initialized account key material as first device %s", device_id)
|
||||
return phrase
|
||||
|
||||
|
||||
async def restore_with_phrase(db: Session, phrase: str) -> None:
|
||||
"""Recover MK from the server-side escrow using the recovery phrase.
|
||||
The device must be registered (``setup_device``) first."""
|
||||
row = _settings(db)
|
||||
if not row.sync_device_id:
|
||||
raise CloudAccountError("register this device before restoring")
|
||||
if not cloud_crypto.validate_recovery_phrase(phrase):
|
||||
raise CloudAccountError("that doesn't look like a valid recovery phrase — check for typos")
|
||||
|
||||
async with _client(row) as client:
|
||||
escrow = await client.get_account_key()
|
||||
if not escrow:
|
||||
raise CloudAccountError("this account has no recovery escrow yet")
|
||||
wrap = RecoveryWrap(
|
||||
wrapped_key=_b64d(escrow["recoveryWrappedKey"]),
|
||||
kdf_salt=_b64d(escrow["kdfSalt"]),
|
||||
kdf_params=escrow["kdfParams"],
|
||||
)
|
||||
master_key = cloud_crypto.unwrap_master_key_with_phrase(wrap, phrase)
|
||||
|
||||
# Also wrap MK to our own device key so future restores on this device
|
||||
# don't need the phrase.
|
||||
private_key = cloud_keys.load_secret(row.account_user_id, cloud_keys.DEVICE_PRIVATE_KEY)
|
||||
if private_key is None:
|
||||
raise CloudAccountError("device key missing from the OS keychain — register this device again")
|
||||
public_key = cloud_crypto.device_public_key(private_key)
|
||||
await client.put_wrapped_key(
|
||||
row.sync_device_id, _b64e(cloud_crypto.wrap_master_key_for_device(master_key, public_key))
|
||||
)
|
||||
cloud_keys.store_secret(row.account_user_id, cloud_keys.MASTER_KEY, master_key)
|
||||
logger.info("restored master key from recovery phrase on device %s", row.sync_device_id)
|
||||
|
||||
|
||||
async def adopt_wrapped_key(db: Session) -> bool:
|
||||
"""For a device in ``awaiting_provision``: fetch our wrapped MK if an
|
||||
existing device has provisioned it. Returns True once MK is in the keychain."""
|
||||
row = _settings(db)
|
||||
if not row.sync_device_id:
|
||||
raise CloudAccountError("register this device before adopting a key")
|
||||
|
||||
private_key = cloud_keys.load_secret(row.account_user_id, cloud_keys.DEVICE_PRIVATE_KEY)
|
||||
if private_key is None:
|
||||
raise CloudAccountError("device key missing from the OS keychain — register this device again")
|
||||
|
||||
async with _client(row) as client:
|
||||
wrapped = await client.get_wrapped_key(row.sync_device_id)
|
||||
if not wrapped:
|
||||
return False
|
||||
master_key = cloud_crypto.unwrap_master_key_for_device(_b64d(wrapped), private_key)
|
||||
cloud_keys.store_secret(row.account_user_id, cloud_keys.MASTER_KEY, master_key)
|
||||
logger.info("adopted provisioned master key on device %s", row.sync_device_id)
|
||||
return True
|
||||
|
||||
|
||||
async def provision_device(db: Session, target_device_id: str) -> None:
|
||||
"""Run on a device that already holds MK: wrap it to another registered
|
||||
device's public key so that device can start syncing."""
|
||||
row = _settings(db)
|
||||
master_key = cloud_keys.load_secret(row.account_user_id, cloud_keys.MASTER_KEY)
|
||||
if master_key is None:
|
||||
raise CloudAccountError("this device holds no master key to provision with")
|
||||
|
||||
async with _client(row) as client:
|
||||
devices = await client.list_devices()
|
||||
target = next((d for d in devices if d["id"] == target_device_id and not d.get("revokedAt")), None)
|
||||
if target is None:
|
||||
raise CloudAccountError("target device not found (or revoked)")
|
||||
wrapped = cloud_crypto.wrap_master_key_for_device(master_key, _b64d(target["publicKey"]))
|
||||
await client.put_wrapped_key(target_device_id, _b64e(wrapped))
|
||||
logger.info("provisioned master key to device %s", target_device_id)
|
||||
|
||||
|
||||
def load_master_key(db: Session) -> bytes:
|
||||
"""The MK for the sync engine. Raises if this device isn't ready."""
|
||||
row = _settings(db)
|
||||
master_key = cloud_keys.load_secret(row.account_user_id, cloud_keys.MASTER_KEY)
|
||||
if master_key is None:
|
||||
raise CloudAccountError("no master key on this device — finish setup or restore first")
|
||||
return master_key
|
||||
@@ -0,0 +1,174 @@
|
||||
"""
|
||||
HTTP client for the Voicebox Cloud API (api.voicebox.sh).
|
||||
|
||||
A thin async wrapper over the bearer-key endpoints the sync client needs:
|
||||
device/key distribution, the encrypted object store, and the sync feed. Every
|
||||
payload sent through here is ciphertext or metadata about ciphertext — the
|
||||
encryption itself happens in ``cloud_crypto`` before bytes reach this module.
|
||||
|
||||
Blob bytes don't flow through the API at all: pushes receive presigned PUT
|
||||
URLs and pulls receive presigned GET URLs, and the client transfers ciphertext
|
||||
directly with the storage host. Those transfers use a separate unauthenticated
|
||||
HTTP client so the bearer key is never sent to the storage host.
|
||||
"""
|
||||
|
||||
import contextlib
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_TIMEOUT = 30.0
|
||||
_BLOB_TIMEOUT = 120.0 # audio assets can be tens of MB
|
||||
|
||||
|
||||
class CloudApiError(Exception):
|
||||
def __init__(self, message: str, status: int | None = None):
|
||||
super().__init__(message)
|
||||
self.status = status
|
||||
|
||||
|
||||
class CloudApiClient:
|
||||
"""One authenticated session against the cloud API. Use as an async context
|
||||
manager so both underlying connection pools are closed."""
|
||||
|
||||
def __init__(self, api_url: str, api_key: str, *, transport: httpx.AsyncBaseTransport | None = None):
|
||||
self._api = httpx.AsyncClient(
|
||||
base_url=api_url.rstrip("/"),
|
||||
headers={"Authorization": f"Bearer {api_key}"},
|
||||
timeout=_TIMEOUT,
|
||||
transport=transport,
|
||||
)
|
||||
# Presigned-URL transfers: no Authorization header, longer timeout.
|
||||
self._blobs = httpx.AsyncClient(timeout=_BLOB_TIMEOUT, transport=transport)
|
||||
|
||||
async def __aenter__(self) -> "CloudApiClient":
|
||||
return self
|
||||
|
||||
async def __aexit__(self, *exc: object) -> None:
|
||||
await self.aclose()
|
||||
|
||||
async def aclose(self) -> None:
|
||||
await self._api.aclose()
|
||||
await self._blobs.aclose()
|
||||
|
||||
async def _call(
|
||||
self,
|
||||
method: str,
|
||||
path: str,
|
||||
*,
|
||||
json: dict | None = None,
|
||||
params: dict | None = None,
|
||||
) -> Any:
|
||||
try:
|
||||
resp = await self._api.request(method, path, json=json, params=params)
|
||||
except httpx.HTTPError as err:
|
||||
raise CloudApiError(f"could not reach Voicebox Cloud: {err}") from err
|
||||
if resp.status_code >= 400:
|
||||
message = f"{method} {path} failed ({resp.status_code})"
|
||||
with contextlib.suppress(ValueError):
|
||||
message = resp.json().get("error", {}).get("message", message)
|
||||
raise CloudApiError(message, status=resp.status_code)
|
||||
payload = resp.json()
|
||||
if not payload.get("ok"):
|
||||
raise CloudApiError(f"{method} {path} returned ok=false", status=resp.status_code)
|
||||
return payload.get("data")
|
||||
|
||||
# -- account ------------------------------------------------------------
|
||||
|
||||
async def me(self) -> dict:
|
||||
return await self._call("GET", "/v1/account/me")
|
||||
|
||||
# -- devices & key distribution ------------------------------------------
|
||||
|
||||
async def register_device(self, name: str, public_key_b64: str) -> dict:
|
||||
"""Returns {deviceId, accountHasKey}."""
|
||||
return await self._call("POST", "/v1/devices", json={"name": name, "publicKey": public_key_b64})
|
||||
|
||||
async def list_devices(self) -> list[dict]:
|
||||
return await self._call("GET", "/v1/devices")
|
||||
|
||||
async def put_wrapped_key(self, device_id: str, wrapped_master_key_b64: str) -> None:
|
||||
await self._call(
|
||||
"POST",
|
||||
f"/v1/devices/{device_id}/wrapped-key",
|
||||
json={"wrappedMasterKey": wrapped_master_key_b64},
|
||||
)
|
||||
|
||||
async def get_wrapped_key(self, device_id: str) -> str | None:
|
||||
data = await self._call("GET", f"/v1/devices/{device_id}/wrapped-key")
|
||||
return data.get("wrappedMasterKey") if data else None
|
||||
|
||||
async def put_account_key(self, recovery_wrapped_key_b64: str, kdf_salt_b64: str, kdf_params: str) -> None:
|
||||
await self._call(
|
||||
"PUT",
|
||||
"/v1/devices/account-key",
|
||||
json={
|
||||
"recoveryWrappedKey": recovery_wrapped_key_b64,
|
||||
"kdfSalt": kdf_salt_b64,
|
||||
"kdfParams": kdf_params,
|
||||
},
|
||||
)
|
||||
|
||||
async def get_account_key(self) -> dict | None:
|
||||
"""Returns {recoveryWrappedKey, kdfSalt, kdfParams} or None if the
|
||||
account has no escrow yet."""
|
||||
return await self._call("GET", "/v1/devices/account-key")
|
||||
|
||||
# -- encrypted object store ----------------------------------------------
|
||||
|
||||
async def push_object(
|
||||
self,
|
||||
*,
|
||||
kind: str,
|
||||
client_id: str,
|
||||
version: int,
|
||||
record: dict | None,
|
||||
assets: list[dict] | None = None,
|
||||
) -> dict:
|
||||
"""Upsert object metadata. ``record`` is {hash, size}; each asset is
|
||||
{role, clientAssetId, hash, size}. Returns {objectId, seq, uploads},
|
||||
where uploads lists presigned PUT URLs for exactly the changed blobs."""
|
||||
return await self._call(
|
||||
"POST",
|
||||
"/v1/objects",
|
||||
json={
|
||||
"kind": kind,
|
||||
"clientId": client_id,
|
||||
"version": version,
|
||||
"record": record,
|
||||
"assets": assets or [],
|
||||
},
|
||||
)
|
||||
|
||||
async def commit_object(self, object_id: str) -> None:
|
||||
"""Ask the server to verify all claimed blobs actually landed in storage."""
|
||||
await self._call("POST", f"/v1/objects/{object_id}/commit")
|
||||
|
||||
async def delete_object(self, object_id: str) -> None:
|
||||
await self._call("DELETE", f"/v1/objects/{object_id}")
|
||||
|
||||
async def get_changes(self, since: int, limit: int = 200) -> dict:
|
||||
"""Sync pull: {changes, cursor, hasMore} for everything newer than ``since``."""
|
||||
return await self._call("GET", "/v1/sync/changes", params={"since": since, "limit": limit})
|
||||
|
||||
# -- blob transfer (presigned URLs, ciphertext only) ----------------------
|
||||
|
||||
async def upload_blob(self, url: str, data: bytes) -> None:
|
||||
try:
|
||||
resp = await self._blobs.put(url, content=data, headers={"Content-Type": "application/octet-stream"})
|
||||
except httpx.HTTPError as err:
|
||||
raise CloudApiError(f"blob upload failed: {err}") from err
|
||||
if resp.status_code >= 400:
|
||||
raise CloudApiError(f"blob upload rejected ({resp.status_code})", status=resp.status_code)
|
||||
|
||||
async def download_blob(self, url: str) -> bytes:
|
||||
try:
|
||||
resp = await self._blobs.get(url)
|
||||
except httpx.HTTPError as err:
|
||||
raise CloudApiError(f"blob download failed: {err}") from err
|
||||
if resp.status_code >= 400:
|
||||
raise CloudApiError(f"blob download rejected ({resp.status_code})", status=resp.status_code)
|
||||
return resp.content
|
||||
@@ -0,0 +1,233 @@
|
||||
"""
|
||||
Client-side cryptography for Voicebox Cloud backup & sync.
|
||||
|
||||
This is the auditable half of the cloud's privacy promise: every byte that
|
||||
leaves this machine is encrypted here first, and the server only ever stores
|
||||
ciphertext plus routing metadata. The key hierarchy (cloud repo,
|
||||
``docs/DESIGN.md``):
|
||||
|
||||
Recovery phrase (BIP39) Device X25519 keypairs
|
||||
| Argon2id(salt, params) | sealed box
|
||||
v v
|
||||
Recovery KEK --wrap--> Master Key (MK) <--wrapped to each device
|
||||
|
|
||||
| per-blob random Content Key (CK),
|
||||
| wrapped by MK inside the envelope
|
||||
v
|
||||
XChaCha20-Poly1305(CK) over each record/asset blob
|
||||
|
||||
Everything in this module is a pure function over bytes — no I/O, no storage,
|
||||
no network. Key persistence (OS keychain) and the sync engine live elsewhere.
|
||||
|
||||
Invariants this module enforces:
|
||||
- The Master Key is random, never derived from anything the server holds
|
||||
(API keys and wallet keys are auth/entitlement, never encryption roots).
|
||||
- Each blob's AAD binds it to its logical slot (object, role, version), so a
|
||||
server cannot substitute one blob for another without decryption failing.
|
||||
- Content Keys travel only inside the envelope, wrapped by MK — the database
|
||||
(local and cloud) stays free of key material.
|
||||
"""
|
||||
|
||||
import json
|
||||
import secrets
|
||||
from dataclasses import dataclass
|
||||
|
||||
import nacl.bindings
|
||||
import nacl.exceptions
|
||||
import nacl.pwhash
|
||||
import nacl.utils
|
||||
from mnemonic import Mnemonic
|
||||
from nacl.public import PrivateKey, PublicKey, SealedBox
|
||||
from nacl.secret import SecretBox
|
||||
|
||||
KEY_BYTES = 32
|
||||
|
||||
# Envelope framing: magic | alg | len(wrapped_ck) | wrapped_ck | nonce | ciphertext
|
||||
ENVELOPE_MAGIC = b"VBX1"
|
||||
ALG_XCHACHA20_POLY1305 = 1
|
||||
_WRAPPED_CK_LEN_BYTES = 2
|
||||
_NONCE_BYTES = nacl.bindings.crypto_aead_xchacha20poly1305_ietf_NPUBBYTES # 24
|
||||
|
||||
# Argon2id cost for the recovery-phrase KEK. MODERATE (~256 MiB, interactive
|
||||
# latency) fits a desktop restore flow; the phrase itself already carries
|
||||
# 128 bits of entropy, so the KDF is hardening, not the main defense.
|
||||
_KDF_OPSLIMIT = nacl.pwhash.argon2id.OPSLIMIT_MODERATE
|
||||
_KDF_MEMLIMIT = nacl.pwhash.argon2id.MEMLIMIT_MODERATE
|
||||
|
||||
_mnemonic = Mnemonic("english")
|
||||
|
||||
|
||||
class CloudCryptoError(Exception):
|
||||
"""Envelope malformed, key wrong, or ciphertext tampered with."""
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Master Key + device keys
|
||||
|
||||
|
||||
def generate_master_key() -> bytes:
|
||||
"""The 32-byte root of content secrecy. Generated once per account, client-side."""
|
||||
return secrets.token_bytes(KEY_BYTES)
|
||||
|
||||
|
||||
def generate_device_keypair() -> tuple[bytes, bytes]:
|
||||
"""X25519 (private, public) for this install. The private key never leaves
|
||||
the device; the public key is registered with the cloud so existing devices
|
||||
can wrap MK to it."""
|
||||
private = PrivateKey.generate()
|
||||
return bytes(private), bytes(private.public_key)
|
||||
|
||||
|
||||
def device_public_key(device_private_key: bytes) -> bytes:
|
||||
"""Re-derive the public half from a stored private key."""
|
||||
return bytes(PrivateKey(device_private_key).public_key)
|
||||
|
||||
|
||||
def wrap_master_key_for_device(master_key: bytes, device_public_key: bytes) -> bytes:
|
||||
"""Seal MK to another device's public key (run on an *existing* device when
|
||||
provisioning a new one). Only the target device's private key can open it."""
|
||||
return SealedBox(PublicKey(device_public_key)).encrypt(master_key)
|
||||
|
||||
|
||||
def unwrap_master_key_for_device(wrapped: bytes, device_private_key: bytes) -> bytes:
|
||||
"""Open a sealed MK with this device's private key."""
|
||||
try:
|
||||
return SealedBox(PrivateKey(device_private_key)).decrypt(wrapped)
|
||||
except nacl.exceptions.CryptoError as err:
|
||||
raise CloudCryptoError("wrapped master key does not match this device key") from err
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Recovery phrase escrow
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class RecoveryWrap:
|
||||
"""What the cloud stores in ``account_key``: ciphertext + the KDF context
|
||||
any client needs to re-derive the KEK from the phrase. Holds no secrets."""
|
||||
|
||||
wrapped_key: bytes
|
||||
kdf_salt: bytes
|
||||
kdf_params: str # JSON, e.g. {"m": ..., "t": ..., "p": 1}
|
||||
|
||||
|
||||
def generate_recovery_phrase() -> str:
|
||||
"""12-word BIP39 mnemonic (128-bit entropy) — shown to the user exactly once."""
|
||||
return _mnemonic.generate(strength=128)
|
||||
|
||||
|
||||
def validate_recovery_phrase(phrase: str) -> bool:
|
||||
"""Word-level checksum validation, for catching typos before an unwrap attempt."""
|
||||
return _mnemonic.check(_normalize_phrase(phrase))
|
||||
|
||||
|
||||
def _normalize_phrase(phrase: str) -> str:
|
||||
return " ".join(phrase.lower().split())
|
||||
|
||||
|
||||
def _derive_kek(phrase: str, salt: bytes, opslimit: int, memlimit: int) -> bytes:
|
||||
return nacl.pwhash.argon2id.kdf(
|
||||
KEY_BYTES,
|
||||
_normalize_phrase(phrase).encode("utf-8"),
|
||||
salt,
|
||||
opslimit=opslimit,
|
||||
memlimit=memlimit,
|
||||
)
|
||||
|
||||
|
||||
def wrap_master_key_with_phrase(master_key: bytes, phrase: str) -> RecoveryWrap:
|
||||
"""Argon2id-stretch the phrase into a KEK and wrap MK under it."""
|
||||
salt = nacl.utils.random(nacl.pwhash.argon2id.SALTBYTES)
|
||||
kek = _derive_kek(phrase, salt, _KDF_OPSLIMIT, _KDF_MEMLIMIT)
|
||||
return RecoveryWrap(
|
||||
wrapped_key=SecretBox(kek).encrypt(master_key),
|
||||
kdf_salt=salt,
|
||||
kdf_params=json.dumps({"m": _KDF_MEMLIMIT, "t": _KDF_OPSLIMIT, "p": 1}),
|
||||
)
|
||||
|
||||
|
||||
def unwrap_master_key_with_phrase(wrap: RecoveryWrap, phrase: str) -> bytes:
|
||||
"""Recover MK on a fresh device from the phrase + the stored KDF context."""
|
||||
try:
|
||||
params = json.loads(wrap.kdf_params)
|
||||
opslimit, memlimit = int(params["t"]), int(params["m"])
|
||||
except (ValueError, KeyError, TypeError) as err:
|
||||
raise CloudCryptoError("malformed KDF parameters") from err
|
||||
kek = _derive_kek(phrase, wrap.kdf_salt, opslimit, memlimit)
|
||||
try:
|
||||
return SecretBox(kek).decrypt(wrap.wrapped_key)
|
||||
except nacl.exceptions.CryptoError as err:
|
||||
raise CloudCryptoError("recovery phrase does not unlock this account key") from err
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Blob envelope
|
||||
|
||||
|
||||
def _build_aad(object_id: str, role: str, version: int) -> bytes:
|
||||
# Binds a blob to its logical slot. Unambiguous because object_id is a UUID
|
||||
# and role is a fixed token — neither contains ":".
|
||||
return f"{object_id}:{role}:{version}".encode()
|
||||
|
||||
|
||||
def encrypt_blob(plaintext: bytes, master_key: bytes, *, object_id: str, role: str, version: int) -> bytes:
|
||||
"""Produce a self-describing VBX1 envelope: a fresh Content Key wrapped by
|
||||
MK rides in the header, and the AAD pins the blob to (object, role, version)."""
|
||||
content_key = secrets.token_bytes(KEY_BYTES)
|
||||
wrapped_ck = SecretBox(master_key).encrypt(content_key)
|
||||
nonce = nacl.utils.random(_NONCE_BYTES)
|
||||
ciphertext = nacl.bindings.crypto_aead_xchacha20poly1305_ietf_encrypt(
|
||||
plaintext,
|
||||
_build_aad(object_id, role, version),
|
||||
nonce,
|
||||
content_key,
|
||||
)
|
||||
return b"".join(
|
||||
[
|
||||
ENVELOPE_MAGIC,
|
||||
bytes([ALG_XCHACHA20_POLY1305]),
|
||||
len(wrapped_ck).to_bytes(_WRAPPED_CK_LEN_BYTES, "big"),
|
||||
wrapped_ck,
|
||||
nonce,
|
||||
ciphertext,
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def decrypt_blob(envelope: bytes, master_key: bytes, *, object_id: str, role: str, version: int) -> bytes:
|
||||
"""Open a VBX1 envelope. Raises CloudCryptoError if the envelope is
|
||||
malformed, the key is wrong, the ciphertext was modified, or the blob was
|
||||
served for a different (object, role, version) slot."""
|
||||
offset = len(ENVELOPE_MAGIC)
|
||||
if envelope[:offset] != ENVELOPE_MAGIC:
|
||||
raise CloudCryptoError("not a VBX1 envelope")
|
||||
if len(envelope) < offset + 1 + _WRAPPED_CK_LEN_BYTES:
|
||||
raise CloudCryptoError("envelope truncated")
|
||||
alg = envelope[offset]
|
||||
if alg != ALG_XCHACHA20_POLY1305:
|
||||
raise CloudCryptoError(f"unsupported envelope algorithm {alg}")
|
||||
offset += 1
|
||||
|
||||
wrapped_len = int.from_bytes(envelope[offset : offset + _WRAPPED_CK_LEN_BYTES], "big")
|
||||
offset += _WRAPPED_CK_LEN_BYTES
|
||||
wrapped_ck = envelope[offset : offset + wrapped_len]
|
||||
offset += wrapped_len
|
||||
nonce = envelope[offset : offset + _NONCE_BYTES]
|
||||
offset += _NONCE_BYTES
|
||||
ciphertext = envelope[offset:]
|
||||
if len(wrapped_ck) != wrapped_len or len(nonce) != _NONCE_BYTES or not ciphertext:
|
||||
raise CloudCryptoError("envelope truncated")
|
||||
|
||||
try:
|
||||
content_key = SecretBox(master_key).decrypt(wrapped_ck)
|
||||
except nacl.exceptions.CryptoError as err:
|
||||
raise CloudCryptoError("master key does not unwrap this blob's content key") from err
|
||||
try:
|
||||
return nacl.bindings.crypto_aead_xchacha20poly1305_ietf_decrypt(
|
||||
ciphertext,
|
||||
_build_aad(object_id, role, version),
|
||||
nonce,
|
||||
content_key,
|
||||
)
|
||||
except nacl.exceptions.CryptoError as err:
|
||||
raise CloudCryptoError("blob failed authentication (tampered, or served for the wrong slot)") from err
|
||||
@@ -0,0 +1,63 @@
|
||||
"""
|
||||
OS-keychain persistence for cloud E2E key material.
|
||||
|
||||
The bearer API key lives in the local database (``CloudSettings``) because it
|
||||
is auth, not secrecy. The *encryption* keys never touch the database: this
|
||||
module stores the device's X25519 private key and the unwrapped Master Key in
|
||||
the OS keychain (macOS Keychain, Windows Credential Locker, Secret Service on
|
||||
Linux) via ``keyring``. Entries are namespaced by cloud account user id so
|
||||
relinking to a different account can never read the previous account's keys.
|
||||
|
||||
Headless installs (Docker/web) may have no keychain backend; operations then
|
||||
raise ``CloudKeyStoreError`` and cloud sync stays unavailable rather than
|
||||
silently degrading to plaintext-on-disk key storage.
|
||||
"""
|
||||
|
||||
import base64
|
||||
|
||||
import keyring
|
||||
import keyring.errors
|
||||
|
||||
_SERVICE = "sh.voicebox.cloud"
|
||||
|
||||
DEVICE_PRIVATE_KEY = "device_private_key"
|
||||
MASTER_KEY = "master_key"
|
||||
_ALL_ENTRIES = (DEVICE_PRIVATE_KEY, MASTER_KEY)
|
||||
|
||||
|
||||
class CloudKeyStoreError(Exception):
|
||||
"""The OS keychain is unavailable or rejected the operation."""
|
||||
|
||||
|
||||
def _entry(account_user_id: str, name: str) -> str:
|
||||
return f"{account_user_id}:{name}"
|
||||
|
||||
|
||||
def store_secret(account_user_id: str, name: str, secret: bytes) -> None:
|
||||
try:
|
||||
keyring.set_password(_SERVICE, _entry(account_user_id, name), base64.b64encode(secret).decode("ascii"))
|
||||
except keyring.errors.KeyringError as err:
|
||||
raise CloudKeyStoreError(f"could not store {name} in the OS keychain") from err
|
||||
|
||||
|
||||
def load_secret(account_user_id: str, name: str) -> bytes | None:
|
||||
try:
|
||||
stored = keyring.get_password(_SERVICE, _entry(account_user_id, name))
|
||||
except keyring.errors.KeyringError as err:
|
||||
raise CloudKeyStoreError(f"could not read {name} from the OS keychain") from err
|
||||
return base64.b64decode(stored) if stored else None
|
||||
|
||||
|
||||
def delete_secret(account_user_id: str, name: str) -> None:
|
||||
try:
|
||||
keyring.delete_password(_SERVICE, _entry(account_user_id, name))
|
||||
except keyring.errors.PasswordDeleteError:
|
||||
pass # already absent
|
||||
except keyring.errors.KeyringError as err:
|
||||
raise CloudKeyStoreError(f"could not delete {name} from the OS keychain") from err
|
||||
|
||||
|
||||
def clear(account_user_id: str) -> None:
|
||||
"""Forget all key material for an account (disconnect / account switch)."""
|
||||
for name in _ALL_ENTRIES:
|
||||
delete_secret(account_user_id, name)
|
||||
@@ -0,0 +1,535 @@
|
||||
"""
|
||||
The cloud sync engine: encrypted backup + multi-device restore.
|
||||
|
||||
Walks the local store (SQLite rows + audio files), maps each entity onto the
|
||||
cloud's object model, and drives the push/pull loop against the blind server.
|
||||
Everything crosses the wire as VBX1 ciphertext (``cloud_crypto``); the server
|
||||
only ever learns kinds, ids, sizes, and hashes.
|
||||
|
||||
Mapping (cloud repo ``docs/DESIGN.md`` §5):
|
||||
|
||||
| local entity | kind | record (encrypted JSON) | assets |
|
||||
| ------------------------------------- | ---------- | ------------------------- | ----------------- |
|
||||
| ``captures`` row + wav | capture | the row | the capture audio |
|
||||
| ``generations`` row + version wavs | generation | the row + version rows | each version wav |
|
||||
| ``profiles`` row + samples + avatar | profile | the row + sample rows | sample wavs, avatar |
|
||||
| ``capture_settings`` / ``generation_settings`` | settings | the row | — |
|
||||
|
||||
Path columns are stored storage-relative inside the (encrypted) record, so a
|
||||
restore re-anchors them under the destination machine's data dir.
|
||||
|
||||
Change detection: envelopes are randomized, so ``CloudSyncState`` keeps the
|
||||
plaintext fingerprint (did the content actually change?) alongside the
|
||||
ciphertext hash the server holds (re-declare unchanged blobs without
|
||||
re-encrypting). Conflicts are last-writer-wins per object, matching §6 —
|
||||
push runs before pull, so local edits are declared before remote state lands.
|
||||
|
||||
AAD binding: records are bound to ``(clientId, "record", version)`` and
|
||||
re-encrypted on every version bump. Asset blobs are bound to
|
||||
``(clientId, "asset:<clientAssetId>", 1)`` — assets are content-addressed and
|
||||
practically immutable (audio never changes in place), so their slot binding
|
||||
doesn't chase the object version.
|
||||
"""
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import logging
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .. import config
|
||||
from ..database import (
|
||||
Capture,
|
||||
CaptureSettings,
|
||||
CloudSettings as DBCloudSettings,
|
||||
CloudSyncState,
|
||||
Generation,
|
||||
GenerationSettings,
|
||||
GenerationVersion,
|
||||
ProfileSample,
|
||||
VoiceProfile,
|
||||
)
|
||||
from . import cloud_account, cloud_crypto
|
||||
from .cloud_api import CloudApiClient
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_ASSET_AAD_VERSION = 1
|
||||
|
||||
|
||||
class CloudSyncError(Exception):
|
||||
"""Sync could not run or an object failed to round-trip."""
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Local object collection (push side)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class LocalAsset:
|
||||
client_asset_id: str
|
||||
role: str # audio | version | sample | avatar
|
||||
path: Path
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class LocalObject:
|
||||
kind: str
|
||||
client_id: str
|
||||
record: dict
|
||||
assets: list[LocalAsset] = field(default_factory=list)
|
||||
|
||||
|
||||
_PATH_COLUMNS = {"audio_path", "avatar_path"}
|
||||
|
||||
|
||||
def _row_to_record(row) -> dict:
|
||||
"""All mapped columns as JSON-safe values; paths storage-relative,
|
||||
datetimes ISO-8601."""
|
||||
record: dict = {}
|
||||
for column in row.__mapper__.columns:
|
||||
value = getattr(row, column.key)
|
||||
if value is None:
|
||||
record[column.key] = None
|
||||
elif column.key in _PATH_COLUMNS:
|
||||
# Rows normally hold data-dir-relative paths already; only rebase
|
||||
# absolute ones. (to_storage_path on a relative value would resolve
|
||||
# it against the CWD and corrupt it.)
|
||||
record[column.key] = config.to_storage_path(value) if Path(value).is_absolute() else value
|
||||
elif isinstance(value, datetime):
|
||||
record[column.key] = value.isoformat()
|
||||
else:
|
||||
record[column.key] = value
|
||||
return record
|
||||
|
||||
|
||||
def _is_datetime_column(column) -> bool:
|
||||
try:
|
||||
return column.type.python_type is datetime
|
||||
except NotImplementedError: # e.g. JSON columns don't declare a python_type
|
||||
return False
|
||||
|
||||
|
||||
def _record_to_row(model, record: dict, existing=None):
|
||||
"""Build or update a model instance from a record dict."""
|
||||
row = existing if existing is not None else model()
|
||||
for column in row.__mapper__.columns:
|
||||
if column.key not in record:
|
||||
continue
|
||||
value = record[column.key]
|
||||
if isinstance(value, str) and _is_datetime_column(column):
|
||||
value = datetime.fromisoformat(value)
|
||||
setattr(row, column.key, value)
|
||||
return row
|
||||
|
||||
|
||||
def _existing_path(value: str | None) -> Path | None:
|
||||
resolved = config.resolve_storage_path(value)
|
||||
return resolved if resolved is not None and resolved.exists() else None
|
||||
|
||||
|
||||
def _collect_captures(db: Session) -> list[LocalObject]:
|
||||
objects = []
|
||||
for row in db.query(Capture).all():
|
||||
assets = []
|
||||
if (path := _existing_path(row.audio_path)) is not None:
|
||||
assets.append(LocalAsset(client_asset_id=row.id, role="audio", path=path))
|
||||
objects.append(LocalObject(kind="capture", client_id=row.id, record=_row_to_record(row), assets=assets))
|
||||
return objects
|
||||
|
||||
|
||||
def _collect_generations(db: Session) -> list[LocalObject]:
|
||||
objects = []
|
||||
for row in db.query(Generation).filter(Generation.status == "completed").all():
|
||||
record = _row_to_record(row)
|
||||
assets = []
|
||||
if (path := _existing_path(row.audio_path)) is not None:
|
||||
assets.append(LocalAsset(client_asset_id=row.id, role="audio", path=path))
|
||||
versions = db.query(GenerationVersion).filter(GenerationVersion.generation_id == row.id).all()
|
||||
record["versions"] = [_row_to_record(v) for v in versions]
|
||||
for version in versions:
|
||||
if (path := _existing_path(version.audio_path)) is not None:
|
||||
assets.append(LocalAsset(client_asset_id=version.id, role="version", path=path))
|
||||
objects.append(LocalObject(kind="generation", client_id=row.id, record=record, assets=assets))
|
||||
return objects
|
||||
|
||||
|
||||
def _collect_profiles(db: Session) -> list[LocalObject]:
|
||||
objects = []
|
||||
for row in db.query(VoiceProfile).all():
|
||||
record = _row_to_record(row)
|
||||
assets = []
|
||||
if (path := _existing_path(row.avatar_path)) is not None:
|
||||
assets.append(LocalAsset(client_asset_id=f"{row.id}-avatar", role="avatar", path=path))
|
||||
samples = db.query(ProfileSample).filter(ProfileSample.profile_id == row.id).all()
|
||||
record["samples"] = [_row_to_record(s) for s in samples]
|
||||
for sample in samples:
|
||||
if (path := _existing_path(sample.audio_path)) is not None:
|
||||
assets.append(LocalAsset(client_asset_id=sample.id, role="sample", path=path))
|
||||
objects.append(LocalObject(kind="profile", client_id=row.id, record=record, assets=assets))
|
||||
return objects
|
||||
|
||||
|
||||
def _collect_settings(db: Session) -> list[LocalObject]:
|
||||
objects = []
|
||||
for client_id, model in (("capture_settings", CaptureSettings), ("generation_settings", GenerationSettings)):
|
||||
row = db.query(model).first()
|
||||
if row is not None:
|
||||
objects.append(LocalObject(kind="settings", client_id=client_id, record=_row_to_record(row)))
|
||||
return objects
|
||||
|
||||
|
||||
def collect_local_objects(db: Session) -> list[LocalObject]:
|
||||
return _collect_captures(db) + _collect_generations(db) + _collect_profiles(db) + _collect_settings(db)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Applying pulled records (pull side)
|
||||
|
||||
|
||||
def _write_asset(record_path_value: str | None, data: bytes) -> None:
|
||||
resolved = config.resolve_storage_path(record_path_value)
|
||||
if resolved is None:
|
||||
return
|
||||
resolved.parent.mkdir(parents=True, exist_ok=True)
|
||||
resolved.write_bytes(data)
|
||||
|
||||
|
||||
def _apply_children(db: Session, model, parent_filter, child_records: list[dict], blobs: dict[str, bytes]) -> None:
|
||||
"""Upsert child rows (versions/samples) by id; drop local children the
|
||||
record no longer contains; write any pulled audio next to them."""
|
||||
wanted = {child["id"] for child in child_records}
|
||||
for stale in db.query(model).filter(parent_filter).all():
|
||||
if stale.id not in wanted:
|
||||
db.delete(stale)
|
||||
for child in child_records:
|
||||
existing = db.query(model).filter(model.id == child["id"]).first()
|
||||
row = _record_to_row(model, child, existing)
|
||||
if existing is None:
|
||||
db.add(row)
|
||||
if child["id"] in blobs:
|
||||
_write_asset(child.get("audio_path"), blobs[child["id"]])
|
||||
|
||||
|
||||
def _apply_capture(db: Session, client_id: str, record: dict, blobs: dict[str, bytes]) -> None:
|
||||
existing = db.query(Capture).filter(Capture.id == client_id).first()
|
||||
row = _record_to_row(Capture, record, existing)
|
||||
if existing is None:
|
||||
db.add(row)
|
||||
if client_id in blobs:
|
||||
_write_asset(record.get("audio_path"), blobs[client_id])
|
||||
|
||||
|
||||
def _apply_generation(db: Session, client_id: str, record: dict, blobs: dict[str, bytes]) -> None:
|
||||
record = dict(record)
|
||||
versions = record.pop("versions", [])
|
||||
existing = db.query(Generation).filter(Generation.id == client_id).first()
|
||||
row = _record_to_row(Generation, record, existing)
|
||||
if existing is None:
|
||||
db.add(row)
|
||||
if client_id in blobs:
|
||||
_write_asset(record.get("audio_path"), blobs[client_id])
|
||||
_apply_children(db, GenerationVersion, GenerationVersion.generation_id == client_id, versions, blobs)
|
||||
|
||||
|
||||
def _apply_profile(db: Session, client_id: str, record: dict, blobs: dict[str, bytes]) -> None:
|
||||
record = dict(record)
|
||||
samples = record.pop("samples", [])
|
||||
existing = db.query(VoiceProfile).filter(VoiceProfile.id == client_id).first()
|
||||
row = _record_to_row(VoiceProfile, record, existing)
|
||||
if existing is None:
|
||||
db.add(row)
|
||||
if f"{client_id}-avatar" in blobs:
|
||||
_write_asset(record.get("avatar_path"), blobs[f"{client_id}-avatar"])
|
||||
_apply_children(db, ProfileSample, ProfileSample.profile_id == client_id, samples, blobs)
|
||||
|
||||
|
||||
def _apply_settings(db: Session, client_id: str, record: dict) -> None:
|
||||
model = CaptureSettings if client_id == "capture_settings" else GenerationSettings
|
||||
existing = db.query(model).first()
|
||||
row = _record_to_row(model, record, existing)
|
||||
if existing is None:
|
||||
db.add(row)
|
||||
|
||||
|
||||
def _apply_record(db: Session, kind: str, client_id: str, record: dict, blobs: dict[str, bytes]) -> None:
|
||||
if kind == "capture":
|
||||
_apply_capture(db, client_id, record, blobs)
|
||||
elif kind == "generation":
|
||||
_apply_generation(db, client_id, record, blobs)
|
||||
elif kind == "profile":
|
||||
_apply_profile(db, client_id, record, blobs)
|
||||
elif kind == "settings":
|
||||
_apply_settings(db, client_id, record)
|
||||
else:
|
||||
raise CloudSyncError(f"unknown object kind {kind!r}")
|
||||
|
||||
|
||||
def _delete_local(db: Session, kind: str, client_id: str) -> None:
|
||||
if kind == "capture":
|
||||
db.query(Capture).filter(Capture.id == client_id).delete()
|
||||
elif kind == "generation":
|
||||
db.query(GenerationVersion).filter(GenerationVersion.generation_id == client_id).delete()
|
||||
db.query(Generation).filter(Generation.id == client_id).delete()
|
||||
elif kind == "profile":
|
||||
db.query(ProfileSample).filter(ProfileSample.profile_id == client_id).delete()
|
||||
db.query(VoiceProfile).filter(VoiceProfile.id == client_id).delete()
|
||||
# settings singletons are never deleted
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# The engine
|
||||
|
||||
|
||||
@dataclass
|
||||
class SyncReport:
|
||||
pushed: int = 0
|
||||
pushed_deletes: int = 0
|
||||
pulled: int = 0
|
||||
pulled_deletes: int = 0
|
||||
cursor: int = 0
|
||||
|
||||
|
||||
def _canonical(record: dict) -> bytes:
|
||||
"""Canonical bytes for change detection. ``updated_at`` is excluded (at the
|
||||
top level and in embedded child rows): its ``onupdate`` trigger can bump it
|
||||
as a side effect of *applying* a pulled record, and letting that feed back
|
||||
into the fingerprint would bounce an already-synced object back and forth.
|
||||
The field still syncs — it just doesn't count as a change by itself."""
|
||||
stripped = {k: v for k, v in record.items() if k != "updated_at"}
|
||||
for key, value in stripped.items():
|
||||
if isinstance(value, list):
|
||||
stripped[key] = [
|
||||
{k: v for k, v in item.items() if k != "updated_at"} if isinstance(item, dict) else item
|
||||
for item in value
|
||||
]
|
||||
return json.dumps(stripped, sort_keys=True, separators=(",", ":")).encode()
|
||||
|
||||
|
||||
def _fingerprint(data: bytes) -> str:
|
||||
return hashlib.sha256(data).hexdigest()
|
||||
|
||||
|
||||
def _get_state(db: Session, kind: str, client_id: str) -> CloudSyncState | None:
|
||||
return db.query(CloudSyncState).filter(CloudSyncState.kind == kind, CloudSyncState.client_id == client_id).first()
|
||||
|
||||
|
||||
def _settings_row(db: Session) -> DBCloudSettings:
|
||||
row = db.query(DBCloudSettings).filter(DBCloudSettings.id == 1).first()
|
||||
if row is None:
|
||||
raise CloudSyncError("not connected to Voicebox Cloud")
|
||||
return row
|
||||
|
||||
|
||||
async def _push_object(
|
||||
client: CloudApiClient,
|
||||
db: Session,
|
||||
master_key: bytes,
|
||||
obj: LocalObject,
|
||||
state: CloudSyncState | None,
|
||||
) -> bool:
|
||||
"""Push one object if it changed. Returns True when a push happened."""
|
||||
record_payload = json.dumps(obj.record, sort_keys=True, separators=(",", ":")).encode()
|
||||
record_fp = _fingerprint(_canonical(obj.record))
|
||||
known_assets: dict = json.loads(state.assets_json) if state else {}
|
||||
|
||||
asset_plain: dict[str, bytes] = {}
|
||||
asset_fps: dict[str, str] = {}
|
||||
for asset in obj.assets:
|
||||
data = asset.path.read_bytes()
|
||||
asset_plain[asset.client_asset_id] = data
|
||||
asset_fps[asset.client_asset_id] = _fingerprint(data)
|
||||
|
||||
unchanged = (
|
||||
state is not None
|
||||
and state.server_object_id is not None
|
||||
and state.record_fingerprint == record_fp
|
||||
and {k: v["fingerprint"] for k, v in known_assets.items()} == asset_fps
|
||||
)
|
||||
if unchanged:
|
||||
return False
|
||||
|
||||
version = (state.version + 1) if state is not None else 1
|
||||
record_env = cloud_crypto.encrypt_blob(
|
||||
record_payload, master_key, object_id=obj.client_id, role="record", version=version
|
||||
)
|
||||
|
||||
descriptors = []
|
||||
envelopes: dict[str, bytes] = {}
|
||||
next_assets: dict[str, dict] = {}
|
||||
for asset in obj.assets:
|
||||
caid = asset.client_asset_id
|
||||
known = known_assets.get(caid)
|
||||
if known and known["fingerprint"] == asset_fps[caid]:
|
||||
# Content unchanged: re-declare the ciphertext the server holds.
|
||||
entry = {"role": asset.role, "fingerprint": asset_fps[caid], "hash": known["hash"], "size": known["size"]}
|
||||
else:
|
||||
envelope = cloud_crypto.encrypt_blob(
|
||||
asset_plain[caid],
|
||||
master_key,
|
||||
object_id=obj.client_id,
|
||||
role=f"asset:{caid}",
|
||||
version=_ASSET_AAD_VERSION,
|
||||
)
|
||||
envelopes[caid] = envelope
|
||||
entry = {
|
||||
"role": asset.role,
|
||||
"fingerprint": asset_fps[caid],
|
||||
"hash": _fingerprint(envelope),
|
||||
"size": len(envelope),
|
||||
}
|
||||
next_assets[caid] = entry
|
||||
descriptors.append({"role": asset.role, "clientAssetId": caid, "hash": entry["hash"], "size": entry["size"]})
|
||||
|
||||
pushed = await client.push_object(
|
||||
kind=obj.kind,
|
||||
client_id=obj.client_id,
|
||||
version=version,
|
||||
record={"hash": _fingerprint(record_env), "size": len(record_env)},
|
||||
assets=descriptors,
|
||||
)
|
||||
uploads = {u["for"]: u["url"] for u in pushed["uploads"]}
|
||||
if "record" in uploads:
|
||||
await client.upload_blob(uploads["record"], record_env)
|
||||
for caid, envelope in envelopes.items():
|
||||
url = uploads.get(f"asset:{caid}")
|
||||
if url:
|
||||
await client.upload_blob(url, envelope)
|
||||
await client.commit_object(pushed["objectId"])
|
||||
|
||||
if state is None:
|
||||
state = CloudSyncState(kind=obj.kind, client_id=obj.client_id)
|
||||
db.add(state)
|
||||
state.server_object_id = pushed["objectId"]
|
||||
state.version = version
|
||||
state.record_fingerprint = record_fp
|
||||
state.record_hash = _fingerprint(record_env)
|
||||
state.record_size = len(record_env)
|
||||
state.assets_json = json.dumps(next_assets)
|
||||
state.last_synced_at = datetime.utcnow()
|
||||
return True
|
||||
|
||||
|
||||
async def _push_all(client: CloudApiClient, db: Session, master_key: bytes, report: SyncReport) -> None:
|
||||
local = collect_local_objects(db)
|
||||
local_ids = {(o.kind, o.client_id) for o in local}
|
||||
|
||||
for obj in local:
|
||||
if await _push_object(client, db, master_key, obj, _get_state(db, obj.kind, obj.client_id)):
|
||||
report.pushed += 1
|
||||
db.commit()
|
||||
|
||||
# Local deletions: state rows whose entity no longer exists → tombstone.
|
||||
for state in db.query(CloudSyncState).all():
|
||||
if (state.kind, state.client_id) not in local_ids and state.kind != "settings":
|
||||
if state.server_object_id:
|
||||
await client.delete_object(state.server_object_id)
|
||||
db.delete(state)
|
||||
report.pushed_deletes += 1
|
||||
db.commit()
|
||||
|
||||
|
||||
async def _pull_changes(client: CloudApiClient, db: Session, master_key: bytes, report: SyncReport) -> None:
|
||||
settings = _settings_row(db)
|
||||
cursor = settings.sync_cursor or 0
|
||||
|
||||
while True:
|
||||
page = await client.get_changes(since=cursor)
|
||||
for change in page["changes"]:
|
||||
kind, client_id = change["kind"], change["clientId"]
|
||||
state = _get_state(db, kind, client_id)
|
||||
|
||||
if change["deleted"]:
|
||||
if state is not None:
|
||||
_delete_local(db, kind, client_id)
|
||||
db.delete(state)
|
||||
report.pulled_deletes += 1
|
||||
# Our own pushes echo back through the feed; the stored ciphertext
|
||||
# hash identifies them as already applied.
|
||||
elif change["record"] and (state is None or state.record_hash != change["record"]["hash"]):
|
||||
await _apply_change(client, db, master_key, change, state)
|
||||
report.pulled += 1
|
||||
|
||||
cursor = change["seq"]
|
||||
|
||||
settings.sync_cursor = cursor
|
||||
db.commit()
|
||||
report.cursor = cursor
|
||||
if not page["hasMore"]:
|
||||
break
|
||||
|
||||
|
||||
async def _apply_change(
|
||||
client: CloudApiClient,
|
||||
db: Session,
|
||||
master_key: bytes,
|
||||
change: dict,
|
||||
state: CloudSyncState | None,
|
||||
) -> None:
|
||||
kind, client_id = change["kind"], change["clientId"]
|
||||
record_cipher = await client.download_blob(change["record"]["url"])
|
||||
record = json.loads(
|
||||
cloud_crypto.decrypt_blob(
|
||||
record_cipher, master_key, object_id=client_id, role="record", version=change["version"]
|
||||
)
|
||||
)
|
||||
|
||||
known_assets: dict = json.loads(state.assets_json) if state else {}
|
||||
blobs: dict[str, bytes] = {}
|
||||
next_assets: dict[str, dict] = {}
|
||||
for asset in change["assets"]:
|
||||
caid = asset["clientAssetId"]
|
||||
known = known_assets.get(caid)
|
||||
if known and known["hash"] == asset["hash"]:
|
||||
next_assets[caid] = known
|
||||
continue # ciphertext we already hold locally
|
||||
if not asset["url"]:
|
||||
continue # declared but never uploaded; skip until it lands
|
||||
cipher = await client.download_blob(asset["url"])
|
||||
plain = cloud_crypto.decrypt_blob(
|
||||
cipher, master_key, object_id=client_id, role=f"asset:{caid}", version=_ASSET_AAD_VERSION
|
||||
)
|
||||
blobs[caid] = plain
|
||||
next_assets[caid] = {
|
||||
"role": asset["role"],
|
||||
"fingerprint": _fingerprint(plain),
|
||||
"hash": asset["hash"],
|
||||
"size": asset["size"],
|
||||
}
|
||||
|
||||
_apply_record(db, kind, client_id, record, blobs)
|
||||
|
||||
if state is None:
|
||||
state = CloudSyncState(kind=kind, client_id=client_id)
|
||||
db.add(state)
|
||||
state.server_object_id = change["id"]
|
||||
state.version = change["version"]
|
||||
state.record_fingerprint = _fingerprint(_canonical(record))
|
||||
state.record_hash = change["record"]["hash"]
|
||||
state.record_size = change["record"]["size"]
|
||||
state.assets_json = json.dumps(next_assets)
|
||||
state.last_synced_at = datetime.utcnow()
|
||||
|
||||
|
||||
async def run_sync(db: Session) -> SyncReport:
|
||||
"""One full sync: push local changes, then pull and apply remote ones."""
|
||||
settings = _settings_row(db)
|
||||
master_key = cloud_account.load_master_key(db)
|
||||
report = SyncReport()
|
||||
|
||||
async with CloudApiClient(config.get_cloud_api_url(), settings.api_key) as client:
|
||||
await _push_all(client, db, master_key, report)
|
||||
await _pull_changes(client, db, master_key, report)
|
||||
|
||||
logger.info(
|
||||
"cloud sync: pushed %d (+%d deletes), pulled %d (+%d deletes), cursor %d",
|
||||
report.pushed,
|
||||
report.pushed_deletes,
|
||||
report.pulled,
|
||||
report.pulled_deletes,
|
||||
report.cursor,
|
||||
)
|
||||
return report
|
||||
@@ -21,9 +21,9 @@ import tarfile
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from .. import __version__
|
||||
from ..config import get_data_dir
|
||||
from ..utils.progress import get_progress_manager
|
||||
from .. import __version__
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -31,8 +31,6 @@ GITHUB_RELEASES_URL = "https://github.com/jamiepine/voicebox/releases/download"
|
||||
|
||||
PROGRESS_KEY = "cuda-backend"
|
||||
|
||||
CUDA_DOWNLOAD_UNSUPPORTED_REASON = "Downloadable CUDA backend releases are currently only published for Windows."
|
||||
|
||||
# The current expected CUDA libs version. Bump this when we change the
|
||||
# CUDA toolkit version or torch's CUDA dependency changes (e.g. cu126 -> cu128).
|
||||
CUDA_LIBS_VERSION = "cu128-v1"
|
||||
@@ -65,25 +63,6 @@ def get_cuda_exe_name() -> str:
|
||||
return "voicebox-server-cuda"
|
||||
|
||||
|
||||
def is_cuda_download_supported() -> bool:
|
||||
"""Return whether this platform has a matching CUDA release asset."""
|
||||
return sys.platform == "win32"
|
||||
|
||||
|
||||
def get_cuda_download_unsupported_reason() -> str | None:
|
||||
"""Explain why this platform cannot use the release-download flow."""
|
||||
if is_cuda_download_supported():
|
||||
return None
|
||||
return CUDA_DOWNLOAD_UNSUPPORTED_REASON
|
||||
|
||||
|
||||
def ensure_cuda_download_supported() -> None:
|
||||
"""Raise if downloading would fetch an asset built for another platform."""
|
||||
reason = get_cuda_download_unsupported_reason()
|
||||
if reason:
|
||||
raise RuntimeError(reason)
|
||||
|
||||
|
||||
def get_cuda_binary_path() -> Optional[Path]:
|
||||
"""Return path to the CUDA executable if it exists inside the onedir."""
|
||||
p = get_cuda_dir() / get_cuda_exe_name()
|
||||
@@ -124,15 +103,12 @@ def get_cuda_status() -> dict:
|
||||
cuda_path = get_cuda_binary_path()
|
||||
progress = progress_manager.get_progress(PROGRESS_KEY)
|
||||
cuda_libs_version = get_installed_cuda_libs_version()
|
||||
unsupported_reason = get_cuda_download_unsupported_reason()
|
||||
|
||||
return {
|
||||
"available": cuda_path is not None,
|
||||
"active": is_cuda_active(),
|
||||
"binary_path": str(cuda_path) if cuda_path else None,
|
||||
"cuda_libs_version": cuda_libs_version,
|
||||
"download_supported": unsupported_reason is None,
|
||||
"unsupported_reason": unsupported_reason,
|
||||
"downloading": progress is not None and progress.get("status") == "downloading",
|
||||
"download_progress": progress,
|
||||
}
|
||||
@@ -281,8 +257,6 @@ async def download_cuda_binary(version: Optional[str] = None):
|
||||
|
||||
async def _download_cuda_binary_locked(version: Optional[str] = None):
|
||||
"""Inner implementation of download_cuda_binary, called under _download_lock."""
|
||||
ensure_cuda_download_supported()
|
||||
|
||||
import httpx
|
||||
|
||||
if version is None:
|
||||
@@ -413,11 +387,6 @@ async def check_and_update_cuda_binary():
|
||||
if not cuda_path:
|
||||
return # No CUDA binary installed, nothing to update
|
||||
|
||||
unsupported_reason = get_cuda_download_unsupported_reason()
|
||||
if unsupported_reason:
|
||||
logger.info("Skipping CUDA backend auto-update: %s", unsupported_reason)
|
||||
return
|
||||
|
||||
need_server = _needs_server_download()
|
||||
need_libs = _needs_cuda_libs_download()
|
||||
|
||||
|
||||
@@ -48,14 +48,9 @@ async def run_generation(
|
||||
This is the single entry point for all background generation work.
|
||||
It is designed to be enqueued via ``services.task_queue.enqueue_generation``.
|
||||
"""
|
||||
from ..backends import (
|
||||
engine_needs_trim,
|
||||
engine_retries_runaway,
|
||||
get_tts_backend_for_engine,
|
||||
load_engine_model,
|
||||
)
|
||||
from ..backends import load_engine_model, get_tts_backend_for_engine, engine_needs_trim
|
||||
from ..utils.chunked_tts import generate_chunked
|
||||
from ..utils.audio import has_tts_runaway, normalize_audio, save_audio, trim_tts_output
|
||||
from ..utils.audio import normalize_audio, save_audio, trim_tts_output
|
||||
|
||||
task_manager = get_task_manager()
|
||||
bg_db = next(get_db())
|
||||
@@ -77,14 +72,12 @@ async def run_generation(
|
||||
|
||||
await history.update_generation_status(generation_id, "generating", bg_db)
|
||||
trim_fn = trim_tts_output if engine_needs_trim(engine) else None
|
||||
runaway_detector = has_tts_runaway if engine_retries_runaway(engine) else None
|
||||
|
||||
gen_kwargs: dict = dict(
|
||||
language=language,
|
||||
seed=seed if mode != "regenerate" else None,
|
||||
instruct=instruct,
|
||||
trim_fn=trim_fn,
|
||||
runaway_detector=runaway_detector,
|
||||
)
|
||||
if max_chunk_chars is not None:
|
||||
gen_kwargs["max_chunk_chars"] = max_chunk_chars
|
||||
@@ -274,14 +267,9 @@ async def generate_audio_sync(
|
||||
normalize, then encodes in-memory via :func:`tts.audio_to_wav_bytes`
|
||||
(same helper ``/generate/stream`` uses).
|
||||
"""
|
||||
from ..backends import (
|
||||
engine_needs_trim,
|
||||
engine_retries_runaway,
|
||||
get_tts_backend_for_engine,
|
||||
load_engine_model,
|
||||
)
|
||||
from ..backends import load_engine_model, get_tts_backend_for_engine, engine_needs_trim
|
||||
from ..utils.chunked_tts import generate_chunked
|
||||
from ..utils.audio import has_tts_runaway, normalize_audio, trim_tts_output
|
||||
from ..utils.audio import normalize_audio, trim_tts_output
|
||||
from . import tts
|
||||
|
||||
bg_db = next(get_db())
|
||||
@@ -299,14 +287,12 @@ async def generate_audio_sync(
|
||||
bg_db.close()
|
||||
|
||||
trim_fn = trim_tts_output if engine_needs_trim(engine) else None
|
||||
runaway_detector = has_tts_runaway if engine_retries_runaway(engine) else None
|
||||
|
||||
gen_kwargs: dict = dict(
|
||||
language=language,
|
||||
seed=seed,
|
||||
instruct=instruct,
|
||||
trim_fn=trim_fn,
|
||||
runaway_detector=runaway_detector,
|
||||
)
|
||||
if max_chunk_chars is not None:
|
||||
gen_kwargs["max_chunk_chars"] = max_chunk_chars
|
||||
|
||||
@@ -1,467 +0,0 @@
|
||||
"""
|
||||
ROCm backend download, assembly, and verification.
|
||||
|
||||
Downloads two archives from GitHub Releases:
|
||||
1. Server core (voicebox-server-rocm.tar.gz) — the exe + non-AMD deps,
|
||||
versioned with the app.
|
||||
2. ROCm libs (rocm-libs-{version}.tar.gz) — AMD runtime libraries,
|
||||
versioned independently (only redownloaded on ROCm toolkit bump).
|
||||
|
||||
Both archives are extracted into {data_dir}/backends/rocm/ which forms the
|
||||
complete PyInstaller --onedir directory structure that torch expects.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import hashlib
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import tarfile
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from ..config import get_data_dir
|
||||
from ..utils.progress import get_progress_manager
|
||||
from .. import __version__
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
GITHUB_RELEASES_URL = "https://github.com/jamiepine/voicebox/releases/download"
|
||||
|
||||
PROGRESS_KEY = "rocm-backend"
|
||||
|
||||
# The current expected ROCm libs version. Bump this when we change the
|
||||
# ROCm toolkit version or torch's ROCm dependency changes (e.g. rocm7.2 -> rocm7.4).
|
||||
ROCM_LIBS_VERSION = "rocm7.2-v1"
|
||||
|
||||
# Prevents concurrent download_rocm_binary() calls from racing on the same
|
||||
# temp file. The auto-update background task and the manual HTTP endpoint
|
||||
# can both invoke download_rocm_binary(); without this lock the progress-
|
||||
# manager status check is a TOCTOU race.
|
||||
_download_lock = asyncio.Lock()
|
||||
|
||||
|
||||
def get_backends_dir() -> Path:
|
||||
"""Directory where downloaded backend binaries are stored."""
|
||||
d = get_data_dir() / "backends"
|
||||
d.mkdir(parents=True, exist_ok=True)
|
||||
return d
|
||||
|
||||
|
||||
def get_rocm_dir() -> Path:
|
||||
"""Directory where the ROCm backend (onedir) is extracted."""
|
||||
d = get_backends_dir() / "rocm"
|
||||
d.mkdir(parents=True, exist_ok=True)
|
||||
return d
|
||||
|
||||
|
||||
def get_rocm_exe_name() -> str:
|
||||
"""Platform-specific ROCm executable filename."""
|
||||
if sys.platform == "win32":
|
||||
return "voicebox-server-rocm.exe"
|
||||
return "voicebox-server-rocm"
|
||||
|
||||
|
||||
def get_rocm_binary_path() -> Optional[Path]:
|
||||
"""Return path to the ROCm executable if it exists inside the onedir."""
|
||||
p = get_rocm_dir() / get_rocm_exe_name()
|
||||
if p.exists():
|
||||
return p
|
||||
return None
|
||||
|
||||
|
||||
def get_rocm_libs_manifest_path() -> Path:
|
||||
"""Path to the rocm-libs.json manifest inside the ROCm dir."""
|
||||
return get_rocm_dir() / "rocm-libs.json"
|
||||
|
||||
|
||||
def get_installed_rocm_libs_version() -> Optional[str]:
|
||||
"""Read the installed ROCm libs version from rocm-libs.json, or None."""
|
||||
manifest_path = get_rocm_libs_manifest_path()
|
||||
if not manifest_path.exists():
|
||||
return None
|
||||
try:
|
||||
data = json.loads(manifest_path.read_text())
|
||||
return data.get("version")
|
||||
except Exception as e:
|
||||
logger.warning(f"Could not read rocm-libs.json: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def is_rocm_active() -> bool:
|
||||
"""Check if the current process is the ROCm binary.
|
||||
|
||||
The ROCm binary sets this env var on startup (see server.py).
|
||||
"""
|
||||
return os.environ.get("VOICEBOX_BACKEND_VARIANT") == "rocm"
|
||||
|
||||
|
||||
def get_rocm_status() -> dict:
|
||||
"""Get current ROCm backend status for the API."""
|
||||
progress_manager = get_progress_manager()
|
||||
rocm_path = get_rocm_binary_path()
|
||||
progress = progress_manager.get_progress(PROGRESS_KEY)
|
||||
rocm_libs_version = get_installed_rocm_libs_version()
|
||||
|
||||
return {
|
||||
"available": rocm_path is not None,
|
||||
"active": is_rocm_active(),
|
||||
"binary_path": str(rocm_path) if rocm_path else None,
|
||||
"rocm_libs_version": rocm_libs_version,
|
||||
"downloading": progress is not None and progress.get("status") == "downloading",
|
||||
"download_progress": progress,
|
||||
}
|
||||
|
||||
|
||||
def _needs_server_download(version: Optional[str] = None) -> bool:
|
||||
"""Check if the server core archive needs to be (re)downloaded."""
|
||||
rocm_path = get_rocm_binary_path()
|
||||
if not rocm_path:
|
||||
return True
|
||||
# Check if the binary version matches the expected app version
|
||||
installed = get_rocm_binary_version()
|
||||
expected = version or __version__
|
||||
if expected.startswith("v"):
|
||||
expected = expected[1:]
|
||||
return installed != expected
|
||||
|
||||
|
||||
def _needs_rocm_libs_download() -> bool:
|
||||
"""Check if the ROCm libs archive needs to be (re)downloaded."""
|
||||
installed = get_installed_rocm_libs_version()
|
||||
if installed is None:
|
||||
return True
|
||||
return installed != ROCM_LIBS_VERSION
|
||||
|
||||
|
||||
async def _download_and_extract_archive(
|
||||
client,
|
||||
url: str,
|
||||
sha256_url: Optional[str],
|
||||
dest_dir: Path,
|
||||
label: str,
|
||||
progress_offset: int,
|
||||
total_size: int,
|
||||
):
|
||||
"""Download a .tar.gz archive and extract it into dest_dir.
|
||||
|
||||
Args:
|
||||
client: httpx.AsyncClient
|
||||
url: URL of the .tar.gz archive
|
||||
sha256_url: URL of the .sha256 checksum file (optional)
|
||||
dest_dir: Directory to extract into
|
||||
label: Human-readable label for progress updates
|
||||
progress_offset: Byte offset for progress reporting (when downloading
|
||||
multiple archives sequentially)
|
||||
total_size: Total bytes across all downloads (for progress bar)
|
||||
"""
|
||||
progress = get_progress_manager()
|
||||
temp_path = dest_dir / f".download-{label.replace(' ', '-')}.tmp"
|
||||
|
||||
# Clean up leftover partial download
|
||||
if temp_path.exists():
|
||||
temp_path.unlink()
|
||||
|
||||
# Fetch expected checksum (fail-fast: never extract an unverified archive)
|
||||
expected_sha = None
|
||||
if sha256_url:
|
||||
try:
|
||||
sha_resp = await client.get(sha256_url)
|
||||
sha_resp.raise_for_status()
|
||||
expected_sha = sha_resp.text.strip().split()[0]
|
||||
logger.info(f"{label}: expected SHA-256: {expected_sha[:16]}...")
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"{label}: failed to fetch checksum from {sha256_url}") from e
|
||||
|
||||
# Stream download, verify, and extract — always clean up temp file
|
||||
downloaded = 0
|
||||
try:
|
||||
async with client.stream("GET", url) as response:
|
||||
response.raise_for_status()
|
||||
with open(temp_path, "wb") as f:
|
||||
async for chunk in response.aiter_bytes(chunk_size=1024 * 1024):
|
||||
f.write(chunk)
|
||||
downloaded += len(chunk)
|
||||
progress.update_progress(
|
||||
PROGRESS_KEY,
|
||||
current=progress_offset + downloaded,
|
||||
total=total_size,
|
||||
filename=f"Downloading {label}",
|
||||
status="downloading",
|
||||
)
|
||||
|
||||
# Verify integrity
|
||||
if expected_sha:
|
||||
progress.update_progress(
|
||||
PROGRESS_KEY,
|
||||
current=progress_offset + downloaded,
|
||||
total=total_size,
|
||||
filename=f"Verifying {label}...",
|
||||
status="downloading",
|
||||
)
|
||||
sha256 = hashlib.sha256()
|
||||
with open(temp_path, "rb") as f:
|
||||
while True:
|
||||
data = f.read(1024 * 1024)
|
||||
if not data:
|
||||
break
|
||||
sha256.update(data)
|
||||
actual = sha256.hexdigest()
|
||||
if actual != expected_sha:
|
||||
raise ValueError(
|
||||
f"{label} integrity check failed: expected {expected_sha[:16]}..., got {actual[:16]}..."
|
||||
)
|
||||
logger.info(f"{label}: integrity verified")
|
||||
|
||||
# Extract (use data filter for path traversal protection on Python 3.12+)
|
||||
progress.update_progress(
|
||||
PROGRESS_KEY,
|
||||
current=progress_offset + downloaded,
|
||||
total=total_size,
|
||||
filename=f"Extracting {label}...",
|
||||
status="downloading",
|
||||
)
|
||||
with tarfile.open(temp_path, "r:gz") as tar:
|
||||
tar.extractall(path=dest_dir, filter="data")
|
||||
|
||||
logger.info(f"{label}: extracted to {dest_dir}")
|
||||
finally:
|
||||
if temp_path.exists():
|
||||
temp_path.unlink()
|
||||
return downloaded
|
||||
|
||||
|
||||
async def download_rocm_binary(version: Optional[str] = None):
|
||||
"""Download the ROCm backend (server core + ROCm libs if needed).
|
||||
|
||||
Downloads both archives from GitHub Releases, extracts them into
|
||||
{data_dir}/backends/rocm/, and writes the rocm-libs.json manifest.
|
||||
|
||||
Only downloads what's needed:
|
||||
- Server core: always redownloaded (versioned with app)
|
||||
- ROCm libs: only if missing or version mismatch
|
||||
|
||||
Args:
|
||||
version: Version tag (e.g. "v0.3.0"). Defaults to current app version.
|
||||
"""
|
||||
if _download_lock.locked():
|
||||
logger.info("ROCm download already in progress, skipping duplicate request")
|
||||
return
|
||||
async with _download_lock:
|
||||
await _download_rocm_binary_locked(version)
|
||||
|
||||
|
||||
async def _download_rocm_binary_locked(version: Optional[str] = None):
|
||||
"""Inner implementation of download_rocm_binary, called under _download_lock."""
|
||||
import httpx
|
||||
|
||||
if version is None:
|
||||
version = f"v{__version__}"
|
||||
|
||||
progress = get_progress_manager()
|
||||
rocm_dir = get_rocm_dir()
|
||||
|
||||
need_server = _needs_server_download(version)
|
||||
need_libs = _needs_rocm_libs_download()
|
||||
|
||||
if not need_server and not need_libs:
|
||||
logger.info("ROCm backend is up to date, nothing to download")
|
||||
return
|
||||
|
||||
logger.info(
|
||||
f"Starting ROCm backend download for {version} "
|
||||
f"(server={'yes' if need_server else 'cached'}, "
|
||||
f"libs={'yes' if need_libs else 'cached'})"
|
||||
)
|
||||
progress.update_progress(
|
||||
PROGRESS_KEY,
|
||||
current=0,
|
||||
total=0,
|
||||
filename="Preparing download...",
|
||||
status="downloading",
|
||||
)
|
||||
|
||||
# Server core and libs archive are both published under the app-version
|
||||
# release tag; the libs content version is encoded in the filename only.
|
||||
server_base_url = f"{GITHUB_RELEASES_URL}/{version}"
|
||||
libs_base_url = server_base_url
|
||||
server_archive = "voicebox-server-rocm.tar.gz"
|
||||
libs_archive = f"rocm-libs-{ROCM_LIBS_VERSION}.tar.gz"
|
||||
|
||||
# Always stage when any download is needed, then atomically rename over
|
||||
# rocm_dir on success. This prevents a failed mid-extraction from leaving
|
||||
# rocm_dir in a partially-installed state that still passes the
|
||||
# get_rocm_binary_path() existence check. Existing files are pre-copied
|
||||
# into staging so partial updates (e.g. libs-only or server-only) preserve
|
||||
# whatever isn't being re-downloaded.
|
||||
use_staging = need_server or need_libs
|
||||
staging_dir = get_backends_dir() / "rocm-staging"
|
||||
|
||||
if use_staging:
|
||||
if staging_dir.exists():
|
||||
shutil.rmtree(staging_dir)
|
||||
staging_dir.mkdir(parents=True, exist_ok=True)
|
||||
# Preserve existing files (server or libs) that don't need re-downloading.
|
||||
# Extracted archives will overwrite only what we actually download.
|
||||
if rocm_dir.exists():
|
||||
shutil.copytree(rocm_dir, staging_dir, dirs_exist_ok=True)
|
||||
extract_dir = staging_dir
|
||||
else:
|
||||
extract_dir = rocm_dir
|
||||
|
||||
try:
|
||||
async with httpx.AsyncClient(follow_redirects=True, timeout=30.0) as client:
|
||||
# Estimate total download size
|
||||
total_size = 0
|
||||
if need_server:
|
||||
try:
|
||||
head = await client.head(f"{server_base_url}/{server_archive}")
|
||||
total_size += int(head.headers.get("content-length", 0))
|
||||
except Exception:
|
||||
pass
|
||||
if need_libs:
|
||||
try:
|
||||
head = await client.head(f"{libs_base_url}/{libs_archive}")
|
||||
total_size += int(head.headers.get("content-length", 0))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
logger.info(f"Total download size: {total_size / 1024 / 1024:.1f} MB")
|
||||
|
||||
offset = 0
|
||||
|
||||
# Download server core
|
||||
if need_server:
|
||||
server_downloaded = await _download_and_extract_archive(
|
||||
client,
|
||||
url=f"{server_base_url}/{server_archive}",
|
||||
sha256_url=f"{server_base_url}/{server_archive}.sha256",
|
||||
dest_dir=extract_dir,
|
||||
label="ROCm server",
|
||||
progress_offset=offset,
|
||||
total_size=total_size,
|
||||
)
|
||||
offset += server_downloaded
|
||||
|
||||
# Make executable on Unix
|
||||
exe_path = extract_dir / get_rocm_exe_name()
|
||||
if sys.platform != "win32" and exe_path.exists():
|
||||
exe_path.chmod(0o755)
|
||||
|
||||
# Download ROCm libs
|
||||
if need_libs:
|
||||
await _download_and_extract_archive(
|
||||
client,
|
||||
url=f"{libs_base_url}/{libs_archive}",
|
||||
sha256_url=f"{libs_base_url}/{libs_archive}.sha256",
|
||||
dest_dir=extract_dir,
|
||||
label="ROCm libraries",
|
||||
progress_offset=offset,
|
||||
total_size=total_size,
|
||||
)
|
||||
|
||||
# Write local rocm-libs.json manifest
|
||||
manifest = {"version": ROCM_LIBS_VERSION}
|
||||
(extract_dir / "rocm-libs.json").write_text(json.dumps(manifest, indent=2) + "\n")
|
||||
|
||||
# Atomic swap: replace rocm_dir with the fully-extracted staging dir
|
||||
if use_staging:
|
||||
backup_dir = get_backends_dir() / "rocm-backup"
|
||||
if backup_dir.exists():
|
||||
shutil.rmtree(backup_dir)
|
||||
if rocm_dir.exists():
|
||||
rocm_dir.rename(backup_dir)
|
||||
try:
|
||||
staging_dir.rename(rocm_dir)
|
||||
except Exception:
|
||||
if backup_dir.exists() and not rocm_dir.exists():
|
||||
backup_dir.rename(rocm_dir)
|
||||
raise
|
||||
else:
|
||||
if backup_dir.exists():
|
||||
shutil.rmtree(backup_dir)
|
||||
|
||||
logger.info(f"ROCm backend ready at {rocm_dir}")
|
||||
progress.mark_complete(PROGRESS_KEY)
|
||||
|
||||
except Exception as e:
|
||||
if use_staging and staging_dir.exists():
|
||||
shutil.rmtree(staging_dir)
|
||||
logger.error(f"ROCm backend download failed: {e}")
|
||||
progress.mark_error(PROGRESS_KEY, str(e))
|
||||
raise
|
||||
|
||||
|
||||
def get_rocm_binary_version() -> Optional[str]:
|
||||
"""Get the version of the installed ROCm binary, or None if not installed."""
|
||||
import subprocess
|
||||
|
||||
rocm_path = get_rocm_binary_path()
|
||||
if not rocm_path:
|
||||
return None
|
||||
try:
|
||||
result = subprocess.run(
|
||||
[str(rocm_path), "--version"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=30,
|
||||
cwd=str(rocm_path.parent), # Run from the onedir directory
|
||||
)
|
||||
# Output format: "voicebox-server 0.3.0"
|
||||
for line in result.stdout.strip().splitlines():
|
||||
if "voicebox-server" in line:
|
||||
return line.split()[-1]
|
||||
except Exception as e:
|
||||
logger.warning(f"Could not get ROCm binary version: {e}")
|
||||
return None
|
||||
|
||||
|
||||
async def check_and_update_rocm_binary():
|
||||
"""Check if the ROCm binary is outdated and auto-download if so.
|
||||
|
||||
Called on server startup. Checks both server version and ROCm libs
|
||||
version. Downloads only what's needed.
|
||||
"""
|
||||
rocm_path = get_rocm_binary_path()
|
||||
if not rocm_path:
|
||||
return # No ROCm binary installed, nothing to update
|
||||
|
||||
if is_rocm_active():
|
||||
logger.info("ROCm backend is active; skipping auto-update to avoid replacing the running backend")
|
||||
return
|
||||
|
||||
need_server = _needs_server_download()
|
||||
need_libs = _needs_rocm_libs_download()
|
||||
|
||||
if not need_server and not need_libs:
|
||||
logger.info(f"ROCm binary is up to date (server=v{__version__}, libs={get_installed_rocm_libs_version()})")
|
||||
return
|
||||
|
||||
reasons = []
|
||||
if need_server:
|
||||
rocm_version = get_rocm_binary_version()
|
||||
reasons.append(f"server v{rocm_version} != v{__version__}")
|
||||
if need_libs:
|
||||
installed_libs = get_installed_rocm_libs_version()
|
||||
reasons.append(f"libs {installed_libs} != {ROCM_LIBS_VERSION}")
|
||||
|
||||
logger.info(f"ROCm backend needs update ({', '.join(reasons)}). Auto-downloading...")
|
||||
|
||||
try:
|
||||
await download_rocm_binary()
|
||||
except Exception as e:
|
||||
logger.error(f"Auto-update of ROCm binary failed: {e}")
|
||||
|
||||
|
||||
async def delete_rocm_binary() -> bool:
|
||||
"""Delete the downloaded ROCm backend directory. Returns True if deleted."""
|
||||
import shutil
|
||||
|
||||
rocm_dir = get_rocm_dir()
|
||||
if rocm_dir.exists() and any(rocm_dir.iterdir()):
|
||||
shutil.rmtree(rocm_dir)
|
||||
logger.info(f"Deleted ROCm backend directory: {rocm_dir}")
|
||||
return True
|
||||
return False
|
||||
@@ -125,24 +125,12 @@ async def list_stories(
|
||||
"""
|
||||
stories = db.query(DBStory).order_by(DBStory.updated_at.desc()).all()
|
||||
|
||||
if not stories:
|
||||
return []
|
||||
|
||||
# Batch-fetch all story item counts in one query to avoid an N+1 pattern
|
||||
# (previously there was one COUNT query per story in the loop below).
|
||||
story_ids = [s.id for s in stories]
|
||||
count_rows = (
|
||||
db.query(DBStoryItem.story_id, func.count(DBStoryItem.id).label("cnt"))
|
||||
.filter(DBStoryItem.story_id.in_(story_ids))
|
||||
.group_by(DBStoryItem.story_id)
|
||||
.all()
|
||||
)
|
||||
item_counts = {row.story_id: row.cnt for row in count_rows}
|
||||
|
||||
result = []
|
||||
for story in stories:
|
||||
item_count = db.query(func.count(DBStoryItem.id)).filter(DBStoryItem.story_id == story.id).scalar()
|
||||
|
||||
response = StoryResponse.model_validate(story)
|
||||
response.item_count = item_counts.get(story.id, 0)
|
||||
response.item_count = item_count
|
||||
result.append(response)
|
||||
|
||||
return result
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
"""An in-process fake of the voicebox-cloud API for tests.
|
||||
|
||||
Implements the surface the desktop sync client uses — devices, the account-key
|
||||
escrow, the encrypted object store, the sync feed, and blob storage — behind an
|
||||
httpx.MockTransport, mirroring apps/api in the voicebox-cloud repo. Every
|
||||
request body is kept in ``seen_bodies`` so tests can assert what the server was
|
||||
shown (never key material, never plaintext).
|
||||
"""
|
||||
|
||||
import json
|
||||
|
||||
import httpx
|
||||
|
||||
STORAGE_HOST = "http://cloud.test/__storage/"
|
||||
|
||||
|
||||
class FakeCloud:
|
||||
def __init__(self):
|
||||
self.devices: dict[str, dict] = {}
|
||||
self.account_key: dict | None = None
|
||||
self.objects: dict[str, dict] = {} # objectId -> row (incl. assets dict)
|
||||
self.storage: dict[str, bytes] = {} # key -> ciphertext
|
||||
self.seen_bodies: list[bytes] = []
|
||||
self._next_device = 0
|
||||
self._next_object = 0
|
||||
self._seq = 0
|
||||
|
||||
def transport(self) -> httpx.MockTransport:
|
||||
return httpx.MockTransport(self.handle)
|
||||
|
||||
# -- helpers --------------------------------------------------------------
|
||||
|
||||
@staticmethod
|
||||
def _ok(data, status=200):
|
||||
return httpx.Response(status, json={"ok": True, "data": data})
|
||||
|
||||
def _seq_next(self) -> int:
|
||||
self._seq += 1
|
||||
return self._seq
|
||||
|
||||
def _find_object(self, kind: str, client_id: str) -> dict | None:
|
||||
return next((o for o in self.objects.values() if o["kind"] == kind and o["clientId"] == client_id), None)
|
||||
|
||||
# -- request routing --------------------------------------------------------
|
||||
|
||||
def handle(self, request: httpx.Request) -> httpx.Response:
|
||||
if request.content:
|
||||
self.seen_bodies.append(request.content)
|
||||
path, method = request.url.path, request.method
|
||||
|
||||
if path.startswith("/__storage/"):
|
||||
key = path[len("/__storage/") :]
|
||||
if method == "PUT":
|
||||
self.storage[key] = request.content
|
||||
return httpx.Response(200)
|
||||
data = self.storage.get(key)
|
||||
return httpx.Response(200, content=data) if data is not None else httpx.Response(404)
|
||||
|
||||
if path == "/v1/devices" and method == "POST":
|
||||
return self._register_device(json.loads(request.content))
|
||||
if path == "/v1/devices" and method == "GET":
|
||||
return self._ok(list(self.devices.values()))
|
||||
if path == "/v1/devices/account-key" and method == "PUT":
|
||||
self.account_key = json.loads(request.content)
|
||||
return self._ok(None)
|
||||
if path == "/v1/devices/account-key" and method == "GET":
|
||||
return self._ok(self.account_key)
|
||||
if path.startswith("/v1/devices/") and path.endswith("/wrapped-key"):
|
||||
device_id = path.split("/")[3]
|
||||
if method == "POST":
|
||||
self.devices[device_id]["wrappedMasterKey"] = json.loads(request.content)["wrappedMasterKey"]
|
||||
return self._ok(None)
|
||||
return self._ok({"wrappedMasterKey": self.devices[device_id]["wrappedMasterKey"]})
|
||||
|
||||
if path == "/v1/objects" and method == "POST":
|
||||
return self._upsert_object(json.loads(request.content))
|
||||
if path.startswith("/v1/objects/") and path.endswith("/commit"):
|
||||
return self._commit(path.split("/")[3])
|
||||
if path.startswith("/v1/objects/") and method == "DELETE":
|
||||
obj = self.objects.get(path.split("/")[3])
|
||||
if obj:
|
||||
obj["deleted"] = True
|
||||
obj["seq"] = self._seq_next()
|
||||
return self._ok(None)
|
||||
|
||||
if path == "/v1/sync/changes" and method == "GET":
|
||||
return self._changes(request.url.params)
|
||||
|
||||
return httpx.Response(404, json={"ok": False, "error": {"message": f"unhandled {method} {path}"}})
|
||||
|
||||
# -- endpoint implementations ----------------------------------------------
|
||||
|
||||
def _register_device(self, body: dict) -> httpx.Response:
|
||||
self._next_device += 1
|
||||
device_id = f"dev-{self._next_device}"
|
||||
self.devices[device_id] = {
|
||||
"id": device_id,
|
||||
"name": body["name"],
|
||||
"publicKey": body["publicKey"],
|
||||
"wrappedMasterKey": None,
|
||||
"revokedAt": None,
|
||||
}
|
||||
return self._ok({"deviceId": device_id, "accountHasKey": self.account_key is not None}, 201)
|
||||
|
||||
def _upsert_object(self, body: dict) -> httpx.Response:
|
||||
obj = self._find_object(body["kind"], body["clientId"])
|
||||
if obj is None:
|
||||
self._next_object += 1
|
||||
obj = {
|
||||
"id": f"obj-{self._next_object}",
|
||||
"kind": body["kind"],
|
||||
"clientId": body["clientId"],
|
||||
"version": 0,
|
||||
"deleted": False,
|
||||
"record": None,
|
||||
"assets": {},
|
||||
}
|
||||
self.objects[obj["id"]] = obj
|
||||
|
||||
obj["version"] = max(obj["version"], body["version"])
|
||||
obj["seq"] = self._seq_next()
|
||||
obj["deleted"] = False
|
||||
|
||||
uploads = []
|
||||
record = body.get("record")
|
||||
if record and (obj["record"] is None or obj["record"]["hash"] != record["hash"]):
|
||||
key = f"o/{obj['id']}/record"
|
||||
obj["record"] = {**record, "key": key}
|
||||
uploads.append({"for": "record", "key": key, "url": STORAGE_HOST + key})
|
||||
for asset in body.get("assets", []):
|
||||
caid = asset["clientAssetId"]
|
||||
existing = obj["assets"].get(caid)
|
||||
if existing is None or existing["hash"] != asset["hash"]:
|
||||
key = f"o/{obj['id']}/a/{caid}"
|
||||
obj["assets"][caid] = {**asset, "key": key}
|
||||
uploads.append({"for": f"asset:{caid}", "key": key, "url": STORAGE_HOST + key})
|
||||
return self._ok({"objectId": obj["id"], "seq": obj["seq"], "uploads": uploads}, 201)
|
||||
|
||||
def _commit(self, object_id: str) -> httpx.Response:
|
||||
obj = self.objects.get(object_id)
|
||||
if obj is None:
|
||||
return httpx.Response(404, json={"ok": False, "error": {"message": "object not found"}})
|
||||
missing = []
|
||||
if obj["record"] and obj["record"]["key"] not in self.storage:
|
||||
missing.append("record")
|
||||
for caid, asset in obj["assets"].items():
|
||||
if asset["key"] not in self.storage:
|
||||
missing.append(f"asset:{caid}")
|
||||
if missing:
|
||||
return httpx.Response(409, json={"ok": False, "error": {"message": f"uploads missing: {missing}"}})
|
||||
return self._ok({"objectId": object_id, "committed": True})
|
||||
|
||||
def _changes(self, params) -> httpx.Response:
|
||||
since = int(params.get("since", 0))
|
||||
limit = int(params.get("limit", 200))
|
||||
rows = sorted((o for o in self.objects.values() if o["seq"] > since), key=lambda o: o["seq"])[:limit]
|
||||
changes = [
|
||||
{
|
||||
"id": o["id"],
|
||||
"kind": o["kind"],
|
||||
"clientId": o["clientId"],
|
||||
"version": o["version"],
|
||||
"seq": o["seq"],
|
||||
"deleted": o["deleted"],
|
||||
"record": (
|
||||
{
|
||||
"hash": o["record"]["hash"],
|
||||
"size": o["record"]["size"],
|
||||
"url": STORAGE_HOST + o["record"]["key"],
|
||||
}
|
||||
if o["record"]
|
||||
else None
|
||||
),
|
||||
"assets": [
|
||||
{
|
||||
"clientAssetId": caid,
|
||||
"role": a["role"],
|
||||
"hash": a["hash"],
|
||||
"size": a["size"],
|
||||
"url": STORAGE_HOST + a["key"] if a["key"] in self.storage else None,
|
||||
}
|
||||
for caid, a in o["assets"].items()
|
||||
],
|
||||
}
|
||||
for o in rows
|
||||
]
|
||||
cursor = rows[-1]["seq"] if rows else since
|
||||
return self._ok({"changes": changes, "cursor": cursor, "hasMore": len(rows) == limit})
|
||||
@@ -1,96 +0,0 @@
|
||||
"""
|
||||
Phase 2.1 Test: AMD GPU detection on Windows.
|
||||
|
||||
Validates is_amd_gpu_windows() via mocked WMI and torch queries.
|
||||
|
||||
Usage:
|
||||
python -m pytest backend/tests/test_amd_gpu_detect.py -v
|
||||
"""
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from backend.utils.platform_detect import is_amd_gpu_windows
|
||||
|
||||
|
||||
class TestAmdGpuWindows:
|
||||
"""Unit tests for is_amd_gpu_windows with mocks."""
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _clear_detection_cache(self):
|
||||
# is_amd_gpu_windows is memoized; reset between cases so each mock takes effect.
|
||||
is_amd_gpu_windows.cache_clear()
|
||||
yield
|
||||
is_amd_gpu_windows.cache_clear()
|
||||
|
||||
@patch("backend.utils.platform_detect.platform.system", return_value="Linux")
|
||||
def test_returns_false_on_linux(self, _mock_system):
|
||||
"""Non-Windows platforms should always return False."""
|
||||
assert is_amd_gpu_windows() is False
|
||||
|
||||
@patch("backend.utils.platform_detect.platform.system", return_value="Windows")
|
||||
@patch(
|
||||
"backend.utils.platform_detect.subprocess.run",
|
||||
return_value=MagicMock(stdout="1\n", returncode=0),
|
||||
)
|
||||
def test_detects_amd_via_wmi(self, _mock_run, _mock_system):
|
||||
"""WMI reporting an AMD adapter should return True."""
|
||||
assert is_amd_gpu_windows() is True
|
||||
|
||||
@patch("backend.utils.platform_detect.platform.system", return_value="Windows")
|
||||
@patch(
|
||||
"backend.utils.platform_detect.subprocess.run",
|
||||
return_value=MagicMock(stdout="0\n", returncode=0),
|
||||
)
|
||||
def test_no_amd_via_wmi(self, _mock_run, _mock_system):
|
||||
"""WMI reporting zero AMD adapters should return False."""
|
||||
assert is_amd_gpu_windows() is False
|
||||
|
||||
@patch("backend.utils.platform_detect.platform.system", return_value="Windows")
|
||||
@patch(
|
||||
"backend.utils.platform_detect.subprocess.run",
|
||||
side_effect=Exception("WMI not available"),
|
||||
)
|
||||
@patch("torch.cuda.is_available", return_value=True)
|
||||
@patch(
|
||||
"torch.cuda.get_device_name",
|
||||
return_value="AMD Radeon RX 7800 XT",
|
||||
)
|
||||
def test_fallback_to_torch_radeon(self, _mock_name, _mock_avail, _mock_run, _mock_system):
|
||||
"""When WMI fails, torch.cuda.get_device_name('Radeon') should return True."""
|
||||
assert is_amd_gpu_windows() is True
|
||||
|
||||
@patch("backend.utils.platform_detect.platform.system", return_value="Windows")
|
||||
@patch(
|
||||
"backend.utils.platform_detect.subprocess.run",
|
||||
side_effect=Exception("WMI not available"),
|
||||
)
|
||||
@patch("torch.cuda.is_available", return_value=True)
|
||||
@patch(
|
||||
"torch.cuda.get_device_name",
|
||||
return_value="NVIDIA GeForce RTX 4090",
|
||||
)
|
||||
def test_fallback_to_torch_nvidia(self, _mock_name, _mock_avail, _mock_run, _mock_system):
|
||||
"""When WMI fails, torch.cuda.get_device_name('NVIDIA') should return False."""
|
||||
assert is_amd_gpu_windows() is False
|
||||
|
||||
@patch("backend.utils.platform_detect.platform.system", return_value="Windows")
|
||||
@patch(
|
||||
"backend.utils.platform_detect.subprocess.run",
|
||||
side_effect=Exception("WMI not available"),
|
||||
)
|
||||
@patch("torch.cuda.is_available", return_value=False)
|
||||
def test_no_torch_cuda(self, _mock_avail, _mock_run, _mock_system):
|
||||
"""When WMI fails and torch.cuda is unavailable, should return False."""
|
||||
assert is_amd_gpu_windows() is False
|
||||
|
||||
@patch("backend.utils.platform_detect.platform.system", return_value="Windows")
|
||||
@patch(
|
||||
"backend.utils.platform_detect.subprocess.run",
|
||||
side_effect=Exception("WMI not available"),
|
||||
)
|
||||
def test_torch_not_installed(self, _mock_run, _mock_system):
|
||||
"""When torch is not installed, should return False without crashing."""
|
||||
with patch.dict("sys.modules", {"torch": None}):
|
||||
assert is_amd_gpu_windows() is False
|
||||
@@ -1,164 +0,0 @@
|
||||
"""
|
||||
Regression tests for GET /audio/{generation_id} on failed generations.
|
||||
|
||||
A failed generation stores an empty ``audio_path``. Previously,
|
||||
``config.resolve_storage_path("")`` resolved to the data directory itself,
|
||||
which exists, so the route's 404 guard passed and ``FileResponse`` raised
|
||||
``RuntimeError: File at path .../data is not a file`` — a 500 instead of
|
||||
a clean 404.
|
||||
|
||||
Usage:
|
||||
python -m pytest backend/tests/test_audio_failed_generation.py -v
|
||||
"""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from fastapi import FastAPI
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from starlette.testclient import TestClient
|
||||
|
||||
# Repo root on sys.path so ``backend`` imports as a package (the audio
|
||||
# routes use package-relative imports).
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
|
||||
|
||||
from backend import config
|
||||
from backend.database import (
|
||||
Base,
|
||||
Generation,
|
||||
GenerationVersion,
|
||||
ProfileSample,
|
||||
VoiceProfile,
|
||||
get_db,
|
||||
)
|
||||
from backend.routes.audio import router as audio_router
|
||||
|
||||
|
||||
def test_resolve_storage_path_empty_returns_none():
|
||||
"""An empty stored path must not resolve to the data dir itself."""
|
||||
assert config.resolve_storage_path("") is None
|
||||
assert config.resolve_storage_path(None) is None
|
||||
# Path("") is truthy, so it must be rejected via its (empty) parts.
|
||||
assert config.resolve_storage_path(Path("")) is None
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(tmp_path, monkeypatch):
|
||||
"""Minimal app with only the audio routes and a temp sqlite DB."""
|
||||
monkeypatch.setattr(config, "_data_dir", tmp_path)
|
||||
# An existing directory that a stored audio_path may wrongly point to.
|
||||
(tmp_path / "somedir").mkdir()
|
||||
|
||||
engine = create_engine(
|
||||
f"sqlite:///{tmp_path / 'test.db'}",
|
||||
connect_args={"check_same_thread": False},
|
||||
)
|
||||
Base.metadata.create_all(bind=engine)
|
||||
testing_session_local = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
session = testing_session_local()
|
||||
profile = VoiceProfile(id="profile-1", name="Test Profile")
|
||||
session.add(profile)
|
||||
|
||||
session.add_all(
|
||||
[
|
||||
Generation(
|
||||
id="gen-failed-empty",
|
||||
profile_id="profile-1",
|
||||
text="failed generation",
|
||||
audio_path="",
|
||||
status="failed",
|
||||
error="engine exploded",
|
||||
),
|
||||
Generation(
|
||||
id="gen-failed-null",
|
||||
profile_id="profile-1",
|
||||
text="failed generation",
|
||||
audio_path=None,
|
||||
status="failed",
|
||||
),
|
||||
Generation(
|
||||
id="gen-missing-file",
|
||||
profile_id="profile-1",
|
||||
text="completed but file deleted",
|
||||
audio_path="generations/does-not-exist.wav",
|
||||
status="completed",
|
||||
),
|
||||
Generation(
|
||||
id="gen-with-version",
|
||||
profile_id="profile-1",
|
||||
text="generation with a broken version",
|
||||
audio_path="somedir",
|
||||
status="completed",
|
||||
),
|
||||
GenerationVersion(
|
||||
id="version-dir",
|
||||
generation_id="gen-with-version",
|
||||
label="original",
|
||||
audio_path="somedir",
|
||||
),
|
||||
ProfileSample(
|
||||
id="sample-dir",
|
||||
profile_id="profile-1",
|
||||
audio_path="somedir",
|
||||
reference_text="sample pointing at a directory",
|
||||
),
|
||||
]
|
||||
)
|
||||
session.commit()
|
||||
session.close()
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(audio_router)
|
||||
|
||||
def override_get_db():
|
||||
db = testing_session_local()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
app.dependency_overrides[get_db] = override_get_db
|
||||
return TestClient(app)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("generation_id", ["gen-failed-empty", "gen-failed-null"])
|
||||
def test_failed_generation_returns_404(client, generation_id):
|
||||
"""Failed generations (empty/null audio_path) get a clean 404, not a 500."""
|
||||
response = client.get(f"/audio/{generation_id}")
|
||||
assert response.status_code == 404
|
||||
assert response.json()["detail"] == "Generation failed; no audio available"
|
||||
|
||||
|
||||
def test_missing_audio_file_returns_404(client):
|
||||
"""A completed generation whose file vanished still 404s."""
|
||||
response = client.get("/audio/gen-missing-file")
|
||||
assert response.status_code == 404
|
||||
assert response.json()["detail"] == "Audio file not found"
|
||||
|
||||
|
||||
def test_unknown_generation_returns_404(client):
|
||||
response = client.get("/audio/no-such-generation")
|
||||
assert response.status_code == 404
|
||||
assert response.json()["detail"] == "Generation not found"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"url",
|
||||
[
|
||||
"/audio/gen-with-version",
|
||||
"/audio/version/version-dir",
|
||||
"/samples/sample-dir",
|
||||
],
|
||||
)
|
||||
def test_audio_path_pointing_at_directory_returns_404(client, url):
|
||||
"""A stored path resolving to an existing directory must 404, not 500.
|
||||
|
||||
Guards the is_file() checks: a directory passes exists() and would
|
||||
crash FileResponse.
|
||||
"""
|
||||
response = client.get(url)
|
||||
assert response.status_code == 404
|
||||
assert response.json()["detail"] == "Audio file not found"
|
||||
@@ -1,123 +0,0 @@
|
||||
"""
|
||||
Regression tests for issue #852: audioop removed from Python 3.13 stdlib.
|
||||
|
||||
Voice sample validation imports audioop transitively (librosa → audioread).
|
||||
The audioop-lts backport must be declared in requirements and bundled in
|
||||
PyInstaller builds on 3.13+.
|
||||
"""
|
||||
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
from build_binary import build_server
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def backend_dir():
|
||||
return Path(__file__).parent.parent
|
||||
|
||||
|
||||
class TestAudioopRequirements:
|
||||
def test_requirements_declare_audioop_lts_for_python_313(self, backend_dir):
|
||||
content = (backend_dir / "requirements.txt").read_text()
|
||||
assert re.search(
|
||||
r"^audioop-lts.*python_version\s*>=\s*['\"]3\.13['\"]",
|
||||
content,
|
||||
re.MULTILINE,
|
||||
), "requirements.txt must pin audioop-lts for Python 3.13+"
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info < (3, 13), reason="Python 3.13+ only")
|
||||
class TestAudioopRuntime:
|
||||
def test_audioop_importable(self):
|
||||
import audioop # noqa: F401
|
||||
|
||||
def test_validate_reference_wav_does_not_fail_on_missing_audioop(self, tmp_path):
|
||||
import numpy as np
|
||||
import soundfile as sf
|
||||
from utils.audio import validate_and_load_reference_audio
|
||||
|
||||
sr = 24000
|
||||
t = np.arange(int(sr * 3), dtype=np.float32) / sr
|
||||
audio = (0.3 * np.sin(2 * np.pi * 220 * t)).astype(np.float32)
|
||||
path = tmp_path / "reference.wav"
|
||||
sf.write(str(path), audio, sr)
|
||||
|
||||
ok, err, out_audio, out_sr = validate_and_load_reference_audio(str(path))
|
||||
|
||||
assert ok, err
|
||||
assert out_audio is not None
|
||||
assert out_sr == sr
|
||||
assert "audioop" not in (err or "").lower()
|
||||
|
||||
|
||||
class TestAudioopBuildArgs:
|
||||
@staticmethod
|
||||
def _hidden_imports(args):
|
||||
imports = []
|
||||
for i, arg in enumerate(args):
|
||||
if arg == "--hidden-import" and i + 1 < len(args):
|
||||
imports.append(args[i + 1])
|
||||
return imports
|
||||
|
||||
def test_pyinstaller_includes_audioop_on_python_313(self):
|
||||
class FakeVersionInfo(tuple):
|
||||
@property
|
||||
def major(self):
|
||||
return self[0]
|
||||
|
||||
@property
|
||||
def minor(self):
|
||||
return self[1]
|
||||
|
||||
@property
|
||||
def micro(self):
|
||||
return self[2]
|
||||
|
||||
fake_313 = FakeVersionInfo((3, 13, 0, "final", 0))
|
||||
|
||||
with (
|
||||
patch("build_binary.PyInstaller.__main__.run") as mock_run,
|
||||
patch("build_binary.platform.system", return_value="Linux"),
|
||||
patch("build_binary.is_apple_silicon", return_value=False),
|
||||
patch("build_binary.os.chdir"),
|
||||
patch("build_binary.sys.version_info", fake_313),
|
||||
):
|
||||
build_server()
|
||||
args = mock_run.call_args[0][0]
|
||||
|
||||
assert "audioop" in self._hidden_imports(args)
|
||||
|
||||
def test_pyinstaller_omits_audioop_on_python_312(self):
|
||||
class FakeVersionInfo(tuple):
|
||||
@property
|
||||
def major(self):
|
||||
return self[0]
|
||||
|
||||
@property
|
||||
def minor(self):
|
||||
return self[1]
|
||||
|
||||
@property
|
||||
def micro(self):
|
||||
return self[2]
|
||||
|
||||
fake_312 = FakeVersionInfo((3, 12, 0, "final", 0))
|
||||
|
||||
with (
|
||||
patch("build_binary.PyInstaller.__main__.run") as mock_run,
|
||||
patch("build_binary.platform.system", return_value="Linux"),
|
||||
patch("build_binary.is_apple_silicon", return_value=False),
|
||||
patch("build_binary.os.chdir"),
|
||||
patch("build_binary.sys.version_info", fake_312),
|
||||
):
|
||||
build_server()
|
||||
args = mock_run.call_args[0][0]
|
||||
|
||||
assert "audioop" not in self._hidden_imports(args)
|
||||
@@ -0,0 +1,174 @@
|
||||
"""Tests for the cloud sync identity flows (services/cloud_account.py).
|
||||
|
||||
Runs the real flows against a fake in-process cloud (httpx.MockTransport) and
|
||||
a fake in-memory keyring — no network, no OS keychain. The central assertion:
|
||||
the master key and recovery phrase never appear in anything sent to the server.
|
||||
"""
|
||||
|
||||
import base64
|
||||
from datetime import datetime
|
||||
|
||||
import keyring
|
||||
import keyring.backend
|
||||
import pytest
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from backend.database.models import Base, CloudSettings
|
||||
from backend.services import cloud_account, cloud_crypto, cloud_keys
|
||||
from backend.services.cloud_account import CloudAccountError
|
||||
from backend.services.cloud_api import CloudApiClient
|
||||
from backend.tests.fake_cloud import FakeCloud
|
||||
|
||||
USER_A = "user-a"
|
||||
|
||||
|
||||
class InMemoryKeyring(keyring.backend.KeyringBackend):
|
||||
priority = 1
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.store: dict[tuple[str, str], str] = {}
|
||||
|
||||
def get_password(self, service, username):
|
||||
return self.store.get((service, username))
|
||||
|
||||
def set_password(self, service, username, password):
|
||||
self.store[(service, username)] = password
|
||||
|
||||
def delete_password(self, service, username):
|
||||
self.store.pop((service, username), None)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake_keyring(monkeypatch):
|
||||
backend = InMemoryKeyring()
|
||||
monkeypatch.setattr(keyring, "get_password", backend.get_password)
|
||||
monkeypatch.setattr(keyring, "set_password", backend.set_password)
|
||||
monkeypatch.setattr(keyring, "delete_password", backend.delete_password)
|
||||
return backend
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cloud():
|
||||
return FakeCloud()
|
||||
|
||||
|
||||
def make_db(account_user_id=USER_A):
|
||||
engine = create_engine("sqlite://")
|
||||
Base.metadata.create_all(engine)
|
||||
db = sessionmaker(bind=engine)()
|
||||
db.add(
|
||||
CloudSettings(
|
||||
id=1,
|
||||
api_key="voicebox_test",
|
||||
device_name="Test Mac",
|
||||
account_user_id=account_user_id,
|
||||
connected_at=datetime(2026, 7, 1),
|
||||
)
|
||||
)
|
||||
db.commit()
|
||||
return db
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def patched_client(monkeypatch, cloud):
|
||||
def _client(row):
|
||||
return CloudApiClient("http://cloud.test", row.api_key, transport=cloud.transport())
|
||||
|
||||
monkeypatch.setattr(cloud_account, "_client", _client)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("patched_client", "fake_keyring")
|
||||
class TestIdentityFlows:
|
||||
async def test_first_device_setup(self, cloud):
|
||||
db = make_db()
|
||||
phrase = await cloud_account.setup_device(db)
|
||||
|
||||
assert phrase is not None
|
||||
assert cloud_crypto.validate_recovery_phrase(phrase)
|
||||
assert cloud_account.identity_status(db).status == "ready"
|
||||
assert cloud.account_key is not None
|
||||
# Registered + provisioned to itself.
|
||||
(device,) = cloud.devices.values()
|
||||
assert device["wrappedMasterKey"]
|
||||
|
||||
# The invariant: neither MK nor the phrase ever crossed the wire.
|
||||
mk = cloud_account.load_master_key(db)
|
||||
for body in cloud.seen_bodies:
|
||||
assert mk not in body
|
||||
assert base64.b64encode(mk) not in body
|
||||
assert phrase.encode() not in body
|
||||
|
||||
async def test_second_device_via_provisioning(self, cloud):
|
||||
db_a = make_db()
|
||||
await cloud_account.setup_device(db_a)
|
||||
mk_a = cloud_account.load_master_key(db_a)
|
||||
|
||||
# Second install: same account, its own DB + keychain namespace. Reuse
|
||||
# the same fake keyring but a distinct account row would collide, so
|
||||
# simulate the second device with a separate account_user_id-scoped
|
||||
# keychain by clearing MK after capturing device state.
|
||||
db_b = make_db(account_user_id="user-a-second-install")
|
||||
assert await cloud_account.setup_device(db_b) is None # account already has key material
|
||||
assert cloud_account.identity_status(db_b).status == "awaiting_provision"
|
||||
assert await cloud_account.adopt_wrapped_key(db_b) is False # nothing provisioned yet
|
||||
|
||||
target_id = db_b.query(CloudSettings).one().sync_device_id
|
||||
await cloud_account.provision_device(db_a, target_id)
|
||||
assert await cloud_account.adopt_wrapped_key(db_b) is True
|
||||
assert cloud_account.load_master_key(db_b) == mk_a
|
||||
|
||||
async def test_restore_with_phrase(self, cloud):
|
||||
db_a = make_db()
|
||||
phrase = await cloud_account.setup_device(db_a)
|
||||
mk_a = cloud_account.load_master_key(db_a)
|
||||
|
||||
db_b = make_db(account_user_id="user-a-fresh-machine")
|
||||
assert await cloud_account.setup_device(db_b) is None
|
||||
await cloud_account.restore_with_phrase(db_b, phrase)
|
||||
assert cloud_account.load_master_key(db_b) == mk_a
|
||||
assert cloud_account.identity_status(db_b).status == "ready"
|
||||
|
||||
async def test_restore_rejects_wrong_phrase(self, cloud):
|
||||
db_a = make_db()
|
||||
await cloud_account.setup_device(db_a)
|
||||
|
||||
db_b = make_db(account_user_id="user-a-fresh-machine")
|
||||
await cloud_account.setup_device(db_b)
|
||||
with pytest.raises(cloud_crypto.CloudCryptoError):
|
||||
await cloud_account.restore_with_phrase(db_b, cloud_crypto.generate_recovery_phrase())
|
||||
|
||||
async def test_restore_rejects_invalid_phrase_early(self, cloud):
|
||||
db = make_db()
|
||||
await cloud_account.setup_device(db)
|
||||
with pytest.raises(CloudAccountError, match="valid recovery phrase"):
|
||||
await cloud_account.restore_with_phrase(
|
||||
db, "not a real phrase at all twelve words missing checksum here ok"
|
||||
)
|
||||
|
||||
async def test_double_registration_rejected(self, cloud):
|
||||
db = make_db()
|
||||
await cloud_account.setup_device(db)
|
||||
with pytest.raises(CloudAccountError, match="already registered"):
|
||||
await cloud_account.setup_device(db)
|
||||
|
||||
async def test_requires_login(self, cloud):
|
||||
engine = create_engine("sqlite://")
|
||||
Base.metadata.create_all(engine)
|
||||
db = sessionmaker(bind=engine)()
|
||||
with pytest.raises(CloudAccountError, match="log in"):
|
||||
await cloud_account.setup_device(db)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("fake_keyring")
|
||||
class TestKeyStore:
|
||||
def test_round_trip_and_clear(self):
|
||||
cloud_keys.store_secret(USER_A, cloud_keys.MASTER_KEY, b"\x01" * 32)
|
||||
assert cloud_keys.load_secret(USER_A, cloud_keys.MASTER_KEY) == b"\x01" * 32
|
||||
assert cloud_keys.load_secret("other-user", cloud_keys.MASTER_KEY) is None
|
||||
cloud_keys.clear(USER_A)
|
||||
assert cloud_keys.load_secret(USER_A, cloud_keys.MASTER_KEY) is None
|
||||
|
||||
def test_delete_absent_is_noop(self):
|
||||
cloud_keys.delete_secret(USER_A, cloud_keys.DEVICE_PRIVATE_KEY)
|
||||
@@ -0,0 +1,137 @@
|
||||
"""Tests for the cloud E2E crypto primitives (services/cloud_crypto.py)."""
|
||||
|
||||
import pytest
|
||||
|
||||
from backend.services.cloud_crypto import (
|
||||
ALG_XCHACHA20_POLY1305,
|
||||
ENVELOPE_MAGIC,
|
||||
CloudCryptoError,
|
||||
RecoveryWrap,
|
||||
decrypt_blob,
|
||||
encrypt_blob,
|
||||
generate_device_keypair,
|
||||
generate_master_key,
|
||||
generate_recovery_phrase,
|
||||
unwrap_master_key_for_device,
|
||||
unwrap_master_key_with_phrase,
|
||||
validate_recovery_phrase,
|
||||
wrap_master_key_for_device,
|
||||
wrap_master_key_with_phrase,
|
||||
)
|
||||
|
||||
SLOT = {"object_id": "0c8f6f4e-9f5a-4a2f-8f6a-1d2e3f4a5b6c", "role": "audio", "version": 3}
|
||||
|
||||
|
||||
class TestMasterKey:
|
||||
def test_master_keys_are_random_32_bytes(self):
|
||||
a, b = generate_master_key(), generate_master_key()
|
||||
assert len(a) == 32
|
||||
assert a != b
|
||||
|
||||
|
||||
class TestDeviceWrap:
|
||||
def test_round_trip(self):
|
||||
mk = generate_master_key()
|
||||
private, public = generate_device_keypair()
|
||||
assert unwrap_master_key_for_device(wrap_master_key_for_device(mk, public), private) == mk
|
||||
|
||||
def test_wrong_device_key_fails(self):
|
||||
mk = generate_master_key()
|
||||
_, public = generate_device_keypair()
|
||||
other_private, _ = generate_device_keypair()
|
||||
with pytest.raises(CloudCryptoError):
|
||||
unwrap_master_key_for_device(wrap_master_key_for_device(mk, public), other_private)
|
||||
|
||||
|
||||
class TestRecoveryPhrase:
|
||||
def test_phrase_is_valid_bip39(self):
|
||||
phrase = generate_recovery_phrase()
|
||||
assert len(phrase.split()) == 12
|
||||
assert validate_recovery_phrase(phrase)
|
||||
|
||||
def test_typo_fails_checksum(self):
|
||||
words = generate_recovery_phrase().split()
|
||||
words[0] = "abandon" if words[0] != "abandon" else "ability"
|
||||
assert not validate_recovery_phrase(" ".join(words))
|
||||
|
||||
def test_round_trip(self):
|
||||
mk = generate_master_key()
|
||||
phrase = generate_recovery_phrase()
|
||||
assert unwrap_master_key_with_phrase(wrap_master_key_with_phrase(mk, phrase), phrase) == mk
|
||||
|
||||
def test_normalization_tolerates_case_and_whitespace(self):
|
||||
mk = generate_master_key()
|
||||
phrase = generate_recovery_phrase()
|
||||
wrap = wrap_master_key_with_phrase(mk, phrase)
|
||||
sloppy = f" {phrase.upper().replace(' ', ' ')} \n"
|
||||
assert unwrap_master_key_with_phrase(wrap, sloppy) == mk
|
||||
|
||||
def test_wrong_phrase_fails(self):
|
||||
wrap = wrap_master_key_with_phrase(generate_master_key(), generate_recovery_phrase())
|
||||
with pytest.raises(CloudCryptoError):
|
||||
unwrap_master_key_with_phrase(wrap, generate_recovery_phrase())
|
||||
|
||||
def test_malformed_kdf_params_fail(self):
|
||||
wrap = wrap_master_key_with_phrase(generate_master_key(), generate_recovery_phrase())
|
||||
broken = RecoveryWrap(wrapped_key=wrap.wrapped_key, kdf_salt=wrap.kdf_salt, kdf_params="not json")
|
||||
with pytest.raises(CloudCryptoError):
|
||||
unwrap_master_key_with_phrase(broken, generate_recovery_phrase())
|
||||
|
||||
|
||||
class TestEnvelope:
|
||||
def test_round_trip(self):
|
||||
mk = generate_master_key()
|
||||
plaintext = b"capture transcript \xf0\x9f\x8e\x99 and some audio bytes" * 100
|
||||
envelope = encrypt_blob(plaintext, mk, **SLOT)
|
||||
assert envelope[:4] == ENVELOPE_MAGIC
|
||||
assert envelope[4] == ALG_XCHACHA20_POLY1305
|
||||
assert decrypt_blob(envelope, mk, **SLOT) == plaintext
|
||||
|
||||
def test_fresh_content_key_per_blob(self):
|
||||
mk = generate_master_key()
|
||||
assert encrypt_blob(b"same", mk, **SLOT) != encrypt_blob(b"same", mk, **SLOT)
|
||||
|
||||
def test_wrong_master_key_fails(self):
|
||||
envelope = encrypt_blob(b"secret", generate_master_key(), **SLOT)
|
||||
with pytest.raises(CloudCryptoError):
|
||||
decrypt_blob(envelope, generate_master_key(), **SLOT)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"slot",
|
||||
[
|
||||
{**SLOT, "object_id": "11111111-2222-3333-4444-555555555555"},
|
||||
{**SLOT, "role": "avatar"},
|
||||
{**SLOT, "version": 4},
|
||||
],
|
||||
)
|
||||
def test_wrong_slot_fails_aad(self, slot):
|
||||
mk = generate_master_key()
|
||||
envelope = encrypt_blob(b"secret", mk, **SLOT)
|
||||
with pytest.raises(CloudCryptoError):
|
||||
decrypt_blob(envelope, mk, **slot)
|
||||
|
||||
def test_tampered_ciphertext_fails(self):
|
||||
mk = generate_master_key()
|
||||
envelope = bytearray(encrypt_blob(b"secret", mk, **SLOT))
|
||||
envelope[-1] ^= 0x01
|
||||
with pytest.raises(CloudCryptoError):
|
||||
decrypt_blob(bytes(envelope), mk, **SLOT)
|
||||
|
||||
def test_bad_magic_and_truncation_fail(self):
|
||||
mk = generate_master_key()
|
||||
envelope = encrypt_blob(b"secret", mk, **SLOT)
|
||||
with pytest.raises(CloudCryptoError):
|
||||
decrypt_blob(b"NOPE" + envelope[4:], mk, **SLOT)
|
||||
with pytest.raises(CloudCryptoError):
|
||||
decrypt_blob(envelope[:20], mk, **SLOT)
|
||||
|
||||
def test_unknown_algorithm_fails(self):
|
||||
mk = generate_master_key()
|
||||
envelope = bytearray(encrypt_blob(b"secret", mk, **SLOT))
|
||||
envelope[4] = 99
|
||||
with pytest.raises(CloudCryptoError):
|
||||
decrypt_blob(bytes(envelope), mk, **SLOT)
|
||||
|
||||
def test_empty_plaintext_round_trips(self):
|
||||
mk = generate_master_key()
|
||||
assert decrypt_blob(encrypt_blob(b"", mk, **SLOT), mk, **SLOT) == b""
|
||||
@@ -0,0 +1,104 @@
|
||||
"""End-to-end round-trip against a real voicebox-cloud dev server.
|
||||
|
||||
Skipped unless VOICEBOX_CLOUD_TEST_API + VOICEBOX_CLOUD_TEST_KEY are set:
|
||||
|
||||
cd voicebox-cloud && pnpm dev:db && pnpm db:migrate && pnpm dev:api
|
||||
# create an account + API key (web app or seed script), then:
|
||||
VOICEBOX_CLOUD_TEST_API=http://localhost:17593 \\
|
||||
VOICEBOX_CLOUD_TEST_KEY=voicebox_… \\
|
||||
pytest backend/tests/test_cloud_roundtrip_integration.py -v
|
||||
|
||||
Exercises the scaffolded server for real: device registration, recovery
|
||||
escrow, encrypted push (presigned PUT + commit), sync pull, decrypt — and
|
||||
verifies the ciphertext at rest is opaque.
|
||||
"""
|
||||
|
||||
import base64
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
|
||||
from backend.services import cloud_crypto
|
||||
from backend.services.cloud_api import CloudApiClient
|
||||
|
||||
API_URL = os.environ.get("VOICEBOX_CLOUD_TEST_API")
|
||||
API_KEY = os.environ.get("VOICEBOX_CLOUD_TEST_KEY")
|
||||
|
||||
pytestmark = pytest.mark.skipif(
|
||||
not (API_URL and API_KEY),
|
||||
reason="set VOICEBOX_CLOUD_TEST_API and VOICEBOX_CLOUD_TEST_KEY to run against a dev server",
|
||||
)
|
||||
|
||||
|
||||
async def test_full_roundtrip():
|
||||
master_key = cloud_crypto.generate_master_key()
|
||||
client_id = str(uuid.uuid4())
|
||||
record_plain = json.dumps({"transcript_raw": "hello from the integration test", "language": "en"}).encode()
|
||||
audio_plain = os.urandom(64_000) # stands in for capture audio
|
||||
|
||||
async with CloudApiClient(API_URL, API_KEY) as client:
|
||||
# Device + escrow round-trip.
|
||||
private_key, public_key = cloud_crypto.generate_device_keypair()
|
||||
registered = await client.register_device("integration-test", base64.b64encode(public_key).decode())
|
||||
device_id = registered["deviceId"]
|
||||
wrapped = cloud_crypto.wrap_master_key_for_device(master_key, public_key)
|
||||
await client.put_wrapped_key(device_id, base64.b64encode(wrapped).decode())
|
||||
fetched = await client.get_wrapped_key(device_id)
|
||||
assert cloud_crypto.unwrap_master_key_for_device(base64.b64decode(fetched), private_key) == master_key
|
||||
|
||||
# Push: encrypt locally, upsert metadata, PUT ciphertext, commit.
|
||||
object_id_placeholder = client_id # AAD object binding uses the client id pre-push
|
||||
record_env = cloud_crypto.encrypt_blob(
|
||||
record_plain, master_key, object_id=object_id_placeholder, role="record", version=1
|
||||
)
|
||||
audio_env = cloud_crypto.encrypt_blob(
|
||||
audio_plain, master_key, object_id=object_id_placeholder, role="audio", version=1
|
||||
)
|
||||
pushed = await client.push_object(
|
||||
kind="capture",
|
||||
client_id=client_id,
|
||||
version=1,
|
||||
record={"hash": hashlib.sha256(record_env).hexdigest(), "size": len(record_env)},
|
||||
assets=[
|
||||
{
|
||||
"role": "audio",
|
||||
"clientAssetId": f"{client_id}-audio",
|
||||
"hash": hashlib.sha256(audio_env).hexdigest(),
|
||||
"size": len(audio_env),
|
||||
}
|
||||
],
|
||||
)
|
||||
uploads = {u["for"]: u["url"] for u in pushed["uploads"]}
|
||||
await client.upload_blob(uploads["record"], record_env)
|
||||
await client.upload_blob(uploads[f"asset:{client_id}-audio"], audio_env)
|
||||
await client.commit_object(pushed["objectId"])
|
||||
|
||||
# Pull: cursor 0 must include our object; ciphertext decrypts to the original.
|
||||
changes = await client.get_changes(since=pushed["seq"] - 1, limit=10)
|
||||
change = next(c for c in changes["changes"] if c["clientId"] == client_id)
|
||||
assert change["kind"] == "capture"
|
||||
assert not change["deleted"]
|
||||
|
||||
record_cipher = await client.download_blob(change["record"]["url"])
|
||||
assert record_cipher == record_env # opaque, byte-identical ciphertext at rest
|
||||
assert record_plain not in record_cipher
|
||||
assert (
|
||||
cloud_crypto.decrypt_blob(record_cipher, master_key, object_id=client_id, role="record", version=1)
|
||||
== record_plain
|
||||
)
|
||||
|
||||
(asset,) = change["assets"]
|
||||
audio_cipher = await client.download_blob(asset["url"])
|
||||
assert (
|
||||
cloud_crypto.decrypt_blob(audio_cipher, master_key, object_id=client_id, role="audio", version=1)
|
||||
== audio_plain
|
||||
)
|
||||
|
||||
# Tombstone propagates.
|
||||
await client.delete_object(pushed["objectId"])
|
||||
changes = await client.get_changes(since=changes["cursor"], limit=10)
|
||||
tombstone = next(c for c in changes["changes"] if c["clientId"] == client_id)
|
||||
assert tombstone["deleted"] is True
|
||||
@@ -0,0 +1,278 @@
|
||||
"""Tests for the cloud sync engine (services/cloud_sync.py).
|
||||
|
||||
Simulates two installs ("machines") of the desktop app — each with its own
|
||||
SQLite database, data directory, and keychain — syncing through the in-process
|
||||
FakeCloud. Covers the full backup → restore path, incremental pushes, deletes,
|
||||
and the blindness invariant (nothing plaintext ever lands in server storage).
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
import keyring
|
||||
import pytest
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from backend import config
|
||||
from backend.database.models import (
|
||||
Base,
|
||||
Capture,
|
||||
CaptureSettings,
|
||||
CloudSettings,
|
||||
Generation,
|
||||
GenerationVersion,
|
||||
ProfileSample,
|
||||
VoiceProfile,
|
||||
)
|
||||
from backend.services import cloud_account, cloud_sync
|
||||
from backend.services.cloud_api import CloudApiClient
|
||||
from backend.tests.fake_cloud import FakeCloud
|
||||
|
||||
AUDIO_A = b"RIFFfake-capture-audio" + b"\x11" * 4000
|
||||
AUDIO_B = b"RIFFfake-generation-audio" + b"\x22" * 4000
|
||||
AUDIO_C = b"RIFFfake-version-audio" + b"\x33" * 4000
|
||||
AUDIO_D = b"RIFFfake-sample-audio" + b"\x44" * 4000
|
||||
AVATAR = b"\x89PNGfake-avatar" + b"\x55" * 500
|
||||
|
||||
|
||||
class Install:
|
||||
"""One simulated machine: its own DB, data dir, and keychain store."""
|
||||
|
||||
def __init__(self, root, name: str):
|
||||
self.data_dir = root / name
|
||||
self.data_dir.mkdir()
|
||||
self.keychain: dict[tuple[str, str], str] = {}
|
||||
engine = create_engine("sqlite://")
|
||||
Base.metadata.create_all(engine)
|
||||
self.db = sessionmaker(bind=engine)()
|
||||
self.db.add(
|
||||
CloudSettings(
|
||||
id=1,
|
||||
api_key=f"voicebox_{name}",
|
||||
device_name=name,
|
||||
account_user_id="user-1",
|
||||
connected_at=datetime(2026, 7, 1),
|
||||
)
|
||||
)
|
||||
self.db.commit()
|
||||
|
||||
def activate(self, monkeypatch):
|
||||
"""Point global config + keychain at this machine."""
|
||||
config.set_data_dir(self.data_dir)
|
||||
store = self.keychain
|
||||
monkeypatch.setattr(keyring, "get_password", lambda s, u: store.get((s, u)))
|
||||
monkeypatch.setattr(keyring, "set_password", lambda s, u, p: store.__setitem__((s, u), p))
|
||||
monkeypatch.setattr(keyring, "delete_password", lambda s, u: store.pop((s, u), None))
|
||||
|
||||
def write_file(self, relative: str, data: bytes) -> str:
|
||||
path = self.data_dir / relative
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_bytes(data)
|
||||
return str(path)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cloud(monkeypatch):
|
||||
fake = FakeCloud()
|
||||
monkeypatch.setattr(
|
||||
cloud_sync,
|
||||
"CloudApiClient",
|
||||
lambda url, key: CloudApiClient(url, key, transport=fake.transport()),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
cloud_account,
|
||||
"_client",
|
||||
lambda row: CloudApiClient("http://cloud.test", row.api_key, transport=fake.transport()),
|
||||
)
|
||||
return fake
|
||||
|
||||
|
||||
def seed_content(install: Install) -> None:
|
||||
db = install.db
|
||||
profile = VoiceProfile(
|
||||
id="prof-1",
|
||||
name="Morgan",
|
||||
description="test voice",
|
||||
language="en",
|
||||
avatar_path=install.write_file("profiles/prof-1/avatar.png", AVATAR),
|
||||
personality="dry wit",
|
||||
)
|
||||
db.add(profile)
|
||||
db.add(
|
||||
ProfileSample(
|
||||
id="samp-1",
|
||||
profile_id="prof-1",
|
||||
audio_path=install.write_file("profiles/prof-1/samples/samp-1.wav", AUDIO_D),
|
||||
reference_text="hello there",
|
||||
)
|
||||
)
|
||||
db.add(
|
||||
Capture(
|
||||
id="cap-1",
|
||||
audio_path=install.write_file("captures/cap-1.wav", AUDIO_A),
|
||||
source="dictation",
|
||||
language="en",
|
||||
transcript_raw="the raw transcript",
|
||||
transcript_refined="the refined transcript",
|
||||
)
|
||||
)
|
||||
db.add(
|
||||
Generation(
|
||||
id="gen-1",
|
||||
profile_id="prof-1",
|
||||
text="hello world",
|
||||
audio_path=install.write_file("generations/gen-1.wav", AUDIO_B),
|
||||
status="completed",
|
||||
source="manual",
|
||||
)
|
||||
)
|
||||
db.add(
|
||||
GenerationVersion(
|
||||
id="ver-1",
|
||||
generation_id="gen-1",
|
||||
label="Take 2",
|
||||
audio_path=install.write_file("generations/ver-1.wav", AUDIO_C),
|
||||
)
|
||||
)
|
||||
db.add(CaptureSettings(id=1, stt_model="turbo", language="auto"))
|
||||
db.commit()
|
||||
|
||||
|
||||
async def connect(install: Install, monkeypatch, phrase: str | None = None) -> str | None:
|
||||
install.activate(monkeypatch)
|
||||
result = await cloud_account.setup_device(install.db)
|
||||
if phrase is not None:
|
||||
await cloud_account.restore_with_phrase(install.db, phrase)
|
||||
return result
|
||||
|
||||
|
||||
class TestSyncEngine:
|
||||
async def test_backup_then_restore_on_second_machine(self, cloud, tmp_path, monkeypatch):
|
||||
a = Install(tmp_path, "machine-a")
|
||||
phrase = await connect(a, monkeypatch)
|
||||
seed_content(a)
|
||||
|
||||
report = await cloud_sync.run_sync(a.db)
|
||||
assert report.pushed == 4 # capture, generation, profile, capture_settings
|
||||
assert report.pulled == 0 # own echoes are recognized by ciphertext hash
|
||||
|
||||
# Server blindness: every stored blob is a VBX1 envelope, no plaintext.
|
||||
assert cloud.storage
|
||||
for blob in cloud.storage.values():
|
||||
assert blob[:4] == b"VBX1"
|
||||
assert b"transcript" not in blob
|
||||
assert AUDIO_A not in blob
|
||||
for body in cloud.seen_bodies:
|
||||
assert b"the raw transcript" not in body
|
||||
assert b"Morgan" not in body
|
||||
|
||||
# Fresh machine: restore identity from phrase, then pull everything.
|
||||
b = Install(tmp_path, "machine-b")
|
||||
await connect(b, monkeypatch, phrase=phrase)
|
||||
report_b = await cloud_sync.run_sync(b.db)
|
||||
assert report_b.pulled == report.pushed
|
||||
|
||||
cap = b.db.query(Capture).one()
|
||||
assert cap.id == "cap-1"
|
||||
assert cap.transcript_raw == "the raw transcript"
|
||||
assert (b.data_dir / "captures/cap-1.wav").read_bytes() == AUDIO_A
|
||||
|
||||
prof = b.db.query(VoiceProfile).one()
|
||||
assert prof.name == "Morgan"
|
||||
assert prof.personality == "dry wit"
|
||||
assert (b.data_dir / "profiles/prof-1/avatar.png").read_bytes() == AVATAR
|
||||
samp = b.db.query(ProfileSample).one()
|
||||
assert samp.reference_text == "hello there"
|
||||
assert (b.data_dir / "profiles/prof-1/samples/samp-1.wav").read_bytes() == AUDIO_D
|
||||
|
||||
gen = b.db.query(Generation).one()
|
||||
assert gen.text == "hello world"
|
||||
assert (b.data_dir / "generations/gen-1.wav").read_bytes() == AUDIO_B
|
||||
ver = b.db.query(GenerationVersion).one()
|
||||
assert ver.label == "Take 2"
|
||||
assert (b.data_dir / "generations/ver-1.wav").read_bytes() == AUDIO_C
|
||||
|
||||
settings = b.db.query(CaptureSettings).one()
|
||||
assert settings.stt_model == "turbo"
|
||||
|
||||
# Second sync on B is a no-op in both directions.
|
||||
report_b2 = await cloud_sync.run_sync(b.db)
|
||||
assert (report_b2.pushed, report_b2.pulled) == (0, 0)
|
||||
|
||||
async def test_incremental_edit_propagates(self, cloud, tmp_path, monkeypatch):
|
||||
a = Install(tmp_path, "machine-a")
|
||||
phrase = await connect(a, monkeypatch)
|
||||
seed_content(a)
|
||||
await cloud_sync.run_sync(a.db)
|
||||
|
||||
b = Install(tmp_path, "machine-b")
|
||||
await connect(b, monkeypatch, phrase=phrase)
|
||||
await cloud_sync.run_sync(b.db)
|
||||
|
||||
# Edit on A: only the capture should push, and only its record blob
|
||||
# should re-upload (the audio is unchanged).
|
||||
a.activate(monkeypatch)
|
||||
blobs_before = dict(cloud.storage)
|
||||
cap = a.db.query(Capture).one()
|
||||
cap.transcript_refined = "edited on machine A"
|
||||
a.db.commit()
|
||||
report_a = await cloud_sync.run_sync(a.db)
|
||||
assert report_a.pushed == 1
|
||||
changed_keys = [k for k, v in cloud.storage.items() if blobs_before.get(k) != v]
|
||||
assert changed_keys == [k for k in changed_keys if k.endswith("/record")]
|
||||
|
||||
b.activate(monkeypatch)
|
||||
report_b = await cloud_sync.run_sync(b.db)
|
||||
assert report_b.pulled == 1
|
||||
assert b.db.query(Capture).one().transcript_refined == "edited on machine A"
|
||||
|
||||
async def test_delete_propagates(self, cloud, tmp_path, monkeypatch):
|
||||
a = Install(tmp_path, "machine-a")
|
||||
phrase = await connect(a, monkeypatch)
|
||||
seed_content(a)
|
||||
await cloud_sync.run_sync(a.db)
|
||||
|
||||
b = Install(tmp_path, "machine-b")
|
||||
await connect(b, monkeypatch, phrase=phrase)
|
||||
await cloud_sync.run_sync(b.db)
|
||||
|
||||
a.activate(monkeypatch)
|
||||
cap = a.db.query(Capture).one()
|
||||
a.db.delete(cap)
|
||||
a.db.commit()
|
||||
report_a = await cloud_sync.run_sync(a.db)
|
||||
assert report_a.pushed_deletes == 1
|
||||
|
||||
b.activate(monkeypatch)
|
||||
report_b = await cloud_sync.run_sync(b.db)
|
||||
assert report_b.pulled_deletes == 1
|
||||
assert b.db.query(Capture).count() == 0
|
||||
|
||||
async def test_last_writer_wins_on_conflict(self, cloud, tmp_path, monkeypatch):
|
||||
a = Install(tmp_path, "machine-a")
|
||||
phrase = await connect(a, monkeypatch)
|
||||
seed_content(a)
|
||||
await cloud_sync.run_sync(a.db)
|
||||
|
||||
b = Install(tmp_path, "machine-b")
|
||||
await connect(b, monkeypatch, phrase=phrase)
|
||||
await cloud_sync.run_sync(b.db)
|
||||
|
||||
# Concurrent edits to the same capture on both machines.
|
||||
a.activate(monkeypatch)
|
||||
a.db.query(Capture).one().transcript_refined = "A's edit"
|
||||
a.db.commit()
|
||||
await cloud_sync.run_sync(a.db)
|
||||
|
||||
b.activate(monkeypatch)
|
||||
b.db.query(Capture).one().transcript_refined = "B's edit"
|
||||
b.db.commit()
|
||||
await cloud_sync.run_sync(b.db) # B pushes after A: B is the last writer
|
||||
|
||||
a.activate(monkeypatch)
|
||||
await cloud_sync.run_sync(a.db)
|
||||
assert a.db.query(Capture).one().transcript_refined == "B's edit"
|
||||
|
||||
b.activate(monkeypatch)
|
||||
await cloud_sync.run_sync(b.db)
|
||||
assert b.db.query(Capture).one().transcript_refined == "B's edit"
|
||||
@@ -1,32 +0,0 @@
|
||||
import sys as py_sys
|
||||
import types
|
||||
|
||||
import pytest
|
||||
|
||||
from backend.services import cuda
|
||||
|
||||
|
||||
def test_cuda_status_reports_unsupported_linux_download(monkeypatch, tmp_path):
|
||||
monkeypatch.setattr(cuda.sys, "platform", "linux")
|
||||
monkeypatch.setattr(cuda, "get_data_dir", lambda: tmp_path)
|
||||
|
||||
status = cuda.get_cuda_status()
|
||||
|
||||
assert status["available"] is False
|
||||
assert status["download_supported"] is False
|
||||
assert status["unsupported_reason"] == cuda.CUDA_DOWNLOAD_UNSUPPORTED_REASON
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_cuda_download_rejects_linux_before_network(monkeypatch, tmp_path):
|
||||
monkeypatch.setattr(cuda.sys, "platform", "linux")
|
||||
monkeypatch.setattr(cuda, "get_data_dir", lambda: tmp_path)
|
||||
|
||||
class UnexpectedClient:
|
||||
def __init__(self, *args, **kwargs):
|
||||
raise AssertionError("unsupported platforms should not start a release download")
|
||||
|
||||
monkeypatch.setitem(py_sys.modules, "httpx", types.SimpleNamespace(AsyncClient=UnexpectedClient))
|
||||
|
||||
with pytest.raises(RuntimeError, match="currently only published for Windows"):
|
||||
await cuda._download_cuda_binary_locked("v0.5.0")
|
||||
@@ -1,68 +0,0 @@
|
||||
"""Ensure TADA voice-prompt encoding disables autograd (#890)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
import soundfile as sf
|
||||
import torch
|
||||
|
||||
from backend.backends.hume_backend import HumeTadaBackend
|
||||
|
||||
|
||||
@dataclass
|
||||
class _FakeEncoderOutput:
|
||||
emb: torch.Tensor
|
||||
|
||||
|
||||
class _GradTrackingEncoder:
|
||||
"""Raises unless called under torch.inference_mode()."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.called_under_inference_mode = False
|
||||
|
||||
def __call__(self, audio, text=None, sample_rate=None):
|
||||
self.called_under_inference_mode = torch.is_inference_mode_enabled()
|
||||
if not self.called_under_inference_mode:
|
||||
raise AssertionError("encoder forward must run under inference_mode")
|
||||
# Touch a requires_grad tensor the way Snake1d alpha would.
|
||||
alpha = torch.nn.Parameter(torch.ones(1, device=audio.device))
|
||||
_ = audio.mean() * alpha
|
||||
return _FakeEncoderOutput(emb=torch.zeros(1, 4, device=audio.device))
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_voice_prompt_runs_encoder_under_inference_mode(tmp_path, monkeypatch):
|
||||
wav = tmp_path / "ref.wav"
|
||||
sf.write(str(wav), np.zeros(24000, dtype=np.float32), 24000)
|
||||
|
||||
backend = HumeTadaBackend()
|
||||
backend.model = object() # mark loaded
|
||||
backend.model_size = "1B"
|
||||
backend._device = "cpu"
|
||||
encoder = _GradTrackingEncoder()
|
||||
backend.encoder = encoder
|
||||
|
||||
monkeypatch.setattr(backend, "load_model", AsyncMock(return_value=None))
|
||||
monkeypatch.setattr(
|
||||
"backend.backends.hume_backend.get_cached_voice_prompt",
|
||||
lambda key: None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"backend.backends.hume_backend.cache_voice_prompt",
|
||||
lambda key, value: None,
|
||||
)
|
||||
|
||||
prompt, from_cache = await backend.create_voice_prompt(
|
||||
str(wav),
|
||||
reference_text="hello world",
|
||||
use_cache=False,
|
||||
)
|
||||
|
||||
assert from_cache is False
|
||||
assert encoder.called_under_inference_mode is True
|
||||
assert isinstance(prompt["emb"], torch.Tensor)
|
||||
assert prompt["emb"].device.type == "cpu"
|
||||
@@ -1,91 +0,0 @@
|
||||
"""Tests for the voicebox.speak MCP tool's ``model_size`` plumbing (issue #884).
|
||||
|
||||
The MCP speak path used to build its ``GenerationRequest`` without a
|
||||
``model_size``, so every agent-triggered generation silently fell back to the
|
||||
schema default ("1.7B") — there was no way to reach 0.6B (or TADA's 1B/3B)
|
||||
through MCP. These tests pin the fix: ``_speak`` now forwards ``model_size``
|
||||
straight into the request, matching the REST ``/generate`` surface.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
|
||||
import backend.routes.generations as generations
|
||||
from backend.mcp_server import tools
|
||||
|
||||
|
||||
class _FakeGeneration:
|
||||
"""Minimal stand-in for GenerationResponse consumed by ``_speak_response``."""
|
||||
|
||||
def model_dump(self, mode="json"):
|
||||
return {"id": "gen-test", "status": "generating"}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def captured_request(monkeypatch):
|
||||
"""Replace the real (torch-backed) generate_speech with a capturing stub.
|
||||
|
||||
``_speak`` imports ``generate_speech`` lazily from ``routes.generations``,
|
||||
so patching the attribute on that module intercepts the call and lets us
|
||||
inspect the ``GenerationRequest`` it would have run.
|
||||
"""
|
||||
captured = {}
|
||||
|
||||
async def fake_generate_speech(req, db):
|
||||
captured["req"] = req
|
||||
return _FakeGeneration()
|
||||
|
||||
monkeypatch.setattr(generations, "generate_speech", fake_generate_speech)
|
||||
# Isolate the unit from the MCP event bus — _speak_response fires a
|
||||
# speak-start event we don't care about here.
|
||||
monkeypatch.setattr(tools.mcp_events, "publish", lambda *a, **k: None)
|
||||
return captured
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_speak_forwards_explicit_model_size(captured_request):
|
||||
await tools._speak(
|
||||
profile_id="p1",
|
||||
profile_name="Morgan",
|
||||
text="hello",
|
||||
engine="qwen",
|
||||
language="en",
|
||||
personality=False,
|
||||
model_size="0.6B",
|
||||
db=None,
|
||||
)
|
||||
assert captured_request["req"].model_size == "0.6B"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_speak_omitted_model_size_is_none(captured_request):
|
||||
# Omitted → None; generate_speech normalizes None to the engine default,
|
||||
# so this reproduces the pre-fix behaviour for callers that don't ask.
|
||||
await tools._speak(
|
||||
profile_id="p1",
|
||||
profile_name="Morgan",
|
||||
text="hello",
|
||||
engine="qwen",
|
||||
language="en",
|
||||
personality=False,
|
||||
db=None,
|
||||
)
|
||||
assert captured_request["req"].model_size is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_speak_rejects_invalid_model_size(captured_request):
|
||||
# The GenerationRequest schema pattern is the single source of truth for
|
||||
# valid sizes; a bad value is rejected before any generation runs.
|
||||
with pytest.raises(ValidationError):
|
||||
await tools._speak(
|
||||
profile_id="p1",
|
||||
profile_name="Morgan",
|
||||
text="hello",
|
||||
engine="qwen",
|
||||
language="en",
|
||||
personality=False,
|
||||
model_size="9B",
|
||||
db=None,
|
||||
)
|
||||
assert "req" not in captured_request
|
||||
@@ -1,55 +0,0 @@
|
||||
"""
|
||||
Smoke test for the MLX backend dependencies on Apple Silicon.
|
||||
|
||||
Guards the `--no-deps` install of mlx-audio/mlx-lm done by `just setup-python`
|
||||
and release.yml: those packages skip their declared dependencies (transformers
|
||||
>=5.x conflict), so a missing transitive dep only surfaces at import time.
|
||||
This test fails fast if the MLX STT/TTS entry points the backend uses stop
|
||||
importing (e.g. the `miniaudio` regression from issue #505).
|
||||
|
||||
Usage:
|
||||
python -m pytest backend/tests/test_mlx_smoke.py -v
|
||||
"""
|
||||
|
||||
import platform
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.skipif(
|
||||
not (sys.platform == "darwin" and platform.machine() == "arm64"),
|
||||
reason="MLX packages are only installed on Apple Silicon macOS",
|
||||
)
|
||||
|
||||
|
||||
def test_mlx_core_runs():
|
||||
"""The MLX runtime itself works (Metal array op)."""
|
||||
import mlx.core as mx
|
||||
|
||||
assert mx.array([1, 2]).sum().item() == 3
|
||||
|
||||
|
||||
def test_mlx_audio_tts_entry_point():
|
||||
"""`from mlx_audio.tts import load` — used by MLXBackend.load_model_async."""
|
||||
from mlx_audio.tts import load
|
||||
|
||||
assert callable(load)
|
||||
|
||||
|
||||
def test_mlx_audio_stt_entry_point():
|
||||
"""`from mlx_audio.stt import load` — used by the Whisper MLX STT path.
|
||||
|
||||
Importing mlx_audio.stt also pulls in miniaudio, so this catches the
|
||||
ModuleNotFoundError from issue #505 on fresh installs.
|
||||
"""
|
||||
from mlx_audio.stt import load
|
||||
|
||||
assert callable(load)
|
||||
|
||||
|
||||
def test_mlx_lm_entry_points():
|
||||
"""`mlx_lm.load` / `mlx_lm.generate` — used by qwen_llm_backend."""
|
||||
from mlx_lm import generate, load
|
||||
|
||||
assert callable(load)
|
||||
assert callable(generate)
|
||||
@@ -1,51 +0,0 @@
|
||||
"""Errored downloads must not be reported as still downloading.
|
||||
|
||||
A failed download intentionally stays in the TaskManager with
|
||||
``status="error"`` so ``/tasks/active`` can surface the error and retry
|
||||
UI — but ``/models/status`` derives its ``downloading`` flag from the
|
||||
same list. Without a status filter, one failed download shows the model
|
||||
as "downloading" forever and masks its real cache state until the app
|
||||
restarts (issue #925, symptom reports like #181).
|
||||
"""
|
||||
|
||||
from backend.utils.tasks import TaskManager
|
||||
|
||||
|
||||
def test_errored_download_is_not_pending():
|
||||
tm = TaskManager()
|
||||
tm.start_download("whisper-turbo")
|
||||
assert [t.model_name for t in tm.get_pending_downloads()] == ["whisper-turbo"]
|
||||
|
||||
tm.error_download("whisper-turbo", "boom")
|
||||
|
||||
assert tm.get_pending_downloads() == []
|
||||
# Still visible to /tasks/active for the error/retry UI.
|
||||
active = tm.get_active_downloads()
|
||||
assert [t.model_name for t in active] == ["whisper-turbo"]
|
||||
assert active[0].status == "error"
|
||||
assert active[0].error == "boom"
|
||||
|
||||
|
||||
def test_retry_after_error_is_pending_again():
|
||||
tm = TaskManager()
|
||||
tm.start_download("qwen3-4b")
|
||||
tm.error_download("qwen3-4b", "boom")
|
||||
tm.start_download("qwen3-4b")
|
||||
assert [t.model_name for t in tm.get_pending_downloads()] == ["qwen3-4b"]
|
||||
|
||||
|
||||
def test_completed_download_is_removed_everywhere():
|
||||
tm = TaskManager()
|
||||
tm.start_download("whisper-turbo")
|
||||
tm.complete_download("whisper-turbo")
|
||||
assert tm.get_pending_downloads() == []
|
||||
assert tm.get_active_downloads() == []
|
||||
|
||||
|
||||
def test_cancel_dismisses_errored_download():
|
||||
tm = TaskManager()
|
||||
tm.start_download("whisper-turbo")
|
||||
tm.error_download("whisper-turbo", "boom")
|
||||
assert tm.cancel_download("whisper-turbo") is True
|
||||
assert tm.get_active_downloads() == []
|
||||
assert tm.get_pending_downloads() == []
|
||||
@@ -1,121 +0,0 @@
|
||||
"""
|
||||
Tests for scripts/package_rocm.py — the ROCm onedir → server + libs splitter.
|
||||
|
||||
The classifier can't be validated against a real AMD build on CI hardware, so
|
||||
these tests pin the file-classification rules against a synthetic onedir layout
|
||||
that mirrors the PyInstaller --rocm output (torch/lib HIP DLLs + bundled
|
||||
rocm_sdk runtime packages).
|
||||
|
||||
Usage:
|
||||
python -m pytest backend/tests/test_package_rocm.py -v
|
||||
"""
|
||||
|
||||
import importlib.util
|
||||
import tarfile
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
_PACKAGE_ROCM = Path(__file__).resolve().parents[2] / "scripts" / "package_rocm.py"
|
||||
_spec = importlib.util.spec_from_file_location("package_rocm", _PACKAGE_ROCM)
|
||||
package_rocm = importlib.util.module_from_spec(_spec)
|
||||
_spec.loader.exec_module(package_rocm)
|
||||
|
||||
|
||||
class TestIsRocmFile:
|
||||
"""Classification of individual files into core vs ROCm libs."""
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"rel_path",
|
||||
[
|
||||
"_internal/torch/lib/amdhip64.dll",
|
||||
"_internal/torch/lib/rocblas.dll",
|
||||
"_internal/torch/lib/hipblaslt.dll",
|
||||
"_internal/torch/lib/miopen.dll",
|
||||
"_internal/_rocm_sdk_core/amd_comgr.dll",
|
||||
"_internal/_rocm_sdk_libraries_custom/lib/rocblas/library/TensileLibrary.dat",
|
||||
"_internal/_rocm_sdk_libraries_custom/lib/miopen/db/kernels.kdb",
|
||||
# Windows path separators must be handled too.
|
||||
"_internal\\torch\\lib\\rccl.dll",
|
||||
],
|
||||
)
|
||||
def test_runtime_files_are_rocm(self, rel_path):
|
||||
assert package_rocm.is_rocm_file(rel_path) is True
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"rel_path",
|
||||
[
|
||||
"voicebox-server-rocm.exe",
|
||||
"_internal/python312.dll",
|
||||
"_internal/torch/lib/torch_cpu.dll",
|
||||
"_internal/torch/lib/c10.dll",
|
||||
# Pure-python rocm_sdk glue stays in the core, even under an SDK dir.
|
||||
"_internal/rocm_sdk/__init__.py",
|
||||
"_internal/_rocm_sdk_core/_dist_info.py",
|
||||
"_internal/torch/_inductor/codegen/something.py",
|
||||
],
|
||||
)
|
||||
def test_core_files_are_not_rocm(self, rel_path):
|
||||
assert package_rocm.is_rocm_file(rel_path) is False
|
||||
|
||||
|
||||
def _write(path: Path, content: bytes = b"x"):
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_bytes(content)
|
||||
|
||||
|
||||
class TestPackage:
|
||||
"""End-to-end split of a synthetic onedir into the two archives."""
|
||||
|
||||
def test_split_and_manifest(self, tmp_path):
|
||||
onedir = tmp_path / "voicebox-server-rocm"
|
||||
_write(onedir / "voicebox-server-rocm.exe")
|
||||
_write(onedir / "_internal" / "python312.dll")
|
||||
_write(onedir / "_internal" / "rocm_sdk" / "__init__.py")
|
||||
_write(onedir / "_internal" / "torch" / "lib" / "torch_cpu.dll")
|
||||
_write(onedir / "_internal" / "torch" / "lib" / "amdhip64.dll")
|
||||
_write(onedir / "_internal" / "_rocm_sdk_core" / "miopen.dll")
|
||||
_write(
|
||||
onedir
|
||||
/ "_internal"
|
||||
/ "_rocm_sdk_libraries_custom"
|
||||
/ "lib"
|
||||
/ "rocblas"
|
||||
/ "library"
|
||||
/ "TensileLibrary.dat"
|
||||
)
|
||||
|
||||
out = tmp_path / "release-assets"
|
||||
package_rocm.package(onedir, out, "rocm7.2-v1", ">=2.9.0,<2.10.0")
|
||||
|
||||
server = out / "voicebox-server-rocm.tar.gz"
|
||||
libs = out / "rocm-libs-rocm7.2-v1.tar.gz"
|
||||
assert server.exists()
|
||||
assert libs.exists()
|
||||
assert (out / "voicebox-server-rocm.tar.gz.sha256").exists()
|
||||
assert (out / "rocm-libs-rocm7.2-v1.tar.gz.sha256").exists()
|
||||
|
||||
with tarfile.open(libs) as tar:
|
||||
lib_names = set(tar.getnames())
|
||||
with tarfile.open(server) as tar:
|
||||
core_names = set(tar.getnames())
|
||||
|
||||
assert "_internal/torch/lib/amdhip64.dll" in lib_names
|
||||
assert "_internal/_rocm_sdk_core/miopen.dll" in lib_names
|
||||
assert (
|
||||
"_internal/_rocm_sdk_libraries_custom/lib/rocblas/library/TensileLibrary.dat"
|
||||
in lib_names
|
||||
)
|
||||
assert "voicebox-server-rocm.exe" in core_names
|
||||
assert "_internal/torch/lib/torch_cpu.dll" in core_names
|
||||
assert "_internal/rocm_sdk/__init__.py" in core_names
|
||||
# Archives must be disjoint.
|
||||
assert lib_names.isdisjoint(core_names)
|
||||
|
||||
def test_empty_rocm_set_exits(self, tmp_path):
|
||||
onedir = tmp_path / "voicebox-server-rocm"
|
||||
_write(onedir / "voicebox-server-rocm.exe")
|
||||
_write(onedir / "_internal" / "torch" / "lib" / "torch_cpu.dll")
|
||||
|
||||
with pytest.raises(SystemExit):
|
||||
package_rocm.package(onedir, tmp_path / "out", "rocm7.2-v1", ">=2.9.0,<2.10.0")
|
||||
@@ -1,117 +0,0 @@
|
||||
"""Regression coverage for runaway MLX Qwen TTS output."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from backend.backends import engine_needs_trim, engine_retries_runaway
|
||||
from backend.utils.audio import has_tts_runaway
|
||||
from backend.utils.chunked_tts import generate_chunked
|
||||
|
||||
SAMPLE_RATE = 1000
|
||||
|
||||
|
||||
def test_mlx_qwen_enables_runaway_retry_without_aggressive_trim():
|
||||
with patch("backend.backends.get_backend_type", return_value="mlx"):
|
||||
assert engine_needs_trim("qwen") is False
|
||||
assert engine_retries_runaway("qwen") is True
|
||||
|
||||
|
||||
def test_pytorch_qwen_keeps_runaway_retry_disabled():
|
||||
with patch("backend.backends.get_backend_type", return_value="pytorch"):
|
||||
assert engine_needs_trim("qwen") is False
|
||||
assert engine_retries_runaway("qwen") is False
|
||||
|
||||
|
||||
def test_detector_flags_long_internal_silence():
|
||||
speech = np.full(2 * SAMPLE_RATE, 0.2, dtype=np.float32)
|
||||
runaway_gap = np.zeros(2500, dtype=np.float32)
|
||||
hallucinated_noise = np.full(2 * SAMPLE_RATE, 0.8, dtype=np.float32)
|
||||
audio = np.concatenate([speech, runaway_gap, hallucinated_noise])
|
||||
|
||||
assert has_tts_runaway(audio, SAMPLE_RATE) is True
|
||||
|
||||
|
||||
def test_detector_ignores_normal_internal_pause():
|
||||
speech = np.full(SAMPLE_RATE, 0.2, dtype=np.float32)
|
||||
normal_pause = np.zeros(1200, dtype=np.float32)
|
||||
audio = np.concatenate([speech, normal_pause, speech])
|
||||
|
||||
assert has_tts_runaway(audio, SAMPLE_RATE) is False
|
||||
|
||||
|
||||
def test_trailing_silence_is_not_a_runaway():
|
||||
speech = np.full(SAMPLE_RATE, 0.2, dtype=np.float32)
|
||||
trailing_silence = np.zeros(2 * SAMPLE_RATE, dtype=np.float32)
|
||||
|
||||
assert (
|
||||
has_tts_runaway(
|
||||
np.concatenate([speech, trailing_silence]),
|
||||
SAMPLE_RATE,
|
||||
)
|
||||
is False
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_runaway_chunk_is_retried_as_smaller_chunks():
|
||||
class FakeBackend:
|
||||
def __init__(self):
|
||||
self.calls = []
|
||||
|
||||
async def generate(self, text, *_args):
|
||||
self.calls.append(text)
|
||||
if len(text) > 200:
|
||||
speech = np.full(SAMPLE_RATE, 0.2, dtype=np.float32)
|
||||
silence = np.zeros(2500, dtype=np.float32)
|
||||
noise = np.full(SAMPLE_RATE, 0.8, dtype=np.float32)
|
||||
return np.concatenate([speech, silence, noise]), SAMPLE_RATE
|
||||
return np.full(SAMPLE_RATE, 0.2, dtype=np.float32), SAMPLE_RATE
|
||||
|
||||
backend = FakeBackend()
|
||||
text = f"{'A' * 119}. {'B' * 119}."
|
||||
|
||||
audio, sample_rate = await generate_chunked(
|
||||
backend,
|
||||
text,
|
||||
{},
|
||||
max_chunk_chars=800,
|
||||
crossfade_ms=50,
|
||||
runaway_detector=has_tts_runaway,
|
||||
)
|
||||
|
||||
assert sample_rate == SAMPLE_RATE
|
||||
assert backend.calls == [text, f"{'A' * 119}.", f"{'B' * 119}."]
|
||||
assert len(audio) == 1950
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_persistent_runaway_fails_instead_of_returning_corrupt_audio():
|
||||
class AlwaysRunawayBackend:
|
||||
def __init__(self):
|
||||
self.calls = []
|
||||
|
||||
async def generate(self, text, *_args):
|
||||
self.calls.append(text)
|
||||
speech = np.full(SAMPLE_RATE, 0.2, dtype=np.float32)
|
||||
silence = np.zeros(2500, dtype=np.float32)
|
||||
noise = np.full(SAMPLE_RATE, 0.8, dtype=np.float32)
|
||||
return np.concatenate([speech, silence, noise]), SAMPLE_RATE
|
||||
|
||||
backend = AlwaysRunawayBackend()
|
||||
text = f"{'A' * 119}. {'B' * 119}."
|
||||
|
||||
with pytest.raises(
|
||||
RuntimeError,
|
||||
match="remained unstable after retrying smaller text chunks",
|
||||
):
|
||||
await generate_chunked(
|
||||
backend,
|
||||
text,
|
||||
{},
|
||||
max_chunk_chars=800,
|
||||
runaway_detector=has_tts_runaway,
|
||||
)
|
||||
|
||||
assert [len(call) for call in backend.calls] == [241, 120, 100]
|
||||
@@ -1,68 +0,0 @@
|
||||
"""
|
||||
Phase 2.2 Test: Backend ROCm compatibility.
|
||||
|
||||
Validates that check_cuda_compatibility() and other backend utilities
|
||||
behave correctly on ROCm/AMD hardware.
|
||||
|
||||
Usage:
|
||||
python -m pytest backend/tests/test_rocm_backends.py -v
|
||||
"""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
class TestCheckCudaCompatibility:
|
||||
"""Unit tests for check_cuda_compatibility with ROCm awareness."""
|
||||
|
||||
def test_no_gpu_returns_compatible(self):
|
||||
from backend.backends.base import check_cuda_compatibility
|
||||
|
||||
with patch("torch.cuda.is_available", return_value=False):
|
||||
compatible, warning = check_cuda_compatibility()
|
||||
assert compatible is True
|
||||
assert warning is None
|
||||
|
||||
def test_rocm_skips_compute_check(self):
|
||||
"""On ROCm, the NVIDIA compute-capability check should be skipped."""
|
||||
from backend.backends.base import check_cuda_compatibility
|
||||
|
||||
with patch("torch.cuda.is_available", return_value=True):
|
||||
with patch("torch.version.hip", "6.2.41133"):
|
||||
compatible, warning = check_cuda_compatibility()
|
||||
assert compatible is True
|
||||
assert warning is None
|
||||
|
||||
def test_cuda_compatible_arch(self):
|
||||
from backend.backends.base import check_cuda_compatibility
|
||||
|
||||
with patch("torch.cuda.is_available", return_value=True):
|
||||
with patch("torch.version.hip", None):
|
||||
with patch("torch.cuda.get_device_capability", return_value=(8, 6)):
|
||||
with patch("torch.cuda.get_device_name", return_value="NVIDIA GeForce RTX 3060"):
|
||||
with patch.object(
|
||||
__import__("torch").cuda, "_get_arch_list",
|
||||
return_value=["sm_80", "sm_86", "sm_89"],
|
||||
create=True,
|
||||
):
|
||||
compatible, warning = check_cuda_compatibility()
|
||||
assert compatible is True
|
||||
assert warning is None
|
||||
|
||||
def test_cuda_incompatible_arch(self):
|
||||
from backend.backends.base import check_cuda_compatibility
|
||||
|
||||
with patch("torch.cuda.is_available", return_value=True):
|
||||
with patch("torch.version.hip", None):
|
||||
with patch("torch.cuda.get_device_capability", return_value=(9, 0)):
|
||||
with patch("torch.cuda.get_device_name", return_value="NVIDIA GeForce RTX 4090"):
|
||||
with patch.object(
|
||||
__import__("torch").cuda, "_get_arch_list",
|
||||
return_value=["sm_80", "sm_86"],
|
||||
create=True,
|
||||
):
|
||||
compatible, warning = check_cuda_compatibility()
|
||||
assert compatible is False
|
||||
assert warning is not None
|
||||
assert "not supported" in warning
|
||||
@@ -1,129 +0,0 @@
|
||||
"""
|
||||
Phase 1.2 Test: ROCm build script configuration.
|
||||
|
||||
Validates that build_binary.py --rocm generates the correct PyInstaller
|
||||
arguments and optionally performs a true E2E build.
|
||||
|
||||
Usage:
|
||||
python -m pytest backend/tests/test_rocm_build.py -v
|
||||
python -m pytest backend/tests/test_rocm_build.py -v -m "slow" # include E2E
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from build_binary import build_server
|
||||
|
||||
|
||||
class TestRocmBuildArgs:
|
||||
"""Validate PyInstaller arguments for ROCm builds."""
|
||||
|
||||
@pytest.fixture
|
||||
def captured_args(self):
|
||||
"""Run build_server(rocm=True) with mocked PyInstaller and return args."""
|
||||
with (
|
||||
patch("build_binary.PyInstaller.__main__.run") as mock_run,
|
||||
patch("build_binary.platform.system", return_value="Linux"),
|
||||
patch("build_binary.os.chdir"),
|
||||
):
|
||||
build_server(rocm=True)
|
||||
return mock_run.call_args[0][0]
|
||||
|
||||
def test_binary_name(self, captured_args):
|
||||
idx = captured_args.index("--name")
|
||||
assert captured_args[idx + 1] == "voicebox-server-rocm"
|
||||
|
||||
def test_pack_mode_is_onedir(self, captured_args):
|
||||
assert "--onedir" in captured_args
|
||||
assert "--onefile" not in captured_args
|
||||
|
||||
def test_hidden_imports_cuda(self, captured_args):
|
||||
"""ROCm builds must include torch.cuda hidden imports."""
|
||||
assert "torch.cuda" in captured_args
|
||||
|
||||
def test_no_cudnn_hidden_import_for_rocm(self, captured_args):
|
||||
"""ROCm builds must NOT include NVIDIA-specific cudnn hidden imports."""
|
||||
assert "torch.backends.cudnn" not in captured_args
|
||||
|
||||
def test_nvidia_excludes_present(self, captured_args):
|
||||
"""ROCm builds must exclude nvidia packages to avoid bundling ~3GB of bloat."""
|
||||
excludes = []
|
||||
for i, arg in enumerate(captured_args):
|
||||
if arg == "--exclude-module":
|
||||
excludes.append(captured_args[i + 1])
|
||||
assert "nvidia" in excludes
|
||||
assert "nvidia.cudnn" in excludes
|
||||
|
||||
|
||||
class TestRocmBuildCli:
|
||||
"""Validate CLI argument parsing for --rocm."""
|
||||
|
||||
def test_rocm_flag_parses(self):
|
||||
build_script = Path(__file__).parent.parent / "build_binary.py"
|
||||
result = subprocess.run(
|
||||
[sys.executable, str(build_script), "--rocm", "--help"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
assert result.returncode == 0
|
||||
assert "--rocm" in result.stdout
|
||||
|
||||
def test_cannot_combine_cuda_and_rocm(self):
|
||||
"""Building with both CUDA and ROCm should raise ValueError."""
|
||||
with pytest.raises(ValueError, match="Cannot build with both CUDA and ROCm"):
|
||||
build_server(cuda=True, rocm=True)
|
||||
|
||||
|
||||
@pytest.mark.slow()
|
||||
@pytest.mark.skipif(sys.platform != "win32", reason="ROCm build E2E only runs on Windows")
|
||||
class TestRocmBuildE2E:
|
||||
"""
|
||||
True end-to-end build test.
|
||||
Executes build_binary.py --rocm, verifies the binary exists, and runs it
|
||||
with --help to confirm it boots without import errors.
|
||||
"""
|
||||
|
||||
def test_rocm_binary_compiles_and_runs(self, tmp_path):
|
||||
backend_dir = Path(__file__).parent.parent
|
||||
build_script = backend_dir / "build_binary.py"
|
||||
dist_dir = backend_dir / "dist"
|
||||
binary_dir = dist_dir / "voicebox-server-rocm"
|
||||
binary_exe = binary_dir / "voicebox-server-rocm.exe"
|
||||
|
||||
# Clean previous dist if it exists to ensure a fresh build
|
||||
if binary_dir.exists():
|
||||
import shutil
|
||||
shutil.rmtree(binary_dir)
|
||||
|
||||
# Run the full build (this can take several minutes)
|
||||
result = subprocess.run(
|
||||
[sys.executable, str(build_script), "--rocm"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
cwd=str(backend_dir),
|
||||
timeout=900,
|
||||
)
|
||||
|
||||
assert result.returncode == 0, (
|
||||
f"Build failed with stdout:\n{result.stdout}\nstderr:\n{result.stderr}"
|
||||
)
|
||||
assert binary_exe.exists(), (
|
||||
f"Expected binary not found at {binary_exe}"
|
||||
)
|
||||
|
||||
# Run the binary with --help to ensure it boots without import errors
|
||||
run_result = subprocess.run(
|
||||
[str(binary_exe), "--help"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=60,
|
||||
)
|
||||
|
||||
# A frozen binary may not have argparse help, but it should not crash
|
||||
# with a ModuleNotFoundError or similar import error.
|
||||
assert "ModuleNotFoundError" not in run_result.stderr
|
||||
assert "ImportError" not in run_result.stderr
|
||||
@@ -1,203 +0,0 @@
|
||||
"""
|
||||
Tests for the ROCm backend download service.
|
||||
|
||||
Mocks httpx to verify download, extraction, and progress reporting
|
||||
without hitting the network.
|
||||
"""
|
||||
|
||||
import json
|
||||
import tarfile
|
||||
import tempfile
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from backend.services import rocm
|
||||
from backend.utils.progress import get_progress_manager
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def reset_progress_manager():
|
||||
"""Reset the global progress manager before each test."""
|
||||
import backend.utils.progress
|
||||
backend.utils.progress._progress_manager = None
|
||||
yield
|
||||
backend.utils.progress._progress_manager = None
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_backends_dir(tmp_path: Path, monkeypatch):
|
||||
"""Patch get_data_dir so downloads land in a temp directory."""
|
||||
monkeypatch.setattr(rocm, "get_backends_dir", lambda: tmp_path / "backends")
|
||||
return tmp_path / "backends"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake_tar_gz():
|
||||
"""Create an in-memory .tar.gz archive containing a dummy file."""
|
||||
buf = BytesIO()
|
||||
with tarfile.open(fileobj=buf, mode="w:gz") as tar:
|
||||
data = b"fake binary content"
|
||||
info = tarfile.TarInfo(name="voicebox-server-rocm.exe")
|
||||
info.size = len(data)
|
||||
tar.addfile(info, BytesIO(data))
|
||||
buf.seek(0)
|
||||
return buf.read()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake_sha256():
|
||||
"""Return a dummy SHA-256 hex string."""
|
||||
return "a" * 64
|
||||
|
||||
|
||||
class FakeResponse:
|
||||
"""Minimal fake for httpx.Response."""
|
||||
|
||||
def __init__(self, content: bytes = b"", status_code: int = 200, headers: dict | None = None):
|
||||
self.content = content
|
||||
self.status_code = status_code
|
||||
self.headers = headers or {}
|
||||
|
||||
def raise_for_status(self):
|
||||
if self.status_code >= 400:
|
||||
raise Exception(f"HTTP {self.status_code}")
|
||||
|
||||
def iter_bytes(self, chunk_size: int = 1024):
|
||||
for i in range(0, len(self.content), chunk_size):
|
||||
yield self.content[i : i + chunk_size]
|
||||
|
||||
async def aiter_bytes(self, chunk_size: int = 1024):
|
||||
for i in range(0, len(self.content), chunk_size):
|
||||
yield self.content[i : i + chunk_size]
|
||||
|
||||
@property
|
||||
def text(self):
|
||||
return self.content.decode()
|
||||
|
||||
|
||||
class FakeHttpxClient:
|
||||
"""Minimal fake for httpx.AsyncClient."""
|
||||
|
||||
def __init__(self, responses: dict[str, FakeResponse]):
|
||||
self._responses = responses
|
||||
|
||||
async def __aenter__(self):
|
||||
return self
|
||||
|
||||
async def __aexit__(self, *args):
|
||||
return False
|
||||
|
||||
async def head(self, url: str):
|
||||
return self._responses.get(url, FakeResponse(status_code=404))
|
||||
|
||||
async def get(self, url: str):
|
||||
return self._responses.get(url, FakeResponse(status_code=404))
|
||||
|
||||
def stream(self, method: str, url: str):
|
||||
resp = self._responses.get(url, FakeResponse(status_code=404))
|
||||
resp.raise_for_status()
|
||||
|
||||
class _Streamer:
|
||||
async def __aenter__(self):
|
||||
return resp
|
||||
|
||||
async def __aexit__(self, *args):
|
||||
return False
|
||||
|
||||
async def aiter_bytes(self, chunk_size: int = 1024):
|
||||
for i in range(0, len(resp.content), chunk_size):
|
||||
yield resp.content[i : i + chunk_size]
|
||||
|
||||
return _Streamer()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_rocm_status_not_installed(mock_backends_dir):
|
||||
status = rocm.get_rocm_status()
|
||||
assert status["available"] is False
|
||||
assert status["active"] is False
|
||||
assert status["binary_path"] is None
|
||||
assert status["downloading"] is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_download_rocm_binary_progress_reporting(mock_backends_dir, fake_tar_gz, fake_sha256):
|
||||
"""
|
||||
Verify that download_rocm_binary():
|
||||
1. Downloads the server archive and ROCm libs archive.
|
||||
2. Extracts them into the backends/rocm directory.
|
||||
3. Reports progress via the progress_manager.
|
||||
"""
|
||||
import hashlib
|
||||
|
||||
server_sha = hashlib.sha256(fake_tar_gz).hexdigest()
|
||||
libs_sha = hashlib.sha256(fake_tar_gz).hexdigest()
|
||||
|
||||
responses = {
|
||||
"https://github.com/jamiepine/voicebox/releases/download/v0.2.3/voicebox-server-rocm.tar.gz": FakeResponse(
|
||||
content=fake_tar_gz,
|
||||
headers={"content-length": str(len(fake_tar_gz))},
|
||||
),
|
||||
"https://github.com/jamiepine/voicebox/releases/download/v0.2.3/voicebox-server-rocm.tar.gz.sha256": FakeResponse(
|
||||
content=f"{server_sha} voicebox-server-rocm.tar.gz\n".encode(),
|
||||
),
|
||||
f"https://github.com/jamiepine/voicebox/releases/download/v0.2.3/rocm-libs-{rocm.ROCM_LIBS_VERSION}.tar.gz": FakeResponse(
|
||||
content=fake_tar_gz,
|
||||
headers={"content-length": str(len(fake_tar_gz))},
|
||||
),
|
||||
f"https://github.com/jamiepine/voicebox/releases/download/v0.2.3/rocm-libs-{rocm.ROCM_LIBS_VERSION}.tar.gz.sha256": FakeResponse(
|
||||
content=f"{libs_sha} rocm-libs.tar.gz\n".encode(),
|
||||
),
|
||||
}
|
||||
|
||||
fake_client = FakeHttpxClient(responses)
|
||||
|
||||
with patch("httpx.AsyncClient", return_value=fake_client):
|
||||
await rocm.download_rocm_binary(version="v0.2.3")
|
||||
|
||||
# Verify extraction
|
||||
rocm_dir = rocm.get_rocm_dir()
|
||||
assert (rocm_dir / "voicebox-server-rocm.exe").exists()
|
||||
|
||||
# Verify manifest written
|
||||
manifest_path = rocm.get_rocm_libs_manifest_path()
|
||||
assert manifest_path.exists()
|
||||
data = json.loads(manifest_path.read_text())
|
||||
assert data["version"] == rocm.ROCM_LIBS_VERSION
|
||||
|
||||
# Verify progress was reported
|
||||
progress = get_progress_manager().get_progress("rocm-backend")
|
||||
assert progress is not None
|
||||
assert progress["status"] == "complete"
|
||||
assert progress["progress"] == 100.0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_is_rocm_active(mock_backends_dir, monkeypatch):
|
||||
monkeypatch.setenv("VOICEBOX_BACKEND_VARIANT", "rocm")
|
||||
assert rocm.is_rocm_active() is True
|
||||
|
||||
monkeypatch.setenv("VOICEBOX_BACKEND_VARIANT", "cpu")
|
||||
assert rocm.is_rocm_active() is False
|
||||
|
||||
monkeypatch.delenv("VOICEBOX_BACKEND_VARIANT", raising=False)
|
||||
assert rocm.is_rocm_active() is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete_rocm_binary(mock_backends_dir, fake_tar_gz):
|
||||
"""Test deleting the ROCm backend directory."""
|
||||
rocm_dir = rocm.get_rocm_dir()
|
||||
rocm_dir.mkdir(parents=True, exist_ok=True)
|
||||
(rocm_dir / "dummy.txt").write_text("hello")
|
||||
|
||||
result = await rocm.delete_rocm_binary()
|
||||
assert result is True
|
||||
assert not rocm_dir.exists()
|
||||
|
||||
# Deleting again should return False
|
||||
result = await rocm.delete_rocm_binary()
|
||||
assert result is False
|
||||
@@ -1,130 +0,0 @@
|
||||
"""
|
||||
Phase 1.1 Test: ROCm requirements installation.
|
||||
|
||||
Validates that requirements-rocm.txt correctly installs ROCm-enabled PyTorch
|
||||
and that torch.cuda.is_available() returns True on AMD hardware.
|
||||
|
||||
Usage:
|
||||
python -m pytest backend/tests/test_rocm_requirements.py -v
|
||||
"""
|
||||
|
||||
import os
|
||||
import platform
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def _has_amd_hardware():
|
||||
"""Check if AMD GPU hardware is present on Windows."""
|
||||
if platform.system() != "Windows":
|
||||
return False
|
||||
try:
|
||||
result = subprocess.run(
|
||||
[
|
||||
"powershell",
|
||||
"-Command",
|
||||
"Get-WmiObject Win32_VideoController | "
|
||||
"Where-Object {$_.AdapterCompatibility -like '*AMD*'} | "
|
||||
"Measure-Object | Select-Object -ExpandProperty Count",
|
||||
],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
)
|
||||
return int(result.stdout.strip()) > 0
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def backend_dir():
|
||||
return Path(__file__).parent.parent
|
||||
|
||||
|
||||
class TestRocmRequirements:
|
||||
"""Validate requirements-rocm.txt content and installation."""
|
||||
|
||||
def test_requirements_file_exists(self, backend_dir):
|
||||
req_file = backend_dir / "requirements-rocm.txt"
|
||||
assert req_file.exists(), "requirements-rocm.txt must exist"
|
||||
|
||||
def test_requirements_file_content(self, backend_dir):
|
||||
import re
|
||||
req_file = backend_dir / "requirements-rocm.txt"
|
||||
content = req_file.read_text()
|
||||
assert "rocm7.2" in content, "Must point to ROCm 7.2 extra index"
|
||||
# Parse exact package names to avoid false positives from URL substrings
|
||||
package_names = re.findall(r"^([A-Za-z][A-Za-z0-9_-]*)", content, re.MULTILINE)
|
||||
assert "torch" in package_names, "Must include torch package"
|
||||
assert "torchaudio" in package_names, "Must include torchaudio package"
|
||||
assert "torchvision" in package_names, "Must include torchvision package"
|
||||
|
||||
@pytest.mark.timeout(900)
|
||||
@pytest.mark.skipif(
|
||||
not os.environ.get("VOICEBOX_TEST_ROCM_INSTALL"),
|
||||
reason="Set VOICEBOX_TEST_ROCM_INSTALL=1 to run the heavy install test",
|
||||
)
|
||||
def test_rocm_torch_installs_and_detects_amd(self, backend_dir):
|
||||
"""
|
||||
Create a temporary venv, install requirements-rocm.txt, and verify
|
||||
torch.cuda.is_available() returns True on AMD hardware.
|
||||
"""
|
||||
req_file = backend_dir / "requirements-rocm.txt"
|
||||
has_amd = _has_amd_hardware()
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
venv_dir = Path(tmpdir) / "venv"
|
||||
subprocess.run(
|
||||
[sys.executable, "-m", "venv", str(venv_dir)],
|
||||
check=True,
|
||||
)
|
||||
|
||||
if sys.platform == "win32":
|
||||
venv_python = venv_dir / "Scripts" / "python.exe"
|
||||
else:
|
||||
venv_python = venv_dir / "bin" / "python"
|
||||
|
||||
# Upgrade pip to avoid resolver issues
|
||||
subprocess.run(
|
||||
[str(venv_python), "-m", "pip", "install", "--upgrade", "pip"],
|
||||
check=True,
|
||||
)
|
||||
|
||||
# Install ROCm requirements
|
||||
subprocess.run(
|
||||
[str(venv_python), "-m", "pip", "install", "-r", str(req_file)],
|
||||
check=True,
|
||||
)
|
||||
|
||||
# Verify torch imports and cuda availability
|
||||
result = subprocess.run(
|
||||
[
|
||||
str(venv_python),
|
||||
"-c",
|
||||
"import torch; print(torch.__version__); print(torch.cuda.is_available())",
|
||||
],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
)
|
||||
|
||||
lines = result.stdout.strip().splitlines()
|
||||
assert len(lines) >= 2, f"Unexpected output: {result.stdout}"
|
||||
torch_version = lines[0]
|
||||
cuda_available = lines[1] == "True"
|
||||
|
||||
# The honest test: on AMD hardware ROCm torch should report cuda available
|
||||
if has_amd:
|
||||
assert cuda_available, (
|
||||
f"AMD hardware detected but torch.cuda.is_available() returned False. "
|
||||
f"torch version: {torch_version}, stderr: {result.stderr}"
|
||||
)
|
||||
else:
|
||||
assert not cuda_available, (
|
||||
f"No AMD hardware detected but torch.cuda.is_available() returned True. "
|
||||
f"torch version: {torch_version}"
|
||||
)
|
||||
@@ -110,43 +110,6 @@ def save_audio(
|
||||
raise OSError(f"Failed to save audio to {path}: {e}") from e
|
||||
|
||||
|
||||
def has_tts_runaway(
|
||||
audio: np.ndarray,
|
||||
sample_rate: int = 24000,
|
||||
frame_ms: int = 20,
|
||||
silence_threshold_db: float = -40.0,
|
||||
max_internal_silence_ms: int = 2000,
|
||||
) -> bool:
|
||||
"""Detect speech followed by a long silence and then more output.
|
||||
|
||||
This shape is a reliable signal that a TTS model missed EOS and resumed
|
||||
with hallucinated speech or codec noise. Leading and trailing silence do
|
||||
not count because they are not bounded by non-silent audio.
|
||||
"""
|
||||
frame_len = int(sample_rate * frame_ms / 1000)
|
||||
if frame_len == 0 or len(audio) < frame_len:
|
||||
return False
|
||||
|
||||
n_frames = len(audio) // frame_len
|
||||
threshold_linear = 10 ** (silence_threshold_db / 20)
|
||||
max_silence_frames = int(max_internal_silence_ms / frame_ms)
|
||||
seen_speech = False
|
||||
consecutive_silence = 0
|
||||
|
||||
for i in range(n_frames):
|
||||
frame = audio[i * frame_len : (i + 1) * frame_len]
|
||||
is_speech = np.sqrt(np.mean(frame**2)) >= threshold_linear
|
||||
if is_speech:
|
||||
if seen_speech and consecutive_silence >= max_silence_frames:
|
||||
return True
|
||||
seen_speech = True
|
||||
consecutive_silence = 0
|
||||
elif seen_speech:
|
||||
consecutive_silence += 1
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def trim_tts_output(
|
||||
audio: np.ndarray,
|
||||
sample_rate: int = 24000,
|
||||
|
||||
@@ -20,8 +20,6 @@ logger = logging.getLogger("voicebox.chunked-tts")
|
||||
# Default chunk size in characters. Can be overridden per-request via
|
||||
# the ``max_chunk_chars`` field on GenerationRequest.
|
||||
DEFAULT_MAX_CHUNK_CHARS = 800
|
||||
MAX_RUNAWAY_RETRIES = 2
|
||||
MIN_RUNAWAY_RETRY_CHARS = 100
|
||||
|
||||
# Common abbreviations that should NOT be treated as sentence endings.
|
||||
# Lowercase for case-insensitive matching.
|
||||
@@ -213,7 +211,6 @@ async def generate_chunked(
|
||||
max_chunk_chars: int = DEFAULT_MAX_CHUNK_CHARS,
|
||||
crossfade_ms: int = 50,
|
||||
trim_fn=None,
|
||||
runaway_detector=None,
|
||||
) -> Tuple[np.ndarray, int]:
|
||||
"""Generate audio with automatic chunking for long text.
|
||||
|
||||
@@ -242,75 +239,25 @@ async def generate_chunked(
|
||||
Optional ``(audio, sample_rate) -> audio`` post-processing
|
||||
function applied to each chunk before concatenation (e.g.
|
||||
``trim_tts_output`` for Chatterbox engines).
|
||||
runaway_detector : callable | None
|
||||
Optional ``(audio, sample_rate) -> bool`` detector. When it flags
|
||||
unstable output, the affected text is split in half and retried.
|
||||
|
||||
Returns
|
||||
-------
|
||||
(audio, sample_rate) : Tuple[np.ndarray, int]
|
||||
"""
|
||||
async def generate_one(
|
||||
chunk_text: str,
|
||||
chunk_seed: int | None,
|
||||
retry_depth: int = 0,
|
||||
) -> tuple[np.ndarray, int]:
|
||||
chunk_audio, chunk_sr = await backend.generate(
|
||||
chunk_text,
|
||||
voice_prompt,
|
||||
language,
|
||||
chunk_seed,
|
||||
instruct,
|
||||
)
|
||||
|
||||
if runaway_detector is not None and runaway_detector(chunk_audio, chunk_sr):
|
||||
if retry_depth >= MAX_RUNAWAY_RETRIES or len(chunk_text) <= MIN_RUNAWAY_RETRY_CHARS:
|
||||
raise RuntimeError(
|
||||
"TTS output remained unstable after retrying smaller text chunks"
|
||||
)
|
||||
|
||||
retry_max_chars = max(MIN_RUNAWAY_RETRY_CHARS, len(chunk_text) // 2)
|
||||
retry_chunks = split_text_into_chunks(chunk_text, retry_max_chars)
|
||||
if len(retry_chunks) <= 1:
|
||||
raise RuntimeError("Unable to split unstable TTS output for retry")
|
||||
|
||||
logger.warning(
|
||||
"Detected unstable TTS output for %d chars; retrying as %d smaller chunks",
|
||||
len(chunk_text),
|
||||
len(retry_chunks),
|
||||
)
|
||||
retry_audio: list[np.ndarray] = []
|
||||
for i, retry_text in enumerate(retry_chunks):
|
||||
retry_seed = (
|
||||
chunk_seed + ((retry_depth + 1) * 1000) + i
|
||||
if chunk_seed is not None
|
||||
else None
|
||||
)
|
||||
audio, sample_rate = await generate_one(
|
||||
retry_text,
|
||||
retry_seed,
|
||||
retry_depth + 1,
|
||||
)
|
||||
retry_audio.append(np.asarray(audio, dtype=np.float32))
|
||||
|
||||
return (
|
||||
concatenate_audio_chunks(
|
||||
retry_audio,
|
||||
sample_rate,
|
||||
crossfade_ms=crossfade_ms,
|
||||
),
|
||||
sample_rate,
|
||||
)
|
||||
|
||||
if trim_fn is not None:
|
||||
chunk_audio = trim_fn(chunk_audio, chunk_sr)
|
||||
return np.asarray(chunk_audio, dtype=np.float32), chunk_sr
|
||||
|
||||
chunks = split_text_into_chunks(text, max_chunk_chars)
|
||||
|
||||
if len(chunks) <= 1:
|
||||
# Short text — single-shot fast path
|
||||
return await generate_one(text, seed)
|
||||
audio, sample_rate = await backend.generate(
|
||||
text,
|
||||
voice_prompt,
|
||||
language,
|
||||
seed,
|
||||
instruct,
|
||||
)
|
||||
if trim_fn is not None:
|
||||
audio = trim_fn(audio, sample_rate)
|
||||
return audio, sample_rate
|
||||
|
||||
# Long text — chunked generation
|
||||
logger.info(
|
||||
@@ -334,12 +281,17 @@ async def generate_chunked(
|
||||
# always produces the same output.
|
||||
chunk_seed = (seed + i) if seed is not None else None
|
||||
|
||||
chunk_audio, chunk_sr = await generate_one(
|
||||
chunk_audio, chunk_sr = await backend.generate(
|
||||
chunk_text,
|
||||
voice_prompt,
|
||||
language,
|
||||
chunk_seed,
|
||||
instruct,
|
||||
)
|
||||
if trim_fn is not None:
|
||||
chunk_audio = trim_fn(chunk_audio, chunk_sr)
|
||||
|
||||
audio_chunks.append(chunk_audio)
|
||||
audio_chunks.append(np.asarray(chunk_audio, dtype=np.float32))
|
||||
if sample_rate is None:
|
||||
sample_rate = chunk_sr
|
||||
|
||||
|
||||
@@ -3,72 +3,19 @@ Platform detection for backend selection.
|
||||
"""
|
||||
|
||||
import platform
|
||||
import subprocess
|
||||
from functools import lru_cache
|
||||
from typing import Literal
|
||||
|
||||
|
||||
def is_apple_silicon() -> bool:
|
||||
"""
|
||||
Check if running on Apple Silicon (arm64 macOS).
|
||||
|
||||
|
||||
Returns:
|
||||
True if on Apple Silicon, False otherwise
|
||||
"""
|
||||
return platform.system() == "Darwin" and platform.machine() == "arm64"
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def is_amd_gpu_windows() -> bool:
|
||||
"""
|
||||
Check if the primary GPU on Windows is an AMD Radeon card.
|
||||
|
||||
Uses WMI to query Win32_VideoController, with a fallback to
|
||||
torch.cuda.get_device_name(0) if WMI is unavailable. This is
|
||||
useful for deciding whether the ROCm backend is appropriate.
|
||||
|
||||
Result is cached since it shells out to PowerShell and the GPU
|
||||
does not change at runtime — safe to call from the health path.
|
||||
|
||||
Returns:
|
||||
True if an AMD GPU is detected on Windows, False otherwise.
|
||||
"""
|
||||
if platform.system() != "Windows":
|
||||
return False
|
||||
|
||||
# Primary method: WMI query for AMD adapters
|
||||
try:
|
||||
result = subprocess.run(
|
||||
[
|
||||
"powershell",
|
||||
"-Command",
|
||||
"Get-CimInstance Win32_VideoController | "
|
||||
"Where-Object {$_.AdapterCompatibility -like '*AMD*'} | "
|
||||
"Measure-Object | Select-Object -ExpandProperty Count",
|
||||
],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
)
|
||||
if int(result.stdout.strip()) > 0:
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Fallback: torch.cuda.get_device_name(0) (works for ROCm/HIP too)
|
||||
try:
|
||||
import torch
|
||||
|
||||
if torch.cuda.is_available():
|
||||
name = torch.cuda.get_device_name(0)
|
||||
if "Radeon" in name or "AMD" in name:
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def get_backend_type() -> Literal["mlx", "pytorch"]:
|
||||
"""
|
||||
Detect the best backend for the current platform.
|
||||
|
||||
@@ -67,19 +67,6 @@ class TaskManager:
|
||||
def get_active_downloads(self) -> List[DownloadTask]:
|
||||
"""Get all active downloads."""
|
||||
return list(self._active_downloads.values())
|
||||
|
||||
def get_pending_downloads(self) -> List[DownloadTask]:
|
||||
"""Get downloads that are still in flight.
|
||||
|
||||
Excludes errored tasks, which stay in the active list so the
|
||||
error/retry UI can show them but must not be reported as
|
||||
"downloading" by /models/status.
|
||||
"""
|
||||
return [
|
||||
task
|
||||
for task in self._active_downloads.values()
|
||||
if task.status in ("downloading", "extracting")
|
||||
]
|
||||
|
||||
def get_active_generations(self) -> List[GenerationTask]:
|
||||
"""Get all active generations."""
|
||||
|
||||
@@ -57,6 +57,7 @@
|
||||
"react-dom": "^18.3.0",
|
||||
"react-hook-form": "^7.53.0",
|
||||
"react-i18next": "^17.0.4",
|
||||
"react-qr-code": "^2.0.18",
|
||||
"react-sound-visualizer": "^1.4.0",
|
||||
"tailwind-merge": "^2.5.4",
|
||||
"wavesurfer.js": "^7.0.0",
|
||||
@@ -1005,6 +1006,8 @@
|
||||
|
||||
"punycode": ["[email protected]", "", {}, "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg=="],
|
||||
|
||||
"qr.js": ["[email protected]", "", {}, "sha512-c4iYnWb+k2E+vYpRimHqSu575b1/wKl4XFeJGpFmrJQz5I88v9aY2czh7s0w36srfCM1sXgC/xpoJz5dJfq+OQ=="],
|
||||
|
||||
"queue-microtask": ["[email protected]", "", {}, "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A=="],
|
||||
|
||||
"react": ["[email protected]", "", { "dependencies": { "loose-envify": "^1.1.0" } }, "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ=="],
|
||||
@@ -1019,6 +1022,8 @@
|
||||
|
||||
"react-loaders": ["[email protected]", "", { "dependencies": { "classnames": "^2.2.3" }, "peerDependencies": { "prop-types": ">=15.6.0", "react": ">=15" } }, "sha512-4igMNqs9Fb3d4Z+0UHIGQNJsw/37gX0nUO8QxupnEKRn1dtyYC1LGwk5GuaoDciMQCQc/MmPwb4Fn6ZfdoX1FQ=="],
|
||||
|
||||
"react-qr-code": ["[email protected]", "", { "dependencies": { "prop-types": "^15.8.1", "qr.js": "0.0.0" }, "peerDependencies": { "react": "*" } }, "sha512-v1Jqz7urLMhkO6jkgJuBYhnqvXagzceg3qJUWayuCK/c6LTIonpWbwxR1f1APGd4xrW/QcQEovNrAojbUz65Tg=="],
|
||||
|
||||
"react-refresh": ["[email protected]", "", {}, "sha512-z6F7K9bV85EfseRCp2bzrpyQ0Gkw1uLoCel9XBVWPg/TjRj94SkJzUTGfOa4bs7iJvBWtQG0Wq7wnI0syw3EBQ=="],
|
||||
|
||||
"react-remove-scroll": ["[email protected]", "", { "dependencies": { "react-remove-scroll-bar": "^2.3.7", "react-style-singleton": "^2.2.3", "tslib": "^2.1.0", "use-callback-ref": "^1.3.3", "use-sidecar": "^1.1.3" }, "peerDependencies": { "@types/react": "*", "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react"] }, "sha512-Iqb9NjCCTt6Hf+vOdNIZGdTiH1QSqr27H/Ek9sv/a97gfueI/5h1s3yRi1nngzMUaOOToin5dI1dXKdXiF+u0Q=="],
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
---
|
||||
# ROCm (AMD GPU) overlay for Voicebox
|
||||
#
|
||||
# docker compose -f docker-compose.yml -f docker-compose.rocm.yml up --build
|
||||
#
|
||||
# Requires ROCm drivers on the host:
|
||||
# https://rocm.docs.amd.com/projects/install-on-linux
|
||||
# RDNA4 (RX 9000): export ROCM_VERSION=7.2 (default 6.3 covers RDNA1-3).
|
||||
|
||||
services:
|
||||
voicebox:
|
||||
build:
|
||||
context: .
|
||||
args:
|
||||
PYTORCH_VARIANT: rocm
|
||||
ROCM_VERSION: ${ROCM_VERSION:-6.3}
|
||||
|
||||
devices:
|
||||
- /dev/kfd
|
||||
- /dev/dri
|
||||
|
||||
environment:
|
||||
# HSA_OVERRIDE_GFX_VERSION forces the ROCm runtime to treat the GPU as a
|
||||
# specific GFX version when auto-detection fails or the GPU is newer than
|
||||
# the ROCm release. app.py sets 10.3.0 (RDNA2) by default; override here
|
||||
# for your GPU family:
|
||||
# RDNA4 / RX 9000 series: 12.0.0
|
||||
# (requires ROCM_VERSION=7.2)
|
||||
# RDNA3 / RX 7000 series / Strix Halo: 11.0.0
|
||||
# RDNA2 / RX 6000 series: 10.3.0
|
||||
# RDNA1 / RX 5000 series: 10.1.0
|
||||
# Vega / GCN5: 9.0.0
|
||||
- HSA_OVERRIDE_GFX_VERSION=${HSA_OVERRIDE_GFX_VERSION:-}
|
||||
|
||||
# Tune the ROCm memory allocator
|
||||
- PYTORCH_HIP_ALLOC_CONF=garbage_collection_threshold:0.8,max_split_size_mb:512
|
||||
|
||||
# Redirect MIOpen kernel cache to a writable, persistent directory.
|
||||
# Without this, MIOpen may fail to write its cache and throw
|
||||
# miopenStatusUnknownError on fresh containers.
|
||||
- MIOPEN_USER_DB_PATH=/app/data/cache/miopen_db
|
||||
- MIOPEN_CUSTOM_CACHE_DIR=/app/data/cache/miopen_cache
|
||||
|
||||
# Use fast heuristics for kernel selection instead of exhaustive
|
||||
# benchmarking. On RDNA4, exhaustive mode tries kernels that fail to
|
||||
# allocate workspace memory (ptr: 0 size: 0), causing system stuttering
|
||||
# on every generation even when the cache is present.
|
||||
- MIOPEN_FIND_MODE=FAST
|
||||
@@ -1,7 +1,3 @@
|
||||
# Voicebox — CPU build (default)
|
||||
# For AMD ROCm GPU acceleration use the overlay:
|
||||
# docker compose -f docker-compose.yml -f docker-compose.rocm.yml up --build
|
||||
|
||||
services:
|
||||
voicebox:
|
||||
build: .
|
||||
|
||||
+3
-74
@@ -1,6 +1,6 @@
|
||||
# Voicebox Project Status & Roadmap
|
||||
|
||||
> Last updated: 2026-07-02 | Current version: **v0.5.0** | 402 open issues | 88 open PRs | 1.3M downloads · 34.8k stars
|
||||
> Last updated: 2026-06-27 | Current version: **v0.5.0** | 402 open issues | 88 open PRs | 1.3M downloads · 34.8k stars
|
||||
|
||||
---
|
||||
|
||||
@@ -218,19 +218,6 @@ Shipped 2026-04-25 (PR #544). Voicebox went from a voice-cloning studio to a ful
|
||||
|
||||
**Integration shape if we revive it:** Zero-shot cloning maps naturally to the Chatterbox-style backend (store `ref_audio` + `ref_text` paths in the voice prompt dict, process at generate time). Est. ~250 lines for `voxcpm_backend.py` + one `ModelConfig` entry + engine registration in `backends/__init__.py`. Frontend UI gating is the bigger lift.
|
||||
|
||||
### Funded Roadmap (2026-H2)
|
||||
|
||||
`$VOICEBOX` funded ~2–3 months of full-time work; cadence resumes the week of 2026-06-27. Direction committed publicly in #806:
|
||||
|
||||
| Item | Notes |
|
||||
|------|-------|
|
||||
| **Resume merge/release cadence** | Clear the 88-PR backlog, regular commits + releases — this is the immediate focus (see Tier 1) |
|
||||
| **Mobile companion app** | New surface; already drawing issues (#773 iPhone logout) |
|
||||
| **Encrypted cloud backup/sync** | For voice profiles + generations — first cloud feature; stays opt-in, local-first remains default |
|
||||
| **More TTS models** | Engine candidates in the Landscape section below; community PRs #507/#766/#777 in queue |
|
||||
| **Better GPU support** | Blackwell/sm_120, ROCm, DirectML, Intel — incl. paying testers for hardware the dev lacks |
|
||||
| **Bug fixes** | 0.5.0 regression cluster first (macOS load crash, capture cutoffs, MCP, refinement) |
|
||||
|
||||
### What's In-Flight
|
||||
|
||||
| Feature | Branch/PR | Status |
|
||||
@@ -239,7 +226,7 @@ Shipped 2026-04-25 (PR #544). Voicebox went from a voice-cloning studio to a ful
|
||||
| Engine sprawl cleanup | issue #419 | First-class vs experimental TTS backends distinction |
|
||||
| Frontend tech-debt burn-down | issue #421 | Biome + a11y debt before gating CI |
|
||||
| Docker registry auto-publish | PR #463, issue #453 | ghcr.io image on tag push |
|
||||
| New model research | `voicebox-new-models` branch | Evaluating Fish Speech, XTTS-v2, Pocket TTS, VibeVoice, Fish Audio S2, index-tts2. **2026-06-27 sweep** added dots.tts, LongCat-AudioDiT, SoproTTS, NeuTTS, Nemotron/Cohere STT — see Landscape → New Candidate Sweep |
|
||||
| New model research | `voicebox-new-models` branch | Evaluating Fish Speech, XTTS-v2, Pocket TTS, VibeVoice, Fish Audio S2, index-tts2 |
|
||||
|
||||
### TTS Engine Comparison
|
||||
|
||||
@@ -605,43 +592,6 @@ Notable:
|
||||
4. **Instruct support fills a real gap** (#173, #224, #303). Qwen CustomVoice partially addresses it with preset speakers; zero-shot clone-with-instruct is still unmet.
|
||||
5. **Long-form + streaming are user-requested** (#363, #365, #464). Candidates with native streaming (Pocket TTS, Fish Speech) get extra weight.
|
||||
|
||||
### New Candidate Sweep (2026-06-27)
|
||||
|
||||
A follow-up deep-research pass, filtered against everything already tracked — the shipped engines plus MOSS-TTS-Nano, Pocket TTS, IndicF5, VibeVoice, Voxtral, Fish/Fish Audio, XTTS-v2, index-tts2, VoxCPM2, OmniVoice, MioTTS, Oolel, Faster-Qwen, Orpheus/Sesame, MiniMax, RVC, Parakeet, Qwen3-ASR, Moshi, GLM-4-Voice, Qwen2.5-Omni — kept only where a **newer sibling/variant** changes the evaluation. Same criteria as the 04-18 cycle: cross-platform, PyPI/clean packaging, permissive license, quality, instruct/style control, long-form, streaming.
|
||||
|
||||
**Top new TTS candidates**
|
||||
|
||||
| Candidate | Add as | Why it matters | Caveat |
|
||||
|-----------|--------|----------------|--------|
|
||||
| **[dots.tts](https://github.com/rednote-hilab/dots.tts)** (soar / mf) | **Top new TTS candidate** | 2B fully-continuous end-to-end autoregressive TTS, 48 kHz AudioVAE output, zero-shot cloning via prompt audio/text, Apache-2.0 code+checkpoints, MeanFlow-distilled variant for low latency. Freshest "serious clone engine" not yet on the roadmap. | Git-source install with constraints, not clean PyPI. Needs Windows/macOS packaging + VRAM/CPU smoke test; probably experimental until platform gating exists. |
|
||||
| **[MOSS-TTS family](https://github.com/OpenMOSS/MOSS-TTS)** / v1.5 / Local-Transformer-v1.5 | **Upgrade the MOSS-Nano entry into a MOSS family epic** | We track only Nano, but MOSS now spans MOSS-TTS, TTSD (long multi-speaker dialogue), VoiceGenerator (text-prompt voice design), TTS-Realtime, SoundEffect. v1.5 adds broader languages, long-reference cloning, pause control, 48 kHz stereo, MLX/vLLM support, Apache-2.0. | Full 4B/8B variants aren't the lightweight Nano win. Treat as several engines/features, not one checkbox. |
|
||||
| **[LongCat-AudioDiT](https://arxiv.org/html/2603.29339v1)** | **High-priority Apple Silicon candidate** | 3.5B non-autoregressive diffusion TTS in waveform latent space, zero-shot cloning, already has an MLX conversion usable via `mlx_audio` — unusually aligned with our Apple Silicon base. | zh/en only, not realtime. Quality play, not low-latency agent speech. |
|
||||
| **[SoproTTS](https://github.com/samuel-vitorino/sopro)** | **Lightweight CPU/streaming cloned TTS** | 135M zero-shot cloning, `pip install -U sopro`, streaming + non-streaming APIs, 3–12s reference, claimed 250 ms TTFA / 0.05 RTF on M3 CPU. Strong local-first/low-maintenance fit. | English-focused, self-described as inconsistent — quality-test before promoting past experimental. |
|
||||
| **[NeuTTS Air / Nano](https://github.com/neuphonic/neutts)** | **GGUF/on-device cloned TTS** | On-device instant cloning, GGUF-ready, ~3s reference, laptop/phone/Pi targets. Air is Apache-2.0. | Needs a GGUF/llama.cpp-style wrapper, not a normal PyTorch backend. Nano has a separate NeuTTS Open License — split needs review. |
|
||||
| **[X-Voice](https://github.com/sunnyxrxrx/X-Voice)** | **Small multilingual clone** | 0.4B multilingual zero-shot cloning, 30 languages, IPA-style unified rep, claims no prompt-transcript requirement — targets a real cloning-UX pain point. | Verify license, packaging, production-readiness of weights/code. |
|
||||
| **[FireRedTTS-2](https://huggingface.co/FireRedTeam/FireRedTTS2)** | **Stories / podcast / multi-speaker** | Apache-2.0 long-form streaming, 3-min / 4-speaker dialogue, cross-lingual code-switching cloning, low first-packet latency. | Stories-editor engine more than a general default. Needs platform/VRAM testing. |
|
||||
| **[Maya1](https://huggingface.co/maya-research/maya1)** | **Expressive English voice-design** | 3B Apache-2.0, voice design, streaming, emotion/style tags, vLLM-compatible, 24 kHz, single-GPU. Good "voice personalities" / game-dialogue fit. | English-only, 16 GB+ VRAM — platform gating required. |
|
||||
|
||||
**MOSS is now a family, not one checkbox.** The single `MOSS-TTS-Nano` row above should become an epic: keep Nano as the CPU-friendly model, and track v1.5 / Local-Transformer-v1.5, Realtime, TTSD, VoiceGenerator, and SoundEffect as siblings under it.
|
||||
|
||||
**STT / capture candidates** (feed the planned streaming-transcription roadmap)
|
||||
|
||||
| Candidate | Add as | Why it matters | Caveat |
|
||||
|-----------|--------|----------------|--------|
|
||||
| **[Nemotron 3.5 ASR Streaming 0.6B](https://huggingface.co/mlx-community/nemotron-3.5-asr-streaming-0.6b)** | **Top new STT candidate** | Cache-aware streaming FastConformer-RNNT, 40 language-locales, punctuation/caps, language-ID conditioning, MLX conversion path — strongest fit for planned streaming transcription. | NVIDIA-origin; verify license + non-CUDA (MLX/CPU) performance. |
|
||||
| **[Cohere Transcribe 03-2026](https://huggingface.co/blog/CohereLabs/cohere-transcribe-03-2026-release)** | **High-quality offline STT** | 2B Apache-2.0, 14 languages, ONNX/INT8 exports across CPU / Apple Silicon / GPU. Cleanest-looking offline `/transcribe` + captures candidate. | Less clearly a streaming dictation model than Nemotron. |
|
||||
| **[ARK-ASR 3B / 0.6B](https://huggingface.co/AutoArk-AI/ARK-ASR-3B)** | **Multilingual STT watch** | New family, broad European/Asian coverage, strong leaderboard claims, INT8 ONNX for edge. | Very new; likely `trust_remote_code`. Validate stability first. |
|
||||
| **[IBM Granite Speech 4.1 2B / NAR](https://huggingface.co/ibm-granite/granite-speech-4.1-2b)** | **ASR + speech translation** | Compact multilingual ASR + bidirectional speech translation (en/fr/de/es/pt/ja); NAR variant for latency-sensitive work. | More compelling if we expand into translation, not just dictation. |
|
||||
|
||||
**Watch-list / blocked** (license or platform work must land first): LEMAS-TTS, Supertonic 3, KugelAudio, GLM-TTS, KittenTTS, TinyTTS (preset/on-device, not cloning); Sarashina2.2, Higgs Audio v3, T5Gemma-TTS, Step-Audio-EditX, MisoTTS (non-commercial terms or CUDA-heavy); MegaTTS3 (incomplete WaveVAE encoder distribution); PFluxTTS, LongCat-Next (paper-only / too broad). **Low-hanging Qwen-family variants:** `Qwen3-TTS-VoiceDesign` (fills text-to-voice-design with minimal churn) and ZipVoice/ZipVoice-Dialog (only if it brings zh-en/dialogue behavior our shipped LuxTTS doesn't already expose).
|
||||
|
||||
**Roadmap patch from this sweep** (reflected in Tier 3 below):
|
||||
1. Replace the `MOSS-TTS-Nano` checkbox with a **MOSS-TTS family** epic (Nano tracked separately as the CPU model).
|
||||
2. New Tier-3 TTS candidates, in order: **dots.tts → LongCat-AudioDiT → SoproTTS → NeuTTS → X-Voice → FireRedTTS-2 → Maya1**.
|
||||
3. New STT expansion candidates, in order: **Nemotron 3.5 → Cohere Transcribe → ARK-ASR → Granite Speech**.
|
||||
4. Keep Sarashina2.2, Higgs v3, T5Gemma, Step-Audio-EditX, MisoTTS, MegaTTS3, PFluxTTS blocked/watch-only.
|
||||
5. **Do platform gating (bottleneck #6 / `ModelConfig.requires`) before shipping GPU-only engines** — Maya1, Step-Audio-EditX, MisoTTS, and probably dots.tts stay experimental until it exists.
|
||||
|
||||
### Adding a New Engine (Now Straightforward)
|
||||
|
||||
With the model config registry and shared `EngineModelSelector` component, adding a new TTS engine requires:
|
||||
@@ -725,11 +675,9 @@ The two-month gap means the highest-leverage work isn't new code — it's review
|
||||
|
||||
### Tier 3 — Future Engines (cross-platform preferred)
|
||||
|
||||
Committed ordering (04-18 cycle), then the 2026-06-27 sweep additions. See Landscape → New Candidate Sweep for full rationale.
|
||||
|
||||
| Priority | Item | Notes |
|
||||
|----------|------|-------|
|
||||
| 1 | **MOSS-TTS family** (was MOSS-TTS-Nano) | Nano first: 0.1B, Apache 2.0, 4-core CPU realtime, 48 kHz stereo, streaming, 20 langs. Best alignment with our criteria. Then track v1.5 / Realtime / TTSD / VoiceGenerator / SoundEffect as siblings under one epic. |
|
||||
| 1 | **MOSS-TTS-Nano** | 0.1B, Apache 2.0, 4-core CPU realtime, 48 kHz stereo, streaming, 20 langs, released 2026-04-13. Best alignment with our criteria. Verify install ergonomics before committing. |
|
||||
| 2 | **Pocket TTS** (Kyutai) | CPU-first 100M model. MIT. Fills streaming gap without CUDA dependency. Several European langs added by Feb 2026. |
|
||||
| 3 | **IndicF5** | Fills Indian-language gap (#339). Closes many language-request issues. |
|
||||
| 4 | **VibeVoice** (Microsoft, #172) | 1.5B, long-form multi-speaker (up to 90 min, 4 speakers). Strong Stories-editor fit. |
|
||||
@@ -738,25 +686,6 @@ Committed ordering (04-18 cycle), then the 2026-06-27 sweep additions. See Lands
|
||||
| 7 | **XTTS-v2** | 17+ langs, mature pip. CPML likely kills commercial use — verify. |
|
||||
| 8 | **index-tts2** (#370) | Unvetted. |
|
||||
| — | ~~**VoxCPM2**~~ | **Backlogged** — CUDA-only upstream. Revisit when tier system ships or MPS bugs are fixed upstream. |
|
||||
| — | *New (06-27 sweep), in order* → | |
|
||||
| 9 | **dots.tts** | 2B end-to-end AR, 48 kHz, Apache-2.0 + fast MeanFlow variant. Top new candidate. Git-source install — smoke-test packaging + VRAM; likely experimental until platform gating exists. |
|
||||
| 10 | **LongCat-AudioDiT** | 3.5B diffusion, has an MLX/`mlx_audio` path — best Apple Silicon fit. zh/en only, not realtime. |
|
||||
| 11 | **SoproTTS** | 135M, `pip install sopro`, streaming, ~250 ms TTFA / 0.05 RTF on M3 CPU. Quality-test first. |
|
||||
| 12 | **NeuTTS Air/Nano** | On-device GGUF cloning, ~3s reference. Needs a GGUF wrapper; Air is Apache-2.0, Nano license split needs review. |
|
||||
| 13 | **X-Voice** | 0.4B, 30 langs, no prompt-transcript required. Verify license/packaging. |
|
||||
| 14 | **FireRedTTS-2** | Apache-2.0 long-form multi-speaker/podcast streaming. Stories-editor engine; needs VRAM testing. |
|
||||
| 15 | **Maya1** | 3B Apache-2.0 expressive voice-design, emotion tags. English-only, 16 GB+ VRAM — gate behind platform tiers. |
|
||||
|
||||
### Tier 3b — STT / Capture Candidates (06-27 sweep)
|
||||
|
||||
Feeds the planned streaming-transcription roadmap; Whisper alternatives.
|
||||
|
||||
| Priority | Item | Notes |
|
||||
|----------|------|-------|
|
||||
| 1 | **Nemotron 3.5 ASR Streaming 0.6B** | Cache-aware streaming FastConformer-RNNT, 40 locales, MLX path. Strongest streaming-dictation fit. Verify license + non-CUDA perf. |
|
||||
| 2 | **Cohere Transcribe 03-2026** | 2B Apache-2.0, 14 langs, ONNX/INT8 across CPU/Apple Silicon/GPU. Cleanest offline `/transcribe` candidate. |
|
||||
| 3 | **ARK-ASR 3B / 0.6B** | Broad multilingual, INT8 ONNX for edge. Very new; likely `trust_remote_code` — validate stability. |
|
||||
| 4 | **IBM Granite Speech 4.1 2B / NAR** | ASR + speech translation (en/fr/de/es/pt/ja). Compelling if we expand into translation. |
|
||||
|
||||
### ~~Previously Prioritized — Now Done~~
|
||||
|
||||
|
||||
@@ -49,7 +49,6 @@ class ModelConfig:
|
||||
model_size: str = "default"
|
||||
size_mb: int = 0
|
||||
needs_trim: bool = False
|
||||
retries_runaway: bool = False
|
||||
supports_instruct: bool = False
|
||||
languages: list[str] = field(default_factory=lambda: ["en"])
|
||||
```
|
||||
@@ -60,7 +59,6 @@ Registry helpers in `backends/__init__.py` replace what used to be per-engine `i
|
||||
- `get_tts_model_configs()` — only TTS variants
|
||||
- `get_model_config(model_name)` — lookup by name
|
||||
- `engine_needs_trim(engine)` — whether output should run through `trim_tts_output()`
|
||||
- `engine_retries_runaway(engine)` — whether unstable output should be retried as smaller chunks
|
||||
- `load_engine_model(engine, model_size)` — downloads + loads, handles engines with multiple sizes
|
||||
- `get_tts_backend_for_engine(engine)` — thread-safe backend factory with double-checked locking
|
||||
|
||||
@@ -154,7 +152,7 @@ The request path from frontend to audio file:
|
||||
|
||||
6. **Inference** — the engine's `generate()` returns `(audio_array, sample_rate)`.
|
||||
|
||||
7. **Validate and post-process** — engines with `retries_runaway=True` retry unstable output as smaller chunks. If `engine_needs_trim(engine)` is True, `trim_tts_output()` strips trailing silence. Effects chains (if any) are applied per generation version, not the clean version.
|
||||
7. **Post-process** — if `engine_needs_trim(engine)` is True, `trim_tts_output()` strips trailing silence. Effects chains (if any) are applied per generation version, not the clean version.
|
||||
|
||||
8. **Persist** — audio is written to the generations directory, a row is inserted into the `generations` table, and the response includes the generation metadata.
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ This page is for the cases where it doesn't:
|
||||
| **Windows + NVIDIA** | PyTorch CUDA (cu128) | Auto-downloads the CUDA backend binary on first use |
|
||||
| **Windows + Intel Arc** | PyTorch XPU (IPEX) | New in 0.4 — works with Arc A-series and B-series |
|
||||
| **Windows generic GPU** | DirectML | Universal Windows GPU support; slower than CUDA |
|
||||
| **Linux + NVIDIA** | PyTorch CUDA (cu128) | Use a local/remote Python backend with CUDA PyTorch |
|
||||
| **Linux + NVIDIA** | PyTorch CUDA (cu128) | Same auto-download flow as Windows |
|
||||
| **Linux + AMD** | PyTorch ROCm | Auto-configures `HSA_OVERRIDE_GFX_VERSION` |
|
||||
| **Linux + Intel Arc** | PyTorch XPU (IPEX) | |
|
||||
| **Any (no GPU)** | PyTorch CPU | Works everywhere; expect 5-50x slower than GPU |
|
||||
@@ -46,7 +46,7 @@ On M-series Macs, Voicebox ships an MLX-optimized backend that uses the Apple Ne
|
||||
|
||||
The Whisper Turbo + MLX combo dropped transcription latency from ~20s to ~2-3s on M-series chips (see CHANGELOG entry for v0.1.10).
|
||||
|
||||
## Windows + NVIDIA — The CUDA Backend Swap
|
||||
## Windows / Linux + NVIDIA — The CUDA Backend Swap
|
||||
|
||||
Voicebox doesn't bundle CUDA into the main installer (it would balloon downloads to multi-gigabyte territory for users who don't have an NVIDIA GPU). Instead, when you first need it, the app downloads a separate **CUDA backend binary** that contains the PyTorch + CUDA runtime.
|
||||
|
||||
|
||||
@@ -75,8 +75,7 @@ No cloud fallback, no bring-your-own-API-key. Local is the product.
|
||||
| Platform | Backend | Notes |
|
||||
|----------|---------|-------|
|
||||
| macOS (Apple Silicon) | MLX (Metal) | 4-5x faster via Neural Engine |
|
||||
| Windows (NVIDIA) | PyTorch (CUDA) | Auto-downloads CUDA binary from within the app |
|
||||
| Linux (NVIDIA) | PyTorch (CUDA) | Use a local/remote Python backend with CUDA PyTorch |
|
||||
| Windows / Linux (NVIDIA) | PyTorch (CUDA) | Auto-downloads CUDA binary from within the app |
|
||||
| Linux (AMD) | PyTorch (ROCm) | Auto-configures HSA_OVERRIDE_GFX_VERSION |
|
||||
| Windows (any GPU) | DirectML | Universal Windows GPU support |
|
||||
| Intel Arc | IPEX/XPU | Intel discrete GPU acceleration |
|
||||
|
||||
@@ -14,12 +14,12 @@ Make sure you have [installed Voicebox](/overview/installation) and launched the
|
||||
Voice profiles are the foundation of Voicebox. Each profile contains voice samples that the AI uses to clone the voice.
|
||||
|
||||
<Steps>
|
||||
<Step title="Navigate to Voices">
|
||||
Click the **Voices** tab in the sidebar
|
||||
<Step title="Navigate to Profiles">
|
||||
Click the **Profiles** tab in the sidebar
|
||||
</Step>
|
||||
|
||||
<Step title="Create New Voice">
|
||||
Click the **+ New Voice** button
|
||||
<Step title="Create New Profile">
|
||||
Click the **+ New Profile** button
|
||||
|
||||
Fill in the details:
|
||||
- **Name:** A descriptive name (e.g., "John Smith")
|
||||
|
||||
@@ -43,26 +43,6 @@ setup-python:
|
||||
fi
|
||||
echo "Installing Python dependencies..."
|
||||
{{ pip }} install --upgrade pip -q
|
||||
if [ "$(uname)" = "Linux" ]; then
|
||||
torch_index=""
|
||||
if [ -e /proc/driver/nvidia/version ] || [ -d /sys/module/nvidia ]; then
|
||||
echo "Detected NVIDIA GPU — installing CUDA PyTorch..."
|
||||
torch_index="https://download.pytorch.org/whl/cu128"
|
||||
elif [ -e /dev/kfd ]; then
|
||||
if [ -n "${VOICEBOX_ROCM_VERSION:-}" ]; then
|
||||
rocm_ver="$VOICEBOX_ROCM_VERSION"
|
||||
elif lspci 2>/dev/null | grep -qi "Navi 4"; then
|
||||
rocm_ver=7.2
|
||||
else
|
||||
rocm_ver=6.3
|
||||
fi
|
||||
echo "Detected AMD GPU — installing ROCm PyTorch (rocm${rocm_ver})..."
|
||||
torch_index="https://download.pytorch.org/whl/rocm${rocm_ver}"
|
||||
fi
|
||||
if [ -n "$torch_index" ]; then
|
||||
{{ pip }} install torch torchaudio --index-url "$torch_index"
|
||||
fi
|
||||
fi
|
||||
{{ pip }} install -r {{ backend_dir }}/requirements.txt
|
||||
# Chatterbox pins numpy<1.26 / torch==2.6 which break on Python 3.12+
|
||||
{{ pip }} install --no-deps chatterbox-tts
|
||||
@@ -72,12 +52,6 @@ setup-python:
|
||||
if [ "$(uname -m)" = "arm64" ] && [ "$(uname)" = "Darwin" ]; then
|
||||
echo "Detected Apple Silicon — installing MLX dependencies..."
|
||||
{{ pip }} install -r {{ backend_dir }}/requirements-mlx.txt
|
||||
# mlx-lm and mlx-audio declare transformers>=5.x, which conflicts with
|
||||
# our transformers<=4.57.x cap, so install them --no-deps (their other
|
||||
# runtime deps are covered by requirements.txt / requirements-mlx.txt —
|
||||
# see the note in requirements-mlx.txt and .github/workflows/release.yml)
|
||||
{{ pip }} install --no-deps mlx-lm==0.31.1
|
||||
{{ pip }} install --no-deps mlx-audio==0.4.1
|
||||
fi
|
||||
{{ pip }} install git+https://github.com/QwenLM/Qwen3-TTS.git
|
||||
{{ pip }} install pyinstaller ruff pytest pytest-asyncio -q
|
||||
@@ -95,10 +69,10 @@ setup-python:
|
||||
}
|
||||
Write-Host "Installing Python dependencies..."
|
||||
& "{{ python }}" -m pip install --upgrade pip -q
|
||||
$gpus = Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name; \
|
||||
Write-Host "Detected GPUs: $($gpus -join ', ')"; \
|
||||
$hasNvidia = ($gpus | Where-Object { $_ -match 'NVIDIA' }).Count -gt 0; \
|
||||
$hasIntelArc = ($gpus | Where-Object { $_ -match 'Arc' }).Count -gt 0; \
|
||||
$gpus = Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name
|
||||
Write-Host "Detected GPUs: $($gpus -join ', ')"
|
||||
$hasNvidia = ($gpus | Where-Object { $_ -match 'NVIDIA' }).Count -gt 0
|
||||
$hasIntelArc = ($gpus | Where-Object { $_ -match 'Arc' }).Count -gt 0
|
||||
if ($hasNvidia) { \
|
||||
Write-Host "NVIDIA GPU detected — installing PyTorch with CUDA support..."; \
|
||||
& "{{ pip }}" install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128; \
|
||||
@@ -232,16 +206,12 @@ build-server: _ensure-venv
|
||||
build-server: _ensure-venv
|
||||
$ErrorActionPreference = "Stop"; \
|
||||
$env:PATH = "{{ venv_bin }};$env:PATH"; \
|
||||
$triple = (rustc --print host-tuple); \
|
||||
New-Item -ItemType Directory -Path "{{ tauri_dir }}/src-tauri/binaries" -Force | Out-Null; \
|
||||
& "{{ python }}" backend/build_binary.py; \
|
||||
if ($LASTEXITCODE -ne 0) { throw "build_binary.py failed with exit code $LASTEXITCODE" }; \
|
||||
$triple = (rustc --print host-tuple); \
|
||||
New-Item -ItemType Directory -Path "{{ tauri_dir }}/src-tauri/binaries" -Force | Out-Null; \
|
||||
Copy-Item "backend/dist/voicebox-server.exe" "{{ tauri_dir }}/src-tauri/binaries/voicebox-server-$triple.exe" -Force; \
|
||||
Write-Host "Copied sidecar: voicebox-server-$triple.exe"; \
|
||||
& "{{ python }}" backend/build_binary.py --shim; \
|
||||
if ($LASTEXITCODE -ne 0) { throw "build_binary.py --shim failed with exit code $LASTEXITCODE" }; \
|
||||
Copy-Item "backend/dist/voicebox-mcp.exe" "{{ tauri_dir }}/src-tauri/binaries/voicebox-mcp-$triple.exe" -Force; \
|
||||
Write-Host "Copied sidecar: voicebox-mcp-$triple.exe"
|
||||
Write-Host "Copied sidecar: voicebox-server-$triple.exe"
|
||||
|
||||
# Build CUDA server binary and place in app data dir for local testing
|
||||
[windows]
|
||||
|
||||
@@ -12,7 +12,6 @@ import type {Metadata} from "next";
|
||||
import {Footer} from "@/components/Footer";
|
||||
import {Navbar} from "@/components/Navbar";
|
||||
import {TokenSection} from "@/components/TokenSection";
|
||||
import {TokenStatsSection} from "@/components/TokenStats";
|
||||
import {
|
||||
TOKEN_PROOFS,
|
||||
TOKEN_SOLSCAN_URL,
|
||||
@@ -31,10 +30,6 @@ export const metadata: Metadata = {
|
||||
},
|
||||
};
|
||||
|
||||
// Re-fetch live on-chain stats at most every 10 minutes (matches the server
|
||||
// cache in token-stats.ts). Keeps the page static-fast while staying fresh.
|
||||
export const revalidate = 600;
|
||||
|
||||
const USE_OF_FUNDS = [
|
||||
{
|
||||
icon: Rocket,
|
||||
@@ -82,9 +77,6 @@ export default function TokenPage() {
|
||||
<main className="pt-16">
|
||||
<TokenSection />
|
||||
|
||||
{/* ── Live on-chain stats ──────────────────────────────────── */}
|
||||
<TokenStatsSection />
|
||||
|
||||
{/* ── Why a token ──────────────────────────────────────────── */}
|
||||
<section className="border-t border-border py-20">
|
||||
<div className="mx-auto max-w-3xl px-6">
|
||||
@@ -152,6 +144,72 @@ export default function TokenPage() {
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* ── On-chain transparency ────────────────────────────────── */}
|
||||
<section className="border-t border-border py-20">
|
||||
<div className="mx-auto max-w-4xl px-6">
|
||||
<div className="text-center mb-12">
|
||||
<div className="text-[11px] font-semibold uppercase tracking-[0.22em] text-accent mb-4">
|
||||
On-chain transparency
|
||||
</div>
|
||||
<h2 className="text-3xl md:text-4xl font-semibold tracking-tight text-foreground">
|
||||
Don't trust — verify.
|
||||
</h2>
|
||||
<p className="text-muted-foreground max-w-2xl mx-auto mt-4">
|
||||
Liquidity is locked and supply is reduced through ongoing
|
||||
buyback & burns. Every action is on-chain and linked here, so
|
||||
you never have to take my word for it.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 sm:grid-cols-3">
|
||||
{TOKEN_PROOFS.map((proof, i) => {
|
||||
const Icon = proof.kind === "lock" ? Lock : Flame;
|
||||
return (
|
||||
<div
|
||||
key={`${proof.label}-${i}`}
|
||||
className="flex flex-col rounded-xl border border-border bg-card/40 backdrop-blur-sm p-6"
|
||||
>
|
||||
<Icon className="h-5 w-5 text-accent mb-3" />
|
||||
<h3 className="text-[15px] font-semibold text-foreground mb-2">
|
||||
{proof.label}
|
||||
</h3>
|
||||
<p className="text-sm leading-relaxed text-muted-foreground flex-1">
|
||||
{proof.detail}
|
||||
</p>
|
||||
{proof.txUrl ? (
|
||||
<a
|
||||
href={proof.txUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="mt-4 inline-flex items-center gap-1.5 text-sm font-medium text-foreground/80 hover:text-foreground transition-colors"
|
||||
>
|
||||
View on Solscan
|
||||
<ArrowUpRight className="h-3.5 w-3.5" />
|
||||
</a>
|
||||
) : (
|
||||
<span className="mt-4 inline-flex items-center gap-1.5 text-xs font-medium text-muted-foreground/60">
|
||||
Proof link pending
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
<div className="mt-6 text-center">
|
||||
<a
|
||||
href={TOKEN_SOLSCAN_URL}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
Inspect supply & holders on Solscan
|
||||
<ArrowUpRight className="h-4 w-4" />
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* ── Official vs community ────────────────────────────────── */}
|
||||
<section className="border-t border-border py-20">
|
||||
<div className="mx-auto max-w-3xl px-6">
|
||||
|
||||
@@ -1,309 +0,0 @@
|
||||
import {ArrowUpRight, Coins, Flame, Lock, Users, Wallet} from "lucide-react";
|
||||
import {
|
||||
TOKEN_CONTRACT_ADDRESS,
|
||||
TOKEN_CREATOR_ADDRESS,
|
||||
TOKEN_SOLSCAN_URL,
|
||||
TOKEN_TICKER,
|
||||
} from "@/lib/constants";
|
||||
import {getTokenStats, type TokenStats} from "@/lib/token-stats";
|
||||
|
||||
// ── formatters ───────────────────────────────────────────────────────────────
|
||||
function compact(n: number | null): string {
|
||||
if (n == null) return "—";
|
||||
const abs = Math.abs(n);
|
||||
if (abs >= 1_000_000_000) return `${(n / 1_000_000_000).toFixed(2)}B`;
|
||||
if (abs >= 1_000_000) return `${(n / 1_000_000).toFixed(2)}M`;
|
||||
if (abs >= 1_000) return `${(n / 1_000).toFixed(1)}K`;
|
||||
return n.toLocaleString("en-US", {maximumFractionDigits: 0});
|
||||
}
|
||||
|
||||
function pct(n: number | null): string {
|
||||
if (n == null) return "—";
|
||||
if (n > 0 && n < 0.01) return "<0.01%";
|
||||
return `${n.toFixed(2)}%`;
|
||||
}
|
||||
|
||||
function usdPrice(n: number | null): string {
|
||||
if (n == null) return "—";
|
||||
if (n < 0.000001) return `$${n.toExponential(2)}`;
|
||||
if (n < 1) return `$${n.toPrecision(3)}`;
|
||||
return `$${n.toLocaleString("en-US", {maximumFractionDigits: 2})}`;
|
||||
}
|
||||
|
||||
function usdBig(n: number | null): string {
|
||||
if (n == null) return "—";
|
||||
if (n >= 1_000_000) return `$${(n / 1_000_000).toFixed(2)}M`;
|
||||
if (n >= 1_000) return `$${(n / 1_000).toFixed(1)}K`;
|
||||
return `$${n.toLocaleString("en-US", {maximumFractionDigits: 0})}`;
|
||||
}
|
||||
|
||||
function sol(n: number | null): string {
|
||||
if (n == null) return "—";
|
||||
return `${n.toLocaleString("en-US", {maximumFractionDigits: 2})} SOL`;
|
||||
}
|
||||
|
||||
function shortAddr(a: string): string {
|
||||
return a.length > 12 ? `${a.slice(0, 4)}…${a.slice(-4)}` : a;
|
||||
}
|
||||
|
||||
function solscanAccount(a: string): string {
|
||||
return `https://solscan.io/account/${a}`;
|
||||
}
|
||||
|
||||
function timeAgo(ts: number): string {
|
||||
const secs = Math.max(0, Math.round((Date.now() - ts) / 1000));
|
||||
if (secs < 60) return "just now";
|
||||
const mins = Math.round(secs / 60);
|
||||
if (mins < 60) return `${mins}m ago`;
|
||||
const hrs = Math.round(mins / 60);
|
||||
return `${hrs}h ago`;
|
||||
}
|
||||
|
||||
export async function TokenStatsSection() {
|
||||
const stats = await getTokenStats();
|
||||
return <TokenStatsView stats={stats} />;
|
||||
}
|
||||
|
||||
// Hidden for now — flip to true to bring the "fees earned for development"
|
||||
// card back. The data is still fetched; it's just not rendered.
|
||||
const SHOW_CREATOR_REWARDS = false;
|
||||
|
||||
function TokenStatsView({stats}: {stats: TokenStats}) {
|
||||
const cards = [
|
||||
{
|
||||
icon: Flame,
|
||||
label: "Burned",
|
||||
value: compact(stats.burned),
|
||||
sub: stats.burnedPct != null ? `${pct(stats.burnedPct)} of initial supply` : "Removed from supply forever",
|
||||
},
|
||||
{
|
||||
icon: Lock,
|
||||
label: "Locked",
|
||||
value: stats.locked != null ? compact(stats.locked) : "Not configured",
|
||||
sub: stats.lockedPct != null ? `${pct(stats.lockedPct)} of supply` : "Liquidity & vesting locks",
|
||||
},
|
||||
{
|
||||
icon: Wallet,
|
||||
label: "Dev / treasury",
|
||||
value: stats.devBalance != null ? compact(stats.devBalance) : "Not configured",
|
||||
sub: stats.devPct != null ? `${pct(stats.devPct)} of supply` : "Team-held tokens",
|
||||
},
|
||||
{
|
||||
icon: Users,
|
||||
label: "Holders",
|
||||
value: stats.holders != null ? `${stats.holdersCapped ? "" : ""}${stats.holders.toLocaleString("en-US")}` : "—",
|
||||
sub: stats.holdersCapped ? "counted (capped)" : "unique wallets",
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<section className="border-t border-border py-20">
|
||||
<div className="mx-auto max-w-5xl px-6">
|
||||
{/* Header */}
|
||||
<div className="text-center mb-12">
|
||||
<div className="text-[11px] font-semibold uppercase tracking-[0.22em] text-accent mb-4">
|
||||
Live on-chain stats
|
||||
</div>
|
||||
<h2 className="text-3xl md:text-4xl font-semibold tracking-tight text-foreground">
|
||||
Every number, straight from the chain.
|
||||
</h2>
|
||||
<p className="text-muted-foreground max-w-2xl mx-auto mt-4">
|
||||
Supply, holders, burns, locks and team holdings for {TOKEN_TICKER},
|
||||
read live from Solana.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Supply + market headline */}
|
||||
<div className="grid gap-4 sm:grid-cols-3 mb-4">
|
||||
<HeadlineStat
|
||||
label="Circulating supply"
|
||||
value={compact(stats.circulating)}
|
||||
sub={
|
||||
stats.totalSupply != null
|
||||
? `of ${compact(stats.totalSupply)} total`
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
<HeadlineStat label="Price" value={usdPrice(stats.priceUsd)} sub="via Jupiter" />
|
||||
<HeadlineStat label="Market cap" value={usdBig(stats.marketCapUsd)} sub="price × supply" />
|
||||
</div>
|
||||
|
||||
{/* Stat cards */}
|
||||
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
|
||||
{cards.map((c) => {
|
||||
const Icon = c.icon;
|
||||
return (
|
||||
<div
|
||||
key={c.label}
|
||||
className="rounded-xl border border-border bg-card/40 backdrop-blur-sm p-6"
|
||||
>
|
||||
<Icon className="h-5 w-5 text-accent mb-3" />
|
||||
<div className="text-[11px] font-medium uppercase tracking-wider text-muted-foreground mb-1">
|
||||
{c.label}
|
||||
</div>
|
||||
<div className="text-2xl font-semibold tracking-tight text-foreground tabular-nums">
|
||||
{c.value}
|
||||
</div>
|
||||
<div className="text-xs text-muted-foreground mt-1">{c.sub}</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Creator rewards — pump.fun creator fees, the funding story */}
|
||||
{SHOW_CREATOR_REWARDS && stats.creatorRewardsSol != null && (
|
||||
<div className="mt-4 rounded-2xl border border-accent/30 bg-gradient-to-b from-accent/[0.08] to-transparent p-8 text-center">
|
||||
<div className="mx-auto mb-3 flex h-10 w-10 items-center justify-center rounded-full border border-accent/30 bg-accent/10">
|
||||
<Coins className="h-5 w-5 text-accent" />
|
||||
</div>
|
||||
<div className="text-[11px] font-semibold uppercase tracking-[0.2em] text-muted-foreground">
|
||||
Fees earned for development
|
||||
</div>
|
||||
<div className="mt-2 text-4xl font-semibold tracking-tight text-foreground tabular-nums">
|
||||
{sol(stats.creatorRewardsSol)}
|
||||
</div>
|
||||
{stats.creatorRewardsUsd != null && (
|
||||
<div className="mt-1 text-sm text-muted-foreground tabular-nums">
|
||||
≈ {usdBig(stats.creatorRewardsUsd)}
|
||||
</div>
|
||||
)}
|
||||
<p className="mx-auto mt-4 max-w-md text-sm leading-relaxed text-muted-foreground">
|
||||
Lifetime {TOKEN_TICKER} trading fees — the funding that pays for
|
||||
full-time work on Voicebox.{" "}
|
||||
<a
|
||||
href={`https://solscan.io/account/${TOKEN_CREATOR_ADDRESS}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center gap-0.5 text-foreground/80 hover:text-foreground"
|
||||
>
|
||||
Verify <ArrowUpRight className="h-3 w-3" />
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Locked breakdown (only if any configured) */}
|
||||
{stats.lockedBreakdown.length > 0 && (
|
||||
<div className="mt-4 rounded-xl border border-border bg-card/40 backdrop-blur-sm p-6">
|
||||
<div className="text-[11px] font-medium uppercase tracking-wider text-muted-foreground mb-4">
|
||||
Locked & vesting
|
||||
</div>
|
||||
<ul className="space-y-3">
|
||||
{stats.lockedBreakdown.map((l) => (
|
||||
<li
|
||||
key={l.account}
|
||||
className="flex items-center gap-3 text-sm"
|
||||
>
|
||||
<Lock className="h-4 w-4 shrink-0 text-accent" />
|
||||
<span className="text-foreground/90">{l.label}</span>
|
||||
{l.unlocksAt && (
|
||||
<span className="text-xs text-muted-foreground">· {l.unlocksAt}</span>
|
||||
)}
|
||||
<span className="ml-auto font-medium tabular-nums text-foreground">
|
||||
{compact(l.amount)}
|
||||
</span>
|
||||
<a
|
||||
href={l.url ?? solscanAccount(l.account)}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-muted-foreground hover:text-foreground"
|
||||
aria-label="View on Solscan"
|
||||
>
|
||||
<ArrowUpRight className="h-4 w-4" />
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Top holders */}
|
||||
{stats.topHolders.length > 0 && (
|
||||
<div className="mt-4 rounded-xl border border-border bg-card/40 backdrop-blur-sm p-6">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<div className="text-[11px] font-medium uppercase tracking-wider text-muted-foreground">
|
||||
Top holders
|
||||
</div>
|
||||
<a
|
||||
href={`${TOKEN_SOLSCAN_URL}#holders`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
All holders <ArrowUpRight className="h-3 w-3" />
|
||||
</a>
|
||||
</div>
|
||||
<ul className="divide-y divide-border/60">
|
||||
{stats.topHolders.map((h, i) => (
|
||||
<li
|
||||
key={h.owner}
|
||||
className="flex items-center gap-3 py-2.5 text-sm"
|
||||
>
|
||||
<span className="w-5 text-xs text-muted-foreground tabular-nums">
|
||||
{i + 1}
|
||||
</span>
|
||||
<a
|
||||
href={solscanAccount(h.owner)}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="font-mono text-foreground/90 hover:text-foreground hover:underline"
|
||||
>
|
||||
{shortAddr(h.owner)}
|
||||
</a>
|
||||
<span className="ml-auto tabular-nums text-foreground">
|
||||
{compact(h.amount)}
|
||||
</span>
|
||||
<span className="w-16 text-right tabular-nums text-muted-foreground">
|
||||
{pct(h.pct)}
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Footer: provenance + freshness */}
|
||||
<div className="mt-6 flex flex-col sm:flex-row items-center justify-between gap-3 text-xs text-muted-foreground">
|
||||
<span>
|
||||
{stats.live ? (
|
||||
<>Updated {timeAgo(stats.updatedAt)} · data via Helius & Jupiter</>
|
||||
) : (
|
||||
<>Live stats unavailable right now — verify on Solscan.</>
|
||||
)}
|
||||
</span>
|
||||
<a
|
||||
href={TOKEN_SOLSCAN_URL}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center gap-1.5 hover:text-foreground transition-colors"
|
||||
>
|
||||
<span className="font-mono">{shortAddr(TOKEN_CONTRACT_ADDRESS)}</span>
|
||||
Inspect on Solscan <ArrowUpRight className="h-3.5 w-3.5" />
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function HeadlineStat({
|
||||
label,
|
||||
value,
|
||||
sub,
|
||||
}: {
|
||||
label: string;
|
||||
value: string;
|
||||
sub?: string;
|
||||
}) {
|
||||
return (
|
||||
<div className="rounded-2xl border border-border bg-card/60 backdrop-blur-sm p-6 text-center">
|
||||
<div className="text-[11px] font-medium uppercase tracking-wider text-muted-foreground mb-2">
|
||||
{label}
|
||||
</div>
|
||||
<div className="text-3xl font-semibold tracking-tight text-foreground tabular-nums">
|
||||
{value}
|
||||
</div>
|
||||
{sub && <div className="text-xs text-muted-foreground mt-1">{sub}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -16,111 +16,6 @@ export const TOKEN_PUMP_URL = `https://pump.fun/coin/${TOKEN_CONTRACT_ADDRESS}`;
|
||||
export const TOKEN_SOLSCAN_URL = `https://solscan.io/token/${TOKEN_CONTRACT_ADDRESS}`;
|
||||
export const TOKEN_TOTAL_SUPPLY = '1B';
|
||||
|
||||
// ── Live on-chain tracking config ───────────────────────────────────────────
|
||||
// Powers the transparency dashboard on /token. Reads are done server-side via
|
||||
// Helius (HELIUS_API_KEY). Every value below has a safe default so the page
|
||||
// still renders if something is unset — sections you haven't configured just
|
||||
// show as "not configured" rather than breaking the build.
|
||||
|
||||
/** Mint supply at launch, used to derive burned = initial − current supply. */
|
||||
export const TOKEN_INITIAL_SUPPLY = 1_000_000_000;
|
||||
|
||||
/**
|
||||
* pump.fun creator wallet — the address that launched the coin and earns creator
|
||||
* fees. Lifetime creator rewards (in SOL) are read from pump.fun's swap-api for
|
||||
* this wallet. Defaults to the dev wallet (they're the same here).
|
||||
*/
|
||||
export const TOKEN_CREATOR_ADDRESS = envStr(
|
||||
'TOKEN_CREATOR_ADDRESS',
|
||||
'BSn573bjkQa5iffMg6zA8eb9mHyzewu2ps9R85qNKXC5',
|
||||
);
|
||||
|
||||
/**
|
||||
* Dev / treasury wallets to surface as "team holdings". List every address you
|
||||
* want counted; balances are summed. Public, read-only — these are already
|
||||
* visible on-chain. Override at deploy time with TOKEN_DEV_WALLETS (comma list).
|
||||
*/
|
||||
export const TOKEN_DEV_WALLETS: string[] = envList('TOKEN_DEV_WALLETS', [
|
||||
'BSn573bjkQa5iffMg6zA8eb9mHyzewu2ps9R85qNKXC5', // Jamie's dev/treasury wallet
|
||||
]);
|
||||
|
||||
/**
|
||||
* Locked supply: token accounts whose $VOICEBOX is locked (liquidity lockers,
|
||||
* vesting escrows). Each entry is summed into "locked"; unlocksAt is optional
|
||||
* copy for the card. Override with TOKEN_LOCKED_ACCOUNTS as a JSON array.
|
||||
*/
|
||||
export interface LockedAccount {
|
||||
label: string;
|
||||
/** The token account or owner address holding the locked $VOICEBOX. */
|
||||
account: string;
|
||||
/** Human-readable unlock date, e.g. "Unlocks Jun 2027" (optional). */
|
||||
unlocksAt?: string;
|
||||
/** Optional Solscan/locker link proving the lock. */
|
||||
url?: string;
|
||||
}
|
||||
export const TOKEN_LOCKED_ACCOUNTS: LockedAccount[] = envJson<LockedAccount[]>(
|
||||
'TOKEN_LOCKED_ACCOUNTS',
|
||||
[
|
||||
// Streamflow locks. `account` is each lock's escrow token account (read for
|
||||
// the live balance, so it ticks down only when actually unlocked/withdrawn);
|
||||
// `url` is the public Streamflow contract page for verification.
|
||||
{
|
||||
label: 'Streamflow lock #1',
|
||||
account: 'EaPun3ZUk5XiKft2tbvVRXgq8HyXjTmg77kUYYe7Q5HM',
|
||||
unlocksAt: 'Unlocks Jun 2027',
|
||||
url: 'https://app.streamflow.finance/contract/solana/mainnet/AmzHaDAZWWZPkvN5zC78mQ3QAedH7hHSCEWeYSbSWXu5',
|
||||
},
|
||||
{
|
||||
label: 'Streamflow lock #2',
|
||||
account: 'FGK5G4CbtryRdoubPN7u4y3WTYS4vqoepPLpppba92cp',
|
||||
unlocksAt: 'Unlocks Jun 2027',
|
||||
url: 'https://app.streamflow.finance/contract/solana/mainnet/GfBjWriW8mcJWS9njC2gBBJoJuGRQQzJLRFNg6a12bW8',
|
||||
},
|
||||
{
|
||||
label: 'Streamflow lock #3',
|
||||
account: 'ELKMRnDin7w6ht4MkQ6FnDU3LvkDtoYbtR9y3P51pf1N',
|
||||
unlocksAt: 'Unlocks Jun 2027',
|
||||
url: 'https://app.streamflow.finance/contract/solana/mainnet/3xa49K6b8ChsL5SoPYrAWigwKmoXAge6YCAmUJWM6Ncw',
|
||||
},
|
||||
],
|
||||
);
|
||||
|
||||
/**
|
||||
* Burn / dead address. The standard SPL incinerator by default. Buyback+burns
|
||||
* that reduce mint supply are already captured by initial − current; this is
|
||||
* only used to additionally surface anything parked at a dead address.
|
||||
*/
|
||||
export const TOKEN_BURN_ADDRESS = envStr(
|
||||
'TOKEN_BURN_ADDRESS',
|
||||
'1nc1nerator11111111111111111111111111111111',
|
||||
);
|
||||
|
||||
/** How long stats are cached server-side (ms). Keeps us off rate limits. */
|
||||
export const TOKEN_STATS_CACHE_MS = 1000 * 60 * 10; // 10 minutes
|
||||
|
||||
// ── tiny env helpers (server-only; safe in this module, no secrets exposed) ──
|
||||
function envStr(key: string, fallback: string): string {
|
||||
const v = process.env[key];
|
||||
return v && v.trim() ? v.trim() : fallback;
|
||||
}
|
||||
function envList(key: string, fallback: string[]): string[] {
|
||||
const v = process.env[key];
|
||||
if (!v || !v.trim()) return fallback;
|
||||
return v
|
||||
.split(',')
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean);
|
||||
}
|
||||
function envJson<T>(key: string, fallback: T): T {
|
||||
const v = process.env[key];
|
||||
if (!v || !v.trim()) return fallback;
|
||||
try {
|
||||
return JSON.parse(v) as T;
|
||||
} catch {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
// On-chain transparency log — locks and buyback+burns.
|
||||
// Add a new entry every time a lock or burn happens; set `txUrl` to its Solscan
|
||||
// link to make the card a live, verifiable proof. Entries without a txUrl render
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user