67 lines
1.8 KiB
Bash
67 lines
1.8 KiB
Bash
#!/usr/bin/env bash
|
|
# common.sh — Shared config for memory scripts
|
|
# Source this: . "$(dirname "$0")/common.sh"
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
|
|
# shellcheck source=scripts/date-format.sh
|
|
. "$PROJECT_DIR/scripts/date-format.sh"
|
|
|
|
# Load .env
|
|
if [ -f "$PROJECT_DIR/.env" ]; then
|
|
set -a
|
|
# shellcheck disable=SC1091
|
|
. "$PROJECT_DIR/.env"
|
|
set +a
|
|
fi
|
|
|
|
# Database connection (uses .pgpass for password)
|
|
DB_HOST="${WARDEN_SUBNET_BASE:-10.0.0}.2"
|
|
DB_PORT="5432"
|
|
DB_NAME="ai_brain"
|
|
DB_USER="clawdie_brain"
|
|
|
|
# Embedding config
|
|
EMBED_MODEL="openai/text-embedding-3-large"
|
|
EMBED_DIMENSIONS=1536
|
|
EMBED_PROVIDER="openrouter"
|
|
EMBED_API_URL="https://openrouter.ai/api/v1/embeddings"
|
|
|
|
# Chunk config
|
|
CHUNK_MAX_CHARS=500
|
|
PG_SLOVENIAN_MONTHS="ARRAY['jan','feb','mar','apr','maj','jun','jul','avg','sep','okt','nov','dec']"
|
|
|
|
# psql wrapper — safe, no interpolation in SQL
|
|
pg() {
|
|
psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" \
|
|
--no-align --tuples-only --quiet "$@"
|
|
}
|
|
|
|
# psql with headers (for display)
|
|
pg_pretty() {
|
|
psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" "$@"
|
|
}
|
|
|
|
# Check dependencies
|
|
require_cmd() {
|
|
command -v "$1" >/dev/null 2>&1 || { echo "Error: $1 not found" >&2; exit 1; }
|
|
}
|
|
|
|
require_cmd psql
|
|
require_cmd curl
|
|
require_cmd python3
|
|
|
|
pg_display_date_expr() {
|
|
local column="${1:-created_at}"
|
|
printf "(to_char(%s, 'DD') || '.' || (%s)[extract(month from %s)::int] || '.' || to_char(%s, 'YYYY'))" \
|
|
"$column" "$PG_SLOVENIAN_MONTHS" "$column" "$column"
|
|
}
|
|
|
|
pg_display_datetime_expr() {
|
|
local column="${1:-created_at}"
|
|
printf "(%s || ' ' || to_char(%s, 'HH24:MI'))" \
|
|
"$(pg_display_date_expr "$column")" "$column"
|
|
}
|