diff --git a/.env.example b/.env.example index d48c72e..477384a 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,6 @@ # Server Configuration NODE_ENV=development -PORT=3000 +PORT=7123 DEBUG=false LOG_LEVEL=info MCP_SERVER=http://localhost:3000 @@ -23,7 +23,7 @@ RATE_LIMIT_REGULAR=100 RATE_LIMIT_WEBSOCKET=1000 # CORS Configuration -CORS_ORIGINS=http://localhost:3000,http://localhost:8123 +CORS_ORIGINS=http://localhost:3000,http://localhost:8123,http://homeassistant.local:8123 CORS_METHODS=GET,POST,PUT,DELETE,OPTIONS CORS_ALLOWED_HEADERS=Content-Type,Authorization,X-Requested-With CORS_EXPOSED_HEADERS= @@ -48,9 +48,9 @@ MAX_RETRIES=3 ANALYSIS_TIMEOUT=30000 # Speech Features Configuration -ENABLE_SPEECH_FEATURES=true -ENABLE_WAKE_WORD=true -ENABLE_SPEECH_TO_TEXT=true +ENABLE_SPEECH_FEATURES=false +ENABLE_WAKE_WORD=false +ENABLE_SPEECH_TO_TEXT=false WHISPER_MODEL_PATH=/models WHISPER_MODEL_TYPE=base @@ -78,9 +78,9 @@ SSE_RECONNECT_TIMEOUT=5000 HOT_RELOAD=true # Test Configuration (only needed for running tests) -TEST_HASS_HOST=http://localhost:8123 +TEST_HASS_HOST=http://homeassistant.local:8123 TEST_HASS_TOKEN=test_token -TEST_HASS_SOCKET_URL=ws://localhost:8123/api/websocket +TEST_HASS_SOCKET_URL=ws://homeassistant.local:8123/api/websocket TEST_PORT=3001 # Version diff --git a/Dockerfile b/Dockerfile index f602ca0..2029dd0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,20 +7,13 @@ WORKDIR /app # Install bun with the latest version RUN npm install -g bun@1.0.35 -# Install only the minimal dependencies needed and clean up in the same layer +# Install Python and other dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ - ca-certificates \ - curl \ - pulseaudio \ - alsa-utils \ - python3-full \ + python3 \ python3-pip \ - python3-dev \ python3-venv \ - portaudio19-dev \ - && rm -rf /var/lib/apt/lists/* \ - && apt-get clean \ - && rm -rf /var/cache/apt/* + build-essential \ + && rm -rf /var/lib/apt/lists/* # Create and activate virtual environment RUN python3 -m venv /opt/venv @@ -31,22 +24,10 @@ ENV VIRTUAL_ENV="/opt/venv" RUN /opt/venv/bin/python -m pip install --upgrade pip # Install Python packages in virtual environment -RUN /opt/venv/bin/python -m pip install --no-cache-dir \ - numpy \ - sounddevice \ - openwakeword \ - faster-whisper \ - requests +RUN /opt/venv/bin/python -m pip install --no-cache-dir numpy scipy -# Set build-time environment variables with increased memory -ENV NODE_ENV=production \ - NODE_OPTIONS="--max-old-space-size=4096" \ - BUN_INSTALL_CACHE=1 - -# Copy only package files first +# Copy package.json and install dependencies COPY package.json ./ - -# Install dependencies with more stable approach RUN bun install --frozen-lockfile || bun install # Copy source files and build @@ -60,20 +41,15 @@ FROM node:20-slim as runner # Install bun in production image with the latest version RUN npm install -g bun@1.0.35 -# Install runtime dependencies +# Install system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ - pulseaudio \ - alsa-utils \ - libasound2 \ - libasound2-plugins \ - python3-full \ + curl \ + python3 \ python3-pip \ - python3-dev \ python3-venv \ - portaudio19-dev \ - && rm -rf /var/lib/apt/lists/* \ - && apt-get clean \ - && rm -rf /var/cache/apt/* + alsa-utils \ + pulseaudio \ + && rm -rf /var/lib/apt/lists/* # Configure ALSA COPY docker/speech/asound.conf /etc/asound.conf @@ -87,19 +63,7 @@ ENV VIRTUAL_ENV="/opt/venv" RUN /opt/venv/bin/python -m pip install --upgrade pip # Install Python packages in virtual environment -RUN /opt/venv/bin/python -m pip install --no-cache-dir \ - numpy \ - sounddevice \ - openwakeword \ - faster-whisper \ - requests - -# Set Python path to use virtual environment -ENV PYTHONPATH="/opt/venv/lib/python3.11/site-packages:$PYTHONPATH" - -# Set production environment variables -ENV NODE_ENV=production \ - NODE_OPTIONS="--max-old-space-size=1024" +RUN /opt/venv/bin/python -m pip install --no-cache-dir numpy scipy # Create a non-root user and add to audio group RUN addgroup --system --gid 1001 nodejs && \ @@ -135,4 +99,4 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ EXPOSE ${PORT:-4000} # Start the application with audio setup -CMD ["/bin/bash", "-c", "/app/docker/speech/setup-audio.sh & bun --smol run start"] \ No newline at end of file +CMD ["/bin/bash", "-c", "/app/docker/speech/setup-audio.sh || echo 'Audio setup failed, continuing anyway' && bun --smol run fix-env.js"] \ No newline at end of file diff --git a/extra/ha-analyzer-cli.ts b/extra/ha-analyzer-cli.ts index 6e8923b..96af8fe 100644 --- a/extra/ha-analyzer-cli.ts +++ b/extra/ha-analyzer-cli.ts @@ -23,7 +23,7 @@ if (!hassToken) { } // MCP Server configuration -const MCP_SERVER = process.env.MCP_SERVER || 'http://localhost:3000'; +const MCP_SERVER = 'http://localhost:3000'; interface McpTool { name: string; diff --git a/fix-env.js b/fix-env.js new file mode 100644 index 0000000..ec7c468 --- /dev/null +++ b/fix-env.js @@ -0,0 +1,9 @@ +// This script fixes the NODE_ENV environment variable before any imports +console.log('Setting NODE_ENV to "development" before imports'); +process.env.NODE_ENV = "development"; + +// Add more debugging +console.log(`NODE_ENV is now set to: "${process.env.NODE_ENV}"`); + +// Import the main application +import './dist/index.js'; diff --git a/smithery.yaml b/smithery.yaml index feb2dbe..8022744 100644 --- a/smithery.yaml +++ b/smithery.yaml @@ -11,10 +11,21 @@ startCommand: hassToken: type: string description: The token for connecting to Home Assistant API. - port: + hassHost: + type: string + default: http://homeassistant.local:8123 + description: The host for connecting to Home Assistant API. + hassSocketUrl: + type: string + default: ws://homeassistant.local:8123 + description: The socket URL for connecting to Home Assistant API. + mcp-port: type: number - default: 4000 + default: 7123 description: The port on which the MCP server will run. + debug: + type: boolean + description: The debug mode for the MCP server. commandFunction: # A function that produces the CLI command to start the MCP on stdio. |- @@ -23,7 +34,10 @@ startCommand: args: ['--smol', 'run', 'start'], env: { HASS_TOKEN: config.hassToken, - PORT: config.port.toString() + HASS_HOST: config.hassHost || process.env.HASS_HOST, + HASS_SOCKET_URL: config.hassSocketUrl || process.env.HASS_SOCKET_URL, + PORT: config.port.toString(), + DEBUG: config.debug !== undefined ? config.debug.toString() : process.env.DEBUG || 'false' } }) diff --git a/src/config/app.config.ts b/src/config/app.config.ts index 1a1ef7d..12766f6 100644 --- a/src/config/app.config.ts +++ b/src/config/app.config.ts @@ -85,10 +85,16 @@ for (const envVar of requiredEnvVars) { } } +// Fix NODE_ENV if it's set to "1" +if (process.env.NODE_ENV === "1") { + console.log('Fixing NODE_ENV from "1" to "development"'); + process.env.NODE_ENV = "development"; +} + // Load and validate configuration export const APP_CONFIG = AppConfigSchema.parse({ PORT: process.env.PORT || 4000, - NODE_ENV: process.env.NODE_ENV || "development", + NODE_ENV: process.env.NODE_ENV, HASS_HOST: process.env.HASS_HOST || "http://192.168.178.63:8123", HASS_TOKEN: process.env.HASS_TOKEN, JWT_SECRET: process.env.JWT_SECRET || "your-secret-key", diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..9e859c7 --- /dev/null +++ b/start.sh @@ -0,0 +1,3 @@ +#!/bin/bash +export NODE_ENV=development +exec bun --smol run start