#!/bin/sh
# ODS — 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://ods-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 ODS
# Fetch URL: http://<ods>:\${CONTINUE_PORT:-8890}/config.yaml
#
# In your local ~/.continue/config.yaml, add:
#   remoteConfigServerUrl: http://<ods-ip>:\${CONTINUE_PORT:-8890}
#
# https://docs.continue.dev/reference

name: ODS Assistant
version: 1.0.0
schema: v1

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

  - name: Local LLM Autocomplete (ODS)
    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 "ODS Continue config ready." > "${WEBROOT}/index.html"

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