Architectural change
The browser no longer talks to the LLM directly. A new Node server
(server.mjs) sits in the middle:
[Browser] → [Node :3000] → [LLM provider]
(no key) (key in .env)
server.mjs is the production runtime: it serves the built SPA out of
dist/ and exposes three JSON endpoints that proxy to the LLM with
credentials held in process.env. The browser-side llm.ts is now a thin
fetch wrapper.
- server.mjs: single-file Node server, no production deps
- server/prompts.mjs: system + user prompt construction (was client-side)
- src/lib/prompts.ts removed (moved server-side)
- src/lib/llm.ts rewritten — no more direct LLM calls, no more
JSON extraction, no more validation; just fetch the proxy
- src/lib/types.ts: drop SaveConfigPayload/TestConnectionResult, add
style_hint and ServerStatus
- vite.config.ts: proxy /api/* → localhost:3000 in dev
- .env.example: LLM_* and PORT/CORS_ORIGIN instead of Supabase values
New feature: random style buttons
The Options → Music style field now has two AI buttons that fill it
with a fresh Suno style description:
- 'Surprise me' → coherent, production-ready style (max 25 words)
- 'Go crazy' → deliberately clashing genre mashup (max 25 words)
The buttons hit a dedicated /api/style/random endpoint on the server
that uses a small, focused system prompt. Each click overwrites the
field. Both buttons show a spinner and disable while a request is
in flight. Errors surface as toasts. AbortController is used so a
fast second click cancels the first.
When the Music style field is non-empty at generation time, its value
is sent to the model as style_hint and used as the basis for the full
120-word style field (per the updated system prompt).
Other UX
- Settings page is now a server-status page: green/red indicator,
model + endpoint, re-check button. The API key is no longer
configurable in the browser (it never was reachable anyway — now
the UI is honest about that).
- Home page header shows a small 'Server offline' warning when the
server is unreachable.
- Settings has a Local data section: list what's in localStorage
with one-click clear-history and clear-all buttons (with confirm).
- Esc cancels any in-flight generation.
- ZIP filename falls back to 'song' if the title sanitizes to empty.
Deployment
deploy/ holds reference files (Dockerfile, docker-compose example,
Caddy fragment, generate-env.sh, README) for adding the service to a
Jannik-Cloud-style stack. The repo is intentionally not wired into
the Jannik-Cloud repo; copy the four files when ready.
58 lines
1.9 KiB
Bash
58 lines
1.9 KiB
Bash
#!/usr/bin/env bash
|
|
# generate-env.sh — create the MelodyMuse `.env` (and AGE-encrypt it).
|
|
#
|
|
# Usage: bash generate-env.sh
|
|
#
|
|
# Customize LLM_ENDPOINT / LLM_MODEL below before running. The script prompts
|
|
# for the LLM_API_KEY so it doesn't end up in your shell history.
|
|
|
|
set -euo pipefail
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
|
|
AGE_PUB_KEY="${REPO_ROOT}/keys/age-public-key.txt"
|
|
|
|
# ─── Customize these for your deployment ─────────────────────────────────────
|
|
LLM_ENDPOINT_DEFAULT="https://api.minimax.chat/v1"
|
|
LLM_MODEL_DEFAULT="MiniMax-M3"
|
|
# ──────────────────────────────────────────────────────────────────────────────
|
|
|
|
echo "LLM endpoint [${LLM_ENDPOINT_DEFAULT}]:"
|
|
read -r LLM_ENDPOINT
|
|
LLM_ENDPOINT="${LLM_ENDPOINT:-$LLM_ENDPOINT_DEFAULT}"
|
|
|
|
echo "LLM model [${LLM_MODEL_DEFAULT}]:"
|
|
read -r LLM_MODEL
|
|
LLM_MODEL="${LLM_MODEL:-$LLM_MODEL_DEFAULT}"
|
|
|
|
echo "LLM API key (input is hidden):"
|
|
read -rs LLM_API_KEY
|
|
echo ""
|
|
|
|
if [[ -z "${LLM_API_KEY}" ]]; then
|
|
echo "ERROR: LLM_API_KEY is required."
|
|
exit 1
|
|
fi
|
|
|
|
cat > "${SCRIPT_DIR}/.env" <<EOF
|
|
# MelodyMuse — generated by generate-env.sh
|
|
LLM_ENDPOINT=${LLM_ENDPOINT}
|
|
LLM_API_KEY=${LLM_API_KEY}
|
|
LLM_MODEL=${LLM_MODEL}
|
|
PORT=3000
|
|
CORS_ORIGIN=*
|
|
EOF
|
|
|
|
chmod 600 "${SCRIPT_DIR}/.env"
|
|
|
|
if [[ -f "${AGE_PUB_KEY}" ]]; then
|
|
age -r "$(cat "${AGE_PUB_KEY}")" -o "${SCRIPT_DIR}/.env.age" "${SCRIPT_DIR}/.env"
|
|
echo ""
|
|
echo "Encrypted .env → .env.age"
|
|
echo "Commit .env.age (NOT .env) to your repo, then re-run deploy."
|
|
else
|
|
echo ""
|
|
echo "No AGE public key found at ${AGE_PUB_KEY}."
|
|
echo "Encrypt manually before committing, e.g.:"
|
|
echo " age -r <recipient> -o .env.age .env"
|
|
fi
|