diff --git a/bin/monadic_dev b/bin/monadic_dev index 3feaf54c..4ffa1e00 100755 --- a/bin/monadic_dev +++ b/bin/monadic_dev @@ -10,7 +10,7 @@ if [ "$1" == "start" ]; then echo "Monadic script executed with 'start' argument 🚀" echo "Run 'monadic_dev stop' to stop the server" elif [ "$1" == "debug" ]; then - ./bin/monadic_dev start --log + ./bin/monadic_dev start echo "Monadic script executed with 'debug' argument 🛑" elif [ "$1" == "stop" ]; then ./bin/monadic_dev stop diff --git a/docker/services/ruby/Dockerfile b/docker/services/ruby/Dockerfile index d924676a..16dc9de6 100644 --- a/docker/services/ruby/Dockerfile +++ b/docker/services/ruby/Dockerfile @@ -69,3 +69,9 @@ RUN chmod +x $WORKSPACE/scripts/* ENV PATH="$WORKSPACE/scripts:/usr/local/bundle/bin:${PATH}" COPY Dockerfile $WORKSPACE/Dockerfile + +# Copy the entrypoint script into the container +COPY entrypoint.sh /usr/local/bin/entrypoint.sh + +# Give execute permission to the script +RUN chmod +x /usr/local/bin/entrypoint.sh diff --git a/docker/services/ruby/apps/content_reader/content_reader_app.rb b/docker/services/ruby/apps/content_reader/content_reader_app.rb index 5b0a4988..e506b929 100644 --- a/docker/services/ruby/apps/content_reader/content_reader_app.rb +++ b/docker/services/ruby/apps/content_reader/content_reader_app.rb @@ -41,7 +41,6 @@ class ContentReader < MonadicApp initiate_from_assistant: true, mathjax: true, image: true, - audio_video: true, tools: [ { type: "function", diff --git a/docker/services/ruby/apps/language_practice/language_practice_app.rb b/docker/services/ruby/apps/language_practice/language_practice_app.rb index b51655e1..dbce1fc5 100644 --- a/docker/services/ruby/apps/language_practice/language_practice_app.rb +++ b/docker/services/ruby/apps/language_practice/language_practice_app.rb @@ -26,7 +26,6 @@ class LanguagePractice < MonadicApp description: description, icon: icon, initiate_from_assistant: true, - speech_rate: 1.0, image: true, pdf: false } diff --git a/docker/services/ruby/apps/language_practice_plus/language_practice_plus_app.rb b/docker/services/ruby/apps/language_practice_plus/language_practice_plus_app.rb index 6006c386..cabb7032 100644 --- a/docker/services/ruby/apps/language_practice_plus/language_practice_plus_app.rb +++ b/docker/services/ruby/apps/language_practice_plus/language_practice_plus_app.rb @@ -35,7 +35,6 @@ class LanguagePracticePlus < MonadicApp icon: icon, initiate_from_assistant: true, image: true, - pdf: false, monadic: true, response_format: { type: "json_schema", diff --git a/docker/services/ruby/apps/speech_draft_helper/speech_draft_helper_app.rb b/docker/services/ruby/apps/speech_draft_helper/speech_draft_helper_app.rb index 3ba33aa1..c12f74e3 100644 --- a/docker/services/ruby/apps/speech_draft_helper/speech_draft_helper_app.rb +++ b/docker/services/ruby/apps/speech_draft_helper/speech_draft_helper_app.rb @@ -44,7 +44,6 @@ class SpeechDraftHelper < MonadicApp icon: icon, initiate_from_assistant: true, image: true, - audio_video: true, tools: [ { type: "function", diff --git a/docker/services/ruby/apps/talk_to_mistral/chat_with_mistral_app.rb b/docker/services/ruby/apps/talk_to_mistral/chat_with_mistral_app.rb index 4fa4882c..4e08b749 100644 --- a/docker/services/ruby/apps/talk_to_mistral/chat_with_mistral_app.rb +++ b/docker/services/ruby/apps/talk_to_mistral/chat_with_mistral_app.rb @@ -36,7 +36,6 @@ class ChatWithMistral < MonadicApp initiate_from_assistant: false, pdf: false, image: false, - toggle: false, models: MistralHelper.list_models, model: "mistral-large-latest" } diff --git a/docker/services/ruby/apps/talk_to_mistral/code_with_mistral_app.rb b/docker/services/ruby/apps/talk_to_mistral/code_with_mistral_app.rb index 4a7da219..0c8b24a2 100644 --- a/docker/services/ruby/apps/talk_to_mistral/code_with_mistral_app.rb +++ b/docker/services/ruby/apps/talk_to_mistral/code_with_mistral_app.rb @@ -175,7 +175,6 @@ class CodeWithMistral < MonadicApp initiate_from_assistant: false, pdf: false, image: false, - toggle: false, models: ["mistral-large-latest"], model: "mistral-large-latest", tools: [ diff --git a/docker/services/ruby/bin/monadic_dev b/docker/services/ruby/bin/monadic_dev index 6667bda3..43f423ca 100755 --- a/docker/services/ruby/bin/monadic_dev +++ b/docker/services/ruby/bin/monadic_dev @@ -5,7 +5,7 @@ require "optimist" require_relative "../lib/monadic/version" -# change current directory to the parent directory of the directory containing this file +# Change current directory to the parent directory of the directory containing this file Dir.chdir(File.expand_path(File.join(__dir__, ".."))) DEFAULT_PORT = 4567 @@ -66,11 +66,24 @@ def start_server(opts) else cmd = "thin start -R #{DOCKER_HOME}/ruby/config.ru -p #{opts[:port] || DEFAULT_PORT} --pid #{PID_FILE}" cmd += " --daemonize" if opts[:daemonize] - cmd += " --log thin.log" if opts[:log] - if system(cmd) + + # Capture the command output + if opts[:daemonize] + output = `#{cmd} 2>&1` + else + output = `#{cmd}` + end + success = $?.success? + + if success puts "Server started on port #{opts[:port] || DEFAULT_PORT}" else puts "Server failed to start" + # Save detailed error log to the specified directory on the host + File.open(File.join(DATA_DIR, "error.log"), "a") do |file| + file.puts("Failed to start server at #{Time.now}") + file.puts(output) # Write the detailed error output + end end end end @@ -128,7 +141,7 @@ def export_document_db pg_dump monadic | gzip > "#{DATA_DIR}/monadic.gz" SHELL - # run command and get the result with error reporting + # Run command and get the result with error reporting res = system(command) if res diff --git a/docker/services/ruby/compose.yml b/docker/services/ruby/compose.yml index 63779ca5..457c0dcf 100644 --- a/docker/services/ruby/compose.yml +++ b/docker/services/ruby/compose.yml @@ -18,7 +18,7 @@ services: restart: always stdin_open: true tty: true - command: ["thin", "start", "-R", "config.ru", "-p", "4567", "-e", "development"] + command: ["sh", "/usr/local/bin/entrypoint.sh"] networks: - monadic-chat-network healthcheck: @@ -28,4 +28,3 @@ services: depends_on: pgvector_service: condition: service_healthy - diff --git a/docker/services/ruby/entrypoint.sh b/docker/services/ruby/entrypoint.sh new file mode 100644 index 00000000..1cc12cc2 --- /dev/null +++ b/docker/services/ruby/entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +# Attempt to start the thin server and capture any errors +thin start -R config.ru -p 4567 -e development > /monadic/data/error.log 2>&1 + +# Check if the thin server started successfully +if [ $? -ne 0 ]; then + echo "Failed to start thin server at $(date)" >> /monadic/data/error.log +fi + +# Keep the container running +tail -f /dev/null diff --git a/docker/services/ruby/lib/monadic.rb b/docker/services/ruby/lib/monadic.rb index 6dae6b3f..8d5b97de 100644 --- a/docker/services/ruby/lib/monadic.rb +++ b/docker/services/ruby/lib/monadic.rb @@ -111,6 +111,23 @@ def init_apps app = a.new app.settings = ActiveSupport::HashWithIndifferentAccess.new(a.instance_variable_get(:@settings)) + app.settings["description"] ||= "" + if !app.settings["initial_prompt"] + app.settings["initial_prompt"] = "You are an AI assistant but the initial prompt is missing. Tell the user they should provide a prompt." + app.settings["description"] << "

The initial prompt is missing.

" + end + if !app.settings["description"] + app.settings["description"] << "

The description is missing.

" + end + if !app.settings["icon"] + app.settings["icon"] = "" + app.settings["description"] << "

The icon is missing.

" + end + if !app.settings["app_name"] + app.settings["app_name"] = "User App (#{SecureRandom.hex(4)})" + app.settings["description"] << "

The app name is missing.

" + end + next if app.settings["disabled"] app_name = app.settings["app_name"] diff --git a/main.js b/main.js index 10d63460..a821e69d 100644 --- a/main.js +++ b/main.js @@ -349,7 +349,7 @@ function checkForUpdates() { type: 'info', buttons: ['OK'], title: 'Up to Date', - message: `You are already using the latest version (${latestVersion}) of the app.`, + message: `You are already using the latest version of the app.`, icon: path.join(iconDir, 'monadic-chat.png') }); } @@ -652,7 +652,7 @@ function toUnixPath(p) { } // Fetch a URL with retries and a delay between attempts -function fetchWithRetry(url, options = {}, retries = 60, delay = 1000, timeout = 20000) { +function fetchWithRetry(url, options = {}, retries = 30, delay = 1000, timeout = 20000) { const attemptFetch = async (attempt) => { try { const controller = new AbortController(); @@ -672,6 +672,8 @@ function fetchWithRetry(url, options = {}, retries = 60, delay = 1000, timeout = console.log(`Retrying in ${delay}ms . . .`); await new Promise(resolve => setTimeout(resolve, delay)); return attemptFetch(attempt + 1); + } else { + console.log(`Failed to connect to server after ${retries} attempts. Please check the error log in the shared folder.`); } throw error; }