aproli90 commited on
Commit
2e1ab99
·
verified ·
1 Parent(s): 7fbfc55

Upload 289 files

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .dockerignore +26 -0
  2. .editorconfig +13 -0
  3. .env.example +95 -0
  4. .github/ISSUE_TEMPLATE/bug_report.yml +73 -0
  5. .github/ISSUE_TEMPLATE/config.yml +8 -0
  6. .github/ISSUE_TEMPLATE/feature_request.md +23 -0
  7. .github/actions/setup-and-build/action.yaml +32 -0
  8. .github/scripts/generate-changelog.sh +261 -0
  9. .github/workflows/ci.yaml +27 -0
  10. .github/workflows/docker.yaml +76 -0
  11. .github/workflows/docs.yaml +35 -0
  12. .github/workflows/pr-release-validation.yaml +31 -0
  13. .github/workflows/semantic-pr.yaml +32 -0
  14. .github/workflows/stale.yml +25 -0
  15. .github/workflows/update-stable.yml +126 -0
  16. .gitignore +43 -0
  17. .husky/_/.gitignore +1 -0
  18. .husky/_/applypatch-msg +2 -0
  19. .husky/_/commit-msg +2 -0
  20. .husky/_/h +22 -0
  21. .husky/_/husky.sh +9 -0
  22. .husky/_/post-applypatch +2 -0
  23. .husky/_/post-checkout +2 -0
  24. .husky/_/post-commit +2 -0
  25. .husky/_/post-merge +2 -0
  26. .husky/_/post-rewrite +2 -0
  27. .husky/_/pre-applypatch +2 -0
  28. .husky/_/pre-auto-gc +2 -0
  29. .husky/_/pre-commit +2 -0
  30. .husky/_/pre-merge-commit +2 -0
  31. .husky/_/pre-push +2 -0
  32. .husky/_/pre-rebase +2 -0
  33. .husky/_/prepare-commit-msg +2 -0
  34. .husky/pre-commit +32 -0
  35. .prettierignore +2 -0
  36. .prettierrc +8 -0
  37. .tool-versions +2 -0
  38. CONTRIBUTING.md +219 -0
  39. Dockerfile +87 -0
  40. FAQ.md +91 -0
  41. LICENSE +21 -0
  42. README.md +327 -10
  43. app/components/chat/APIKeyManager.tsx +112 -0
  44. app/components/chat/Artifact.tsx +263 -0
  45. app/components/chat/AssistantMessage.tsx +31 -0
  46. app/components/chat/BaseChat.module.scss +47 -0
  47. app/components/chat/BaseChat.tsx +626 -0
  48. app/components/chat/Chat.client.tsx +556 -0
  49. app/components/chat/ChatAlert.tsx +108 -0
  50. app/components/chat/CodeBlock.module.scss +10 -0
.dockerignore ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Ignore Git and GitHub files
2
+ .git
3
+ .github/
4
+
5
+ # Ignore Husky configuration files
6
+ .husky/
7
+
8
+ # Ignore documentation and metadata files
9
+ CONTRIBUTING.md
10
+ LICENSE
11
+ README.md
12
+
13
+ # Ignore environment examples and sensitive info
14
+ .env
15
+ *.local
16
+ *.example
17
+
18
+ # Ignore node modules, logs and cache files
19
+ **/*.log
20
+ **/node_modules
21
+ **/dist
22
+ **/build
23
+ **/.cache
24
+ logs
25
+ dist-ssr
26
+ .DS_Store
.editorconfig ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ end_of_line = lf
6
+ charset = utf-8
7
+ trim_trailing_whitespace = true
8
+ insert_final_newline = true
9
+ max_line_length = 120
10
+ indent_size = 2
11
+
12
+ [*.md]
13
+ trim_trailing_whitespace = false
.env.example ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Rename this file to .env once you have filled in the below environment variables!
2
+
3
+ # Get your GROQ API Key here -
4
+ # https://console.groq.com/keys
5
+ # You only need this environment variable set if you want to use Groq models
6
+ GROQ_API_KEY=
7
+
8
+ # Get your HuggingFace API Key here -
9
+ # https://huggingface.co/settings/tokens
10
+ # You only need this environment variable set if you want to use HuggingFace models
11
+ HuggingFace_API_KEY=
12
+
13
+
14
+ # Get your Open AI API Key by following these instructions -
15
+ # https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key
16
+ # You only need this environment variable set if you want to use GPT models
17
+ OPENAI_API_KEY=
18
+
19
+ # Get your Anthropic API Key in your account settings -
20
+ # https://console.anthropic.com/settings/keys
21
+ # You only need this environment variable set if you want to use Claude models
22
+ ANTHROPIC_API_KEY=
23
+
24
+ # Get your OpenRouter API Key in your account settings -
25
+ # https://openrouter.ai/settings/keys
26
+ # You only need this environment variable set if you want to use OpenRouter models
27
+ OPEN_ROUTER_API_KEY=
28
+
29
+ # Get your Google Generative AI API Key by following these instructions -
30
+ # https://console.cloud.google.com/apis/credentials
31
+ # You only need this environment variable set if you want to use Google Generative AI models
32
+ GOOGLE_GENERATIVE_AI_API_KEY=
33
+
34
+ # You only need this environment variable set if you want to use oLLAMA models
35
+ # DONT USE http://localhost:11434 due to IPV6 issues
36
+ # USE EXAMPLE http://127.0.0.1:11434
37
+ OLLAMA_API_BASE_URL=
38
+
39
+ # You only need this environment variable set if you want to use OpenAI Like models
40
+ OPENAI_LIKE_API_BASE_URL=
41
+
42
+ # You only need this environment variable set if you want to use Together AI models
43
+ TOGETHER_API_BASE_URL=
44
+
45
+ # You only need this environment variable set if you want to use DeepSeek models through their API
46
+ DEEPSEEK_API_KEY=
47
+
48
+ # Get your OpenAI Like API Key
49
+ OPENAI_LIKE_API_KEY=
50
+
51
+ # Get your Together API Key
52
+ TOGETHER_API_KEY=
53
+
54
+ # You only need this environment variable set if you want to use Hyperbolic models
55
+ #Get your Hyperbolics API Key at https://app.hyperbolic.xyz/settings
56
+ #baseURL="https://api.hyperbolic.xyz/v1/chat/completions"
57
+ HYPERBOLIC_API_KEY=
58
+ HYPERBOLIC_API_BASE_URL=
59
+
60
+ # Get your Mistral API Key by following these instructions -
61
+ # https://console.mistral.ai/api-keys/
62
+ # You only need this environment variable set if you want to use Mistral models
63
+ MISTRAL_API_KEY=
64
+
65
+ # Get the Cohere Api key by following these instructions -
66
+ # https://dashboard.cohere.com/api-keys
67
+ # You only need this environment variable set if you want to use Cohere models
68
+ COHERE_API_KEY=
69
+
70
+ # Get LMStudio Base URL from LM Studio Developer Console
71
+ # Make sure to enable CORS
72
+ # DONT USE http://localhost:1234 due to IPV6 issues
73
+ # Example: http://127.0.0.1:1234
74
+ LMSTUDIO_API_BASE_URL=
75
+
76
+ # Get your xAI API key
77
+ # https://x.ai/api
78
+ # You only need this environment variable set if you want to use xAI models
79
+ XAI_API_KEY=
80
+
81
+ # Get your Perplexity API Key here -
82
+ # https://www.perplexity.ai/settings/api
83
+ # You only need this environment variable set if you want to use Perplexity models
84
+ PERPLEXITY_API_KEY=
85
+
86
+ # Include this environment variable if you want more logging for debugging locally
87
+ VITE_LOG_LEVEL=debug
88
+
89
+ # Example Context Values for qwen2.5-coder:32b
90
+ #
91
+ # DEFAULT_NUM_CTX=32768 # Consumes 36GB of VRAM
92
+ # DEFAULT_NUM_CTX=24576 # Consumes 32GB of VRAM
93
+ # DEFAULT_NUM_CTX=12288 # Consumes 26GB of VRAM
94
+ # DEFAULT_NUM_CTX=6144 # Consumes 24GB of VRAM
95
+ DEFAULT_NUM_CTX=
.github/ISSUE_TEMPLATE/bug_report.yml ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "Bug report"
2
+ description: Create a report to help us improve
3
+ body:
4
+ - type: markdown
5
+ attributes:
6
+ value: |
7
+ Thank you for reporting an issue :pray:.
8
+
9
+ This issue tracker is for bugs and issues found with [Bolt.new](https://bolt.new).
10
+ If you experience issues related to WebContainer, please file an issue in our [WebContainer repo](https://github.com/stackblitz/webcontainer-core), or file an issue in our [StackBlitz core repo](https://github.com/stackblitz/core) for issues with StackBlitz.
11
+
12
+ The more information you fill in, the better we can help you.
13
+ - type: textarea
14
+ id: description
15
+ attributes:
16
+ label: Describe the bug
17
+ description: Provide a clear and concise description of what you're running into.
18
+ validations:
19
+ required: true
20
+ - type: input
21
+ id: link
22
+ attributes:
23
+ label: Link to the Bolt URL that caused the error
24
+ description: Please do not delete it after reporting!
25
+ validations:
26
+ required: true
27
+ - type: textarea
28
+ id: steps
29
+ attributes:
30
+ label: Steps to reproduce
31
+ description: Describe the steps we have to take to reproduce the behavior.
32
+ placeholder: |
33
+ 1. Go to '...'
34
+ 2. Click on '....'
35
+ 3. Scroll down to '....'
36
+ 4. See error
37
+ validations:
38
+ required: true
39
+ - type: textarea
40
+ id: expected
41
+ attributes:
42
+ label: Expected behavior
43
+ description: Provide a clear and concise description of what you expected to happen.
44
+ validations:
45
+ required: true
46
+ - type: textarea
47
+ id: screenshots
48
+ attributes:
49
+ label: Screen Recording / Screenshot
50
+ description: If applicable, **please include a screen recording** (preferably) or screenshot showcasing the issue. This will assist us in resolving your issue <u>quickly</u>.
51
+ - type: textarea
52
+ id: platform
53
+ attributes:
54
+ label: Platform
55
+ value: |
56
+ - OS: [e.g. macOS, Windows, Linux]
57
+ - Browser: [e.g. Chrome, Safari, Firefox]
58
+ - Version: [e.g. 91.1]
59
+ - type: input
60
+ id: provider
61
+ attributes:
62
+ label: Provider Used
63
+ description: Tell us the provider you are using.
64
+ - type: input
65
+ id: model
66
+ attributes:
67
+ label: Model Used
68
+ description: Tell us the model you are using.
69
+ - type: textarea
70
+ id: additional
71
+ attributes:
72
+ label: Additional context
73
+ description: Add any other context about the problem here.
.github/ISSUE_TEMPLATE/config.yml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ blank_issues_enabled: false
2
+ contact_links:
3
+ - name: Bolt.new related issues
4
+ url: https://github.com/stackblitz/bolt.new/issues/new/choose
5
+ about: Report issues related to Bolt.new (not Bolt.diy)
6
+ - name: Chat
7
+ url: https://thinktank.ottomator.ai
8
+ about: Ask questions and discuss with other Bolt.diy users.
.github/ISSUE_TEMPLATE/feature_request.md ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+ ---
8
+
9
+ **Is your feature request related to a problem? Please describe:**
10
+
11
+ <!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
12
+
13
+ **Describe the solution you'd like:**
14
+
15
+ <!-- A clear and concise description of what you want to happen. -->
16
+
17
+ **Describe alternatives you've considered:**
18
+
19
+ <!-- A clear and concise description of any alternative solutions or features you've considered. -->
20
+
21
+ **Additional context:**
22
+
23
+ <!-- Add any other context or screenshots about the feature request here. -->
.github/actions/setup-and-build/action.yaml ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Setup and Build
2
+ description: Generic setup action
3
+ inputs:
4
+ pnpm-version:
5
+ required: false
6
+ type: string
7
+ default: '9.4.0'
8
+ node-version:
9
+ required: false
10
+ type: string
11
+ default: '20.15.1'
12
+
13
+ runs:
14
+ using: composite
15
+
16
+ steps:
17
+ - uses: pnpm/action-setup@v4
18
+ with:
19
+ version: ${{ inputs.pnpm-version }}
20
+ run_install: false
21
+
22
+ - name: Set Node.js version to ${{ inputs.node-version }}
23
+ uses: actions/setup-node@v4
24
+ with:
25
+ node-version: ${{ inputs.node-version }}
26
+ cache: pnpm
27
+
28
+ - name: Install dependencies and build project
29
+ shell: bash
30
+ run: |
31
+ pnpm install
32
+ pnpm run build
.github/scripts/generate-changelog.sh ADDED
@@ -0,0 +1,261 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+
3
+ # Ensure we're running in bash
4
+ if [ -z "$BASH_VERSION" ]; then
5
+ echo "This script requires bash. Please run with: bash $0" >&2
6
+ exit 1
7
+ fi
8
+
9
+ # Ensure we're using bash 4.0 or later for associative arrays
10
+ if ((BASH_VERSINFO[0] < 4)); then
11
+ echo "This script requires bash version 4 or later" >&2
12
+ echo "Current bash version: $BASH_VERSION" >&2
13
+ exit 1
14
+ fi
15
+
16
+ # Set default values for required environment variables if not in GitHub Actions
17
+ if [ -z "$GITHUB_ACTIONS" ]; then
18
+ : "${GITHUB_SERVER_URL:=https://github.com}"
19
+ : "${GITHUB_REPOSITORY:=stackblitz-labs/bolt.diy}"
20
+ : "${GITHUB_OUTPUT:=/tmp/github_output}"
21
+ touch "$GITHUB_OUTPUT"
22
+
23
+ # Running locally
24
+ echo "Running locally - checking for upstream remote..."
25
+ MAIN_REMOTE="origin"
26
+ if git remote -v | grep -q "upstream"; then
27
+ MAIN_REMOTE="upstream"
28
+ fi
29
+ MAIN_BRANCH="main" # or "master" depending on your repository
30
+
31
+ # Ensure we have latest tags
32
+ git fetch ${MAIN_REMOTE} --tags
33
+
34
+ # Use the remote reference for git log
35
+ GITLOG_REF="${MAIN_REMOTE}/${MAIN_BRANCH}"
36
+ else
37
+ # Running in GitHub Actions
38
+ GITLOG_REF="HEAD"
39
+ fi
40
+
41
+ # Get the latest tag
42
+ LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
43
+
44
+ # Start changelog file
45
+ echo "# 🚀 Release v${NEW_VERSION}" > changelog.md
46
+ echo "" >> changelog.md
47
+ echo "## What's Changed 🌟" >> changelog.md
48
+ echo "" >> changelog.md
49
+
50
+ if [ -z "$LATEST_TAG" ]; then
51
+ echo "### 🎉 First Release" >> changelog.md
52
+ echo "" >> changelog.md
53
+ echo "Exciting times! This marks our first release. Thanks to everyone who contributed! 🙌" >> changelog.md
54
+ echo "" >> changelog.md
55
+ COMPARE_BASE="$(git rev-list --max-parents=0 HEAD)"
56
+ else
57
+ echo "### 🔄 Changes since $LATEST_TAG" >> changelog.md
58
+ echo "" >> changelog.md
59
+ COMPARE_BASE="$LATEST_TAG"
60
+ fi
61
+
62
+ # Function to extract conventional commit type and associated emoji
63
+ get_commit_type() {
64
+ local msg="$1"
65
+ if [[ $msg =~ ^feat(\(.+\))?:|^feature(\(.+\))?: ]]; then echo "✨ Features"
66
+ elif [[ $msg =~ ^fix(\(.+\))?: ]]; then echo "🐛 Bug Fixes"
67
+ elif [[ $msg =~ ^docs(\(.+\))?: ]]; then echo "📚 Documentation"
68
+ elif [[ $msg =~ ^style(\(.+\))?: ]]; then echo "💎 Styles"
69
+ elif [[ $msg =~ ^refactor(\(.+\))?: ]]; then echo "♻️ Code Refactoring"
70
+ elif [[ $msg =~ ^perf(\(.+\))?: ]]; then echo "⚡ Performance Improvements"
71
+ elif [[ $msg =~ ^test(\(.+\))?: ]]; then echo "🧪 Tests"
72
+ elif [[ $msg =~ ^build(\(.+\))?: ]]; then echo "🛠️ Build System"
73
+ elif [[ $msg =~ ^ci(\(.+\))?: ]]; then echo "⚙️ CI"
74
+ elif [[ $msg =~ ^chore(\(.+\))?: ]]; then echo "" # Skip chore commits
75
+ else echo "🔍 Other Changes" # Default category with emoji
76
+ fi
77
+ }
78
+
79
+ # Initialize associative arrays
80
+ declare -A CATEGORIES
81
+ declare -A COMMITS_BY_CATEGORY
82
+ declare -A ALL_AUTHORS
83
+ declare -A NEW_CONTRIBUTORS
84
+
85
+ # Get all historical authors before the compare base
86
+ while IFS= read -r author; do
87
+ ALL_AUTHORS["$author"]=1
88
+ done < <(git log "${COMPARE_BASE}" --pretty=format:"%ae" | sort -u)
89
+
90
+ # Process all commits since last tag
91
+ while IFS= read -r commit_line; do
92
+ if [[ ! $commit_line =~ ^[a-f0-9]+\| ]]; then
93
+ echo "WARNING: Skipping invalid commit line format: $commit_line" >&2
94
+ continue
95
+ fi
96
+
97
+ HASH=$(echo "$commit_line" | cut -d'|' -f1)
98
+ COMMIT_MSG=$(echo "$commit_line" | cut -d'|' -f2)
99
+ BODY=$(echo "$commit_line" | cut -d'|' -f3)
100
+ # Skip if hash doesn't match the expected format
101
+ if [[ ! $HASH =~ ^[a-f0-9]{40}$ ]]; then
102
+ continue
103
+ fi
104
+
105
+ HASH=$(echo "$commit_line" | cut -d'|' -f1)
106
+ COMMIT_MSG=$(echo "$commit_line" | cut -d'|' -f2)
107
+ BODY=$(echo "$commit_line" | cut -d'|' -f3)
108
+
109
+
110
+ # Validate hash format
111
+ if [[ ! $HASH =~ ^[a-f0-9]{40}$ ]]; then
112
+ echo "WARNING: Invalid commit hash format: $HASH" >&2
113
+ continue
114
+ fi
115
+
116
+ # Check if it's a merge commit
117
+ if [[ $COMMIT_MSG =~ Merge\ pull\ request\ #([0-9]+) ]]; then
118
+ # echo "Processing as merge commit" >&2
119
+ PR_NUM="${BASH_REMATCH[1]}"
120
+
121
+ # Extract the PR title from the merge commit body
122
+ PR_TITLE=$(echo "$BODY" | grep -v "^Merge pull request" | head -n 1)
123
+
124
+ # Only process if it follows conventional commit format
125
+ CATEGORY=$(get_commit_type "$PR_TITLE")
126
+
127
+ if [ -n "$CATEGORY" ]; then # Only process if it's a conventional commit
128
+ # Get PR author's GitHub username
129
+ GITHUB_USERNAME=$(gh pr view "$PR_NUM" --json author --jq '.author.login')
130
+
131
+ if [ -n "$GITHUB_USERNAME" ]; then
132
+ # Check if this is a first-time contributor
133
+ AUTHOR_EMAIL=$(git show -s --format='%ae' "$HASH")
134
+ if [ -z "${ALL_AUTHORS[$AUTHOR_EMAIL]}" ]; then
135
+ NEW_CONTRIBUTORS["$GITHUB_USERNAME"]=1
136
+ ALL_AUTHORS["$AUTHOR_EMAIL"]=1
137
+ fi
138
+
139
+ CATEGORIES["$CATEGORY"]=1
140
+ COMMITS_BY_CATEGORY["$CATEGORY"]+="* ${PR_TITLE#*: } ([#$PR_NUM](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/pull/$PR_NUM)) by @$GITHUB_USERNAME"$'\n'
141
+ else
142
+ COMMITS_BY_CATEGORY["$CATEGORY"]+="* ${PR_TITLE#*: } ([#$PR_NUM](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/pull/$PR_NUM))"$'\n'
143
+ fi
144
+ fi
145
+ # Check if it's a squash merge by looking for (#NUMBER) pattern
146
+ elif [[ $COMMIT_MSG =~ \(#([0-9]+)\) ]]; then
147
+ # echo "Processing as squash commit" >&2
148
+ PR_NUM="${BASH_REMATCH[1]}"
149
+
150
+ # Only process if it follows conventional commit format
151
+ CATEGORY=$(get_commit_type "$COMMIT_MSG")
152
+
153
+ if [ -n "$CATEGORY" ]; then # Only process if it's a conventional commit
154
+ # Get PR author's GitHub username
155
+ GITHUB_USERNAME=$(gh pr view "$PR_NUM" --json author --jq '.author.login')
156
+
157
+ if [ -n "$GITHUB_USERNAME" ]; then
158
+ # Check if this is a first-time contributor
159
+ AUTHOR_EMAIL=$(git show -s --format='%ae' "$HASH")
160
+ if [ -z "${ALL_AUTHORS[$AUTHOR_EMAIL]}" ]; then
161
+ NEW_CONTRIBUTORS["$GITHUB_USERNAME"]=1
162
+ ALL_AUTHORS["$AUTHOR_EMAIL"]=1
163
+ fi
164
+
165
+ CATEGORIES["$CATEGORY"]=1
166
+ COMMIT_TITLE=${COMMIT_MSG%% (#*} # Remove the PR number suffix
167
+ COMMIT_TITLE=${COMMIT_TITLE#*: } # Remove the type prefix
168
+ COMMITS_BY_CATEGORY["$CATEGORY"]+="* $COMMIT_TITLE ([#$PR_NUM](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/pull/$PR_NUM)) by @$GITHUB_USERNAME"$'\n'
169
+ else
170
+ COMMIT_TITLE=${COMMIT_MSG%% (#*} # Remove the PR number suffix
171
+ COMMIT_TITLE=${COMMIT_TITLE#*: } # Remove the type prefix
172
+ COMMITS_BY_CATEGORY["$CATEGORY"]+="* $COMMIT_TITLE ([#$PR_NUM](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/pull/$PR_NUM))"$'\n'
173
+ fi
174
+ fi
175
+
176
+ else
177
+ # echo "Processing as regular commit" >&2
178
+ # Process conventional commits without PR numbers
179
+ CATEGORY=$(get_commit_type "$COMMIT_MSG")
180
+
181
+ if [ -n "$CATEGORY" ]; then # Only process if it's a conventional commit
182
+ # Get commit author info
183
+ AUTHOR_EMAIL=$(git show -s --format='%ae' "$HASH")
184
+
185
+ # Try to get GitHub username using gh api
186
+ if [ -n "$GITHUB_ACTIONS" ] || command -v gh >/dev/null 2>&1; then
187
+ GITHUB_USERNAME=$(gh api "/repos/${GITHUB_REPOSITORY}/commits/${HASH}" --jq '.author.login' 2>/dev/null)
188
+ fi
189
+
190
+ if [ -n "$GITHUB_USERNAME" ]; then
191
+ # If we got GitHub username, use it
192
+ if [ -z "${ALL_AUTHORS[$AUTHOR_EMAIL]}" ]; then
193
+ NEW_CONTRIBUTORS["$GITHUB_USERNAME"]=1
194
+ ALL_AUTHORS["$AUTHOR_EMAIL"]=1
195
+ fi
196
+
197
+ CATEGORIES["$CATEGORY"]=1
198
+ COMMIT_TITLE=${COMMIT_MSG#*: } # Remove the type prefix
199
+ COMMITS_BY_CATEGORY["$CATEGORY"]+="* $COMMIT_TITLE (${HASH:0:7}) by @$GITHUB_USERNAME"$'\n'
200
+ else
201
+ # Fallback to git author name if no GitHub username found
202
+ AUTHOR_NAME=$(git show -s --format='%an' "$HASH")
203
+
204
+ if [ -z "${ALL_AUTHORS[$AUTHOR_EMAIL]}" ]; then
205
+ NEW_CONTRIBUTORS["$AUTHOR_NAME"]=1
206
+ ALL_AUTHORS["$AUTHOR_EMAIL"]=1
207
+ fi
208
+
209
+ CATEGORIES["$CATEGORY"]=1
210
+ COMMIT_TITLE=${COMMIT_MSG#*: } # Remove the type prefix
211
+ COMMITS_BY_CATEGORY["$CATEGORY"]+="* $COMMIT_TITLE (${HASH:0:7}) by $AUTHOR_NAME"$'\n'
212
+ fi
213
+ fi
214
+ fi
215
+
216
+ done < <(git log "${COMPARE_BASE}..${GITLOG_REF}" --pretty=format:"%H|%s|%b" --reverse --first-parent)
217
+
218
+ # Write categorized commits to changelog with their emojis
219
+ for category in "✨ Features" "🐛 Bug Fixes" "📚 Documentation" "💎 Styles" "♻️ Code Refactoring" "⚡ Performance Improvements" "🧪 Tests" "🛠️ Build System" "⚙️ CI" "🔍 Other Changes"; do
220
+ if [ -n "${COMMITS_BY_CATEGORY[$category]}" ]; then
221
+ echo "### $category" >> changelog.md
222
+ echo "" >> changelog.md
223
+ echo "${COMMITS_BY_CATEGORY[$category]}" >> changelog.md
224
+ echo "" >> changelog.md
225
+ fi
226
+ done
227
+
228
+ # Add first-time contributors section if there are any
229
+ if [ ${#NEW_CONTRIBUTORS[@]} -gt 0 ]; then
230
+ echo "## ✨ First-time Contributors" >> changelog.md
231
+ echo "" >> changelog.md
232
+ echo "A huge thank you to our amazing new contributors! Your first contribution marks the start of an exciting journey! 🌟" >> changelog.md
233
+ echo "" >> changelog.md
234
+ # Use readarray to sort the keys
235
+ readarray -t sorted_contributors < <(printf '%s\n' "${!NEW_CONTRIBUTORS[@]}" | sort)
236
+ for github_username in "${sorted_contributors[@]}"; do
237
+ echo "* 🌟 [@$github_username](https://github.com/$github_username)" >> changelog.md
238
+ done
239
+ echo "" >> changelog.md
240
+ fi
241
+
242
+ # Add compare link if not first release
243
+ if [ -n "$LATEST_TAG" ]; then
244
+ echo "## 📈 Stats" >> changelog.md
245
+ echo "" >> changelog.md
246
+ echo "**Full Changelog**: [\`$LATEST_TAG..v${NEW_VERSION}\`](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/compare/$LATEST_TAG...v${NEW_VERSION})" >> changelog.md
247
+ fi
248
+
249
+ # Output the changelog content
250
+ CHANGELOG_CONTENT=$(cat changelog.md)
251
+ {
252
+ echo "content<<EOF"
253
+ echo "$CHANGELOG_CONTENT"
254
+ echo "EOF"
255
+ } >> "$GITHUB_OUTPUT"
256
+
257
+ # Also print to stdout for local testing
258
+ echo "Generated changelog:"
259
+ echo "==================="
260
+ cat changelog.md
261
+ echo "==================="
.github/workflows/ci.yaml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: CI/CD
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+
9
+ jobs:
10
+ test:
11
+ name: Test
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - name: Checkout
15
+ uses: actions/checkout@v4
16
+
17
+ - name: Setup and Build
18
+ uses: ./.github/actions/setup-and-build
19
+
20
+ - name: Run type check
21
+ run: pnpm run typecheck
22
+
23
+ # - name: Run ESLint
24
+ # run: pnpm run lint
25
+
26
+ - name: Run tests
27
+ run: pnpm run test
.github/workflows/docker.yaml ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ name: Docker Publish
3
+
4
+ on:
5
+ workflow_dispatch:
6
+ push:
7
+ branches:
8
+ - main
9
+ tags:
10
+ - v*
11
+ - "*"
12
+
13
+ env:
14
+ REGISTRY: ghcr.io
15
+ DOCKER_IMAGE: ghcr.io/${{ github.repository }}
16
+ BUILD_TARGET: bolt-ai-production # bolt-ai-development
17
+
18
+ jobs:
19
+ docker-build-publish:
20
+ runs-on: ubuntu-latest
21
+ steps:
22
+ - name: Checkout
23
+ uses: actions/checkout@v4
24
+
25
+ - id: string
26
+ uses: ASzc/change-string-case-action@v6
27
+ with:
28
+ string: ${{ env.DOCKER_IMAGE }}
29
+
30
+ - name: Docker meta
31
+ id: meta
32
+ uses: crazy-max/ghaction-docker-meta@v5
33
+ with:
34
+ images: ${{ steps.string.outputs.lowercase }}
35
+ flavor: |
36
+ latest=true
37
+ prefix=
38
+ suffix=
39
+ tags: |
40
+ type=semver,pattern={{version}}
41
+ type=pep440,pattern={{version}}
42
+ type=ref,event=tag
43
+ type=raw,value={{sha}}
44
+
45
+ - name: Set up QEMU
46
+ uses: docker/setup-qemu-action@v3
47
+
48
+ - name: Set up Docker Buildx
49
+ uses: docker/setup-buildx-action@v3
50
+
51
+ - name: Login to Container Registry
52
+ uses: docker/login-action@v3
53
+ with:
54
+ registry: ${{ env.REGISTRY }}
55
+ username: ${{ github.actor }} # ${{ secrets.DOCKER_USERNAME }}
56
+ password: ${{ secrets.GITHUB_TOKEN }} # ${{ secrets.DOCKER_PASSWORD }}
57
+
58
+ - name: Build and push
59
+ uses: docker/build-push-action@v6
60
+ with:
61
+ context: .
62
+ file: ./Dockerfile
63
+ target: ${{ env.BUILD_TARGET }}
64
+ push: true
65
+ tags: ${{ steps.meta.outputs.tags }}
66
+ labels: ${{ steps.meta.outputs.labels }}
67
+ cache-from: type=registry,ref=${{ steps.string.outputs.lowercase }}:latest
68
+ cache-to: type=inline
69
+
70
+ - name: Check manifest
71
+ run: |
72
+ docker buildx imagetools inspect ${{ steps.string.outputs.lowercase }}:${{ steps.meta.outputs.version }}
73
+
74
+ - name: Dump context
75
+ if: always()
76
+ uses: crazy-max/ghaction-dump-context@v2
.github/workflows/docs.yaml ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Docs CI/CD
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ paths:
8
+ - 'docs/**' # This will only trigger the workflow when files in docs directory change
9
+ permissions:
10
+ contents: write
11
+ jobs:
12
+ build_docs:
13
+ runs-on: ubuntu-latest
14
+ defaults:
15
+ run:
16
+ working-directory: ./docs
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ - name: Configure Git Credentials
20
+ run: |
21
+ git config user.name github-actions[bot]
22
+ git config user.email 41898282+github-actions[bot]@users.noreply.github.com
23
+ - uses: actions/setup-python@v5
24
+ with:
25
+ python-version: 3.x
26
+ - run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
27
+ - uses: actions/cache@v4
28
+ with:
29
+ key: mkdocs-material-${{ env.cache_id }}
30
+ path: .cache
31
+ restore-keys: |
32
+ mkdocs-material-
33
+
34
+ - run: pip install mkdocs-material
35
+ - run: mkdocs gh-deploy --force
.github/workflows/pr-release-validation.yaml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: PR Validation
2
+
3
+ on:
4
+ pull_request:
5
+ types: [opened, synchronize, reopened, labeled, unlabeled]
6
+ branches:
7
+ - main
8
+
9
+ jobs:
10
+ validate:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - name: Validate PR Labels
17
+ run: |
18
+ if [[ "${{ contains(github.event.pull_request.labels.*.name, 'stable-release') }}" == "true" ]]; then
19
+ echo "✓ PR has stable-release label"
20
+
21
+ # Check version bump labels
22
+ if [[ "${{ contains(github.event.pull_request.labels.*.name, 'major') }}" == "true" ]]; then
23
+ echo "✓ Major version bump requested"
24
+ elif [[ "${{ contains(github.event.pull_request.labels.*.name, 'minor') }}" == "true" ]]; then
25
+ echo "✓ Minor version bump requested"
26
+ else
27
+ echo "✓ Patch version bump will be applied"
28
+ fi
29
+ else
30
+ echo "This PR doesn't have the stable-release label. No release will be created."
31
+ fi
.github/workflows/semantic-pr.yaml ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Semantic Pull Request
2
+ on:
3
+ pull_request_target:
4
+ types: [opened, reopened, edited, synchronize]
5
+ permissions:
6
+ pull-requests: read
7
+ jobs:
8
+ main:
9
+ name: Validate PR Title
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ # https://github.com/amannn/action-semantic-pull-request/releases/tag/v5.5.3
13
+ - uses: amannn/action-semantic-pull-request@0723387faaf9b38adef4775cd42cfd5155ed6017
14
+ env:
15
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16
+ with:
17
+ subjectPattern: ^(?![A-Z]).+$
18
+ subjectPatternError: |
19
+ The subject "{subject}" found in the pull request title "{title}"
20
+ didn't match the configured pattern. Please ensure that the subject
21
+ doesn't start with an uppercase character.
22
+ types: |
23
+ fix
24
+ feat
25
+ chore
26
+ build
27
+ ci
28
+ perf
29
+ docs
30
+ refactor
31
+ revert
32
+ test
.github/workflows/stale.yml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Mark Stale Issues and Pull Requests
2
+
3
+ on:
4
+ schedule:
5
+ - cron: '0 2 * * *' # Runs daily at 2:00 AM UTC
6
+ workflow_dispatch: # Allows manual triggering of the workflow
7
+
8
+ jobs:
9
+ stale:
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - name: Mark stale issues and pull requests
14
+ uses: actions/stale@v8
15
+ with:
16
+ repo-token: ${{ secrets.GITHUB_TOKEN }}
17
+ stale-issue-message: "This issue has been marked as stale due to inactivity. If no further activity occurs, it will be closed in 7 days."
18
+ stale-pr-message: "This pull request has been marked as stale due to inactivity. If no further activity occurs, it will be closed in 7 days."
19
+ days-before-stale: 10 # Number of days before marking an issue or PR as stale
20
+ days-before-close: 4 # Number of days after being marked stale before closing
21
+ stale-issue-label: "stale" # Label to apply to stale issues
22
+ stale-pr-label: "stale" # Label to apply to stale pull requests
23
+ exempt-issue-labels: "pinned,important" # Issues with these labels won't be marked stale
24
+ exempt-pr-labels: "pinned,important" # PRs with these labels won't be marked stale
25
+ operations-per-run: 75 # Limits the number of actions per run to avoid API rate limits
.github/workflows/update-stable.yml ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Update Stable Branch
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ permissions:
9
+ contents: write
10
+
11
+ jobs:
12
+ prepare-release:
13
+ if: contains(github.event.head_commit.message, '#release')
14
+ runs-on: ubuntu-latest
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ with:
19
+ fetch-depth: 0
20
+
21
+ - name: Configure Git
22
+ run: |
23
+ git config --global user.name 'github-actions[bot]'
24
+ git config --global user.email 'github-actions[bot]@users.noreply.github.com'
25
+
26
+ - name: Setup Node.js
27
+ uses: actions/setup-node@v4
28
+ with:
29
+ node-version: '20'
30
+
31
+ - name: Install pnpm
32
+ uses: pnpm/action-setup@v2
33
+ with:
34
+ version: latest
35
+ run_install: false
36
+
37
+ - name: Get pnpm store directory
38
+ id: pnpm-cache
39
+ shell: bash
40
+ run: |
41
+ echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
42
+
43
+ - name: Setup pnpm cache
44
+ uses: actions/cache@v4
45
+ with:
46
+ path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
47
+ key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
48
+ restore-keys: |
49
+ ${{ runner.os }}-pnpm-store-
50
+
51
+ - name: Get Current Version
52
+ id: current_version
53
+ run: |
54
+ CURRENT_VERSION=$(node -p "require('./package.json').version")
55
+ echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
56
+
57
+ - name: Install semver
58
+ run: pnpm add -g semver
59
+
60
+ - name: Determine Version Bump
61
+ id: version_bump
62
+ run: |
63
+ COMMIT_MSG="${{ github.event.head_commit.message }}"
64
+ if [[ $COMMIT_MSG =~ "#release:major" ]]; then
65
+ echo "bump=major" >> $GITHUB_OUTPUT
66
+ elif [[ $COMMIT_MSG =~ "#release:minor" ]]; then
67
+ echo "bump=minor" >> $GITHUB_OUTPUT
68
+ else
69
+ echo "bump=patch" >> $GITHUB_OUTPUT
70
+ fi
71
+
72
+ - name: Bump Version
73
+ id: bump_version
74
+ run: |
75
+ NEW_VERSION=$(semver -i ${{ steps.version_bump.outputs.bump }} ${{ steps.current_version.outputs.version }})
76
+ echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
77
+
78
+ - name: Update Package.json
79
+ run: |
80
+ NEW_VERSION=${{ steps.bump_version.outputs.new_version }}
81
+ pnpm version $NEW_VERSION --no-git-tag-version --allow-same-version
82
+
83
+
84
+ - name: Prepare changelog script
85
+ run: chmod +x .github/scripts/generate-changelog.sh
86
+
87
+ - name: Generate Changelog
88
+ id: changelog
89
+ env:
90
+ NEW_VERSION: ${{ steps.bump_version.outputs.new_version }}
91
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92
+
93
+ run: .github/scripts/generate-changelog.sh
94
+
95
+ - name: Get the latest commit hash and version tag
96
+ run: |
97
+ echo "COMMIT_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV
98
+ echo "NEW_VERSION=${{ steps.bump_version.outputs.new_version }}" >> $GITHUB_ENV
99
+
100
+ - name: Commit and Tag Release
101
+ run: |
102
+ git pull
103
+ git add package.json pnpm-lock.yaml changelog.md
104
+ git commit -m "chore: release version ${{ steps.bump_version.outputs.new_version }}"
105
+ git tag "v${{ steps.bump_version.outputs.new_version }}"
106
+ git push
107
+ git push --tags
108
+
109
+ - name: Update Stable Branch
110
+ run: |
111
+ if ! git checkout stable 2>/dev/null; then
112
+ echo "Creating new stable branch..."
113
+ git checkout -b stable
114
+ fi
115
+ git merge main --no-ff -m "chore: release version ${{ steps.bump_version.outputs.new_version }}"
116
+ git push --set-upstream origin stable --force
117
+
118
+ - name: Create GitHub Release
119
+ env:
120
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
121
+ run: |
122
+ VERSION="v${{ steps.bump_version.outputs.new_version }}"
123
+ gh release create "$VERSION" \
124
+ --title "Release $VERSION" \
125
+ --notes "${{ steps.changelog.outputs.content }}" \
126
+ --target stable
.gitignore ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ logs
2
+ *.log
3
+ npm-debug.log*
4
+ yarn-debug.log*
5
+ yarn-error.log*
6
+ pnpm-debug.log*
7
+ lerna-debug.log*
8
+
9
+ node_modules
10
+ dist
11
+ dist-ssr
12
+ *.local
13
+
14
+ .vscode/*
15
+ .vscode/launch.json
16
+ !.vscode/extensions.json
17
+ .idea
18
+ .DS_Store
19
+ *.suo
20
+ *.ntvs*
21
+ *.njsproj
22
+ *.sln
23
+ *.sw?
24
+
25
+ /.history
26
+ /.cache
27
+ /build
28
+ .env.local
29
+ .env
30
+ .dev.vars
31
+ *.vars
32
+ .wrangler
33
+ _worker.bundle
34
+
35
+ Modelfile
36
+ modelfiles
37
+
38
+ # docs ignore
39
+ site
40
+
41
+ # commit file ignore
42
+ app/commit.json
43
+ messages.json
.husky/_/.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ *
.husky/_/applypatch-msg ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ #!/usr/bin/env sh
2
+ . "$(dirname "$0")/h"
.husky/_/commit-msg ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ #!/usr/bin/env sh
2
+ . "$(dirname "$0")/h"
.husky/_/h ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env sh
2
+ [ "$HUSKY" = "2" ] && set -x
3
+ n=$(basename "$0")
4
+ s=$(dirname "$(dirname "$0")")/$n
5
+
6
+ [ ! -f "$s" ] && exit 0
7
+
8
+ if [ -f "$HOME/.huskyrc" ]; then
9
+ echo "husky - '~/.huskyrc' is DEPRECATED, please move your code to ~/.config/husky/init.sh"
10
+ fi
11
+ i="${XDG_CONFIG_HOME:-$HOME/.config}/husky/init.sh"
12
+ [ -f "$i" ] && . "$i"
13
+
14
+ [ "${HUSKY-}" = "0" ] && exit 0
15
+
16
+ export PATH="node_modules/.bin:$PATH"
17
+ sh -e "$s" "$@"
18
+ c=$?
19
+
20
+ [ $c != 0 ] && echo "husky - $n script failed (code $c)"
21
+ [ $c = 127 ] && echo "husky - command not found in PATH=$PATH"
22
+ exit $c
.husky/_/husky.sh ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ echo "husky - DEPRECATED
2
+
3
+ Please remove the following two lines from $0:
4
+
5
+ #!/usr/bin/env sh
6
+ . \"\$(dirname -- \"\$0\")/_/husky.sh\"
7
+
8
+ They WILL FAIL in v10.0.0
9
+ "
.husky/_/post-applypatch ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ #!/usr/bin/env sh
2
+ . "$(dirname "$0")/h"
.husky/_/post-checkout ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ #!/usr/bin/env sh
2
+ . "$(dirname "$0")/h"
.husky/_/post-commit ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ #!/usr/bin/env sh
2
+ . "$(dirname "$0")/h"
.husky/_/post-merge ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ #!/usr/bin/env sh
2
+ . "$(dirname "$0")/h"
.husky/_/post-rewrite ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ #!/usr/bin/env sh
2
+ . "$(dirname "$0")/h"
.husky/_/pre-applypatch ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ #!/usr/bin/env sh
2
+ . "$(dirname "$0")/h"
.husky/_/pre-auto-gc ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ #!/usr/bin/env sh
2
+ . "$(dirname "$0")/h"
.husky/_/pre-commit ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ #!/usr/bin/env sh
2
+ . "$(dirname "$0")/h"
.husky/_/pre-merge-commit ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ #!/usr/bin/env sh
2
+ . "$(dirname "$0")/h"
.husky/_/pre-push ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ #!/usr/bin/env sh
2
+ . "$(dirname "$0")/h"
.husky/_/pre-rebase ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ #!/usr/bin/env sh
2
+ . "$(dirname "$0")/h"
.husky/_/prepare-commit-msg ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ #!/usr/bin/env sh
2
+ . "$(dirname "$0")/h"
.husky/pre-commit ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+
3
+ echo "🔍 Running pre-commit hook to check the code looks good... 🔍"
4
+
5
+ # Load NVM if available (useful for managing Node.js versions)
6
+ export NVM_DIR="$HOME/.nvm"
7
+ [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
8
+
9
+ # Ensure `pnpm` is available
10
+ echo "Checking if pnpm is available..."
11
+ if ! command -v pnpm >/dev/null 2>&1; then
12
+ echo "❌ pnpm not found! Please ensure pnpm is installed and available in PATH."
13
+ exit 1
14
+ fi
15
+
16
+ # Run typecheck
17
+ echo "Running typecheck..."
18
+ if ! pnpm typecheck; then
19
+ echo "❌ Type checking failed! Please review TypeScript types."
20
+ echo "Once you're done, don't forget to add your changes to the commit! 🚀"
21
+ exit 1
22
+ fi
23
+
24
+ # Run lint
25
+ echo "Running lint..."
26
+ if ! pnpm lint; then
27
+ echo "❌ Linting failed! Run 'pnpm lint:fix' to fix the easy issues."
28
+ echo "Once you're done, don't forget to add your beautification to the commit! 🤩"
29
+ exit 1
30
+ fi
31
+
32
+ echo "👍 All checks passed! Committing changes..."
.prettierignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ pnpm-lock.yaml
2
+ .astro
.prettierrc ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "printWidth": 120,
3
+ "singleQuote": true,
4
+ "useTabs": false,
5
+ "tabWidth": 2,
6
+ "semi": true,
7
+ "bracketSpacing": true
8
+ }
.tool-versions ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ nodejs 20.15.1
2
+ pnpm 9.4.0
CONTRIBUTING.md ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Contribution Guidelines
2
+
3
+ Welcome! This guide provides all the details you need to contribute effectively to the project. Thank you for helping us make **bolt.diy** a better tool for developers worldwide. 💡
4
+
5
+ ---
6
+
7
+ ## 📋 Table of Contents
8
+
9
+ 1. [Code of Conduct](#code-of-conduct)
10
+ 2. [How Can I Contribute?](#how-can-i-contribute)
11
+ 3. [Pull Request Guidelines](#pull-request-guidelines)
12
+ 4. [Coding Standards](#coding-standards)
13
+ 5. [Development Setup](#development-setup)
14
+ 6. [Testing](#testing)
15
+ 7. [Deployment](#deployment)
16
+ 8. [Docker Deployment](#docker-deployment)
17
+ 9. [VS Code Dev Containers Integration](#vs-code-dev-containers-integration)
18
+
19
+ ---
20
+
21
+ ## 🛡️ Code of Conduct
22
+
23
+ This project is governed by our **Code of Conduct**. By participating, you agree to uphold this code. Report unacceptable behavior to the project maintainers.
24
+
25
+ ---
26
+
27
+ ## 🛠️ How Can I Contribute?
28
+
29
+ ### 1️⃣ Reporting Bugs or Feature Requests
30
+ - Check the [issue tracker](#) to avoid duplicates.
31
+ - Use issue templates (if available).
32
+ - Provide detailed, relevant information and steps to reproduce bugs.
33
+
34
+ ### 2️⃣ Code Contributions
35
+ 1. Fork the repository.
36
+ 2. Create a feature or fix branch.
37
+ 3. Write and test your code.
38
+ 4. Submit a pull request (PR).
39
+
40
+ ### 3️⃣ Join as a Core Contributor
41
+ Interested in maintaining and growing the project? Fill out our [Contributor Application Form](https://forms.gle/TBSteXSDCtBDwr5m7).
42
+
43
+ ---
44
+
45
+ ## ✅ Pull Request Guidelines
46
+
47
+ ### PR Checklist
48
+ - Branch from the **main** branch.
49
+ - Update documentation, if needed.
50
+ - Test all functionality manually.
51
+ - Focus on one feature/bug per PR.
52
+
53
+ ### Review Process
54
+ 1. Manual testing by reviewers.
55
+ 2. At least one maintainer review required.
56
+ 3. Address review comments.
57
+ 4. Maintain a clean commit history.
58
+
59
+ ---
60
+
61
+ ## 📏 Coding Standards
62
+
63
+ ### General Guidelines
64
+ - Follow existing code style.
65
+ - Comment complex logic.
66
+ - Keep functions small and focused.
67
+ - Use meaningful variable names.
68
+
69
+ ---
70
+
71
+ ## 🖥️ Development Setup
72
+
73
+ ### 1️⃣ Initial Setup
74
+ - Clone the repository:
75
+ ```bash
76
+ git clone https://github.com/stackblitz-labs/bolt.diy.git
77
+ ```
78
+ - Install dependencies:
79
+ ```bash
80
+ pnpm install
81
+ ```
82
+ - Set up environment variables:
83
+ 1. Rename `.env.example` to `.env.local`.
84
+ 2. Add your API keys:
85
+ ```bash
86
+ GROQ_API_KEY=XXX
87
+ HuggingFace_API_KEY=XXX
88
+ OPENAI_API_KEY=XXX
89
+ ...
90
+ ```
91
+ 3. Optionally set:
92
+ - Debug level: `VITE_LOG_LEVEL=debug`
93
+ - Context size: `DEFAULT_NUM_CTX=32768`
94
+
95
+ **Note**: Never commit your `.env.local` file to version control. It’s already in `.gitignore`.
96
+
97
+ ### 2️⃣ Run Development Server
98
+ ```bash
99
+ pnpm run dev
100
+ ```
101
+ **Tip**: Use **Google Chrome Canary** for local testing.
102
+
103
+ ---
104
+
105
+ ## 🧪 Testing
106
+
107
+ Run the test suite with:
108
+ ```bash
109
+ pnpm test
110
+ ```
111
+
112
+ ---
113
+
114
+ ## 🚀 Deployment
115
+
116
+ ### Deploy to Cloudflare Pages
117
+ ```bash
118
+ pnpm run deploy
119
+ ```
120
+ Ensure you have required permissions and that Wrangler is configured.
121
+
122
+ ---
123
+
124
+ ## 🐳 Docker Deployment
125
+
126
+ This section outlines the methods for deploying the application using Docker. The processes for **Development** and **Production** are provided separately for clarity.
127
+
128
+ ---
129
+
130
+ ### 🧑‍💻 Development Environment
131
+
132
+ #### Build Options
133
+
134
+ **Option 1: Helper Scripts**
135
+ ```bash
136
+ # Development build
137
+ npm run dockerbuild
138
+ ```
139
+
140
+ **Option 2: Direct Docker Build Command**
141
+ ```bash
142
+ docker build . --target bolt-ai-development
143
+ ```
144
+
145
+ **Option 3: Docker Compose Profile**
146
+ ```bash
147
+ docker-compose --profile development up
148
+ ```
149
+
150
+ #### Running the Development Container
151
+ ```bash
152
+ docker run -p 5173:5173 --env-file .env.local bolt-ai:development
153
+ ```
154
+
155
+ ---
156
+
157
+ ### 🏭 Production Environment
158
+
159
+ #### Build Options
160
+
161
+ **Option 1: Helper Scripts**
162
+ ```bash
163
+ # Production build
164
+ npm run dockerbuild:prod
165
+ ```
166
+
167
+ **Option 2: Direct Docker Build Command**
168
+ ```bash
169
+ docker build . --target bolt-ai-production
170
+ ```
171
+
172
+ **Option 3: Docker Compose Profile**
173
+ ```bash
174
+ docker-compose --profile production up
175
+ ```
176
+
177
+ #### Running the Production Container
178
+ ```bash
179
+ docker run -p 5173:5173 --env-file .env.local bolt-ai:production
180
+ ```
181
+
182
+ ---
183
+
184
+ ### Coolify Deployment
185
+
186
+ For an easy deployment process, use [Coolify](https://github.com/coollabsio/coolify):
187
+ 1. Import your Git repository into Coolify.
188
+ 2. Choose **Docker Compose** as the build pack.
189
+ 3. Configure environment variables (e.g., API keys).
190
+ 4. Set the start command:
191
+ ```bash
192
+ docker compose --profile production up
193
+ ```
194
+
195
+ ---
196
+
197
+ ## 🛠️ VS Code Dev Containers Integration
198
+
199
+ The `docker-compose.yaml` configuration is compatible with **VS Code Dev Containers**, making it easy to set up a development environment directly in Visual Studio Code.
200
+
201
+ ### Steps to Use Dev Containers
202
+
203
+ 1. Open the command palette in VS Code (`Ctrl+Shift+P` or `Cmd+Shift+P` on macOS).
204
+ 2. Select **Dev Containers: Reopen in Container**.
205
+ 3. Choose the **development** profile when prompted.
206
+ 4. VS Code will rebuild the container and open it with the pre-configured environment.
207
+
208
+ ---
209
+
210
+ ## 🔑 Environment Variables
211
+
212
+ Ensure `.env.local` is configured correctly with:
213
+ - API keys.
214
+ - Context-specific configurations.
215
+
216
+ Example for the `DEFAULT_NUM_CTX` variable:
217
+ ```bash
218
+ DEFAULT_NUM_CTX=24576 # Uses 32GB VRAM
219
+ ```
Dockerfile ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ARG BASE=node:20.18.0
2
+ FROM ${BASE} AS base
3
+
4
+ WORKDIR /app
5
+
6
+ # Install dependencies (this step is cached as long as the dependencies don't change)
7
+ COPY package.json pnpm-lock.yaml ./
8
+
9
+ RUN corepack enable pnpm && pnpm install
10
+
11
+ # Copy the rest of your app's source code
12
+ COPY . .
13
+
14
+ # Expose the port the app runs on
15
+ EXPOSE 5173
16
+
17
+ # Production image
18
+ FROM base AS bolt-ai-production
19
+
20
+ # Define environment variables with default values or let them be overridden
21
+ ARG GROQ_API_KEY
22
+ ARG HuggingFace_API_KEY
23
+ ARG OPENAI_API_KEY
24
+ ARG ANTHROPIC_API_KEY
25
+ ARG OPEN_ROUTER_API_KEY
26
+ ARG GOOGLE_GENERATIVE_AI_API_KEY
27
+ ARG OLLAMA_API_BASE_URL
28
+ ARG XAI_API_KEY
29
+ ARG TOGETHER_API_KEY
30
+ ARG TOGETHER_API_BASE_URL
31
+ ARG VITE_LOG_LEVEL=debug
32
+ ARG DEFAULT_NUM_CTX
33
+
34
+ ENV WRANGLER_SEND_METRICS=false \
35
+ GROQ_API_KEY=${GROQ_API_KEY} \
36
+ HuggingFace_KEY=${HuggingFace_API_KEY} \
37
+ OPENAI_API_KEY=${OPENAI_API_KEY} \
38
+ ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY} \
39
+ OPEN_ROUTER_API_KEY=${OPEN_ROUTER_API_KEY} \
40
+ GOOGLE_GENERATIVE_AI_API_KEY=${GOOGLE_GENERATIVE_AI_API_KEY} \
41
+ OLLAMA_API_BASE_URL=${OLLAMA_API_BASE_URL} \
42
+ XAI_API_KEY=${XAI_API_KEY} \
43
+ TOGETHER_API_KEY=${TOGETHER_API_KEY} \
44
+ TOGETHER_API_BASE_URL=${TOGETHER_API_BASE_URL} \
45
+ VITE_LOG_LEVEL=${VITE_LOG_LEVEL} \
46
+ DEFAULT_NUM_CTX=${DEFAULT_NUM_CTX}
47
+
48
+ # Pre-configure wrangler to disable metrics
49
+ RUN mkdir -p /root/.config/.wrangler && \
50
+ echo '{"enabled":false}' > /root/.config/.wrangler/metrics.json
51
+
52
+ RUN npm run build
53
+
54
+ CMD [ "pnpm", "run", "dockerstart"]
55
+
56
+ # Development image
57
+ FROM base AS bolt-ai-development
58
+
59
+ # Define the same environment variables for development
60
+ ARG GROQ_API_KEY
61
+ ARG HuggingFace
62
+ ARG OPENAI_API_KEY
63
+ ARG ANTHROPIC_API_KEY
64
+ ARG OPEN_ROUTER_API_KEY
65
+ ARG GOOGLE_GENERATIVE_AI_API_KEY
66
+ ARG OLLAMA_API_BASE_URL
67
+ ARG XAI_API_KEY
68
+ ARG TOGETHER_API_KEY
69
+ ARG TOGETHER_API_BASE_URL
70
+ ARG VITE_LOG_LEVEL=debug
71
+ ARG DEFAULT_NUM_CTX
72
+
73
+ ENV GROQ_API_KEY=${GROQ_API_KEY} \
74
+ HuggingFace_API_KEY=${HuggingFace_API_KEY} \
75
+ OPENAI_API_KEY=${OPENAI_API_KEY} \
76
+ ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY} \
77
+ OPEN_ROUTER_API_KEY=${OPEN_ROUTER_API_KEY} \
78
+ GOOGLE_GENERATIVE_AI_API_KEY=${GOOGLE_GENERATIVE_AI_API_KEY} \
79
+ OLLAMA_API_BASE_URL=${OLLAMA_API_BASE_URL} \
80
+ XAI_API_KEY=${XAI_API_KEY} \
81
+ TOGETHER_API_KEY=${TOGETHER_API_KEY} \
82
+ TOGETHER_API_BASE_URL=${TOGETHER_API_BASE_URL} \
83
+ VITE_LOG_LEVEL=${VITE_LOG_LEVEL} \
84
+ DEFAULT_NUM_CTX=${DEFAULT_NUM_CTX}
85
+
86
+ RUN mkdir -p ${WORKDIR}/run
87
+ CMD pnpm run dev --host
FAQ.md ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Frequently Asked Questions (FAQ)
2
+
3
+ <details>
4
+ <summary><strong>What are the best models for bolt.diy?</strong></summary>
5
+
6
+ For the best experience with bolt.diy, we recommend using the following models:
7
+
8
+ - **Claude 3.5 Sonnet (old)**: Best overall coder, providing excellent results across all use cases
9
+ - **Gemini 2.0 Flash**: Exceptional speed while maintaining good performance
10
+ - **GPT-4o**: Strong alternative to Claude 3.5 Sonnet with comparable capabilities
11
+ - **DeepSeekCoder V2 236b**: Best open source model (available through OpenRouter, DeepSeek API, or self-hosted)
12
+ - **Qwen 2.5 Coder 32b**: Best model for self-hosting with reasonable hardware requirements
13
+
14
+ **Note**: Models with less than 7b parameters typically lack the capability to properly interact with bolt!
15
+ </details>
16
+
17
+ <details>
18
+ <summary><strong>How do I get the best results with bolt.diy?</strong></summary>
19
+
20
+ - **Be specific about your stack**:
21
+ Mention the frameworks or libraries you want to use (e.g., Astro, Tailwind, ShadCN) in your initial prompt. This ensures that bolt.diy scaffolds the project according to your preferences.
22
+
23
+ - **Use the enhance prompt icon**:
24
+ Before sending your prompt, click the *enhance* icon to let the AI refine your prompt. You can edit the suggested improvements before submitting.
25
+
26
+ - **Scaffold the basics first, then add features**:
27
+ Ensure the foundational structure of your application is in place before introducing advanced functionality. This helps bolt.diy establish a solid base to build on.
28
+
29
+ - **Batch simple instructions**:
30
+ Combine simple tasks into a single prompt to save time and reduce API credit consumption. For example:
31
+ *"Change the color scheme, add mobile responsiveness, and restart the dev server."*
32
+ </details>
33
+
34
+ <details>
35
+ <summary><strong>How do I contribute to bolt.diy?</strong></summary>
36
+
37
+ Check out our [Contribution Guide](CONTRIBUTING.md) for more details on how to get involved!
38
+ </details>
39
+
40
+ <details>
41
+ <summary><strong>What are the future plans for bolt.diy?</strong></summary>
42
+
43
+ Visit our [Roadmap](https://roadmap.sh/r/ottodev-roadmap-2ovzo) for the latest updates.
44
+ New features and improvements are on the way!
45
+ </details>
46
+
47
+ <details>
48
+ <summary><strong>Why are there so many open issues/pull requests?</strong></summary>
49
+
50
+ bolt.diy began as a small showcase project on @ColeMedin's YouTube channel to explore editing open-source projects with local LLMs. However, it quickly grew into a massive community effort!
51
+
52
+ We're forming a team of maintainers to manage demand and streamline issue resolution. The maintainers are rockstars, and we're also exploring partnerships to help the project thrive.
53
+ </details>
54
+
55
+ <details>
56
+ <summary><strong>How do local LLMs compare to larger models like Claude 3.5 Sonnet for bolt.diy?</strong></summary>
57
+
58
+ While local LLMs are improving rapidly, larger models like GPT-4o, Claude 3.5 Sonnet, and DeepSeek Coder V2 236b still offer the best results for complex applications. Our ongoing focus is to improve prompts, agents, and the platform to better support smaller local LLMs.
59
+ </details>
60
+
61
+ <details>
62
+ <summary><strong>Common Errors and Troubleshooting</strong></summary>
63
+
64
+ ### **"There was an error processing this request"**
65
+ This generic error message means something went wrong. Check both:
66
+ - The terminal (if you started the app with Docker or `pnpm`).
67
+ - The developer console in your browser (press `F12` or right-click > *Inspect*, then go to the *Console* tab).
68
+
69
+ ### **"x-api-key header missing"**
70
+ This error is sometimes resolved by restarting the Docker container.
71
+ If that doesn't work, try switching from Docker to `pnpm` or vice versa. We're actively investigating this issue.
72
+
73
+ ### **Blank preview when running the app**
74
+ A blank preview often occurs due to hallucinated bad code or incorrect commands.
75
+ To troubleshoot:
76
+ - Check the developer console for errors.
77
+ - Remember, previews are core functionality, so the app isn't broken! We're working on making these errors more transparent.
78
+
79
+ ### **"Everything works, but the results are bad"**
80
+ Local LLMs like Qwen-2.5-Coder are powerful for small applications but still experimental for larger projects. For better results, consider using larger models like GPT-4o, Claude 3.5 Sonnet, or DeepSeek Coder V2 236b.
81
+
82
+ ### **"Received structured exception #0xc0000005: access violation"**
83
+ If you are getting this, you are probably on Windows. The fix is generally to update the [Visual C++ Redistributable](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170)
84
+
85
+ ### **"Miniflare or Wrangler errors in Windows"**
86
+ You will need to make sure you have the latest version of Visual Studio C++ installed (14.40.33816), more information here https://github.com/stackblitz-labs/bolt.diy/issues/19.
87
+ </details>
88
+
89
+ ---
90
+
91
+ Got more questions? Feel free to reach out or open an issue in our GitHub repo!
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2024 StackBlitz, Inc. and bolt.diy contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md CHANGED
@@ -1,10 +1,327 @@
1
- ---
2
- title: Bolt.diy
3
- emoji: 📉
4
- colorFrom: indigo
5
- colorTo: gray
6
- sdk: docker
7
- pinned: false
8
- ---
9
-
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # bolt.diy (Previously oTToDev)
2
+ [![bolt.diy: AI-Powered Full-Stack Web Development in the Browser](./public/social_preview_index.jpg)](https://bolt.diy)
3
+
4
+ Welcome to bolt.diy, the official open source version of Bolt.new (previously known as oTToDev and bolt.new ANY LLM), which allows you to choose the LLM that you use for each prompt! Currently, you can use OpenAI, Anthropic, Ollama, OpenRouter, Gemini, LMStudio, Mistral, xAI, HuggingFace, DeepSeek, or Groq models - and it is easily extended to use any other model supported by the Vercel AI SDK! See the instructions below for running this locally and extending it to include more models.
5
+
6
+ Check the [bolt.diy Docs](https://stackblitz-labs.github.io/bolt.diy/) for more information.
7
+
8
+ We have also launched an experimental agent called the "bolt.diy Expert" that can answer common questions about bolt.diy. Find it here on the [oTTomator Live Agent Studio](https://studio.ottomator.ai/).
9
+
10
+ bolt.diy was originally started by [Cole Medin](https://www.youtube.com/@ColeMedin) but has quickly grown into a massive community effort to build the BEST open source AI coding assistant!
11
+
12
+ ## Table of Contents
13
+
14
+ - [Join the Community](#join-the-community)
15
+ - [Requested Additions](#requested-additions)
16
+ - [Features](#features)
17
+ - [Setup](#setup)
18
+ - [Run the Application](#run-the-application)
19
+ - [Available Scripts](#available-scripts)
20
+ - [Contributing](#contributing)
21
+ - [Roadmap](#roadmap)
22
+ - [FAQ](#faq)
23
+
24
+ ## Join the community
25
+
26
+ [Join the bolt.diy community here, in the thinktank on ottomator.ai!](https://thinktank.ottomator.ai)
27
+
28
+
29
+ ## Requested Additions
30
+
31
+ - ✅ OpenRouter Integration (@coleam00)
32
+ - ✅ Gemini Integration (@jonathands)
33
+ - ✅ Autogenerate Ollama models from what is downloaded (@yunatamos)
34
+ - ✅ Filter models by provider (@jasonm23)
35
+ - ✅ Download project as ZIP (@fabwaseem)
36
+ - ✅ Improvements to the main bolt.new prompt in `app\lib\.server\llm\prompts.ts` (@kofi-bhr)
37
+ - ✅ DeepSeek API Integration (@zenith110)
38
+ - ✅ Mistral API Integration (@ArulGandhi)
39
+ - ✅ "Open AI Like" API Integration (@ZerxZ)
40
+ - ✅ Ability to sync files (one way sync) to local folder (@muzafferkadir)
41
+ - ✅ Containerize the application with Docker for easy installation (@aaronbolton)
42
+ - ✅ Publish projects directly to GitHub (@goncaloalves)
43
+ - ✅ Ability to enter API keys in the UI (@ali00209)
44
+ - ✅ xAI Grok Beta Integration (@milutinke)
45
+ - ✅ LM Studio Integration (@karrot0)
46
+ - ✅ HuggingFace Integration (@ahsan3219)
47
+ - ✅ Bolt terminal to see the output of LLM run commands (@thecodacus)
48
+ - ✅ Streaming of code output (@thecodacus)
49
+ - ✅ Ability to revert code to earlier version (@wonderwhy-er)
50
+ - ✅ Cohere Integration (@hasanraiyan)
51
+ - ✅ Dynamic model max token length (@hasanraiyan)
52
+ - ✅ Better prompt enhancing (@SujalXplores)
53
+ - ✅ Prompt caching (@SujalXplores)
54
+ - ✅ Load local projects into the app (@wonderwhy-er)
55
+ - ✅ Together Integration (@mouimet-infinisoft)
56
+ - ✅ Mobile friendly (@qwikode)
57
+ - ✅ Better prompt enhancing (@SujalXplores)
58
+ - ✅ Attach images to prompts (@atrokhym)
59
+ - ✅ Added Git Clone button (@thecodacus)
60
+ - ✅ Git Import from url (@thecodacus)
61
+ - ✅ PromptLibrary to have different variations of prompts for different use cases (@thecodacus)
62
+ - ✅ Detect package.json and commands to auto install & run preview for folder and git import (@wonderwhy-er)
63
+ - ✅ Selection tool to target changes visually (@emcconnell)
64
+ - ✅ Detect terminal Errors and ask bolt to fix it (@thecodacus)
65
+ - ✅ Detect preview Errors and ask bolt to fix it (@wonderwhy-er)
66
+ - ✅ Add Starter Template Options (@thecodacus)
67
+ - ⬜ **HIGH PRIORITY** - Prevent bolt from rewriting files as often (file locking and diffs)
68
+ - ⬜ **HIGH PRIORITY** - Better prompting for smaller LLMs (code window sometimes doesn't start)
69
+ - ⬜ **HIGH PRIORITY** - Run agents in the backend as opposed to a single model call
70
+ - ✅ Add Prompt Caching Support for Claude models - upto 90% cost reduction (@aproli90)
71
+ - ⬜ Deploy directly to Vercel/Netlify/other similar platforms
72
+ - ⬜ Have LLM plan the project in a MD file for better results/transparency
73
+ - ⬜ VSCode Integration with git-like confirmations
74
+ - ⬜ Upload documents for knowledge - UI design templates, a code base to reference coding style, etc.
75
+ - ⬜ Voice prompting
76
+ - ⬜ Azure Open AI API Integration
77
+ - ✅ Perplexity Integration (@meetpateltech)
78
+ - ⬜ Vertex AI Integration
79
+
80
+ ## Features
81
+
82
+ - **AI-powered full-stack web development** directly in your browser.
83
+ - **Support for multiple LLMs** with an extensible architecture to integrate additional models.
84
+ - **Attach images to prompts** for better contextual understanding.
85
+ - **Integrated terminal** to view output of LLM-run commands.
86
+ - **Revert code to earlier versions** for easier debugging and quicker changes.
87
+ - **Download projects as ZIP** for easy portability.
88
+ - **Integration-ready Docker support** for a hassle-free setup.
89
+
90
+ ## Setup
91
+
92
+ If you're new to installing software from GitHub, don't worry! If you encounter any issues, feel free to submit an "issue" using the provided links or improve this documentation by forking the repository, editing the instructions, and submitting a pull request. The following instruction will help you get the stable branch up and running on your local machine in no time.
93
+
94
+ Let's get you up and running with the stable version of Bolt.DIY!
95
+
96
+ ## Quick Download
97
+
98
+ [![Download Latest Release](https://img.shields.io/github/v/release/stackblitz-labs/bolt.diy?label=Download%20Bolt&sort=semver)](https://github.com/stackblitz-labs/bolt.diy/releases/latest) ← Click here to go the the latest release version!
99
+
100
+ - Next **click source.zip**
101
+
102
+
103
+
104
+
105
+ ## Prerequisites
106
+
107
+ Before you begin, you'll need to install two important pieces of software:
108
+
109
+ ### Install Node.js
110
+
111
+ Node.js is required to run the application.
112
+
113
+ 1. Visit the [Node.js Download Page](https://nodejs.org/en/download/)
114
+ 2. Download the "LTS" (Long Term Support) version for your operating system
115
+ 3. Run the installer, accepting the default settings
116
+ 4. Verify Node.js is properly installed:
117
+ - **For Windows Users**:
118
+ 1. Press `Windows + R`
119
+ 2. Type "sysdm.cpl" and press Enter
120
+ 3. Go to "Advanced" tab → "Environment Variables"
121
+ 4. Check if `Node.js` appears in the "Path" variable
122
+ - **For Mac/Linux Users**:
123
+ 1. Open Terminal
124
+ 2. Type this command:
125
+ ```bash
126
+ echo $PATH
127
+ ```
128
+ 3. Look for `/usr/local/bin` in the output
129
+
130
+ ## Running the Application
131
+
132
+ You have two options for running Bolt.DIY: directly on your machine or using Docker.
133
+
134
+ ### Option 1: Direct Installation (Recommended for Beginners)
135
+
136
+ 1. **Install Package Manager (pnpm)**:
137
+ ```bash
138
+ npm install -g pnpm
139
+ ```
140
+
141
+ 2. **Install Project Dependencies**:
142
+ ```bash
143
+ pnpm install
144
+ ```
145
+
146
+ 3. **Start the Application**:
147
+ ```bash
148
+ pnpm run dev
149
+ ```
150
+
151
+ **Important Note**: If you're using Google Chrome, you'll need Chrome Canary for local development. [Download it here](https://www.google.com/chrome/canary/)
152
+
153
+ ### Option 2: Using Docker
154
+
155
+ This option requires some familiarity with Docker but provides a more isolated environment.
156
+
157
+ #### Additional Prerequisite
158
+ - Install Docker: [Download Docker](https://www.docker.com/)
159
+
160
+ #### Steps:
161
+
162
+ 1. **Build the Docker Image**:
163
+ ```bash
164
+ # Using npm script:
165
+ npm run dockerbuild
166
+
167
+ # OR using direct Docker command:
168
+ docker build . --target bolt-ai-development
169
+ ```
170
+
171
+ 2. **Run the Container**:
172
+ ```bash
173
+ docker-compose --profile development up
174
+ ```
175
+
176
+
177
+
178
+
179
+ ## Configuring API Keys and Providers
180
+
181
+ ### Adding Your API Keys
182
+
183
+ Setting up your API keys in Bolt.DIY is straightforward:
184
+
185
+ 1. Open the home page (main interface)
186
+ 2. Select your desired provider from the dropdown menu
187
+ 3. Click the pencil (edit) icon
188
+ 4. Enter your API key in the secure input field
189
+
190
+ ![API Key Configuration Interface](./docs/images/api-key-ui-section.png)
191
+
192
+ ### Configuring Custom Base URLs
193
+
194
+ For providers that support custom base URLs (such as Ollama or LM Studio), follow these steps:
195
+
196
+ 1. Click the settings icon in the sidebar to open the settings menu
197
+ ![Settings Button Location](./docs/images/bolt-settings-button.png)
198
+
199
+ 2. Navigate to the "Providers" tab
200
+ 3. Search for your provider using the search bar
201
+ 4. Enter your custom base URL in the designated field
202
+ ![Provider Base URL Configuration](./docs/images/provider-base-url.png)
203
+
204
+ > **Note**: Custom base URLs are particularly useful when running local instances of AI models or using custom API endpoints.
205
+
206
+ ### Supported Providers
207
+ - Ollama
208
+ - LM Studio
209
+ - OpenAILike
210
+
211
+ ## Setup Using Git (For Developers only)
212
+
213
+ This method is recommended for developers who want to:
214
+ - Contribute to the project
215
+ - Stay updated with the latest changes
216
+ - Switch between different versions
217
+ - Create custom modifications
218
+
219
+ #### Prerequisites
220
+ 1. Install Git: [Download Git](https://git-scm.com/downloads)
221
+
222
+ #### Initial Setup
223
+
224
+ 1. **Clone the Repository**:
225
+ ```bash
226
+ # Using HTTPS
227
+ git clone https://github.com/stackblitz-labs/bolt.diy.git
228
+ ```
229
+
230
+ 2. **Navigate to Project Directory**:
231
+ ```bash
232
+ cd bolt.diy
233
+ ```
234
+
235
+ 3. **Switch to the Main Branch**:
236
+ ```bash
237
+ git checkout main
238
+ ```
239
+ 4. **Install Dependencies**:
240
+ ```bash
241
+ pnpm install
242
+ ```
243
+
244
+ 5. **Start the Development Server**:
245
+ ```bash
246
+ pnpm run dev
247
+ ```
248
+
249
+ #### Staying Updated
250
+
251
+ To get the latest changes from the repository:
252
+
253
+ 1. **Save Your Local Changes** (if any):
254
+ ```bash
255
+ git stash
256
+ ```
257
+
258
+ 2. **Pull Latest Updates**:
259
+ ```bash
260
+ git pull origin main
261
+ ```
262
+
263
+ 3. **Update Dependencies**:
264
+ ```bash
265
+ pnpm install
266
+ ```
267
+
268
+ 4. **Restore Your Local Changes** (if any):
269
+ ```bash
270
+ git stash pop
271
+ ```
272
+
273
+ #### Troubleshooting Git Setup
274
+
275
+ If you encounter issues:
276
+
277
+ 1. **Clean Installation**:
278
+ ```bash
279
+ # Remove node modules and lock files
280
+ rm -rf node_modules pnpm-lock.yaml
281
+
282
+ # Clear pnpm cache
283
+ pnpm store prune
284
+
285
+ # Reinstall dependencies
286
+ pnpm install
287
+ ```
288
+
289
+ 2. **Reset Local Changes**:
290
+ ```bash
291
+ # Discard all local changes
292
+ git reset --hard origin/main
293
+ ```
294
+
295
+ Remember to always commit your local changes or stash them before pulling updates to avoid conflicts.
296
+
297
+ ---
298
+
299
+ ## Available Scripts
300
+
301
+ - **`pnpm run dev`**: Starts the development server.
302
+ - **`pnpm run build`**: Builds the project.
303
+ - **`pnpm run start`**: Runs the built application locally using Wrangler Pages.
304
+ - **`pnpm run preview`**: Builds and runs the production build locally.
305
+ - **`pnpm test`**: Runs the test suite using Vitest.
306
+ - **`pnpm run typecheck`**: Runs TypeScript type checking.
307
+ - **`pnpm run typegen`**: Generates TypeScript types using Wrangler.
308
+ - **`pnpm run deploy`**: Deploys the project to Cloudflare Pages.
309
+ - **`pnpm run lint:fix`**: Automatically fixes linting issues.
310
+
311
+ ---
312
+
313
+ ## Contributing
314
+
315
+ We welcome contributions! Check out our [Contributing Guide](CONTRIBUTING.md) to get started.
316
+
317
+ ---
318
+
319
+ ## Roadmap
320
+
321
+ Explore upcoming features and priorities on our [Roadmap](https://roadmap.sh/r/ottodev-roadmap-2ovzo).
322
+
323
+ ---
324
+
325
+ ## FAQ
326
+
327
+ For answers to common questions, issues, and to see a list of recommended models, visit our [FAQ Page](FAQ.md).
app/components/chat/APIKeyManager.tsx ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React, { useState, useEffect } from 'react';
2
+ import { IconButton } from '~/components/ui/IconButton';
3
+ import { Switch } from '~/components/ui/Switch';
4
+ import type { ProviderInfo } from '~/types/model';
5
+ import Cookies from 'js-cookie';
6
+
7
+ interface APIKeyManagerProps {
8
+ provider: ProviderInfo;
9
+ apiKey: string;
10
+ setApiKey: (key: string) => void;
11
+ getApiKeyLink?: string;
12
+ labelForGetApiKey?: string;
13
+ }
14
+
15
+ const apiKeyMemoizeCache: { [k: string]: Record<string, string> } = {};
16
+
17
+ export function getApiKeysFromCookies() {
18
+ const storedApiKeys = Cookies.get('apiKeys');
19
+ let parsedKeys = {};
20
+
21
+ if (storedApiKeys) {
22
+ parsedKeys = apiKeyMemoizeCache[storedApiKeys];
23
+
24
+ if (!parsedKeys) {
25
+ parsedKeys = apiKeyMemoizeCache[storedApiKeys] = JSON.parse(storedApiKeys);
26
+ }
27
+ }
28
+
29
+ return parsedKeys;
30
+ }
31
+
32
+ // eslint-disable-next-line @typescript-eslint/naming-convention
33
+ export const APIKeyManager: React.FC<APIKeyManagerProps> = ({ provider, apiKey, setApiKey }) => {
34
+ const [isEditing, setIsEditing] = useState(false);
35
+ const [tempKey, setTempKey] = useState(apiKey);
36
+ const [isPromptCachingEnabled, setIsPromptCachingEnabled] = useState(() => {
37
+ // Read initial state from localStorage, defaulting to true
38
+ const savedState = localStorage.getItem('PROMPT_CACHING_ENABLED');
39
+ return savedState !== null ? JSON.parse(savedState) : true;
40
+ });
41
+
42
+ useEffect(() => {
43
+ // Update localStorage whenever the prompt caching state changes
44
+ localStorage.setItem('PROMPT_CACHING_ENABLED', JSON.stringify(isPromptCachingEnabled));
45
+ }, [isPromptCachingEnabled]);
46
+
47
+ const handleSave = () => {
48
+ setApiKey(tempKey);
49
+ setIsEditing(false);
50
+ };
51
+
52
+ return (
53
+ <div className="space-y-4">
54
+ <div className="flex items-start sm:items-center mt-2 mb-2 flex-col sm:flex-row">
55
+ <div>
56
+ <span className="text-sm text-bolt-elements-textSecondary">{provider?.name} API Key:</span>
57
+ {!isEditing && (
58
+ <div className="flex items-center">
59
+ <span className="flex-1 text-xs text-bolt-elements-textPrimary mr-2">
60
+ {apiKey ? '••••••••' : 'Not set (will still work if set in .env file)'}
61
+ </span>
62
+ <IconButton onClick={() => setIsEditing(true)} title="Edit API Key">
63
+ <div className="i-ph:pencil-simple" />
64
+ </IconButton>
65
+ </div>
66
+ )}
67
+ </div>
68
+
69
+ {isEditing ? (
70
+ <div className="flex items-center gap-3 mt-2">
71
+ <input
72
+ type="password"
73
+ value={tempKey}
74
+ placeholder="Your API Key"
75
+ onChange={(e) => setTempKey(e.target.value)}
76
+ className="flex-1 px-2 py-1 text-xs lg:text-sm rounded border border-bolt-elements-borderColor bg-bolt-elements-prompt-background text-bolt-elements-textPrimary focus:outline-none focus:ring-2 focus:ring-bolt-elements-focus"
77
+ />
78
+ <IconButton onClick={handleSave} title="Save API Key">
79
+ <div className="i-ph:check" />
80
+ </IconButton>
81
+ <IconButton onClick={() => setIsEditing(false)} title="Cancel">
82
+ <div className="i-ph:x" />
83
+ </IconButton>
84
+ </div>
85
+ ) : (
86
+ <>
87
+ {provider?.getApiKeyLink && (
88
+ <IconButton className="ml-auto" onClick={() => window.open(provider?.getApiKeyLink)} title="Edit API Key">
89
+ <span className="mr-2 text-xs lg:text-sm">{provider?.labelForGetApiKey || 'Get API Key'}</span>
90
+ <div className={provider?.icon || 'i-ph:key'} />
91
+ </IconButton>
92
+ )}
93
+ </>
94
+ )}
95
+ </div>
96
+
97
+ {provider?.name === 'Anthropic' && (
98
+ <div className="border-t pt-4 pb-4 -mt-4">
99
+ <div className="flex items-center space-x-2">
100
+ <Switch checked={isPromptCachingEnabled} onCheckedChange={setIsPromptCachingEnabled} />
101
+ <label htmlFor="prompt-caching" className="text-sm text-bolt-elements-textSecondary">
102
+ Enable Prompt Caching
103
+ </label>
104
+ </div>
105
+ <p className="text-xs text-bolt-elements-textTertiary mt-2">
106
+ When enabled, allows caching of prompts for 10x cheaper responses. Recommended for Claude models.
107
+ </p>
108
+ </div>
109
+ )}
110
+ </div>
111
+ );
112
+ };
app/components/chat/Artifact.tsx ADDED
@@ -0,0 +1,263 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useStore } from '@nanostores/react';
2
+ import { AnimatePresence, motion } from 'framer-motion';
3
+ import { computed } from 'nanostores';
4
+ import { memo, useEffect, useRef, useState } from 'react';
5
+ import { createHighlighter, type BundledLanguage, type BundledTheme, type HighlighterGeneric } from 'shiki';
6
+ import type { ActionState } from '~/lib/runtime/action-runner';
7
+ import { workbenchStore } from '~/lib/stores/workbench';
8
+ import { classNames } from '~/utils/classNames';
9
+ import { cubicEasingFn } from '~/utils/easings';
10
+ import { WORK_DIR } from '~/utils/constants';
11
+
12
+ const highlighterOptions = {
13
+ langs: ['shell'],
14
+ themes: ['light-plus', 'dark-plus'],
15
+ };
16
+
17
+ const shellHighlighter: HighlighterGeneric<BundledLanguage, BundledTheme> =
18
+ import.meta.hot?.data.shellHighlighter ?? (await createHighlighter(highlighterOptions));
19
+
20
+ if (import.meta.hot) {
21
+ import.meta.hot.data.shellHighlighter = shellHighlighter;
22
+ }
23
+
24
+ interface ArtifactProps {
25
+ messageId: string;
26
+ }
27
+
28
+ export const Artifact = memo(({ messageId }: ArtifactProps) => {
29
+ const userToggledActions = useRef(false);
30
+ const [showActions, setShowActions] = useState(false);
31
+ const [allActionFinished, setAllActionFinished] = useState(false);
32
+
33
+ const artifacts = useStore(workbenchStore.artifacts);
34
+ const artifact = artifacts[messageId];
35
+
36
+ const actions = useStore(
37
+ computed(artifact.runner.actions, (actions) => {
38
+ return Object.values(actions);
39
+ }),
40
+ );
41
+
42
+ const toggleActions = () => {
43
+ userToggledActions.current = true;
44
+ setShowActions(!showActions);
45
+ };
46
+
47
+ useEffect(() => {
48
+ if (actions.length && !showActions && !userToggledActions.current) {
49
+ setShowActions(true);
50
+ }
51
+
52
+ if (actions.length !== 0 && artifact.type === 'bundled') {
53
+ const finished = !actions.find((action) => action.status !== 'complete');
54
+
55
+ if (allActionFinished !== finished) {
56
+ setAllActionFinished(finished);
57
+ }
58
+ }
59
+ }, [actions]);
60
+
61
+ return (
62
+ <div className="artifact border border-bolt-elements-borderColor flex flex-col overflow-hidden rounded-lg w-full transition-border duration-150">
63
+ <div className="flex">
64
+ <button
65
+ className="flex items-stretch bg-bolt-elements-artifacts-background hover:bg-bolt-elements-artifacts-backgroundHover w-full overflow-hidden"
66
+ onClick={() => {
67
+ const showWorkbench = workbenchStore.showWorkbench.get();
68
+ workbenchStore.showWorkbench.set(!showWorkbench);
69
+ }}
70
+ >
71
+ {artifact.type == 'bundled' && (
72
+ <>
73
+ <div className="p-4">
74
+ {allActionFinished ? (
75
+ <div className={'i-ph:files-light'} style={{ fontSize: '2rem' }}></div>
76
+ ) : (
77
+ <div className={'i-svg-spinners:90-ring-with-bg'} style={{ fontSize: '2rem' }}></div>
78
+ )}
79
+ </div>
80
+ <div className="bg-bolt-elements-artifacts-borderColor w-[1px]" />
81
+ </>
82
+ )}
83
+ <div className="px-5 p-3.5 w-full text-left">
84
+ <div className="w-full text-bolt-elements-textPrimary font-medium leading-5 text-sm">{artifact?.title}</div>
85
+ <div className="w-full w-full text-bolt-elements-textSecondary text-xs mt-0.5">Click to open Workbench</div>
86
+ </div>
87
+ </button>
88
+ <div className="bg-bolt-elements-artifacts-borderColor w-[1px]" />
89
+ <AnimatePresence>
90
+ {actions.length && artifact.type !== 'bundled' && (
91
+ <motion.button
92
+ initial={{ width: 0 }}
93
+ animate={{ width: 'auto' }}
94
+ exit={{ width: 0 }}
95
+ transition={{ duration: 0.15, ease: cubicEasingFn }}
96
+ className="bg-bolt-elements-artifacts-background hover:bg-bolt-elements-artifacts-backgroundHover"
97
+ onClick={toggleActions}
98
+ >
99
+ <div className="p-4">
100
+ <div className={showActions ? 'i-ph:caret-up-bold' : 'i-ph:caret-down-bold'}></div>
101
+ </div>
102
+ </motion.button>
103
+ )}
104
+ </AnimatePresence>
105
+ </div>
106
+ <AnimatePresence>
107
+ {artifact.type !== 'bundled' && showActions && actions.length > 0 && (
108
+ <motion.div
109
+ className="actions"
110
+ initial={{ height: 0 }}
111
+ animate={{ height: 'auto' }}
112
+ exit={{ height: '0px' }}
113
+ transition={{ duration: 0.15 }}
114
+ >
115
+ <div className="bg-bolt-elements-artifacts-borderColor h-[1px]" />
116
+
117
+ <div className="p-5 text-left bg-bolt-elements-actions-background">
118
+ <ActionList actions={actions} />
119
+ </div>
120
+ </motion.div>
121
+ )}
122
+ </AnimatePresence>
123
+ </div>
124
+ );
125
+ });
126
+
127
+ interface ShellCodeBlockProps {
128
+ classsName?: string;
129
+ code: string;
130
+ }
131
+
132
+ function ShellCodeBlock({ classsName, code }: ShellCodeBlockProps) {
133
+ return (
134
+ <div
135
+ className={classNames('text-xs', classsName)}
136
+ dangerouslySetInnerHTML={{
137
+ __html: shellHighlighter.codeToHtml(code, {
138
+ lang: 'shell',
139
+ theme: 'dark-plus',
140
+ }),
141
+ }}
142
+ ></div>
143
+ );
144
+ }
145
+
146
+ interface ActionListProps {
147
+ actions: ActionState[];
148
+ }
149
+
150
+ const actionVariants = {
151
+ hidden: { opacity: 0, y: 20 },
152
+ visible: { opacity: 1, y: 0 },
153
+ };
154
+
155
+ function openArtifactInWorkbench(filePath: any) {
156
+ if (workbenchStore.currentView.get() !== 'code') {
157
+ workbenchStore.currentView.set('code');
158
+ }
159
+
160
+ workbenchStore.setSelectedFile(`${WORK_DIR}/${filePath}`);
161
+ }
162
+
163
+ const ActionList = memo(({ actions }: ActionListProps) => {
164
+ return (
165
+ <motion.div initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} transition={{ duration: 0.15 }}>
166
+ <ul className="list-none space-y-2.5">
167
+ {actions.map((action, index) => {
168
+ const { status, type, content } = action;
169
+ const isLast = index === actions.length - 1;
170
+
171
+ return (
172
+ <motion.li
173
+ key={index}
174
+ variants={actionVariants}
175
+ initial="hidden"
176
+ animate="visible"
177
+ transition={{
178
+ duration: 0.2,
179
+ ease: cubicEasingFn,
180
+ }}
181
+ >
182
+ <div className="flex items-center gap-1.5 text-sm">
183
+ <div className={classNames('text-lg', getIconColor(action.status))}>
184
+ {status === 'running' ? (
185
+ <>
186
+ {type !== 'start' ? (
187
+ <div className="i-svg-spinners:90-ring-with-bg"></div>
188
+ ) : (
189
+ <div className="i-ph:terminal-window-duotone"></div>
190
+ )}
191
+ </>
192
+ ) : status === 'pending' ? (
193
+ <div className="i-ph:circle-duotone"></div>
194
+ ) : status === 'complete' ? (
195
+ <div className="i-ph:check"></div>
196
+ ) : status === 'failed' || status === 'aborted' ? (
197
+ <div className="i-ph:x"></div>
198
+ ) : null}
199
+ </div>
200
+ {type === 'file' ? (
201
+ <div>
202
+ Create{' '}
203
+ <code
204
+ className="bg-bolt-elements-artifacts-inlineCode-background text-bolt-elements-artifacts-inlineCode-text px-1.5 py-1 rounded-md text-bolt-elements-item-contentAccent hover:underline cursor-pointer"
205
+ onClick={() => openArtifactInWorkbench(action.filePath)}
206
+ >
207
+ {action.filePath}
208
+ </code>
209
+ </div>
210
+ ) : type === 'shell' ? (
211
+ <div className="flex items-center w-full min-h-[28px]">
212
+ <span className="flex-1">Run command</span>
213
+ </div>
214
+ ) : type === 'start' ? (
215
+ <a
216
+ onClick={(e) => {
217
+ e.preventDefault();
218
+ workbenchStore.currentView.set('preview');
219
+ }}
220
+ className="flex items-center w-full min-h-[28px]"
221
+ >
222
+ <span className="flex-1">Start Application</span>
223
+ </a>
224
+ ) : null}
225
+ </div>
226
+ {(type === 'shell' || type === 'start') && (
227
+ <ShellCodeBlock
228
+ classsName={classNames('mt-1', {
229
+ 'mb-3.5': !isLast,
230
+ })}
231
+ code={content}
232
+ />
233
+ )}
234
+ </motion.li>
235
+ );
236
+ })}
237
+ </ul>
238
+ </motion.div>
239
+ );
240
+ });
241
+
242
+ function getIconColor(status: ActionState['status']) {
243
+ switch (status) {
244
+ case 'pending': {
245
+ return 'text-bolt-elements-textTertiary';
246
+ }
247
+ case 'running': {
248
+ return 'text-bolt-elements-loader-progress';
249
+ }
250
+ case 'complete': {
251
+ return 'text-bolt-elements-icon-success';
252
+ }
253
+ case 'aborted': {
254
+ return 'text-bolt-elements-textSecondary';
255
+ }
256
+ case 'failed': {
257
+ return 'text-bolt-elements-icon-error';
258
+ }
259
+ default: {
260
+ return undefined;
261
+ }
262
+ }
263
+ }
app/components/chat/AssistantMessage.tsx ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { memo } from 'react';
2
+ import { Markdown } from './Markdown';
3
+ import type { JSONValue } from 'ai';
4
+
5
+ interface AssistantMessageProps {
6
+ content: string;
7
+ annotations?: JSONValue[];
8
+ }
9
+
10
+ export const AssistantMessage = memo(({ content, annotations }: AssistantMessageProps) => {
11
+ const filteredAnnotations = (annotations?.filter(
12
+ (annotation: JSONValue) => annotation && typeof annotation === 'object' && Object.keys(annotation).includes('type'),
13
+ ) || []) as { type: string; value: any }[];
14
+
15
+ const usage: {
16
+ completionTokens: number;
17
+ promptTokens: number;
18
+ totalTokens: number;
19
+ } = filteredAnnotations.find((annotation) => annotation.type === 'usage')?.value;
20
+
21
+ return (
22
+ <div className="overflow-hidden w-full">
23
+ {usage && (
24
+ <div className="text-sm text-bolt-elements-textSecondary mb-2">
25
+ Tokens: {usage.totalTokens} (prompt: {usage.promptTokens}, completion: {usage.completionTokens})
26
+ </div>
27
+ )}
28
+ <Markdown html>{content}</Markdown>
29
+ </div>
30
+ );
31
+ });
app/components/chat/BaseChat.module.scss ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .BaseChat {
2
+ &[data-chat-visible='false'] {
3
+ --workbench-inner-width: 100%;
4
+ --workbench-left: 0;
5
+
6
+ .Chat {
7
+ --at-apply: bolt-ease-cubic-bezier;
8
+ transition-property: transform, opacity;
9
+ transition-duration: 0.3s;
10
+ will-change: transform, opacity;
11
+ transform: translateX(-50%);
12
+ opacity: 0;
13
+ }
14
+ }
15
+ }
16
+
17
+ .Chat {
18
+ opacity: 1;
19
+ }
20
+
21
+ .PromptEffectContainer {
22
+ --prompt-container-offset: 50px;
23
+ --prompt-line-stroke-width: 1px;
24
+ position: absolute;
25
+ pointer-events: none;
26
+ inset: calc(var(--prompt-container-offset) / -2);
27
+ width: calc(100% + var(--prompt-container-offset));
28
+ height: calc(100% + var(--prompt-container-offset));
29
+ }
30
+
31
+ .PromptEffectLine {
32
+ width: calc(100% - var(--prompt-container-offset) + var(--prompt-line-stroke-width));
33
+ height: calc(100% - var(--prompt-container-offset) + var(--prompt-line-stroke-width));
34
+ x: calc(var(--prompt-container-offset) / 2 - var(--prompt-line-stroke-width) / 2);
35
+ y: calc(var(--prompt-container-offset) / 2 - var(--prompt-line-stroke-width) / 2);
36
+ rx: calc(8px - var(--prompt-line-stroke-width));
37
+ fill: transparent;
38
+ stroke-width: var(--prompt-line-stroke-width);
39
+ stroke: url(#line-gradient);
40
+ stroke-dasharray: 35px 65px;
41
+ stroke-dashoffset: 10;
42
+ }
43
+
44
+ .PromptShine {
45
+ fill: url(#shine-gradient);
46
+ mix-blend-mode: overlay;
47
+ }
app/components/chat/BaseChat.tsx ADDED
@@ -0,0 +1,626 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * @ts-nocheck
3
+ * Preventing TS checks with files presented in the video for a better presentation.
4
+ */
5
+ import type { Message } from 'ai';
6
+ import React, { type RefCallback, useCallback, useEffect, useState } from 'react';
7
+ import { ClientOnly } from 'remix-utils/client-only';
8
+ import { Menu } from '~/components/sidebar/Menu.client';
9
+ import { IconButton } from '~/components/ui/IconButton';
10
+ import { Workbench } from '~/components/workbench/Workbench.client';
11
+ import { classNames } from '~/utils/classNames';
12
+ import { MODEL_LIST, PROVIDER_LIST, initializeModelList } from '~/utils/constants';
13
+ import { Messages } from './Messages.client';
14
+ import { SendButton } from './SendButton.client';
15
+ import { APIKeyManager, getApiKeysFromCookies } from './APIKeyManager';
16
+ import Cookies from 'js-cookie';
17
+ import * as Tooltip from '@radix-ui/react-tooltip';
18
+
19
+ import styles from './BaseChat.module.scss';
20
+ import { ExportChatButton } from '~/components/chat/chatExportAndImport/ExportChatButton';
21
+ import { ImportButtons } from '~/components/chat/chatExportAndImport/ImportButtons';
22
+ import { ExamplePrompts } from '~/components/chat/ExamplePrompts';
23
+ import GitCloneButton from './GitCloneButton';
24
+
25
+ import FilePreview from './FilePreview';
26
+ import { ModelSelector } from '~/components/chat/ModelSelector';
27
+ import { SpeechRecognitionButton } from '~/components/chat/SpeechRecognition';
28
+ import type { IProviderSetting, ProviderInfo } from '~/types/model';
29
+ import { ScreenshotStateManager } from './ScreenshotStateManager';
30
+ import { toast } from 'react-toastify';
31
+ import StarterTemplates from './StarterTemplates';
32
+ import type { ActionAlert } from '~/types/actions';
33
+ import ChatAlert from './ChatAlert';
34
+ import { LLMManager } from '~/lib/modules/llm/manager';
35
+
36
+ const TEXTAREA_MIN_HEIGHT = 76;
37
+
38
+ interface BaseChatProps {
39
+ textareaRef?: React.RefObject<HTMLTextAreaElement> | undefined;
40
+ messageRef?: RefCallback<HTMLDivElement> | undefined;
41
+ scrollRef?: RefCallback<HTMLDivElement> | undefined;
42
+ showChat?: boolean;
43
+ chatStarted?: boolean;
44
+ isStreaming?: boolean;
45
+ messages?: Message[];
46
+ description?: string;
47
+ enhancingPrompt?: boolean;
48
+ promptEnhanced?: boolean;
49
+ input?: string;
50
+ model?: string;
51
+ setModel?: (model: string) => void;
52
+ provider?: ProviderInfo;
53
+ setProvider?: (provider: ProviderInfo) => void;
54
+ providerList?: ProviderInfo[];
55
+ handleStop?: () => void;
56
+ sendMessage?: (event: React.UIEvent, messageInput?: string) => void;
57
+ handleInputChange?: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;
58
+ enhancePrompt?: () => void;
59
+ importChat?: (description: string, messages: Message[]) => Promise<void>;
60
+ exportChat?: () => void;
61
+ uploadedFiles?: File[];
62
+ setUploadedFiles?: (files: File[]) => void;
63
+ imageDataList?: string[];
64
+ setImageDataList?: (dataList: string[]) => void;
65
+ actionAlert?: ActionAlert;
66
+ clearAlert?: () => void;
67
+ }
68
+
69
+ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
70
+ (
71
+ {
72
+ textareaRef,
73
+ messageRef,
74
+ scrollRef,
75
+ showChat = true,
76
+ chatStarted = false,
77
+ isStreaming = false,
78
+ model,
79
+ setModel,
80
+ provider,
81
+ setProvider,
82
+ providerList,
83
+ input = '',
84
+ enhancingPrompt,
85
+ handleInputChange,
86
+
87
+ // promptEnhanced,
88
+ enhancePrompt,
89
+ sendMessage,
90
+ handleStop,
91
+ importChat,
92
+ exportChat,
93
+ uploadedFiles = [],
94
+ setUploadedFiles,
95
+ imageDataList = [],
96
+ setImageDataList,
97
+ messages,
98
+ actionAlert,
99
+ clearAlert,
100
+ },
101
+ ref,
102
+ ) => {
103
+ const TEXTAREA_MAX_HEIGHT = chatStarted ? 400 : 200;
104
+ const [apiKeys, setApiKeys] = useState<Record<string, string>>(getApiKeysFromCookies());
105
+ const [modelList, setModelList] = useState(MODEL_LIST);
106
+ const [isModelSettingsCollapsed, setIsModelSettingsCollapsed] = useState(false);
107
+ const [isListening, setIsListening] = useState(false);
108
+ const [recognition, setRecognition] = useState<SpeechRecognition | null>(null);
109
+ const [transcript, setTranscript] = useState('');
110
+ const [isModelLoading, setIsModelLoading] = useState<string | undefined>('all');
111
+
112
+ const getProviderSettings = useCallback(() => {
113
+ let providerSettings: Record<string, IProviderSetting> | undefined = undefined;
114
+
115
+ try {
116
+ const savedProviderSettings = Cookies.get('providers');
117
+
118
+ if (savedProviderSettings) {
119
+ const parsedProviderSettings = JSON.parse(savedProviderSettings);
120
+
121
+ if (typeof parsedProviderSettings === 'object' && parsedProviderSettings !== null) {
122
+ providerSettings = parsedProviderSettings;
123
+ }
124
+ }
125
+ } catch (error) {
126
+ console.error('Error loading Provider Settings from cookies:', error);
127
+
128
+ // Clear invalid cookie data
129
+ Cookies.remove('providers');
130
+ }
131
+
132
+ return providerSettings;
133
+ }, []);
134
+ useEffect(() => {
135
+ console.log(transcript);
136
+ }, [transcript]);
137
+
138
+ useEffect(() => {
139
+ if (typeof window !== 'undefined' && ('SpeechRecognition' in window || 'webkitSpeechRecognition' in window)) {
140
+ const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
141
+ const recognition = new SpeechRecognition();
142
+ recognition.continuous = true;
143
+ recognition.interimResults = true;
144
+
145
+ recognition.onresult = (event) => {
146
+ const transcript = Array.from(event.results)
147
+ .map((result) => result[0])
148
+ .map((result) => result.transcript)
149
+ .join('');
150
+
151
+ setTranscript(transcript);
152
+
153
+ if (handleInputChange) {
154
+ const syntheticEvent = {
155
+ target: { value: transcript },
156
+ } as React.ChangeEvent<HTMLTextAreaElement>;
157
+ handleInputChange(syntheticEvent);
158
+ }
159
+ };
160
+
161
+ recognition.onerror = (event) => {
162
+ console.error('Speech recognition error:', event.error);
163
+ setIsListening(false);
164
+ };
165
+
166
+ setRecognition(recognition);
167
+ }
168
+ }, []);
169
+
170
+ useEffect(() => {
171
+ if (typeof window !== 'undefined') {
172
+ const providerSettings = getProviderSettings();
173
+ let parsedApiKeys: Record<string, string> | undefined = {};
174
+
175
+ try {
176
+ parsedApiKeys = getApiKeysFromCookies();
177
+ setApiKeys(parsedApiKeys);
178
+ } catch (error) {
179
+ console.error('Error loading API keys from cookies:', error);
180
+
181
+ // Clear invalid cookie data
182
+ Cookies.remove('apiKeys');
183
+ }
184
+ setIsModelLoading('all');
185
+ initializeModelList({ apiKeys: parsedApiKeys, providerSettings })
186
+ .then((modelList) => {
187
+ // console.log('Model List: ', modelList);
188
+ setModelList(modelList);
189
+ })
190
+ .catch((error) => {
191
+ console.error('Error initializing model list:', error);
192
+ })
193
+ .finally(() => {
194
+ setIsModelLoading(undefined);
195
+ });
196
+ }
197
+ }, [providerList]);
198
+
199
+ const onApiKeysChange = async (providerName: string, apiKey: string) => {
200
+ const newApiKeys = { ...apiKeys, [providerName]: apiKey };
201
+ setApiKeys(newApiKeys);
202
+ Cookies.set('apiKeys', JSON.stringify(newApiKeys));
203
+
204
+ const provider = LLMManager.getInstance(import.meta.env || process.env || {}).getProvider(providerName);
205
+
206
+ if (provider && provider.getDynamicModels) {
207
+ setIsModelLoading(providerName);
208
+
209
+ try {
210
+ const providerSettings = getProviderSettings();
211
+ const staticModels = provider.staticModels;
212
+ const dynamicModels = await provider.getDynamicModels(
213
+ newApiKeys,
214
+ providerSettings,
215
+ import.meta.env || process.env || {},
216
+ );
217
+
218
+ setModelList((preModels) => {
219
+ const filteredOutPreModels = preModels.filter((x) => x.provider !== providerName);
220
+ return [...filteredOutPreModels, ...staticModels, ...dynamicModels];
221
+ });
222
+ } catch (error) {
223
+ console.error('Error loading dynamic models:', error);
224
+ }
225
+ setIsModelLoading(undefined);
226
+ }
227
+ };
228
+
229
+ const startListening = () => {
230
+ if (recognition) {
231
+ recognition.start();
232
+ setIsListening(true);
233
+ }
234
+ };
235
+
236
+ const stopListening = () => {
237
+ if (recognition) {
238
+ recognition.stop();
239
+ setIsListening(false);
240
+ }
241
+ };
242
+
243
+ const handleSendMessage = (event: React.UIEvent, messageInput?: string) => {
244
+ if (sendMessage) {
245
+ sendMessage(event, messageInput);
246
+
247
+ if (recognition) {
248
+ recognition.abort(); // Stop current recognition
249
+ setTranscript(''); // Clear transcript
250
+ setIsListening(false);
251
+
252
+ // Clear the input by triggering handleInputChange with empty value
253
+ if (handleInputChange) {
254
+ const syntheticEvent = {
255
+ target: { value: '' },
256
+ } as React.ChangeEvent<HTMLTextAreaElement>;
257
+ handleInputChange(syntheticEvent);
258
+ }
259
+ }
260
+ }
261
+ };
262
+
263
+ const handleFileUpload = () => {
264
+ const input = document.createElement('input');
265
+ input.type = 'file';
266
+ input.accept = 'image/*';
267
+
268
+ input.onchange = async (e) => {
269
+ const file = (e.target as HTMLInputElement).files?.[0];
270
+
271
+ if (file) {
272
+ const reader = new FileReader();
273
+
274
+ reader.onload = (e) => {
275
+ const base64Image = e.target?.result as string;
276
+ setUploadedFiles?.([...uploadedFiles, file]);
277
+ setImageDataList?.([...imageDataList, base64Image]);
278
+ };
279
+ reader.readAsDataURL(file);
280
+ }
281
+ };
282
+
283
+ input.click();
284
+ };
285
+
286
+ const handlePaste = async (e: React.ClipboardEvent) => {
287
+ const items = e.clipboardData?.items;
288
+
289
+ if (!items) {
290
+ return;
291
+ }
292
+
293
+ for (const item of items) {
294
+ if (item.type.startsWith('image/')) {
295
+ e.preventDefault();
296
+
297
+ const file = item.getAsFile();
298
+
299
+ if (file) {
300
+ const reader = new FileReader();
301
+
302
+ reader.onload = (e) => {
303
+ const base64Image = e.target?.result as string;
304
+ setUploadedFiles?.([...uploadedFiles, file]);
305
+ setImageDataList?.([...imageDataList, base64Image]);
306
+ };
307
+ reader.readAsDataURL(file);
308
+ }
309
+
310
+ break;
311
+ }
312
+ }
313
+ };
314
+
315
+ const baseChat = (
316
+ <div
317
+ ref={ref}
318
+ className={classNames(styles.BaseChat, 'relative flex h-full w-full overflow-hidden')}
319
+ data-chat-visible={showChat}
320
+ >
321
+ <ClientOnly>{() => <Menu />}</ClientOnly>
322
+ <div ref={scrollRef} className="flex flex-col lg:flex-row overflow-y-auto w-full h-full">
323
+ <div className={classNames(styles.Chat, 'flex flex-col flex-grow lg:min-w-[var(--chat-min-width)] h-full')}>
324
+ {!chatStarted && (
325
+ <div id="intro" className="mt-[16vh] max-w-chat mx-auto text-center px-4 lg:px-0">
326
+ <h1 className="text-3xl lg:text-6xl font-bold text-bolt-elements-textPrimary mb-4 animate-fade-in">
327
+ Where ideas begin
328
+ </h1>
329
+ <p className="text-md lg:text-xl mb-8 text-bolt-elements-textSecondary animate-fade-in animation-delay-200">
330
+ Bring ideas to life in seconds or get help on existing projects.
331
+ </p>
332
+ </div>
333
+ )}
334
+ <div
335
+ className={classNames('pt-6 px-2 sm:px-6', {
336
+ 'h-full flex flex-col': chatStarted,
337
+ })}
338
+ >
339
+ <ClientOnly>
340
+ {() => {
341
+ return chatStarted ? (
342
+ <Messages
343
+ ref={messageRef}
344
+ className="flex flex-col w-full flex-1 max-w-chat pb-6 mx-auto z-1"
345
+ messages={messages}
346
+ isStreaming={isStreaming}
347
+ />
348
+ ) : null;
349
+ }}
350
+ </ClientOnly>
351
+ <div
352
+ className={classNames('flex flex-col gap-4 w-full max-w-chat mx-auto z-prompt mb-6', {
353
+ 'sticky bottom-2': chatStarted,
354
+ })}
355
+ >
356
+ <div className="bg-bolt-elements-background-depth-2">
357
+ {actionAlert && (
358
+ <ChatAlert
359
+ alert={actionAlert}
360
+ clearAlert={() => clearAlert?.()}
361
+ postMessage={(message) => {
362
+ sendMessage?.({} as any, message);
363
+ clearAlert?.();
364
+ }}
365
+ />
366
+ )}
367
+ </div>
368
+ <div
369
+ className={classNames(
370
+ 'bg-bolt-elements-background-depth-2 p-3 rounded-lg border border-bolt-elements-borderColor relative w-full max-w-chat mx-auto z-prompt',
371
+
372
+ /*
373
+ * {
374
+ * 'sticky bottom-2': chatStarted,
375
+ * },
376
+ */
377
+ )}
378
+ >
379
+ <svg className={classNames(styles.PromptEffectContainer)}>
380
+ <defs>
381
+ <linearGradient
382
+ id="line-gradient"
383
+ x1="20%"
384
+ y1="0%"
385
+ x2="-14%"
386
+ y2="10%"
387
+ gradientUnits="userSpaceOnUse"
388
+ gradientTransform="rotate(-45)"
389
+ >
390
+ <stop offset="0%" stopColor="#b44aff" stopOpacity="0%"></stop>
391
+ <stop offset="40%" stopColor="#b44aff" stopOpacity="80%"></stop>
392
+ <stop offset="50%" stopColor="#b44aff" stopOpacity="80%"></stop>
393
+ <stop offset="100%" stopColor="#b44aff" stopOpacity="0%"></stop>
394
+ </linearGradient>
395
+ <linearGradient id="shine-gradient">
396
+ <stop offset="0%" stopColor="white" stopOpacity="0%"></stop>
397
+ <stop offset="40%" stopColor="#ffffff" stopOpacity="80%"></stop>
398
+ <stop offset="50%" stopColor="#ffffff" stopOpacity="80%"></stop>
399
+ <stop offset="100%" stopColor="white" stopOpacity="0%"></stop>
400
+ </linearGradient>
401
+ </defs>
402
+ <rect className={classNames(styles.PromptEffectLine)} pathLength="100" strokeLinecap="round"></rect>
403
+ <rect className={classNames(styles.PromptShine)} x="48" y="24" width="70" height="1"></rect>
404
+ </svg>
405
+ <div>
406
+ <ClientOnly>
407
+ {() => (
408
+ <div className={isModelSettingsCollapsed ? 'hidden' : ''}>
409
+ <ModelSelector
410
+ key={provider?.name + ':' + modelList.length}
411
+ model={model}
412
+ setModel={setModel}
413
+ modelList={modelList}
414
+ provider={provider}
415
+ setProvider={setProvider}
416
+ providerList={providerList || (PROVIDER_LIST as ProviderInfo[])}
417
+ apiKeys={apiKeys}
418
+ modelLoading={isModelLoading}
419
+ />
420
+ {(providerList || []).length > 0 && provider && (
421
+ <APIKeyManager
422
+ provider={provider}
423
+ apiKey={apiKeys[provider.name] || ''}
424
+ setApiKey={(key) => {
425
+ onApiKeysChange(provider.name, key);
426
+ }}
427
+ />
428
+ )}
429
+ </div>
430
+ )}
431
+ </ClientOnly>
432
+ </div>
433
+ <FilePreview
434
+ files={uploadedFiles}
435
+ imageDataList={imageDataList}
436
+ onRemove={(index) => {
437
+ setUploadedFiles?.(uploadedFiles.filter((_, i) => i !== index));
438
+ setImageDataList?.(imageDataList.filter((_, i) => i !== index));
439
+ }}
440
+ />
441
+ <ClientOnly>
442
+ {() => (
443
+ <ScreenshotStateManager
444
+ setUploadedFiles={setUploadedFiles}
445
+ setImageDataList={setImageDataList}
446
+ uploadedFiles={uploadedFiles}
447
+ imageDataList={imageDataList}
448
+ />
449
+ )}
450
+ </ClientOnly>
451
+ <div
452
+ className={classNames(
453
+ 'relative shadow-xs border border-bolt-elements-borderColor backdrop-blur rounded-lg',
454
+ )}
455
+ >
456
+ <textarea
457
+ ref={textareaRef}
458
+ className={classNames(
459
+ 'w-full pl-4 pt-4 pr-16 outline-none resize-none text-bolt-elements-textPrimary placeholder-bolt-elements-textTertiary bg-transparent text-sm',
460
+ 'transition-all duration-200',
461
+ 'hover:border-bolt-elements-focus',
462
+ )}
463
+ onDragEnter={(e) => {
464
+ e.preventDefault();
465
+ e.currentTarget.style.border = '2px solid #1488fc';
466
+ }}
467
+ onDragOver={(e) => {
468
+ e.preventDefault();
469
+ e.currentTarget.style.border = '2px solid #1488fc';
470
+ }}
471
+ onDragLeave={(e) => {
472
+ e.preventDefault();
473
+ e.currentTarget.style.border = '1px solid var(--bolt-elements-borderColor)';
474
+ }}
475
+ onDrop={(e) => {
476
+ e.preventDefault();
477
+ e.currentTarget.style.border = '1px solid var(--bolt-elements-borderColor)';
478
+
479
+ const files = Array.from(e.dataTransfer.files);
480
+ files.forEach((file) => {
481
+ if (file.type.startsWith('image/')) {
482
+ const reader = new FileReader();
483
+
484
+ reader.onload = (e) => {
485
+ const base64Image = e.target?.result as string;
486
+ setUploadedFiles?.([...uploadedFiles, file]);
487
+ setImageDataList?.([...imageDataList, base64Image]);
488
+ };
489
+ reader.readAsDataURL(file);
490
+ }
491
+ });
492
+ }}
493
+ onKeyDown={(event) => {
494
+ if (event.key === 'Enter') {
495
+ if (event.shiftKey) {
496
+ return;
497
+ }
498
+
499
+ event.preventDefault();
500
+
501
+ if (isStreaming) {
502
+ handleStop?.();
503
+ return;
504
+ }
505
+
506
+ // ignore if using input method engine
507
+ if (event.nativeEvent.isComposing) {
508
+ return;
509
+ }
510
+
511
+ handleSendMessage?.(event);
512
+ }
513
+ }}
514
+ value={input}
515
+ onChange={(event) => {
516
+ handleInputChange?.(event);
517
+ }}
518
+ onPaste={handlePaste}
519
+ style={{
520
+ minHeight: TEXTAREA_MIN_HEIGHT,
521
+ maxHeight: TEXTAREA_MAX_HEIGHT,
522
+ }}
523
+ placeholder="How can Bolt help you today?"
524
+ translate="no"
525
+ />
526
+ <ClientOnly>
527
+ {() => (
528
+ <SendButton
529
+ show={input.length > 0 || isStreaming || uploadedFiles.length > 0}
530
+ isStreaming={isStreaming}
531
+ disabled={!providerList || providerList.length === 0}
532
+ onClick={(event) => {
533
+ if (isStreaming) {
534
+ handleStop?.();
535
+ return;
536
+ }
537
+
538
+ if (input.length > 0 || uploadedFiles.length > 0) {
539
+ handleSendMessage?.(event);
540
+ }
541
+ }}
542
+ />
543
+ )}
544
+ </ClientOnly>
545
+ <div className="flex justify-between items-center text-sm p-4 pt-2">
546
+ <div className="flex gap-1 items-center">
547
+ <IconButton title="Upload file" className="transition-all" onClick={() => handleFileUpload()}>
548
+ <div className="i-ph:paperclip text-xl"></div>
549
+ </IconButton>
550
+ <IconButton
551
+ title="Enhance prompt"
552
+ disabled={input.length === 0 || enhancingPrompt}
553
+ className={classNames('transition-all', enhancingPrompt ? 'opacity-100' : '')}
554
+ onClick={() => {
555
+ enhancePrompt?.();
556
+ toast.success('Prompt enhanced!');
557
+ }}
558
+ >
559
+ {enhancingPrompt ? (
560
+ <div className="i-svg-spinners:90-ring-with-bg text-bolt-elements-loader-progress text-xl animate-spin"></div>
561
+ ) : (
562
+ <div className="i-bolt:stars text-xl"></div>
563
+ )}
564
+ </IconButton>
565
+
566
+ <SpeechRecognitionButton
567
+ isListening={isListening}
568
+ onStart={startListening}
569
+ onStop={stopListening}
570
+ disabled={isStreaming}
571
+ />
572
+ {chatStarted && <ClientOnly>{() => <ExportChatButton exportChat={exportChat} />}</ClientOnly>}
573
+ <IconButton
574
+ title="Model Settings"
575
+ className={classNames('transition-all flex items-center gap-1', {
576
+ 'bg-bolt-elements-item-backgroundAccent text-bolt-elements-item-contentAccent':
577
+ isModelSettingsCollapsed,
578
+ 'bg-bolt-elements-item-backgroundDefault text-bolt-elements-item-contentDefault':
579
+ !isModelSettingsCollapsed,
580
+ })}
581
+ onClick={() => setIsModelSettingsCollapsed(!isModelSettingsCollapsed)}
582
+ disabled={!providerList || providerList.length === 0}
583
+ >
584
+ <div className={`i-ph:caret-${isModelSettingsCollapsed ? 'right' : 'down'} text-lg`} />
585
+ {isModelSettingsCollapsed ? <span className="text-xs">{model}</span> : <span />}
586
+ </IconButton>
587
+ </div>
588
+ {input.length > 3 ? (
589
+ <div className="text-xs text-bolt-elements-textTertiary">
590
+ Use <kbd className="kdb px-1.5 py-0.5 rounded bg-bolt-elements-background-depth-2">Shift</kbd>{' '}
591
+ + <kbd className="kdb px-1.5 py-0.5 rounded bg-bolt-elements-background-depth-2">Return</kbd>{' '}
592
+ a new line
593
+ </div>
594
+ ) : null}
595
+ </div>
596
+ </div>
597
+ </div>
598
+ </div>
599
+ </div>
600
+ <div className="flex flex-col justify-center gap-5">
601
+ {!chatStarted && (
602
+ <div className="flex justify-center gap-2">
603
+ {ImportButtons(importChat)}
604
+ <GitCloneButton importChat={importChat} />
605
+ </div>
606
+ )}
607
+ {!chatStarted &&
608
+ ExamplePrompts((event, messageInput) => {
609
+ if (isStreaming) {
610
+ handleStop?.();
611
+ return;
612
+ }
613
+
614
+ handleSendMessage?.(event, messageInput);
615
+ })}
616
+ {!chatStarted && <StarterTemplates />}
617
+ </div>
618
+ </div>
619
+ <ClientOnly>{() => <Workbench chatStarted={chatStarted} isStreaming={isStreaming} />}</ClientOnly>
620
+ </div>
621
+ </div>
622
+ );
623
+
624
+ return <Tooltip.Provider delayDuration={200}>{baseChat}</Tooltip.Provider>;
625
+ },
626
+ );
app/components/chat/Chat.client.tsx ADDED
@@ -0,0 +1,556 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * @ts-nocheck
3
+ * Preventing TS checks with files presented in the video for a better presentation.
4
+ */
5
+ import { useStore } from '@nanostores/react';
6
+ import type { Message } from 'ai';
7
+ import { useChat } from 'ai/react';
8
+ import { useAnimate } from 'framer-motion';
9
+ import { memo, useCallback, useEffect, useRef, useState } from 'react';
10
+ import { cssTransition, toast, ToastContainer } from 'react-toastify';
11
+ import { useMessageParser, usePromptEnhancer, useShortcuts, useSnapScroll } from '~/lib/hooks';
12
+ import { description, useChatHistory } from '~/lib/persistence';
13
+ import { chatStore } from '~/lib/stores/chat';
14
+ import { workbenchStore } from '~/lib/stores/workbench';
15
+ import { DEFAULT_MODEL, DEFAULT_PROVIDER, PROMPT_COOKIE_KEY, PROVIDER_LIST } from '~/utils/constants';
16
+ import { cubicEasingFn } from '~/utils/easings';
17
+ import { createScopedLogger, renderLogger } from '~/utils/logger';
18
+ import { BaseChat } from './BaseChat';
19
+ import Cookies from 'js-cookie';
20
+ import { debounce } from '~/utils/debounce';
21
+ import { useSettings } from '~/lib/hooks/useSettings';
22
+ import type { ProviderInfo } from '~/types/model';
23
+ import { useSearchParams } from '@remix-run/react';
24
+ import { createSampler } from '~/utils/sampler';
25
+ import { getTemplates, selectStarterTemplate } from '~/utils/selectStarterTemplate';
26
+
27
+ const toastAnimation = cssTransition({
28
+ enter: 'animated fadeInRight',
29
+ exit: 'animated fadeOutRight',
30
+ });
31
+
32
+ const logger = createScopedLogger('Chat');
33
+
34
+ export function Chat() {
35
+ renderLogger.trace('Chat');
36
+
37
+ const { ready, initialMessages, storeMessageHistory, importChat, exportChat } = useChatHistory();
38
+ const title = useStore(description);
39
+ useEffect(() => {
40
+ workbenchStore.setReloadedMessages(initialMessages.map((m) => m.id));
41
+ }, [initialMessages]);
42
+
43
+ return (
44
+ <>
45
+ {ready && (
46
+ <ChatImpl
47
+ description={title}
48
+ initialMessages={initialMessages}
49
+ exportChat={exportChat}
50
+ storeMessageHistory={storeMessageHistory}
51
+ importChat={importChat}
52
+ />
53
+ )}
54
+ <ToastContainer
55
+ closeButton={({ closeToast }) => {
56
+ return (
57
+ <button className="Toastify__close-button" onClick={closeToast}>
58
+ <div className="i-ph:x text-lg" />
59
+ </button>
60
+ );
61
+ }}
62
+ icon={({ type }) => {
63
+ /**
64
+ * @todo Handle more types if we need them. This may require extra color palettes.
65
+ */
66
+ switch (type) {
67
+ case 'success': {
68
+ return <div className="i-ph:check-bold text-bolt-elements-icon-success text-2xl" />;
69
+ }
70
+ case 'error': {
71
+ return <div className="i-ph:warning-circle-bold text-bolt-elements-icon-error text-2xl" />;
72
+ }
73
+ }
74
+
75
+ return undefined;
76
+ }}
77
+ position="bottom-right"
78
+ pauseOnFocusLoss
79
+ transition={toastAnimation}
80
+ />
81
+ </>
82
+ );
83
+ }
84
+
85
+ const processSampledMessages = createSampler(
86
+ (options: {
87
+ messages: Message[];
88
+ initialMessages: Message[];
89
+ isLoading: boolean;
90
+ parseMessages: (messages: Message[], isLoading: boolean) => void;
91
+ storeMessageHistory: (messages: Message[]) => Promise<void>;
92
+ }) => {
93
+ const { messages, initialMessages, isLoading, parseMessages, storeMessageHistory } = options;
94
+ parseMessages(messages, isLoading);
95
+
96
+ if (messages.length > initialMessages.length) {
97
+ storeMessageHistory(messages).catch((error) => toast.error(error.message));
98
+ }
99
+ },
100
+ 50,
101
+ );
102
+
103
+ interface ChatProps {
104
+ initialMessages: Message[];
105
+ storeMessageHistory: (messages: Message[]) => Promise<void>;
106
+ importChat: (description: string, messages: Message[]) => Promise<void>;
107
+ exportChat: () => void;
108
+ description?: string;
109
+ }
110
+
111
+ export const ChatImpl = memo(
112
+ ({ description, initialMessages, storeMessageHistory, importChat, exportChat }: ChatProps) => {
113
+ useShortcuts();
114
+
115
+ const textareaRef = useRef<HTMLTextAreaElement>(null);
116
+ const [chatStarted, setChatStarted] = useState(initialMessages.length > 0);
117
+ const [uploadedFiles, setUploadedFiles] = useState<File[]>([]); // Move here
118
+ const [imageDataList, setImageDataList] = useState<string[]>([]); // Move here
119
+ const [searchParams, setSearchParams] = useSearchParams();
120
+ const [fakeLoading, setFakeLoading] = useState(false);
121
+ const files = useStore(workbenchStore.files);
122
+ const actionAlert = useStore(workbenchStore.alert);
123
+ const { activeProviders, promptId, autoSelectTemplate, contextOptimizationEnabled } = useSettings();
124
+
125
+ function isPromptCachingEnabled(): boolean {
126
+ // Server-side default
127
+ if (typeof window === 'undefined') {
128
+ console.log('Server-side: isPromptCachingEnabled: window undefined');
129
+ return false;
130
+ }
131
+
132
+ try {
133
+ // Read from localStorage in browser
134
+ const savedState = localStorage.getItem('PROMPT_CACHING_ENABLED');
135
+ console.log('Saved prompt caching state:', savedState);
136
+
137
+ return savedState !== null ? JSON.parse(savedState) : false;
138
+ } catch (error) {
139
+ console.error('Error reading prompt caching setting:', error);
140
+ return false; // Default to true if reading fails
141
+ }
142
+ }
143
+
144
+ const [model, setModel] = useState(() => {
145
+ const savedModel = Cookies.get('selectedModel');
146
+ return savedModel || DEFAULT_MODEL;
147
+ });
148
+ const [provider, setProvider] = useState(() => {
149
+ const savedProvider = Cookies.get('selectedProvider');
150
+ return (PROVIDER_LIST.find((p) => p.name === savedProvider) || DEFAULT_PROVIDER) as ProviderInfo;
151
+ });
152
+
153
+ const { showChat } = useStore(chatStore);
154
+
155
+ const [animationScope, animate] = useAnimate();
156
+
157
+ const [apiKeys, setApiKeys] = useState<Record<string, string>>({});
158
+
159
+ const { messages, isLoading, input, handleInputChange, setInput, stop, append, setMessages, reload } = useChat({
160
+ api: '/api/chat',
161
+ body: {
162
+ apiKeys,
163
+ files,
164
+ promptId,
165
+ contextOptimization: contextOptimizationEnabled,
166
+ isPromptCachingEnabled: provider.name === 'Anthropic' && isPromptCachingEnabled(),
167
+ },
168
+ sendExtraMessageFields: true,
169
+ onError: (error) => {
170
+ logger.error('Request failed\n\n', error);
171
+ toast.error(
172
+ 'There was an error processing your request: ' + (error.message ? error.message : 'No details were returned'),
173
+ );
174
+ },
175
+ onFinish: (message, response) => {
176
+ const usage = response.usage;
177
+
178
+ if (usage) {
179
+ console.log('Token usage:', usage);
180
+
181
+ // You can now use the usage data as needed
182
+ }
183
+
184
+ logger.debug('Finished streaming');
185
+ },
186
+ initialMessages,
187
+ initialInput: Cookies.get(PROMPT_COOKIE_KEY) || '',
188
+ });
189
+ useEffect(() => {
190
+ const prompt = searchParams.get('prompt');
191
+
192
+ // console.log(prompt, searchParams, model, provider);
193
+
194
+ if (prompt) {
195
+ setSearchParams({});
196
+ runAnimation();
197
+ append({
198
+ role: 'user',
199
+ content: [
200
+ {
201
+ type: 'text',
202
+ text: `[Model: ${model}]\n\n[Provider: ${provider.name}]\n\n${prompt}`,
203
+ },
204
+ ] as any, // Type assertion to bypass compiler check
205
+ });
206
+ }
207
+ }, [model, provider, searchParams]);
208
+
209
+ const { enhancingPrompt, promptEnhanced, enhancePrompt, resetEnhancer } = usePromptEnhancer();
210
+ const { parsedMessages, parseMessages } = useMessageParser();
211
+
212
+ const TEXTAREA_MAX_HEIGHT = chatStarted ? 400 : 200;
213
+
214
+ useEffect(() => {
215
+ chatStore.setKey('started', initialMessages.length > 0);
216
+ }, []);
217
+
218
+ useEffect(() => {
219
+ processSampledMessages({
220
+ messages,
221
+ initialMessages,
222
+ isLoading,
223
+ parseMessages,
224
+ storeMessageHistory,
225
+ });
226
+ }, [messages, isLoading, parseMessages]);
227
+
228
+ const scrollTextArea = () => {
229
+ const textarea = textareaRef.current;
230
+
231
+ if (textarea) {
232
+ textarea.scrollTop = textarea.scrollHeight;
233
+ }
234
+ };
235
+
236
+ const abort = () => {
237
+ stop();
238
+ chatStore.setKey('aborted', true);
239
+ workbenchStore.abortAllActions();
240
+ };
241
+
242
+ useEffect(() => {
243
+ const textarea = textareaRef.current;
244
+
245
+ if (textarea) {
246
+ textarea.style.height = 'auto';
247
+
248
+ const scrollHeight = textarea.scrollHeight;
249
+
250
+ textarea.style.height = `${Math.min(scrollHeight, TEXTAREA_MAX_HEIGHT)}px`;
251
+ textarea.style.overflowY = scrollHeight > TEXTAREA_MAX_HEIGHT ? 'auto' : 'hidden';
252
+ }
253
+ }, [input, textareaRef]);
254
+
255
+ const runAnimation = async () => {
256
+ if (chatStarted) {
257
+ return;
258
+ }
259
+
260
+ await Promise.all([
261
+ animate('#examples', { opacity: 0, display: 'none' }, { duration: 0.1 }),
262
+ animate('#intro', { opacity: 0, flex: 1 }, { duration: 0.2, ease: cubicEasingFn }),
263
+ ]);
264
+
265
+ chatStore.setKey('started', true);
266
+
267
+ setChatStarted(true);
268
+ };
269
+
270
+ const sendMessage = async (_event: React.UIEvent, messageInput?: string) => {
271
+ const _input = messageInput || input;
272
+
273
+ if (_input.length === 0 || isLoading) {
274
+ return;
275
+ }
276
+
277
+ /**
278
+ * @note (delm) Usually saving files shouldn't take long but it may take longer if there
279
+ * many unsaved files. In that case we need to block user input and show an indicator
280
+ * of some kind so the user is aware that something is happening. But I consider the
281
+ * happy case to be no unsaved files and I would expect users to save their changes
282
+ * before they send another message.
283
+ */
284
+ await workbenchStore.saveAllFiles();
285
+
286
+ const fileModifications = workbenchStore.getFileModifcations();
287
+
288
+ chatStore.setKey('aborted', false);
289
+
290
+ runAnimation();
291
+
292
+ if (!chatStarted && messageInput && autoSelectTemplate) {
293
+ setFakeLoading(true);
294
+ setMessages([
295
+ {
296
+ id: `${new Date().getTime()}`,
297
+ role: 'user',
298
+ content: [
299
+ {
300
+ type: 'text',
301
+ text: `[Model: ${model}]\n\n[Provider: ${provider.name}]\n\n${_input}`,
302
+ },
303
+ ...imageDataList.map((imageData) => ({
304
+ type: 'image',
305
+ image: imageData,
306
+ })),
307
+ ] as any, // Type assertion to bypass compiler check
308
+ },
309
+ ]);
310
+
311
+ // reload();
312
+
313
+ const { template, title } = await selectStarterTemplate({
314
+ message: messageInput,
315
+ model,
316
+ provider,
317
+ });
318
+
319
+ if (template !== 'blank') {
320
+ const temResp = await getTemplates(template, title).catch((e) => {
321
+ if (e.message.includes('rate limit')) {
322
+ toast.warning('Rate limit exceeded. Skipping starter template\n Continuing with blank template');
323
+ } else {
324
+ toast.warning('Failed to import starter template\n Continuing with blank template');
325
+ }
326
+
327
+ return null;
328
+ });
329
+
330
+ if (temResp) {
331
+ const { assistantMessage, userMessage } = temResp;
332
+
333
+ setMessages([
334
+ {
335
+ id: `${new Date().getTime()}`,
336
+ role: 'user',
337
+ content: messageInput,
338
+
339
+ // annotations: ['hidden'],
340
+ },
341
+ {
342
+ id: `${new Date().getTime()}`,
343
+ role: 'assistant',
344
+ content: assistantMessage,
345
+ },
346
+ {
347
+ id: `${new Date().getTime()}`,
348
+ role: 'user',
349
+ content: `[Model: ${model}]\n\n[Provider: ${provider.name}]\n\n${userMessage}`,
350
+ annotations: ['hidden'],
351
+ },
352
+ ]);
353
+
354
+ reload();
355
+ setFakeLoading(false);
356
+
357
+ return;
358
+ } else {
359
+ setMessages([
360
+ {
361
+ id: `${new Date().getTime()}`,
362
+ role: 'user',
363
+ content: [
364
+ {
365
+ type: 'text',
366
+ text: `[Model: ${model}]\n\n[Provider: ${provider.name}]\n\n${_input}`,
367
+ },
368
+ ...imageDataList.map((imageData) => ({
369
+ type: 'image',
370
+ image: imageData,
371
+ })),
372
+ ] as any, // Type assertion to bypass compiler check
373
+ },
374
+ ]);
375
+ reload();
376
+ setFakeLoading(false);
377
+
378
+ return;
379
+ }
380
+ } else {
381
+ setMessages([
382
+ {
383
+ id: `${new Date().getTime()}`,
384
+ role: 'user',
385
+ content: [
386
+ {
387
+ type: 'text',
388
+ text: `[Model: ${model}]\n\n[Provider: ${provider.name}]\n\n${_input}`,
389
+ },
390
+ ...imageDataList.map((imageData) => ({
391
+ type: 'image',
392
+ image: imageData,
393
+ })),
394
+ ] as any, // Type assertion to bypass compiler check
395
+ },
396
+ ]);
397
+ reload();
398
+ setFakeLoading(false);
399
+
400
+ return;
401
+ }
402
+ }
403
+
404
+ if (fileModifications !== undefined) {
405
+ /**
406
+ * If we have file modifications we append a new user message manually since we have to prefix
407
+ * the user input with the file modifications and we don't want the new user input to appear
408
+ * in the prompt. Using `append` is almost the same as `handleSubmit` except that we have to
409
+ * manually reset the input and we'd have to manually pass in file attachments. However, those
410
+ * aren't relevant here.
411
+ */
412
+ append({
413
+ role: 'user',
414
+ content: [
415
+ {
416
+ type: 'text',
417
+ text: `[Model: ${model}]\n\n[Provider: ${provider.name}]\n\n${_input}`,
418
+ },
419
+ ...imageDataList.map((imageData) => ({
420
+ type: 'image',
421
+ image: imageData,
422
+ })),
423
+ ] as any, // Type assertion to bypass compiler check
424
+ });
425
+
426
+ /**
427
+ * After sending a new message we reset all modifications since the model
428
+ * should now be aware of all the changes.
429
+ */
430
+ workbenchStore.resetAllFileModifications();
431
+ } else {
432
+ append({
433
+ role: 'user',
434
+ content: [
435
+ {
436
+ type: 'text',
437
+ text: `[Model: ${model}]\n\n[Provider: ${provider.name}]\n\n${_input}`,
438
+ },
439
+ ...imageDataList.map((imageData) => ({
440
+ type: 'image',
441
+ image: imageData,
442
+ })),
443
+ ] as any, // Type assertion to bypass compiler check
444
+ });
445
+ }
446
+
447
+ setInput('');
448
+ Cookies.remove(PROMPT_COOKIE_KEY);
449
+
450
+ // Add file cleanup here
451
+ setUploadedFiles([]);
452
+ setImageDataList([]);
453
+
454
+ resetEnhancer();
455
+
456
+ textareaRef.current?.blur();
457
+ };
458
+
459
+ /**
460
+ * Handles the change event for the textarea and updates the input state.
461
+ * @param event - The change event from the textarea.
462
+ */
463
+ const onTextareaChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
464
+ handleInputChange(event);
465
+ };
466
+
467
+ /**
468
+ * Debounced function to cache the prompt in cookies.
469
+ * Caches the trimmed value of the textarea input after a delay to optimize performance.
470
+ */
471
+ const debouncedCachePrompt = useCallback(
472
+ debounce((event: React.ChangeEvent<HTMLTextAreaElement>) => {
473
+ const trimmedValue = event.target.value.trim();
474
+ Cookies.set(PROMPT_COOKIE_KEY, trimmedValue, { expires: 30 });
475
+ }, 1000),
476
+ [],
477
+ );
478
+
479
+ const [messageRef, scrollRef] = useSnapScroll();
480
+
481
+ useEffect(() => {
482
+ const storedApiKeys = Cookies.get('apiKeys');
483
+
484
+ if (storedApiKeys) {
485
+ setApiKeys(JSON.parse(storedApiKeys));
486
+ }
487
+ }, []);
488
+
489
+ const handleModelChange = (newModel: string) => {
490
+ setModel(newModel);
491
+ Cookies.set('selectedModel', newModel, { expires: 30 });
492
+ };
493
+
494
+ const handleProviderChange = (newProvider: ProviderInfo) => {
495
+ setProvider(newProvider);
496
+ Cookies.set('selectedProvider', newProvider.name, { expires: 30 });
497
+ };
498
+
499
+ return (
500
+ <BaseChat
501
+ ref={animationScope}
502
+ textareaRef={textareaRef}
503
+ input={input}
504
+ showChat={showChat}
505
+ chatStarted={chatStarted}
506
+ isStreaming={isLoading || fakeLoading}
507
+ enhancingPrompt={enhancingPrompt}
508
+ promptEnhanced={promptEnhanced}
509
+ sendMessage={sendMessage}
510
+ model={model}
511
+ setModel={handleModelChange}
512
+ provider={provider}
513
+ setProvider={handleProviderChange}
514
+ providerList={activeProviders}
515
+ messageRef={messageRef}
516
+ scrollRef={scrollRef}
517
+ handleInputChange={(e) => {
518
+ onTextareaChange(e);
519
+ debouncedCachePrompt(e);
520
+ }}
521
+ handleStop={abort}
522
+ description={description}
523
+ importChat={importChat}
524
+ exportChat={exportChat}
525
+ messages={messages.map((message, i) => {
526
+ if (message.role === 'user') {
527
+ return message;
528
+ }
529
+
530
+ return {
531
+ ...message,
532
+ content: parsedMessages[i] || '',
533
+ };
534
+ })}
535
+ enhancePrompt={() => {
536
+ enhancePrompt(
537
+ input,
538
+ (input) => {
539
+ setInput(input);
540
+ scrollTextArea();
541
+ },
542
+ model,
543
+ provider,
544
+ apiKeys,
545
+ );
546
+ }}
547
+ uploadedFiles={uploadedFiles}
548
+ setUploadedFiles={setUploadedFiles}
549
+ imageDataList={imageDataList}
550
+ setImageDataList={setImageDataList}
551
+ actionAlert={actionAlert}
552
+ clearAlert={() => workbenchStore.clearAlert()}
553
+ />
554
+ );
555
+ },
556
+ );
app/components/chat/ChatAlert.tsx ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { AnimatePresence, motion } from 'framer-motion';
2
+ import type { ActionAlert } from '~/types/actions';
3
+ import { classNames } from '~/utils/classNames';
4
+
5
+ interface Props {
6
+ alert: ActionAlert;
7
+ clearAlert: () => void;
8
+ postMessage: (message: string) => void;
9
+ }
10
+
11
+ export default function ChatAlert({ alert, clearAlert, postMessage }: Props) {
12
+ const { description, content, source } = alert;
13
+
14
+ const isPreview = source === 'preview';
15
+ const title = isPreview ? 'Preview Error' : 'Terminal Error';
16
+ const message = isPreview
17
+ ? 'We encountered an error while running the preview. Would you like Bolt to analyze and help resolve this issue?'
18
+ : 'We encountered an error while running terminal commands. Would you like Bolt to analyze and help resolve this issue?';
19
+
20
+ return (
21
+ <AnimatePresence>
22
+ <motion.div
23
+ initial={{ opacity: 0, y: -20 }}
24
+ animate={{ opacity: 1, y: 0 }}
25
+ exit={{ opacity: 0, y: -20 }}
26
+ transition={{ duration: 0.3 }}
27
+ className={`rounded-lg border border-bolt-elements-borderColor bg-bolt-elements-background-depth-2 p-4`}
28
+ >
29
+ <div className="flex items-start">
30
+ {/* Icon */}
31
+ <motion.div
32
+ className="flex-shrink-0"
33
+ initial={{ scale: 0 }}
34
+ animate={{ scale: 1 }}
35
+ transition={{ delay: 0.2 }}
36
+ >
37
+ <div className={`i-ph:warning-duotone text-xl text-bolt-elements-button-danger-text`}></div>
38
+ </motion.div>
39
+ {/* Content */}
40
+ <div className="ml-3 flex-1">
41
+ <motion.h3
42
+ initial={{ opacity: 0 }}
43
+ animate={{ opacity: 1 }}
44
+ transition={{ delay: 0.1 }}
45
+ className={`text-sm font-medium text-bolt-elements-textPrimary`}
46
+ >
47
+ {title}
48
+ </motion.h3>
49
+ <motion.div
50
+ initial={{ opacity: 0 }}
51
+ animate={{ opacity: 1 }}
52
+ transition={{ delay: 0.2 }}
53
+ className={`mt-2 text-sm text-bolt-elements-textSecondary`}
54
+ >
55
+ <p>{message}</p>
56
+ {description && (
57
+ <div className="text-xs text-bolt-elements-textSecondary p-2 bg-bolt-elements-background-depth-3 rounded mt-4 mb-4">
58
+ Error: {description}
59
+ </div>
60
+ )}
61
+ </motion.div>
62
+
63
+ {/* Actions */}
64
+ <motion.div
65
+ className="mt-4"
66
+ initial={{ opacity: 0, y: 10 }}
67
+ animate={{ opacity: 1, y: 0 }}
68
+ transition={{ delay: 0.3 }}
69
+ >
70
+ <div className={classNames(' flex gap-2')}>
71
+ <button
72
+ onClick={() =>
73
+ postMessage(
74
+ `*Fix this ${isPreview ? 'preview' : 'terminal'} error* \n\`\`\`${isPreview ? 'js' : 'sh'}\n${content}\n\`\`\`\n`,
75
+ )
76
+ }
77
+ className={classNames(
78
+ `px-2 py-1.5 rounded-md text-sm font-medium`,
79
+ 'bg-bolt-elements-button-primary-background',
80
+ 'hover:bg-bolt-elements-button-primary-backgroundHover',
81
+ 'focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-bolt-elements-button-danger-background',
82
+ 'text-bolt-elements-button-primary-text',
83
+ 'flex items-center gap-1.5',
84
+ )}
85
+ >
86
+ <div className="i-ph:chat-circle-duotone"></div>
87
+ Ask Bolt
88
+ </button>
89
+ <button
90
+ onClick={clearAlert}
91
+ className={classNames(
92
+ `px-2 py-1.5 rounded-md text-sm font-medium`,
93
+ 'bg-bolt-elements-button-secondary-background',
94
+ 'hover:bg-bolt-elements-button-secondary-backgroundHover',
95
+ 'focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-bolt-elements-button-secondary-background',
96
+ 'text-bolt-elements-button-secondary-text',
97
+ )}
98
+ >
99
+ Dismiss
100
+ </button>
101
+ </div>
102
+ </motion.div>
103
+ </div>
104
+ </div>
105
+ </motion.div>
106
+ </AnimatePresence>
107
+ );
108
+ }
app/components/chat/CodeBlock.module.scss ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ .CopyButtonContainer {
2
+ button:before {
3
+ content: 'Copied';
4
+ font-size: 12px;
5
+ position: absolute;
6
+ left: -53px;
7
+ padding: 2px 6px;
8
+ height: 30px;
9
+ }
10
+ }