diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..2f8f89bc3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,26 @@ +# Ignore Git and GitHub files +.git +.github/ + +# Ignore Husky configuration files +.husky/ + +# Ignore documentation and metadata files +CONTRIBUTING.md +LICENSE +README.md + +# Ignore environment examples and sensitive info +.env +*.local +*.example + +# Ignore node modules, logs and cache files +**/*.log +**/node_modules +**/dist +**/build +**/.cache +logs +dist-ssr +.DS_Store diff --git a/.env.example b/.env.example index 1eefa239e..774950885 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,4 @@ -# Rename this file to .env.local once you have filled in the below environment variables! +# Rename this file to .env once you have filled in the below environment variables! # Get your GROQ API Key here - # https://console.groq.com/keys diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ad3b1951a..dfba642ca 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,11 +3,13 @@ First off, thank you for considering contributing to Bolt.new! This fork aims to expand the capabilities of the original project by integrating multiple LLM providers and enhancing functionality. Every contribution helps make Bolt.new a better tool for developers worldwide. ## 📋 Table of Contents + - [Code of Conduct](#code-of-conduct) - [How Can I Contribute?](#how-can-i-contribute) - [Pull Request Guidelines](#pull-request-guidelines) - [Coding Standards](#coding-standards) - [Development Setup](#development-setup) +- [Deploymnt with Docker](#docker-deployment-documentation) - [Project Structure](#project-structure) ## Code of Conduct @@ -17,29 +19,34 @@ This project and everyone participating in it is governed by our Code of Conduct ## How Can I Contribute? ### 🐞 Reporting Bugs and Feature Requests + - Check the issue tracker to avoid duplicates - Use the issue templates when available - Include as much relevant information as possible - For bugs, add steps to reproduce the issue ### 🔧 Code Contributions + 1. Fork the repository 2. Create a new branch for your feature/fix 3. Write your code 4. Submit a pull request ### ✨ Becoming a Core Contributor + We're looking for dedicated contributors to help maintain and grow this project. If you're interested in becoming a core contributor, please fill out our [Contributor Application Form](https://forms.gle/TBSteXSDCtBDwr5m7). ## Pull Request Guidelines ### 📝 PR Checklist + - [ ] Branch from the main branch - [ ] Update documentation if needed - [ ] Manually verify all new functionality works as expected - [ ] Keep PRs focused and atomic ### 👀 Review Process + 1. Manually test the changes 2. At least one maintainer review required 3. Address all review comments @@ -48,6 +55,7 @@ We're looking for dedicated contributors to help maintain and grow this project. ## Coding Standards ### 💻 General Guidelines + - Follow existing code style - Comment complex logic - Keep functions focused and small @@ -56,12 +64,15 @@ We're looking for dedicated contributors to help maintain and grow this project. ## Development Setup ### 🔄 Initial Setup + 1. Clone the repository: + ```bash git clone https://github.com/coleam00/bolt.new-any-llm.git ``` 2. Install dependencies: + ```bash pnpm install ``` @@ -69,30 +80,138 @@ pnpm install 3. Set up environment variables: - Rename `.env.example` to `.env.local` - Add your LLM API keys (only set the ones you plan to use): + ```bash GROQ_API_KEY=XXX OPENAI_API_KEY=XXX ANTHROPIC_API_KEY=XXX ... ``` - - Optionally set debug level: + +- Optionally set debug level: + ```bash VITE_LOG_LEVEL=debug ``` + **Important**: Never commit your `.env.local` file to version control. It's already included in .gitignore. ### 🚀 Running the Development Server + ```bash pnpm run dev ``` **Note**: You will need Google Chrome Canary to run this locally if you use Chrome! It's an easy install and a good browser for web development anyway. -## Questions? +## Testing + +Run the test suite with: + +```bash +pnpm test +``` + +## Deployment + +To deploy the application to Cloudflare Pages: + +```bash +pnpm run deploy +``` + +Make sure you have the necessary permissions and Wrangler is correctly configured for your Cloudflare account. + +# Docker Deployment Documentation + +This guide outlines various methods for building and deploying the application using Docker. + +## Build Methods + +### 1. Using Helper Scripts + +NPM scripts are provided for convenient building: + +```bash +# Development build +npm run dockerbuild + +# Production build +npm run dockerbuild:prod +``` + +### 2. Direct Docker Build Commands + +You can use Docker's target feature to specify the build environment: + +```bash +# Development build +docker build . --target bolt-ai-development + +# Production build +docker build . --target bolt-ai-production +``` + +### 3. Docker Compose with Profiles + +Use Docker Compose profiles to manage different environments: + +```bash +# Development environment +docker-compose --profile development up + +# Production environment +docker-compose --profile production up +``` + +## Running the Application + +After building using any of the methods above, run the container with: + +```bash +# Development +docker run -p 5173:5173 --env-file .env.local bolt-ai:development + +# Production +docker run -p 5173:5173 --env-file .env.local bolt-ai:production +``` + +## Deployment with Coolify + +[Coolify](https://github.com/coollabsio/coolify) provides a straightforward deployment process: + +1. Import your Git repository as a new project +2. Select your target environment (development/production) +3. Choose "Docker Compose" as the Build Pack +4. Configure deployment domains +5. Set the custom start command: + ```bash + docker compose --profile production up + ``` +6. Configure environment variables + - Add necessary AI API keys + - Adjust other environment variables as needed +7. Deploy the application + +## VS Code Integration + +The `docker-compose.yaml` configuration is compatible with VS Code dev containers: + +1. Open the command palette in VS Code +2. Select the dev container configuration +3. Choose the "development" profile from the context menu + +## Environment Files + +Ensure you have the appropriate `.env.local` file configured before running the containers. This file should contain: + +- API keys +- Environment-specific configurations +- Other required environment variables -For any questions about contributing, please: -1. Check existing documentation -2. Search through issues -3. Create a new issue with the question label +## Notes -Thank you for contributing to Bolt.new! 🚀 \ No newline at end of file +- Port 5173 is exposed and mapped for both development and production environments +- Environment variables are loaded from `.env.local` +- Different profiles (development/production) can be used for different deployment scenarios +- The configuration supports both local development and production deployment diff --git a/Dockerfile b/Dockerfile index 999236f36..3b5a74cde 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,31 +1,67 @@ -# Use an official Node.js runtime as the base image -FROM node:20.15.1 +ARG BASE=node:20.18.0 +FROM ${BASE} AS base -# Set the working directory in the container WORKDIR /app -# Install pnpm -RUN npm install -g pnpm@9.4.0 +# Install dependencies (this step is cached as long as the dependencies don't change) +COPY package.json pnpm-lock.yaml ./ -# Copy package.json and pnpm-lock.yaml (if available) -COPY package.json pnpm-lock.yaml* ./ +RUN corepack enable pnpm && pnpm install -# Install dependencies -RUN pnpm install --frozen-lockfile - -# Copy the rest of the application code +# Copy the rest of your app's source code COPY . . -# Build the application -RUN pnpm run build +# Expose the port the app runs on +EXPOSE 5173 + +# Production image +FROM base AS bolt-ai-production + +# Define environment variables with default values or let them be overridden +ARG GROQ_API_KEY +ARG OPENAI_API_KEY +ARG ANTHROPIC_API_KEY +ARG OPEN_ROUTER_API_KEY +ARG GOOGLE_GENERATIVE_AI_API_KEY +ARG OLLAMA_API_BASE_URL +ARG VITE_LOG_LEVEL=debug + +ENV WRANGLER_SEND_METRICS=false \ + GROQ_API_KEY=${GROQ_API_KEY} \ + OPENAI_API_KEY=${OPENAI_API_KEY} \ + ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY} \ + OPEN_ROUTER_API_KEY=${OPEN_ROUTER_API_KEY} \ + GOOGLE_GENERATIVE_AI_API_KEY=${GOOGLE_GENERATIVE_AI_API_KEY} \ + OLLAMA_API_BASE_URL=${OLLAMA_API_BASE_URL} \ + VITE_LOG_LEVEL=${VITE_LOG_LEVEL} + +# Pre-configure wrangler to disable metrics +RUN mkdir -p /root/.config/.wrangler && \ + echo '{"enabled":false}' > /root/.config/.wrangler/metrics.json + +RUN npm run build + +CMD [ "pnpm", "run", "dockerstart"] + +# Development image +FROM base AS bolt-ai-development -# Make sure bindings.sh is executable -RUN chmod +x bindings.sh +# Define the same environment variables for development +ARG GROQ_API_KEY +ARG OPENAI_API_KEY +ARG ANTHROPIC_API_KEY +ARG OPEN_ROUTER_API_KEY +ARG GOOGLE_GENERATIVE_AI_API_KEY +ARG OLLAMA_API_BASE_URL +ARG VITE_LOG_LEVEL=debug -# Expose the port the app runs on (adjust if you specified a different port) -EXPOSE 3000 -# Ensure the app listens on all network interfaces -ENV HOST 0.0.0.0 +ENV GROQ_API_KEY=${GROQ_API_KEY} \ + OPENAI_API_KEY=${OPENAI_API_KEY} \ + ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY} \ + OPEN_ROUTER_API_KEY=${OPEN_ROUTER_API_KEY} \ + GOOGLE_GENERATIVE_AI_API_KEY=${GOOGLE_GENERATIVE_AI_API_KEY} \ + OLLAMA_API_BASE_URL=${OLLAMA_API_BASE_URL} \ + VITE_LOG_LEVEL=${VITE_LOG_LEVEL} -# Start the application -CMD ["pnpm", "run", "start"] \ No newline at end of file +RUN mkdir -p ${WORKDIR}/run +CMD pnpm run dev --host diff --git a/README.md b/README.md index fc52370c7..885e2ddb7 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ This fork of Bolt.new allows you to choose the LLM that you use for each prompt! - ✅ Publish projects directly to GitHub (@goncaloalves) - ⬜ Prevent Bolt from rewriting files as often (Done but need to review PR still) - ⬜ **HIGH PRIORITY** - Better prompting for smaller LLMs (code window sometimes doesn't start) +- ⬜ **HIGH PRIORITY** Load local projects into the app - ⬜ **HIGH PRIORITY** - Attach images to prompts - ⬜ **HIGH PRIORITY** - Run agents in the backend as opposed to a single model call - ⬜ LM Studio Integration @@ -29,12 +30,17 @@ This fork of Bolt.new allows you to choose the LLM that you use for each prompt! - ⬜ Azure Open AI API Integration - ⬜ HuggingFace Integration - ⬜ Perplexity Integration +- ⬜ Vertex AI Integration +- ⬜ Cohere Integration - ⬜ Deploy directly to Vercel/Netlify/other similar platforms -- ⬜ Load local projects into the app - ⬜ Ability to revert code to earlier version - ⬜ Prompt caching +- ⬜ Better prompt enhancing - ⬜ Ability to enter API keys in the UI - ⬜ Have LLM plan the project in a MD file for better results/transparency +- ⬜ VSCode Integration with git-like confirmations +- ⬜ Upload documents for knowledge - UI design templates, a code base to reference coding style, etc. +- ⬜ Voice prompting # Bolt.new: AI-Powered Full-Stack Web Development in the Browser @@ -54,33 +60,51 @@ Claude, v0, etc are incredible- but you can't install packages, run backends, or - **AI with Environment Control**: Unlike traditional dev environments where the AI can only assist in code generation, Bolt.new gives AI models **complete control** over the entire environment including the filesystem, node server, package manager, terminal, and browser console. This empowers AI agents to handle the whole app lifecycle—from creation to deployment. -Whether you’re an experienced developer, a PM, or a designer, Bolt.new allows you to easily build production-grade full-stack applications. Whether you’re an experienced developer, a PM, or a designer, Bolt.new allows you to easily build production-grade full-stack applications. For developers interested in building their own AI-powered development tools with WebContainers, check out the open-source Bolt codebase in this repo! -## Prerequisites +## Setup -Before you begin, ensure you have the following installed: +Many of you are new users to installing software from Github. If you have any installation troubles reach out and submit an "issue" using the links above, or feel free to enhance this documentation by forking, editing the instructions, and doing a pull request. -- Node.js (v20.15.1) -- pnpm (v9.4.0) +1. Install Git from https://git-scm.com/downloads -## Setup +2. Install Node.js from https://nodejs.org/en/download/ -1. Clone the repository (if you haven't already): +Pay attention to the installer notes after completion. -```bash +On all operating systems, the path to Node.js should automatically be added to your system path. But you can check your path if you want to be sure. On Windows, you can search for "edit the system environment variables" in your system, select "Environment Variables..." once you are in the system properties, and then check for a path to Node in your "Path" system variable. On a Mac or Linux machine, it will tell you to check if /usr/local/bin is in your $PATH. To determine if usr/local/bin is included in $PATH open your Terminal and run: + +``` +echo $PATH . +``` + +If you see usr/local/bin in the output then you're good to go. + +3. Clone the repository (if you haven't already) by opening a Terminal window (or CMD with admin permissions) and then typing in this: + +``` git clone https://github.com/coleam00/bolt.new-any-llm.git ``` -2. Install dependencies: +3. Rename .env.example to .env and add your LLM API keys. You will find this file on a Mac at "[your name]/bold.new-any-llm/.env.example". For Windows and Linux the path will be similar. -```bash -pnpm install +![image](https://github.com/user-attachments/assets/7e6a532c-2268-401f-8310-e8d20c731328) + +If you can't see the file indicated above, its likely you can't view hidden files. On Mac, open a Terminal window and enter this command below. On Windows, you will see the hidden files option in File Explorer Settings. A quick Google search will help you if you are stuck here. + +``` +defaults write com.apple.finder AppleShowAllFiles YES ``` -3. Rename `.env.example` to .env.local and add your LLM API keys (you only have to set the ones you want to use and Ollama doesn't need an API key because it runs locally on your computer): +**NOTE**: you only have to set the ones you want to use and Ollama doesn't need an API key because it runs locally on your computer: + +Get your GROQ API Key here: https://console.groq.com/keys + +Get your Open AI API Key by following these instructions: https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key + +Get your Anthropic API Key in your account settings: https://console.anthropic.com/settings/keys ``` GROQ_API_KEY=XXX @@ -94,7 +118,73 @@ Optionally, you can set the debug level: VITE_LOG_LEVEL=debug ``` -**Important**: Never commit your `.env.local` file to version control. It's already included in .gitignore. +**Important**: Never commit your `.env` file to version control. It's already included in .gitignore. + +## Run with Docker + +Prerequisites: + +Git and Node.js as mentioned above, as well as Docker: https://www.docker.com/ + +### 1a. Using Helper Scripts + +NPM scripts are provided for convenient building: + +```bash +# Development build +npm run dockerbuild + +# Production build +npm run dockerbuild:prod +``` + +### 1b. Direct Docker Build Commands (alternative to using NPM scripts) + +You can use Docker's target feature to specify the build environment instead of using NPM scripts if you wish: + +```bash +# Development build +docker build . --target bolt-ai-development + +# Production build +docker build . --target bolt-ai-production +``` + +### 2. Docker Compose with Profiles to Run the Container + +Use Docker Compose profiles to manage different environments: + +```bash +# Development environment +docker-compose --profile development up + +# Production environment +docker-compose --profile production up +``` + +When you run the Docker Compose command with the development profile, any changes you +make on your machine to the code will automatically be reflected in the site running +on the container (i.e. hot reloading still applies!). + +## Run Without Docker + +1. Install dependencies using Terminal (or CMD in Windows with admin permissions): + +``` +pnpm install +``` + +If you get an error saying "command not found: pnpm" or similar, then that means pnpm isn't installed. You can install it via this: + +``` +sudo npm install -g pnpm +``` + +2. Start the application with the command: + +```bash +pnpm run dev +``` ## Adding New LLMs: diff --git a/app/lib/.server/llm/model.ts b/app/lib/.server/llm/model.ts index 3cc75ecc9..3b88872fa 100644 --- a/app/lib/.server/llm/model.ts +++ b/app/lib/.server/llm/model.ts @@ -1,6 +1,7 @@ // @ts-nocheck // Preventing TS checks with files presented in the video for a better presentation. import { getAPIKey, getBaseURL } from '~/lib/.server/llm/api-key'; +import { getAPIKey, getBaseURL } from '~/lib/.server/llm/api-key'; import { createAnthropic } from '@ai-sdk/anthropic'; import { createOpenAI } from '@ai-sdk/openai'; import { createGoogleGenerativeAI } from '@ai-sdk/google'; @@ -24,6 +25,8 @@ export function getOpenAILikeModel(baseURL: string, apiKey: string, model: strin return openai(model); } + return openai(model); +} export function getOpenAIModel(apiKey: string, model: string) { const openai = createOpenAI({ apiKey, @@ -32,6 +35,14 @@ export function getOpenAIModel(apiKey: string, model: string) { return openai(model); } +export function getMistralModel(apiKey: string, model: string) { + const mistral = createMistral({ + apiKey + }); + + return mistral(model); +} + export function getGoogleModel(apiKey: string, model: string) { const google = createGoogleGenerativeAI(apiKey); @@ -103,5 +114,6 @@ export function getModel(provider: string, customApiKey: string, model: string, return getDeepseekModel(apiKey, model); default: return getOllamaModel(baseURL, model); + return getOllamaModel(baseURL, model); } } diff --git a/app/utils/constants.ts b/app/utils/constants.ts index 25900d6db..4c7c278ad 100644 --- a/app/utils/constants.ts +++ b/app/utils/constants.ts @@ -1,4 +1,5 @@ import type { ModelInfo, OllamaApiResponse, OllamaModel } from './types'; +import type { ModelInfo, OllamaApiResponse, OllamaModel } from './types'; export const WORK_DIR_NAME = 'project'; export const WORK_DIR = `/home/${WORK_DIR_NAME}`; @@ -64,6 +65,7 @@ async function getOllamaModels(): Promise { const response = await fetch(`${url}api/tags`); const data = (await response.json()) as OllamaApiResponse; + return data.models.map((model: OllamaModel) => ({ return data.models.map((model: OllamaModel) => ({ name: model.name, label: `${model.name} (${model.details.parameter_size})`, diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 000000000..8c4613640 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,55 @@ +services: + bolt-ai: + image: bolt-ai:production + build: + context: . + dockerfile: Dockerfile + target: bolt-ai-production + ports: + - "5173:5173" + env_file: ".env.local" + environment: + - NODE_ENV=production + - COMPOSE_PROFILES=production + # No strictly neded but serving as hints for Coolify + - PORT=5173 + - GROQ_API_KEY=${GROQ_API_KEY} + - OPENAI_API_KEY=${OPENAI_API_KEY} + - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY} + - OPEN_ROUTER_API_KEY=${OPEN_ROUTER_API_KEY} + - GOOGLE_GENERATIVE_AI_API_KEY=${GOOGLE_GENERATIVE_AI_API_KEY} + - OLLAMA_API_BASE_URL=${OLLAMA_API_BASE_URL} + - VITE_LOG_LEVEL=${VITE_LOG_LEVEL:-debug} + command: pnpm run dockerstart + profiles: + - production # This service only runs in the production profile + + bolt-ai-dev: + image: bolt-ai:development + build: + target: bolt-ai-development + environment: + - NODE_ENV=development + - VITE_HMR_PROTOCOL=ws + - VITE_HMR_HOST=localhost + - VITE_HMR_PORT=5173 + - CHOKIDAR_USEPOLLING=true + - WATCHPACK_POLLING=true + - PORT=5173 + - GROQ_API_KEY=${GROQ_API_KEY} + - OPENAI_API_KEY=${OPENAI_API_KEY} + - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY} + - OPEN_ROUTER_API_KEY=${OPEN_ROUTER_API_KEY} + - GOOGLE_GENERATIVE_AI_API_KEY=${GOOGLE_GENERATIVE_AI_API_KEY} + - OLLAMA_API_BASE_URL=${OLLAMA_API_BASE_URL} + - VITE_LOG_LEVEL=${VITE_LOG_LEVEL:-debug} + volumes: + - type: bind + source: . + target: /app + consistency: cached + - /app/node_modules + ports: + - "5173:5173" # Same port, no conflict as only one runs at a time + command: pnpm run dev --host 0.0.0.0 + profiles: ["development", "default"] # Make development the default profile diff --git a/package.json b/package.json index 7c22df5b6..79ab6e9bf 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,11 @@ "test:watch": "vitest", "lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .", "lint:fix": "npm run lint -- --fix", - "start": "bindings=$(./bindings.sh) && wrangler pages dev ./build/client $bindings --ip 0.0.0.0 --port 3000", + "start": "bindings=$(./bindings.sh) && wrangler pages dev ./build/client $bindings", + "dockerstart": "bindings=$(./bindings.sh) && wrangler pages dev ./build/client $bindings --ip 0.0.0.0 --port 5173 --no-show-interactive-dev-session", + "dockerrun": "docker run -it -d --name bolt-ai-live -p 5173:5173 --env-file .env.local bolt-ai", + "dockerbuild:prod": "docker build -t bolt-ai:production bolt-ai:latest --target bolt-ai-production .", + "dockerbuild": "docker build -t bolt-ai:development -t bolt-ai:latest --target bolt-ai-development .", "typecheck": "tsc", "typegen": "wrangler types", "preview": "pnpm run build && pnpm run start", @@ -27,6 +31,7 @@ "@ai-sdk/google": "^0.0.52", "@ai-sdk/mistral": "^0.0.44", "@ai-sdk/openai": "^0.0.66", + "@ai-sdk/mistral": "^0.0.43", "@codemirror/autocomplete": "^6.17.0", "@codemirror/commands": "^6.6.0", "@codemirror/lang-cpp": "^6.0.2", @@ -48,6 +53,8 @@ "@nanostores/react": "^0.7.2", "@octokit/rest": "^21.0.2", "@octokit/types": "^13.6.1", + "@octokit/rest": "^21.0.2", + "@octokit/types": "^13.6.1", "@openrouter/ai-sdk-provider": "^0.0.5", "@radix-ui/react-dialog": "^1.1.1", "@radix-ui/react-dropdown-menu": "^2.1.1", @@ -112,5 +119,6 @@ }, "resolutions": { "@typescript-eslint/utils": "^8.0.0-alpha.30" - } + }, + "packageManager": "pnpm@9.12.2+sha512.22721b3a11f81661ae1ec68ce1a7b879425a1ca5b991c975b074ac220b187ce56c708fe5db69f4c962c989452eee76c82877f4ee80f474cebd61ee13461b6228" } diff --git a/wrangler.toml b/wrangler.toml index 09f2e3a88..93c41604e 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -3,3 +3,4 @@ name = "bolt" compatibility_flags = ["nodejs_compat"] compatibility_date = "2024-07-01" pages_build_output_dir = "./build/client" +send_metrics = false