#!/usr/bin/env bash set -euo pipefail ROOT_OVERRIDE="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" export ROOT_OVERRIDE # shellcheck disable=SC1091 source "${ROOT_OVERRIDE}/scripts/common.sh" init_log update-native acquire_lock jr-sql-ai-native-model.lock print_header "update-native: START" load_env need_cmd curl need_cmd python need_cmd "$OLLAMA_BIN" check_for_legacy_docker_ollama [[ -n "$BASE_MODEL" ]] || fail "BASE_MODEL is empty" 60 log "update-native: ensuring local Ollama runtime is ready at ${OLLAMA_URL}" ensure_ollama_ready "$OLLAMA_API_MAX_WAIT" "$OLLAMA_API_START_WAIT" || fail "Ollama API not reachable at ${OLLAMA_URL}" 61 ok "update-native: Ollama API reachable" pull_configured_models tmp="$(mktemp)" trap 'rm -f "$tmp"' EXIT render_modelfile "$tmp" log "update-native: rebuilding expert model ${EXPERT_MODEL}" ollama_cmd create "${EXPERT_MODEL}" -f "$tmp" verify_models_available ok "update-native: base and expert models are available" warmup_sqlai print_footer "update-native: END status=OK log=${LOG_FILE}"