feat(setup): one guided flow; ask for PostgreSQL and generate the bundled database's password
This commit is contained in:
7 files changed
+91
-271
No files matched your search
@@ -106,10 +106,13 @@ local [Ollama](https://ollama.com) or a hosted provider API key.
|
||||
./install.sh
|
||||
```
|
||||
|
||||
It builds the five services into `~/.local/bin`, asks for a forge (choose
|
||||
**None** if you only want event-driven automation) and a model, writes
|
||||
`~/.config/archie/config.toml`, starts PostgreSQL with Docker Compose, and
|
||||
installs and starts systemd user units. Use `--no-systemd` to run the
|
||||
It builds the five services into `~/.local/bin`, then runs `archied setup`,
|
||||
which asks for the PostgreSQL URL (the default is the bundled Compose
|
||||
database), a model provider and key, and a forge (choose **none** for
|
||||
event-driven automation only). Answers go to `~/.config/archie/config.toml`
|
||||
and keys to `~/.config/archie/env`. It then starts PostgreSQL with Docker
|
||||
Compose when you kept the default, and installs and starts systemd user
|
||||
units. Re-run `archied setup` at any time to change the answers. Use `--no-systemd` to run the
|
||||
processes yourself. A prebuilt release archive works too; its
|
||||
`INSTRUCTIONS.md` covers that path.
|
||||
|
||||
|
||||
+4
-5
@@ -14,7 +14,7 @@
|
||||
# serve from. Required: each fails closed without it.
|
||||
# `docker compose up -d postgres` starts a matching local postgres:18 with this
|
||||
# default URL.
|
||||
database_url = "postgres://archie:archie@127.0.0.1:5432/archie?sslmode=disable"
|
||||
# database_url = "postgres://archie:archie@127.0.0.1:5432/archie?sslmode=disable"
|
||||
|
||||
# skills_dir = "~/.local/share/archie/skills" # SKILL.md search path; defaults under work_dir when unset
|
||||
# workflow_routing_file = "~/.local/share/archie/workflow-routing.yaml" # kind->workflow rebinding (bug/feature)
|
||||
@@ -99,10 +99,9 @@ builder = "openai/gpt-5.4"
|
||||
# voice note as its media placeholder -- the turn still runs.
|
||||
# transcription = "openai/whisper-1"
|
||||
|
||||
[providers.openai]
|
||||
class = "openai"
|
||||
api_key = { engine = "bws", key = "OPENAI_API_KEY" }
|
||||
# api_key_env = "OPENAI_API_KEY" # backwards-compatible environment form
|
||||
# [providers.openai]
|
||||
# class = "openai"
|
||||
# api_key = { engine = "env", key = "OPENAI_API_KEY" }
|
||||
|
||||
[providers.ollama]
|
||||
class = "ollama"
|
||||
|
||||
+4
-2
@@ -25,13 +25,15 @@ services:
|
||||
image: postgres:18
|
||||
environment:
|
||||
POSTGRES_USER: archie
|
||||
POSTGRES_PASSWORD: archie
|
||||
# archied setup generates this into ~/.config/archie/env; the fallback is
|
||||
# the dev password deployments/dev.toml uses.
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-archie}
|
||||
POSTGRES_DB: archie
|
||||
# postgres:18 moved its default PGDATA under a versioned path; pin the
|
||||
# classic location so the named volume keeps working across image updates.
|
||||
PGDATA: /var/lib/postgresql/data/pgdata
|
||||
ports:
|
||||
- "5432:5432"
|
||||
- "127.0.0.1:5432:5432"
|
||||
volumes:
|
||||
- pg_data:/var/lib/postgresql/data
|
||||
restart: unless-stopped
|
||||
|
||||
+17
-222
@@ -202,209 +202,31 @@ echo "==> Building native archie binaries..."
|
||||
)
|
||||
echo " Installed archied, archie-gateway, archie-state-store, archie-ui, archie-messaging and updater to ${ARCHIE_BIN_DIR}/"
|
||||
|
||||
# 5. Interactive Configuration: Forge & LLM Provider Setup
|
||||
if [ ! -f "${ENV_FILE}" ]; then
|
||||
touch "${ENV_FILE}"
|
||||
chmod 600 "${ENV_FILE}"
|
||||
fi
|
||||
|
||||
# read_secret prompts without echoing. A token typed at a visible prompt stays
|
||||
# in terminal scrollback and in any screen recording, so it is never echoed
|
||||
# even though that costs the usual typo feedback.
|
||||
read_secret() {
|
||||
local prompt="$1" varname="$2" value=""
|
||||
read -rsp "${prompt}" value || value=""
|
||||
echo >&2
|
||||
printf -v "${varname}" '%s' "${value}"
|
||||
}
|
||||
|
||||
# set_env_key writes KEY=value to the env file, replacing any existing entry.
|
||||
# Appending meant a second install run left the revoked token above the new one
|
||||
# and grew the file without bound.
|
||||
set_env_key() {
|
||||
local key="$1" value="$2" tmp
|
||||
tmp="$(mktemp "${ARCHIE_CONFIG_DIR}/.env.XXXXXX")"
|
||||
chmod 600 "${tmp}"
|
||||
if [ -f "${ENV_FILE}" ]; then
|
||||
grep -v "^${key}=" "${ENV_FILE}" > "${tmp}" || true
|
||||
fi
|
||||
# Single quotes with embedded-quote escaping: systemd's EnvironmentFile takes
|
||||
# the value literally, so a token containing " or \ must not be re-quoted.
|
||||
printf "%s='%s'\n" "${key}" "${value//\'/\'\\\'\'}" >> "${tmp}"
|
||||
mv "${tmp}" "${ENV_FILE}"
|
||||
chmod 600 "${ENV_FILE}"
|
||||
}
|
||||
|
||||
# Detect existing environment keys
|
||||
FOUND_ENV_KEYS=()
|
||||
[ -n "${OPENAI_API_KEY:-}" ] && FOUND_ENV_KEYS+=("OpenAI")
|
||||
[ -n "${ANTHROPIC_API_KEY:-}" ] && FOUND_ENV_KEYS+=("Anthropic")
|
||||
[ -n "${OPENROUTER_API_KEY:-}" ] && FOUND_ENV_KEYS+=("OpenRouter")
|
||||
[ -n "${GEMINI_API_KEY:-}" ] && FOUND_ENV_KEYS+=("Gemini")
|
||||
[ -n "${GROQ_API_KEY:-}" ] && FOUND_ENV_KEYS+=("Groq")
|
||||
[ -n "${DEEPSEEK_API_KEY:-}" ] && FOUND_ENV_KEYS+=("DeepSeek")
|
||||
[ -n "${MISTRAL_API_KEY:-}" ] && FOUND_ENV_KEYS+=("Mistral")
|
||||
|
||||
# Detect local LLM binaries
|
||||
FOUND_OLLAMA=false
|
||||
FOUND_LLAMA_SERVER=false
|
||||
command -v ollama &>/dev/null && FOUND_OLLAMA=true
|
||||
command -v llama-server &>/dev/null && FOUND_LLAMA_SERVER=true
|
||||
|
||||
FORGE_TYPE="github"
|
||||
GITEA_URL="https://gitea.example.com"
|
||||
SELF_HOST_LLM=false
|
||||
OLLAMA_MODEL=""
|
||||
CLOUD_MODEL=""
|
||||
|
||||
if [ "${INTERACTIVE}" = true ]; then
|
||||
echo ""
|
||||
echo "------------------------------------------------------------"
|
||||
echo " Step 1: Code Forge Configuration (GitHub / Gitea / Standalone)"
|
||||
echo "------------------------------------------------------------"
|
||||
echo "Do you want to configure a code forge to watch for issues/PRs?"
|
||||
echo " 1) GitHub (Default - recommended for GitHub repos)"
|
||||
echo " 2) Gitea (Self-hosted Gitea instance)"
|
||||
echo " 3) None (Run Archie in standalone mode without forge polling)"
|
||||
read -rp "Select option [1-3, default=1]: " forge_option || forge_option="1"
|
||||
forge_option="${forge_option:-1}"
|
||||
|
||||
case "${forge_option}" in
|
||||
1)
|
||||
FORGE_TYPE="github"
|
||||
echo " See docs/github-token.md for instructions (Note: Archie requires a Classic PAT, ghp_...)."
|
||||
read_secret "Enter ARCHIE_GITHUB_TOKEN (leave blank to configure later): " gh_token_input
|
||||
if [ -n "${gh_token_input}" ]; then
|
||||
set_env_key ARCHIE_GITHUB_TOKEN "${gh_token_input}"
|
||||
fi
|
||||
;;
|
||||
2)
|
||||
FORGE_TYPE="gitea"
|
||||
read -rp "Enter Gitea Base URL [https://gitea.example.com]: " gitea_url_input || gitea_url_input=""
|
||||
GITEA_URL="${gitea_url_input:-https://gitea.example.com}"
|
||||
read_secret "Enter ARCHIE_GITEA_TOKEN (leave blank to configure later): " gitea_token_input
|
||||
if [ -n "${gitea_token_input}" ]; then
|
||||
set_env_key ARCHIE_GITEA_TOKEN "${gitea_token_input}"
|
||||
fi
|
||||
# Copy Gitea plugin scripts if available
|
||||
if [ -d "${SRC_DIR}/extras/gitea" ]; then
|
||||
cp -rn "${SRC_DIR}/extras/gitea/"* "${ARCHIE_DATA_DIR}/plugins/" 2>/dev/null || true
|
||||
fi
|
||||
;;
|
||||
3)
|
||||
FORGE_TYPE="none"
|
||||
echo " Forge polling disabled. Archie will run in standalone mode."
|
||||
;;
|
||||
esac
|
||||
|
||||
echo ""
|
||||
echo "------------------------------------------------------------"
|
||||
echo " Step 2: LLM Provider Configuration"
|
||||
echo "------------------------------------------------------------"
|
||||
|
||||
if [ "${FOUND_OLLAMA}" = true ] || [ "${FOUND_LLAMA_SERVER}" = true ]; then
|
||||
echo "Detected local LLM engines on your system:"
|
||||
[ "${FOUND_OLLAMA}" = true ] && echo " - Ollama"
|
||||
[ "${FOUND_LLAMA_SERVER}" = true ] && echo " - llama-server"
|
||||
echo ""
|
||||
read -rp "Do you want Archie to use a self-hosted local LLM? [y/N]: " self_host_choice || self_host_choice="n"
|
||||
if [[ "${self_host_choice}" =~ ^[Yy] ]]; then
|
||||
SELF_HOST_LLM=true
|
||||
fi
|
||||
else
|
||||
read -rp "Do you want to set up Archie with a self-hosted local LLM (Ollama / llama.cpp)? [y/N]: " self_host_choice || self_host_choice="n"
|
||||
if [[ "${self_host_choice}" =~ ^[Yy] ]]; then
|
||||
SELF_HOST_LLM=true
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${SELF_HOST_LLM}" = true ]; then
|
||||
if [ "${FOUND_OLLAMA}" = true ]; then
|
||||
echo "Querying installed Ollama models ('ollama list')..."
|
||||
OLLAMA_MODELS=($(ollama list 2>/dev/null | tail -n +2 | awk '{print $1}'))
|
||||
|
||||
if [ ${#OLLAMA_MODELS[@]} -gt 0 ]; then
|
||||
echo "Installed Ollama models found:"
|
||||
for idx in "${!OLLAMA_MODELS[@]}"; do
|
||||
echo " $((idx+1))) ${OLLAMA_MODELS[$idx]}"
|
||||
done
|
||||
read -rp "Select model number [1-${#OLLAMA_MODELS[@]}, default=1]: " model_idx || model_idx="1"
|
||||
model_idx="${model_idx:-1}"
|
||||
selected_i=$((model_idx - 1))
|
||||
if [ ${selected_i} -ge 0 ] && [ ${selected_i} -lt ${#OLLAMA_MODELS[@]} ]; then
|
||||
OLLAMA_MODEL="${OLLAMA_MODELS[$selected_i]}"
|
||||
echo "Selected model: ${OLLAMA_MODEL}"
|
||||
fi
|
||||
else
|
||||
echo "No models found in Ollama yet."
|
||||
read -rp "Enter model name to pull or use (e.g. llama3 or qwen2.5:7b): " OLLAMA_MODEL || OLLAMA_MODEL="llama3"
|
||||
fi
|
||||
else
|
||||
echo "Ollama is not currently found on \$PATH."
|
||||
echo "Install Ollama from https://ollama.com and pull a model (e.g. 'ollama pull llama3')."
|
||||
read -rp "Enter model name to configure (default: llama3): " OLLAMA_MODEL || OLLAMA_MODEL="llama3"
|
||||
fi
|
||||
fi
|
||||
|
||||
# A cloud provider needs a model name. archied setup requires one, and the
|
||||
# installer previously emitted no [models] at all on this path.
|
||||
if [ "${SELF_HOST_LLM}" = false ]; then
|
||||
read -rp "Model name for OpenAI (e.g. gpt-5.4): " CLOUD_MODEL || CLOUD_MODEL=""
|
||||
CLOUD_MODEL="${CLOUD_MODEL:-gpt-5.4}"
|
||||
fi
|
||||
|
||||
# Prompt for cloud provider key if not self-hosting and no keys detected
|
||||
if [ "${SELF_HOST_LLM}" = false ] && [ ${#FOUND_ENV_KEYS[@]} -eq 0 ]; then
|
||||
echo "No existing cloud provider API keys were detected."
|
||||
read_secret "Enter OPENAI_API_KEY (leave blank to configure later): " openai_key_input
|
||||
if [ -n "${openai_key_input}" ]; then
|
||||
set_env_key OPENAI_API_KEY "${openai_key_input}"
|
||||
FOUND_ENV_KEYS+=("OpenAI")
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Generate config.toml through archied setup rather than here.
|
||||
#
|
||||
# archied setup renders the config, so the code writing it is the code that
|
||||
# reads it.
|
||||
#
|
||||
# The answers collected above are passed as parameters. Secrets are passed as
|
||||
# REFERENCES to the env keys set_env_key just wrote, never as values: a value on a
|
||||
# command line lands in shell history and every process listing, and would be a
|
||||
# second way to set a secret that no secret engine knows about.
|
||||
# 5. Configuration. archied setup asks every question and writes config.toml
|
||||
# plus any secrets to the env file beside it; this script asks nothing itself.
|
||||
if [ ! -f "${ARCHIE_CONFIG_DIR}/config.toml" ]; then
|
||||
echo "==> Generating initial config.toml..."
|
||||
setup_args=(--defaults -config "${ARCHIE_CONFIG_DIR}/config.toml" -forge-type "${FORGE_TYPE}")
|
||||
case "${FORGE_TYPE}" in
|
||||
github)
|
||||
setup_args+=(-forge-secret-ref env:ARCHIE_GITHUB_TOKEN)
|
||||
;;
|
||||
gitea)
|
||||
setup_args+=(-forge-host "${GITEA_URL}" -forge-secret-ref env:ARCHIE_GITEA_TOKEN)
|
||||
;;
|
||||
esac
|
||||
if [ "${SELF_HOST_LLM}" = true ]; then
|
||||
setup_args+=(-provider ollama -model "${OLLAMA_MODEL}")
|
||||
echo "==> Generating config.toml (archied setup)..."
|
||||
if [ "${INTERACTIVE}" = true ]; then
|
||||
setup_args=(-config "${ARCHIE_CONFIG_DIR}/config.toml")
|
||||
else
|
||||
# Reference the key in the env file, so the config keeps working if the
|
||||
# operator adds it later. With no key present archied disables that provider
|
||||
# and says so, rather than leaving the daemon unable to start.
|
||||
setup_args+=(-provider openai -model "${CLOUD_MODEL}" -provider-secret-ref env:OPENAI_API_KEY)
|
||||
# Unattended: no forge and keyless Ollama, so the services boot without a secret.
|
||||
setup_args=(--defaults -config "${ARCHIE_CONFIG_DIR}/config.toml" -forge-type none)
|
||||
fi
|
||||
if ! "${ARCHIE_BIN_DIR}/archied" setup "${setup_args[@]}"; then
|
||||
echo "ERROR: archied setup could not generate ${ARCHIE_CONFIG_DIR}/config.toml" >&2
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo " [SKIP] ${ARCHIE_CONFIG_DIR}/config.toml already exists (preserving user config)."
|
||||
echo " [SKIP] ${ARCHIE_CONFIG_DIR}/config.toml already exists. Re-run 'archied setup' to change it."
|
||||
fi
|
||||
|
||||
# Every service fails closed without PostgreSQL. The generated database_url
|
||||
# matches the Compose postgres service, so start it when Docker can.
|
||||
if command -v docker &>/dev/null && [ -f "${SRC_DIR}/docker-compose.yml" ]; then
|
||||
# Every service fails closed without PostgreSQL. The default database_url is
|
||||
# the Compose postgres service, so start it when the config still uses it.
|
||||
if ! grep -qF '@127.0.0.1:5432/archie' "${ARCHIE_CONFIG_DIR}/config.toml"; then
|
||||
echo " [OK] Using the PostgreSQL server named by database_url."
|
||||
elif command -v docker &>/dev/null && [ -f "${SRC_DIR}/docker-compose.yml" ]; then
|
||||
echo "==> Starting PostgreSQL 18 (docker compose up -d postgres)..."
|
||||
docker compose -f "${SRC_DIR}/docker-compose.yml" up -d postgres ||
|
||||
docker compose --env-file "${ENV_FILE}" -f "${SRC_DIR}/docker-compose.yml" up -d postgres ||
|
||||
echo " [WARN] Could not start PostgreSQL. Start it before the services, or point database_url at your own PostgreSQL 18."
|
||||
else
|
||||
echo " [WARN] Docker not found: point database_url in ${ARCHIE_CONFIG_DIR}/config.toml at a PostgreSQL 18 server before starting the services."
|
||||
@@ -576,13 +398,6 @@ echo " - Agent image: ghcr.io/samcharles93/archie-agent:latest"
|
||||
echo " - Config : ${ARCHIE_CONFIG_DIR}/config.toml"
|
||||
echo " - Secrets : ${ENV_FILE}"
|
||||
echo " - Data : ${ARCHIE_DATA_DIR}/"
|
||||
echo " - Forge Mode : ${FORGE_TYPE}"
|
||||
|
||||
if [ "${SELF_HOST_LLM}" = true ] && [ -n "${OLLAMA_MODEL}" ]; then
|
||||
echo " - LLM Model : ollama/${OLLAMA_MODEL}"
|
||||
elif [ ${#FOUND_ENV_KEYS[@]} -gt 0 ]; then
|
||||
echo " - LLM Keys : Found (${FOUND_ENV_KEYS[*]})"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Check PATH
|
||||
@@ -593,26 +408,6 @@ if [[ ":$PATH:" != *":${ARCHIE_BIN_DIR}:"* ]]; then
|
||||
echo ""
|
||||
fi
|
||||
|
||||
if [ "${SELF_HOST_LLM}" = false ] && [ ${#FOUND_ENV_KEYS[@]} -eq 0 ] && ! grep -q "=" "${ENV_FILE}" 2>/dev/null; then
|
||||
echo "============================================================"
|
||||
echo " Notice: LLM Provider Configuration Needed"
|
||||
echo "============================================================"
|
||||
echo "No LLM provider keys or local models were configured yet."
|
||||
echo "Archie requires an LLM provider to run workflows."
|
||||
echo ""
|
||||
echo "To finish configuration:"
|
||||
echo " 1. For Cloud Providers (OpenAI, Anthropic, OpenRouter, etc.):"
|
||||
echo " Add your API key to ${ENV_FILE}:"
|
||||
echo " OPENAI_API_KEY=\"sk-...\""
|
||||
echo " 2. For Local LLMs (Ollama):"
|
||||
echo " Install Ollama (https://ollama.com), run 'ollama pull llama3',"
|
||||
echo " and set [models] in ${ARCHIE_CONFIG_DIR}/config.toml to 'ollama/llama3'."
|
||||
echo ""
|
||||
echo "See documentation: ${SRC_DIR}/docs/github-token.md"
|
||||
echo "============================================================"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
if [ "${SERVICE_INSTALLED}" = true ] && [ "${AUTO_START}" = true ]; then
|
||||
echo "Service Management:"
|
||||
echo " - Units installed : archied archie-state-store archie-gateway archie-ui archie-messaging"
|
||||
@@ -620,8 +415,8 @@ if [ "${SERVICE_INSTALLED}" = true ] && [ "${AUTO_START}" = true ]; then
|
||||
echo " - Service status : systemctl --user status archied archie-state-store archie-gateway archie-ui archie-messaging"
|
||||
echo " - Restart daemon : systemctl --user restart archied"
|
||||
else
|
||||
echo "Manual Startup:"
|
||||
echo " 1. Add tokens to ${ENV_FILE} or ${ARCHIE_CONFIG_DIR}/config.toml"
|
||||
echo " 2. Run daemon : archied"
|
||||
echo "Manual Startup: start the five services as in ${SRC_DIR}/deployments/README.md"
|
||||
fi
|
||||
echo ""
|
||||
echo "Dashboard: http://127.0.0.1:8484 Change the config: archied setup"
|
||||
echo ""
|
||||
@@ -52,6 +52,7 @@ func IsSetupArgs(args []string) bool {
|
||||
// environment variable is consulted.
|
||||
type setupFlags struct {
|
||||
cfgPath string
|
||||
databaseURL string
|
||||
defaults bool
|
||||
botUser string
|
||||
operator string
|
||||
@@ -69,6 +70,7 @@ func bindSetupFlags(fs *flag.FlagSet) *setupFlags {
|
||||
f := &setupFlags{}
|
||||
fs.StringVar(&f.cfgPath, "config", configuration.DefaultConfigPath(), "path to write config.toml")
|
||||
fs.BoolVar(&f.defaults, "defaults", false, "write a known-valid unattended baseline config without prompting")
|
||||
fs.StringVar(&f.databaseURL, "database-url", "", "PostgreSQL 18 connection URL")
|
||||
fs.StringVar(&f.botUser, "bot-user", "", "forge username for archied's commits and API calls")
|
||||
fs.StringVar(&f.operator, "operator", "", "operator display name (optional)")
|
||||
fs.StringVar(&f.forgeType, "forge-type", "", "forge type: github | gitea | none")
|
||||
@@ -92,6 +94,9 @@ func (f *setupFlags) params() (setup.Params, error) {
|
||||
if f.defaults {
|
||||
params = defaultsParams()
|
||||
}
|
||||
if f.databaseURL != "" {
|
||||
params.DatabaseURL = f.databaseURL
|
||||
}
|
||||
if f.botUser != "" {
|
||||
params.BotUser = f.botUser
|
||||
}
|
||||
@@ -168,9 +173,10 @@ func existingConfig(loader *configuration.Loader, path string) ([]byte, setup.Ex
|
||||
var existing setup.ExistingValues
|
||||
if doc, err := loader.File(path); err == nil {
|
||||
existing = setup.ExistingValues{
|
||||
BotUser: doc.Config.BotUser,
|
||||
Operator: doc.Config.Chat.Operator,
|
||||
ForgeHost: doc.Config.Forge.Host,
|
||||
BotUser: doc.Config.BotUser,
|
||||
Operator: doc.Config.Chat.Operator,
|
||||
ForgeHost: doc.Config.Forge.Host,
|
||||
DatabaseURL: doc.Config.DatabaseURL,
|
||||
}
|
||||
}
|
||||
return base, existing, nil
|
||||
|
||||
@@ -4,6 +4,8 @@ package setup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@@ -32,9 +34,10 @@ type ModelDiscovery interface {
|
||||
// ExistingValues prefills prompts on a re-run. The zero value is correct
|
||||
// for a fresh install.
|
||||
type ExistingValues struct {
|
||||
BotUser string
|
||||
Operator string
|
||||
ForgeHost string
|
||||
BotUser string
|
||||
Operator string
|
||||
ForgeHost string
|
||||
DatabaseURL string
|
||||
}
|
||||
|
||||
// tableEdits groups pending edits by table before Run flattens them into
|
||||
@@ -45,12 +48,13 @@ type tableEdits = map[string]map[string]string
|
||||
// Params pre-answers setup questions; a step prompts only for unset fields.
|
||||
// Provider is a config class; Model is the bare model name.
|
||||
type Params struct {
|
||||
BotUser string
|
||||
Operator string
|
||||
ForgeType string // github | gitea | none
|
||||
ForgeHost string
|
||||
Provider string // openai | anthropic | openrouter | gemini | groq | deepseek | mistral | ollama
|
||||
Model string // bare model name; the step adds the "class/" prefix
|
||||
DatabaseURL string
|
||||
BotUser string
|
||||
Operator string
|
||||
ForgeType string // github | gitea | none
|
||||
ForgeHost string
|
||||
Provider string // openai | anthropic | openrouter | gemini | groq | deepseek | mistral | ollama
|
||||
Model string // bare model name; the step adds the "class/" prefix
|
||||
|
||||
// TelegramUserIDs non-empty configures Telegram. The reference fields name
|
||||
// already-stored secrets as engine:key; when set, the step writes the
|
||||
@@ -84,6 +88,12 @@ func RunParams(ctx context.Context, p Prompter, discovery ModelDiscovery, secret
|
||||
}
|
||||
}
|
||||
|
||||
dbURL, err := stepDatabase(ctx, p, secrets, existing.DatabaseURL, params.DatabaseURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
add(tableEdits{"": {"database_url": tomlwrite.String(dbURL)}})
|
||||
|
||||
botUser := params.BotUser
|
||||
if strings.TrimSpace(botUser) == "" {
|
||||
var err error
|
||||
@@ -132,3 +142,32 @@ func RunParams(ctx context.Context, p Prompter, discovery ModelDiscovery, secret
|
||||
|
||||
return edits, nil
|
||||
}
|
||||
|
||||
// stepDatabase returns the PostgreSQL URL. A blank answer on a fresh install
|
||||
// means the bundled Compose database with a generated password, which goes to
|
||||
// the env file as POSTGRES_PASSWORD for Compose to initialise it with.
|
||||
func stepDatabase(ctx context.Context, p Prompter, secrets SecretSink, existing, param string) (string, error) {
|
||||
if strings.TrimSpace(param) != "" {
|
||||
return param, nil
|
||||
}
|
||||
prompt := "PostgreSQL 18 URL (blank for the bundled database with a generated password): "
|
||||
if existing != "" {
|
||||
prompt = "PostgreSQL 18 URL: "
|
||||
}
|
||||
url, err := p.ReadLine(ctx, prompt, existing)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("setup: database url: %w", err)
|
||||
}
|
||||
if strings.TrimSpace(url) != "" {
|
||||
return url, nil
|
||||
}
|
||||
pw := make([]byte, 24)
|
||||
if _, err := rand.Read(pw); err != nil {
|
||||
return "", fmt.Errorf("setup: generate database password: %w", err)
|
||||
}
|
||||
password := hex.EncodeToString(pw)
|
||||
if err := secrets.Put("env", "POSTGRES_PASSWORD", password); err != nil {
|
||||
return "", fmt.Errorf("setup: store database password: %w", err)
|
||||
}
|
||||
return "postgres://archie:" + password + "@127.0.0.1:5432/archie?sslmode=disable", nil
|
||||
}
|
||||
@@ -28,10 +28,6 @@ var cloudProviders = []cloudProvider{
|
||||
{name: "Mistral", class: "mistral", apiKeyEnv: "MISTRAL_API_KEY"},
|
||||
}
|
||||
|
||||
// templateDefaultActiveProvider is the provider config.example.toml enables
|
||||
// by default. Setup replaces that table unless OpenAI is chosen with a key.
|
||||
const templateDefaultActiveProvider = "openai"
|
||||
|
||||
func stepProvider(ctx context.Context, p Prompter, discovery ModelDiscovery, secrets SecretSink, params Params) (tableEdits, string, error) {
|
||||
options := make([]string, 0, len(cloudProviders)+1)
|
||||
for _, cp := range cloudProviders {
|
||||
@@ -54,26 +50,13 @@ func stepProvider(ctx context.Context, p Prompter, discovery ModelDiscovery, sec
|
||||
}
|
||||
}
|
||||
|
||||
var edits tableEdits
|
||||
var model string
|
||||
var err error
|
||||
if choice == len(cloudProviders) {
|
||||
if params.ProviderAPIKeyRef != (config.SecretRef{}) {
|
||||
return nil, "", fmt.Errorf("setup: a provider key reference was given, but the self-hosted provider is keyless, so nothing would use it")
|
||||
}
|
||||
edits, model, err = stepSelfHostedModel(ctx, p, discovery, params.Model)
|
||||
} else {
|
||||
edits, model, err = stepCloudProvider(ctx, p, secrets, cloudProviders[choice], params.Model, params.ProviderAPIKeyRef)
|
||||
return stepSelfHostedModel(ctx, p, discovery, params.Model)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
openaiTable := "providers." + templateDefaultActiveProvider
|
||||
if _, chosenOpenAI := edits[openaiTable]; !chosenOpenAI {
|
||||
edits[openaiTable] = map[string]string{"api_key": tomlwrite.Ref("", "")}
|
||||
}
|
||||
return edits, model, nil
|
||||
return stepCloudProvider(ctx, p, secrets, cloudProviders[choice], params.Model, params.ProviderAPIKeyRef)
|
||||
}
|
||||
|
||||
// providerChoice maps a typed Params.Provider class to the same select index
|
||||
@@ -150,13 +133,6 @@ func cloudKeyEdit(ctx context.Context, p Prompter, secrets SecretSink, cp cloudP
|
||||
return "", fmt.Errorf("setup: %s api key: %w", cp.name, err)
|
||||
}
|
||||
if strings.TrimSpace(key) == "" {
|
||||
if cp.class == templateDefaultActiveProvider {
|
||||
// Skipping the key normally means "configure later" and leaves
|
||||
// api_key untouched -- but for openai specifically that would leave
|
||||
// the template's own unresolvable bws default active. See
|
||||
// templateDefaultActiveProvider.
|
||||
return tomlwrite.Ref("", ""), nil
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
if err := secrets.Put("env", cp.apiKeyEnv, key); err != nil {
|
||||
|
||||
Reference in new issue
Block a user