diff --git a/README.md b/README.md index 405e3887..84235f8c 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,9 @@ https://thinktank.ottomator.ai - ✅ Mobile friendly (@qwikode) - ✅ Better prompt enhancing (@SujalXplores) - ✅ Attach images to prompts (@atrokhym) +- ✅ Added Git Clone button (@thecodacus) +- ✅ Git Import from url (@thecodacus) +- ✅ PromptLibrary to have different variations of prompts for different use cases (@thecodacus) - ✅ Detect package.json and commands to auto install & run preview for folder and git import (@wonderwhy-er) - ✅ Selection tool to target changes visually (@emcconnell) - ⬜ **HIGH PRIORITY** - Prevent bolt from rewriting files as often (file locking and diffs) diff --git a/app/commit.json b/app/commit.json index e6f6db03..d46475e3 100644 --- a/app/commit.json +++ b/app/commit.json @@ -1 +1 @@ -{ "commit": "eb1d5417e77e699e0489f09814e87fb5afed9dd5" , "version": "" } +{ "commit": "de2cb43d170033c43a6cf436af02e033f66a7e4d" , "version": "" } diff --git a/app/components/chat/BaseChat.tsx b/app/components/chat/BaseChat.tsx index edefe058..2084cbb3 100644 --- a/app/components/chat/BaseChat.tsx +++ b/app/components/chat/BaseChat.tsx @@ -77,6 +77,8 @@ export const BaseChat = React.forwardRef( input = '', enhancingPrompt, handleInputChange, + + // promptEnhanced, enhancePrompt, sendMessage, handleStop, diff --git a/app/components/chat/Chat.client.tsx b/app/components/chat/Chat.client.tsx index dd169235..cff4e367 100644 --- a/app/components/chat/Chat.client.tsx +++ b/app/components/chat/Chat.client.tsx @@ -93,7 +93,7 @@ export const ChatImpl = memo( const [uploadedFiles, setUploadedFiles] = useState([]); // Move here const [imageDataList, setImageDataList] = useState([]); // Move here const files = useStore(workbenchStore.files); - const { activeProviders } = useSettings(); + const { activeProviders, promptId } = useSettings(); const [model, setModel] = useState(() => { const savedModel = Cookies.get('selectedModel'); @@ -115,6 +115,7 @@ export const ChatImpl = memo( body: { apiKeys, files, + promptId, }, sendExtraMessageFields: true, onError: (error) => { diff --git a/app/components/settings/debug/DebugTab.tsx b/app/components/settings/debug/DebugTab.tsx index d07f8ae2..cf2341b5 100644 --- a/app/components/settings/debug/DebugTab.tsx +++ b/app/components/settings/debug/DebugTab.tsx @@ -303,7 +303,7 @@ const checkProviderStatus = async (url: string | null, providerName: string): Pr }; export default function DebugTab() { - const { providers, latestBranch } = useSettings(); + const { providers, isLatestBranch } = useSettings(); const [activeProviders, setActiveProviders] = useState([]); const [updateMessage, setUpdateMessage] = useState(''); const [systemInfo] = useState(getSystemInfo()); @@ -363,7 +363,7 @@ export default function DebugTab() { setIsCheckingUpdate(true); setUpdateMessage('Checking for updates...'); - const branchToCheck = latestBranch ? 'main' : 'stable'; + const branchToCheck = isLatestBranch ? 'main' : 'stable'; console.log(`[Debug] Checking for updates against ${branchToCheck} branch`); const localCommitResponse = await fetch(GITHUB_URLS.commitJson(branchToCheck)); @@ -391,7 +391,7 @@ export default function DebugTab() { } finally { setIsCheckingUpdate(false); } - }, [isCheckingUpdate, latestBranch]); + }, [isCheckingUpdate, isLatestBranch]); const handleCopyToClipboard = useCallback(() => { const debugInfo = { @@ -408,7 +408,7 @@ export default function DebugTab() { })), Version: { hash: versionHash.slice(0, 7), - branch: latestBranch ? 'main' : 'stable', + branch: isLatestBranch ? 'main' : 'stable', }, Timestamp: new Date().toISOString(), }; @@ -416,7 +416,7 @@ export default function DebugTab() { navigator.clipboard.writeText(JSON.stringify(debugInfo, null, 2)).then(() => { toast.success('Debug information copied to clipboard!'); }); - }, [activeProviders, systemInfo, latestBranch]); + }, [activeProviders, systemInfo, isLatestBranch]); return (
@@ -523,7 +523,7 @@ export default function DebugTab() {

{versionHash.slice(0, 7)} - (v{versionTag || '0.0.1'}) - {latestBranch ? 'nightly' : 'stable'} + (v{versionTag || '0.0.1'}) - {isLatestBranch ? 'nightly' : 'stable'}

diff --git a/app/components/settings/features/FeaturesTab.tsx b/app/components/settings/features/FeaturesTab.tsx index 410f7ca0..bad8850e 100644 --- a/app/components/settings/features/FeaturesTab.tsx +++ b/app/components/settings/features/FeaturesTab.tsx @@ -1,10 +1,20 @@ import React from 'react'; import { Switch } from '~/components/ui/Switch'; +import { PromptLibrary } from '~/lib/common/prompt-library'; import { useSettings } from '~/lib/hooks/useSettings'; export default function FeaturesTab() { - const { debug, enableDebugMode, isLocalModel, enableLocalModels, enableEventLogs, latestBranch, enableLatestBranch } = - useSettings(); + const { + debug, + enableDebugMode, + isLocalModel, + enableLocalModels, + enableEventLogs, + isLatestBranch, + enableLatestBranch, + promptId, + setPromptId, + } = useSettings(); const handleToggle = (enabled: boolean) => { enableDebugMode(enabled); @@ -27,7 +37,7 @@ export default function FeaturesTab() { Check for updates against the main branch instead of stable

- + @@ -37,10 +47,28 @@ export default function FeaturesTab() {

Disclaimer: Experimental features may be unstable and are subject to change.

+
Experimental Providers
+
+
+ Prompt Library +

+ Choose a prompt from the library to use as the system prompt. +

+
+ +
); diff --git a/app/lib/.server/llm/stream-text.ts b/app/lib/.server/llm/stream-text.ts index 11ac99bd..74cdd9d4 100644 --- a/app/lib/.server/llm/stream-text.ts +++ b/app/lib/.server/llm/stream-text.ts @@ -1,10 +1,20 @@ import { convertToCoreMessages, streamText as _streamText } from 'ai'; import { getModel } from '~/lib/.server/llm/model'; import { MAX_TOKENS } from './constants'; -import { getSystemPrompt } from './prompts'; -import { DEFAULT_MODEL, DEFAULT_PROVIDER, getModelList, MODEL_REGEX, PROVIDER_REGEX } from '~/utils/constants'; +import { getSystemPrompt } from '~/lib/common/prompts/prompts'; +import { + DEFAULT_MODEL, + DEFAULT_PROVIDER, + getModelList, + MODEL_REGEX, + MODIFICATIONS_TAG_NAME, + PROVIDER_REGEX, + WORK_DIR, +} from '~/utils/constants'; import ignore from 'ignore'; import type { IProviderSetting } from '~/types/model'; +import { PromptLibrary } from '~/lib/common/prompt-library'; +import { allowedHTMLElements } from '~/utils/markdown'; interface ToolResult { toolCallId: string; @@ -139,8 +149,9 @@ export async function streamText(props: { apiKeys?: Record; files?: FileMap; providerSettings?: Record; + promptId?: string; }) { - const { messages, env, options, apiKeys, files, providerSettings } = props; + const { messages, env, options, apiKeys, files, providerSettings, promptId } = props; let currentModel = DEFAULT_MODEL; let currentProvider = DEFAULT_PROVIDER.name; const MODEL_LIST = await getModelList(apiKeys || {}, providerSettings); @@ -170,11 +181,17 @@ export async function streamText(props: { const dynamicMaxTokens = modelDetails && modelDetails.maxTokenAllowed ? modelDetails.maxTokenAllowed : MAX_TOKENS; - let systemPrompt = getSystemPrompt(); + let systemPrompt = + PromptLibrary.getPropmtFromLibrary(promptId || 'default', { + cwd: WORK_DIR, + allowedHtmlElements: allowedHTMLElements, + modificationTagName: MODIFICATIONS_TAG_NAME, + }) ?? getSystemPrompt(); let codeContext = ''; if (files) { codeContext = createFilesContext(files); + codeContext = ''; systemPrompt = `${systemPrompt}\n\n ${codeContext}`; } diff --git a/app/lib/common/prompt-library.ts b/app/lib/common/prompt-library.ts new file mode 100644 index 00000000..7513e811 --- /dev/null +++ b/app/lib/common/prompt-library.ts @@ -0,0 +1,49 @@ +import { getSystemPrompt } from './prompts/prompts'; +import optimized from './prompts/optimized'; + +export interface PromptOptions { + cwd: string; + allowedHtmlElements: string[]; + modificationTagName: string; +} + +export class PromptLibrary { + static library: Record< + string, + { + label: string; + description: string; + get: (options: PromptOptions) => string; + } + > = { + default: { + label: 'Default Prompt', + description: 'This is the battle tested default system Prompt', + get: (options) => getSystemPrompt(options.cwd), + }, + optimized: { + label: 'Optimized Prompt (experimental)', + description: 'an Experimental version of the prompt for lower token usage', + get: (options) => optimized(options), + }, + }; + static getList() { + return Object.entries(this.library).map(([key, value]) => { + const { label, description } = value; + return { + id: key, + label, + description, + }; + }); + } + static getPropmtFromLibrary(promptId: string, options: PromptOptions) { + const prompt = this.library[promptId]; + + if (!prompt) { + throw 'Prompt Now Found'; + } + + return this.library[promptId]?.get(options); + } +} diff --git a/app/lib/common/prompts/optimized.ts b/app/lib/common/prompts/optimized.ts new file mode 100644 index 00000000..26eb2da5 --- /dev/null +++ b/app/lib/common/prompts/optimized.ts @@ -0,0 +1,199 @@ +import type { PromptOptions } from '~/lib/common/prompt-library'; + +export default (options: PromptOptions) => { + const { cwd, allowedHtmlElements, modificationTagName } = options; + return ` +You are Bolt, an expert AI assistant and exceptional senior software developer with vast knowledge across multiple programming languages, frameworks, and best practices. + + + - Operating in WebContainer, an in-browser Node.js runtime + - Limited Python support: standard library only, no pip + - No C/C++ compiler, native binaries, or Git + - Prefer Node.js scripts over shell scripts + - Use Vite for web servers + - Databases: prefer libsql, sqlite, or non-native solutions + - When for react dont forget to write vite config and index.html to the project + + Available shell commands: cat, cp, ls, mkdir, mv, rm, rmdir, touch, hostname, ps, pwd, uptime, env, node, python3, code, jq, curl, head, sort, tail, clear, which, export, chmod, scho, kill, ln, xxd, alias, getconf, loadenv, wasm, xdg-open, command, exit, source + + + + Use 2 spaces for indentation + + + + Available HTML elements: ${allowedHtmlElements.join(', ')} + + + + File modifications in \`<${modificationTagName}>\` section: + - \`\`: GNU unified diff format + - \`\`: Full new content + + + + do not mention the phrase "chain of thought" + Before solutions, briefly outline implementation steps (2-4 lines max): + - List concrete steps + - Identify key components + - Note potential challenges + - Do not write the actual code just the plan and structure if needed + - Once completed planning start writing the artifacts + + + + Create a single, comprehensive artifact for each project: + - Use \`\` tags with \`title\` and \`id\` attributes + - Use \`\` tags with \`type\` attribute: + - shell: Run commands + - file: Write/update files (use \`filePath\` attribute) + - start: Start dev server (only when necessary) + - Order actions logically + - Install dependencies first + - Provide full, updated content for all files + - Use coding best practices: modular, clean, readable code + + + +# CRITICAL RULES - NEVER IGNORE + +## File and Command Handling +1. ALWAYS use artifacts for file contents and commands - NO EXCEPTIONS +2. When writing a file, INCLUDE THE ENTIRE FILE CONTENT - NO PARTIAL UPDATES +3. For modifications, ONLY alter files that require changes - DO NOT touch unaffected files + +## Response Format +4. Use markdown EXCLUSIVELY - HTML tags are ONLY allowed within artifacts +5. Be concise - Explain ONLY when explicitly requested +6. NEVER use the word "artifact" in responses + +## Development Process +7. ALWAYS think and plan comprehensively before providing a solution +8. Current working directory: \`${cwd} \` - Use this for all file paths +9. Don't use cli scaffolding to steup the project, use cwd as Root of the project +11. For nodejs projects ALWAYS install dependencies after writing package.json file + +## Coding Standards +10. ALWAYS create smaller, atomic components and modules +11. Modularity is PARAMOUNT - Break down functionality into logical, reusable parts +12. IMMEDIATELY refactor any file exceeding 250 lines +13. ALWAYS plan refactoring before implementation - Consider impacts on the entire system + +## Artifact Usage +22. Use \`\` tags with \`title\` and \`id\` attributes for each project +23. Use \`\` tags with appropriate \`type\` attribute: + - \`shell\`: For running commands + - \`file\`: For writing/updating files (include \`filePath\` attribute) + - \`start\`: For starting dev servers (use only when necessary/ or new dependencies are installed) +24. Order actions logically - dependencies MUST be installed first +25. For Vite project must include vite config and index.html for entry point +26. Provide COMPLETE, up-to-date content for all files - NO placeholders or partial updates + +CRITICAL: These rules are ABSOLUTE and MUST be followed WITHOUT EXCEPTION in EVERY response. + +Examples: + + + Can you help me create a JavaScript function to calculate the factorial of a number? + + Certainly, I can help you create a JavaScript function to calculate the factorial of a number. + + + +function factorial(n) { + ... +} + +... + + +node index.js + + + + + + + Build a snake game + + Certainly! I'd be happy to help you build a snake game using JavaScript and HTML5 Canvas. This will be a basic implementation that you can later expand upon. Let's create the game step by step. + + + +{ + "name": "snake", + "scripts": { + "dev": "vite" + } + ... +} + + +npm install --save-dev vite + + +... + + +npm run dev + + + + Now you can play the Snake game by opening the provided local server URL in your browser. Use the arrow keys to control the snake. Eat the red food to grow and increase your score. The game ends if you hit the wall or your own tail. + + + + + Make a bouncing ball with real gravity using React + + Certainly! I'll create a bouncing ball with real gravity using React. We'll use the react-spring library for physics-based animations. + + + +{ + "name": "bouncing-ball", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "vite build", + "preview": "vite preview" + }, + "dependencies": { + "react": "^18.2.0", + "react-dom": "^18.2.0", + "react-spring": "^9.7.1" + }, + "devDependencies": { + "@types/react": "^18.0.28", + "@types/react-dom": "^18.0.11", + "@vitejs/plugin-react": "^3.1.0", + "vite": "^4.2.0" + } +} + + +... + + +... + + +... + + +... + + +npm run dev + + + + You can now view the bouncing ball animation in the preview. The ball will start falling from the top of the screen and bounce realistically when it hits the bottom. + + + +Always use artifacts for file contents and commands, following the format shown in these examples. +`; +}; diff --git a/app/lib/.server/llm/prompts.ts b/app/lib/common/prompts/prompts.ts similarity index 100% rename from app/lib/.server/llm/prompts.ts rename to app/lib/common/prompts/prompts.ts diff --git a/app/lib/hooks/useSettings.tsx b/app/lib/hooks/useSettings.tsx index 36eefb42..cbdc1894 100644 --- a/app/lib/hooks/useSettings.tsx +++ b/app/lib/hooks/useSettings.tsx @@ -4,6 +4,7 @@ import { isEventLogsEnabled, isLocalModelsEnabled, LOCAL_PROVIDERS, + promptStore, providersStore, latestBranchStore, } from '~/lib/stores/settings'; @@ -24,8 +25,9 @@ export function useSettings() { const providers = useStore(providersStore); const debug = useStore(isDebugMode); const eventLogs = useStore(isEventLogsEnabled); + const promptId = useStore(promptStore); const isLocalModel = useStore(isLocalModelsEnabled); - const latestBranch = useStore(latestBranchStore); + const isLatestBranch = useStore(latestBranchStore); const [activeProviders, setActiveProviders] = useState([]); // Function to check if we're on stable version @@ -92,8 +94,14 @@ export function useSettings() { isLocalModelsEnabled.set(savedLocalModels === 'true'); } + const promptId = Cookies.get('promptId'); + + if (promptId) { + promptStore.set(promptId); + } + // load latest branch setting from cookies or determine based on version - const savedLatestBranch = Cookies.get('latestBranch'); + const savedLatestBranch = Cookies.get('isLatestBranch'); let checkCommit = Cookies.get('commitHash'); if (checkCommit === undefined) { @@ -105,7 +113,7 @@ export function useSettings() { checkIsStableVersion().then((isStable) => { const shouldUseLatest = !isStable; latestBranchStore.set(shouldUseLatest); - Cookies.set('latestBranch', String(shouldUseLatest)); + Cookies.set('isLatestBranch', String(shouldUseLatest)); Cookies.set('commitHash', String(commit.commit)); }); } else { @@ -162,10 +170,14 @@ export function useSettings() { Cookies.set('isLocalModelsEnabled', String(enabled)); }, []); + const setPromptId = useCallback((promptId: string) => { + promptStore.set(promptId); + Cookies.set('promptId', promptId); + }, []); const enableLatestBranch = useCallback((enabled: boolean) => { latestBranchStore.set(enabled); logStore.logSystem(`Main branch updates ${enabled ? 'enabled' : 'disabled'}`); - Cookies.set('latestBranch', String(enabled)); + Cookies.set('isLatestBranch', String(enabled)); }, []); return { @@ -178,7 +190,9 @@ export function useSettings() { enableEventLogs, isLocalModel, enableLocalModels, - latestBranch, + promptId, + setPromptId, + isLatestBranch, enableLatestBranch, }; } diff --git a/app/lib/stores/settings.ts b/app/lib/stores/settings.ts index b2f41335..cbaf30e9 100644 --- a/app/lib/stores/settings.ts +++ b/app/lib/stores/settings.ts @@ -47,4 +47,6 @@ export const isEventLogsEnabled = atom(false); export const isLocalModelsEnabled = atom(true); +export const promptStore = atom('default'); + export const latestBranchStore = atom(false); diff --git a/app/routes/api.chat.ts b/app/routes/api.chat.ts index 2c47054d..16ce9134 100644 --- a/app/routes/api.chat.ts +++ b/app/routes/api.chat.ts @@ -1,7 +1,7 @@ import { type ActionFunctionArgs } from '@remix-run/cloudflare'; import { createDataStream } from 'ai'; import { MAX_RESPONSE_SEGMENTS, MAX_TOKENS } from '~/lib/.server/llm/constants'; -import { CONTINUE_PROMPT } from '~/lib/.server/llm/prompts'; +import { CONTINUE_PROMPT } from '~/lib/common/prompts/prompts'; import { streamText, type Messages, type StreamingOptions } from '~/lib/.server/llm/stream-text'; import SwitchableStream from '~/lib/.server/llm/switchable-stream'; import type { IProviderSetting } from '~/types/model'; @@ -29,9 +29,10 @@ function parseCookies(cookieHeader: string): Record { } async function chatAction({ context, request }: ActionFunctionArgs) { - const { messages, files } = await request.json<{ + const { messages, files, promptId } = await request.json<{ messages: Messages; files: any; + promptId?: string; }>(); const cookieHeader = request.headers.get('Cookie'); @@ -98,6 +99,7 @@ async function chatAction({ context, request }: ActionFunctionArgs) { apiKeys, files, providerSettings, + promptId, }); return stream.switchSource(result.toDataStream()); @@ -111,6 +113,7 @@ async function chatAction({ context, request }: ActionFunctionArgs) { apiKeys, files, providerSettings, + promptId, }); stream.switchSource(result.toDataStream());