bolt.diy
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .dockerignore +26 -0
- .editorconfig +13 -0
- .env +90 -0
- .env.example +106 -0
- .gitattributes +35 -35
- .gitignore +42 -0
- .husky/_/.gitignore +1 -0
- .husky/_/applypatch-msg +2 -0
- .husky/_/commit-msg +2 -0
- .husky/_/h +22 -0
- .husky/_/husky.sh +9 -0
- .husky/_/post-applypatch +2 -0
- .husky/_/post-checkout +2 -0
- .husky/_/post-commit +2 -0
- .husky/_/post-merge +2 -0
- .husky/_/post-rewrite +2 -0
- .husky/_/pre-applypatch +2 -0
- .husky/_/pre-auto-gc +2 -0
- .husky/_/pre-commit +2 -0
- .husky/_/pre-merge-commit +2 -0
- .husky/_/pre-push +2 -0
- .husky/_/pre-rebase +2 -0
- .husky/_/prepare-commit-msg +2 -0
- .husky/pre-commit +32 -0
- .prettierignore +2 -0
- .prettierrc +8 -0
- .tool-versions +2 -0
- CONTRIBUTING.md +219 -0
- Dockerfile +92 -0
- FAQ.md +91 -0
- LICENSE +21 -0
- README.md +329 -12
- app/components/chat/APIKeyManager.tsx +85 -0
- app/components/chat/Artifact.tsx +263 -0
- app/components/chat/AssistantMessage.tsx +31 -0
- app/components/chat/BaseChat.module.scss +47 -0
- app/components/chat/BaseChat.tsx +626 -0
- app/components/chat/Chat.client.tsx +536 -0
- app/components/chat/ChatAlert.tsx +108 -0
- app/components/chat/CodeBlock.module.scss +10 -0
- app/components/chat/CodeBlock.tsx +82 -0
- app/components/chat/ExamplePrompts.tsx +36 -0
- app/components/chat/FilePreview.tsx +35 -0
- app/components/chat/GitCloneButton.tsx +125 -0
- app/components/chat/ImportFolderButton.tsx +128 -0
- app/components/chat/Markdown.module.scss +171 -0
- app/components/chat/Markdown.spec.ts +48 -0
- app/components/chat/Markdown.tsx +118 -0
- app/components/chat/Messages.client.tsx +115 -0
- app/components/chat/ModelSelector.tsx +106 -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
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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=sk-5b08a4b7e19a43119da602407af429f5
|
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=https://api.hyperbolic.xyz/v1
|
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=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjNqaWdtZTEyM0BnbWFpbC5jb20iLCJpYXQiOjE3MzU4NDc4MDd9.pGqbhfZmGrueciclEqr7w77idv4MBzT4-ZHuQChHVzQ
|
50 |
+
#model=accounts/fireworks/models/deepseek-v3
|
51 |
+
|
52 |
+
# Get your Together API Key
|
53 |
+
TOGETHER_API_KEY=
|
54 |
+
|
55 |
+
# Get your Mistral API Key by following these instructions -
|
56 |
+
# https://console.mistral.ai/api-keys/
|
57 |
+
# You only need this environment variable set if you want to use Mistral models
|
58 |
+
MISTRAL_API_KEY=
|
59 |
+
|
60 |
+
# Get the Cohere Api key by following these instructions -
|
61 |
+
# https://dashboard.cohere.com/api-keys
|
62 |
+
# You only need this environment variable set if you want to use Cohere models
|
63 |
+
COHERE_API_KEY=
|
64 |
+
|
65 |
+
# Get LMStudio Base URL from LM Studio Developer Console
|
66 |
+
# Make sure to enable CORS
|
67 |
+
# DONT USE http://localhost:1234 due to IPV6 issues
|
68 |
+
# Example: http://127.0.0.1:1234
|
69 |
+
LMSTUDIO_API_BASE_URL=
|
70 |
+
|
71 |
+
# Get your xAI API key
|
72 |
+
# https://x.ai/api
|
73 |
+
# You only need this environment variable set if you want to use xAI models
|
74 |
+
XAI_API_KEY=
|
75 |
+
|
76 |
+
# Get your Perplexity API Key here -
|
77 |
+
# https://www.perplexity.ai/settings/api
|
78 |
+
# You only need this environment variable set if you want to use Perplexity models
|
79 |
+
PERPLEXITY_API_KEY=
|
80 |
+
|
81 |
+
# Include this environment variable if you want more logging for debugging locally
|
82 |
+
VITE_LOG_LEVEL=debug
|
83 |
+
|
84 |
+
# Example Context Values for qwen2.5-coder:32b
|
85 |
+
#
|
86 |
+
# DEFAULT_NUM_CTX=32768 # Consumes 36GB of VRAM
|
87 |
+
# DEFAULT_NUM_CTX=24576 # Consumes 32GB of VRAM
|
88 |
+
# DEFAULT_NUM_CTX=12288 # Consumes 26GB of VRAM
|
89 |
+
# DEFAULT_NUM_CTX=6144 # Consumes 24GB of VRAM
|
90 |
+
DEFAULT_NUM_CTX=
|
.env.example
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
# Get your AWS configuration
|
87 |
+
# https://console.aws.amazon.com/iam/home
|
88 |
+
# The JSON should include the following keys:
|
89 |
+
# - region: The AWS region where Bedrock is available.
|
90 |
+
# - accessKeyId: Your AWS access key ID.
|
91 |
+
# - secretAccessKey: Your AWS secret access key.
|
92 |
+
# - sessionToken (optional): Temporary session token if using an IAM role or temporary credentials.
|
93 |
+
# Example JSON:
|
94 |
+
# {"region": "us-east-1", "accessKeyId": "yourAccessKeyId", "secretAccessKey": "yourSecretAccessKey", "sessionToken": "yourSessionToken"}
|
95 |
+
AWS_BEDROCK_CONFIG=
|
96 |
+
|
97 |
+
# Include this environment variable if you want more logging for debugging locally
|
98 |
+
VITE_LOG_LEVEL=debug
|
99 |
+
|
100 |
+
# Example Context Values for qwen2.5-coder:32b
|
101 |
+
#
|
102 |
+
# DEFAULT_NUM_CTX=32768 # Consumes 36GB of VRAM
|
103 |
+
# DEFAULT_NUM_CTX=24576 # Consumes 32GB of VRAM
|
104 |
+
# DEFAULT_NUM_CTX=12288 # Consumes 26GB of VRAM
|
105 |
+
# DEFAULT_NUM_CTX=6144 # Consumes 24GB of VRAM
|
106 |
+
DEFAULT_NUM_CTX=
|
.gitattributes
CHANGED
@@ -1,35 +1,35 @@
|
|
1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
.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,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 AWS_BEDROCK_CONFIG
|
32 |
+
ARG VITE_LOG_LEVEL=debug
|
33 |
+
ARG DEFAULT_NUM_CTX
|
34 |
+
|
35 |
+
ENV WRANGLER_SEND_METRICS=false \
|
36 |
+
GROQ_API_KEY=${GROQ_API_KEY} \
|
37 |
+
HuggingFace_KEY=${HuggingFace_API_KEY} \
|
38 |
+
OPENAI_API_KEY=${OPENAI_API_KEY} \
|
39 |
+
ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY} \
|
40 |
+
OPEN_ROUTER_API_KEY=${OPEN_ROUTER_API_KEY} \
|
41 |
+
GOOGLE_GENERATIVE_AI_API_KEY=${GOOGLE_GENERATIVE_AI_API_KEY} \
|
42 |
+
OLLAMA_API_BASE_URL=${OLLAMA_API_BASE_URL} \
|
43 |
+
XAI_API_KEY=${XAI_API_KEY} \
|
44 |
+
TOGETHER_API_KEY=${TOGETHER_API_KEY} \
|
45 |
+
TOGETHER_API_BASE_URL=${TOGETHER_API_BASE_URL} \
|
46 |
+
AWS_BEDROCK_CONFIG=${AWS_BEDROCK_CONFIG} \
|
47 |
+
VITE_LOG_LEVEL=${VITE_LOG_LEVEL} \
|
48 |
+
DEFAULT_NUM_CTX=${DEFAULT_NUM_CTX}\
|
49 |
+
RUNNING_IN_DOCKER=true
|
50 |
+
|
51 |
+
# Pre-configure wrangler to disable metrics
|
52 |
+
RUN mkdir -p /root/.config/.wrangler && \
|
53 |
+
echo '{"enabled":false}' > /root/.config/.wrangler/metrics.json
|
54 |
+
|
55 |
+
RUN pnpm run build
|
56 |
+
|
57 |
+
CMD [ "pnpm", "run", "dockerstart"]
|
58 |
+
|
59 |
+
# Development image
|
60 |
+
FROM base AS bolt-ai-development
|
61 |
+
|
62 |
+
# Define the same environment variables for development
|
63 |
+
ARG GROQ_API_KEY
|
64 |
+
ARG HuggingFace
|
65 |
+
ARG OPENAI_API_KEY
|
66 |
+
ARG ANTHROPIC_API_KEY
|
67 |
+
ARG OPEN_ROUTER_API_KEY
|
68 |
+
ARG GOOGLE_GENERATIVE_AI_API_KEY
|
69 |
+
ARG OLLAMA_API_BASE_URL
|
70 |
+
ARG XAI_API_KEY
|
71 |
+
ARG TOGETHER_API_KEY
|
72 |
+
ARG TOGETHER_API_BASE_URL
|
73 |
+
ARG VITE_LOG_LEVEL=debug
|
74 |
+
ARG DEFAULT_NUM_CTX
|
75 |
+
|
76 |
+
ENV GROQ_API_KEY=${GROQ_API_KEY} \
|
77 |
+
HuggingFace_API_KEY=${HuggingFace_API_KEY} \
|
78 |
+
OPENAI_API_KEY=${OPENAI_API_KEY} \
|
79 |
+
ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY} \
|
80 |
+
OPEN_ROUTER_API_KEY=${OPEN_ROUTER_API_KEY} \
|
81 |
+
GOOGLE_GENERATIVE_AI_API_KEY=${GOOGLE_GENERATIVE_AI_API_KEY} \
|
82 |
+
OLLAMA_API_BASE_URL=${OLLAMA_API_BASE_URL} \
|
83 |
+
XAI_API_KEY=${XAI_API_KEY} \
|
84 |
+
TOGETHER_API_KEY=${TOGETHER_API_KEY} \
|
85 |
+
TOGETHER_API_BASE_URL=${TOGETHER_API_BASE_URL} \
|
86 |
+
AWS_BEDROCK_CONFIG=${AWS_BEDROCK_CONFIG} \
|
87 |
+
VITE_LOG_LEVEL=${VITE_LOG_LEVEL} \
|
88 |
+
DEFAULT_NUM_CTX=${DEFAULT_NUM_CTX}\
|
89 |
+
RUNNING_IN_DOCKER=true
|
90 |
+
|
91 |
+
RUN mkdir -p ${WORKDIR}/run
|
92 |
+
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,12 +1,329 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
Also [this pinned post in our community](https://thinktank.ottomator.ai/t/videos-tutorial-helpful-content/3243) has a bunch of incredible resources for running and deploying bolt.diy yourself!
|
9 |
+
|
10 |
+
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/).
|
11 |
+
|
12 |
+
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!
|
13 |
+
|
14 |
+
## Table of Contents
|
15 |
+
|
16 |
+
- [Join the Community](#join-the-community)
|
17 |
+
- [Requested Additions](#requested-additions)
|
18 |
+
- [Features](#features)
|
19 |
+
- [Setup](#setup)
|
20 |
+
- [Run the Application](#run-the-application)
|
21 |
+
- [Available Scripts](#available-scripts)
|
22 |
+
- [Contributing](#contributing)
|
23 |
+
- [Roadmap](#roadmap)
|
24 |
+
- [FAQ](#faq)
|
25 |
+
|
26 |
+
## Join the community
|
27 |
+
|
28 |
+
[Join the bolt.diy community here, in the oTTomator Think Tank!](https://thinktank.ottomator.ai)
|
29 |
+
|
30 |
+
|
31 |
+
## Requested Additions
|
32 |
+
|
33 |
+
- ✅ OpenRouter Integration (@coleam00)
|
34 |
+
- ✅ Gemini Integration (@jonathands)
|
35 |
+
- ✅ Autogenerate Ollama models from what is downloaded (@yunatamos)
|
36 |
+
- ✅ Filter models by provider (@jasonm23)
|
37 |
+
- ✅ Download project as ZIP (@fabwaseem)
|
38 |
+
- ✅ Improvements to the main bolt.new prompt in `app\lib\.server\llm\prompts.ts` (@kofi-bhr)
|
39 |
+
- ✅ DeepSeek API Integration (@zenith110)
|
40 |
+
- ✅ Mistral API Integration (@ArulGandhi)
|
41 |
+
- ✅ "Open AI Like" API Integration (@ZerxZ)
|
42 |
+
- ✅ Ability to sync files (one way sync) to local folder (@muzafferkadir)
|
43 |
+
- ✅ Containerize the application with Docker for easy installation (@aaronbolton)
|
44 |
+
- ✅ Publish projects directly to GitHub (@goncaloalves)
|
45 |
+
- ✅ Ability to enter API keys in the UI (@ali00209)
|
46 |
+
- ✅ xAI Grok Beta Integration (@milutinke)
|
47 |
+
- ✅ LM Studio Integration (@karrot0)
|
48 |
+
- ✅ HuggingFace Integration (@ahsan3219)
|
49 |
+
- ✅ Bolt terminal to see the output of LLM run commands (@thecodacus)
|
50 |
+
- ✅ Streaming of code output (@thecodacus)
|
51 |
+
- ✅ Ability to revert code to earlier version (@wonderwhy-er)
|
52 |
+
- ✅ Cohere Integration (@hasanraiyan)
|
53 |
+
- ✅ Dynamic model max token length (@hasanraiyan)
|
54 |
+
- ✅ Better prompt enhancing (@SujalXplores)
|
55 |
+
- ✅ Prompt caching (@SujalXplores)
|
56 |
+
- ✅ Load local projects into the app (@wonderwhy-er)
|
57 |
+
- ✅ Together Integration (@mouimet-infinisoft)
|
58 |
+
- ✅ Mobile friendly (@qwikode)
|
59 |
+
- ✅ Better prompt enhancing (@SujalXplores)
|
60 |
+
- ✅ Attach images to prompts (@atrokhym)
|
61 |
+
- ✅ Added Git Clone button (@thecodacus)
|
62 |
+
- ✅ Git Import from url (@thecodacus)
|
63 |
+
- ✅ PromptLibrary to have different variations of prompts for different use cases (@thecodacus)
|
64 |
+
- ✅ Detect package.json and commands to auto install & run preview for folder and git import (@wonderwhy-er)
|
65 |
+
- ✅ Selection tool to target changes visually (@emcconnell)
|
66 |
+
- ✅ Detect terminal Errors and ask bolt to fix it (@thecodacus)
|
67 |
+
- ✅ Detect preview Errors and ask bolt to fix it (@wonderwhy-er)
|
68 |
+
- ✅ Add Starter Template Options (@thecodacus)
|
69 |
+
- ✅ Perplexity Integration (@meetpateltech)
|
70 |
+
- ✅ AWS Bedrock Integration (@kunjabijukchhe)
|
71 |
+
- ⬜ **HIGH PRIORITY** - Prevent bolt from rewriting files as often (file locking and diffs)
|
72 |
+
- ⬜ **HIGH PRIORITY** - Better prompting for smaller LLMs (code window sometimes doesn't start)
|
73 |
+
- ⬜ **HIGH PRIORITY** - Run agents in the backend as opposed to a single model call
|
74 |
+
- ⬜ Deploy directly to Vercel/Netlify/other similar platforms
|
75 |
+
- ⬜ Have LLM plan the project in a MD file for better results/transparency
|
76 |
+
- ⬜ VSCode Integration with git-like confirmations
|
77 |
+
- ⬜ Upload documents for knowledge - UI design templates, a code base to reference coding style, etc.
|
78 |
+
- ⬜ Voice prompting
|
79 |
+
- ⬜ Azure Open AI API Integration
|
80 |
+
- ⬜ Vertex AI Integration
|
81 |
+
|
82 |
+
## Features
|
83 |
+
|
84 |
+
- **AI-powered full-stack web development** directly in your browser.
|
85 |
+
- **Support for multiple LLMs** with an extensible architecture to integrate additional models.
|
86 |
+
- **Attach images to prompts** for better contextual understanding.
|
87 |
+
- **Integrated terminal** to view output of LLM-run commands.
|
88 |
+
- **Revert code to earlier versions** for easier debugging and quicker changes.
|
89 |
+
- **Download projects as ZIP** for easy portability.
|
90 |
+
- **Integration-ready Docker support** for a hassle-free setup.
|
91 |
+
|
92 |
+
## Setup
|
93 |
+
|
94 |
+
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.
|
95 |
+
|
96 |
+
Let's get you up and running with the stable version of Bolt.DIY!
|
97 |
+
|
98 |
+
## Quick Download
|
99 |
+
|
100 |
+
[![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!
|
101 |
+
|
102 |
+
- Next **click source.zip**
|
103 |
+
|
104 |
+
|
105 |
+
|
106 |
+
|
107 |
+
## Prerequisites
|
108 |
+
|
109 |
+
Before you begin, you'll need to install two important pieces of software:
|
110 |
+
|
111 |
+
### Install Node.js
|
112 |
+
|
113 |
+
Node.js is required to run the application.
|
114 |
+
|
115 |
+
1. Visit the [Node.js Download Page](https://nodejs.org/en/download/)
|
116 |
+
2. Download the "LTS" (Long Term Support) version for your operating system
|
117 |
+
3. Run the installer, accepting the default settings
|
118 |
+
4. Verify Node.js is properly installed:
|
119 |
+
- **For Windows Users**:
|
120 |
+
1. Press `Windows + R`
|
121 |
+
2. Type "sysdm.cpl" and press Enter
|
122 |
+
3. Go to "Advanced" tab → "Environment Variables"
|
123 |
+
4. Check if `Node.js` appears in the "Path" variable
|
124 |
+
- **For Mac/Linux Users**:
|
125 |
+
1. Open Terminal
|
126 |
+
2. Type this command:
|
127 |
+
```bash
|
128 |
+
echo $PATH
|
129 |
+
```
|
130 |
+
3. Look for `/usr/local/bin` in the output
|
131 |
+
|
132 |
+
## Running the Application
|
133 |
+
|
134 |
+
You have two options for running Bolt.DIY: directly on your machine or using Docker.
|
135 |
+
|
136 |
+
### Option 1: Direct Installation (Recommended for Beginners)
|
137 |
+
|
138 |
+
1. **Install Package Manager (pnpm)**:
|
139 |
+
```bash
|
140 |
+
npm install -g pnpm
|
141 |
+
```
|
142 |
+
|
143 |
+
2. **Install Project Dependencies**:
|
144 |
+
```bash
|
145 |
+
pnpm install
|
146 |
+
```
|
147 |
+
|
148 |
+
3. **Start the Application**:
|
149 |
+
```bash
|
150 |
+
pnpm run dev
|
151 |
+
```
|
152 |
+
|
153 |
+
**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/)
|
154 |
+
|
155 |
+
### Option 2: Using Docker
|
156 |
+
|
157 |
+
This option requires some familiarity with Docker but provides a more isolated environment.
|
158 |
+
|
159 |
+
#### Additional Prerequisite
|
160 |
+
- Install Docker: [Download Docker](https://www.docker.com/)
|
161 |
+
|
162 |
+
#### Steps:
|
163 |
+
|
164 |
+
1. **Build the Docker Image**:
|
165 |
+
```bash
|
166 |
+
# Using npm script:
|
167 |
+
npm run dockerbuild
|
168 |
+
|
169 |
+
# OR using direct Docker command:
|
170 |
+
docker build . --target bolt-ai-development
|
171 |
+
```
|
172 |
+
|
173 |
+
2. **Run the Container**:
|
174 |
+
```bash
|
175 |
+
docker-compose --profile development up
|
176 |
+
```
|
177 |
+
|
178 |
+
|
179 |
+
|
180 |
+
|
181 |
+
## Configuring API Keys and Providers
|
182 |
+
|
183 |
+
### Adding Your API Keys
|
184 |
+
|
185 |
+
Setting up your API keys in Bolt.DIY is straightforward:
|
186 |
+
|
187 |
+
1. Open the home page (main interface)
|
188 |
+
2. Select your desired provider from the dropdown menu
|
189 |
+
3. Click the pencil (edit) icon
|
190 |
+
4. Enter your API key in the secure input field
|
191 |
+
|
192 |
+
![API Key Configuration Interface](./docs/images/api-key-ui-section.png)
|
193 |
+
|
194 |
+
### Configuring Custom Base URLs
|
195 |
+
|
196 |
+
For providers that support custom base URLs (such as Ollama or LM Studio), follow these steps:
|
197 |
+
|
198 |
+
1. Click the settings icon in the sidebar to open the settings menu
|
199 |
+
![Settings Button Location](./docs/images/bolt-settings-button.png)
|
200 |
+
|
201 |
+
2. Navigate to the "Providers" tab
|
202 |
+
3. Search for your provider using the search bar
|
203 |
+
4. Enter your custom base URL in the designated field
|
204 |
+
![Provider Base URL Configuration](./docs/images/provider-base-url.png)
|
205 |
+
|
206 |
+
> **Note**: Custom base URLs are particularly useful when running local instances of AI models or using custom API endpoints.
|
207 |
+
|
208 |
+
### Supported Providers
|
209 |
+
- Ollama
|
210 |
+
- LM Studio
|
211 |
+
- OpenAILike
|
212 |
+
|
213 |
+
## Setup Using Git (For Developers only)
|
214 |
+
|
215 |
+
This method is recommended for developers who want to:
|
216 |
+
- Contribute to the project
|
217 |
+
- Stay updated with the latest changes
|
218 |
+
- Switch between different versions
|
219 |
+
- Create custom modifications
|
220 |
+
|
221 |
+
#### Prerequisites
|
222 |
+
1. Install Git: [Download Git](https://git-scm.com/downloads)
|
223 |
+
|
224 |
+
#### Initial Setup
|
225 |
+
|
226 |
+
1. **Clone the Repository**:
|
227 |
+
```bash
|
228 |
+
# Using HTTPS
|
229 |
+
git clone https://github.com/stackblitz-labs/bolt.diy.git
|
230 |
+
```
|
231 |
+
|
232 |
+
2. **Navigate to Project Directory**:
|
233 |
+
```bash
|
234 |
+
cd bolt.diy
|
235 |
+
```
|
236 |
+
|
237 |
+
3. **Switch to the Main Branch**:
|
238 |
+
```bash
|
239 |
+
git checkout main
|
240 |
+
```
|
241 |
+
4. **Install Dependencies**:
|
242 |
+
```bash
|
243 |
+
pnpm install
|
244 |
+
```
|
245 |
+
|
246 |
+
5. **Start the Development Server**:
|
247 |
+
```bash
|
248 |
+
pnpm run dev
|
249 |
+
```
|
250 |
+
|
251 |
+
#### Staying Updated
|
252 |
+
|
253 |
+
To get the latest changes from the repository:
|
254 |
+
|
255 |
+
1. **Save Your Local Changes** (if any):
|
256 |
+
```bash
|
257 |
+
git stash
|
258 |
+
```
|
259 |
+
|
260 |
+
2. **Pull Latest Updates**:
|
261 |
+
```bash
|
262 |
+
git pull origin main
|
263 |
+
```
|
264 |
+
|
265 |
+
3. **Update Dependencies**:
|
266 |
+
```bash
|
267 |
+
pnpm install
|
268 |
+
```
|
269 |
+
|
270 |
+
4. **Restore Your Local Changes** (if any):
|
271 |
+
```bash
|
272 |
+
git stash pop
|
273 |
+
```
|
274 |
+
|
275 |
+
#### Troubleshooting Git Setup
|
276 |
+
|
277 |
+
If you encounter issues:
|
278 |
+
|
279 |
+
1. **Clean Installation**:
|
280 |
+
```bash
|
281 |
+
# Remove node modules and lock files
|
282 |
+
rm -rf node_modules pnpm-lock.yaml
|
283 |
+
|
284 |
+
# Clear pnpm cache
|
285 |
+
pnpm store prune
|
286 |
+
|
287 |
+
# Reinstall dependencies
|
288 |
+
pnpm install
|
289 |
+
```
|
290 |
+
|
291 |
+
2. **Reset Local Changes**:
|
292 |
+
```bash
|
293 |
+
# Discard all local changes
|
294 |
+
git reset --hard origin/main
|
295 |
+
```
|
296 |
+
|
297 |
+
Remember to always commit your local changes or stash them before pulling updates to avoid conflicts.
|
298 |
+
|
299 |
+
---
|
300 |
+
|
301 |
+
## Available Scripts
|
302 |
+
|
303 |
+
- **`pnpm run dev`**: Starts the development server.
|
304 |
+
- **`pnpm run build`**: Builds the project.
|
305 |
+
- **`pnpm run start`**: Runs the built application locally using Wrangler Pages.
|
306 |
+
- **`pnpm run preview`**: Builds and runs the production build locally.
|
307 |
+
- **`pnpm test`**: Runs the test suite using Vitest.
|
308 |
+
- **`pnpm run typecheck`**: Runs TypeScript type checking.
|
309 |
+
- **`pnpm run typegen`**: Generates TypeScript types using Wrangler.
|
310 |
+
- **`pnpm run deploy`**: Deploys the project to Cloudflare Pages.
|
311 |
+
- **`pnpm run lint:fix`**: Automatically fixes linting issues.
|
312 |
+
|
313 |
+
---
|
314 |
+
|
315 |
+
## Contributing
|
316 |
+
|
317 |
+
We welcome contributions! Check out our [Contributing Guide](CONTRIBUTING.md) to get started.
|
318 |
+
|
319 |
+
---
|
320 |
+
|
321 |
+
## Roadmap
|
322 |
+
|
323 |
+
Explore upcoming features and priorities on our [Roadmap](https://roadmap.sh/r/ottodev-roadmap-2ovzo).
|
324 |
+
|
325 |
+
---
|
326 |
+
|
327 |
+
## FAQ
|
328 |
+
|
329 |
+
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,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React, { useState } from 'react';
|
2 |
+
import { IconButton } from '~/components/ui/IconButton';
|
3 |
+
import type { ProviderInfo } from '~/types/model';
|
4 |
+
import Cookies from 'js-cookie';
|
5 |
+
|
6 |
+
interface APIKeyManagerProps {
|
7 |
+
provider: ProviderInfo;
|
8 |
+
apiKey: string;
|
9 |
+
setApiKey: (key: string) => void;
|
10 |
+
getApiKeyLink?: string;
|
11 |
+
labelForGetApiKey?: string;
|
12 |
+
}
|
13 |
+
|
14 |
+
const apiKeyMemoizeCache: { [k: string]: Record<string, string> } = {};
|
15 |
+
|
16 |
+
export function getApiKeysFromCookies() {
|
17 |
+
const storedApiKeys = Cookies.get('apiKeys');
|
18 |
+
let parsedKeys = {};
|
19 |
+
|
20 |
+
if (storedApiKeys) {
|
21 |
+
parsedKeys = apiKeyMemoizeCache[storedApiKeys];
|
22 |
+
|
23 |
+
if (!parsedKeys) {
|
24 |
+
parsedKeys = apiKeyMemoizeCache[storedApiKeys] = JSON.parse(storedApiKeys);
|
25 |
+
}
|
26 |
+
}
|
27 |
+
|
28 |
+
return parsedKeys;
|
29 |
+
}
|
30 |
+
|
31 |
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
32 |
+
export const APIKeyManager: React.FC<APIKeyManagerProps> = ({ provider, apiKey, setApiKey }) => {
|
33 |
+
const [isEditing, setIsEditing] = useState(false);
|
34 |
+
const [tempKey, setTempKey] = useState(apiKey);
|
35 |
+
|
36 |
+
const handleSave = () => {
|
37 |
+
setApiKey(tempKey);
|
38 |
+
setIsEditing(false);
|
39 |
+
};
|
40 |
+
|
41 |
+
return (
|
42 |
+
<div className="flex items-start sm:items-center mt-2 mb-2 flex-col sm:flex-row">
|
43 |
+
<div>
|
44 |
+
<span className="text-sm text-bolt-elements-textSecondary">{provider?.name} API Key:</span>
|
45 |
+
{!isEditing && (
|
46 |
+
<div className="flex items-center mb-4">
|
47 |
+
<span className="flex-1 text-xs text-bolt-elements-textPrimary mr-2">
|
48 |
+
{apiKey ? '••••••••' : 'Not set (will still work if set in .env file)'}
|
49 |
+
</span>
|
50 |
+
<IconButton onClick={() => setIsEditing(true)} title="Edit API Key">
|
51 |
+
<div className="i-ph:pencil-simple" />
|
52 |
+
</IconButton>
|
53 |
+
</div>
|
54 |
+
)}
|
55 |
+
</div>
|
56 |
+
|
57 |
+
{isEditing ? (
|
58 |
+
<div className="flex items-center gap-3 mt-2">
|
59 |
+
<input
|
60 |
+
type="password"
|
61 |
+
value={tempKey}
|
62 |
+
placeholder="Your API Key"
|
63 |
+
onChange={(e) => setTempKey(e.target.value)}
|
64 |
+
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"
|
65 |
+
/>
|
66 |
+
<IconButton onClick={handleSave} title="Save API Key">
|
67 |
+
<div className="i-ph:check" />
|
68 |
+
</IconButton>
|
69 |
+
<IconButton onClick={() => setIsEditing(false)} title="Cancel">
|
70 |
+
<div className="i-ph:x" />
|
71 |
+
</IconButton>
|
72 |
+
</div>
|
73 |
+
) : (
|
74 |
+
<>
|
75 |
+
{provider?.getApiKeyLink && (
|
76 |
+
<IconButton className="ml-auto" onClick={() => window.open(provider?.getApiKeyLink)} title="Edit API Key">
|
77 |
+
<span className="mr-2 text-xs lg:text-sm">{provider?.labelForGetApiKey || 'Get API Key'}</span>
|
78 |
+
<div className={provider?.icon || 'i-ph:key'} />
|
79 |
+
</IconButton>
|
80 |
+
)}
|
81 |
+
</>
|
82 |
+
)}
|
83 |
+
</div>
|
84 |
+
);
|
85 |
+
};
|
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,536 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
const [model, setModel] = useState(() => {
|
126 |
+
const savedModel = Cookies.get('selectedModel');
|
127 |
+
return savedModel || DEFAULT_MODEL;
|
128 |
+
});
|
129 |
+
const [provider, setProvider] = useState(() => {
|
130 |
+
const savedProvider = Cookies.get('selectedProvider');
|
131 |
+
return (PROVIDER_LIST.find((p) => p.name === savedProvider) || DEFAULT_PROVIDER) as ProviderInfo;
|
132 |
+
});
|
133 |
+
|
134 |
+
const { showChat } = useStore(chatStore);
|
135 |
+
|
136 |
+
const [animationScope, animate] = useAnimate();
|
137 |
+
|
138 |
+
const [apiKeys, setApiKeys] = useState<Record<string, string>>({});
|
139 |
+
|
140 |
+
const { messages, isLoading, input, handleInputChange, setInput, stop, append, setMessages, reload } = useChat({
|
141 |
+
api: '/api/chat',
|
142 |
+
body: {
|
143 |
+
apiKeys,
|
144 |
+
files,
|
145 |
+
promptId,
|
146 |
+
contextOptimization: contextOptimizationEnabled,
|
147 |
+
},
|
148 |
+
sendExtraMessageFields: true,
|
149 |
+
onError: (error) => {
|
150 |
+
logger.error('Request failed\n\n', error);
|
151 |
+
toast.error(
|
152 |
+
'There was an error processing your request: ' + (error.message ? error.message : 'No details were returned'),
|
153 |
+
);
|
154 |
+
},
|
155 |
+
onFinish: (message, response) => {
|
156 |
+
const usage = response.usage;
|
157 |
+
|
158 |
+
if (usage) {
|
159 |
+
console.log('Token usage:', usage);
|
160 |
+
|
161 |
+
// You can now use the usage data as needed
|
162 |
+
}
|
163 |
+
|
164 |
+
logger.debug('Finished streaming');
|
165 |
+
},
|
166 |
+
initialMessages,
|
167 |
+
initialInput: Cookies.get(PROMPT_COOKIE_KEY) || '',
|
168 |
+
});
|
169 |
+
useEffect(() => {
|
170 |
+
const prompt = searchParams.get('prompt');
|
171 |
+
|
172 |
+
// console.log(prompt, searchParams, model, provider);
|
173 |
+
|
174 |
+
if (prompt) {
|
175 |
+
setSearchParams({});
|
176 |
+
runAnimation();
|
177 |
+
append({
|
178 |
+
role: 'user',
|
179 |
+
content: [
|
180 |
+
{
|
181 |
+
type: 'text',
|
182 |
+
text: `[Model: ${model}]\n\n[Provider: ${provider.name}]\n\n${prompt}`,
|
183 |
+
},
|
184 |
+
] as any, // Type assertion to bypass compiler check
|
185 |
+
});
|
186 |
+
}
|
187 |
+
}, [model, provider, searchParams]);
|
188 |
+
|
189 |
+
const { enhancingPrompt, promptEnhanced, enhancePrompt, resetEnhancer } = usePromptEnhancer();
|
190 |
+
const { parsedMessages, parseMessages } = useMessageParser();
|
191 |
+
|
192 |
+
const TEXTAREA_MAX_HEIGHT = chatStarted ? 400 : 200;
|
193 |
+
|
194 |
+
useEffect(() => {
|
195 |
+
chatStore.setKey('started', initialMessages.length > 0);
|
196 |
+
}, []);
|
197 |
+
|
198 |
+
useEffect(() => {
|
199 |
+
processSampledMessages({
|
200 |
+
messages,
|
201 |
+
initialMessages,
|
202 |
+
isLoading,
|
203 |
+
parseMessages,
|
204 |
+
storeMessageHistory,
|
205 |
+
});
|
206 |
+
}, [messages, isLoading, parseMessages]);
|
207 |
+
|
208 |
+
const scrollTextArea = () => {
|
209 |
+
const textarea = textareaRef.current;
|
210 |
+
|
211 |
+
if (textarea) {
|
212 |
+
textarea.scrollTop = textarea.scrollHeight;
|
213 |
+
}
|
214 |
+
};
|
215 |
+
|
216 |
+
const abort = () => {
|
217 |
+
stop();
|
218 |
+
chatStore.setKey('aborted', true);
|
219 |
+
workbenchStore.abortAllActions();
|
220 |
+
};
|
221 |
+
|
222 |
+
useEffect(() => {
|
223 |
+
const textarea = textareaRef.current;
|
224 |
+
|
225 |
+
if (textarea) {
|
226 |
+
textarea.style.height = 'auto';
|
227 |
+
|
228 |
+
const scrollHeight = textarea.scrollHeight;
|
229 |
+
|
230 |
+
textarea.style.height = `${Math.min(scrollHeight, TEXTAREA_MAX_HEIGHT)}px`;
|
231 |
+
textarea.style.overflowY = scrollHeight > TEXTAREA_MAX_HEIGHT ? 'auto' : 'hidden';
|
232 |
+
}
|
233 |
+
}, [input, textareaRef]);
|
234 |
+
|
235 |
+
const runAnimation = async () => {
|
236 |
+
if (chatStarted) {
|
237 |
+
return;
|
238 |
+
}
|
239 |
+
|
240 |
+
await Promise.all([
|
241 |
+
animate('#examples', { opacity: 0, display: 'none' }, { duration: 0.1 }),
|
242 |
+
animate('#intro', { opacity: 0, flex: 1 }, { duration: 0.2, ease: cubicEasingFn }),
|
243 |
+
]);
|
244 |
+
|
245 |
+
chatStore.setKey('started', true);
|
246 |
+
|
247 |
+
setChatStarted(true);
|
248 |
+
};
|
249 |
+
|
250 |
+
const sendMessage = async (_event: React.UIEvent, messageInput?: string) => {
|
251 |
+
const _input = messageInput || input;
|
252 |
+
|
253 |
+
if (_input.length === 0 || isLoading) {
|
254 |
+
return;
|
255 |
+
}
|
256 |
+
|
257 |
+
/**
|
258 |
+
* @note (delm) Usually saving files shouldn't take long but it may take longer if there
|
259 |
+
* many unsaved files. In that case we need to block user input and show an indicator
|
260 |
+
* of some kind so the user is aware that something is happening. But I consider the
|
261 |
+
* happy case to be no unsaved files and I would expect users to save their changes
|
262 |
+
* before they send another message.
|
263 |
+
*/
|
264 |
+
await workbenchStore.saveAllFiles();
|
265 |
+
|
266 |
+
const fileModifications = workbenchStore.getFileModifcations();
|
267 |
+
|
268 |
+
chatStore.setKey('aborted', false);
|
269 |
+
|
270 |
+
runAnimation();
|
271 |
+
|
272 |
+
if (!chatStarted && messageInput && autoSelectTemplate) {
|
273 |
+
setFakeLoading(true);
|
274 |
+
setMessages([
|
275 |
+
{
|
276 |
+
id: `${new Date().getTime()}`,
|
277 |
+
role: 'user',
|
278 |
+
content: [
|
279 |
+
{
|
280 |
+
type: 'text',
|
281 |
+
text: `[Model: ${model}]\n\n[Provider: ${provider.name}]\n\n${_input}`,
|
282 |
+
},
|
283 |
+
...imageDataList.map((imageData) => ({
|
284 |
+
type: 'image',
|
285 |
+
image: imageData,
|
286 |
+
})),
|
287 |
+
] as any, // Type assertion to bypass compiler check
|
288 |
+
},
|
289 |
+
]);
|
290 |
+
|
291 |
+
// reload();
|
292 |
+
|
293 |
+
const { template, title } = await selectStarterTemplate({
|
294 |
+
message: messageInput,
|
295 |
+
model,
|
296 |
+
provider,
|
297 |
+
});
|
298 |
+
|
299 |
+
if (template !== 'blank') {
|
300 |
+
const temResp = await getTemplates(template, title).catch((e) => {
|
301 |
+
if (e.message.includes('rate limit')) {
|
302 |
+
toast.warning('Rate limit exceeded. Skipping starter template\n Continuing with blank template');
|
303 |
+
} else {
|
304 |
+
toast.warning('Failed to import starter template\n Continuing with blank template');
|
305 |
+
}
|
306 |
+
|
307 |
+
return null;
|
308 |
+
});
|
309 |
+
|
310 |
+
if (temResp) {
|
311 |
+
const { assistantMessage, userMessage } = temResp;
|
312 |
+
|
313 |
+
setMessages([
|
314 |
+
{
|
315 |
+
id: `${new Date().getTime()}`,
|
316 |
+
role: 'user',
|
317 |
+
content: messageInput,
|
318 |
+
|
319 |
+
// annotations: ['hidden'],
|
320 |
+
},
|
321 |
+
{
|
322 |
+
id: `${new Date().getTime()}`,
|
323 |
+
role: 'assistant',
|
324 |
+
content: assistantMessage,
|
325 |
+
},
|
326 |
+
{
|
327 |
+
id: `${new Date().getTime()}`,
|
328 |
+
role: 'user',
|
329 |
+
content: `[Model: ${model}]\n\n[Provider: ${provider.name}]\n\n${userMessage}`,
|
330 |
+
annotations: ['hidden'],
|
331 |
+
},
|
332 |
+
]);
|
333 |
+
|
334 |
+
reload();
|
335 |
+
setFakeLoading(false);
|
336 |
+
|
337 |
+
return;
|
338 |
+
} else {
|
339 |
+
setMessages([
|
340 |
+
{
|
341 |
+
id: `${new Date().getTime()}`,
|
342 |
+
role: 'user',
|
343 |
+
content: [
|
344 |
+
{
|
345 |
+
type: 'text',
|
346 |
+
text: `[Model: ${model}]\n\n[Provider: ${provider.name}]\n\n${_input}`,
|
347 |
+
},
|
348 |
+
...imageDataList.map((imageData) => ({
|
349 |
+
type: 'image',
|
350 |
+
image: imageData,
|
351 |
+
})),
|
352 |
+
] as any, // Type assertion to bypass compiler check
|
353 |
+
},
|
354 |
+
]);
|
355 |
+
reload();
|
356 |
+
setFakeLoading(false);
|
357 |
+
|
358 |
+
return;
|
359 |
+
}
|
360 |
+
} else {
|
361 |
+
setMessages([
|
362 |
+
{
|
363 |
+
id: `${new Date().getTime()}`,
|
364 |
+
role: 'user',
|
365 |
+
content: [
|
366 |
+
{
|
367 |
+
type: 'text',
|
368 |
+
text: `[Model: ${model}]\n\n[Provider: ${provider.name}]\n\n${_input}`,
|
369 |
+
},
|
370 |
+
...imageDataList.map((imageData) => ({
|
371 |
+
type: 'image',
|
372 |
+
image: imageData,
|
373 |
+
})),
|
374 |
+
] as any, // Type assertion to bypass compiler check
|
375 |
+
},
|
376 |
+
]);
|
377 |
+
reload();
|
378 |
+
setFakeLoading(false);
|
379 |
+
|
380 |
+
return;
|
381 |
+
}
|
382 |
+
}
|
383 |
+
|
384 |
+
if (fileModifications !== undefined) {
|
385 |
+
/**
|
386 |
+
* If we have file modifications we append a new user message manually since we have to prefix
|
387 |
+
* the user input with the file modifications and we don't want the new user input to appear
|
388 |
+
* in the prompt. Using `append` is almost the same as `handleSubmit` except that we have to
|
389 |
+
* manually reset the input and we'd have to manually pass in file attachments. However, those
|
390 |
+
* aren't relevant here.
|
391 |
+
*/
|
392 |
+
append({
|
393 |
+
role: 'user',
|
394 |
+
content: [
|
395 |
+
{
|
396 |
+
type: 'text',
|
397 |
+
text: `[Model: ${model}]\n\n[Provider: ${provider.name}]\n\n${_input}`,
|
398 |
+
},
|
399 |
+
...imageDataList.map((imageData) => ({
|
400 |
+
type: 'image',
|
401 |
+
image: imageData,
|
402 |
+
})),
|
403 |
+
] as any, // Type assertion to bypass compiler check
|
404 |
+
});
|
405 |
+
|
406 |
+
/**
|
407 |
+
* After sending a new message we reset all modifications since the model
|
408 |
+
* should now be aware of all the changes.
|
409 |
+
*/
|
410 |
+
workbenchStore.resetAllFileModifications();
|
411 |
+
} else {
|
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 |
+
setInput('');
|
428 |
+
Cookies.remove(PROMPT_COOKIE_KEY);
|
429 |
+
|
430 |
+
// Add file cleanup here
|
431 |
+
setUploadedFiles([]);
|
432 |
+
setImageDataList([]);
|
433 |
+
|
434 |
+
resetEnhancer();
|
435 |
+
|
436 |
+
textareaRef.current?.blur();
|
437 |
+
};
|
438 |
+
|
439 |
+
/**
|
440 |
+
* Handles the change event for the textarea and updates the input state.
|
441 |
+
* @param event - The change event from the textarea.
|
442 |
+
*/
|
443 |
+
const onTextareaChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
|
444 |
+
handleInputChange(event);
|
445 |
+
};
|
446 |
+
|
447 |
+
/**
|
448 |
+
* Debounced function to cache the prompt in cookies.
|
449 |
+
* Caches the trimmed value of the textarea input after a delay to optimize performance.
|
450 |
+
*/
|
451 |
+
const debouncedCachePrompt = useCallback(
|
452 |
+
debounce((event: React.ChangeEvent<HTMLTextAreaElement>) => {
|
453 |
+
const trimmedValue = event.target.value.trim();
|
454 |
+
Cookies.set(PROMPT_COOKIE_KEY, trimmedValue, { expires: 30 });
|
455 |
+
}, 1000),
|
456 |
+
[],
|
457 |
+
);
|
458 |
+
|
459 |
+
const [messageRef, scrollRef] = useSnapScroll();
|
460 |
+
|
461 |
+
useEffect(() => {
|
462 |
+
const storedApiKeys = Cookies.get('apiKeys');
|
463 |
+
|
464 |
+
if (storedApiKeys) {
|
465 |
+
setApiKeys(JSON.parse(storedApiKeys));
|
466 |
+
}
|
467 |
+
}, []);
|
468 |
+
|
469 |
+
const handleModelChange = (newModel: string) => {
|
470 |
+
setModel(newModel);
|
471 |
+
Cookies.set('selectedModel', newModel, { expires: 30 });
|
472 |
+
};
|
473 |
+
|
474 |
+
const handleProviderChange = (newProvider: ProviderInfo) => {
|
475 |
+
setProvider(newProvider);
|
476 |
+
Cookies.set('selectedProvider', newProvider.name, { expires: 30 });
|
477 |
+
};
|
478 |
+
|
479 |
+
return (
|
480 |
+
<BaseChat
|
481 |
+
ref={animationScope}
|
482 |
+
textareaRef={textareaRef}
|
483 |
+
input={input}
|
484 |
+
showChat={showChat}
|
485 |
+
chatStarted={chatStarted}
|
486 |
+
isStreaming={isLoading || fakeLoading}
|
487 |
+
enhancingPrompt={enhancingPrompt}
|
488 |
+
promptEnhanced={promptEnhanced}
|
489 |
+
sendMessage={sendMessage}
|
490 |
+
model={model}
|
491 |
+
setModel={handleModelChange}
|
492 |
+
provider={provider}
|
493 |
+
setProvider={handleProviderChange}
|
494 |
+
providerList={activeProviders}
|
495 |
+
messageRef={messageRef}
|
496 |
+
scrollRef={scrollRef}
|
497 |
+
handleInputChange={(e) => {
|
498 |
+
onTextareaChange(e);
|
499 |
+
debouncedCachePrompt(e);
|
500 |
+
}}
|
501 |
+
handleStop={abort}
|
502 |
+
description={description}
|
503 |
+
importChat={importChat}
|
504 |
+
exportChat={exportChat}
|
505 |
+
messages={messages.map((message, i) => {
|
506 |
+
if (message.role === 'user') {
|
507 |
+
return message;
|
508 |
+
}
|
509 |
+
|
510 |
+
return {
|
511 |
+
...message,
|
512 |
+
content: parsedMessages[i] || '',
|
513 |
+
};
|
514 |
+
})}
|
515 |
+
enhancePrompt={() => {
|
516 |
+
enhancePrompt(
|
517 |
+
input,
|
518 |
+
(input) => {
|
519 |
+
setInput(input);
|
520 |
+
scrollTextArea();
|
521 |
+
},
|
522 |
+
model,
|
523 |
+
provider,
|
524 |
+
apiKeys,
|
525 |
+
);
|
526 |
+
}}
|
527 |
+
uploadedFiles={uploadedFiles}
|
528 |
+
setUploadedFiles={setUploadedFiles}
|
529 |
+
imageDataList={imageDataList}
|
530 |
+
setImageDataList={setImageDataList}
|
531 |
+
actionAlert={actionAlert}
|
532 |
+
clearAlert={() => workbenchStore.clearAlert()}
|
533 |
+
/>
|
534 |
+
);
|
535 |
+
},
|
536 |
+
);
|
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 |
+
}
|
app/components/chat/CodeBlock.tsx
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { memo, useEffect, useState } from 'react';
|
2 |
+
import { bundledLanguages, codeToHtml, isSpecialLang, type BundledLanguage, type SpecialLanguage } from 'shiki';
|
3 |
+
import { classNames } from '~/utils/classNames';
|
4 |
+
import { createScopedLogger } from '~/utils/logger';
|
5 |
+
|
6 |
+
import styles from './CodeBlock.module.scss';
|
7 |
+
|
8 |
+
const logger = createScopedLogger('CodeBlock');
|
9 |
+
|
10 |
+
interface CodeBlockProps {
|
11 |
+
className?: string;
|
12 |
+
code: string;
|
13 |
+
language?: BundledLanguage | SpecialLanguage;
|
14 |
+
theme?: 'light-plus' | 'dark-plus';
|
15 |
+
disableCopy?: boolean;
|
16 |
+
}
|
17 |
+
|
18 |
+
export const CodeBlock = memo(
|
19 |
+
({ className, code, language = 'plaintext', theme = 'dark-plus', disableCopy = false }: CodeBlockProps) => {
|
20 |
+
const [html, setHTML] = useState<string | undefined>(undefined);
|
21 |
+
const [copied, setCopied] = useState(false);
|
22 |
+
|
23 |
+
const copyToClipboard = () => {
|
24 |
+
if (copied) {
|
25 |
+
return;
|
26 |
+
}
|
27 |
+
|
28 |
+
navigator.clipboard.writeText(code);
|
29 |
+
|
30 |
+
setCopied(true);
|
31 |
+
|
32 |
+
setTimeout(() => {
|
33 |
+
setCopied(false);
|
34 |
+
}, 2000);
|
35 |
+
};
|
36 |
+
|
37 |
+
useEffect(() => {
|
38 |
+
if (language && !isSpecialLang(language) && !(language in bundledLanguages)) {
|
39 |
+
logger.warn(`Unsupported language '${language}'`);
|
40 |
+
}
|
41 |
+
|
42 |
+
logger.trace(`Language = ${language}`);
|
43 |
+
|
44 |
+
const processCode = async () => {
|
45 |
+
setHTML(await codeToHtml(code, { lang: language, theme }));
|
46 |
+
};
|
47 |
+
|
48 |
+
processCode();
|
49 |
+
}, [code]);
|
50 |
+
|
51 |
+
return (
|
52 |
+
<div className={classNames('relative group text-left', className)}>
|
53 |
+
<div
|
54 |
+
className={classNames(
|
55 |
+
styles.CopyButtonContainer,
|
56 |
+
'bg-transparant absolute top-[10px] right-[10px] rounded-md z-10 text-lg flex items-center justify-center opacity-0 group-hover:opacity-100',
|
57 |
+
{
|
58 |
+
'rounded-l-0 opacity-100': copied,
|
59 |
+
},
|
60 |
+
)}
|
61 |
+
>
|
62 |
+
{!disableCopy && (
|
63 |
+
<button
|
64 |
+
className={classNames(
|
65 |
+
'flex items-center bg-accent-500 p-[6px] justify-center before:bg-white before:rounded-l-md before:text-gray-500 before:border-r before:border-gray-300 rounded-md transition-theme',
|
66 |
+
{
|
67 |
+
'before:opacity-0': !copied,
|
68 |
+
'before:opacity-100': copied,
|
69 |
+
},
|
70 |
+
)}
|
71 |
+
title="Copy Code"
|
72 |
+
onClick={() => copyToClipboard()}
|
73 |
+
>
|
74 |
+
<div className="i-ph:clipboard-text-duotone"></div>
|
75 |
+
</button>
|
76 |
+
)}
|
77 |
+
</div>
|
78 |
+
<div dangerouslySetInnerHTML={{ __html: html ?? '' }}></div>
|
79 |
+
</div>
|
80 |
+
);
|
81 |
+
},
|
82 |
+
);
|
app/components/chat/ExamplePrompts.tsx
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React from 'react';
|
2 |
+
|
3 |
+
const EXAMPLE_PROMPTS = [
|
4 |
+
{ text: 'Build a todo app in React using Tailwind' },
|
5 |
+
{ text: 'Build a simple blog using Astro' },
|
6 |
+
{ text: 'Create a cookie consent form using Material UI' },
|
7 |
+
{ text: 'Make a space invaders game' },
|
8 |
+
{ text: 'Make a Tic Tac Toe game in html, css and js only' },
|
9 |
+
];
|
10 |
+
|
11 |
+
export function ExamplePrompts(sendMessage?: { (event: React.UIEvent, messageInput?: string): void | undefined }) {
|
12 |
+
return (
|
13 |
+
<div id="examples" className="relative flex flex-col gap-9 w-full max-w-3xl mx-auto flex justify-center mt-6">
|
14 |
+
<div
|
15 |
+
className="flex flex-wrap justify-center gap-2"
|
16 |
+
style={{
|
17 |
+
animation: '.25s ease-out 0s 1 _fade-and-move-in_g2ptj_1 forwards',
|
18 |
+
}}
|
19 |
+
>
|
20 |
+
{EXAMPLE_PROMPTS.map((examplePrompt, index: number) => {
|
21 |
+
return (
|
22 |
+
<button
|
23 |
+
key={index}
|
24 |
+
onClick={(event) => {
|
25 |
+
sendMessage?.(event, examplePrompt.text);
|
26 |
+
}}
|
27 |
+
className="border border-bolt-elements-borderColor rounded-full bg-gray-50 hover:bg-gray-100 dark:bg-gray-950 dark:hover:bg-gray-900 text-bolt-elements-textSecondary hover:text-bolt-elements-textPrimary px-3 py-1 text-xs transition-theme"
|
28 |
+
>
|
29 |
+
{examplePrompt.text}
|
30 |
+
</button>
|
31 |
+
);
|
32 |
+
})}
|
33 |
+
</div>
|
34 |
+
</div>
|
35 |
+
);
|
36 |
+
}
|
app/components/chat/FilePreview.tsx
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React from 'react';
|
2 |
+
|
3 |
+
interface FilePreviewProps {
|
4 |
+
files: File[];
|
5 |
+
imageDataList: string[];
|
6 |
+
onRemove: (index: number) => void;
|
7 |
+
}
|
8 |
+
|
9 |
+
const FilePreview: React.FC<FilePreviewProps> = ({ files, imageDataList, onRemove }) => {
|
10 |
+
if (!files || files.length === 0) {
|
11 |
+
return null;
|
12 |
+
}
|
13 |
+
|
14 |
+
return (
|
15 |
+
<div className="flex flex-row overflow-x-auto -mt-2">
|
16 |
+
{files.map((file, index) => (
|
17 |
+
<div key={file.name + file.size} className="mr-2 relative">
|
18 |
+
{imageDataList[index] && (
|
19 |
+
<div className="relative pt-4 pr-4">
|
20 |
+
<img src={imageDataList[index]} alt={file.name} className="max-h-20" />
|
21 |
+
<button
|
22 |
+
onClick={() => onRemove(index)}
|
23 |
+
className="absolute top-1 right-1 z-10 bg-black rounded-full w-5 h-5 shadow-md hover:bg-gray-900 transition-colors flex items-center justify-center"
|
24 |
+
>
|
25 |
+
<div className="i-ph:x w-3 h-3 text-gray-200" />
|
26 |
+
</button>
|
27 |
+
</div>
|
28 |
+
)}
|
29 |
+
</div>
|
30 |
+
))}
|
31 |
+
</div>
|
32 |
+
);
|
33 |
+
};
|
34 |
+
|
35 |
+
export default FilePreview;
|
app/components/chat/GitCloneButton.tsx
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import ignore from 'ignore';
|
2 |
+
import { useGit } from '~/lib/hooks/useGit';
|
3 |
+
import type { Message } from 'ai';
|
4 |
+
import { detectProjectCommands, createCommandsMessage } from '~/utils/projectCommands';
|
5 |
+
import { generateId } from '~/utils/fileUtils';
|
6 |
+
import { useState } from 'react';
|
7 |
+
import { toast } from 'react-toastify';
|
8 |
+
import { LoadingOverlay } from '~/components/ui/LoadingOverlay';
|
9 |
+
|
10 |
+
const IGNORE_PATTERNS = [
|
11 |
+
'node_modules/**',
|
12 |
+
'.git/**',
|
13 |
+
'.github/**',
|
14 |
+
'.vscode/**',
|
15 |
+
'**/*.jpg',
|
16 |
+
'**/*.jpeg',
|
17 |
+
'**/*.png',
|
18 |
+
'dist/**',
|
19 |
+
'build/**',
|
20 |
+
'.next/**',
|
21 |
+
'coverage/**',
|
22 |
+
'.cache/**',
|
23 |
+
'.vscode/**',
|
24 |
+
'.idea/**',
|
25 |
+
'**/*.log',
|
26 |
+
'**/.DS_Store',
|
27 |
+
'**/npm-debug.log*',
|
28 |
+
'**/yarn-debug.log*',
|
29 |
+
'**/yarn-error.log*',
|
30 |
+
'**/*lock.json',
|
31 |
+
'**/*lock.yaml',
|
32 |
+
];
|
33 |
+
|
34 |
+
const ig = ignore().add(IGNORE_PATTERNS);
|
35 |
+
|
36 |
+
interface GitCloneButtonProps {
|
37 |
+
className?: string;
|
38 |
+
importChat?: (description: string, messages: Message[]) => Promise<void>;
|
39 |
+
}
|
40 |
+
|
41 |
+
export default function GitCloneButton({ importChat }: GitCloneButtonProps) {
|
42 |
+
const { ready, gitClone } = useGit();
|
43 |
+
const [loading, setLoading] = useState(false);
|
44 |
+
|
45 |
+
const onClick = async (_e: any) => {
|
46 |
+
if (!ready) {
|
47 |
+
return;
|
48 |
+
}
|
49 |
+
|
50 |
+
const repoUrl = prompt('Enter the Git url');
|
51 |
+
|
52 |
+
if (repoUrl) {
|
53 |
+
setLoading(true);
|
54 |
+
|
55 |
+
try {
|
56 |
+
const { workdir, data } = await gitClone(repoUrl);
|
57 |
+
|
58 |
+
if (importChat) {
|
59 |
+
const filePaths = Object.keys(data).filter((filePath) => !ig.ignores(filePath));
|
60 |
+
console.log(filePaths);
|
61 |
+
|
62 |
+
const textDecoder = new TextDecoder('utf-8');
|
63 |
+
|
64 |
+
const fileContents = filePaths
|
65 |
+
.map((filePath) => {
|
66 |
+
const { data: content, encoding } = data[filePath];
|
67 |
+
return {
|
68 |
+
path: filePath,
|
69 |
+
content:
|
70 |
+
encoding === 'utf8' ? content : content instanceof Uint8Array ? textDecoder.decode(content) : '',
|
71 |
+
};
|
72 |
+
})
|
73 |
+
.filter((f) => f.content);
|
74 |
+
|
75 |
+
const commands = await detectProjectCommands(fileContents);
|
76 |
+
const commandsMessage = createCommandsMessage(commands);
|
77 |
+
|
78 |
+
const filesMessage: Message = {
|
79 |
+
role: 'assistant',
|
80 |
+
content: `Cloning the repo ${repoUrl} into ${workdir}
|
81 |
+
<boltArtifact id="imported-files" title="Git Cloned Files" type="bundled">
|
82 |
+
${fileContents
|
83 |
+
.map(
|
84 |
+
(file) =>
|
85 |
+
`<boltAction type="file" filePath="${file.path}">
|
86 |
+
${file.content}
|
87 |
+
</boltAction>`,
|
88 |
+
)
|
89 |
+
.join('\n')}
|
90 |
+
</boltArtifact>`,
|
91 |
+
id: generateId(),
|
92 |
+
createdAt: new Date(),
|
93 |
+
};
|
94 |
+
|
95 |
+
const messages = [filesMessage];
|
96 |
+
|
97 |
+
if (commandsMessage) {
|
98 |
+
messages.push(commandsMessage);
|
99 |
+
}
|
100 |
+
|
101 |
+
await importChat(`Git Project:${repoUrl.split('/').slice(-1)[0]}`, messages);
|
102 |
+
}
|
103 |
+
} catch (error) {
|
104 |
+
console.error('Error during import:', error);
|
105 |
+
toast.error('Failed to import repository');
|
106 |
+
} finally {
|
107 |
+
setLoading(false);
|
108 |
+
}
|
109 |
+
}
|
110 |
+
};
|
111 |
+
|
112 |
+
return (
|
113 |
+
<>
|
114 |
+
<button
|
115 |
+
onClick={onClick}
|
116 |
+
title="Clone a Git Repo"
|
117 |
+
className="px-4 py-2 rounded-lg border border-bolt-elements-borderColor bg-bolt-elements-prompt-background text-bolt-elements-textPrimary hover:bg-bolt-elements-background-depth-3 transition-all flex items-center gap-2"
|
118 |
+
>
|
119 |
+
<span className="i-ph:git-branch" />
|
120 |
+
Clone a Git Repo
|
121 |
+
</button>
|
122 |
+
{loading && <LoadingOverlay message="Please wait while we clone the repository..." />}
|
123 |
+
</>
|
124 |
+
);
|
125 |
+
}
|
app/components/chat/ImportFolderButton.tsx
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React, { useState } from 'react';
|
2 |
+
import type { Message } from 'ai';
|
3 |
+
import { toast } from 'react-toastify';
|
4 |
+
import { MAX_FILES, isBinaryFile, shouldIncludeFile } from '~/utils/fileUtils';
|
5 |
+
import { createChatFromFolder } from '~/utils/folderImport';
|
6 |
+
import { logStore } from '~/lib/stores/logs'; // Assuming logStore is imported from this location
|
7 |
+
|
8 |
+
interface ImportFolderButtonProps {
|
9 |
+
className?: string;
|
10 |
+
importChat?: (description: string, messages: Message[]) => Promise<void>;
|
11 |
+
}
|
12 |
+
|
13 |
+
export const ImportFolderButton: React.FC<ImportFolderButtonProps> = ({ className, importChat }) => {
|
14 |
+
const [isLoading, setIsLoading] = useState(false);
|
15 |
+
|
16 |
+
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
17 |
+
const allFiles = Array.from(e.target.files || []);
|
18 |
+
|
19 |
+
const filteredFiles = allFiles.filter((file) => {
|
20 |
+
const path = file.webkitRelativePath.split('/').slice(1).join('/');
|
21 |
+
const include = shouldIncludeFile(path);
|
22 |
+
|
23 |
+
return include;
|
24 |
+
});
|
25 |
+
|
26 |
+
if (filteredFiles.length === 0) {
|
27 |
+
const error = new Error('No valid files found');
|
28 |
+
logStore.logError('File import failed - no valid files', error, { folderName: 'Unknown Folder' });
|
29 |
+
toast.error('No files found in the selected folder');
|
30 |
+
|
31 |
+
return;
|
32 |
+
}
|
33 |
+
|
34 |
+
if (filteredFiles.length > MAX_FILES) {
|
35 |
+
const error = new Error(`Too many files: ${filteredFiles.length}`);
|
36 |
+
logStore.logError('File import failed - too many files', error, {
|
37 |
+
fileCount: filteredFiles.length,
|
38 |
+
maxFiles: MAX_FILES,
|
39 |
+
});
|
40 |
+
toast.error(
|
41 |
+
`This folder contains ${filteredFiles.length.toLocaleString()} files. This product is not yet optimized for very large projects. Please select a folder with fewer than ${MAX_FILES.toLocaleString()} files.`,
|
42 |
+
);
|
43 |
+
|
44 |
+
return;
|
45 |
+
}
|
46 |
+
|
47 |
+
const folderName = filteredFiles[0]?.webkitRelativePath.split('/')[0] || 'Unknown Folder';
|
48 |
+
setIsLoading(true);
|
49 |
+
|
50 |
+
const loadingToast = toast.loading(`Importing ${folderName}...`);
|
51 |
+
|
52 |
+
try {
|
53 |
+
const fileChecks = await Promise.all(
|
54 |
+
filteredFiles.map(async (file) => ({
|
55 |
+
file,
|
56 |
+
isBinary: await isBinaryFile(file),
|
57 |
+
})),
|
58 |
+
);
|
59 |
+
|
60 |
+
const textFiles = fileChecks.filter((f) => !f.isBinary).map((f) => f.file);
|
61 |
+
const binaryFilePaths = fileChecks
|
62 |
+
.filter((f) => f.isBinary)
|
63 |
+
.map((f) => f.file.webkitRelativePath.split('/').slice(1).join('/'));
|
64 |
+
|
65 |
+
if (textFiles.length === 0) {
|
66 |
+
const error = new Error('No text files found');
|
67 |
+
logStore.logError('File import failed - no text files', error, { folderName });
|
68 |
+
toast.error('No text files found in the selected folder');
|
69 |
+
|
70 |
+
return;
|
71 |
+
}
|
72 |
+
|
73 |
+
if (binaryFilePaths.length > 0) {
|
74 |
+
logStore.logWarning(`Skipping binary files during import`, {
|
75 |
+
folderName,
|
76 |
+
binaryCount: binaryFilePaths.length,
|
77 |
+
});
|
78 |
+
toast.info(`Skipping ${binaryFilePaths.length} binary files`);
|
79 |
+
}
|
80 |
+
|
81 |
+
const messages = await createChatFromFolder(textFiles, binaryFilePaths, folderName);
|
82 |
+
|
83 |
+
if (importChat) {
|
84 |
+
await importChat(folderName, [...messages]);
|
85 |
+
}
|
86 |
+
|
87 |
+
logStore.logSystem('Folder imported successfully', {
|
88 |
+
folderName,
|
89 |
+
textFileCount: textFiles.length,
|
90 |
+
binaryFileCount: binaryFilePaths.length,
|
91 |
+
});
|
92 |
+
toast.success('Folder imported successfully');
|
93 |
+
} catch (error) {
|
94 |
+
logStore.logError('Failed to import folder', error, { folderName });
|
95 |
+
console.error('Failed to import folder:', error);
|
96 |
+
toast.error('Failed to import folder');
|
97 |
+
} finally {
|
98 |
+
setIsLoading(false);
|
99 |
+
toast.dismiss(loadingToast);
|
100 |
+
e.target.value = ''; // Reset file input
|
101 |
+
}
|
102 |
+
};
|
103 |
+
|
104 |
+
return (
|
105 |
+
<>
|
106 |
+
<input
|
107 |
+
type="file"
|
108 |
+
id="folder-import"
|
109 |
+
className="hidden"
|
110 |
+
webkitdirectory=""
|
111 |
+
directory=""
|
112 |
+
onChange={handleFileChange}
|
113 |
+
{...({} as any)}
|
114 |
+
/>
|
115 |
+
<button
|
116 |
+
onClick={() => {
|
117 |
+
const input = document.getElementById('folder-import');
|
118 |
+
input?.click();
|
119 |
+
}}
|
120 |
+
className={className}
|
121 |
+
disabled={isLoading}
|
122 |
+
>
|
123 |
+
<div className="i-ph:upload-simple" />
|
124 |
+
{isLoading ? 'Importing...' : 'Import Folder'}
|
125 |
+
</button>
|
126 |
+
</>
|
127 |
+
);
|
128 |
+
};
|
app/components/chat/Markdown.module.scss
ADDED
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
$font-mono: ui-monospace, 'Fira Code', Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
|
2 |
+
$code-font-size: 13px;
|
3 |
+
|
4 |
+
@mixin not-inside-actions {
|
5 |
+
&:not(:has(:global(.actions)), :global(.actions *)) {
|
6 |
+
@content;
|
7 |
+
}
|
8 |
+
}
|
9 |
+
|
10 |
+
.MarkdownContent {
|
11 |
+
line-height: 1.6;
|
12 |
+
color: var(--bolt-elements-textPrimary);
|
13 |
+
|
14 |
+
> *:not(:last-child) {
|
15 |
+
margin-block-end: 16px;
|
16 |
+
}
|
17 |
+
|
18 |
+
:global(.artifact) {
|
19 |
+
margin: 1.5em 0;
|
20 |
+
}
|
21 |
+
|
22 |
+
:is(h1, h2, h3, h4, h5, h6) {
|
23 |
+
@include not-inside-actions {
|
24 |
+
margin-block-start: 24px;
|
25 |
+
margin-block-end: 16px;
|
26 |
+
font-weight: 600;
|
27 |
+
line-height: 1.25;
|
28 |
+
color: var(--bolt-elements-textPrimary);
|
29 |
+
}
|
30 |
+
}
|
31 |
+
|
32 |
+
h1 {
|
33 |
+
font-size: 2em;
|
34 |
+
border-bottom: 1px solid var(--bolt-elements-borderColor);
|
35 |
+
padding-bottom: 0.3em;
|
36 |
+
}
|
37 |
+
|
38 |
+
h2 {
|
39 |
+
font-size: 1.5em;
|
40 |
+
border-bottom: 1px solid var(--bolt-elements-borderColor);
|
41 |
+
padding-bottom: 0.3em;
|
42 |
+
}
|
43 |
+
|
44 |
+
h3 {
|
45 |
+
font-size: 1.25em;
|
46 |
+
}
|
47 |
+
|
48 |
+
h4 {
|
49 |
+
font-size: 1em;
|
50 |
+
}
|
51 |
+
|
52 |
+
h5 {
|
53 |
+
font-size: 0.875em;
|
54 |
+
}
|
55 |
+
|
56 |
+
h6 {
|
57 |
+
font-size: 0.85em;
|
58 |
+
color: #6a737d;
|
59 |
+
}
|
60 |
+
|
61 |
+
p {
|
62 |
+
white-space: pre-wrap;
|
63 |
+
|
64 |
+
&:not(:last-of-type) {
|
65 |
+
margin-block-start: 0;
|
66 |
+
margin-block-end: 16px;
|
67 |
+
}
|
68 |
+
}
|
69 |
+
|
70 |
+
a {
|
71 |
+
color: var(--bolt-elements-messages-linkColor);
|
72 |
+
text-decoration: none;
|
73 |
+
cursor: pointer;
|
74 |
+
|
75 |
+
&:hover {
|
76 |
+
text-decoration: underline;
|
77 |
+
}
|
78 |
+
}
|
79 |
+
|
80 |
+
:not(pre) > code {
|
81 |
+
font-family: $font-mono;
|
82 |
+
font-size: $code-font-size;
|
83 |
+
|
84 |
+
@include not-inside-actions {
|
85 |
+
border-radius: 6px;
|
86 |
+
padding: 0.2em 0.4em;
|
87 |
+
background-color: var(--bolt-elements-messages-inlineCode-background);
|
88 |
+
color: var(--bolt-elements-messages-inlineCode-text);
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
92 |
+
pre {
|
93 |
+
padding: 20px 16px;
|
94 |
+
border-radius: 6px;
|
95 |
+
}
|
96 |
+
|
97 |
+
pre:has(> code) {
|
98 |
+
font-family: $font-mono;
|
99 |
+
font-size: $code-font-size;
|
100 |
+
background: transparent;
|
101 |
+
overflow-x: auto;
|
102 |
+
min-width: 0;
|
103 |
+
}
|
104 |
+
|
105 |
+
blockquote {
|
106 |
+
margin: 0;
|
107 |
+
padding: 0 1em;
|
108 |
+
color: var(--bolt-elements-textTertiary);
|
109 |
+
border-left: 0.25em solid var(--bolt-elements-borderColor);
|
110 |
+
}
|
111 |
+
|
112 |
+
:is(ul, ol) {
|
113 |
+
@include not-inside-actions {
|
114 |
+
padding-left: 2em;
|
115 |
+
margin-block-start: 0;
|
116 |
+
margin-block-end: 16px;
|
117 |
+
}
|
118 |
+
}
|
119 |
+
|
120 |
+
ul {
|
121 |
+
@include not-inside-actions {
|
122 |
+
list-style-type: disc;
|
123 |
+
}
|
124 |
+
}
|
125 |
+
|
126 |
+
ol {
|
127 |
+
@include not-inside-actions {
|
128 |
+
list-style-type: decimal;
|
129 |
+
}
|
130 |
+
}
|
131 |
+
|
132 |
+
li {
|
133 |
+
@include not-inside-actions {
|
134 |
+
& + li {
|
135 |
+
margin-block-start: 8px;
|
136 |
+
}
|
137 |
+
|
138 |
+
> *:not(:last-child) {
|
139 |
+
margin-block-end: 16px;
|
140 |
+
}
|
141 |
+
}
|
142 |
+
}
|
143 |
+
|
144 |
+
img {
|
145 |
+
max-width: 100%;
|
146 |
+
box-sizing: border-box;
|
147 |
+
}
|
148 |
+
|
149 |
+
hr {
|
150 |
+
height: 0.25em;
|
151 |
+
padding: 0;
|
152 |
+
margin: 24px 0;
|
153 |
+
background-color: var(--bolt-elements-borderColor);
|
154 |
+
border: 0;
|
155 |
+
}
|
156 |
+
|
157 |
+
table {
|
158 |
+
border-collapse: collapse;
|
159 |
+
width: 100%;
|
160 |
+
margin-block-end: 16px;
|
161 |
+
|
162 |
+
:is(th, td) {
|
163 |
+
padding: 6px 13px;
|
164 |
+
border: 1px solid #dfe2e5;
|
165 |
+
}
|
166 |
+
|
167 |
+
tr:nth-child(2n) {
|
168 |
+
background-color: #f6f8fa;
|
169 |
+
}
|
170 |
+
}
|
171 |
+
}
|
app/components/chat/Markdown.spec.ts
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { describe, expect, it } from 'vitest';
|
2 |
+
import { stripCodeFenceFromArtifact } from './Markdown';
|
3 |
+
|
4 |
+
describe('stripCodeFenceFromArtifact', () => {
|
5 |
+
it('should remove code fences around artifact element', () => {
|
6 |
+
const input = "```xml\n<div class='__boltArtifact__'></div>\n```";
|
7 |
+
const expected = "\n<div class='__boltArtifact__'></div>\n";
|
8 |
+
expect(stripCodeFenceFromArtifact(input)).toBe(expected);
|
9 |
+
});
|
10 |
+
|
11 |
+
it('should handle code fence with language specification', () => {
|
12 |
+
const input = "```typescript\n<div class='__boltArtifact__'></div>\n```";
|
13 |
+
const expected = "\n<div class='__boltArtifact__'></div>\n";
|
14 |
+
expect(stripCodeFenceFromArtifact(input)).toBe(expected);
|
15 |
+
});
|
16 |
+
|
17 |
+
it('should not modify content without artifacts', () => {
|
18 |
+
const input = '```\nregular code block\n```';
|
19 |
+
expect(stripCodeFenceFromArtifact(input)).toBe(input);
|
20 |
+
});
|
21 |
+
|
22 |
+
it('should handle empty input', () => {
|
23 |
+
expect(stripCodeFenceFromArtifact('')).toBe('');
|
24 |
+
});
|
25 |
+
|
26 |
+
it('should handle artifact without code fences', () => {
|
27 |
+
const input = "<div class='__boltArtifact__'></div>";
|
28 |
+
expect(stripCodeFenceFromArtifact(input)).toBe(input);
|
29 |
+
});
|
30 |
+
|
31 |
+
it('should handle multiple artifacts but only remove fences around them', () => {
|
32 |
+
const input = [
|
33 |
+
'Some text',
|
34 |
+
'```typescript',
|
35 |
+
"<div class='__boltArtifact__'></div>",
|
36 |
+
'```',
|
37 |
+
'```',
|
38 |
+
'regular code',
|
39 |
+
'```',
|
40 |
+
].join('\n');
|
41 |
+
|
42 |
+
const expected = ['Some text', '', "<div class='__boltArtifact__'></div>", '', '```', 'regular code', '```'].join(
|
43 |
+
'\n',
|
44 |
+
);
|
45 |
+
|
46 |
+
expect(stripCodeFenceFromArtifact(input)).toBe(expected);
|
47 |
+
});
|
48 |
+
});
|
app/components/chat/Markdown.tsx
ADDED
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { memo, useMemo } from 'react';
|
2 |
+
import ReactMarkdown, { type Components } from 'react-markdown';
|
3 |
+
import type { BundledLanguage } from 'shiki';
|
4 |
+
import { createScopedLogger } from '~/utils/logger';
|
5 |
+
import { rehypePlugins, remarkPlugins, allowedHTMLElements } from '~/utils/markdown';
|
6 |
+
import { Artifact } from './Artifact';
|
7 |
+
import { CodeBlock } from './CodeBlock';
|
8 |
+
|
9 |
+
import styles from './Markdown.module.scss';
|
10 |
+
|
11 |
+
const logger = createScopedLogger('MarkdownComponent');
|
12 |
+
|
13 |
+
interface MarkdownProps {
|
14 |
+
children: string;
|
15 |
+
html?: boolean;
|
16 |
+
limitedMarkdown?: boolean;
|
17 |
+
}
|
18 |
+
|
19 |
+
export const Markdown = memo(({ children, html = false, limitedMarkdown = false }: MarkdownProps) => {
|
20 |
+
logger.trace('Render');
|
21 |
+
|
22 |
+
const components = useMemo(() => {
|
23 |
+
return {
|
24 |
+
div: ({ className, children, node, ...props }) => {
|
25 |
+
if (className?.includes('__boltArtifact__')) {
|
26 |
+
const messageId = node?.properties.dataMessageId as string;
|
27 |
+
|
28 |
+
if (!messageId) {
|
29 |
+
logger.error(`Invalid message id ${messageId}`);
|
30 |
+
}
|
31 |
+
|
32 |
+
return <Artifact messageId={messageId} />;
|
33 |
+
}
|
34 |
+
|
35 |
+
return (
|
36 |
+
<div className={className} {...props}>
|
37 |
+
{children}
|
38 |
+
</div>
|
39 |
+
);
|
40 |
+
},
|
41 |
+
pre: (props) => {
|
42 |
+
const { children, node, ...rest } = props;
|
43 |
+
|
44 |
+
const [firstChild] = node?.children ?? [];
|
45 |
+
|
46 |
+
if (
|
47 |
+
firstChild &&
|
48 |
+
firstChild.type === 'element' &&
|
49 |
+
firstChild.tagName === 'code' &&
|
50 |
+
firstChild.children[0].type === 'text'
|
51 |
+
) {
|
52 |
+
const { className, ...rest } = firstChild.properties;
|
53 |
+
const [, language = 'plaintext'] = /language-(\w+)/.exec(String(className) || '') ?? [];
|
54 |
+
|
55 |
+
return <CodeBlock code={firstChild.children[0].value} language={language as BundledLanguage} {...rest} />;
|
56 |
+
}
|
57 |
+
|
58 |
+
return <pre {...rest}>{children}</pre>;
|
59 |
+
},
|
60 |
+
} satisfies Components;
|
61 |
+
}, []);
|
62 |
+
|
63 |
+
return (
|
64 |
+
<ReactMarkdown
|
65 |
+
allowedElements={allowedHTMLElements}
|
66 |
+
className={styles.MarkdownContent}
|
67 |
+
components={components}
|
68 |
+
remarkPlugins={remarkPlugins(limitedMarkdown)}
|
69 |
+
rehypePlugins={rehypePlugins(html)}
|
70 |
+
>
|
71 |
+
{stripCodeFenceFromArtifact(children)}
|
72 |
+
</ReactMarkdown>
|
73 |
+
);
|
74 |
+
});
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Removes code fence markers (```) surrounding an artifact element while preserving the artifact content.
|
78 |
+
* This is necessary because artifacts should not be wrapped in code blocks when rendered for rendering action list.
|
79 |
+
*
|
80 |
+
* @param content - The markdown content to process
|
81 |
+
* @returns The processed content with code fence markers removed around artifacts
|
82 |
+
*
|
83 |
+
* @example
|
84 |
+
* // Removes code fences around artifact
|
85 |
+
* const input = "```xml\n<div class='__boltArtifact__'></div>\n```";
|
86 |
+
* stripCodeFenceFromArtifact(input);
|
87 |
+
* // Returns: "\n<div class='__boltArtifact__'></div>\n"
|
88 |
+
*
|
89 |
+
* @remarks
|
90 |
+
* - Only removes code fences that directly wrap an artifact (marked with __boltArtifact__ class)
|
91 |
+
* - Handles code fences with optional language specifications (e.g. ```xml, ```typescript)
|
92 |
+
* - Preserves original content if no artifact is found
|
93 |
+
* - Safely handles edge cases like empty input or artifacts at start/end of content
|
94 |
+
*/
|
95 |
+
export const stripCodeFenceFromArtifact = (content: string) => {
|
96 |
+
if (!content || !content.includes('__boltArtifact__')) {
|
97 |
+
return content;
|
98 |
+
}
|
99 |
+
|
100 |
+
const lines = content.split('\n');
|
101 |
+
const artifactLineIndex = lines.findIndex((line) => line.includes('__boltArtifact__'));
|
102 |
+
|
103 |
+
// Return original content if artifact line not found
|
104 |
+
if (artifactLineIndex === -1) {
|
105 |
+
return content;
|
106 |
+
}
|
107 |
+
|
108 |
+
// Check previous line for code fence
|
109 |
+
if (artifactLineIndex > 0 && lines[artifactLineIndex - 1]?.trim().match(/^```\w*$/)) {
|
110 |
+
lines[artifactLineIndex - 1] = '';
|
111 |
+
}
|
112 |
+
|
113 |
+
if (artifactLineIndex < lines.length - 1 && lines[artifactLineIndex + 1]?.trim().match(/^```$/)) {
|
114 |
+
lines[artifactLineIndex + 1] = '';
|
115 |
+
}
|
116 |
+
|
117 |
+
return lines.join('\n');
|
118 |
+
};
|
app/components/chat/Messages.client.tsx
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import type { Message } from 'ai';
|
2 |
+
import React, { Fragment } from 'react';
|
3 |
+
import { classNames } from '~/utils/classNames';
|
4 |
+
import { AssistantMessage } from './AssistantMessage';
|
5 |
+
import { UserMessage } from './UserMessage';
|
6 |
+
import { useLocation } from '@remix-run/react';
|
7 |
+
import { db, chatId } from '~/lib/persistence/useChatHistory';
|
8 |
+
import { forkChat } from '~/lib/persistence/db';
|
9 |
+
import { toast } from 'react-toastify';
|
10 |
+
import WithTooltip from '~/components/ui/Tooltip';
|
11 |
+
|
12 |
+
interface MessagesProps {
|
13 |
+
id?: string;
|
14 |
+
className?: string;
|
15 |
+
isStreaming?: boolean;
|
16 |
+
messages?: Message[];
|
17 |
+
}
|
18 |
+
|
19 |
+
export const Messages = React.forwardRef<HTMLDivElement, MessagesProps>((props: MessagesProps, ref) => {
|
20 |
+
const { id, isStreaming = false, messages = [] } = props;
|
21 |
+
const location = useLocation();
|
22 |
+
|
23 |
+
const handleRewind = (messageId: string) => {
|
24 |
+
const searchParams = new URLSearchParams(location.search);
|
25 |
+
searchParams.set('rewindTo', messageId);
|
26 |
+
window.location.search = searchParams.toString();
|
27 |
+
};
|
28 |
+
|
29 |
+
const handleFork = async (messageId: string) => {
|
30 |
+
try {
|
31 |
+
if (!db || !chatId.get()) {
|
32 |
+
toast.error('Chat persistence is not available');
|
33 |
+
return;
|
34 |
+
}
|
35 |
+
|
36 |
+
const urlId = await forkChat(db, chatId.get()!, messageId);
|
37 |
+
window.location.href = `/chat/${urlId}`;
|
38 |
+
} catch (error) {
|
39 |
+
toast.error('Failed to fork chat: ' + (error as Error).message);
|
40 |
+
}
|
41 |
+
};
|
42 |
+
|
43 |
+
return (
|
44 |
+
<div id={id} ref={ref} className={props.className}>
|
45 |
+
{messages.length > 0
|
46 |
+
? messages.map((message, index) => {
|
47 |
+
const { role, content, id: messageId, annotations } = message;
|
48 |
+
const isUserMessage = role === 'user';
|
49 |
+
const isFirst = index === 0;
|
50 |
+
const isLast = index === messages.length - 1;
|
51 |
+
const isHidden = annotations?.includes('hidden');
|
52 |
+
|
53 |
+
if (isHidden) {
|
54 |
+
return <Fragment key={index} />;
|
55 |
+
}
|
56 |
+
|
57 |
+
return (
|
58 |
+
<div
|
59 |
+
key={index}
|
60 |
+
className={classNames('flex gap-4 p-6 w-full rounded-[calc(0.75rem-1px)]', {
|
61 |
+
'bg-bolt-elements-messages-background': isUserMessage || !isStreaming || (isStreaming && !isLast),
|
62 |
+
'bg-gradient-to-b from-bolt-elements-messages-background from-30% to-transparent':
|
63 |
+
isStreaming && isLast,
|
64 |
+
'mt-4': !isFirst,
|
65 |
+
})}
|
66 |
+
>
|
67 |
+
{isUserMessage && (
|
68 |
+
<div className="flex items-center justify-center w-[34px] h-[34px] overflow-hidden bg-white text-gray-600 rounded-full shrink-0 self-start">
|
69 |
+
<div className="i-ph:user-fill text-xl"></div>
|
70 |
+
</div>
|
71 |
+
)}
|
72 |
+
<div className="grid grid-col-1 w-full">
|
73 |
+
{isUserMessage ? (
|
74 |
+
<UserMessage content={content} />
|
75 |
+
) : (
|
76 |
+
<AssistantMessage content={content} annotations={message.annotations} />
|
77 |
+
)}
|
78 |
+
</div>
|
79 |
+
{!isUserMessage && (
|
80 |
+
<div className="flex gap-2 flex-col lg:flex-row">
|
81 |
+
{messageId && (
|
82 |
+
<WithTooltip tooltip="Revert to this message">
|
83 |
+
<button
|
84 |
+
onClick={() => handleRewind(messageId)}
|
85 |
+
key="i-ph:arrow-u-up-left"
|
86 |
+
className={classNames(
|
87 |
+
'i-ph:arrow-u-up-left',
|
88 |
+
'text-xl text-bolt-elements-textSecondary hover:text-bolt-elements-textPrimary transition-colors',
|
89 |
+
)}
|
90 |
+
/>
|
91 |
+
</WithTooltip>
|
92 |
+
)}
|
93 |
+
|
94 |
+
<WithTooltip tooltip="Fork chat from this message">
|
95 |
+
<button
|
96 |
+
onClick={() => handleFork(messageId)}
|
97 |
+
key="i-ph:git-fork"
|
98 |
+
className={classNames(
|
99 |
+
'i-ph:git-fork',
|
100 |
+
'text-xl text-bolt-elements-textSecondary hover:text-bolt-elements-textPrimary transition-colors',
|
101 |
+
)}
|
102 |
+
/>
|
103 |
+
</WithTooltip>
|
104 |
+
</div>
|
105 |
+
)}
|
106 |
+
</div>
|
107 |
+
);
|
108 |
+
})
|
109 |
+
: null}
|
110 |
+
{isStreaming && (
|
111 |
+
<div className="text-center w-full text-bolt-elements-textSecondary i-svg-spinners:3-dots-fade text-4xl mt-4"></div>
|
112 |
+
)}
|
113 |
+
</div>
|
114 |
+
);
|
115 |
+
});
|
app/components/chat/ModelSelector.tsx
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import type { ProviderInfo } from '~/types/model';
|
2 |
+
import { useEffect } from 'react';
|
3 |
+
import type { ModelInfo } from '~/lib/modules/llm/types';
|
4 |
+
|
5 |
+
interface ModelSelectorProps {
|
6 |
+
model?: string;
|
7 |
+
setModel?: (model: string) => void;
|
8 |
+
provider?: ProviderInfo;
|
9 |
+
setProvider?: (provider: ProviderInfo) => void;
|
10 |
+
modelList: ModelInfo[];
|
11 |
+
providerList: ProviderInfo[];
|
12 |
+
apiKeys: Record<string, string>;
|
13 |
+
modelLoading?: string;
|
14 |
+
}
|
15 |
+
|
16 |
+
export const ModelSelector = ({
|
17 |
+
model,
|
18 |
+
setModel,
|
19 |
+
provider,
|
20 |
+
setProvider,
|
21 |
+
modelList,
|
22 |
+
providerList,
|
23 |
+
modelLoading,
|
24 |
+
}: ModelSelectorProps) => {
|
25 |
+
// Load enabled providers from cookies
|
26 |
+
|
27 |
+
// Update enabled providers when cookies change
|
28 |
+
useEffect(() => {
|
29 |
+
// If current provider is disabled, switch to first enabled provider
|
30 |
+
if (providerList.length == 0) {
|
31 |
+
return;
|
32 |
+
}
|
33 |
+
|
34 |
+
if (provider && !providerList.map((p) => p.name).includes(provider.name)) {
|
35 |
+
const firstEnabledProvider = providerList[0];
|
36 |
+
setProvider?.(firstEnabledProvider);
|
37 |
+
|
38 |
+
// Also update the model to the first available one for the new provider
|
39 |
+
const firstModel = modelList.find((m) => m.provider === firstEnabledProvider.name);
|
40 |
+
|
41 |
+
if (firstModel) {
|
42 |
+
setModel?.(firstModel.name);
|
43 |
+
}
|
44 |
+
}
|
45 |
+
}, [providerList, provider, setProvider, modelList, setModel]);
|
46 |
+
|
47 |
+
if (providerList.length === 0) {
|
48 |
+
return (
|
49 |
+
<div className="mb-2 p-4 rounded-lg border border-bolt-elements-borderColor bg-bolt-elements-prompt-background text-bolt-elements-textPrimary">
|
50 |
+
<p className="text-center">
|
51 |
+
No providers are currently enabled. Please enable at least one provider in the settings to start using the
|
52 |
+
chat.
|
53 |
+
</p>
|
54 |
+
</div>
|
55 |
+
);
|
56 |
+
}
|
57 |
+
|
58 |
+
return (
|
59 |
+
<div className="mb-2 flex gap-2 flex-col sm:flex-row">
|
60 |
+
<select
|
61 |
+
value={provider?.name ?? ''}
|
62 |
+
onChange={(e) => {
|
63 |
+
const newProvider = providerList.find((p: ProviderInfo) => p.name === e.target.value);
|
64 |
+
|
65 |
+
if (newProvider && setProvider) {
|
66 |
+
setProvider(newProvider);
|
67 |
+
}
|
68 |
+
|
69 |
+
const firstModel = [...modelList].find((m) => m.provider === e.target.value);
|
70 |
+
|
71 |
+
if (firstModel && setModel) {
|
72 |
+
setModel(firstModel.name);
|
73 |
+
}
|
74 |
+
}}
|
75 |
+
className="flex-1 p-2 rounded-lg 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 transition-all"
|
76 |
+
>
|
77 |
+
{providerList.map((provider: ProviderInfo) => (
|
78 |
+
<option key={provider.name} value={provider.name}>
|
79 |
+
{provider.name}
|
80 |
+
</option>
|
81 |
+
))}
|
82 |
+
</select>
|
83 |
+
<select
|
84 |
+
key={provider?.name}
|
85 |
+
value={model}
|
86 |
+
onChange={(e) => setModel?.(e.target.value)}
|
87 |
+
className="flex-1 p-2 rounded-lg 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 transition-all lg:max-w-[70%]"
|
88 |
+
disabled={modelLoading === 'all' || modelLoading === provider?.name}
|
89 |
+
>
|
90 |
+
{modelLoading == 'all' || modelLoading == provider?.name ? (
|
91 |
+
<option key={0} value="">
|
92 |
+
Loading...
|
93 |
+
</option>
|
94 |
+
) : (
|
95 |
+
[...modelList]
|
96 |
+
.filter((e) => e.provider == provider?.name && e.name)
|
97 |
+
.map((modelOption, index) => (
|
98 |
+
<option key={index} value={modelOption.name}>
|
99 |
+
{modelOption.label}
|
100 |
+
</option>
|
101 |
+
))
|
102 |
+
)}
|
103 |
+
</select>
|
104 |
+
</div>
|
105 |
+
);
|
106 |
+
};
|