#!/bin/sh
# Dream Server — Continue config generator
# Runs as part of nginx's docker-entrypoint.d/ on container start.
# Writes a Continue config.yaml into the webroot with LLM_API_URL injected.

set -e

WEBROOT="/usr/share/nginx/html"
LLM_API_URL="${LLM_API_URL:-http://dream-llama-server:8080}"

mkdir -p "${WEBROOT}"

# Write the Continue config.yaml that IDE clients will fetch
cat > "${WEBROOT}/config.yaml" <<EOF
# Continue config — auto-generated by Dream Server
# Fetch URL: http://<dream-server>:\${CONTINUE_PORT:-8890}/config.yaml
#
# In your local ~/.continue/config.yaml, add:
#   remoteConfigServerUrl: http://<dream-server-ip>:\${CONTINUE_PORT:-8890}
#
# https://docs.continue.dev/reference

name: Dream Server Assistant
version: 1.0.0
schema: v1

models:
  - name: Local LLM (Dream Server)
    provider: openai
    apiBase: ${LLM_API_URL}/v1
    model: AUTODETECT
    roles:
      - chat
      - edit
      - apply

  - name: Local LLM Autocomplete (Dream Server)
    provider: openai
    apiBase: ${LLM_API_URL}/v1
    model: AUTODETECT
    roles:
      - autocomplete

context:
  - provider: code
  - provider: docs
  - provider: diff
  - provider: terminal
  - provider: problems
  - provider: folder
  - provider: codebase
EOF

# Write a minimal health sentinel (nginx serves /health via config)
echo "Dream Server Continue config ready." > "${WEBROOT}/index.html"

echo "[continue-init] config.yaml written to ${WEBROOT} (LLM_API_URL=${LLM_API_URL})"
