Skip to content

Commit 4d65405

Browse files
Update configure scripts
1 parent 42d94e5 commit 4d65405

14 files changed

Lines changed: 295 additions & 360 deletions

File tree

bin/aider

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
source ./variables/local.env
33

44
export VERTEXAI_PROJECT=$GCLOUD_PROJECT
5-
export VERTEXAI_LOCATION=$GCLOUD_REGION # $GCLOUD_CLAUDE_REGION
6-
echo $VERTEXAI_PROJECT $VERTEXAI_LOCATION
5+
export VERTEXAI_LOCATION=$GCLOUD_REGION
76
export OPENAI_API_KEY=$OPENAI_API_KEY
87
export DEEPSEEK_API_KEY=$DEEPSEEK_API_KEY
98
export OPENROUTER_API_KEY=$OPENROUTER_API_KEY
109
export GEMINI_API_KEY=$GEMINI_API_KEY
1110

12-
aider --model vertex_ai/gemini-2.5-pro-exp-03-25 --no-auto-accept-architect --test-cmd "npm run test && cd frontend && npm run build" --auto-test --lint-cmd "npm run lint"
11+
MODEL=vertex_ai/gemini-2.5-pro
12+
#MODEL=o3
13+
EDITOR_MODEL=vertex_ai/gemini-2.5-flash
14+
WEAK_MODEL=vertex_ai/gemini-2.5-flash
15+
16+
echo $MODEL $EDITOR_MODEL $VERTEXAI_PROJECT $VERTEXAI_LOCATION
17+
18+
aider --model $MODEL --editor-model $EDITOR_MODEL --weak-model $WEAK_MODEL --no-auto-accept-architect --test-cmd "npm run test && cd frontend && npm run build" --auto-test

bin/configure

Lines changed: 18 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
set -e # Exit immediately if a command exits with a non-zero status.
33

4+
# This script should support running in bash or zsh
5+
46
echo "Starting TypedAI configuration script..."
57
echo "---------------------------------------------------------------------"
68

@@ -26,21 +28,19 @@ update_env_variable() {
2628
echo "$var_name=$new_value" >> "$file_path"
2729
echo "Added $var_name to $file_path."
2830
fi
29-
[ -f "$temp_file" ] && rm -f "$temp_file"
31+
rm -f "$temp_file"
3032
}
3133

3234
# --- Python Setup ---
3335
echo ""
3436
echo "--- Stage 1: Python Environment Setup ---"
35-
# Source the script part. Use '|| exit 1' to ensure main script exits if part fails.
3637
source ./bin/configure_parts/python_setup || exit 1
3738
echo "Python environment setup complete."
3839
echo "---------------------------------------------------------------------"
3940

4041
# --- Node.js Setup ---
4142
echo ""
4243
echo "--- Node.js Environment Setup (using fnm) ---"
43-
# Source the script part. Use '|| exit 1' to ensure main script exits if part fails.
4444
source ./bin/configure_parts/nodejs_setup || exit 1
4545
echo "Node.js environment setup complete."
4646
echo "---------------------------------------------------------------------"
@@ -78,50 +78,15 @@ echo "---------------------------------------------------------------------"
7878
# --- Google Cloud Platform Services Configuration ---
7979
echo ""
8080
echo "--- Google Cloud Platform (GCP) Services Configuration ---"
81-
USE_GCP_SERVICES=false
82-
GCP_SETUP_SUCCESS=false
83-
84-
# Check current GCLOUD_PROJECT to suggest default for GCP usage
85-
# Source local.env carefully to get existing values without erroring on unset variables
86-
(set +e; set +u; source ./variables/local.env)
87-
CURRENT_GCLOUD_PROJECT=${GCLOUD_PROJECT:-} # Use parameter expansion for robustness
88-
89-
GCP_PROMPT_DEFAULT="n"
90-
if [ -n "$CURRENT_GCLOUD_PROJECT" ]; then # If project is already set, assume user wants GCP
91-
GCP_PROMPT_DEFAULT="y"
92-
fi
93-
94-
read -r -p "Do you plan to use any Google Cloud services (e.g., Vertex AI, Gemini, Cloud Tracing)? (Y/n, default: $GCP_PROMPT_DEFAULT) " gcp_choice
95-
gcp_choice_lower=$(echo "$gcp_choice" | tr '[:upper:]' '[:lower:]')
96-
97-
if [[ "$gcp_choice_lower" == "y" ]] || ([[ -z "$gcp_choice" ]] && [[ "$GCP_PROMPT_DEFAULT" == "y" ]]); then
98-
echo "Configuring Google Cloud services..."
99-
# Source the script part. Check its exit code.
100-
if source ./bin/configure_parts/gcp_services_setup; then
101-
update_env_variable "./variables/local.env" "TRACE_AGENT_ENABLED" "true"
102-
USE_GCP_SERVICES=true # Mark that GCP services are configured for this session
103-
GCP_SETUP_SUCCESS=true
104-
echo "GCP services configured. TRACE_AGENT_ENABLED set to true."
105-
else
106-
echo "GCP services setup failed or was exited by the user. TRACE_AGENT_ENABLED will be set to false."
107-
update_env_variable "./variables/local.env" "TRACE_AGENT_ENABLED" "false"
108-
GCP_SETUP_SUCCESS=false
109-
fi
110-
else
111-
echo "Skipping Google Cloud services configuration."
112-
update_env_variable "./variables/local.env" "TRACE_AGENT_ENABLED" "false"
113-
GCP_SETUP_SUCCESS=false
114-
fi
115-
116-
# Refresh GCLOUD_PROJECT in case gcp_services_setup set it
117-
(set +e; set +u; source ./variables/local.env)
118-
CURRENT_GCLOUD_PROJECT=${GCLOUD_PROJECT:-}
81+
# This script will ask the user if they want to set up GCP and handle the full flow.
82+
# It exports GCP_SETUP_SUCCESS and CURRENT_GCLOUD_PROJECT for use in later steps.
83+
source ./bin/configure_parts/gcp_services_setup || exit 1
84+
echo "GCP services check complete."
11985
echo "---------------------------------------------------------------------"
12086

12187
# --- Application Setup (local.env, Angular, CLI paths) ---
12288
echo ""
12389
echo "--- Application Configuration and Frontend ---"
124-
# Source the script part. Use '|| exit 1' to ensure main script exits if it fails.
12590
# This part is expected to create ./variables/local.env if it doesn't exist.
12691
source ./bin/configure_parts/app_setup || exit 1
12792
echo "Application configuration and frontend setup complete."
@@ -130,117 +95,21 @@ echo "---------------------------------------------------------------------"
13095

13196
# --- Database Setup ---
13297
echo ""
133-
echo "--- Stage 5: Database Setup ---"
134-
# Source local.env again to ensure we have the latest DATABASE_TYPE if it was set previously
135-
(set +e; set +u; source ./variables/local.env)
136-
CURRENT_DB_TYPE=${DATABASE_TYPE:-}
137-
138-
echo "Choose a database type for TypedAI."
139-
echo "Current setting in ./variables/local.env: DATABASE_TYPE=${CURRENT_DB_TYPE:-Not set}"
140-
echo ""
141-
PS3="Select database option: " # Prompt for select
142-
OPTIONS=()
143-
OPTION_ACTIONS=() # Parallel array to store actions
144-
145-
# Option 1: Firestore (only if GCP services are configured OR GCLOUD_PROJECT is already set from a previous run)
146-
# Check if GCP setup was successful in this run OR if GCLOUD_PROJECT is already present in local.env
147-
if [ "$GCP_SETUP_SUCCESS" = true ] || [ -n "$CURRENT_GCLOUD_PROJECT" ]; then
148-
OPTIONS+=("Firestore (Native Mode, via Google Cloud)")
149-
OPTION_ACTIONS+=("firestore")
150-
else
151-
echo "Note: Firestore (Native Mode) option is unavailable because GCP services are not configured or GCLOUD_PROJECT is not set."
152-
fi
153-
154-
OPTIONS+=("PostgreSQL (Requires Docker or a separate PostgreSQL instance)")
155-
OPTION_ACTIONS+=("postgres")
156-
OPTIONS+=("In-Memory (Data is lost when the application stops; for quick testing only)")
157-
OPTION_ACTIONS+=("inmemory")
158-
159-
if [ -n "$CURRENT_DB_TYPE" ]; then
160-
OPTIONS+=("Keep current setting ($CURRENT_DB_TYPE)")
161-
OPTION_ACTIONS+=("keep")
162-
fi
163-
OPTIONS+=("Exit configuration")
164-
OPTION_ACTIONS+=("exit")
165-
166-
# Use a loop to handle invalid input and re-prompt
167-
while true; do
168-
select opt in "${OPTIONS[@]}"; do
169-
choice_idx=$((REPLY - 1))
170-
ACTION=${OPTION_ACTIONS[$choice_idx]}
171-
172-
if [ -n "$ACTION" ]; then
173-
case $ACTION in
174-
firestore)
175-
echo "You selected Firestore."
176-
update_env_variable "./variables/local.env" "DATABASE_TYPE" "firestore"
177-
# Ensure GCLOUD_PROJECT is available for firestore_setup
178-
# This check is also inside firestore_setup, but good to have here too.
179-
(set +e; set +u; source ./variables/local.env) # Re-source in case it was just set
180-
if [ -z "$GCLOUD_PROJECT" ]; then
181-
echo "Error: GCLOUD_PROJECT not set. Firestore setup cannot proceed."
182-
echo "Please re-run ./bin/configure and enable GCP services with a project ID."
183-
exit 1 # Critical for Firestore
184-
fi
185-
# Source the script part. Use '|| exit 1' to ensure main script exits if part fails.
186-
source ./bin/configure_parts/firestore_setup || exit 1
187-
break 2 # Break out of select and while loop
188-
;;
189-
postgres)
190-
echo "You selected PostgreSQL."
191-
update_env_variable "./variables/local.env" "DATABASE_TYPE" "postgres"
192-
# Source the script part. Use '|| exit 1' to ensure main script exits if part fails.
193-
source ./bin/configure_parts/postgres_setup || exit 1
194-
break 2 # Break out of select and while loop
195-
;;
196-
inmemory)
197-
echo "You selected In-Memory database."
198-
update_env_variable "./variables/local.env" "DATABASE_TYPE" "memory"
199-
echo "In-Memory database selected. No further setup needed for the database itself."
200-
break 2 # Break out of select and while loop
201-
;;
202-
keep)
203-
echo "Keeping current database setting: $CURRENT_DB_TYPE."
204-
# Optionally re-run setup for current DB type if it's Firestore or Postgres
205-
if [ "$CURRENT_DB_TYPE" == "firestore" ]; then
206-
read -r -p "Re-run Firestore setup/check steps? (y/N) " rerun_fs
207-
if [[ "$rerun_fs" =~ ^[Yy]$ ]]; then
208-
# Ensure GCLOUD_PROJECT is available before re-running Firestore setup
209-
(set +e; set +u; source ./variables/local.env)
210-
if [ -z "$GCLOUD_PROJECT" ]; then
211-
echo "Error: GCLOUD_PROJECT not set. Cannot re-run Firestore setup."
212-
echo "Please ensure it's set in ./variables/local.env."
213-
else
214-
source ./bin/configure_parts/firestore_setup || echo "Warning: Re-running Firestore setup failed."
215-
fi
216-
fi
217-
elif [ "$CURRENT_DB_TYPE" == "postgres" ]; then
218-
read -r -p "Re-run PostgreSQL setup/check steps? (y/N) " rerun_pg
219-
if [[ "$rerun_pg" =~ ^[Yy]$ ]]; then source ./bin/configure_parts/postgres_setup || echo "Warning: Re-running PostgreSQL setup failed."; fi
220-
fi
221-
break 2 # Break out of select and while loop
222-
;;
223-
exit)
224-
echo "Exiting configuration as requested."
225-
exit 0
226-
;;
227-
*) echo "Invalid option $REPLY"; continue ;; # Invalid input, stay in select
228-
esac
229-
else
230-
echo "Invalid option $REPLY" # Should not happen with select, but for safety
231-
continue # Stay in select
232-
fi
233-
done
234-
done # End while true loop for select
235-
236-
echo "Database setup choice processed."
98+
echo "--- Database Setup ---"
99+
source ./bin/configure_parts/db_setup || exit 1
237100
echo "---------------------------------------------------------------------"
238101

102+
239103
echo ""
240104
echo "--- Configuration Complete ---"
241105
echo "All selected setup steps have been processed."
242106
echo "Please review any specific instructions or warnings displayed above."
243-
echo "If you configured shell environments (e.g., for fnm), you might need to source your shell config or open a new terminal."
244107
echo ""
245-
echo "Next steps: 'npm run start:local' (backend) and 'cd frontend && npm run start:local' (frontend)."
108+
echo "✅ Configuration complete."
109+
echo "To apply the environment changes, you MUST open a new terminal window or run 'source ~/.zshrc' (or ~/.bashrc)."
110+
echo ""
111+
echo "Next steps:"
112+
echo " - Backend a: 'npm run start:local'"
113+
echo " - Frontend: 'cd frontend && npm run start:local'"
246114
echo "done"
115+
exit 0

bin/configure_parts/DOCS.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Requirements for setup scripts (./bin/configure etc.)
2+
3+
# Configure script
4+
5+
`./bin/configure` is the project setup/configuration script that is run interactively by the user.
6+
7+
It should support running in bash or zsh, and if running on OSX should update both the .bashrc and .zshrc files.
8+
9+
10+
# ./bin/configure_test
11+
12+
Runs the `./bin/configure` script in a Docker container with a non-root user to test the configure scripts in a clean environment.
13+
14+
When run interactively, it will prompt the user for input.
15+
16+
Can pass `TYPEDAI_TEST_` prefixed environment variables to the script for non-interactive automated setup and testing.
17+
18+
Example:
19+
`./configure_test TYPEDAI_TEST_DB_TYPE=postgres TYPEDAI_TEST_USE_GCP=n TYPEDAI_TEST_FNM_INSTALL_CHOICE=1 TYPEDAI_TEST_PYENV_INSTALL_CHOICE=1 TYPEDAI_TEST_RG_INSTALL_CHOICE=1`
20+
21+
# ./bin/configure_parts/Dockerfile
22+
23+
This is used from configure_test to manually test the setup script in a fresh environment

bin/configure_parts/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ RUN apt-get update -y && \
99
apt-get install -y sudo git curl unzip ca-certificates gnupg lsb-release rsync \
1010
make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev \
1111
libsqlite3-dev wget llvm libncursesw5-dev xz-utils tk-dev \
12-
libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev && \
12+
libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev cmake && \
1313
apt-get clean && \
1414
rm -rf /var/lib/apt/lists/*
1515

bin/configure_parts/app_setup

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/bin/bash
2+
# Source the helper function
3+
source ./bin/configure_parts/shell_helpers.sh
24
# Application Configuration and Frontend Setup ---------------------------------
35
echo "--- Starting Application Configuration and Frontend Setup ---"
46

@@ -37,13 +39,30 @@ if [ -z "$CURRENT_SINGLE_USER_EMAIL" ]; then
3739
echo "Attempting to set SINGLE_USER_EMAIL from gcloud config..."
3840
# Use --quiet to suppress output, check exit code
3941
GCLOUD_ACCOUNT=$(gcloud config get-value account --quiet 2>/dev/null)
42+
# There could be version update output. If there is more than one line, take the first line
43+
GCLOUD_ACCOUNT=$(echo "$GCLOUD_ACCOUNT" | head -n 1)
4044
# Basic check if GCLOUD_ACCOUNT looks like an email address
4145
if [[ "$GCLOUD_ACCOUNT" =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ ]]; then
4246
_update_app_env_var "./variables/local.env" "SINGLE_USER_EMAIL" "${GCLOUD_ACCOUNT}"
4347
echo "Set SINGLE_USER_EMAIL to ${GCLOUD_ACCOUNT} in ./variables/local.env"
4448
else
4549
echo "Could not automatically determine SINGLE_USER_EMAIL from gcloud config."
46-
echo "Please manually update SINGLE_USER_EMAIL in ./variables/local.env"
50+
user_email=""
51+
if [ -n "$TYPEDAI_TEST_SINGLE_USER_EMAIL" ]; then
52+
echo "Using TYPEDAI_TEST_SINGLE_USER_EMAIL. Value: $TYPEDAI_TEST_SINGLE_USER_EMAIL"
53+
user_email="$TYPEDAI_TEST_SINGLE_USER_EMAIL"
54+
else
55+
read -r -p "Please enter the email address for the single user account: " user_email
56+
fi
57+
58+
if [[ "$user_email" =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ ]]; then
59+
_update_app_env_var "./variables/local.env" "SINGLE_USER_EMAIL" "$user_email"
60+
echo "Set SINGLE_USER_EMAIL to $user_email in ./variables/local.env"
61+
else
62+
echo "Warning: Invalid email address provided for SINGLE_USER_EMAIL. Value was: \"$user_email\""
63+
echo "Please manually update SINGLE_USER_EMAIL in ./variables/local.env"
64+
exit 1
65+
fi
4766
fi
4867
else
4968
echo "SINGLE_USER_EMAIL is already set in ./variables/local.env: $CURRENT_SINGLE_USER_EMAIL"
@@ -73,30 +92,9 @@ fi
7392
# CLI setup -------------
7493

7594
echo "Setting up CLI environment variables in shell profiles..."
76-
# Setup for bash
77-
if [ -f ~/.bashrc ]; then
78-
if ! grep -q "TYPEDAI_HOME" ~/.bashrc; then
79-
echo "# TypedAI CLI environment" >> ~/.bashrc
80-
echo "export TYPEDAI_HOME=$(pwd)" >> ~/.bashrc
81-
echo "export PATH=\$TYPEDAI_HOME/bin/path:\$PATH" >> ~/.bashrc
82-
echo "Added TypedAI CLI environment variables to ~/.bashrc"
83-
else
84-
echo "TypedAI CLI environment variables already present in ~/.bashrc"
85-
fi
86-
fi
87-
88-
# Setup for zsh
89-
if [ -f ~/.zshrc ]; then
90-
if ! grep -q "TYPEDAI_HOME" ~/.zshrc; then
91-
echo "# TypedAI CLI environment" >> ~/.zshrc
92-
echo "export TYPEDAI_HOME=$(pwd)" >> ~/.zshrc
93-
echo "export PATH=\$TYPEDAI_HOME/bin/path:\$PATH" >> ~/.zshrc
94-
echo "Added TypedAI CLI environment variables to ~/.zshrc"
95-
else
96-
echo "TypedAI CLI environment variables already present in ~/.zshrc"
97-
fi
98-
fi
95+
comment="# TypedAI CLI environment"
96+
content="export TYPEDAI_HOME=$(pwd)\nexport PATH=\$TYPEDAI_HOME/bin/path:\$PATH"
97+
update_shell_profiles "$comment" "$content"
9998

10099
echo "Application Configuration and Frontend Setup complete."
101-
# Exit with 0 to indicate success of this part
102100
exit 0

bin/configure_parts/db_setup

Whitespace-only changes.

0 commit comments

Comments
 (0)