merged main
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .github/ISSUE_TEMPLATE/config.yml +8 -0
- .github/workflows/commit.yaml +33 -0
- .github/workflows/pr-release-validation.yaml +31 -0
- .github/workflows/update-stable.yml +210 -0
- .gitignore +3 -0
- .husky/pre-commit +26 -3
- CONTRIBUTING.md +1 -1
- FAQ.md +11 -11
- README.md +127 -133
- app/commit.json +1 -0
- app/components/chat/Artifact.tsx +24 -2
- app/components/chat/BaseChat.module.scss +0 -76
- app/components/chat/BaseChat.tsx +79 -59
- app/components/chat/Chat.client.tsx +4 -1
- app/components/chat/GitCloneButton.tsx +110 -0
- app/components/chat/ImportFolderButton.tsx +86 -127
- app/components/chat/ModelSelector.tsx +36 -2
- app/components/chat/SendButton.client.tsx +8 -3
- app/components/chat/chatExportAndImport/ImportButtons.tsx +1 -2
- app/components/editor/codemirror/languages.ts +7 -0
- app/components/git/GitUrlImport.client.tsx +117 -0
- app/components/header/Header.tsx +7 -8
- app/components/settings/Settings.module.scss +63 -0
- app/components/settings/SettingsWindow.tsx +128 -0
- app/components/settings/chat-history/ChatHistoryTab.tsx +113 -0
- app/components/settings/connections/ConnectionsTab.tsx +53 -0
- app/components/settings/debug/DebugTab.tsx +494 -0
- app/components/settings/event-logs/EventLogsTab.tsx +219 -0
- app/components/settings/features/FeaturesTab.tsx +33 -0
- app/components/settings/providers/ProvidersTab.tsx +95 -0
- app/components/sidebar/Menu.client.tsx +29 -6
- app/components/ui/BackgroundRays/index.tsx +18 -0
- app/components/ui/BackgroundRays/styles.module.scss +246 -0
- app/components/ui/SettingsButton.tsx +17 -0
- app/components/ui/Switch.tsx +37 -0
- app/components/workbench/Preview.tsx +234 -13
- app/components/workbench/ScreenshotSelector.tsx +1 -1
- app/components/workbench/Workbench.client.tsx +13 -11
- app/lib/.server/llm/api-key.ts +1 -1
- app/lib/.server/llm/model.ts +9 -2
- app/lib/.server/llm/prompts.ts +5 -5
- app/lib/.server/llm/stream-text.ts +16 -11
- app/lib/hooks/useGit.ts +287 -0
- app/lib/hooks/useSettings.tsx +125 -0
- app/lib/persistence/useChatHistory.ts +4 -0
- app/lib/runtime/__snapshots__/message-parser.spec.ts.snap +18 -0
- app/lib/runtime/message-parser.spec.ts +5 -1
- app/lib/runtime/message-parser.ts +2 -0
- app/lib/stores/logs.ts +149 -0
- app/lib/stores/settings.ts +21 -12
.github/ISSUE_TEMPLATE/config.yml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
blank_issues_enabled: false
|
2 |
+
contact_links:
|
3 |
+
- name: Bolt.new related issues
|
4 |
+
url: https://github.com/stackblitz/bolt.new/issues/new/choose
|
5 |
+
about: Report issues related to Bolt.new (not Bolt.diy)
|
6 |
+
- name: Chat
|
7 |
+
url: https://thinktank.ottomator.ai
|
8 |
+
about: Ask questions and discuss with other Bolt.diy users.
|
.github/workflows/commit.yaml
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Update Commit Hash File
|
2 |
+
|
3 |
+
on:
|
4 |
+
push:
|
5 |
+
branches:
|
6 |
+
- main
|
7 |
+
|
8 |
+
permissions:
|
9 |
+
contents: write
|
10 |
+
|
11 |
+
jobs:
|
12 |
+
update-commit:
|
13 |
+
if: contains(github.event.head_commit.message, '#release') != true
|
14 |
+
runs-on: ubuntu-latest
|
15 |
+
|
16 |
+
steps:
|
17 |
+
- name: Checkout the code
|
18 |
+
uses: actions/checkout@v3
|
19 |
+
|
20 |
+
- name: Get the latest commit hash
|
21 |
+
run: echo "COMMIT_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV
|
22 |
+
|
23 |
+
- name: Update commit file
|
24 |
+
run: |
|
25 |
+
echo "{ \"commit\": \"$COMMIT_HASH\" }" > app/commit.json
|
26 |
+
|
27 |
+
- name: Commit and push the update
|
28 |
+
run: |
|
29 |
+
git config --global user.name "github-actions[bot]"
|
30 |
+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
31 |
+
git add app/commit.json
|
32 |
+
git commit -m "chore: update commit hash to $COMMIT_HASH"
|
33 |
+
git push
|
.github/workflows/pr-release-validation.yaml
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: PR Validation
|
2 |
+
|
3 |
+
on:
|
4 |
+
pull_request:
|
5 |
+
types: [opened, synchronize, reopened, labeled, unlabeled]
|
6 |
+
branches:
|
7 |
+
- main
|
8 |
+
|
9 |
+
jobs:
|
10 |
+
validate:
|
11 |
+
runs-on: ubuntu-latest
|
12 |
+
|
13 |
+
steps:
|
14 |
+
- uses: actions/checkout@v4
|
15 |
+
|
16 |
+
- name: Validate PR Labels
|
17 |
+
run: |
|
18 |
+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'stable-release') }}" == "true" ]]; then
|
19 |
+
echo "✓ PR has stable-release label"
|
20 |
+
|
21 |
+
# Check version bump labels
|
22 |
+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'major') }}" == "true" ]]; then
|
23 |
+
echo "✓ Major version bump requested"
|
24 |
+
elif [[ "${{ contains(github.event.pull_request.labels.*.name, 'minor') }}" == "true" ]]; then
|
25 |
+
echo "✓ Minor version bump requested"
|
26 |
+
else
|
27 |
+
echo "✓ Patch version bump will be applied"
|
28 |
+
fi
|
29 |
+
else
|
30 |
+
echo "This PR doesn't have the stable-release label. No release will be created."
|
31 |
+
fi
|
.github/workflows/update-stable.yml
ADDED
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Update Stable Branch
|
2 |
+
|
3 |
+
on:
|
4 |
+
push:
|
5 |
+
branches:
|
6 |
+
- main
|
7 |
+
|
8 |
+
permissions:
|
9 |
+
contents: write
|
10 |
+
|
11 |
+
jobs:
|
12 |
+
update-commit:
|
13 |
+
if: contains(github.event.head_commit.message, '#release')
|
14 |
+
runs-on: ubuntu-latest
|
15 |
+
|
16 |
+
steps:
|
17 |
+
- name: Checkout the code
|
18 |
+
uses: actions/checkout@v3
|
19 |
+
|
20 |
+
- name: Get the latest commit hash
|
21 |
+
run: echo "COMMIT_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV
|
22 |
+
|
23 |
+
- name: Update commit file
|
24 |
+
run: |
|
25 |
+
echo "{ \"commit\": \"$COMMIT_HASH\" }" > app/commit.json
|
26 |
+
|
27 |
+
- name: Commit and push the update
|
28 |
+
run: |
|
29 |
+
git config --global user.name "github-actions[bot]"
|
30 |
+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
31 |
+
git add app/commit.json
|
32 |
+
git commit -m "chore: update commit hash to $COMMIT_HASH"
|
33 |
+
git push
|
34 |
+
prepare-release:
|
35 |
+
needs: update-commit
|
36 |
+
if: contains(github.event.head_commit.message, '#release')
|
37 |
+
runs-on: ubuntu-latest
|
38 |
+
|
39 |
+
steps:
|
40 |
+
- uses: actions/checkout@v4
|
41 |
+
with:
|
42 |
+
fetch-depth: 0
|
43 |
+
|
44 |
+
- name: Configure Git
|
45 |
+
run: |
|
46 |
+
git config --global user.name 'github-actions[bot]'
|
47 |
+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
|
48 |
+
|
49 |
+
- name: Setup Node.js
|
50 |
+
uses: actions/setup-node@v4
|
51 |
+
with:
|
52 |
+
node-version: '20'
|
53 |
+
|
54 |
+
- name: Install pnpm
|
55 |
+
uses: pnpm/action-setup@v2
|
56 |
+
with:
|
57 |
+
version: latest
|
58 |
+
run_install: false
|
59 |
+
|
60 |
+
- name: Get pnpm store directory
|
61 |
+
id: pnpm-cache
|
62 |
+
shell: bash
|
63 |
+
run: |
|
64 |
+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
|
65 |
+
|
66 |
+
- name: Setup pnpm cache
|
67 |
+
uses: actions/cache@v4
|
68 |
+
with:
|
69 |
+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
|
70 |
+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
71 |
+
restore-keys: |
|
72 |
+
${{ runner.os }}-pnpm-store-
|
73 |
+
|
74 |
+
- name: Get Current Version
|
75 |
+
id: current_version
|
76 |
+
run: |
|
77 |
+
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
78 |
+
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
|
79 |
+
|
80 |
+
- name: Install semver
|
81 |
+
run: pnpm add -g semver
|
82 |
+
|
83 |
+
- name: Determine Version Bump
|
84 |
+
id: version_bump
|
85 |
+
run: |
|
86 |
+
COMMIT_MSG="${{ github.event.head_commit.message }}"
|
87 |
+
if [[ $COMMIT_MSG =~ "#release:major" ]]; then
|
88 |
+
echo "bump=major" >> $GITHUB_OUTPUT
|
89 |
+
elif [[ $COMMIT_MSG =~ "#release:minor" ]]; then
|
90 |
+
echo "bump=minor" >> $GITHUB_OUTPUT
|
91 |
+
else
|
92 |
+
echo "bump=patch" >> $GITHUB_OUTPUT
|
93 |
+
fi
|
94 |
+
|
95 |
+
- name: Bump Version
|
96 |
+
id: bump_version
|
97 |
+
run: |
|
98 |
+
NEW_VERSION=$(semver -i ${{ steps.version_bump.outputs.bump }} ${{ steps.current_version.outputs.version }})
|
99 |
+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
100 |
+
|
101 |
+
- name: Update Package.json
|
102 |
+
run: |
|
103 |
+
NEW_VERSION=${{ steps.bump_version.outputs.new_version }}
|
104 |
+
pnpm version $NEW_VERSION --no-git-tag-version --allow-same-version
|
105 |
+
|
106 |
+
- name: Generate Changelog
|
107 |
+
id: changelog
|
108 |
+
run: |
|
109 |
+
# Get the latest tag
|
110 |
+
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
|
111 |
+
|
112 |
+
# Start changelog file
|
113 |
+
echo "# Release v${{ steps.bump_version.outputs.new_version }}" > changelog.md
|
114 |
+
echo "" >> changelog.md
|
115 |
+
|
116 |
+
if [ -z "$LATEST_TAG" ]; then
|
117 |
+
echo "### 🎉 First Release" >> changelog.md
|
118 |
+
echo "" >> changelog.md
|
119 |
+
COMPARE_BASE="$(git rev-list --max-parents=0 HEAD)"
|
120 |
+
else
|
121 |
+
echo "### 🔄 Changes since $LATEST_TAG" >> changelog.md
|
122 |
+
echo "" >> changelog.md
|
123 |
+
COMPARE_BASE="$LATEST_TAG"
|
124 |
+
fi
|
125 |
+
|
126 |
+
# Function to extract conventional commit type
|
127 |
+
get_commit_type() {
|
128 |
+
if [[ $1 =~ ^feat:|^feature: ]]; then echo "✨ Features";
|
129 |
+
elif [[ $1 =~ ^fix: ]]; then echo "🐛 Bug Fixes";
|
130 |
+
elif [[ $1 =~ ^docs: ]]; then echo "📚 Documentation";
|
131 |
+
elif [[ $1 =~ ^style: ]]; then echo "💎 Styles";
|
132 |
+
elif [[ $1 =~ ^refactor: ]]; then echo "♻️ Code Refactoring";
|
133 |
+
elif [[ $1 =~ ^perf: ]]; then echo "⚡️ Performance Improvements";
|
134 |
+
elif [[ $1 =~ ^test: ]]; then echo "✅ Tests";
|
135 |
+
elif [[ $1 =~ ^build: ]]; then echo "🛠️ Build System";
|
136 |
+
elif [[ $1 =~ ^ci: ]]; then echo "⚙️ CI";
|
137 |
+
elif [[ $1 =~ ^chore: ]]; then echo "🔧 Chores";
|
138 |
+
else echo "🔍 Other Changes";
|
139 |
+
fi
|
140 |
+
}
|
141 |
+
|
142 |
+
# Generate categorized changelog
|
143 |
+
declare -A CATEGORIES
|
144 |
+
declare -A COMMITS_BY_CATEGORY
|
145 |
+
|
146 |
+
# Get commits since last tag or all commits if no tag exists
|
147 |
+
while IFS= read -r commit_line; do
|
148 |
+
HASH=$(echo "$commit_line" | cut -d'|' -f1)
|
149 |
+
MSG=$(echo "$commit_line" | cut -d'|' -f2)
|
150 |
+
PR_NUM=$(echo "$commit_line" | cut -d'|' -f3)
|
151 |
+
|
152 |
+
CATEGORY=$(get_commit_type "$MSG")
|
153 |
+
CATEGORIES["$CATEGORY"]=1
|
154 |
+
|
155 |
+
# Format commit message with PR link if available
|
156 |
+
if [ -n "$PR_NUM" ]; then
|
157 |
+
COMMITS_BY_CATEGORY["$CATEGORY"]+="- ${MSG#*: } ([#$PR_NUM](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/pull/$PR_NUM))"$'\n'
|
158 |
+
else
|
159 |
+
COMMITS_BY_CATEGORY["$CATEGORY"]+="- ${MSG#*: }"$'\n'
|
160 |
+
fi
|
161 |
+
done < <(git log "${COMPARE_BASE}..HEAD" --pretty=format:"%H|%s|%(trailers:key=PR-Number,valueonly)" --reverse)
|
162 |
+
|
163 |
+
# Write categorized commits to changelog
|
164 |
+
for category in "✨ Features" "🐛 Bug Fixes" "📚 Documentation" "💎 Styles" "♻️ Code Refactoring" "⚡️ Performance Improvements" "✅ Tests" "🛠️ Build System" "⚙️ CI" "🔧 Chores" "🔍 Other Changes"; do
|
165 |
+
if [ -n "${COMMITS_BY_CATEGORY[$category]}" ]; then
|
166 |
+
echo "#### $category" >> changelog.md
|
167 |
+
echo "" >> changelog.md
|
168 |
+
echo "${COMMITS_BY_CATEGORY[$category]}" >> changelog.md
|
169 |
+
echo "" >> changelog.md
|
170 |
+
fi
|
171 |
+
done
|
172 |
+
|
173 |
+
# Add compare link if not first release
|
174 |
+
if [ -n "$LATEST_TAG" ]; then
|
175 |
+
echo "**Full Changelog**: [\`$LATEST_TAG..v${{ steps.bump_version.outputs.new_version }}\`](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/compare/$LATEST_TAG...v${{ steps.bump_version.outputs.new_version }})" >> changelog.md
|
176 |
+
fi
|
177 |
+
|
178 |
+
# Save changelog content for the release
|
179 |
+
CHANGELOG_CONTENT=$(cat changelog.md)
|
180 |
+
echo "content<<EOF" >> $GITHUB_OUTPUT
|
181 |
+
echo "$CHANGELOG_CONTENT" >> $GITHUB_OUTPUT
|
182 |
+
echo "EOF" >> $GITHUB_OUTPUT
|
183 |
+
|
184 |
+
- name: Commit and Tag Release
|
185 |
+
run: |
|
186 |
+
git pull
|
187 |
+
git add package.json pnpm-lock.yaml changelog.md
|
188 |
+
git commit -m "chore: release version ${{ steps.bump_version.outputs.new_version }}"
|
189 |
+
git tag "v${{ steps.bump_version.outputs.new_version }}"
|
190 |
+
git push
|
191 |
+
git push --tags
|
192 |
+
|
193 |
+
- name: Update Stable Branch
|
194 |
+
run: |
|
195 |
+
if ! git checkout stable 2>/dev/null; then
|
196 |
+
echo "Creating new stable branch..."
|
197 |
+
git checkout -b stable
|
198 |
+
fi
|
199 |
+
git merge main --no-ff -m "chore: release version ${{ steps.bump_version.outputs.new_version }}"
|
200 |
+
git push --set-upstream origin stable --force
|
201 |
+
|
202 |
+
- name: Create GitHub Release
|
203 |
+
env:
|
204 |
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
205 |
+
run: |
|
206 |
+
VERSION="v${{ steps.bump_version.outputs.new_version }}"
|
207 |
+
gh release create "$VERSION" \
|
208 |
+
--title "Release $VERSION" \
|
209 |
+
--notes "${{ steps.changelog.outputs.content }}" \
|
210 |
+
--target stable
|
.gitignore
CHANGED
@@ -37,3 +37,6 @@ modelfiles
|
|
37 |
|
38 |
# docs ignore
|
39 |
site
|
|
|
|
|
|
|
|
37 |
|
38 |
# docs ignore
|
39 |
site
|
40 |
+
|
41 |
+
# commit file ignore
|
42 |
+
app/commit.json
|
.husky/pre-commit
CHANGED
@@ -2,19 +2,42 @@
|
|
2 |
|
3 |
echo "🔍 Running pre-commit hook to check the code looks good... 🔍"
|
4 |
|
|
|
5 |
export NVM_DIR="$HOME/.nvm"
|
6 |
-
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
if ! pnpm typecheck; then
|
9 |
echo "❌ Type checking failed! Please review TypeScript types."
|
10 |
echo "Once you're done, don't forget to add your changes to the commit! 🚀"
|
11 |
exit 1
|
12 |
fi
|
13 |
|
|
|
|
|
14 |
if ! pnpm lint; then
|
15 |
-
echo "❌ Linting failed! 'pnpm lint:fix'
|
16 |
echo "Once you're done, don't forget to add your beautification to the commit! 🤩"
|
17 |
exit 1
|
18 |
fi
|
19 |
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
# Update commit.json with the latest commit hash
|
33 |
+
echo "Updating commit.json with the latest commit hash..."
|
34 |
+
COMMIT_HASH=$(git rev-parse HEAD)
|
35 |
+
if [ $? -ne 0 ]; then
|
36 |
+
echo "❌ Failed to get commit hash. Ensure you are in a git repository."
|
37 |
+
exit 1
|
38 |
+
fi
|
39 |
+
|
40 |
+
echo "{ \"commit\": \"$COMMIT_HASH\" }" > app/commit.json
|
41 |
+
git add app/commit.json
|
42 |
+
|
43 |
+
echo "👍 All checks passed! Committing changes..."
|
CONTRIBUTING.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
# Contributing to oTToDev
|
2 |
|
3 |
-
First off, thank you for considering contributing to
|
4 |
|
5 |
## 📋 Table of Contents
|
6 |
- [Code of Conduct](#code-of-conduct)
|
|
|
1 |
# Contributing to oTToDev
|
2 |
|
3 |
+
First off, thank you for considering contributing to Bolt.diy! This fork aims to expand the capabilities of the original project by integrating multiple LLM providers and enhancing functionality. Every contribution helps make Bolt.diy a better tool for developers worldwide.
|
4 |
|
5 |
## 📋 Table of Contents
|
6 |
- [Code of Conduct](#code-of-conduct)
|
FAQ.md
CHANGED
@@ -1,45 +1,45 @@
|
|
1 |
[](https://bolt.new)
|
2 |
|
3 |
-
# Bolt.new Fork by Cole Medin -
|
4 |
|
5 |
## FAQ
|
6 |
|
7 |
-
### How do I get the best results with
|
8 |
|
9 |
- **Be specific about your stack**: If you want to use specific frameworks or libraries (like Astro, Tailwind, ShadCN, or any other popular JavaScript framework), mention them in your initial prompt to ensure Bolt scaffolds the project accordingly.
|
10 |
|
11 |
- **Use the enhance prompt icon**: Before sending your prompt, try clicking the 'enhance' icon to have the AI model help you refine your prompt, then edit the results before submitting.
|
12 |
|
13 |
-
- **Scaffold the basics first, then add features**: Make sure the basic structure of your application is in place before diving into more advanced functionality. This helps
|
14 |
|
15 |
-
- **Batch simple instructions**: Save time by combining simple instructions into one message. For example, you can ask
|
16 |
|
17 |
-
### Do you plan on merging
|
18 |
|
19 |
More news coming on this coming early next month - stay tuned!
|
20 |
|
21 |
### Why are there so many open issues/pull requests?
|
22 |
|
23 |
-
|
24 |
grew into a massive community project that I am working hard to keep up with the demand of by forming a team of maintainers and getting as many people involved as I can.
|
25 |
That effort is going well and all of our maintainers are ABSOLUTE rockstars, but it still takes time to organize everything so we can efficiently get through all
|
26 |
the issues and PRs. But rest assured, we are working hard and even working on some partnerships behind the scenes to really help this project take off!
|
27 |
|
28 |
-
### How do local LLMs fair compared to larger models like Claude 3.5 Sonnet for
|
29 |
|
30 |
As much as the gap is quickly closing between open source and massive close source models, you’re still going to get the best results with the very large models like GPT-4o, Claude 3.5 Sonnet, and DeepSeek Coder V2 236b. This is one of the big tasks we have at hand - figuring out how to prompt better, use agents, and improve the platform as a whole to make it work better for even the smaller local LLMs!
|
31 |
|
32 |
### I'm getting the error: "There was an error processing this request"
|
33 |
|
34 |
-
If you see this error within
|
35 |
|
36 |
### I'm getting the error: "x-api-key header missing"
|
37 |
|
38 |
-
We have seen this error a couple times and for some reason just restarting the Docker container has fixed it. This seems to be Ollama specific. Another thing to try is try to run
|
39 |
|
40 |
-
### I'm getting a blank preview when
|
41 |
|
42 |
-
We promise you that we are constantly testing new PRs coming into
|
43 |
|
44 |
### How to add a LLM:
|
45 |
|
|
|
1 |
[](https://bolt.new)
|
2 |
|
3 |
+
# Bolt.new Fork by Cole Medin - Bolt.diy
|
4 |
|
5 |
## FAQ
|
6 |
|
7 |
+
### How do I get the best results with Bolt.diy?
|
8 |
|
9 |
- **Be specific about your stack**: If you want to use specific frameworks or libraries (like Astro, Tailwind, ShadCN, or any other popular JavaScript framework), mention them in your initial prompt to ensure Bolt scaffolds the project accordingly.
|
10 |
|
11 |
- **Use the enhance prompt icon**: Before sending your prompt, try clicking the 'enhance' icon to have the AI model help you refine your prompt, then edit the results before submitting.
|
12 |
|
13 |
+
- **Scaffold the basics first, then add features**: Make sure the basic structure of your application is in place before diving into more advanced functionality. This helps Bolt.diy understand the foundation of your project and ensure everything is wired up right before building out more advanced functionality.
|
14 |
|
15 |
+
- **Batch simple instructions**: Save time by combining simple instructions into one message. For example, you can ask Bolt.diy to change the color scheme, add mobile responsiveness, and restart the dev server, all in one go saving you time and reducing API credit consumption significantly.
|
16 |
|
17 |
+
### Do you plan on merging Bolt.diy back into the official Bolt.new repo?
|
18 |
|
19 |
More news coming on this coming early next month - stay tuned!
|
20 |
|
21 |
### Why are there so many open issues/pull requests?
|
22 |
|
23 |
+
Bolt.diy was started simply to showcase how to edit an open source project and to do something cool with local LLMs on my (@ColeMedin) YouTube channel! However, it quickly
|
24 |
grew into a massive community project that I am working hard to keep up with the demand of by forming a team of maintainers and getting as many people involved as I can.
|
25 |
That effort is going well and all of our maintainers are ABSOLUTE rockstars, but it still takes time to organize everything so we can efficiently get through all
|
26 |
the issues and PRs. But rest assured, we are working hard and even working on some partnerships behind the scenes to really help this project take off!
|
27 |
|
28 |
+
### How do local LLMs fair compared to larger models like Claude 3.5 Sonnet for Bolt.diy/Bolt.new?
|
29 |
|
30 |
As much as the gap is quickly closing between open source and massive close source models, you’re still going to get the best results with the very large models like GPT-4o, Claude 3.5 Sonnet, and DeepSeek Coder V2 236b. This is one of the big tasks we have at hand - figuring out how to prompt better, use agents, and improve the platform as a whole to make it work better for even the smaller local LLMs!
|
31 |
|
32 |
### I'm getting the error: "There was an error processing this request"
|
33 |
|
34 |
+
If you see this error within Bolt.diy, that is just the application telling you there is a problem at a high level, and this could mean a number of different things. To find the actual error, please check BOTH the terminal where you started the application (with Docker or pnpm) and the developer console in the browser. For most browsers, you can access the developer console by pressing F12 or right clicking anywhere in the browser and selecting “Inspect”. Then go to the “console” tab in the top right.
|
35 |
|
36 |
### I'm getting the error: "x-api-key header missing"
|
37 |
|
38 |
+
We have seen this error a couple times and for some reason just restarting the Docker container has fixed it. This seems to be Ollama specific. Another thing to try is try to run Bolt.diy with Docker or pnpm, whichever you didn’t run first. We are still on the hunt for why this happens once and a while!
|
39 |
|
40 |
+
### I'm getting a blank preview when Bolt.diy runs my app!
|
41 |
|
42 |
+
We promise you that we are constantly testing new PRs coming into Bolt.diy and the preview is core functionality, so the application is not broken! When you get a blank preview or don’t get a preview, this is generally because the LLM hallucinated bad code or incorrect commands. We are working on making this more transparent so it is obvious. Sometimes the error will appear in developer console too so check that as well.
|
43 |
|
44 |
### How to add a LLM:
|
45 |
|
README.md
CHANGED
@@ -1,12 +1,14 @@
|
|
1 |
-
[
|
59 |
-
|
60 |
-
## What Makes Bolt.new Different
|
61 |
-
|
62 |
-
Claude, v0, etc are incredible- but you can't install packages, run backends, or edit code. That’s where Bolt.new stands out:
|
63 |
-
|
64 |
-
- **Full-Stack in the Browser**: Bolt.new integrates cutting-edge AI models with an in-browser development environment powered by **StackBlitz’s WebContainers**. This allows you to:
|
65 |
-
- Install and run npm tools and libraries (like Vite, Next.js, and more)
|
66 |
-
- Run Node.js servers
|
67 |
-
- Interact with third-party APIs
|
68 |
-
- Deploy to production from chat
|
69 |
-
- Share your work via a URL
|
70 |
-
|
71 |
-
- **AI with Environment Control**: Unlike traditional dev environments where the AI can only assist in code generation, Bolt.new gives AI models **complete control** over the entire environment including the filesystem, node server, package manager, terminal, and browser console. This empowers AI agents to handle the whole app lifecycle—from creation to deployment.
|
72 |
-
|
73 |
-
Whether you’re an experienced developer, a PM, or a designer, Bolt.new allows you to easily build production-grade full-stack applications.
|
74 |
-
|
75 |
-
For developers interested in building their own AI-powered development tools with WebContainers, check out the open-source Bolt codebase in this repo!
|
76 |
-
|
77 |
-
## Setup
|
78 |
-
|
79 |
-
Many of you are new users to installing software from Github. If you have any installation troubles reach out and submit an "issue" using the links above, or feel free to enhance this documentation by forking, editing the instructions, and doing a pull request.
|
80 |
-
|
81 |
-
1. Install Git from https://git-scm.com/downloads
|
82 |
-
|
83 |
-
2. Install Node.js from https://nodejs.org/en/download/
|
84 |
-
|
85 |
-
Pay attention to the installer notes after completion.
|
86 |
-
|
87 |
-
On all operating systems, the path to Node.js should automatically be added to your system path. But you can check your path if you want to be sure. On Windows, you can search for "edit the system environment variables" in your system, select "Environment Variables..." once you are in the system properties, and then check for a path to Node in your "Path" system variable. On a Mac or Linux machine, it will tell you to check if /usr/local/bin is in your $PATH. To determine if usr/local/bin is included in $PATH open your Terminal and run:
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
|
|
92 |
|
93 |
-
|
94 |
|
95 |
-
|
96 |
|
97 |
-
|
98 |
-
git clone https://github.com/coleam00/bolt.new-any-llm.git
|
99 |
-
```
|
100 |
|
101 |
-
|
|
|
102 |
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
|
105 |
-
|
106 |
|
107 |
-
|
108 |
-
defaults write com.apple.finder AppleShowAllFiles YES
|
109 |
-
```
|
110 |
|
111 |
-
|
|
|
|
|
112 |
|
113 |
-
|
114 |
|
115 |
-
|
116 |
|
117 |
-
|
|
|
118 |
|
119 |
-
```
|
120 |
-
GROQ_API_KEY=
|
121 |
-
OPENAI_API_KEY=
|
122 |
-
ANTHROPIC_API_KEY=
|
123 |
-
```
|
124 |
|
125 |
-
|
126 |
|
127 |
-
|
128 |
-
VITE_LOG_LEVEL=debug
|
129 |
-
```
|
130 |
|
131 |
-
|
|
|
|
|
132 |
|
133 |
-
|
134 |
-
OLLAMA_API_BASE_URL=http://localhost:11434
|
135 |
-
DEFAULT_NUM_CTX=8192
|
136 |
-
```
|
137 |
|
138 |
-
**Important**:
|
139 |
|
140 |
-
|
141 |
|
142 |
-
|
143 |
|
144 |
-
|
145 |
|
146 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
|
148 |
-
|
|
|
|
|
|
|
|
|
149 |
|
150 |
-
|
151 |
-
# Development build
|
152 |
-
npm run dockerbuild
|
153 |
|
154 |
-
|
155 |
-
|
156 |
-
```
|
157 |
|
158 |
-
|
159 |
|
160 |
-
|
161 |
|
162 |
-
|
163 |
-
|
164 |
-
|
|
|
|
|
165 |
|
166 |
-
|
167 |
-
|
168 |
-
|
|
|
|
|
169 |
|
170 |
-
|
|
|
|
|
|
|
|
|
|
|
171 |
|
172 |
-
|
173 |
|
174 |
-
|
175 |
-
# Development environment
|
176 |
-
docker-compose --profile development up
|
177 |
|
178 |
-
|
179 |
-
docker-compose --profile production up
|
180 |
-
```
|
181 |
|
182 |
-
|
183 |
-
make on your machine to the code will automatically be reflected in the site running
|
184 |
-
on the container (i.e. hot reloading still applies!).
|
185 |
|
186 |
-
|
|
|
187 |
|
188 |
-
|
|
|
189 |
|
190 |
-
```
|
191 |
-
|
192 |
-
```
|
193 |
|
194 |
-
|
|
|
195 |
|
196 |
-
```
|
197 |
-
|
198 |
-
```
|
199 |
|
200 |
-
|
|
|
201 |
|
202 |
-
```bash
|
203 |
-
pnpm run dev
|
204 |
-
```
|
205 |
-
## Available Scripts
|
206 |
|
207 |
-
|
208 |
-
- `pnpm run build`: Builds the project.
|
209 |
-
- `pnpm run start`: Runs the built application locally using Wrangler Pages. This script uses `bindings.sh` to set up necessary bindings so you don't have to duplicate environment variables.
|
210 |
-
- `pnpm run preview`: Builds the project and then starts it locally, useful for testing the production build. Note, HTTP streaming currently doesn't work as expected with `wrangler pages dev`.
|
211 |
-
- `pnpm test`: Runs the test suite using Vitest.
|
212 |
-
- `pnpm run typecheck`: Runs TypeScript type checking.
|
213 |
-
- `pnpm run typegen`: Generates TypeScript types using Wrangler.
|
214 |
-
- `pnpm run deploy`: Builds the project and deploys it to Cloudflare Pages.
|
215 |
-
- `pnpm run lint:fix`: Runs the linter and automatically fixes issues according to your ESLint configuration.
|
216 |
|
217 |
-
|
218 |
|
219 |
-
|
220 |
|
221 |
-
|
222 |
-
pnpm run dev
|
223 |
-
```
|
224 |
|
225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
|
227 |
-
## How do I contribute to
|
228 |
|
229 |
-
[Please check out our dedicated page for contributing to
|
230 |
|
231 |
-
## What are the future plans for
|
232 |
|
233 |
[Check out our Roadmap here!](https://roadmap.sh/r/ottodev-roadmap-2ovzo)
|
234 |
|
@@ -236,4 +230,4 @@ Lot more updates to this roadmap coming soon!
|
|
236 |
|
237 |
## FAQ
|
238 |
|
239 |
-
[Please check out our dedicated page for FAQ's related to
|
|
|
1 |
+
[](https://bolt.diy)
|
2 |
|
3 |
+
# Bolt.diy (Previously oTToDev)
|
4 |
|
5 |
+
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.
|
6 |
|
7 |
+
Check the [Bolt.diy Docs](https://stackblitz-labs.github.io/bolt.diy/) for more information. This documentation is still being updated after the transfer.
|
8 |
|
9 |
+
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!
|
10 |
+
|
11 |
+
## Join the community for Bolt.diy!
|
12 |
|
13 |
https://thinktank.ottomator.ai
|
14 |
|
|
|
43 |
- ✅ Mobile friendly (@qwikode)
|
44 |
- ✅ Better prompt enhancing (@SujalXplores)
|
45 |
- ✅ Attach images to prompts (@atrokhym)
|
46 |
+
- ✅ Detect package.json and commands to auto install and run preview for folder and git import (@wonderwhy-er)
|
47 |
- ⬜ **HIGH PRIORITY** - Prevent Bolt from rewriting files as often (file locking and diffs)
|
48 |
- ⬜ **HIGH PRIORITY** - Better prompting for smaller LLMs (code window sometimes doesn't start)
|
49 |
- ⬜ **HIGH PRIORITY** - Run agents in the backend as opposed to a single model call
|
|
|
56 |
- ⬜ Perplexity Integration
|
57 |
- ⬜ Vertex AI Integration
|
58 |
|
59 |
+
## Bolt.diy Features
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
+
- **AI-powered full-stack web development** directly in your browser.
|
62 |
+
- **Support for multiple LLMs** with an extensible architecture to integrate additional models.
|
63 |
+
- **Attach images to prompts** for better contextual understanding.
|
64 |
+
- **Integrated terminal** to view output of LLM-run commands.
|
65 |
+
- **Revert code to earlier versions** for easier debugging and quicker changes.
|
66 |
+
- **Download projects as ZIP** for easy portability.
|
67 |
+
- **Integration-ready Docker support** for a hassle-free setup.
|
68 |
|
69 |
+
## Setup Bolt.diy
|
70 |
|
71 |
+
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.
|
72 |
|
73 |
+
### Prerequisites
|
|
|
|
|
74 |
|
75 |
+
1. **Install Git**: [Download Git](https://git-scm.com/downloads)
|
76 |
+
2. **Install Node.js**: [Download Node.js](https://nodejs.org/en/download/)
|
77 |
|
78 |
+
- After installation, the Node.js path is usually added to your system automatically. To verify:
|
79 |
+
- **Windows**: Search for "Edit the system environment variables," click "Environment Variables," and check if `Node.js` is in the `Path` variable.
|
80 |
+
- **Mac/Linux**: Open a terminal and run:
|
81 |
+
```bash
|
82 |
+
echo $PATH
|
83 |
+
```
|
84 |
+
Look for `/usr/local/bin` in the output.
|
85 |
|
86 |
+
### Clone the Repository
|
87 |
|
88 |
+
Clone the repository using Git:
|
|
|
|
|
89 |
|
90 |
+
```bash
|
91 |
+
git clone -b stable https://github.com/stackblitz-labs/bolt.diy
|
92 |
+
```
|
93 |
|
94 |
+
### (Optional) Configure Environment Variables
|
95 |
|
96 |
+
Most environment variables can be configured directly through the settings menu of the application. However, if you need to manually configure them:
|
97 |
|
98 |
+
1. Rename `.env.example` to `.env.local`.
|
99 |
+
2. Add your LLM API keys. For example:
|
100 |
|
101 |
+
```env
|
102 |
+
GROQ_API_KEY=YOUR_GROQ_API_KEY
|
103 |
+
OPENAI_API_KEY=YOUR_OPENAI_API_KEY
|
104 |
+
ANTHROPIC_API_KEY=YOUR_ANTHROPIC_API_KEY
|
105 |
+
```
|
106 |
|
107 |
+
**Note**: Ollama does not require an API key as it runs locally.
|
108 |
|
109 |
+
3. Optionally, set additional configurations:
|
|
|
|
|
110 |
|
111 |
+
```env
|
112 |
+
# Debugging
|
113 |
+
VITE_LOG_LEVEL=debug
|
114 |
|
115 |
+
# Ollama settings (example: 8K context, localhost port 11434)
|
116 |
+
OLLAMA_API_BASE_URL=http://localhost:11434
|
117 |
+
DEFAULT_NUM_CTX=8192
|
118 |
+
```
|
119 |
|
120 |
+
**Important**: Do not commit your `.env.local` file to version control. This file is already included in `.gitignore`.
|
121 |
|
122 |
+
---
|
123 |
|
124 |
+
## Run the Application
|
125 |
|
126 |
+
### Option 1: Without Docker
|
127 |
|
128 |
+
1. **Install Dependencies**:
|
129 |
+
```bash
|
130 |
+
pnpm install
|
131 |
+
```
|
132 |
+
If `pnpm` is not installed, install it using:
|
133 |
+
```bash
|
134 |
+
sudo npm install -g pnpm
|
135 |
+
```
|
136 |
|
137 |
+
2. **Start the Application**:
|
138 |
+
```bash
|
139 |
+
pnpm run dev
|
140 |
+
```
|
141 |
+
This will start the Remix Vite development server. You will need Google Chrome Canary to run this locally if you use Chrome! It's an easy install and a good browser for web development anyway.
|
142 |
|
143 |
+
### Option 2: With Docker
|
|
|
|
|
144 |
|
145 |
+
#### Prerequisites
|
146 |
+
- Ensure Git, Node.js, and Docker are installed: [Download Docker](https://www.docker.com/)
|
|
|
147 |
|
148 |
+
#### Steps
|
149 |
|
150 |
+
1. **Build the Docker Image**:
|
151 |
|
152 |
+
Use the provided NPM scripts:
|
153 |
+
```bash
|
154 |
+
npm run dockerbuild # Development build
|
155 |
+
npm run dockerbuild:prod # Production build
|
156 |
+
```
|
157 |
|
158 |
+
Alternatively, use Docker commands directly:
|
159 |
+
```bash
|
160 |
+
docker build . --target bolt-ai-development # Development build
|
161 |
+
docker build . --target bolt-ai-production # Production build
|
162 |
+
```
|
163 |
|
164 |
+
2. **Run the Container**:
|
165 |
+
Use Docker Compose profiles to manage environments:
|
166 |
+
```bash
|
167 |
+
docker-compose --profile development up # Development
|
168 |
+
docker-compose --profile production up # Production
|
169 |
+
```
|
170 |
|
171 |
+
- With the development profile, changes to your code will automatically reflect in the running container (hot reloading).
|
172 |
|
173 |
+
---
|
|
|
|
|
174 |
|
175 |
+
### Update Your Local Version to the Latest
|
|
|
|
|
176 |
|
177 |
+
To keep your local version of Bolt.diy up to date with the latest changes, follow these steps for your operating system:
|
|
|
|
|
178 |
|
179 |
+
#### 1. **Navigate to your project folder**
|
180 |
+
Navigate to the directory where you cloned the repository and open a terminal:
|
181 |
|
182 |
+
#### 2. **Fetch the Latest Changes**
|
183 |
+
Use Git to pull the latest changes from the main repository:
|
184 |
|
185 |
+
```bash
|
186 |
+
git pull origin main
|
187 |
+
```
|
188 |
|
189 |
+
#### 3. **Update Dependencies**
|
190 |
+
After pulling the latest changes, update the project dependencies by running the following command:
|
191 |
|
192 |
+
```bash
|
193 |
+
pnpm install
|
194 |
+
```
|
195 |
|
196 |
+
#### 4. **Run the Application**
|
197 |
+
Once the updates are complete, you can start the application again with:
|
198 |
|
199 |
+
```bash
|
200 |
+
pnpm run dev
|
201 |
+
```
|
|
|
202 |
|
203 |
+
This ensures that you're running the latest version of Bolt.diy and can take advantage of all the newest features and bug fixes.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
|
205 |
+
---
|
206 |
|
207 |
+
## Available Scripts
|
208 |
|
209 |
+
Here are the available commands for managing the application:
|
|
|
|
|
210 |
|
211 |
+
- `pnpm run dev`: Start the development server.
|
212 |
+
- `pnpm run build`: Build the project.
|
213 |
+
- `pnpm run start`: Run the built application locally (uses Wrangler Pages).
|
214 |
+
- `pnpm run preview`: Build and start the application locally for production testing.
|
215 |
+
- `pnpm test`: Run the test suite using Vitest.
|
216 |
+
- `pnpm run typecheck`: Perform TypeScript type checking.
|
217 |
+
- `pnpm run typegen`: Generate TypeScript types using Wrangler.
|
218 |
+
- `pnpm run deploy`: Build and deploy the project to Cloudflare Pages.
|
219 |
+
- `pnpm lint:fix`: Run the linter and automatically fix issues.
|
220 |
|
221 |
+
## How do I contribute to Bolt.diy?
|
222 |
|
223 |
+
[Please check out our dedicated page for contributing to Bolt.diy here!](CONTRIBUTING.md)
|
224 |
|
225 |
+
## What are the future plans for Bolt.diy?
|
226 |
|
227 |
[Check out our Roadmap here!](https://roadmap.sh/r/ottodev-roadmap-2ovzo)
|
228 |
|
|
|
230 |
|
231 |
## FAQ
|
232 |
|
233 |
+
[Please check out our dedicated page for FAQ's related to Bolt.diy here!](FAQ.md)
|
app/commit.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{ "commit": "1e04ab38b07e82852626b164890f4a6df1f98cef" }
|
app/components/chat/Artifact.tsx
CHANGED
@@ -28,6 +28,7 @@ interface ArtifactProps {
|
|
28 |
export const Artifact = memo(({ messageId }: ArtifactProps) => {
|
29 |
const userToggledActions = useRef(false);
|
30 |
const [showActions, setShowActions] = useState(false);
|
|
|
31 |
|
32 |
const artifacts = useStore(workbenchStore.artifacts);
|
33 |
const artifact = artifacts[messageId];
|
@@ -47,6 +48,14 @@ export const Artifact = memo(({ messageId }: ArtifactProps) => {
|
|
47 |
if (actions.length && !showActions && !userToggledActions.current) {
|
48 |
setShowActions(true);
|
49 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
}, [actions]);
|
51 |
|
52 |
return (
|
@@ -59,6 +68,18 @@ export const Artifact = memo(({ messageId }: ArtifactProps) => {
|
|
59 |
workbenchStore.showWorkbench.set(!showWorkbench);
|
60 |
}}
|
61 |
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
<div className="px-5 p-3.5 w-full text-left">
|
63 |
<div className="w-full text-bolt-elements-textPrimary font-medium leading-5 text-sm">{artifact?.title}</div>
|
64 |
<div className="w-full w-full text-bolt-elements-textSecondary text-xs mt-0.5">Click to open Workbench</div>
|
@@ -66,7 +87,7 @@ export const Artifact = memo(({ messageId }: ArtifactProps) => {
|
|
66 |
</button>
|
67 |
<div className="bg-bolt-elements-artifacts-borderColor w-[1px]" />
|
68 |
<AnimatePresence>
|
69 |
-
{actions.length && (
|
70 |
<motion.button
|
71 |
initial={{ width: 0 }}
|
72 |
animate={{ width: 'auto' }}
|
@@ -83,7 +104,7 @@ export const Artifact = memo(({ messageId }: ArtifactProps) => {
|
|
83 |
</AnimatePresence>
|
84 |
</div>
|
85 |
<AnimatePresence>
|
86 |
-
{showActions && actions.length > 0 && (
|
87 |
<motion.div
|
88 |
className="actions"
|
89 |
initial={{ height: 0 }}
|
@@ -92,6 +113,7 @@ export const Artifact = memo(({ messageId }: ArtifactProps) => {
|
|
92 |
transition={{ duration: 0.15 }}
|
93 |
>
|
94 |
<div className="bg-bolt-elements-artifacts-borderColor h-[1px]" />
|
|
|
95 |
<div className="p-5 text-left bg-bolt-elements-actions-background">
|
96 |
<ActionList actions={actions} />
|
97 |
</div>
|
|
|
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];
|
|
|
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 (
|
|
|
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>
|
|
|
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' }}
|
|
|
104 |
</AnimatePresence>
|
105 |
</div>
|
106 |
<AnimatePresence>
|
107 |
+
{artifact.type !== 'bundled' && showActions && actions.length > 0 && (
|
108 |
<motion.div
|
109 |
className="actions"
|
110 |
initial={{ height: 0 }}
|
|
|
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>
|
app/components/chat/BaseChat.module.scss
CHANGED
@@ -18,82 +18,6 @@
|
|
18 |
opacity: 1;
|
19 |
}
|
20 |
|
21 |
-
.RayContainer {
|
22 |
-
--gradient-opacity: 0.85;
|
23 |
-
--ray-gradient: radial-gradient(rgba(83, 196, 255, var(--gradient-opacity)) 0%, rgba(43, 166, 255, 0) 100%);
|
24 |
-
transition: opacity 0.25s linear;
|
25 |
-
position: fixed;
|
26 |
-
inset: 0;
|
27 |
-
pointer-events: none;
|
28 |
-
user-select: none;
|
29 |
-
}
|
30 |
-
|
31 |
-
.LightRayOne {
|
32 |
-
width: 480px;
|
33 |
-
height: 680px;
|
34 |
-
transform: rotate(80deg);
|
35 |
-
top: -540px;
|
36 |
-
left: 250px;
|
37 |
-
filter: blur(110px);
|
38 |
-
position: absolute;
|
39 |
-
border-radius: 100%;
|
40 |
-
background: var(--ray-gradient);
|
41 |
-
}
|
42 |
-
|
43 |
-
.LightRayTwo {
|
44 |
-
width: 110px;
|
45 |
-
height: 400px;
|
46 |
-
transform: rotate(-20deg);
|
47 |
-
top: -280px;
|
48 |
-
left: 350px;
|
49 |
-
mix-blend-mode: overlay;
|
50 |
-
opacity: 0.6;
|
51 |
-
filter: blur(60px);
|
52 |
-
position: absolute;
|
53 |
-
border-radius: 100%;
|
54 |
-
background: var(--ray-gradient);
|
55 |
-
}
|
56 |
-
|
57 |
-
.LightRayThree {
|
58 |
-
width: 400px;
|
59 |
-
height: 370px;
|
60 |
-
top: -350px;
|
61 |
-
left: 200px;
|
62 |
-
mix-blend-mode: overlay;
|
63 |
-
opacity: 0.6;
|
64 |
-
filter: blur(21px);
|
65 |
-
position: absolute;
|
66 |
-
border-radius: 100%;
|
67 |
-
background: var(--ray-gradient);
|
68 |
-
}
|
69 |
-
|
70 |
-
.LightRayFour {
|
71 |
-
position: absolute;
|
72 |
-
width: 330px;
|
73 |
-
height: 370px;
|
74 |
-
top: -330px;
|
75 |
-
left: 50px;
|
76 |
-
mix-blend-mode: overlay;
|
77 |
-
opacity: 0.5;
|
78 |
-
filter: blur(21px);
|
79 |
-
border-radius: 100%;
|
80 |
-
background: var(--ray-gradient);
|
81 |
-
}
|
82 |
-
|
83 |
-
.LightRayFive {
|
84 |
-
position: absolute;
|
85 |
-
width: 110px;
|
86 |
-
height: 400px;
|
87 |
-
transform: rotate(-40deg);
|
88 |
-
top: -280px;
|
89 |
-
left: -10px;
|
90 |
-
mix-blend-mode: overlay;
|
91 |
-
opacity: 0.8;
|
92 |
-
filter: blur(60px);
|
93 |
-
border-radius: 100%;
|
94 |
-
background: var(--ray-gradient);
|
95 |
-
}
|
96 |
-
|
97 |
.PromptEffectContainer {
|
98 |
--prompt-container-offset: 50px;
|
99 |
--prompt-line-stroke-width: 1px;
|
|
|
18 |
opacity: 1;
|
19 |
}
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
.PromptEffectContainer {
|
22 |
--prompt-container-offset: 50px;
|
23 |
--prompt-line-stroke-width: 1px;
|
app/components/chat/BaseChat.tsx
CHANGED
@@ -17,14 +17,15 @@ import Cookies from 'js-cookie';
|
|
17 |
import * as Tooltip from '@radix-ui/react-tooltip';
|
18 |
|
19 |
import styles from './BaseChat.module.scss';
|
20 |
-
import type { ProviderInfo } from '~/utils/types';
|
21 |
import { ExportChatButton } from '~/components/chat/chatExportAndImport/ExportChatButton';
|
22 |
import { ImportButtons } from '~/components/chat/chatExportAndImport/ImportButtons';
|
23 |
import { ExamplePrompts } from '~/components/chat/ExamplePrompts';
|
|
|
24 |
|
25 |
import FilePreview from './FilePreview';
|
26 |
import { ModelSelector } from '~/components/chat/ModelSelector';
|
27 |
import { SpeechRecognitionButton } from '~/components/chat/SpeechRecognition';
|
|
|
28 |
import { ScreenshotStateManager } from './ScreenshotStateManager';
|
29 |
|
30 |
const TEXTAREA_MIN_HEIGHT = 76;
|
@@ -45,6 +46,7 @@ interface BaseChatProps {
|
|
45 |
setModel?: (model: string) => void;
|
46 |
provider?: ProviderInfo;
|
47 |
setProvider?: (provider: ProviderInfo) => void;
|
|
|
48 |
handleStop?: () => void;
|
49 |
sendMessage?: (event: React.UIEvent, messageInput?: string) => void;
|
50 |
handleInputChange?: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;
|
@@ -70,6 +72,7 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
|
|
70 |
setModel,
|
71 |
provider,
|
72 |
setProvider,
|
|
|
73 |
input = '',
|
74 |
enhancingPrompt,
|
75 |
handleInputChange,
|
@@ -88,14 +91,30 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
|
|
88 |
ref,
|
89 |
) => {
|
90 |
const TEXTAREA_MAX_HEIGHT = chatStarted ? 400 : 200;
|
91 |
-
const [apiKeys, setApiKeys] = useState<Record<string, string>>({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
const [modelList, setModelList] = useState(MODEL_LIST);
|
93 |
const [isModelSettingsCollapsed, setIsModelSettingsCollapsed] = useState(false);
|
94 |
const [isListening, setIsListening] = useState(false);
|
95 |
const [recognition, setRecognition] = useState<SpeechRecognition | null>(null);
|
96 |
const [transcript, setTranscript] = useState('');
|
97 |
|
98 |
-
|
|
|
|
|
|
|
99 |
useEffect(() => {
|
100 |
// Load API keys from cookies on component mount
|
101 |
try {
|
@@ -115,7 +134,26 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
|
|
115 |
Cookies.remove('apiKeys');
|
116 |
}
|
117 |
|
118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
setModelList(modelList);
|
120 |
});
|
121 |
|
@@ -184,23 +222,6 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
|
|
184 |
}
|
185 |
};
|
186 |
|
187 |
-
const updateApiKey = (provider: string, key: string) => {
|
188 |
-
try {
|
189 |
-
const updatedApiKeys = { ...apiKeys, [provider]: key };
|
190 |
-
setApiKeys(updatedApiKeys);
|
191 |
-
|
192 |
-
// Save updated API keys to cookies with 30 day expiry and secure settings
|
193 |
-
Cookies.set('apiKeys', JSON.stringify(updatedApiKeys), {
|
194 |
-
expires: 30, // 30 days
|
195 |
-
secure: true, // Only send over HTTPS
|
196 |
-
sameSite: 'strict', // Protect against CSRF
|
197 |
-
path: '/', // Accessible across the site
|
198 |
-
});
|
199 |
-
} catch (error) {
|
200 |
-
console.error('Error saving API keys to cookies:', error);
|
201 |
-
}
|
202 |
-
};
|
203 |
-
|
204 |
const handleFileUpload = () => {
|
205 |
const input = document.createElement('input');
|
206 |
input.type = 'file';
|
@@ -256,24 +277,14 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
|
|
256 |
const baseChat = (
|
257 |
<div
|
258 |
ref={ref}
|
259 |
-
className={classNames(
|
260 |
-
styles.BaseChat,
|
261 |
-
'relative flex flex-col lg:flex-row h-full w-full overflow-hidden bg-bolt-elements-background-depth-1',
|
262 |
-
)}
|
263 |
data-chat-visible={showChat}
|
264 |
>
|
265 |
-
<div className={classNames(styles.RayContainer)}>
|
266 |
-
<div className={classNames(styles.LightRayOne)}></div>
|
267 |
-
<div className={classNames(styles.LightRayTwo)}></div>
|
268 |
-
<div className={classNames(styles.LightRayThree)}></div>
|
269 |
-
<div className={classNames(styles.LightRayFour)}></div>
|
270 |
-
<div className={classNames(styles.LightRayFive)}></div>
|
271 |
-
</div>
|
272 |
<ClientOnly>{() => <Menu />}</ClientOnly>
|
273 |
<div ref={scrollRef} className="flex flex-col lg:flex-row overflow-y-auto w-full h-full">
|
274 |
<div className={classNames(styles.Chat, 'flex flex-col flex-grow lg:min-w-[var(--chat-min-width)] h-full')}>
|
275 |
{!chatStarted && (
|
276 |
-
<div id="intro" className="mt-[
|
277 |
<h1 className="text-3xl lg:text-6xl font-bold text-bolt-elements-textPrimary mb-4 animate-fade-in">
|
278 |
Where ideas begin
|
279 |
</h1>
|
@@ -318,15 +329,15 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
|
|
318 |
gradientUnits="userSpaceOnUse"
|
319 |
gradientTransform="rotate(-45)"
|
320 |
>
|
321 |
-
<stop offset="0%" stopColor="#
|
322 |
-
<stop offset="40%" stopColor="#
|
323 |
-
<stop offset="50%" stopColor="#
|
324 |
-
<stop offset="100%" stopColor="#
|
325 |
</linearGradient>
|
326 |
<linearGradient id="shine-gradient">
|
327 |
<stop offset="0%" stopColor="white" stopOpacity="0%"></stop>
|
328 |
-
<stop offset="40%" stopColor="#
|
329 |
-
<stop offset="50%" stopColor="#
|
330 |
<stop offset="100%" stopColor="white" stopOpacity="0%"></stop>
|
331 |
</linearGradient>
|
332 |
</defs>
|
@@ -334,21 +345,6 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
|
|
334 |
<rect className={classNames(styles.PromptShine)} x="48" y="24" width="70" height="1"></rect>
|
335 |
</svg>
|
336 |
<div>
|
337 |
-
<div className="flex justify-between items-center mb-2">
|
338 |
-
<button
|
339 |
-
onClick={() => setIsModelSettingsCollapsed(!isModelSettingsCollapsed)}
|
340 |
-
className={classNames('flex items-center gap-2 p-2 rounded-lg transition-all', {
|
341 |
-
'bg-bolt-elements-item-backgroundAccent text-bolt-elements-item-contentAccent':
|
342 |
-
isModelSettingsCollapsed,
|
343 |
-
'bg-bolt-elements-item-backgroundDefault text-bolt-elements-item-contentDefault':
|
344 |
-
!isModelSettingsCollapsed,
|
345 |
-
})}
|
346 |
-
>
|
347 |
-
<div className={`i-ph:caret-${isModelSettingsCollapsed ? 'right' : 'down'} text-lg`} />
|
348 |
-
<span>Model Settings</span>
|
349 |
-
</button>
|
350 |
-
</div>
|
351 |
-
|
352 |
<div className={isModelSettingsCollapsed ? 'hidden' : ''}>
|
353 |
<ModelSelector
|
354 |
key={provider?.name + ':' + modelList.length}
|
@@ -357,14 +353,18 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
|
|
357 |
modelList={modelList}
|
358 |
provider={provider}
|
359 |
setProvider={setProvider}
|
360 |
-
providerList={PROVIDER_LIST}
|
361 |
apiKeys={apiKeys}
|
362 |
/>
|
363 |
-
{provider && (
|
364 |
<APIKeyManager
|
365 |
provider={provider}
|
366 |
apiKey={apiKeys[provider.name] || ''}
|
367 |
-
setApiKey={(key) =>
|
|
|
|
|
|
|
|
|
368 |
/>
|
369 |
)}
|
370 |
</div>
|
@@ -395,7 +395,7 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
|
|
395 |
<textarea
|
396 |
ref={textareaRef}
|
397 |
className={classNames(
|
398 |
-
'w-full pl-4 pt-4 pr-16
|
399 |
'transition-all duration-200',
|
400 |
'hover:border-bolt-elements-focus',
|
401 |
)}
|
@@ -462,6 +462,7 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
|
|
462 |
<SendButton
|
463 |
show={input.length > 0 || isStreaming || uploadedFiles.length > 0}
|
464 |
isStreaming={isStreaming}
|
|
|
465 |
onClick={(event) => {
|
466 |
if (isStreaming) {
|
467 |
handleStop?.();
|
@@ -512,6 +513,20 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
|
|
512 |
disabled={isStreaming}
|
513 |
/>
|
514 |
{chatStarted && <ClientOnly>{() => <ExportChatButton exportChat={exportChat} />}</ClientOnly>}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
515 |
</div>
|
516 |
{input.length > 3 ? (
|
517 |
<div className="text-xs text-bolt-elements-textTertiary">
|
@@ -524,7 +539,12 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
|
|
524 |
</div>
|
525 |
</div>
|
526 |
</div>
|
527 |
-
{!chatStarted &&
|
|
|
|
|
|
|
|
|
|
|
528 |
{!chatStarted &&
|
529 |
ExamplePrompts((event, messageInput) => {
|
530 |
if (isStreaming) {
|
|
|
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 |
|
31 |
const TEXTAREA_MIN_HEIGHT = 76;
|
|
|
46 |
setModel?: (model: string) => void;
|
47 |
provider?: ProviderInfo;
|
48 |
setProvider?: (provider: ProviderInfo) => void;
|
49 |
+
providerList?: ProviderInfo[];
|
50 |
handleStop?: () => void;
|
51 |
sendMessage?: (event: React.UIEvent, messageInput?: string) => void;
|
52 |
handleInputChange?: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;
|
|
|
72 |
setModel,
|
73 |
provider,
|
74 |
setProvider,
|
75 |
+
providerList,
|
76 |
input = '',
|
77 |
enhancingPrompt,
|
78 |
handleInputChange,
|
|
|
91 |
ref,
|
92 |
) => {
|
93 |
const TEXTAREA_MAX_HEIGHT = chatStarted ? 400 : 200;
|
94 |
+
const [apiKeys, setApiKeys] = useState<Record<string, string>>(() => {
|
95 |
+
const savedKeys = Cookies.get('apiKeys');
|
96 |
+
|
97 |
+
if (savedKeys) {
|
98 |
+
try {
|
99 |
+
return JSON.parse(savedKeys);
|
100 |
+
} catch (error) {
|
101 |
+
console.error('Failed to parse API keys from cookies:', error);
|
102 |
+
return {};
|
103 |
+
}
|
104 |
+
}
|
105 |
+
|
106 |
+
return {};
|
107 |
+
});
|
108 |
const [modelList, setModelList] = useState(MODEL_LIST);
|
109 |
const [isModelSettingsCollapsed, setIsModelSettingsCollapsed] = useState(false);
|
110 |
const [isListening, setIsListening] = useState(false);
|
111 |
const [recognition, setRecognition] = useState<SpeechRecognition | null>(null);
|
112 |
const [transcript, setTranscript] = useState('');
|
113 |
|
114 |
+
useEffect(() => {
|
115 |
+
console.log(transcript);
|
116 |
+
}, [transcript]);
|
117 |
+
|
118 |
useEffect(() => {
|
119 |
// Load API keys from cookies on component mount
|
120 |
try {
|
|
|
134 |
Cookies.remove('apiKeys');
|
135 |
}
|
136 |
|
137 |
+
let providerSettings: Record<string, IProviderSetting> | undefined = undefined;
|
138 |
+
|
139 |
+
try {
|
140 |
+
const savedProviderSettings = Cookies.get('providers');
|
141 |
+
|
142 |
+
if (savedProviderSettings) {
|
143 |
+
const parsedProviderSettings = JSON.parse(savedProviderSettings);
|
144 |
+
|
145 |
+
if (typeof parsedProviderSettings === 'object' && parsedProviderSettings !== null) {
|
146 |
+
providerSettings = parsedProviderSettings;
|
147 |
+
}
|
148 |
+
}
|
149 |
+
} catch (error) {
|
150 |
+
console.error('Error loading Provider Settings from cookies:', error);
|
151 |
+
|
152 |
+
// Clear invalid cookie data
|
153 |
+
Cookies.remove('providers');
|
154 |
+
}
|
155 |
+
|
156 |
+
initializeModelList(providerSettings).then((modelList) => {
|
157 |
setModelList(modelList);
|
158 |
});
|
159 |
|
|
|
222 |
}
|
223 |
};
|
224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
const handleFileUpload = () => {
|
226 |
const input = document.createElement('input');
|
227 |
input.type = 'file';
|
|
|
277 |
const baseChat = (
|
278 |
<div
|
279 |
ref={ref}
|
280 |
+
className={classNames(styles.BaseChat, 'relative flex h-full w-full overflow-hidden')}
|
|
|
|
|
|
|
281 |
data-chat-visible={showChat}
|
282 |
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
<ClientOnly>{() => <Menu />}</ClientOnly>
|
284 |
<div ref={scrollRef} className="flex flex-col lg:flex-row overflow-y-auto w-full h-full">
|
285 |
<div className={classNames(styles.Chat, 'flex flex-col flex-grow lg:min-w-[var(--chat-min-width)] h-full')}>
|
286 |
{!chatStarted && (
|
287 |
+
<div id="intro" className="mt-[16vh] max-w-chat mx-auto text-center px-4 lg:px-0">
|
288 |
<h1 className="text-3xl lg:text-6xl font-bold text-bolt-elements-textPrimary mb-4 animate-fade-in">
|
289 |
Where ideas begin
|
290 |
</h1>
|
|
|
329 |
gradientUnits="userSpaceOnUse"
|
330 |
gradientTransform="rotate(-45)"
|
331 |
>
|
332 |
+
<stop offset="0%" stopColor="#b44aff" stopOpacity="0%"></stop>
|
333 |
+
<stop offset="40%" stopColor="#b44aff" stopOpacity="80%"></stop>
|
334 |
+
<stop offset="50%" stopColor="#b44aff" stopOpacity="80%"></stop>
|
335 |
+
<stop offset="100%" stopColor="#b44aff" stopOpacity="0%"></stop>
|
336 |
</linearGradient>
|
337 |
<linearGradient id="shine-gradient">
|
338 |
<stop offset="0%" stopColor="white" stopOpacity="0%"></stop>
|
339 |
+
<stop offset="40%" stopColor="#ffffff" stopOpacity="80%"></stop>
|
340 |
+
<stop offset="50%" stopColor="#ffffff" stopOpacity="80%"></stop>
|
341 |
<stop offset="100%" stopColor="white" stopOpacity="0%"></stop>
|
342 |
</linearGradient>
|
343 |
</defs>
|
|
|
345 |
<rect className={classNames(styles.PromptShine)} x="48" y="24" width="70" height="1"></rect>
|
346 |
</svg>
|
347 |
<div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
348 |
<div className={isModelSettingsCollapsed ? 'hidden' : ''}>
|
349 |
<ModelSelector
|
350 |
key={provider?.name + ':' + modelList.length}
|
|
|
353 |
modelList={modelList}
|
354 |
provider={provider}
|
355 |
setProvider={setProvider}
|
356 |
+
providerList={providerList || PROVIDER_LIST}
|
357 |
apiKeys={apiKeys}
|
358 |
/>
|
359 |
+
{(providerList || []).length > 0 && provider && (
|
360 |
<APIKeyManager
|
361 |
provider={provider}
|
362 |
apiKey={apiKeys[provider.name] || ''}
|
363 |
+
setApiKey={(key) => {
|
364 |
+
const newApiKeys = { ...apiKeys, [provider.name]: key };
|
365 |
+
setApiKeys(newApiKeys);
|
366 |
+
Cookies.set('apiKeys', JSON.stringify(newApiKeys));
|
367 |
+
}}
|
368 |
/>
|
369 |
)}
|
370 |
</div>
|
|
|
395 |
<textarea
|
396 |
ref={textareaRef}
|
397 |
className={classNames(
|
398 |
+
'w-full pl-4 pt-4 pr-16 outline-none resize-none text-bolt-elements-textPrimary placeholder-bolt-elements-textTertiary bg-transparent text-sm',
|
399 |
'transition-all duration-200',
|
400 |
'hover:border-bolt-elements-focus',
|
401 |
)}
|
|
|
462 |
<SendButton
|
463 |
show={input.length > 0 || isStreaming || uploadedFiles.length > 0}
|
464 |
isStreaming={isStreaming}
|
465 |
+
disabled={!providerList || providerList.length === 0}
|
466 |
onClick={(event) => {
|
467 |
if (isStreaming) {
|
468 |
handleStop?.();
|
|
|
513 |
disabled={isStreaming}
|
514 |
/>
|
515 |
{chatStarted && <ClientOnly>{() => <ExportChatButton exportChat={exportChat} />}</ClientOnly>}
|
516 |
+
<IconButton
|
517 |
+
title="Model Settings"
|
518 |
+
className={classNames('transition-all flex items-center gap-1', {
|
519 |
+
'bg-bolt-elements-item-backgroundAccent text-bolt-elements-item-contentAccent':
|
520 |
+
isModelSettingsCollapsed,
|
521 |
+
'bg-bolt-elements-item-backgroundDefault text-bolt-elements-item-contentDefault':
|
522 |
+
!isModelSettingsCollapsed,
|
523 |
+
})}
|
524 |
+
onClick={() => setIsModelSettingsCollapsed(!isModelSettingsCollapsed)}
|
525 |
+
disabled={!providerList || providerList.length === 0}
|
526 |
+
>
|
527 |
+
<div className={`i-ph:caret-${isModelSettingsCollapsed ? 'right' : 'down'} text-lg`} />
|
528 |
+
{isModelSettingsCollapsed ? <span className="text-xs">{model}</span> : <span />}
|
529 |
+
</IconButton>
|
530 |
</div>
|
531 |
{input.length > 3 ? (
|
532 |
<div className="text-xs text-bolt-elements-textTertiary">
|
|
|
539 |
</div>
|
540 |
</div>
|
541 |
</div>
|
542 |
+
{!chatStarted && (
|
543 |
+
<div className="flex justify-center gap-2">
|
544 |
+
{ImportButtons(importChat)}
|
545 |
+
<GitCloneButton importChat={importChat} />
|
546 |
+
</div>
|
547 |
+
)}
|
548 |
{!chatStarted &&
|
549 |
ExamplePrompts((event, messageInput) => {
|
550 |
if (isStreaming) {
|
app/components/chat/Chat.client.tsx
CHANGED
@@ -17,8 +17,9 @@ 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 type { ProviderInfo } from '~/utils/types';
|
21 |
import { debounce } from '~/utils/debounce';
|
|
|
|
|
22 |
|
23 |
const toastAnimation = cssTransition({
|
24 |
enter: 'animated fadeInRight',
|
@@ -91,6 +92,7 @@ export const ChatImpl = memo(
|
|
91 |
const [chatStarted, setChatStarted] = useState(initialMessages.length > 0);
|
92 |
const [uploadedFiles, setUploadedFiles] = useState<File[]>([]); // Move here
|
93 |
const [imageDataList, setImageDataList] = useState<string[]>([]); // Move here
|
|
|
94 |
|
95 |
const [model, setModel] = useState(() => {
|
96 |
const savedModel = Cookies.get('selectedModel');
|
@@ -316,6 +318,7 @@ export const ChatImpl = memo(
|
|
316 |
setModel={handleModelChange}
|
317 |
provider={provider}
|
318 |
setProvider={handleProviderChange}
|
|
|
319 |
messageRef={messageRef}
|
320 |
scrollRef={scrollRef}
|
321 |
handleInputChange={(e) => {
|
|
|
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 |
|
24 |
const toastAnimation = cssTransition({
|
25 |
enter: 'animated fadeInRight',
|
|
|
92 |
const [chatStarted, setChatStarted] = useState(initialMessages.length > 0);
|
93 |
const [uploadedFiles, setUploadedFiles] = useState<File[]>([]); // Move here
|
94 |
const [imageDataList, setImageDataList] = useState<string[]>([]); // Move here
|
95 |
+
const { activeProviders } = useSettings();
|
96 |
|
97 |
const [model, setModel] = useState(() => {
|
98 |
const savedModel = Cookies.get('selectedModel');
|
|
|
318 |
setModel={handleModelChange}
|
319 |
provider={provider}
|
320 |
setProvider={handleProviderChange}
|
321 |
+
providerList={activeProviders}
|
322 |
messageRef={messageRef}
|
323 |
scrollRef={scrollRef}
|
324 |
handleInputChange={(e) => {
|
app/components/chat/GitCloneButton.tsx
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
7 |
+
const IGNORE_PATTERNS = [
|
8 |
+
'node_modules/**',
|
9 |
+
'.git/**',
|
10 |
+
'.github/**',
|
11 |
+
'.vscode/**',
|
12 |
+
'**/*.jpg',
|
13 |
+
'**/*.jpeg',
|
14 |
+
'**/*.png',
|
15 |
+
'dist/**',
|
16 |
+
'build/**',
|
17 |
+
'.next/**',
|
18 |
+
'coverage/**',
|
19 |
+
'.cache/**',
|
20 |
+
'.vscode/**',
|
21 |
+
'.idea/**',
|
22 |
+
'**/*.log',
|
23 |
+
'**/.DS_Store',
|
24 |
+
'**/npm-debug.log*',
|
25 |
+
'**/yarn-debug.log*',
|
26 |
+
'**/yarn-error.log*',
|
27 |
+
'**/*lock.json',
|
28 |
+
'**/*lock.yaml',
|
29 |
+
];
|
30 |
+
|
31 |
+
const ig = ignore().add(IGNORE_PATTERNS);
|
32 |
+
|
33 |
+
interface GitCloneButtonProps {
|
34 |
+
className?: string;
|
35 |
+
importChat?: (description: string, messages: Message[]) => Promise<void>;
|
36 |
+
}
|
37 |
+
|
38 |
+
export default function GitCloneButton({ importChat }: GitCloneButtonProps) {
|
39 |
+
const { ready, gitClone } = useGit();
|
40 |
+
const onClick = async (_e: any) => {
|
41 |
+
if (!ready) {
|
42 |
+
return;
|
43 |
+
}
|
44 |
+
|
45 |
+
const repoUrl = prompt('Enter the Git url');
|
46 |
+
|
47 |
+
if (repoUrl) {
|
48 |
+
const { workdir, data } = await gitClone(repoUrl);
|
49 |
+
|
50 |
+
if (importChat) {
|
51 |
+
const filePaths = Object.keys(data).filter((filePath) => !ig.ignores(filePath));
|
52 |
+
console.log(filePaths);
|
53 |
+
|
54 |
+
const textDecoder = new TextDecoder('utf-8');
|
55 |
+
|
56 |
+
// Convert files to common format for command detection
|
57 |
+
const fileContents = filePaths
|
58 |
+
.map((filePath) => {
|
59 |
+
const { data: content, encoding } = data[filePath];
|
60 |
+
return {
|
61 |
+
path: filePath,
|
62 |
+
content: encoding === 'utf8' ? content : content instanceof Uint8Array ? textDecoder.decode(content) : '',
|
63 |
+
};
|
64 |
+
})
|
65 |
+
.filter((f) => f.content);
|
66 |
+
|
67 |
+
// Detect and create commands message
|
68 |
+
const commands = await detectProjectCommands(fileContents);
|
69 |
+
const commandsMessage = createCommandsMessage(commands);
|
70 |
+
|
71 |
+
// Create files message
|
72 |
+
const filesMessage: Message = {
|
73 |
+
role: 'assistant',
|
74 |
+
content: `Cloning the repo ${repoUrl} into ${workdir}
|
75 |
+
<boltArtifact id="imported-files" title="Git Cloned Files" type="bundled">
|
76 |
+
${fileContents
|
77 |
+
.map(
|
78 |
+
(file) =>
|
79 |
+
`<boltAction type="file" filePath="${file.path}">
|
80 |
+
${file.content}
|
81 |
+
</boltAction>`,
|
82 |
+
)
|
83 |
+
.join('\n')}
|
84 |
+
</boltArtifact>`,
|
85 |
+
id: generateId(),
|
86 |
+
createdAt: new Date(),
|
87 |
+
};
|
88 |
+
|
89 |
+
const messages = [filesMessage];
|
90 |
+
|
91 |
+
if (commandsMessage) {
|
92 |
+
messages.push(commandsMessage);
|
93 |
+
}
|
94 |
+
|
95 |
+
await importChat(`Git Project:${repoUrl.split('/').slice(-1)[0]}`, messages);
|
96 |
+
}
|
97 |
+
}
|
98 |
+
};
|
99 |
+
|
100 |
+
return (
|
101 |
+
<button
|
102 |
+
onClick={onClick}
|
103 |
+
title="Clone a Git Repo"
|
104 |
+
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"
|
105 |
+
>
|
106 |
+
<span className="i-ph:git-branch" />
|
107 |
+
Clone a Git Repo
|
108 |
+
</button>
|
109 |
+
);
|
110 |
+
}
|
app/components/chat/ImportFolderButton.tsx
CHANGED
@@ -1,102 +1,98 @@
|
|
1 |
-
import React from 'react';
|
2 |
import type { Message } from 'ai';
|
3 |
import { toast } from 'react-toastify';
|
4 |
-
import
|
|
|
|
|
5 |
|
6 |
interface ImportFolderButtonProps {
|
7 |
className?: string;
|
8 |
importChat?: (description: string, messages: Message[]) => Promise<void>;
|
9 |
}
|
10 |
|
11 |
-
|
12 |
-
const
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
const ig = ignore().add(IGNORE_PATTERNS);
|
30 |
-
const generateId = () => Math.random().toString(36).substring(2, 15);
|
31 |
-
|
32 |
-
const isBinaryFile = async (file: File): Promise<boolean> => {
|
33 |
-
const chunkSize = 1024; // Read the first 1 KB of the file
|
34 |
-
const buffer = new Uint8Array(await file.slice(0, chunkSize).arrayBuffer());
|
35 |
-
|
36 |
-
for (let i = 0; i < buffer.length; i++) {
|
37 |
-
const byte = buffer[i];
|
38 |
-
|
39 |
-
if (byte === 0 || (byte < 32 && byte !== 9 && byte !== 10 && byte !== 13)) {
|
40 |
-
return true; // Found a binary character
|
41 |
}
|
42 |
-
}
|
43 |
|
44 |
-
|
45 |
-
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
});
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
createdAt: new Date(),
|
94 |
-
};
|
95 |
-
|
96 |
-
const description = `Folder Import: ${files[0].webkitRelativePath.split('/')[0]}`;
|
97 |
-
|
98 |
-
if (importChat) {
|
99 |
-
await importChat(description, [userMessage, message]);
|
100 |
}
|
101 |
};
|
102 |
|
@@ -108,46 +104,8 @@ ${fileArtifacts.join('\n\n')}
|
|
108 |
className="hidden"
|
109 |
webkitdirectory=""
|
110 |
directory=""
|
111 |
-
onChange={
|
112 |
-
|
113 |
-
const filteredFiles = allFiles.filter((file) => shouldIncludeFile(file.webkitRelativePath));
|
114 |
-
|
115 |
-
if (filteredFiles.length === 0) {
|
116 |
-
toast.error('No files found in the selected folder');
|
117 |
-
return;
|
118 |
-
}
|
119 |
-
|
120 |
-
try {
|
121 |
-
const fileChecks = await Promise.all(
|
122 |
-
filteredFiles.map(async (file) => ({
|
123 |
-
file,
|
124 |
-
isBinary: await isBinaryFile(file),
|
125 |
-
})),
|
126 |
-
);
|
127 |
-
|
128 |
-
const textFiles = fileChecks.filter((f) => !f.isBinary).map((f) => f.file);
|
129 |
-
const binaryFilePaths = fileChecks
|
130 |
-
.filter((f) => f.isBinary)
|
131 |
-
.map((f) => f.file.webkitRelativePath.split('/').slice(1).join('/'));
|
132 |
-
|
133 |
-
if (textFiles.length === 0) {
|
134 |
-
toast.error('No text files found in the selected folder');
|
135 |
-
return;
|
136 |
-
}
|
137 |
-
|
138 |
-
if (binaryFilePaths.length > 0) {
|
139 |
-
toast.info(`Skipping ${binaryFilePaths.length} binary files`);
|
140 |
-
}
|
141 |
-
|
142 |
-
await createChatFromFolder(textFiles, binaryFilePaths);
|
143 |
-
} catch (error) {
|
144 |
-
console.error('Failed to import folder:', error);
|
145 |
-
toast.error('Failed to import folder');
|
146 |
-
}
|
147 |
-
|
148 |
-
e.target.value = ''; // Reset file input
|
149 |
-
}}
|
150 |
-
{...({} as any)} // if removed webkitdirectory will throw errors as unknow attribute
|
151 |
/>
|
152 |
<button
|
153 |
onClick={() => {
|
@@ -155,9 +113,10 @@ ${fileArtifacts.join('\n\n')}
|
|
155 |
input?.click();
|
156 |
}}
|
157 |
className={className}
|
|
|
158 |
>
|
159 |
<div className="i-ph:upload-simple" />
|
160 |
-
Import Folder
|
161 |
</button>
|
162 |
</>
|
163 |
);
|
|
|
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 |
+
if (allFiles.length > MAX_FILES) {
|
20 |
+
const error = new Error(`Too many files: ${allFiles.length}`);
|
21 |
+
logStore.logError('File import failed - too many files', error, {
|
22 |
+
fileCount: allFiles.length,
|
23 |
+
maxFiles: MAX_FILES,
|
24 |
+
});
|
25 |
+
toast.error(
|
26 |
+
`This folder contains ${allFiles.length.toLocaleString()} files. This product is not yet optimized for very large projects. Please select a folder with fewer than ${MAX_FILES.toLocaleString()} files.`,
|
27 |
+
);
|
28 |
+
|
29 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
}
|
|
|
31 |
|
32 |
+
const folderName = allFiles[0]?.webkitRelativePath.split('/')[0] || 'Unknown Folder';
|
33 |
+
setIsLoading(true);
|
34 |
|
35 |
+
const loadingToast = toast.loading(`Importing ${folderName}...`);
|
36 |
+
|
37 |
+
try {
|
38 |
+
const filteredFiles = allFiles.filter((file) => shouldIncludeFile(file.webkitRelativePath));
|
39 |
+
|
40 |
+
if (filteredFiles.length === 0) {
|
41 |
+
const error = new Error('No valid files found');
|
42 |
+
logStore.logError('File import failed - no valid files', error, { folderName });
|
43 |
+
toast.error('No files found in the selected folder');
|
44 |
|
45 |
+
return;
|
46 |
+
}
|
47 |
+
|
48 |
+
const fileChecks = await Promise.all(
|
49 |
+
filteredFiles.map(async (file) => ({
|
50 |
+
file,
|
51 |
+
isBinary: await isBinaryFile(file),
|
52 |
+
})),
|
53 |
+
);
|
54 |
+
|
55 |
+
const textFiles = fileChecks.filter((f) => !f.isBinary).map((f) => f.file);
|
56 |
+
const binaryFilePaths = fileChecks
|
57 |
+
.filter((f) => f.isBinary)
|
58 |
+
.map((f) => f.file.webkitRelativePath.split('/').slice(1).join('/'));
|
59 |
+
|
60 |
+
if (textFiles.length === 0) {
|
61 |
+
const error = new Error('No text files found');
|
62 |
+
logStore.logError('File import failed - no text files', error, { folderName });
|
63 |
+
toast.error('No text files found in the selected folder');
|
64 |
+
|
65 |
+
return;
|
66 |
+
}
|
67 |
+
|
68 |
+
if (binaryFilePaths.length > 0) {
|
69 |
+
logStore.logWarning(`Skipping binary files during import`, {
|
70 |
+
folderName,
|
71 |
+
binaryCount: binaryFilePaths.length,
|
72 |
});
|
73 |
+
toast.info(`Skipping ${binaryFilePaths.length} binary files`);
|
74 |
+
}
|
75 |
+
|
76 |
+
const messages = await createChatFromFolder(textFiles, binaryFilePaths, folderName);
|
77 |
+
|
78 |
+
if (importChat) {
|
79 |
+
await importChat(folderName, [...messages]);
|
80 |
+
}
|
81 |
+
|
82 |
+
logStore.logSystem('Folder imported successfully', {
|
83 |
+
folderName,
|
84 |
+
textFileCount: textFiles.length,
|
85 |
+
binaryFileCount: binaryFilePaths.length,
|
86 |
+
});
|
87 |
+
toast.success('Folder imported successfully');
|
88 |
+
} catch (error) {
|
89 |
+
logStore.logError('Failed to import folder', error, { folderName });
|
90 |
+
console.error('Failed to import folder:', error);
|
91 |
+
toast.error('Failed to import folder');
|
92 |
+
} finally {
|
93 |
+
setIsLoading(false);
|
94 |
+
toast.dismiss(loadingToast);
|
95 |
+
e.target.value = ''; // Reset file input
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
}
|
97 |
};
|
98 |
|
|
|
104 |
className="hidden"
|
105 |
webkitdirectory=""
|
106 |
directory=""
|
107 |
+
onChange={handleFileChange}
|
108 |
+
{...({} as any)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
/>
|
110 |
<button
|
111 |
onClick={() => {
|
|
|
113 |
input?.click();
|
114 |
}}
|
115 |
className={className}
|
116 |
+
disabled={isLoading}
|
117 |
>
|
118 |
<div className="i-ph:upload-simple" />
|
119 |
+
{isLoading ? 'Importing...' : 'Import Folder'}
|
120 |
</button>
|
121 |
</>
|
122 |
);
|
app/components/chat/ModelSelector.tsx
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import type { ProviderInfo } from '~/types/model';
|
2 |
import type { ModelInfo } from '~/utils/types';
|
|
|
3 |
|
4 |
interface ModelSelectorProps {
|
5 |
model?: string;
|
@@ -19,6 +20,39 @@ export const ModelSelector = ({
|
|
19 |
modelList,
|
20 |
providerList,
|
21 |
}: ModelSelectorProps) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
return (
|
23 |
<div className="mb-2 flex gap-2 flex-col sm:flex-row">
|
24 |
<select
|
@@ -52,8 +86,8 @@ export const ModelSelector = ({
|
|
52 |
>
|
53 |
{[...modelList]
|
54 |
.filter((e) => e.provider == provider?.name && e.name)
|
55 |
-
.map((modelOption) => (
|
56 |
-
<option key={
|
57 |
{modelOption.label}
|
58 |
</option>
|
59 |
))}
|
|
|
1 |
import type { ProviderInfo } from '~/types/model';
|
2 |
import type { ModelInfo } from '~/utils/types';
|
3 |
+
import { useEffect } from 'react';
|
4 |
|
5 |
interface ModelSelectorProps {
|
6 |
model?: string;
|
|
|
20 |
modelList,
|
21 |
providerList,
|
22 |
}: ModelSelectorProps) => {
|
23 |
+
// Load enabled providers from cookies
|
24 |
+
|
25 |
+
// Update enabled providers when cookies change
|
26 |
+
useEffect(() => {
|
27 |
+
// If current provider is disabled, switch to first enabled provider
|
28 |
+
if (providerList.length == 0) {
|
29 |
+
return;
|
30 |
+
}
|
31 |
+
|
32 |
+
if (provider && !providerList.map((p) => p.name).includes(provider.name)) {
|
33 |
+
const firstEnabledProvider = providerList[0];
|
34 |
+
setProvider?.(firstEnabledProvider);
|
35 |
+
|
36 |
+
// Also update the model to the first available one for the new provider
|
37 |
+
const firstModel = modelList.find((m) => m.provider === firstEnabledProvider.name);
|
38 |
+
|
39 |
+
if (firstModel) {
|
40 |
+
setModel?.(firstModel.name);
|
41 |
+
}
|
42 |
+
}
|
43 |
+
}, [providerList, provider, setProvider, modelList, setModel]);
|
44 |
+
|
45 |
+
if (providerList.length === 0) {
|
46 |
+
return (
|
47 |
+
<div className="mb-2 p-4 rounded-lg border border-bolt-elements-borderColor bg-bolt-elements-prompt-background text-bolt-elements-textPrimary">
|
48 |
+
<p className="text-center">
|
49 |
+
No providers are currently enabled. Please enable at least one provider in the settings to start using the
|
50 |
+
chat.
|
51 |
+
</p>
|
52 |
+
</div>
|
53 |
+
);
|
54 |
+
}
|
55 |
+
|
56 |
return (
|
57 |
<div className="mb-2 flex gap-2 flex-col sm:flex-row">
|
58 |
<select
|
|
|
86 |
>
|
87 |
{[...modelList]
|
88 |
.filter((e) => e.provider == provider?.name && e.name)
|
89 |
+
.map((modelOption, index) => (
|
90 |
+
<option key={index} value={modelOption.name}>
|
91 |
{modelOption.label}
|
92 |
</option>
|
93 |
))}
|
app/components/chat/SendButton.client.tsx
CHANGED
@@ -3,25 +3,30 @@ import { AnimatePresence, cubicBezier, motion } from 'framer-motion';
|
|
3 |
interface SendButtonProps {
|
4 |
show: boolean;
|
5 |
isStreaming?: boolean;
|
|
|
6 |
onClick?: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
7 |
onImagesSelected?: (images: File[]) => void;
|
8 |
}
|
9 |
|
10 |
const customEasingFn = cubicBezier(0.4, 0, 0.2, 1);
|
11 |
|
12 |
-
export const SendButton = ({ show, isStreaming, onClick }: SendButtonProps) => {
|
13 |
return (
|
14 |
<AnimatePresence>
|
15 |
{show ? (
|
16 |
<motion.button
|
17 |
-
className="absolute flex justify-center items-center top-[18px] right-[22px] p-1 bg-accent-500 hover:brightness-94 color-white rounded-md w-[34px] h-[34px] transition-theme"
|
18 |
transition={{ ease: customEasingFn, duration: 0.17 }}
|
19 |
initial={{ opacity: 0, y: 10 }}
|
20 |
animate={{ opacity: 1, y: 0 }}
|
21 |
exit={{ opacity: 0, y: 10 }}
|
|
|
22 |
onClick={(event) => {
|
23 |
event.preventDefault();
|
24 |
-
|
|
|
|
|
|
|
25 |
}}
|
26 |
>
|
27 |
<div className="text-lg">
|
|
|
3 |
interface SendButtonProps {
|
4 |
show: boolean;
|
5 |
isStreaming?: boolean;
|
6 |
+
disabled?: boolean;
|
7 |
onClick?: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
8 |
onImagesSelected?: (images: File[]) => void;
|
9 |
}
|
10 |
|
11 |
const customEasingFn = cubicBezier(0.4, 0, 0.2, 1);
|
12 |
|
13 |
+
export const SendButton = ({ show, isStreaming, disabled, onClick }: SendButtonProps) => {
|
14 |
return (
|
15 |
<AnimatePresence>
|
16 |
{show ? (
|
17 |
<motion.button
|
18 |
+
className="absolute flex justify-center items-center top-[18px] right-[22px] p-1 bg-accent-500 hover:brightness-94 color-white rounded-md w-[34px] h-[34px] transition-theme disabled:opacity-50 disabled:cursor-not-allowed"
|
19 |
transition={{ ease: customEasingFn, duration: 0.17 }}
|
20 |
initial={{ opacity: 0, y: 10 }}
|
21 |
animate={{ opacity: 1, y: 0 }}
|
22 |
exit={{ opacity: 0, y: 10 }}
|
23 |
+
disabled={disabled}
|
24 |
onClick={(event) => {
|
25 |
event.preventDefault();
|
26 |
+
|
27 |
+
if (!disabled) {
|
28 |
+
onClick?.(event);
|
29 |
+
}
|
30 |
}}
|
31 |
>
|
32 |
<div className="text-lg">
|
app/components/chat/chatExportAndImport/ImportButtons.tsx
CHANGED
@@ -1,11 +1,10 @@
|
|
1 |
import type { Message } from 'ai';
|
2 |
import { toast } from 'react-toastify';
|
3 |
-
import React from 'react';
|
4 |
import { ImportFolderButton } from '~/components/chat/ImportFolderButton';
|
5 |
|
6 |
export function ImportButtons(importChat: ((description: string, messages: Message[]) => Promise<void>) | undefined) {
|
7 |
return (
|
8 |
-
<div className="flex flex-col items-center justify-center
|
9 |
<input
|
10 |
type="file"
|
11 |
id="chat-import"
|
|
|
1 |
import type { Message } from 'ai';
|
2 |
import { toast } from 'react-toastify';
|
|
|
3 |
import { ImportFolderButton } from '~/components/chat/ImportFolderButton';
|
4 |
|
5 |
export function ImportButtons(importChat: ((description: string, messages: Message[]) => Promise<void>) | undefined) {
|
6 |
return (
|
7 |
+
<div className="flex flex-col items-center justify-center w-auto">
|
8 |
<input
|
9 |
type="file"
|
10 |
id="chat-import"
|
app/components/editor/codemirror/languages.ts
CHANGED
@@ -1,6 +1,13 @@
|
|
1 |
import { LanguageDescription } from '@codemirror/language';
|
2 |
|
3 |
export const supportedLanguages = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
LanguageDescription.of({
|
5 |
name: 'TS',
|
6 |
extensions: ['ts'],
|
|
|
1 |
import { LanguageDescription } from '@codemirror/language';
|
2 |
|
3 |
export const supportedLanguages = [
|
4 |
+
LanguageDescription.of({
|
5 |
+
name: 'VUE',
|
6 |
+
extensions: ['vue'],
|
7 |
+
async load() {
|
8 |
+
return import('@codemirror/lang-vue').then((module) => module.vue());
|
9 |
+
},
|
10 |
+
}),
|
11 |
LanguageDescription.of({
|
12 |
name: 'TS',
|
13 |
extensions: ['ts'],
|
app/components/git/GitUrlImport.client.tsx
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { useSearchParams } from '@remix-run/react';
|
2 |
+
import { generateId, type Message } from 'ai';
|
3 |
+
import ignore from 'ignore';
|
4 |
+
import { useEffect, useState } from 'react';
|
5 |
+
import { ClientOnly } from 'remix-utils/client-only';
|
6 |
+
import { BaseChat } from '~/components/chat/BaseChat';
|
7 |
+
import { Chat } from '~/components/chat/Chat.client';
|
8 |
+
import { useGit } from '~/lib/hooks/useGit';
|
9 |
+
import { useChatHistory } from '~/lib/persistence';
|
10 |
+
import { createCommandsMessage, detectProjectCommands } from '~/utils/projectCommands';
|
11 |
+
|
12 |
+
const IGNORE_PATTERNS = [
|
13 |
+
'node_modules/**',
|
14 |
+
'.git/**',
|
15 |
+
'.github/**',
|
16 |
+
'.vscode/**',
|
17 |
+
'**/*.jpg',
|
18 |
+
'**/*.jpeg',
|
19 |
+
'**/*.png',
|
20 |
+
'dist/**',
|
21 |
+
'build/**',
|
22 |
+
'.next/**',
|
23 |
+
'coverage/**',
|
24 |
+
'.cache/**',
|
25 |
+
'.vscode/**',
|
26 |
+
'.idea/**',
|
27 |
+
'**/*.log',
|
28 |
+
'**/.DS_Store',
|
29 |
+
'**/npm-debug.log*',
|
30 |
+
'**/yarn-debug.log*',
|
31 |
+
'**/yarn-error.log*',
|
32 |
+
'**/*lock.json',
|
33 |
+
'**/*lock.yaml',
|
34 |
+
];
|
35 |
+
|
36 |
+
export function GitUrlImport() {
|
37 |
+
const [searchParams] = useSearchParams();
|
38 |
+
const { ready: historyReady, importChat } = useChatHistory();
|
39 |
+
const { ready: gitReady, gitClone } = useGit();
|
40 |
+
const [imported, setImported] = useState(false);
|
41 |
+
|
42 |
+
const importRepo = async (repoUrl?: string) => {
|
43 |
+
if (!gitReady && !historyReady) {
|
44 |
+
return;
|
45 |
+
}
|
46 |
+
|
47 |
+
if (repoUrl) {
|
48 |
+
const ig = ignore().add(IGNORE_PATTERNS);
|
49 |
+
const { workdir, data } = await gitClone(repoUrl);
|
50 |
+
|
51 |
+
if (importChat) {
|
52 |
+
const filePaths = Object.keys(data).filter((filePath) => !ig.ignores(filePath));
|
53 |
+
|
54 |
+
const textDecoder = new TextDecoder('utf-8');
|
55 |
+
|
56 |
+
// Convert files to common format for command detection
|
57 |
+
const fileContents = filePaths
|
58 |
+
.map((filePath) => {
|
59 |
+
const { data: content, encoding } = data[filePath];
|
60 |
+
return {
|
61 |
+
path: filePath,
|
62 |
+
content: encoding === 'utf8' ? content : content instanceof Uint8Array ? textDecoder.decode(content) : '',
|
63 |
+
};
|
64 |
+
})
|
65 |
+
.filter((f) => f.content);
|
66 |
+
|
67 |
+
// Detect and create commands message
|
68 |
+
const commands = await detectProjectCommands(fileContents);
|
69 |
+
const commandsMessage = createCommandsMessage(commands);
|
70 |
+
|
71 |
+
// Create files message
|
72 |
+
const filesMessage: Message = {
|
73 |
+
role: 'assistant',
|
74 |
+
content: `Cloning the repo ${repoUrl} into ${workdir}
|
75 |
+
<boltArtifact id="imported-files" title="Git Cloned Files" type="bundled">
|
76 |
+
${fileContents
|
77 |
+
.map(
|
78 |
+
(file) =>
|
79 |
+
`<boltAction type="file" filePath="${file.path}">
|
80 |
+
${file.content}
|
81 |
+
</boltAction>`,
|
82 |
+
)
|
83 |
+
.join('\n')}
|
84 |
+
</boltArtifact>`,
|
85 |
+
id: generateId(),
|
86 |
+
createdAt: new Date(),
|
87 |
+
};
|
88 |
+
|
89 |
+
const messages = [filesMessage];
|
90 |
+
|
91 |
+
if (commandsMessage) {
|
92 |
+
messages.push(commandsMessage);
|
93 |
+
}
|
94 |
+
|
95 |
+
await importChat(`Git Project:${repoUrl.split('/').slice(-1)[0]}`, messages);
|
96 |
+
}
|
97 |
+
}
|
98 |
+
};
|
99 |
+
|
100 |
+
useEffect(() => {
|
101 |
+
if (!historyReady || !gitReady || imported) {
|
102 |
+
return;
|
103 |
+
}
|
104 |
+
|
105 |
+
const url = searchParams.get('url');
|
106 |
+
|
107 |
+
if (!url) {
|
108 |
+
window.location.href = '/';
|
109 |
+
return;
|
110 |
+
}
|
111 |
+
|
112 |
+
importRepo(url);
|
113 |
+
setImported(true);
|
114 |
+
}, [searchParams, historyReady, gitReady, imported]);
|
115 |
+
|
116 |
+
return <ClientOnly fallback={<BaseChat />}>{() => <Chat />}</ClientOnly>;
|
117 |
+
}
|
app/components/header/Header.tsx
CHANGED
@@ -10,18 +10,17 @@ export function Header() {
|
|
10 |
|
11 |
return (
|
12 |
<header
|
13 |
-
className={classNames(
|
14 |
-
'
|
15 |
-
|
16 |
-
|
17 |
-
'border-bolt-elements-borderColor': chat.started,
|
18 |
-
},
|
19 |
-
)}
|
20 |
>
|
21 |
<div className="flex items-center gap-2 z-logo text-bolt-elements-textPrimary cursor-pointer">
|
22 |
<div className="i-ph:sidebar-simple-duotone text-xl" />
|
23 |
<a href="/" className="text-2xl font-semibold text-accent flex items-center">
|
24 |
-
<span className="i-bolt:logo-text?mask w-[46px] inline-block" />
|
|
|
|
|
25 |
</a>
|
26 |
</div>
|
27 |
{chat.started && ( // Display ChatDescription and HeaderActionButtons only when the chat has started.
|
|
|
10 |
|
11 |
return (
|
12 |
<header
|
13 |
+
className={classNames('flex items-center p-5 border-b h-[var(--header-height)]', {
|
14 |
+
'border-transparent': !chat.started,
|
15 |
+
'border-bolt-elements-borderColor': chat.started,
|
16 |
+
})}
|
|
|
|
|
|
|
17 |
>
|
18 |
<div className="flex items-center gap-2 z-logo text-bolt-elements-textPrimary cursor-pointer">
|
19 |
<div className="i-ph:sidebar-simple-duotone text-xl" />
|
20 |
<a href="/" className="text-2xl font-semibold text-accent flex items-center">
|
21 |
+
{/* <span className="i-bolt:logo-text?mask w-[46px] inline-block" /> */}
|
22 |
+
<img src="/logo-light-styled.png" alt="logo" className="w-[90px] inline-block dark:hidden" />
|
23 |
+
<img src="/logo-dark-styled.png" alt="logo" className="w-[90px] inline-block hidden dark:block" />
|
24 |
</a>
|
25 |
</div>
|
26 |
{chat.started && ( // Display ChatDescription and HeaderActionButtons only when the chat has started.
|
app/components/settings/Settings.module.scss
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.settings-tabs {
|
2 |
+
button {
|
3 |
+
width: 100%;
|
4 |
+
display: flex;
|
5 |
+
align-items: center;
|
6 |
+
gap: 0.5rem;
|
7 |
+
padding: 0.75rem 1rem;
|
8 |
+
border-radius: 0.5rem;
|
9 |
+
text-align: left;
|
10 |
+
font-size: 0.875rem;
|
11 |
+
transition: all 0.2s;
|
12 |
+
margin-bottom: 0.5rem;
|
13 |
+
|
14 |
+
&.active {
|
15 |
+
background: var(--bolt-elements-button-primary-background);
|
16 |
+
color: var(--bolt-elements-textPrimary);
|
17 |
+
}
|
18 |
+
|
19 |
+
&:not(.active) {
|
20 |
+
background: var(--bolt-elements-bg-depth-3);
|
21 |
+
color: var(--bolt-elements-textPrimary);
|
22 |
+
|
23 |
+
&:hover {
|
24 |
+
background: var(--bolt-elements-button-primary-backgroundHover);
|
25 |
+
}
|
26 |
+
}
|
27 |
+
}
|
28 |
+
}
|
29 |
+
|
30 |
+
.settings-button {
|
31 |
+
background-color: var(--bolt-elements-button-primary-background);
|
32 |
+
color: var(--bolt-elements-textPrimary);
|
33 |
+
border-radius: 0.5rem;
|
34 |
+
padding: 0.5rem 1rem;
|
35 |
+
transition: background-color 0.2s;
|
36 |
+
|
37 |
+
&:hover {
|
38 |
+
background-color: var(--bolt-elements-button-primary-backgroundHover);
|
39 |
+
}
|
40 |
+
}
|
41 |
+
|
42 |
+
.settings-danger-area {
|
43 |
+
background-color: transparent;
|
44 |
+
color: var(--bolt-elements-textPrimary);
|
45 |
+
border-radius: 0.5rem;
|
46 |
+
padding: 1rem;
|
47 |
+
margin-bottom: 1rem;
|
48 |
+
border-style: solid;
|
49 |
+
border-color: var(--bolt-elements-button-danger-backgroundHover);
|
50 |
+
border-width: thin;
|
51 |
+
|
52 |
+
button {
|
53 |
+
background-color: var(--bolt-elements-button-danger-background);
|
54 |
+
color: var(--bolt-elements-button-danger-text);
|
55 |
+
border-radius: 0.5rem;
|
56 |
+
padding: 0.5rem 1rem;
|
57 |
+
transition: background-color 0.2s;
|
58 |
+
|
59 |
+
&:hover {
|
60 |
+
background-color: var(--bolt-elements-button-danger-backgroundHover);
|
61 |
+
}
|
62 |
+
}
|
63 |
+
}
|
app/components/settings/SettingsWindow.tsx
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import * as RadixDialog from '@radix-ui/react-dialog';
|
2 |
+
import { motion } from 'framer-motion';
|
3 |
+
import { useState, type ReactElement } from 'react';
|
4 |
+
import { classNames } from '~/utils/classNames';
|
5 |
+
import { DialogTitle, dialogVariants, dialogBackdropVariants } from '~/components/ui/Dialog';
|
6 |
+
import { IconButton } from '~/components/ui/IconButton';
|
7 |
+
import styles from './Settings.module.scss';
|
8 |
+
import ChatHistoryTab from './chat-history/ChatHistoryTab';
|
9 |
+
import ProvidersTab from './providers/ProvidersTab';
|
10 |
+
import { useSettings } from '~/lib/hooks/useSettings';
|
11 |
+
import FeaturesTab from './features/FeaturesTab';
|
12 |
+
import DebugTab from './debug/DebugTab';
|
13 |
+
import EventLogsTab from './event-logs/EventLogsTab';
|
14 |
+
import ConnectionsTab from './connections/ConnectionsTab';
|
15 |
+
|
16 |
+
interface SettingsProps {
|
17 |
+
open: boolean;
|
18 |
+
onClose: () => void;
|
19 |
+
}
|
20 |
+
|
21 |
+
type TabType = 'chat-history' | 'providers' | 'features' | 'debug' | 'event-logs' | 'connection';
|
22 |
+
|
23 |
+
export const SettingsWindow = ({ open, onClose }: SettingsProps) => {
|
24 |
+
const { debug, eventLogs } = useSettings();
|
25 |
+
const [activeTab, setActiveTab] = useState<TabType>('chat-history');
|
26 |
+
|
27 |
+
const tabs: { id: TabType; label: string; icon: string; component?: ReactElement }[] = [
|
28 |
+
{ id: 'chat-history', label: 'Chat History', icon: 'i-ph:book', component: <ChatHistoryTab /> },
|
29 |
+
{ id: 'providers', label: 'Providers', icon: 'i-ph:key', component: <ProvidersTab /> },
|
30 |
+
{ id: 'features', label: 'Features', icon: 'i-ph:star', component: <FeaturesTab /> },
|
31 |
+
{ id: 'connection', label: 'Connection', icon: 'i-ph:link', component: <ConnectionsTab /> },
|
32 |
+
...(debug
|
33 |
+
? [
|
34 |
+
{
|
35 |
+
id: 'debug' as TabType,
|
36 |
+
label: 'Debug Tab',
|
37 |
+
icon: 'i-ph:bug',
|
38 |
+
component: <DebugTab />,
|
39 |
+
},
|
40 |
+
]
|
41 |
+
: []),
|
42 |
+
...(eventLogs
|
43 |
+
? [
|
44 |
+
{
|
45 |
+
id: 'event-logs' as TabType,
|
46 |
+
label: 'Event Logs',
|
47 |
+
icon: 'i-ph:list-bullets',
|
48 |
+
component: <EventLogsTab />,
|
49 |
+
},
|
50 |
+
]
|
51 |
+
: []),
|
52 |
+
];
|
53 |
+
|
54 |
+
return (
|
55 |
+
<RadixDialog.Root open={open}>
|
56 |
+
<RadixDialog.Portal>
|
57 |
+
<RadixDialog.Overlay asChild onClick={onClose}>
|
58 |
+
<motion.div
|
59 |
+
className="bg-black/50 fixed inset-0 z-max backdrop-blur-sm"
|
60 |
+
initial="closed"
|
61 |
+
animate="open"
|
62 |
+
exit="closed"
|
63 |
+
variants={dialogBackdropVariants}
|
64 |
+
/>
|
65 |
+
</RadixDialog.Overlay>
|
66 |
+
<RadixDialog.Content asChild>
|
67 |
+
<motion.div
|
68 |
+
className="fixed top-[50%] left-[50%] z-max h-[85vh] w-[90vw] max-w-[900px] translate-x-[-50%] translate-y-[-50%] border border-bolt-elements-borderColor rounded-lg shadow-lg focus:outline-none overflow-hidden"
|
69 |
+
initial="closed"
|
70 |
+
animate="open"
|
71 |
+
exit="closed"
|
72 |
+
variants={dialogVariants}
|
73 |
+
>
|
74 |
+
<div className="flex h-full">
|
75 |
+
<div
|
76 |
+
className={classNames(
|
77 |
+
'w-48 border-r border-bolt-elements-borderColor bg-bolt-elements-background-depth-1 p-4 flex flex-col justify-between',
|
78 |
+
styles['settings-tabs'],
|
79 |
+
)}
|
80 |
+
>
|
81 |
+
<DialogTitle className="flex-shrink-0 text-lg font-semibold text-bolt-elements-textPrimary mb-2">
|
82 |
+
Settings
|
83 |
+
</DialogTitle>
|
84 |
+
{tabs.map((tab) => (
|
85 |
+
<button
|
86 |
+
key={tab.id}
|
87 |
+
onClick={() => setActiveTab(tab.id)}
|
88 |
+
className={classNames(activeTab === tab.id ? styles.active : '')}
|
89 |
+
>
|
90 |
+
<div className={tab.icon} />
|
91 |
+
{tab.label}
|
92 |
+
</button>
|
93 |
+
))}
|
94 |
+
<div className="mt-auto flex flex-col gap-2">
|
95 |
+
<a
|
96 |
+
href="https://github.com/stackblitz-labs/bolt.diy"
|
97 |
+
target="_blank"
|
98 |
+
rel="noopener noreferrer"
|
99 |
+
className={classNames(styles['settings-button'], 'flex items-center gap-2')}
|
100 |
+
>
|
101 |
+
<div className="i-ph:github-logo" />
|
102 |
+
GitHub
|
103 |
+
</a>
|
104 |
+
<a
|
105 |
+
href="https://stackblitz-labs.github.io/bolt.diy/"
|
106 |
+
target="_blank"
|
107 |
+
rel="noopener noreferrer"
|
108 |
+
className={classNames(styles['settings-button'], 'flex items-center gap-2')}
|
109 |
+
>
|
110 |
+
<div className="i-ph:book" />
|
111 |
+
Docs
|
112 |
+
</a>
|
113 |
+
</div>
|
114 |
+
</div>
|
115 |
+
|
116 |
+
<div className="flex-1 flex flex-col p-8 pt-10 bg-bolt-elements-background-depth-2">
|
117 |
+
<div className="flex-1 overflow-y-auto">{tabs.find((tab) => tab.id === activeTab)?.component}</div>
|
118 |
+
</div>
|
119 |
+
</div>
|
120 |
+
<RadixDialog.Close asChild onClick={onClose}>
|
121 |
+
<IconButton icon="i-ph:x" className="absolute top-[10px] right-[10px]" />
|
122 |
+
</RadixDialog.Close>
|
123 |
+
</motion.div>
|
124 |
+
</RadixDialog.Content>
|
125 |
+
</RadixDialog.Portal>
|
126 |
+
</RadixDialog.Root>
|
127 |
+
);
|
128 |
+
};
|
app/components/settings/chat-history/ChatHistoryTab.tsx
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { useNavigate } from '@remix-run/react';
|
2 |
+
import React, { useState } from 'react';
|
3 |
+
import { toast } from 'react-toastify';
|
4 |
+
import { db, deleteById, getAll } from '~/lib/persistence';
|
5 |
+
import { classNames } from '~/utils/classNames';
|
6 |
+
import styles from '~/components/settings/Settings.module.scss';
|
7 |
+
import { logStore } from '~/lib/stores/logs'; // Import logStore for event logging
|
8 |
+
|
9 |
+
export default function ChatHistoryTab() {
|
10 |
+
const navigate = useNavigate();
|
11 |
+
const [isDeleting, setIsDeleting] = useState(false);
|
12 |
+
const downloadAsJson = (data: any, filename: string) => {
|
13 |
+
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
|
14 |
+
const url = URL.createObjectURL(blob);
|
15 |
+
const link = document.createElement('a');
|
16 |
+
link.href = url;
|
17 |
+
link.download = filename;
|
18 |
+
document.body.appendChild(link);
|
19 |
+
link.click();
|
20 |
+
document.body.removeChild(link);
|
21 |
+
URL.revokeObjectURL(url);
|
22 |
+
};
|
23 |
+
|
24 |
+
const handleDeleteAllChats = async () => {
|
25 |
+
if (!db) {
|
26 |
+
const error = new Error('Database is not available');
|
27 |
+
logStore.logError('Failed to delete chats - DB unavailable', error);
|
28 |
+
toast.error('Database is not available');
|
29 |
+
|
30 |
+
return;
|
31 |
+
}
|
32 |
+
|
33 |
+
try {
|
34 |
+
setIsDeleting(true);
|
35 |
+
|
36 |
+
const allChats = await getAll(db);
|
37 |
+
await Promise.all(allChats.map((chat) => deleteById(db!, chat.id)));
|
38 |
+
logStore.logSystem('All chats deleted successfully', { count: allChats.length });
|
39 |
+
toast.success('All chats deleted successfully');
|
40 |
+
navigate('/', { replace: true });
|
41 |
+
} catch (error) {
|
42 |
+
logStore.logError('Failed to delete chats', error);
|
43 |
+
toast.error('Failed to delete chats');
|
44 |
+
console.error(error);
|
45 |
+
} finally {
|
46 |
+
setIsDeleting(false);
|
47 |
+
}
|
48 |
+
};
|
49 |
+
|
50 |
+
const handleExportAllChats = async () => {
|
51 |
+
if (!db) {
|
52 |
+
const error = new Error('Database is not available');
|
53 |
+
logStore.logError('Failed to export chats - DB unavailable', error);
|
54 |
+
toast.error('Database is not available');
|
55 |
+
|
56 |
+
return;
|
57 |
+
}
|
58 |
+
|
59 |
+
try {
|
60 |
+
const allChats = await getAll(db);
|
61 |
+
const exportData = {
|
62 |
+
chats: allChats,
|
63 |
+
exportDate: new Date().toISOString(),
|
64 |
+
};
|
65 |
+
|
66 |
+
downloadAsJson(exportData, `all-chats-${new Date().toISOString()}.json`);
|
67 |
+
logStore.logSystem('Chats exported successfully', { count: allChats.length });
|
68 |
+
toast.success('Chats exported successfully');
|
69 |
+
} catch (error) {
|
70 |
+
logStore.logError('Failed to export chats', error);
|
71 |
+
toast.error('Failed to export chats');
|
72 |
+
console.error(error);
|
73 |
+
}
|
74 |
+
};
|
75 |
+
|
76 |
+
return (
|
77 |
+
<>
|
78 |
+
<div className="p-4">
|
79 |
+
<h3 className="text-lg font-medium text-bolt-elements-textPrimary mb-4">Chat History</h3>
|
80 |
+
<button
|
81 |
+
onClick={handleExportAllChats}
|
82 |
+
className={classNames(
|
83 |
+
'bg-bolt-elements-button-primary-background',
|
84 |
+
'rounded-lg px-4 py-2 mb-4 transition-colors duration-200',
|
85 |
+
'hover:bg-bolt-elements-button-primary-backgroundHover',
|
86 |
+
'text-bolt-elements-button-primary-text',
|
87 |
+
)}
|
88 |
+
>
|
89 |
+
Export All Chats
|
90 |
+
</button>
|
91 |
+
|
92 |
+
<div
|
93 |
+
className={classNames('text-bolt-elements-textPrimary rounded-lg py-4 mb-4', styles['settings-danger-area'])}
|
94 |
+
>
|
95 |
+
<h4 className="font-semibold">Danger Area</h4>
|
96 |
+
<p className="mb-2">This action cannot be undone!</p>
|
97 |
+
<button
|
98 |
+
onClick={handleDeleteAllChats}
|
99 |
+
disabled={isDeleting}
|
100 |
+
className={classNames(
|
101 |
+
'bg-bolt-elements-button-danger-background',
|
102 |
+
'rounded-lg px-4 py-2 transition-colors duration-200',
|
103 |
+
isDeleting ? 'opacity-50 cursor-not-allowed' : 'hover:bg-bolt-elements-button-danger-backgroundHover',
|
104 |
+
'text-bolt-elements-button-danger-text',
|
105 |
+
)}
|
106 |
+
>
|
107 |
+
{isDeleting ? 'Deleting...' : 'Delete All Chats'}
|
108 |
+
</button>
|
109 |
+
</div>
|
110 |
+
</div>
|
111 |
+
</>
|
112 |
+
);
|
113 |
+
}
|
app/components/settings/connections/ConnectionsTab.tsx
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React, { useState } from 'react';
|
2 |
+
import { toast } from 'react-toastify';
|
3 |
+
import Cookies from 'js-cookie';
|
4 |
+
import { logStore } from '~/lib/stores/logs';
|
5 |
+
|
6 |
+
export default function ConnectionsTab() {
|
7 |
+
const [githubUsername, setGithubUsername] = useState(Cookies.get('githubUsername') || '');
|
8 |
+
const [githubToken, setGithubToken] = useState(Cookies.get('githubToken') || '');
|
9 |
+
|
10 |
+
const handleSaveConnection = () => {
|
11 |
+
Cookies.set('githubUsername', githubUsername);
|
12 |
+
Cookies.set('githubToken', githubToken);
|
13 |
+
logStore.logSystem('GitHub connection settings updated', {
|
14 |
+
username: githubUsername,
|
15 |
+
hasToken: !!githubToken,
|
16 |
+
});
|
17 |
+
toast.success('GitHub credentials saved successfully!');
|
18 |
+
};
|
19 |
+
|
20 |
+
return (
|
21 |
+
<div className="p-4 mb-4 border border-bolt-elements-borderColor rounded-lg bg-bolt-elements-background-depth-3">
|
22 |
+
<h3 className="text-lg font-medium text-bolt-elements-textPrimary mb-4">GitHub Connection</h3>
|
23 |
+
<div className="flex mb-4">
|
24 |
+
<div className="flex-1 mr-2">
|
25 |
+
<label className="block text-sm text-bolt-elements-textSecondary mb-1">GitHub Username:</label>
|
26 |
+
<input
|
27 |
+
type="text"
|
28 |
+
value={githubUsername}
|
29 |
+
onChange={(e) => setGithubUsername(e.target.value)}
|
30 |
+
className="w-full bg-white dark:bg-bolt-elements-background-depth-4 relative px-2 py-1.5 rounded-md focus:outline-none placeholder-bolt-elements-textTertiary text-bolt-elements-textPrimary dark:text-bolt-elements-textPrimary border border-bolt-elements-borderColor"
|
31 |
+
/>
|
32 |
+
</div>
|
33 |
+
<div className="flex-1">
|
34 |
+
<label className="block text-sm text-bolt-elements-textSecondary mb-1">Personal Access Token:</label>
|
35 |
+
<input
|
36 |
+
type="password"
|
37 |
+
value={githubToken}
|
38 |
+
onChange={(e) => setGithubToken(e.target.value)}
|
39 |
+
className="w-full bg-white dark:bg-bolt-elements-background-depth-4 relative px-2 py-1.5 rounded-md focus:outline-none placeholder-bolt-elements-textTertiary text-bolt-elements-textPrimary dark:text-bolt-elements-textPrimary border border-bolt-elements-borderColor"
|
40 |
+
/>
|
41 |
+
</div>
|
42 |
+
</div>
|
43 |
+
<div className="flex mb-4">
|
44 |
+
<button
|
45 |
+
onClick={handleSaveConnection}
|
46 |
+
className="bg-bolt-elements-button-primary-background rounded-lg px-4 py-2 mr-2 transition-colors duration-200 hover:bg-bolt-elements-button-primary-backgroundHover text-bolt-elements-button-primary-text"
|
47 |
+
>
|
48 |
+
Save Connection
|
49 |
+
</button>
|
50 |
+
</div>
|
51 |
+
</div>
|
52 |
+
);
|
53 |
+
}
|
app/components/settings/debug/DebugTab.tsx
ADDED
@@ -0,0 +1,494 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React, { useCallback, useEffect, useState } from 'react';
|
2 |
+
import { useSettings } from '~/lib/hooks/useSettings';
|
3 |
+
import commit from '~/commit.json';
|
4 |
+
|
5 |
+
interface ProviderStatus {
|
6 |
+
name: string;
|
7 |
+
enabled: boolean;
|
8 |
+
isLocal: boolean;
|
9 |
+
isRunning: boolean | null;
|
10 |
+
error?: string;
|
11 |
+
lastChecked: Date;
|
12 |
+
responseTime?: number;
|
13 |
+
url: string | null;
|
14 |
+
}
|
15 |
+
|
16 |
+
interface SystemInfo {
|
17 |
+
os: string;
|
18 |
+
browser: string;
|
19 |
+
screen: string;
|
20 |
+
language: string;
|
21 |
+
timezone: string;
|
22 |
+
memory: string;
|
23 |
+
cores: number;
|
24 |
+
}
|
25 |
+
|
26 |
+
interface IProviderConfig {
|
27 |
+
name: string;
|
28 |
+
settings: {
|
29 |
+
enabled: boolean;
|
30 |
+
};
|
31 |
+
}
|
32 |
+
|
33 |
+
const LOCAL_PROVIDERS = ['Ollama', 'LMStudio', 'OpenAILike'];
|
34 |
+
const versionHash = commit.commit;
|
35 |
+
const GITHUB_URLS = {
|
36 |
+
original: 'https://api.github.com/repos/stackblitz-labs/bolt.diy/commits/main',
|
37 |
+
fork: 'https://api.github.com/repos/Stijnus/bolt.new-any-llm/commits/main',
|
38 |
+
};
|
39 |
+
|
40 |
+
function getSystemInfo(): SystemInfo {
|
41 |
+
const formatBytes = (bytes: number): string => {
|
42 |
+
if (bytes === 0) {
|
43 |
+
return '0 Bytes';
|
44 |
+
}
|
45 |
+
|
46 |
+
const k = 1024;
|
47 |
+
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
|
48 |
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
49 |
+
|
50 |
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
51 |
+
};
|
52 |
+
|
53 |
+
return {
|
54 |
+
os: navigator.platform,
|
55 |
+
browser: navigator.userAgent.split(' ').slice(-1)[0],
|
56 |
+
screen: `${window.screen.width}x${window.screen.height}`,
|
57 |
+
language: navigator.language,
|
58 |
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
59 |
+
memory: formatBytes(performance?.memory?.jsHeapSizeLimit || 0),
|
60 |
+
cores: navigator.hardwareConcurrency || 0,
|
61 |
+
};
|
62 |
+
}
|
63 |
+
|
64 |
+
const checkProviderStatus = async (url: string | null, providerName: string): Promise<ProviderStatus> => {
|
65 |
+
if (!url) {
|
66 |
+
console.log(`[Debug] No URL provided for ${providerName}`);
|
67 |
+
return {
|
68 |
+
name: providerName,
|
69 |
+
enabled: false,
|
70 |
+
isLocal: true,
|
71 |
+
isRunning: false,
|
72 |
+
error: 'No URL configured',
|
73 |
+
lastChecked: new Date(),
|
74 |
+
url: null,
|
75 |
+
};
|
76 |
+
}
|
77 |
+
|
78 |
+
console.log(`[Debug] Checking status for ${providerName} at ${url}`);
|
79 |
+
|
80 |
+
const startTime = performance.now();
|
81 |
+
|
82 |
+
try {
|
83 |
+
if (providerName.toLowerCase() === 'ollama') {
|
84 |
+
// Special check for Ollama root endpoint
|
85 |
+
try {
|
86 |
+
console.log(`[Debug] Checking Ollama root endpoint: ${url}`);
|
87 |
+
|
88 |
+
const controller = new AbortController();
|
89 |
+
const timeoutId = setTimeout(() => controller.abort(), 5000); // 5 second timeout
|
90 |
+
|
91 |
+
const response = await fetch(url, {
|
92 |
+
signal: controller.signal,
|
93 |
+
headers: {
|
94 |
+
Accept: 'text/plain,application/json',
|
95 |
+
},
|
96 |
+
});
|
97 |
+
clearTimeout(timeoutId);
|
98 |
+
|
99 |
+
const text = await response.text();
|
100 |
+
console.log(`[Debug] Ollama root response:`, text);
|
101 |
+
|
102 |
+
if (text.includes('Ollama is running')) {
|
103 |
+
console.log(`[Debug] Ollama running confirmed via root endpoint`);
|
104 |
+
return {
|
105 |
+
name: providerName,
|
106 |
+
enabled: false,
|
107 |
+
isLocal: true,
|
108 |
+
isRunning: true,
|
109 |
+
lastChecked: new Date(),
|
110 |
+
responseTime: performance.now() - startTime,
|
111 |
+
url,
|
112 |
+
};
|
113 |
+
}
|
114 |
+
} catch (error) {
|
115 |
+
console.log(`[Debug] Ollama root check failed:`, error);
|
116 |
+
|
117 |
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
118 |
+
|
119 |
+
if (errorMessage.includes('aborted')) {
|
120 |
+
return {
|
121 |
+
name: providerName,
|
122 |
+
enabled: false,
|
123 |
+
isLocal: true,
|
124 |
+
isRunning: false,
|
125 |
+
error: 'Connection timeout',
|
126 |
+
lastChecked: new Date(),
|
127 |
+
responseTime: performance.now() - startTime,
|
128 |
+
url,
|
129 |
+
};
|
130 |
+
}
|
131 |
+
}
|
132 |
+
}
|
133 |
+
|
134 |
+
// Try different endpoints based on provider
|
135 |
+
const checkUrls = [`${url}/api/health`, `${url}/v1/models`];
|
136 |
+
console.log(`[Debug] Checking additional endpoints:`, checkUrls);
|
137 |
+
|
138 |
+
const results = await Promise.all(
|
139 |
+
checkUrls.map(async (checkUrl) => {
|
140 |
+
try {
|
141 |
+
console.log(`[Debug] Trying endpoint: ${checkUrl}`);
|
142 |
+
|
143 |
+
const controller = new AbortController();
|
144 |
+
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
145 |
+
|
146 |
+
const response = await fetch(checkUrl, {
|
147 |
+
signal: controller.signal,
|
148 |
+
headers: {
|
149 |
+
Accept: 'application/json',
|
150 |
+
},
|
151 |
+
});
|
152 |
+
clearTimeout(timeoutId);
|
153 |
+
|
154 |
+
const ok = response.ok;
|
155 |
+
console.log(`[Debug] Endpoint ${checkUrl} response:`, ok);
|
156 |
+
|
157 |
+
if (ok) {
|
158 |
+
try {
|
159 |
+
const data = await response.json();
|
160 |
+
console.log(`[Debug] Endpoint ${checkUrl} data:`, data);
|
161 |
+
} catch {
|
162 |
+
console.log(`[Debug] Could not parse JSON from ${checkUrl}`);
|
163 |
+
}
|
164 |
+
}
|
165 |
+
|
166 |
+
return ok;
|
167 |
+
} catch (error) {
|
168 |
+
console.log(`[Debug] Endpoint ${checkUrl} failed:`, error);
|
169 |
+
return false;
|
170 |
+
}
|
171 |
+
}),
|
172 |
+
);
|
173 |
+
|
174 |
+
const isRunning = results.some((result) => result);
|
175 |
+
console.log(`[Debug] Final status for ${providerName}:`, isRunning);
|
176 |
+
|
177 |
+
return {
|
178 |
+
name: providerName,
|
179 |
+
enabled: false,
|
180 |
+
isLocal: true,
|
181 |
+
isRunning,
|
182 |
+
lastChecked: new Date(),
|
183 |
+
responseTime: performance.now() - startTime,
|
184 |
+
url,
|
185 |
+
};
|
186 |
+
} catch (error) {
|
187 |
+
console.log(`[Debug] Provider check failed for ${providerName}:`, error);
|
188 |
+
return {
|
189 |
+
name: providerName,
|
190 |
+
enabled: false,
|
191 |
+
isLocal: true,
|
192 |
+
isRunning: false,
|
193 |
+
error: error instanceof Error ? error.message : 'Unknown error',
|
194 |
+
lastChecked: new Date(),
|
195 |
+
responseTime: performance.now() - startTime,
|
196 |
+
url,
|
197 |
+
};
|
198 |
+
}
|
199 |
+
};
|
200 |
+
|
201 |
+
export default function DebugTab() {
|
202 |
+
const { providers } = useSettings();
|
203 |
+
const [activeProviders, setActiveProviders] = useState<ProviderStatus[]>([]);
|
204 |
+
const [updateMessage, setUpdateMessage] = useState<string>('');
|
205 |
+
const [systemInfo] = useState<SystemInfo>(getSystemInfo());
|
206 |
+
const [isCheckingUpdate, setIsCheckingUpdate] = useState(false);
|
207 |
+
|
208 |
+
const updateProviderStatuses = async () => {
|
209 |
+
if (!providers) {
|
210 |
+
return;
|
211 |
+
}
|
212 |
+
|
213 |
+
try {
|
214 |
+
const entries = Object.entries(providers) as [string, IProviderConfig][];
|
215 |
+
const statuses = entries
|
216 |
+
.filter(([, provider]) => LOCAL_PROVIDERS.includes(provider.name))
|
217 |
+
.map(async ([, provider]) => {
|
218 |
+
const envVarName =
|
219 |
+
provider.name.toLowerCase() === 'ollama'
|
220 |
+
? 'OLLAMA_API_BASE_URL'
|
221 |
+
: provider.name.toLowerCase() === 'lmstudio'
|
222 |
+
? 'LMSTUDIO_API_BASE_URL'
|
223 |
+
: `REACT_APP_${provider.name.toUpperCase()}_URL`;
|
224 |
+
|
225 |
+
// Access environment variables through import.meta.env
|
226 |
+
const url = import.meta.env[envVarName] || null;
|
227 |
+
console.log(`[Debug] Using URL for ${provider.name}:`, url, `(from ${envVarName})`);
|
228 |
+
|
229 |
+
const status = await checkProviderStatus(url, provider.name);
|
230 |
+
|
231 |
+
return {
|
232 |
+
...status,
|
233 |
+
enabled: provider.settings.enabled ?? false,
|
234 |
+
};
|
235 |
+
});
|
236 |
+
|
237 |
+
Promise.all(statuses).then(setActiveProviders);
|
238 |
+
} catch (error) {
|
239 |
+
console.error('[Debug] Failed to update provider statuses:', error);
|
240 |
+
}
|
241 |
+
};
|
242 |
+
|
243 |
+
useEffect(() => {
|
244 |
+
updateProviderStatuses();
|
245 |
+
|
246 |
+
const interval = setInterval(updateProviderStatuses, 30000);
|
247 |
+
|
248 |
+
return () => clearInterval(interval);
|
249 |
+
}, [providers]);
|
250 |
+
|
251 |
+
const handleCheckForUpdate = useCallback(async () => {
|
252 |
+
if (isCheckingUpdate) {
|
253 |
+
return;
|
254 |
+
}
|
255 |
+
|
256 |
+
try {
|
257 |
+
setIsCheckingUpdate(true);
|
258 |
+
setUpdateMessage('Checking for updates...');
|
259 |
+
|
260 |
+
const [originalResponse, forkResponse] = await Promise.all([
|
261 |
+
fetch(GITHUB_URLS.original),
|
262 |
+
fetch(GITHUB_URLS.fork),
|
263 |
+
]);
|
264 |
+
|
265 |
+
if (!originalResponse.ok || !forkResponse.ok) {
|
266 |
+
throw new Error('Failed to fetch repository information');
|
267 |
+
}
|
268 |
+
|
269 |
+
const [originalData, forkData] = await Promise.all([
|
270 |
+
originalResponse.json() as Promise<{ sha: string }>,
|
271 |
+
forkResponse.json() as Promise<{ sha: string }>,
|
272 |
+
]);
|
273 |
+
|
274 |
+
const originalCommitHash = originalData.sha;
|
275 |
+
const forkCommitHash = forkData.sha;
|
276 |
+
const isForked = versionHash === forkCommitHash && forkCommitHash !== originalCommitHash;
|
277 |
+
|
278 |
+
if (originalCommitHash !== versionHash) {
|
279 |
+
setUpdateMessage(
|
280 |
+
`Update available from original repository!\n` +
|
281 |
+
`Current: ${versionHash.slice(0, 7)}${isForked ? ' (forked)' : ''}\n` +
|
282 |
+
`Latest: ${originalCommitHash.slice(0, 7)}`,
|
283 |
+
);
|
284 |
+
} else {
|
285 |
+
setUpdateMessage('You are on the latest version from the original repository');
|
286 |
+
}
|
287 |
+
} catch (error) {
|
288 |
+
setUpdateMessage('Failed to check for updates');
|
289 |
+
console.error('[Debug] Failed to check for updates:', error);
|
290 |
+
} finally {
|
291 |
+
setIsCheckingUpdate(false);
|
292 |
+
}
|
293 |
+
}, [isCheckingUpdate]);
|
294 |
+
|
295 |
+
const handleCopyToClipboard = useCallback(() => {
|
296 |
+
const debugInfo = {
|
297 |
+
System: systemInfo,
|
298 |
+
Providers: activeProviders.map((provider) => ({
|
299 |
+
name: provider.name,
|
300 |
+
enabled: provider.enabled,
|
301 |
+
isLocal: provider.isLocal,
|
302 |
+
running: provider.isRunning,
|
303 |
+
error: provider.error,
|
304 |
+
lastChecked: provider.lastChecked,
|
305 |
+
responseTime: provider.responseTime,
|
306 |
+
url: provider.url,
|
307 |
+
})),
|
308 |
+
Version: versionHash,
|
309 |
+
Timestamp: new Date().toISOString(),
|
310 |
+
};
|
311 |
+
navigator.clipboard.writeText(JSON.stringify(debugInfo, null, 2)).then(() => {
|
312 |
+
alert('Debug information copied to clipboard!');
|
313 |
+
});
|
314 |
+
}, [activeProviders, systemInfo]);
|
315 |
+
|
316 |
+
return (
|
317 |
+
<div className="p-4 space-y-6">
|
318 |
+
<div className="flex items-center justify-between">
|
319 |
+
<h3 className="text-lg font-medium text-bolt-elements-textPrimary">Debug Information</h3>
|
320 |
+
<div className="flex gap-2">
|
321 |
+
<button
|
322 |
+
onClick={handleCopyToClipboard}
|
323 |
+
className="bg-bolt-elements-button-primary-background rounded-lg px-4 py-2 transition-colors duration-200 hover:bg-bolt-elements-button-primary-backgroundHover text-bolt-elements-button-primary-text"
|
324 |
+
>
|
325 |
+
Copy Debug Info
|
326 |
+
</button>
|
327 |
+
<button
|
328 |
+
onClick={handleCheckForUpdate}
|
329 |
+
disabled={isCheckingUpdate}
|
330 |
+
className={`bg-bolt-elements-button-primary-background rounded-lg px-4 py-2 transition-colors duration-200
|
331 |
+
${!isCheckingUpdate ? 'hover:bg-bolt-elements-button-primary-backgroundHover' : 'opacity-75 cursor-not-allowed'}
|
332 |
+
text-bolt-elements-button-primary-text`}
|
333 |
+
>
|
334 |
+
{isCheckingUpdate ? 'Checking...' : 'Check for Updates'}
|
335 |
+
</button>
|
336 |
+
</div>
|
337 |
+
</div>
|
338 |
+
|
339 |
+
{updateMessage && (
|
340 |
+
<div
|
341 |
+
className={`bg-bolt-elements-surface rounded-lg p-3 ${
|
342 |
+
updateMessage.includes('Update available') ? 'border-l-4 border-yellow-400' : ''
|
343 |
+
}`}
|
344 |
+
>
|
345 |
+
<p className="text-bolt-elements-textSecondary whitespace-pre-line">{updateMessage}</p>
|
346 |
+
{updateMessage.includes('Update available') && (
|
347 |
+
<div className="mt-3 text-sm">
|
348 |
+
<p className="font-medium text-bolt-elements-textPrimary">To update:</p>
|
349 |
+
<ol className="list-decimal ml-4 mt-1 text-bolt-elements-textSecondary">
|
350 |
+
<li>
|
351 |
+
Pull the latest changes:{' '}
|
352 |
+
<code className="bg-bolt-elements-surface-hover px-1 rounded">git pull upstream main</code>
|
353 |
+
</li>
|
354 |
+
<li>
|
355 |
+
Install any new dependencies:{' '}
|
356 |
+
<code className="bg-bolt-elements-surface-hover px-1 rounded">pnpm install</code>
|
357 |
+
</li>
|
358 |
+
<li>Restart the application</li>
|
359 |
+
</ol>
|
360 |
+
</div>
|
361 |
+
)}
|
362 |
+
</div>
|
363 |
+
)}
|
364 |
+
|
365 |
+
<section className="space-y-4">
|
366 |
+
<div>
|
367 |
+
<h4 className="text-md font-medium text-bolt-elements-textPrimary mb-2">System Information</h4>
|
368 |
+
<div className="bg-bolt-elements-surface rounded-lg p-4">
|
369 |
+
<div className="grid grid-cols-2 md:grid-cols-3 gap-4">
|
370 |
+
<div>
|
371 |
+
<p className="text-xs text-bolt-elements-textSecondary">Operating System</p>
|
372 |
+
<p className="text-sm font-medium text-bolt-elements-textPrimary">{systemInfo.os}</p>
|
373 |
+
</div>
|
374 |
+
<div>
|
375 |
+
<p className="text-xs text-bolt-elements-textSecondary">Browser</p>
|
376 |
+
<p className="text-sm font-medium text-bolt-elements-textPrimary">{systemInfo.browser}</p>
|
377 |
+
</div>
|
378 |
+
<div>
|
379 |
+
<p className="text-xs text-bolt-elements-textSecondary">Screen Resolution</p>
|
380 |
+
<p className="text-sm font-medium text-bolt-elements-textPrimary">{systemInfo.screen}</p>
|
381 |
+
</div>
|
382 |
+
<div>
|
383 |
+
<p className="text-xs text-bolt-elements-textSecondary">Language</p>
|
384 |
+
<p className="text-sm font-medium text-bolt-elements-textPrimary">{systemInfo.language}</p>
|
385 |
+
</div>
|
386 |
+
<div>
|
387 |
+
<p className="text-xs text-bolt-elements-textSecondary">Timezone</p>
|
388 |
+
<p className="text-sm font-medium text-bolt-elements-textPrimary">{systemInfo.timezone}</p>
|
389 |
+
</div>
|
390 |
+
<div>
|
391 |
+
<p className="text-xs text-bolt-elements-textSecondary">CPU Cores</p>
|
392 |
+
<p className="text-sm font-medium text-bolt-elements-textPrimary">{systemInfo.cores}</p>
|
393 |
+
</div>
|
394 |
+
</div>
|
395 |
+
<div className="mt-3 pt-3 border-t border-bolt-elements-surface-hover">
|
396 |
+
<p className="text-xs text-bolt-elements-textSecondary">Version</p>
|
397 |
+
<p className="text-sm font-medium text-bolt-elements-textPrimary font-mono">
|
398 |
+
{versionHash.slice(0, 7)}
|
399 |
+
<span className="ml-2 text-xs text-bolt-elements-textSecondary">
|
400 |
+
({new Date().toLocaleDateString()})
|
401 |
+
</span>
|
402 |
+
</p>
|
403 |
+
</div>
|
404 |
+
</div>
|
405 |
+
</div>
|
406 |
+
|
407 |
+
<div>
|
408 |
+
<h4 className="text-md font-medium text-bolt-elements-textPrimary mb-2">Local LLM Status</h4>
|
409 |
+
<div className="bg-bolt-elements-surface rounded-lg">
|
410 |
+
<div className="grid grid-cols-1 divide-y">
|
411 |
+
{activeProviders.map((provider) => (
|
412 |
+
<div key={provider.name} className="p-3 flex flex-col space-y-2">
|
413 |
+
<div className="flex items-center justify-between">
|
414 |
+
<div className="flex items-center gap-3">
|
415 |
+
<div className="flex-shrink-0">
|
416 |
+
<div
|
417 |
+
className={`w-2 h-2 rounded-full ${
|
418 |
+
!provider.enabled ? 'bg-gray-300' : provider.isRunning ? 'bg-green-400' : 'bg-red-400'
|
419 |
+
}`}
|
420 |
+
/>
|
421 |
+
</div>
|
422 |
+
<div>
|
423 |
+
<p className="text-sm font-medium text-bolt-elements-textPrimary">{provider.name}</p>
|
424 |
+
{provider.url && (
|
425 |
+
<p className="text-xs text-bolt-elements-textSecondary truncate max-w-[300px]">
|
426 |
+
{provider.url}
|
427 |
+
</p>
|
428 |
+
)}
|
429 |
+
</div>
|
430 |
+
</div>
|
431 |
+
<div className="flex items-center gap-2">
|
432 |
+
<span
|
433 |
+
className={`px-2 py-0.5 text-xs rounded-full ${
|
434 |
+
provider.enabled ? 'bg-green-100 text-green-800' : 'bg-gray-100 text-gray-800'
|
435 |
+
}`}
|
436 |
+
>
|
437 |
+
{provider.enabled ? 'Enabled' : 'Disabled'}
|
438 |
+
</span>
|
439 |
+
{provider.enabled && (
|
440 |
+
<span
|
441 |
+
className={`px-2 py-0.5 text-xs rounded-full ${
|
442 |
+
provider.isRunning ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800'
|
443 |
+
}`}
|
444 |
+
>
|
445 |
+
{provider.isRunning ? 'Running' : 'Not Running'}
|
446 |
+
</span>
|
447 |
+
)}
|
448 |
+
</div>
|
449 |
+
</div>
|
450 |
+
|
451 |
+
<div className="pl-5 flex flex-col space-y-1 text-xs">
|
452 |
+
{/* Status Details */}
|
453 |
+
<div className="flex flex-wrap gap-2">
|
454 |
+
<span className="text-bolt-elements-textSecondary">
|
455 |
+
Last checked: {new Date(provider.lastChecked).toLocaleTimeString()}
|
456 |
+
</span>
|
457 |
+
{provider.responseTime && (
|
458 |
+
<span className="text-bolt-elements-textSecondary">
|
459 |
+
Response time: {Math.round(provider.responseTime)}ms
|
460 |
+
</span>
|
461 |
+
)}
|
462 |
+
</div>
|
463 |
+
|
464 |
+
{/* Error Message */}
|
465 |
+
{provider.error && (
|
466 |
+
<div className="mt-1 text-red-600 bg-red-50 rounded-md p-2">
|
467 |
+
<span className="font-medium">Error:</span> {provider.error}
|
468 |
+
</div>
|
469 |
+
)}
|
470 |
+
|
471 |
+
{/* Connection Info */}
|
472 |
+
{provider.url && (
|
473 |
+
<div className="text-bolt-elements-textSecondary">
|
474 |
+
<span className="font-medium">Endpoints checked:</span>
|
475 |
+
<ul className="list-disc list-inside pl-2 mt-1">
|
476 |
+
<li>{provider.url} (root)</li>
|
477 |
+
<li>{provider.url}/api/health</li>
|
478 |
+
<li>{provider.url}/v1/models</li>
|
479 |
+
</ul>
|
480 |
+
</div>
|
481 |
+
)}
|
482 |
+
</div>
|
483 |
+
</div>
|
484 |
+
))}
|
485 |
+
{activeProviders.length === 0 && (
|
486 |
+
<div className="p-4 text-center text-bolt-elements-textSecondary">No local LLMs configured</div>
|
487 |
+
)}
|
488 |
+
</div>
|
489 |
+
</div>
|
490 |
+
</div>
|
491 |
+
</section>
|
492 |
+
</div>
|
493 |
+
);
|
494 |
+
}
|
app/components/settings/event-logs/EventLogsTab.tsx
ADDED
@@ -0,0 +1,219 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React, { useCallback, useEffect, useState, useMemo } from 'react';
|
2 |
+
import { useSettings } from '~/lib/hooks/useSettings';
|
3 |
+
import { toast } from 'react-toastify';
|
4 |
+
import { Switch } from '~/components/ui/Switch';
|
5 |
+
import { logStore, type LogEntry } from '~/lib/stores/logs';
|
6 |
+
import { useStore } from '@nanostores/react';
|
7 |
+
import { classNames } from '~/utils/classNames';
|
8 |
+
|
9 |
+
export default function EventLogsTab() {
|
10 |
+
const {} = useSettings();
|
11 |
+
const showLogs = useStore(logStore.showLogs);
|
12 |
+
const [logLevel, setLogLevel] = useState<LogEntry['level'] | 'all'>('info');
|
13 |
+
const [autoScroll, setAutoScroll] = useState(true);
|
14 |
+
const [searchQuery, setSearchQuery] = useState('');
|
15 |
+
const [, forceUpdate] = useState({});
|
16 |
+
|
17 |
+
const filteredLogs = useMemo(() => {
|
18 |
+
const logs = logStore.getLogs();
|
19 |
+
return logs.filter((log) => {
|
20 |
+
const matchesLevel = !logLevel || log.level === logLevel || logLevel === 'all';
|
21 |
+
const matchesSearch =
|
22 |
+
!searchQuery ||
|
23 |
+
log.message?.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
24 |
+
JSON.stringify(log.details)?.toLowerCase()?.includes(searchQuery?.toLowerCase());
|
25 |
+
|
26 |
+
return matchesLevel && matchesSearch;
|
27 |
+
});
|
28 |
+
}, [logLevel, searchQuery]);
|
29 |
+
|
30 |
+
// Effect to initialize showLogs
|
31 |
+
useEffect(() => {
|
32 |
+
logStore.showLogs.set(true);
|
33 |
+
}, []);
|
34 |
+
|
35 |
+
useEffect(() => {
|
36 |
+
// System info logs
|
37 |
+
logStore.logSystem('Application initialized', {
|
38 |
+
version: process.env.NEXT_PUBLIC_APP_VERSION,
|
39 |
+
environment: process.env.NODE_ENV,
|
40 |
+
});
|
41 |
+
|
42 |
+
// Debug logs for system state
|
43 |
+
logStore.logDebug('System configuration loaded', {
|
44 |
+
runtime: 'Next.js',
|
45 |
+
features: ['AI Chat', 'Event Logging'],
|
46 |
+
});
|
47 |
+
|
48 |
+
// Warning logs for potential issues
|
49 |
+
logStore.logWarning('Resource usage threshold approaching', {
|
50 |
+
memoryUsage: '75%',
|
51 |
+
cpuLoad: '60%',
|
52 |
+
});
|
53 |
+
|
54 |
+
// Error logs with detailed context
|
55 |
+
logStore.logError('API connection failed', new Error('Connection timeout'), {
|
56 |
+
endpoint: '/api/chat',
|
57 |
+
retryCount: 3,
|
58 |
+
lastAttempt: new Date().toISOString(),
|
59 |
+
});
|
60 |
+
}, []);
|
61 |
+
|
62 |
+
useEffect(() => {
|
63 |
+
const container = document.querySelector('.logs-container');
|
64 |
+
|
65 |
+
if (container && autoScroll) {
|
66 |
+
container.scrollTop = container.scrollHeight;
|
67 |
+
}
|
68 |
+
}, [filteredLogs, autoScroll]);
|
69 |
+
|
70 |
+
const handleClearLogs = useCallback(() => {
|
71 |
+
if (confirm('Are you sure you want to clear all logs?')) {
|
72 |
+
logStore.clearLogs();
|
73 |
+
toast.success('Logs cleared successfully');
|
74 |
+
forceUpdate({}); // Force a re-render after clearing logs
|
75 |
+
}
|
76 |
+
}, []);
|
77 |
+
|
78 |
+
const handleExportLogs = useCallback(() => {
|
79 |
+
try {
|
80 |
+
const logText = logStore
|
81 |
+
.getLogs()
|
82 |
+
.map(
|
83 |
+
(log) =>
|
84 |
+
`[${log.level.toUpperCase()}] ${log.timestamp} - ${log.message}${
|
85 |
+
log.details ? '\nDetails: ' + JSON.stringify(log.details, null, 2) : ''
|
86 |
+
}`,
|
87 |
+
)
|
88 |
+
.join('\n\n');
|
89 |
+
|
90 |
+
const blob = new Blob([logText], { type: 'text/plain' });
|
91 |
+
const url = URL.createObjectURL(blob);
|
92 |
+
const a = document.createElement('a');
|
93 |
+
a.href = url;
|
94 |
+
a.download = `event-logs-${new Date().toISOString()}.txt`;
|
95 |
+
document.body.appendChild(a);
|
96 |
+
a.click();
|
97 |
+
document.body.removeChild(a);
|
98 |
+
URL.revokeObjectURL(url);
|
99 |
+
toast.success('Logs exported successfully');
|
100 |
+
} catch (error) {
|
101 |
+
toast.error('Failed to export logs');
|
102 |
+
console.error('Export error:', error);
|
103 |
+
}
|
104 |
+
}, []);
|
105 |
+
|
106 |
+
const getLevelColor = (level: LogEntry['level']) => {
|
107 |
+
switch (level) {
|
108 |
+
case 'info':
|
109 |
+
return 'text-blue-500';
|
110 |
+
case 'warning':
|
111 |
+
return 'text-yellow-500';
|
112 |
+
case 'error':
|
113 |
+
return 'text-red-500';
|
114 |
+
case 'debug':
|
115 |
+
return 'text-gray-500';
|
116 |
+
default:
|
117 |
+
return 'text-bolt-elements-textPrimary';
|
118 |
+
}
|
119 |
+
};
|
120 |
+
|
121 |
+
return (
|
122 |
+
<div className="p-4 h-full flex flex-col">
|
123 |
+
<div className="flex flex-col space-y-4 mb-4">
|
124 |
+
{/* Title and Toggles Row */}
|
125 |
+
<div className="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4">
|
126 |
+
<h3 className="text-lg font-medium text-bolt-elements-textPrimary">Event Logs</h3>
|
127 |
+
<div className="flex flex-wrap items-center gap-4">
|
128 |
+
<div className="flex items-center space-x-2">
|
129 |
+
<span className="text-sm text-bolt-elements-textSecondary whitespace-nowrap">Show Actions</span>
|
130 |
+
<Switch checked={showLogs} onCheckedChange={(checked) => logStore.showLogs.set(checked)} />
|
131 |
+
</div>
|
132 |
+
<div className="flex items-center space-x-2">
|
133 |
+
<span className="text-sm text-bolt-elements-textSecondary whitespace-nowrap">Auto-scroll</span>
|
134 |
+
<Switch checked={autoScroll} onCheckedChange={setAutoScroll} />
|
135 |
+
</div>
|
136 |
+
</div>
|
137 |
+
</div>
|
138 |
+
|
139 |
+
{/* Controls Row */}
|
140 |
+
<div className="flex flex-wrap items-center gap-2">
|
141 |
+
<select
|
142 |
+
value={logLevel}
|
143 |
+
onChange={(e) => setLogLevel(e.target.value as LogEntry['level'])}
|
144 |
+
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-[20%] text-sm min-w-[100px]"
|
145 |
+
>
|
146 |
+
<option value="all">All</option>
|
147 |
+
<option value="info">Info</option>
|
148 |
+
<option value="warning">Warning</option>
|
149 |
+
<option value="error">Error</option>
|
150 |
+
<option value="debug">Debug</option>
|
151 |
+
</select>
|
152 |
+
<div className="flex-1 min-w-[200px]">
|
153 |
+
<input
|
154 |
+
type="text"
|
155 |
+
placeholder="Search logs..."
|
156 |
+
value={searchQuery}
|
157 |
+
onChange={(e) => setSearchQuery(e.target.value)}
|
158 |
+
className="w-full bg-white dark:bg-bolt-elements-background-depth-4 relative px-2 py-1.5 rounded-md focus:outline-none placeholder-bolt-elements-textTertiary text-bolt-elements-textPrimary dark:text-bolt-elements-textPrimary border border-bolt-elements-borderColor"
|
159 |
+
/>
|
160 |
+
</div>
|
161 |
+
{showLogs && (
|
162 |
+
<div className="flex items-center gap-2 flex-nowrap">
|
163 |
+
<button
|
164 |
+
onClick={handleExportLogs}
|
165 |
+
className={classNames(
|
166 |
+
'bg-bolt-elements-button-primary-background',
|
167 |
+
'rounded-lg px-4 py-2 transition-colors duration-200',
|
168 |
+
'hover:bg-bolt-elements-button-primary-backgroundHover',
|
169 |
+
'text-bolt-elements-button-primary-text',
|
170 |
+
)}
|
171 |
+
>
|
172 |
+
Export Logs
|
173 |
+
</button>
|
174 |
+
<button
|
175 |
+
onClick={handleClearLogs}
|
176 |
+
className={classNames(
|
177 |
+
'bg-bolt-elements-button-danger-background',
|
178 |
+
'rounded-lg px-4 py-2 transition-colors duration-200',
|
179 |
+
'hover:bg-bolt-elements-button-danger-backgroundHover',
|
180 |
+
'text-bolt-elements-button-danger-text',
|
181 |
+
)}
|
182 |
+
>
|
183 |
+
Clear Logs
|
184 |
+
</button>
|
185 |
+
</div>
|
186 |
+
)}
|
187 |
+
</div>
|
188 |
+
</div>
|
189 |
+
|
190 |
+
<div className="bg-bolt-elements-bg-depth-1 rounded-lg p-4 h-[calc(100vh - 250px)] min-h-[400px] overflow-y-auto logs-container overflow-y-auto">
|
191 |
+
{filteredLogs.length === 0 ? (
|
192 |
+
<div className="text-center text-bolt-elements-textSecondary py-8">No logs found</div>
|
193 |
+
) : (
|
194 |
+
filteredLogs.map((log, index) => (
|
195 |
+
<div
|
196 |
+
key={index}
|
197 |
+
className="text-sm mb-3 font-mono border-b border-bolt-elements-borderColor pb-2 last:border-0"
|
198 |
+
>
|
199 |
+
<div className="flex items-start space-x-2 flex-wrap">
|
200 |
+
<span className={`font-bold ${getLevelColor(log.level)} whitespace-nowrap`}>
|
201 |
+
[{log.level.toUpperCase()}]
|
202 |
+
</span>
|
203 |
+
<span className="text-bolt-elements-textSecondary whitespace-nowrap">
|
204 |
+
{new Date(log.timestamp).toLocaleString()}
|
205 |
+
</span>
|
206 |
+
<span className="text-bolt-elements-textPrimary break-all">{log.message}</span>
|
207 |
+
</div>
|
208 |
+
{log.details && (
|
209 |
+
<pre className="mt-2 text-xs text-bolt-elements-textSecondary overflow-x-auto whitespace-pre-wrap break-all">
|
210 |
+
{JSON.stringify(log.details, null, 2)}
|
211 |
+
</pre>
|
212 |
+
)}
|
213 |
+
</div>
|
214 |
+
))
|
215 |
+
)}
|
216 |
+
</div>
|
217 |
+
</div>
|
218 |
+
);
|
219 |
+
}
|
app/components/settings/features/FeaturesTab.tsx
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React from 'react';
|
2 |
+
import { Switch } from '~/components/ui/Switch';
|
3 |
+
import { useSettings } from '~/lib/hooks/useSettings';
|
4 |
+
|
5 |
+
export default function FeaturesTab() {
|
6 |
+
const { debug, enableDebugMode, isLocalModel, enableLocalModels, eventLogs, enableEventLogs } = useSettings();
|
7 |
+
return (
|
8 |
+
<div className="p-4 bg-bolt-elements-bg-depth-2 border border-bolt-elements-borderColor rounded-lg mb-4">
|
9 |
+
<div className="mb-6">
|
10 |
+
<h3 className="text-lg font-medium text-bolt-elements-textPrimary mb-4">Optional Features</h3>
|
11 |
+
<div className="flex items-center justify-between mb-2">
|
12 |
+
<span className="text-bolt-elements-textPrimary">Debug Info</span>
|
13 |
+
<Switch className="ml-auto" checked={debug} onCheckedChange={enableDebugMode} />
|
14 |
+
</div>
|
15 |
+
<div className="flex items-center justify-between mb-2">
|
16 |
+
<span className="text-bolt-elements-textPrimary">Event Logs</span>
|
17 |
+
<Switch className="ml-auto" checked={eventLogs} onCheckedChange={enableEventLogs} />
|
18 |
+
</div>
|
19 |
+
</div>
|
20 |
+
|
21 |
+
<div className="mb-6 border-t border-bolt-elements-borderColor pt-4">
|
22 |
+
<h3 className="text-lg font-medium text-bolt-elements-textPrimary mb-4">Experimental Features</h3>
|
23 |
+
<p className="text-sm text-bolt-elements-textSecondary mb-4">
|
24 |
+
Disclaimer: Experimental features may be unstable and are subject to change.
|
25 |
+
</p>
|
26 |
+
<div className="flex items-center justify-between mb-2">
|
27 |
+
<span className="text-bolt-elements-textPrimary">Enable Local Models</span>
|
28 |
+
<Switch className="ml-auto" checked={isLocalModel} onCheckedChange={enableLocalModels} />
|
29 |
+
</div>
|
30 |
+
</div>
|
31 |
+
</div>
|
32 |
+
);
|
33 |
+
}
|
app/components/settings/providers/ProvidersTab.tsx
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React, { useEffect, useState } from 'react';
|
2 |
+
import { Switch } from '~/components/ui/Switch';
|
3 |
+
import { useSettings } from '~/lib/hooks/useSettings';
|
4 |
+
import { LOCAL_PROVIDERS, URL_CONFIGURABLE_PROVIDERS } from '~/lib/stores/settings';
|
5 |
+
import type { IProviderConfig } from '~/types/model';
|
6 |
+
import { logStore } from '~/lib/stores/logs';
|
7 |
+
|
8 |
+
export default function ProvidersTab() {
|
9 |
+
const { providers, updateProviderSettings, isLocalModel } = useSettings();
|
10 |
+
const [filteredProviders, setFilteredProviders] = useState<IProviderConfig[]>([]);
|
11 |
+
|
12 |
+
// Load base URLs from cookies
|
13 |
+
const [searchTerm, setSearchTerm] = useState('');
|
14 |
+
|
15 |
+
useEffect(() => {
|
16 |
+
let newFilteredProviders: IProviderConfig[] = Object.entries(providers).map(([key, value]) => ({
|
17 |
+
...value,
|
18 |
+
name: key,
|
19 |
+
}));
|
20 |
+
|
21 |
+
if (searchTerm && searchTerm.length > 0) {
|
22 |
+
newFilteredProviders = newFilteredProviders.filter((provider) =>
|
23 |
+
provider.name.toLowerCase().includes(searchTerm.toLowerCase()),
|
24 |
+
);
|
25 |
+
}
|
26 |
+
|
27 |
+
if (!isLocalModel) {
|
28 |
+
newFilteredProviders = newFilteredProviders.filter((provider) => !LOCAL_PROVIDERS.includes(provider.name));
|
29 |
+
}
|
30 |
+
|
31 |
+
newFilteredProviders.sort((a, b) => a.name.localeCompare(b.name));
|
32 |
+
|
33 |
+
setFilteredProviders(newFilteredProviders);
|
34 |
+
}, [providers, searchTerm, isLocalModel]);
|
35 |
+
|
36 |
+
return (
|
37 |
+
<div className="p-4">
|
38 |
+
<div className="flex mb-4">
|
39 |
+
<input
|
40 |
+
type="text"
|
41 |
+
placeholder="Search providers..."
|
42 |
+
value={searchTerm}
|
43 |
+
onChange={(e) => setSearchTerm(e.target.value)}
|
44 |
+
className="w-full bg-white dark:bg-bolt-elements-background-depth-4 relative px-2 py-1.5 rounded-md focus:outline-none placeholder-bolt-elements-textTertiary text-bolt-elements-textPrimary dark:text-bolt-elements-textPrimary border border-bolt-elements-borderColor"
|
45 |
+
/>
|
46 |
+
</div>
|
47 |
+
{filteredProviders.map((provider) => (
|
48 |
+
<div
|
49 |
+
key={provider.name}
|
50 |
+
className="flex flex-col mb-2 provider-item hover:bg-bolt-elements-bg-depth-3 p-4 rounded-lg border border-bolt-elements-borderColor "
|
51 |
+
>
|
52 |
+
<div className="flex items-center justify-between mb-2">
|
53 |
+
<div className="flex items-center gap-2">
|
54 |
+
<img src={`/icons/${provider.name}.svg`} alt={`${provider.name} icon`} className="w-6 h-6 dark:invert" />
|
55 |
+
<span className="text-bolt-elements-textPrimary">{provider.name}</span>
|
56 |
+
</div>
|
57 |
+
<Switch
|
58 |
+
className="ml-auto"
|
59 |
+
checked={provider.settings.enabled}
|
60 |
+
onCheckedChange={(enabled) => {
|
61 |
+
updateProviderSettings(provider.name, { ...provider.settings, enabled });
|
62 |
+
|
63 |
+
if (enabled) {
|
64 |
+
logStore.logProvider(`Provider ${provider.name} enabled`, { provider: provider.name });
|
65 |
+
} else {
|
66 |
+
logStore.logProvider(`Provider ${provider.name} disabled`, { provider: provider.name });
|
67 |
+
}
|
68 |
+
}}
|
69 |
+
/>
|
70 |
+
</div>
|
71 |
+
{/* Base URL input for configurable providers */}
|
72 |
+
{URL_CONFIGURABLE_PROVIDERS.includes(provider.name) && provider.settings.enabled && (
|
73 |
+
<div className="mt-2">
|
74 |
+
<label className="block text-sm text-bolt-elements-textSecondary mb-1">Base URL:</label>
|
75 |
+
<input
|
76 |
+
type="text"
|
77 |
+
value={provider.settings.baseUrl || ''}
|
78 |
+
onChange={(e) => {
|
79 |
+
const newBaseUrl = e.target.value;
|
80 |
+
updateProviderSettings(provider.name, { ...provider.settings, baseUrl: newBaseUrl });
|
81 |
+
logStore.logProvider(`Base URL updated for ${provider.name}`, {
|
82 |
+
provider: provider.name,
|
83 |
+
baseUrl: newBaseUrl,
|
84 |
+
});
|
85 |
+
}}
|
86 |
+
placeholder={`Enter ${provider.name} base URL`}
|
87 |
+
className="w-full bg-white dark:bg-bolt-elements-background-depth-4 relative px-2 py-1.5 rounded-md focus:outline-none placeholder-bolt-elements-textTertiary text-bolt-elements-textPrimary dark:text-bolt-elements-textPrimary border border-bolt-elements-borderColor"
|
88 |
+
/>
|
89 |
+
</div>
|
90 |
+
)}
|
91 |
+
</div>
|
92 |
+
))}
|
93 |
+
</div>
|
94 |
+
);
|
95 |
+
}
|
app/components/sidebar/Menu.client.tsx
CHANGED
@@ -3,6 +3,8 @@ import { useCallback, useEffect, useRef, useState } from 'react';
|
|
3 |
import { toast } from 'react-toastify';
|
4 |
import { Dialog, DialogButton, DialogDescription, DialogRoot, DialogTitle } from '~/components/ui/Dialog';
|
5 |
import { ThemeSwitch } from '~/components/ui/ThemeSwitch';
|
|
|
|
|
6 |
import { db, deleteById, getAll, chatId, type ChatHistoryItem, useChatHistory } from '~/lib/persistence';
|
7 |
import { cubicEasingFn } from '~/utils/easings';
|
8 |
import { logger } from '~/utils/logger';
|
@@ -33,12 +35,32 @@ const menuVariants = {
|
|
33 |
|
34 |
type DialogContent = { type: 'delete'; item: ChatHistoryItem } | null;
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
export const Menu = () => {
|
37 |
const { duplicateCurrentChat, exportChat } = useChatHistory();
|
38 |
const menuRef = useRef<HTMLDivElement>(null);
|
39 |
const [list, setList] = useState<ChatHistoryItem[]>([]);
|
40 |
const [open, setOpen] = useState(false);
|
41 |
const [dialogContent, setDialogContent] = useState<DialogContent>(null);
|
|
|
42 |
|
43 |
const { filteredItems: filteredList, handleSearchChange } = useSearchFilter({
|
44 |
items: list,
|
@@ -123,18 +145,17 @@ export const Menu = () => {
|
|
123 |
variants={menuVariants}
|
124 |
className="flex selection-accent flex-col side-menu fixed top-0 w-[350px] h-full bg-bolt-elements-background-depth-2 border-r rounded-r-3xl border-bolt-elements-borderColor z-sidebar shadow-xl shadow-bolt-elements-sidebar-dropdownShadow text-sm"
|
125 |
>
|
126 |
-
<div className="
|
|
|
127 |
<div className="flex-1 flex flex-col h-full w-full overflow-hidden">
|
128 |
<div className="p-4 select-none">
|
129 |
<a
|
130 |
href="/"
|
131 |
-
className="flex gap-2 items-center bg-bolt-elements-sidebar-buttonBackgroundDefault text-bolt-elements-sidebar-buttonText hover:bg-bolt-elements-sidebar-buttonBackgroundHover rounded-md p-2 transition-theme"
|
132 |
>
|
133 |
<span className="inline-block i-bolt:chat scale-110" />
|
134 |
Start new chat
|
135 |
</a>
|
136 |
-
</div>
|
137 |
-
<div className="pl-4 pr-4 my-2">
|
138 |
<div className="relative w-full">
|
139 |
<input
|
140 |
className="w-full bg-white dark:bg-bolt-elements-background-depth-4 relative px-2 py-1.5 rounded-md focus:outline-none placeholder-bolt-elements-textTertiary text-bolt-elements-textPrimary dark:text-bolt-elements-textPrimary border border-bolt-elements-borderColor"
|
@@ -200,10 +221,12 @@ export const Menu = () => {
|
|
200 |
</Dialog>
|
201 |
</DialogRoot>
|
202 |
</div>
|
203 |
-
<div className="flex items-center border-t border-bolt-elements-borderColor p-4">
|
204 |
-
<
|
|
|
205 |
</div>
|
206 |
</div>
|
|
|
207 |
</motion.div>
|
208 |
);
|
209 |
};
|
|
|
3 |
import { toast } from 'react-toastify';
|
4 |
import { Dialog, DialogButton, DialogDescription, DialogRoot, DialogTitle } from '~/components/ui/Dialog';
|
5 |
import { ThemeSwitch } from '~/components/ui/ThemeSwitch';
|
6 |
+
import { SettingsWindow } from '~/components/settings/SettingsWindow';
|
7 |
+
import { SettingsButton } from '~/components/ui/SettingsButton';
|
8 |
import { db, deleteById, getAll, chatId, type ChatHistoryItem, useChatHistory } from '~/lib/persistence';
|
9 |
import { cubicEasingFn } from '~/utils/easings';
|
10 |
import { logger } from '~/utils/logger';
|
|
|
35 |
|
36 |
type DialogContent = { type: 'delete'; item: ChatHistoryItem } | null;
|
37 |
|
38 |
+
function CurrentDateTime() {
|
39 |
+
const [dateTime, setDateTime] = useState(new Date());
|
40 |
+
|
41 |
+
useEffect(() => {
|
42 |
+
const timer = setInterval(() => {
|
43 |
+
setDateTime(new Date());
|
44 |
+
}, 60000); // Update every minute
|
45 |
+
|
46 |
+
return () => clearInterval(timer);
|
47 |
+
}, []);
|
48 |
+
|
49 |
+
return (
|
50 |
+
<div className="flex items-center gap-2 px-4 py-3 font-bold text-gray-700 dark:text-gray-300 border-b border-bolt-elements-borderColor">
|
51 |
+
<div className="h-4 w-4 i-ph:clock-thin" />
|
52 |
+
{dateTime.toLocaleDateString()} {dateTime.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}
|
53 |
+
</div>
|
54 |
+
);
|
55 |
+
}
|
56 |
+
|
57 |
export const Menu = () => {
|
58 |
const { duplicateCurrentChat, exportChat } = useChatHistory();
|
59 |
const menuRef = useRef<HTMLDivElement>(null);
|
60 |
const [list, setList] = useState<ChatHistoryItem[]>([]);
|
61 |
const [open, setOpen] = useState(false);
|
62 |
const [dialogContent, setDialogContent] = useState<DialogContent>(null);
|
63 |
+
const [isSettingsOpen, setIsSettingsOpen] = useState(false);
|
64 |
|
65 |
const { filteredItems: filteredList, handleSearchChange } = useSearchFilter({
|
66 |
items: list,
|
|
|
145 |
variants={menuVariants}
|
146 |
className="flex selection-accent flex-col side-menu fixed top-0 w-[350px] h-full bg-bolt-elements-background-depth-2 border-r rounded-r-3xl border-bolt-elements-borderColor z-sidebar shadow-xl shadow-bolt-elements-sidebar-dropdownShadow text-sm"
|
147 |
>
|
148 |
+
<div className="h-[60px]" /> {/* Spacer for top margin */}
|
149 |
+
<CurrentDateTime />
|
150 |
<div className="flex-1 flex flex-col h-full w-full overflow-hidden">
|
151 |
<div className="p-4 select-none">
|
152 |
<a
|
153 |
href="/"
|
154 |
+
className="flex gap-2 items-center bg-bolt-elements-sidebar-buttonBackgroundDefault text-bolt-elements-sidebar-buttonText hover:bg-bolt-elements-sidebar-buttonBackgroundHover rounded-md p-2 transition-theme mb-4"
|
155 |
>
|
156 |
<span className="inline-block i-bolt:chat scale-110" />
|
157 |
Start new chat
|
158 |
</a>
|
|
|
|
|
159 |
<div className="relative w-full">
|
160 |
<input
|
161 |
className="w-full bg-white dark:bg-bolt-elements-background-depth-4 relative px-2 py-1.5 rounded-md focus:outline-none placeholder-bolt-elements-textTertiary text-bolt-elements-textPrimary dark:text-bolt-elements-textPrimary border border-bolt-elements-borderColor"
|
|
|
221 |
</Dialog>
|
222 |
</DialogRoot>
|
223 |
</div>
|
224 |
+
<div className="flex items-center justify-between border-t border-bolt-elements-borderColor p-4">
|
225 |
+
<SettingsButton onClick={() => setIsSettingsOpen(true)} />
|
226 |
+
<ThemeSwitch />
|
227 |
</div>
|
228 |
</div>
|
229 |
+
<SettingsWindow open={isSettingsOpen} onClose={() => setIsSettingsOpen(false)} />
|
230 |
</motion.div>
|
231 |
);
|
232 |
};
|
app/components/ui/BackgroundRays/index.tsx
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import styles from './styles.module.scss';
|
2 |
+
|
3 |
+
const BackgroundRays = () => {
|
4 |
+
return (
|
5 |
+
<div className={`${styles.rayContainer} `}>
|
6 |
+
<div className={`${styles.lightRay} ${styles.ray1}`}></div>
|
7 |
+
<div className={`${styles.lightRay} ${styles.ray2}`}></div>
|
8 |
+
<div className={`${styles.lightRay} ${styles.ray3}`}></div>
|
9 |
+
<div className={`${styles.lightRay} ${styles.ray4}`}></div>
|
10 |
+
<div className={`${styles.lightRay} ${styles.ray5}`}></div>
|
11 |
+
<div className={`${styles.lightRay} ${styles.ray6}`}></div>
|
12 |
+
<div className={`${styles.lightRay} ${styles.ray7}`}></div>
|
13 |
+
<div className={`${styles.lightRay} ${styles.ray8}`}></div>
|
14 |
+
</div>
|
15 |
+
);
|
16 |
+
};
|
17 |
+
|
18 |
+
export default BackgroundRays;
|
app/components/ui/BackgroundRays/styles.module.scss
ADDED
@@ -0,0 +1,246 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.rayContainer {
|
2 |
+
// Theme-specific colors
|
3 |
+
--ray-color-primary: color-mix(in srgb, var(--primary-color), transparent 30%);
|
4 |
+
--ray-color-secondary: color-mix(in srgb, var(--secondary-color), transparent 30%);
|
5 |
+
--ray-color-accent: color-mix(in srgb, var(--accent-color), transparent 30%);
|
6 |
+
|
7 |
+
// Theme-specific gradients
|
8 |
+
--ray-gradient-primary: radial-gradient(var(--ray-color-primary) 0%, transparent 70%);
|
9 |
+
--ray-gradient-secondary: radial-gradient(var(--ray-color-secondary) 0%, transparent 70%);
|
10 |
+
--ray-gradient-accent: radial-gradient(var(--ray-color-accent) 0%, transparent 70%);
|
11 |
+
|
12 |
+
position: fixed;
|
13 |
+
inset: 0;
|
14 |
+
overflow: hidden;
|
15 |
+
animation: fadeIn 1.5s ease-out;
|
16 |
+
pointer-events: none;
|
17 |
+
z-index: 0;
|
18 |
+
// background-color: transparent;
|
19 |
+
|
20 |
+
:global(html[data-theme='dark']) & {
|
21 |
+
mix-blend-mode: screen;
|
22 |
+
}
|
23 |
+
|
24 |
+
:global(html[data-theme='light']) & {
|
25 |
+
mix-blend-mode: multiply;
|
26 |
+
}
|
27 |
+
}
|
28 |
+
|
29 |
+
.lightRay {
|
30 |
+
position: absolute;
|
31 |
+
border-radius: 100%;
|
32 |
+
|
33 |
+
:global(html[data-theme='dark']) & {
|
34 |
+
mix-blend-mode: screen;
|
35 |
+
}
|
36 |
+
|
37 |
+
:global(html[data-theme='light']) & {
|
38 |
+
mix-blend-mode: multiply;
|
39 |
+
opacity: 0.4;
|
40 |
+
}
|
41 |
+
}
|
42 |
+
|
43 |
+
.ray1 {
|
44 |
+
width: 600px;
|
45 |
+
height: 800px;
|
46 |
+
background: var(--ray-gradient-primary);
|
47 |
+
transform: rotate(65deg);
|
48 |
+
top: -500px;
|
49 |
+
left: -100px;
|
50 |
+
filter: blur(80px);
|
51 |
+
opacity: 0.6;
|
52 |
+
animation: float1 15s infinite ease-in-out;
|
53 |
+
}
|
54 |
+
|
55 |
+
.ray2 {
|
56 |
+
width: 400px;
|
57 |
+
height: 600px;
|
58 |
+
background: var(--ray-gradient-secondary);
|
59 |
+
transform: rotate(-30deg);
|
60 |
+
top: -300px;
|
61 |
+
left: 200px;
|
62 |
+
filter: blur(60px);
|
63 |
+
opacity: 0.6;
|
64 |
+
animation: float2 18s infinite ease-in-out;
|
65 |
+
}
|
66 |
+
|
67 |
+
.ray3 {
|
68 |
+
width: 500px;
|
69 |
+
height: 400px;
|
70 |
+
background: var(--ray-gradient-accent);
|
71 |
+
top: -320px;
|
72 |
+
left: 500px;
|
73 |
+
filter: blur(65px);
|
74 |
+
opacity: 0.5;
|
75 |
+
animation: float3 20s infinite ease-in-out;
|
76 |
+
}
|
77 |
+
|
78 |
+
.ray4 {
|
79 |
+
width: 400px;
|
80 |
+
height: 450px;
|
81 |
+
background: var(--ray-gradient-secondary);
|
82 |
+
top: -350px;
|
83 |
+
left: 800px;
|
84 |
+
filter: blur(55px);
|
85 |
+
opacity: 0.55;
|
86 |
+
animation: float4 17s infinite ease-in-out;
|
87 |
+
}
|
88 |
+
|
89 |
+
.ray5 {
|
90 |
+
width: 350px;
|
91 |
+
height: 500px;
|
92 |
+
background: var(--ray-gradient-primary);
|
93 |
+
transform: rotate(-45deg);
|
94 |
+
top: -250px;
|
95 |
+
left: 1000px;
|
96 |
+
filter: blur(45px);
|
97 |
+
opacity: 0.6;
|
98 |
+
animation: float5 16s infinite ease-in-out;
|
99 |
+
}
|
100 |
+
|
101 |
+
.ray6 {
|
102 |
+
width: 300px;
|
103 |
+
height: 700px;
|
104 |
+
background: var(--ray-gradient-accent);
|
105 |
+
transform: rotate(75deg);
|
106 |
+
top: -400px;
|
107 |
+
left: 600px;
|
108 |
+
filter: blur(75px);
|
109 |
+
opacity: 0.45;
|
110 |
+
animation: float6 19s infinite ease-in-out;
|
111 |
+
}
|
112 |
+
|
113 |
+
.ray7 {
|
114 |
+
width: 450px;
|
115 |
+
height: 600px;
|
116 |
+
background: var(--ray-gradient-primary);
|
117 |
+
transform: rotate(45deg);
|
118 |
+
top: -450px;
|
119 |
+
left: 350px;
|
120 |
+
filter: blur(65px);
|
121 |
+
opacity: 0.55;
|
122 |
+
animation: float7 21s infinite ease-in-out;
|
123 |
+
}
|
124 |
+
|
125 |
+
.ray8 {
|
126 |
+
width: 380px;
|
127 |
+
height: 550px;
|
128 |
+
background: var(--ray-gradient-secondary);
|
129 |
+
transform: rotate(-60deg);
|
130 |
+
top: -380px;
|
131 |
+
left: 750px;
|
132 |
+
filter: blur(58px);
|
133 |
+
opacity: 0.6;
|
134 |
+
animation: float8 14s infinite ease-in-out;
|
135 |
+
}
|
136 |
+
|
137 |
+
@keyframes float1 {
|
138 |
+
0%,
|
139 |
+
100% {
|
140 |
+
transform: rotate(65deg) translate(0, 0);
|
141 |
+
}
|
142 |
+
25% {
|
143 |
+
transform: rotate(70deg) translate(30px, 20px);
|
144 |
+
}
|
145 |
+
50% {
|
146 |
+
transform: rotate(60deg) translate(-20px, 40px);
|
147 |
+
}
|
148 |
+
75% {
|
149 |
+
transform: rotate(68deg) translate(-40px, 10px);
|
150 |
+
}
|
151 |
+
}
|
152 |
+
|
153 |
+
@keyframes float2 {
|
154 |
+
0%,
|
155 |
+
100% {
|
156 |
+
transform: rotate(-30deg) scale(1);
|
157 |
+
}
|
158 |
+
33% {
|
159 |
+
transform: rotate(-25deg) scale(1.1);
|
160 |
+
}
|
161 |
+
66% {
|
162 |
+
transform: rotate(-35deg) scale(0.95);
|
163 |
+
}
|
164 |
+
}
|
165 |
+
|
166 |
+
@keyframes float3 {
|
167 |
+
0%,
|
168 |
+
100% {
|
169 |
+
transform: translate(0, 0) rotate(0deg);
|
170 |
+
}
|
171 |
+
25% {
|
172 |
+
transform: translate(40px, 20px) rotate(5deg);
|
173 |
+
}
|
174 |
+
75% {
|
175 |
+
transform: translate(-30px, 40px) rotate(-5deg);
|
176 |
+
}
|
177 |
+
}
|
178 |
+
|
179 |
+
@keyframes float4 {
|
180 |
+
0%,
|
181 |
+
100% {
|
182 |
+
transform: scale(1) rotate(0deg);
|
183 |
+
}
|
184 |
+
50% {
|
185 |
+
transform: scale(1.15) rotate(10deg);
|
186 |
+
}
|
187 |
+
}
|
188 |
+
|
189 |
+
@keyframes float5 {
|
190 |
+
0%,
|
191 |
+
100% {
|
192 |
+
transform: rotate(-45deg) translate(0, 0);
|
193 |
+
}
|
194 |
+
33% {
|
195 |
+
transform: rotate(-40deg) translate(25px, -20px);
|
196 |
+
}
|
197 |
+
66% {
|
198 |
+
transform: rotate(-50deg) translate(-25px, 20px);
|
199 |
+
}
|
200 |
+
}
|
201 |
+
|
202 |
+
@keyframes float6 {
|
203 |
+
0%,
|
204 |
+
100% {
|
205 |
+
transform: rotate(75deg) scale(1);
|
206 |
+
filter: blur(75px);
|
207 |
+
}
|
208 |
+
50% {
|
209 |
+
transform: rotate(85deg) scale(1.1);
|
210 |
+
filter: blur(65px);
|
211 |
+
}
|
212 |
+
}
|
213 |
+
|
214 |
+
@keyframes float7 {
|
215 |
+
0%,
|
216 |
+
100% {
|
217 |
+
transform: rotate(45deg) translate(0, 0);
|
218 |
+
opacity: 0.55;
|
219 |
+
}
|
220 |
+
50% {
|
221 |
+
transform: rotate(40deg) translate(-30px, 30px);
|
222 |
+
opacity: 0.65;
|
223 |
+
}
|
224 |
+
}
|
225 |
+
|
226 |
+
@keyframes float8 {
|
227 |
+
0%,
|
228 |
+
100% {
|
229 |
+
transform: rotate(-60deg) scale(1);
|
230 |
+
}
|
231 |
+
25% {
|
232 |
+
transform: rotate(-55deg) scale(1.05);
|
233 |
+
}
|
234 |
+
75% {
|
235 |
+
transform: rotate(-65deg) scale(0.95);
|
236 |
+
}
|
237 |
+
}
|
238 |
+
|
239 |
+
@keyframes fadeIn {
|
240 |
+
from {
|
241 |
+
opacity: 0;
|
242 |
+
}
|
243 |
+
to {
|
244 |
+
opacity: 1;
|
245 |
+
}
|
246 |
+
}
|
app/components/ui/SettingsButton.tsx
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { memo } from 'react';
|
2 |
+
import { IconButton } from '~/components/ui/IconButton';
|
3 |
+
interface SettingsButtonProps {
|
4 |
+
onClick: () => void;
|
5 |
+
}
|
6 |
+
|
7 |
+
export const SettingsButton = memo(({ onClick }: SettingsButtonProps) => {
|
8 |
+
return (
|
9 |
+
<IconButton
|
10 |
+
onClick={onClick}
|
11 |
+
icon="i-ph:gear"
|
12 |
+
size="xl"
|
13 |
+
title="Settings"
|
14 |
+
className="text-[#666] hover:text-bolt-elements-textPrimary hover:bg-bolt-elements-item-backgroundActive/10 transition-colors"
|
15 |
+
/>
|
16 |
+
);
|
17 |
+
});
|
app/components/ui/Switch.tsx
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { memo } from 'react';
|
2 |
+
import * as SwitchPrimitive from '@radix-ui/react-switch';
|
3 |
+
import { classNames } from '~/utils/classNames';
|
4 |
+
|
5 |
+
interface SwitchProps {
|
6 |
+
className?: string;
|
7 |
+
checked?: boolean;
|
8 |
+
onCheckedChange?: (event: boolean) => void;
|
9 |
+
}
|
10 |
+
|
11 |
+
export const Switch = memo(({ className, onCheckedChange, checked }: SwitchProps) => {
|
12 |
+
return (
|
13 |
+
<SwitchPrimitive.Root
|
14 |
+
className={classNames(
|
15 |
+
'relative h-6 w-11 cursor-pointer rounded-full bg-bolt-elements-button-primary-background',
|
16 |
+
'transition-colors duration-200 ease-in-out',
|
17 |
+
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2',
|
18 |
+
'disabled:cursor-not-allowed disabled:opacity-50',
|
19 |
+
'data-[state=checked]:bg-bolt-elements-item-contentAccent',
|
20 |
+
className,
|
21 |
+
)}
|
22 |
+
checked={checked}
|
23 |
+
onCheckedChange={(e) => onCheckedChange?.(e)}
|
24 |
+
>
|
25 |
+
<SwitchPrimitive.Thumb
|
26 |
+
className={classNames(
|
27 |
+
'block h-5 w-5 rounded-full bg-white',
|
28 |
+
'shadow-lg shadow-black/20',
|
29 |
+
'transition-transform duration-200 ease-in-out',
|
30 |
+
'translate-x-0.5',
|
31 |
+
'data-[state=checked]:translate-x-[1.375rem]',
|
32 |
+
'will-change-transform',
|
33 |
+
)}
|
34 |
+
/>
|
35 |
+
</SwitchPrimitive.Root>
|
36 |
+
);
|
37 |
+
});
|
app/components/workbench/Preview.tsx
CHANGED
@@ -5,11 +5,16 @@ import { workbenchStore } from '~/lib/stores/workbench';
|
|
5 |
import { PortDropdown } from './PortDropdown';
|
6 |
import { ScreenshotSelector } from './ScreenshotSelector';
|
7 |
|
|
|
|
|
8 |
export const Preview = memo(() => {
|
9 |
const iframeRef = useRef<HTMLIFrameElement>(null);
|
|
|
10 |
const inputRef = useRef<HTMLInputElement>(null);
|
|
|
11 |
const [activePreviewIndex, setActivePreviewIndex] = useState(0);
|
12 |
const [isPortDropdownOpen, setIsPortDropdownOpen] = useState(false);
|
|
|
13 |
const hasSelectedPreview = useRef(false);
|
14 |
const previews = useStore(workbenchStore.previews);
|
15 |
const activePreview = previews[activePreviewIndex];
|
@@ -18,6 +23,23 @@ export const Preview = memo(() => {
|
|
18 |
const [iframeUrl, setIframeUrl] = useState<string | undefined>();
|
19 |
const [isSelectionMode, setIsSelectionMode] = useState(false);
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
useEffect(() => {
|
22 |
if (!activePreview) {
|
23 |
setUrl('');
|
@@ -27,10 +49,9 @@ export const Preview = memo(() => {
|
|
27 |
}
|
28 |
|
29 |
const { baseUrl } = activePreview;
|
30 |
-
|
31 |
setUrl(baseUrl);
|
32 |
setIframeUrl(baseUrl);
|
33 |
-
}, [activePreview
|
34 |
|
35 |
const validateUrl = useCallback(
|
36 |
(value: string) => {
|
@@ -58,14 +79,13 @@ export const Preview = memo(() => {
|
|
58 |
[],
|
59 |
);
|
60 |
|
61 |
-
//
|
62 |
useEffect(() => {
|
63 |
if (previews.length > 1 && !hasSelectedPreview.current) {
|
64 |
const minPortIndex = previews.reduce(findMinPortIndex, 0);
|
65 |
-
|
66 |
setActivePreviewIndex(minPortIndex);
|
67 |
}
|
68 |
-
}, [previews]);
|
69 |
|
70 |
const reloadPreview = () => {
|
71 |
if (iframeRef.current) {
|
@@ -73,8 +93,128 @@ export const Preview = memo(() => {
|
|
73 |
}
|
74 |
};
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
return (
|
77 |
-
<div className="w-full h-full flex flex-col">
|
78 |
{isPortDropdownOpen && (
|
79 |
<div className="z-iframe-overlay w-full h-full absolute" onClick={() => setIsPortDropdownOpen(false)} />
|
80 |
)}
|
@@ -109,6 +249,7 @@ export const Preview = memo(() => {
|
|
109 |
}}
|
110 |
/>
|
111 |
</div>
|
|
|
112 |
{previews.length > 1 && (
|
113 |
<PortDropdown
|
114 |
activePreviewIndex={activePreviewIndex}
|
@@ -119,20 +260,100 @@ export const Preview = memo(() => {
|
|
119 |
previews={previews}
|
120 |
/>
|
121 |
)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
</div>
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
isSelectionMode={isSelectionMode}
|
129 |
setIsSelectionMode={setIsSelectionMode}
|
130 |
containerRef={iframeRef}
|
131 |
/>
|
132 |
</>
|
133 |
) : (
|
134 |
-
|
135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
</div>
|
137 |
</div>
|
138 |
);
|
|
|
5 |
import { PortDropdown } from './PortDropdown';
|
6 |
import { ScreenshotSelector } from './ScreenshotSelector';
|
7 |
|
8 |
+
type ResizeSide = 'left' | 'right' | null;
|
9 |
+
|
10 |
export const Preview = memo(() => {
|
11 |
const iframeRef = useRef<HTMLIFrameElement>(null);
|
12 |
+
const containerRef = useRef<HTMLDivElement>(null);
|
13 |
const inputRef = useRef<HTMLInputElement>(null);
|
14 |
+
|
15 |
const [activePreviewIndex, setActivePreviewIndex] = useState(0);
|
16 |
const [isPortDropdownOpen, setIsPortDropdownOpen] = useState(false);
|
17 |
+
const [isFullscreen, setIsFullscreen] = useState(false);
|
18 |
const hasSelectedPreview = useRef(false);
|
19 |
const previews = useStore(workbenchStore.previews);
|
20 |
const activePreview = previews[activePreviewIndex];
|
|
|
23 |
const [iframeUrl, setIframeUrl] = useState<string | undefined>();
|
24 |
const [isSelectionMode, setIsSelectionMode] = useState(false);
|
25 |
|
26 |
+
// Toggle between responsive mode and device mode
|
27 |
+
const [isDeviceModeOn, setIsDeviceModeOn] = useState(false);
|
28 |
+
|
29 |
+
// Use percentage for width
|
30 |
+
const [widthPercent, setWidthPercent] = useState<number>(37.5); // 375px assuming 1000px window width initially
|
31 |
+
|
32 |
+
const resizingState = useRef({
|
33 |
+
isResizing: false,
|
34 |
+
side: null as ResizeSide,
|
35 |
+
startX: 0,
|
36 |
+
startWidthPercent: 37.5,
|
37 |
+
windowWidth: window.innerWidth,
|
38 |
+
});
|
39 |
+
|
40 |
+
// Define the scaling factor
|
41 |
+
const SCALING_FACTOR = 2; // Adjust this value to increase/decrease sensitivity
|
42 |
+
|
43 |
useEffect(() => {
|
44 |
if (!activePreview) {
|
45 |
setUrl('');
|
|
|
49 |
}
|
50 |
|
51 |
const { baseUrl } = activePreview;
|
|
|
52 |
setUrl(baseUrl);
|
53 |
setIframeUrl(baseUrl);
|
54 |
+
}, [activePreview]);
|
55 |
|
56 |
const validateUrl = useCallback(
|
57 |
(value: string) => {
|
|
|
79 |
[],
|
80 |
);
|
81 |
|
82 |
+
// When previews change, display the lowest port if user hasn't selected a preview
|
83 |
useEffect(() => {
|
84 |
if (previews.length > 1 && !hasSelectedPreview.current) {
|
85 |
const minPortIndex = previews.reduce(findMinPortIndex, 0);
|
|
|
86 |
setActivePreviewIndex(minPortIndex);
|
87 |
}
|
88 |
+
}, [previews, findMinPortIndex]);
|
89 |
|
90 |
const reloadPreview = () => {
|
91 |
if (iframeRef.current) {
|
|
|
93 |
}
|
94 |
};
|
95 |
|
96 |
+
const toggleFullscreen = async () => {
|
97 |
+
if (!isFullscreen && containerRef.current) {
|
98 |
+
await containerRef.current.requestFullscreen();
|
99 |
+
} else if (document.fullscreenElement) {
|
100 |
+
await document.exitFullscreen();
|
101 |
+
}
|
102 |
+
};
|
103 |
+
|
104 |
+
useEffect(() => {
|
105 |
+
const handleFullscreenChange = () => {
|
106 |
+
setIsFullscreen(!!document.fullscreenElement);
|
107 |
+
};
|
108 |
+
|
109 |
+
document.addEventListener('fullscreenchange', handleFullscreenChange);
|
110 |
+
|
111 |
+
return () => {
|
112 |
+
document.removeEventListener('fullscreenchange', handleFullscreenChange);
|
113 |
+
};
|
114 |
+
}, []);
|
115 |
+
|
116 |
+
const toggleDeviceMode = () => {
|
117 |
+
setIsDeviceModeOn((prev) => !prev);
|
118 |
+
};
|
119 |
+
|
120 |
+
const startResizing = (e: React.MouseEvent, side: ResizeSide) => {
|
121 |
+
if (!isDeviceModeOn) {
|
122 |
+
return;
|
123 |
+
}
|
124 |
+
|
125 |
+
// Prevent text selection
|
126 |
+
document.body.style.userSelect = 'none';
|
127 |
+
|
128 |
+
resizingState.current.isResizing = true;
|
129 |
+
resizingState.current.side = side;
|
130 |
+
resizingState.current.startX = e.clientX;
|
131 |
+
resizingState.current.startWidthPercent = widthPercent;
|
132 |
+
resizingState.current.windowWidth = window.innerWidth;
|
133 |
+
|
134 |
+
document.addEventListener('mousemove', onMouseMove);
|
135 |
+
document.addEventListener('mouseup', onMouseUp);
|
136 |
+
|
137 |
+
e.preventDefault(); // Prevent any text selection on mousedown
|
138 |
+
};
|
139 |
+
|
140 |
+
const onMouseMove = (e: MouseEvent) => {
|
141 |
+
if (!resizingState.current.isResizing) {
|
142 |
+
return;
|
143 |
+
}
|
144 |
+
|
145 |
+
const dx = e.clientX - resizingState.current.startX;
|
146 |
+
const windowWidth = resizingState.current.windowWidth;
|
147 |
+
|
148 |
+
// Apply scaling factor to increase sensitivity
|
149 |
+
const dxPercent = (dx / windowWidth) * 100 * SCALING_FACTOR;
|
150 |
+
|
151 |
+
let newWidthPercent = resizingState.current.startWidthPercent;
|
152 |
+
|
153 |
+
if (resizingState.current.side === 'right') {
|
154 |
+
newWidthPercent = resizingState.current.startWidthPercent + dxPercent;
|
155 |
+
} else if (resizingState.current.side === 'left') {
|
156 |
+
newWidthPercent = resizingState.current.startWidthPercent - dxPercent;
|
157 |
+
}
|
158 |
+
|
159 |
+
// Clamp the width between 10% and 90%
|
160 |
+
newWidthPercent = Math.max(10, Math.min(newWidthPercent, 90));
|
161 |
+
|
162 |
+
setWidthPercent(newWidthPercent);
|
163 |
+
};
|
164 |
+
|
165 |
+
const onMouseUp = () => {
|
166 |
+
resizingState.current.isResizing = false;
|
167 |
+
resizingState.current.side = null;
|
168 |
+
document.removeEventListener('mousemove', onMouseMove);
|
169 |
+
document.removeEventListener('mouseup', onMouseUp);
|
170 |
+
|
171 |
+
// Restore text selection
|
172 |
+
document.body.style.userSelect = '';
|
173 |
+
};
|
174 |
+
|
175 |
+
// Handle window resize to ensure widthPercent remains valid
|
176 |
+
useEffect(() => {
|
177 |
+
const handleWindowResize = () => {
|
178 |
+
/*
|
179 |
+
* Optional: Adjust widthPercent if necessary
|
180 |
+
* For now, since widthPercent is relative, no action is needed
|
181 |
+
*/
|
182 |
+
};
|
183 |
+
|
184 |
+
window.addEventListener('resize', handleWindowResize);
|
185 |
+
|
186 |
+
return () => {
|
187 |
+
window.removeEventListener('resize', handleWindowResize);
|
188 |
+
};
|
189 |
+
}, []);
|
190 |
+
|
191 |
+
// A small helper component for the handle's "grip" icon
|
192 |
+
const GripIcon = () => (
|
193 |
+
<div
|
194 |
+
style={{
|
195 |
+
display: 'flex',
|
196 |
+
justifyContent: 'center',
|
197 |
+
alignItems: 'center',
|
198 |
+
height: '100%',
|
199 |
+
pointerEvents: 'none',
|
200 |
+
}}
|
201 |
+
>
|
202 |
+
<div
|
203 |
+
style={{
|
204 |
+
color: 'rgba(0,0,0,0.5)',
|
205 |
+
fontSize: '10px',
|
206 |
+
lineHeight: '5px',
|
207 |
+
userSelect: 'none',
|
208 |
+
marginLeft: '1px',
|
209 |
+
}}
|
210 |
+
>
|
211 |
+
••• •••
|
212 |
+
</div>
|
213 |
+
</div>
|
214 |
+
);
|
215 |
+
|
216 |
return (
|
217 |
+
<div ref={containerRef} className="w-full h-full flex flex-col relative">
|
218 |
{isPortDropdownOpen && (
|
219 |
<div className="z-iframe-overlay w-full h-full absolute" onClick={() => setIsPortDropdownOpen(false)} />
|
220 |
)}
|
|
|
249 |
}}
|
250 |
/>
|
251 |
</div>
|
252 |
+
|
253 |
{previews.length > 1 && (
|
254 |
<PortDropdown
|
255 |
activePreviewIndex={activePreviewIndex}
|
|
|
260 |
previews={previews}
|
261 |
/>
|
262 |
)}
|
263 |
+
|
264 |
+
{/* Device mode toggle button */}
|
265 |
+
<IconButton
|
266 |
+
icon="i-ph:devices"
|
267 |
+
onClick={toggleDeviceMode}
|
268 |
+
title={isDeviceModeOn ? 'Switch to Responsive Mode' : 'Switch to Device Mode'}
|
269 |
+
/>
|
270 |
+
|
271 |
+
{/* Fullscreen toggle button */}
|
272 |
+
<IconButton
|
273 |
+
icon={isFullscreen ? 'i-ph:arrows-in' : 'i-ph:arrows-out'}
|
274 |
+
onClick={toggleFullscreen}
|
275 |
+
title={isFullscreen ? 'Exit Full Screen' : 'Full Screen'}
|
276 |
+
/>
|
277 |
</div>
|
278 |
+
|
279 |
+
<div className="flex-1 border-t border-bolt-elements-borderColor flex justify-center items-center overflow-auto">
|
280 |
+
<div
|
281 |
+
style={{
|
282 |
+
width: isDeviceModeOn ? `${widthPercent}%` : '100%',
|
283 |
+
height: '100%', // Always full height
|
284 |
+
overflow: 'visible',
|
285 |
+
background: '#fff',
|
286 |
+
position: 'relative',
|
287 |
+
display: 'flex',
|
288 |
+
}}
|
289 |
+
>
|
290 |
+
{activePreview ? (
|
291 |
+
<>
|
292 |
+
<iframe ref={iframeRef} title="preview" className="border-none w-full h-full bg-white" src={iframeUrl} allowFullScreen />
|
293 |
+
<ScreenshotSelector
|
294 |
isSelectionMode={isSelectionMode}
|
295 |
setIsSelectionMode={setIsSelectionMode}
|
296 |
containerRef={iframeRef}
|
297 |
/>
|
298 |
</>
|
299 |
) : (
|
300 |
+
<div className="flex w-full h-full justify-center items-center bg-white">No preview available</div>
|
301 |
+
)}
|
302 |
+
|
303 |
+
{isDeviceModeOn && (
|
304 |
+
<>
|
305 |
+
{/* Left handle */}
|
306 |
+
<div
|
307 |
+
onMouseDown={(e) => startResizing(e, 'left')}
|
308 |
+
style={{
|
309 |
+
position: 'absolute',
|
310 |
+
top: 0,
|
311 |
+
left: 0,
|
312 |
+
width: '15px',
|
313 |
+
marginLeft: '-15px',
|
314 |
+
height: '100%',
|
315 |
+
cursor: 'ew-resize',
|
316 |
+
background: 'rgba(255,255,255,.2)',
|
317 |
+
display: 'flex',
|
318 |
+
alignItems: 'center',
|
319 |
+
justifyContent: 'center',
|
320 |
+
transition: 'background 0.2s',
|
321 |
+
userSelect: 'none',
|
322 |
+
}}
|
323 |
+
onMouseOver={(e) => (e.currentTarget.style.background = 'rgba(255,255,255,.5)')}
|
324 |
+
onMouseOut={(e) => (e.currentTarget.style.background = 'rgba(255,255,255,.2)')}
|
325 |
+
title="Drag to resize width"
|
326 |
+
>
|
327 |
+
<GripIcon />
|
328 |
+
</div>
|
329 |
+
|
330 |
+
{/* Right handle */}
|
331 |
+
<div
|
332 |
+
onMouseDown={(e) => startResizing(e, 'right')}
|
333 |
+
style={{
|
334 |
+
position: 'absolute',
|
335 |
+
top: 0,
|
336 |
+
right: 0,
|
337 |
+
width: '15px',
|
338 |
+
marginRight: '-15px',
|
339 |
+
height: '100%',
|
340 |
+
cursor: 'ew-resize',
|
341 |
+
background: 'rgba(255,255,255,.2)',
|
342 |
+
display: 'flex',
|
343 |
+
alignItems: 'center',
|
344 |
+
justifyContent: 'center',
|
345 |
+
transition: 'background 0.2s',
|
346 |
+
userSelect: 'none',
|
347 |
+
}}
|
348 |
+
onMouseOver={(e) => (e.currentTarget.style.background = 'rgba(255,255,255,.5)')}
|
349 |
+
onMouseOut={(e) => (e.currentTarget.style.background = 'rgba(255,255,255,.2)')}
|
350 |
+
title="Drag to resize width"
|
351 |
+
>
|
352 |
+
<GripIcon />
|
353 |
+
</div>
|
354 |
+
</>
|
355 |
+
)}
|
356 |
+
</div>
|
357 |
</div>
|
358 |
</div>
|
359 |
);
|
app/components/workbench/ScreenshotSelector.tsx
CHANGED
@@ -117,7 +117,7 @@ export const ScreenshotSelector = memo(
|
|
117 |
|
118 |
// Get window scroll position
|
119 |
const scrollX = window.scrollX;
|
120 |
-
const scrollY = window.scrollY;
|
121 |
|
122 |
// Get the container's position in the page
|
123 |
const containerRect = containerRef.current.getBoundingClientRect();
|
|
|
117 |
|
118 |
// Get window scroll position
|
119 |
const scrollX = window.scrollX;
|
120 |
+
const scrollY = window.scrollY + 40;
|
121 |
|
122 |
// Get the container's position in the page
|
123 |
const containerRect = containerRef.current.getBoundingClientRect();
|
app/components/workbench/Workbench.client.tsx
CHANGED
@@ -17,6 +17,7 @@ import { renderLogger } from '~/utils/logger';
|
|
17 |
import { EditorPanel } from './EditorPanel';
|
18 |
import { Preview } from './Preview';
|
19 |
import useViewport from '~/lib/hooks';
|
|
|
20 |
|
21 |
interface WorkspaceProps {
|
22 |
chatStarted?: boolean;
|
@@ -180,21 +181,22 @@ export const Workbench = memo(({ chatStarted, isStreaming }: WorkspaceProps) =>
|
|
180 |
return;
|
181 |
}
|
182 |
|
183 |
-
const githubUsername =
|
|
|
184 |
|
185 |
-
if (!githubUsername) {
|
186 |
-
|
187 |
-
|
188 |
-
}
|
189 |
|
190 |
-
|
|
|
|
|
|
|
191 |
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
}
|
196 |
-
|
197 |
-
workbenchStore.pushToGitHub(repoName, githubUsername, githubToken);
|
198 |
}}
|
199 |
>
|
200 |
<div className="i-ph:github-logo" />
|
|
|
17 |
import { EditorPanel } from './EditorPanel';
|
18 |
import { Preview } from './Preview';
|
19 |
import useViewport from '~/lib/hooks';
|
20 |
+
import Cookies from 'js-cookie';
|
21 |
|
22 |
interface WorkspaceProps {
|
23 |
chatStarted?: boolean;
|
|
|
181 |
return;
|
182 |
}
|
183 |
|
184 |
+
const githubUsername = Cookies.get('githubUsername');
|
185 |
+
const githubToken = Cookies.get('githubToken');
|
186 |
|
187 |
+
if (!githubUsername || !githubToken) {
|
188 |
+
const usernameInput = prompt('Please enter your GitHub username:');
|
189 |
+
const tokenInput = prompt('Please enter your GitHub personal access token:');
|
|
|
190 |
|
191 |
+
if (!usernameInput || !tokenInput) {
|
192 |
+
alert('GitHub username and token are required. Push to GitHub cancelled.');
|
193 |
+
return;
|
194 |
+
}
|
195 |
|
196 |
+
workbenchStore.pushToGitHub(repoName, usernameInput, tokenInput);
|
197 |
+
} else {
|
198 |
+
workbenchStore.pushToGitHub(repoName, githubUsername, githubToken);
|
199 |
}
|
|
|
|
|
200 |
}}
|
201 |
>
|
202 |
<div className="i-ph:github-logo" />
|
app/lib/.server/llm/api-key.ts
CHANGED
@@ -51,7 +51,7 @@ export function getAPIKey(cloudflareEnv: Env, provider: string, userApiKeys?: Re
|
|
51 |
export function getBaseURL(cloudflareEnv: Env, provider: string) {
|
52 |
switch (provider) {
|
53 |
case 'Together':
|
54 |
-
return env.TOGETHER_API_BASE_URL || cloudflareEnv.TOGETHER_API_BASE_URL;
|
55 |
case 'OpenAILike':
|
56 |
return env.OPENAI_LIKE_API_BASE_URL || cloudflareEnv.OPENAI_LIKE_API_BASE_URL;
|
57 |
case 'LMStudio':
|
|
|
51 |
export function getBaseURL(cloudflareEnv: Env, provider: string) {
|
52 |
switch (provider) {
|
53 |
case 'Together':
|
54 |
+
return env.TOGETHER_API_BASE_URL || cloudflareEnv.TOGETHER_API_BASE_URL || 'https://api.together.xyz/v1';
|
55 |
case 'OpenAILike':
|
56 |
return env.OPENAI_LIKE_API_BASE_URL || cloudflareEnv.OPENAI_LIKE_API_BASE_URL;
|
57 |
case 'LMStudio':
|
app/lib/.server/llm/model.ts
CHANGED
@@ -11,6 +11,7 @@ import { createOpenRouter } from '@openrouter/ai-sdk-provider';
|
|
11 |
import { createMistral } from '@ai-sdk/mistral';
|
12 |
import { createCohere } from '@ai-sdk/cohere';
|
13 |
import type { LanguageModelV1 } from 'ai';
|
|
|
14 |
|
15 |
export const DEFAULT_NUM_CTX = process.env.DEFAULT_NUM_CTX ? parseInt(process.env.DEFAULT_NUM_CTX, 10) : 32768;
|
16 |
|
@@ -127,14 +128,20 @@ export function getXAIModel(apiKey: OptionalApiKey, model: string) {
|
|
127 |
return openai(model);
|
128 |
}
|
129 |
|
130 |
-
export function getModel(
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
/*
|
132 |
* let apiKey; // Declare first
|
133 |
* let baseURL;
|
134 |
*/
|
135 |
|
136 |
const apiKey = getAPIKey(env, provider, apiKeys); // Then assign
|
137 |
-
const baseURL = getBaseURL(env, provider);
|
138 |
|
139 |
switch (provider) {
|
140 |
case 'Anthropic':
|
|
|
11 |
import { createMistral } from '@ai-sdk/mistral';
|
12 |
import { createCohere } from '@ai-sdk/cohere';
|
13 |
import type { LanguageModelV1 } from 'ai';
|
14 |
+
import type { IProviderSetting } from '~/types/model';
|
15 |
|
16 |
export const DEFAULT_NUM_CTX = process.env.DEFAULT_NUM_CTX ? parseInt(process.env.DEFAULT_NUM_CTX, 10) : 32768;
|
17 |
|
|
|
128 |
return openai(model);
|
129 |
}
|
130 |
|
131 |
+
export function getModel(
|
132 |
+
provider: string,
|
133 |
+
model: string,
|
134 |
+
env: Env,
|
135 |
+
apiKeys?: Record<string, string>,
|
136 |
+
providerSettings?: Record<string, IProviderSetting>,
|
137 |
+
) {
|
138 |
/*
|
139 |
* let apiKey; // Declare first
|
140 |
* let baseURL;
|
141 |
*/
|
142 |
|
143 |
const apiKey = getAPIKey(env, provider, apiKeys); // Then assign
|
144 |
+
const baseURL = providerSettings?.[provider].baseUrl || getBaseURL(env, provider);
|
145 |
|
146 |
switch (provider) {
|
147 |
case 'Anthropic':
|
app/lib/.server/llm/prompts.ts
CHANGED
@@ -174,14 +174,14 @@ You are Bolt, an expert AI assistant and exceptional senior software developer w
|
|
174 |
|
175 |
- When Using \`npx\`, ALWAYS provide the \`--yes\` flag.
|
176 |
- When running multiple shell commands, use \`&&\` to run them sequentially.
|
177 |
-
- ULTRA IMPORTANT: Do NOT
|
178 |
|
179 |
- file: For writing new files or updating existing files. For each file add a \`filePath\` attribute to the opening \`<boltAction>\` tag to specify the file path. The content of the file artifact is the file contents. All file paths MUST BE relative to the current working directory.
|
180 |
|
181 |
-
- start: For starting development server.
|
182 |
-
- Use to start application if
|
183 |
-
- Only use this action when you need to run a dev server
|
184 |
-
- ULTRA
|
185 |
|
186 |
|
187 |
9. The order of the actions is VERY IMPORTANT. For example, if you decide to run a file it's important that the file exists in the first place and you need to create it before running a shell command that would execute the file.
|
|
|
174 |
|
175 |
- When Using \`npx\`, ALWAYS provide the \`--yes\` flag.
|
176 |
- When running multiple shell commands, use \`&&\` to run them sequentially.
|
177 |
+
- ULTRA IMPORTANT: Do NOT run a dev command with shell action use start action to run dev commands
|
178 |
|
179 |
- file: For writing new files or updating existing files. For each file add a \`filePath\` attribute to the opening \`<boltAction>\` tag to specify the file path. The content of the file artifact is the file contents. All file paths MUST BE relative to the current working directory.
|
180 |
|
181 |
+
- start: For starting a development server.
|
182 |
+
- Use to start application if it hasn’t been started yet or when NEW dependencies have been added.
|
183 |
+
- Only use this action when you need to run a dev server or start the application
|
184 |
+
- ULTRA IMPORTANT: do NOT re-run a dev server if files are updated. The existing dev server can automatically detect changes and executes the file changes
|
185 |
|
186 |
|
187 |
9. The order of the actions is VERY IMPORTANT. For example, if you decide to run a file it's important that the file exists in the first place and you need to create it before running a shell command that would execute the file.
|
app/lib/.server/llm/stream-text.ts
CHANGED
@@ -1,11 +1,9 @@
|
|
1 |
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
2 |
-
// @ts-nocheck – TODO: Provider proper types
|
3 |
-
|
4 |
import { convertToCoreMessages, streamText as _streamText } from 'ai';
|
5 |
import { getModel } from '~/lib/.server/llm/model';
|
6 |
import { MAX_TOKENS } from './constants';
|
7 |
import { getSystemPrompt } from './prompts';
|
8 |
-
import { DEFAULT_MODEL, DEFAULT_PROVIDER,
|
|
|
9 |
|
10 |
interface ToolResult<Name extends string, Args, Result> {
|
11 |
toolCallId: string;
|
@@ -43,7 +41,7 @@ function extractPropertiesFromMessage(message: Message): { model: string; provid
|
|
43 |
* Extract provider
|
44 |
* const providerMatch = message.content.match(PROVIDER_REGEX);
|
45 |
*/
|
46 |
-
const provider = providerMatch ? providerMatch[1] : DEFAULT_PROVIDER;
|
47 |
|
48 |
const cleanedContent = Array.isArray(message.content)
|
49 |
? message.content.map((item) => {
|
@@ -61,10 +59,17 @@ function extractPropertiesFromMessage(message: Message): { model: string; provid
|
|
61 |
return { model, provider, content: cleanedContent };
|
62 |
}
|
63 |
|
64 |
-
export function streamText(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
let currentModel = DEFAULT_MODEL;
|
66 |
-
let currentProvider = DEFAULT_PROVIDER;
|
67 |
-
|
68 |
const processedMessages = messages.map((message) => {
|
69 |
if (message.role === 'user') {
|
70 |
const { model, provider, content } = extractPropertiesFromMessage(message);
|
@@ -86,10 +91,10 @@ export function streamText(messages: Messages, env: Env, options?: StreamingOpti
|
|
86 |
const dynamicMaxTokens = modelDetails && modelDetails.maxTokenAllowed ? modelDetails.maxTokenAllowed : MAX_TOKENS;
|
87 |
|
88 |
return _streamText({
|
89 |
-
|
90 |
-
model: getModel(currentProvider, currentModel, env, apiKeys),
|
91 |
system: getSystemPrompt(),
|
92 |
maxTokens: dynamicMaxTokens,
|
93 |
-
messages: convertToCoreMessages(processedMessages),
|
|
|
94 |
});
|
95 |
}
|
|
|
|
|
|
|
|
|
1 |
import { convertToCoreMessages, streamText as _streamText } from 'ai';
|
2 |
import { getModel } from '~/lib/.server/llm/model';
|
3 |
import { MAX_TOKENS } from './constants';
|
4 |
import { getSystemPrompt } from './prompts';
|
5 |
+
import { DEFAULT_MODEL, DEFAULT_PROVIDER, getModelList, MODEL_REGEX, PROVIDER_REGEX } from '~/utils/constants';
|
6 |
+
import type { IProviderSetting } from '~/types/model';
|
7 |
|
8 |
interface ToolResult<Name extends string, Args, Result> {
|
9 |
toolCallId: string;
|
|
|
41 |
* Extract provider
|
42 |
* const providerMatch = message.content.match(PROVIDER_REGEX);
|
43 |
*/
|
44 |
+
const provider = providerMatch ? providerMatch[1] : DEFAULT_PROVIDER.name;
|
45 |
|
46 |
const cleanedContent = Array.isArray(message.content)
|
47 |
? message.content.map((item) => {
|
|
|
59 |
return { model, provider, content: cleanedContent };
|
60 |
}
|
61 |
|
62 |
+
export async function streamText(props: {
|
63 |
+
messages: Messages;
|
64 |
+
env: Env;
|
65 |
+
options?: StreamingOptions;
|
66 |
+
apiKeys?: Record<string, string>;
|
67 |
+
providerSettings?: Record<string, IProviderSetting>;
|
68 |
+
}) {
|
69 |
+
const { messages, env, options, apiKeys, providerSettings } = props;
|
70 |
let currentModel = DEFAULT_MODEL;
|
71 |
+
let currentProvider = DEFAULT_PROVIDER.name;
|
72 |
+
const MODEL_LIST = await getModelList(apiKeys || {}, providerSettings);
|
73 |
const processedMessages = messages.map((message) => {
|
74 |
if (message.role === 'user') {
|
75 |
const { model, provider, content } = extractPropertiesFromMessage(message);
|
|
|
91 |
const dynamicMaxTokens = modelDetails && modelDetails.maxTokenAllowed ? modelDetails.maxTokenAllowed : MAX_TOKENS;
|
92 |
|
93 |
return _streamText({
|
94 |
+
model: getModel(currentProvider, currentModel, env, apiKeys, providerSettings) as any,
|
|
|
95 |
system: getSystemPrompt(),
|
96 |
maxTokens: dynamicMaxTokens,
|
97 |
+
messages: convertToCoreMessages(processedMessages as any),
|
98 |
+
...options,
|
99 |
});
|
100 |
}
|
app/lib/hooks/useGit.ts
ADDED
@@ -0,0 +1,287 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import type { WebContainer } from '@webcontainer/api';
|
2 |
+
import { useCallback, useEffect, useRef, useState, type MutableRefObject } from 'react';
|
3 |
+
import { webcontainer as webcontainerPromise } from '~/lib/webcontainer';
|
4 |
+
import git, { type GitAuth, type PromiseFsClient } from 'isomorphic-git';
|
5 |
+
import http from 'isomorphic-git/http/web';
|
6 |
+
import Cookies from 'js-cookie';
|
7 |
+
import { toast } from 'react-toastify';
|
8 |
+
|
9 |
+
const lookupSavedPassword = (url: string) => {
|
10 |
+
const domain = url.split('/')[2];
|
11 |
+
const gitCreds = Cookies.get(`git:${domain}`);
|
12 |
+
|
13 |
+
if (!gitCreds) {
|
14 |
+
return null;
|
15 |
+
}
|
16 |
+
|
17 |
+
try {
|
18 |
+
const { username, password } = JSON.parse(gitCreds || '{}');
|
19 |
+
return { username, password };
|
20 |
+
} catch (error) {
|
21 |
+
console.log(`Failed to parse Git Cookie ${error}`);
|
22 |
+
return null;
|
23 |
+
}
|
24 |
+
};
|
25 |
+
|
26 |
+
const saveGitAuth = (url: string, auth: GitAuth) => {
|
27 |
+
const domain = url.split('/')[2];
|
28 |
+
Cookies.set(`git:${domain}`, JSON.stringify(auth));
|
29 |
+
};
|
30 |
+
|
31 |
+
export function useGit() {
|
32 |
+
const [ready, setReady] = useState(false);
|
33 |
+
const [webcontainer, setWebcontainer] = useState<WebContainer>();
|
34 |
+
const [fs, setFs] = useState<PromiseFsClient>();
|
35 |
+
const fileData = useRef<Record<string, { data: any; encoding?: string }>>({});
|
36 |
+
useEffect(() => {
|
37 |
+
webcontainerPromise.then((container) => {
|
38 |
+
fileData.current = {};
|
39 |
+
setWebcontainer(container);
|
40 |
+
setFs(getFs(container, fileData));
|
41 |
+
setReady(true);
|
42 |
+
});
|
43 |
+
}, []);
|
44 |
+
|
45 |
+
const gitClone = useCallback(
|
46 |
+
async (url: string) => {
|
47 |
+
if (!webcontainer || !fs || !ready) {
|
48 |
+
throw 'Webcontainer not initialized';
|
49 |
+
}
|
50 |
+
|
51 |
+
fileData.current = {};
|
52 |
+
await git.clone({
|
53 |
+
fs,
|
54 |
+
http,
|
55 |
+
dir: webcontainer.workdir,
|
56 |
+
url,
|
57 |
+
depth: 1,
|
58 |
+
singleBranch: true,
|
59 |
+
corsProxy: 'https://cors.isomorphic-git.org',
|
60 |
+
onAuth: (url) => {
|
61 |
+
// let domain=url.split("/")[2]
|
62 |
+
|
63 |
+
let auth = lookupSavedPassword(url);
|
64 |
+
|
65 |
+
if (auth) {
|
66 |
+
return auth;
|
67 |
+
}
|
68 |
+
|
69 |
+
if (confirm('This repo is password protected. Ready to enter a username & password?')) {
|
70 |
+
auth = {
|
71 |
+
username: prompt('Enter username'),
|
72 |
+
password: prompt('Enter password'),
|
73 |
+
};
|
74 |
+
return auth;
|
75 |
+
} else {
|
76 |
+
return { cancel: true };
|
77 |
+
}
|
78 |
+
},
|
79 |
+
onAuthFailure: (url, _auth) => {
|
80 |
+
toast.error(`Error Authenticating with ${url.split('/')[2]}`);
|
81 |
+
},
|
82 |
+
onAuthSuccess: (url, auth) => {
|
83 |
+
saveGitAuth(url, auth);
|
84 |
+
},
|
85 |
+
});
|
86 |
+
|
87 |
+
const data: Record<string, { data: any; encoding?: string }> = {};
|
88 |
+
|
89 |
+
for (const [key, value] of Object.entries(fileData.current)) {
|
90 |
+
data[key] = value;
|
91 |
+
}
|
92 |
+
|
93 |
+
return { workdir: webcontainer.workdir, data };
|
94 |
+
},
|
95 |
+
[webcontainer],
|
96 |
+
);
|
97 |
+
|
98 |
+
return { ready, gitClone };
|
99 |
+
}
|
100 |
+
|
101 |
+
const getFs = (
|
102 |
+
webcontainer: WebContainer,
|
103 |
+
record: MutableRefObject<Record<string, { data: any; encoding?: string }>>,
|
104 |
+
) => ({
|
105 |
+
promises: {
|
106 |
+
readFile: async (path: string, options: any) => {
|
107 |
+
const encoding = options.encoding;
|
108 |
+
const relativePath = pathUtils.relative(webcontainer.workdir, path);
|
109 |
+
console.log('readFile', relativePath, encoding);
|
110 |
+
|
111 |
+
return await webcontainer.fs.readFile(relativePath, encoding);
|
112 |
+
},
|
113 |
+
writeFile: async (path: string, data: any, options: any) => {
|
114 |
+
const encoding = options.encoding;
|
115 |
+
const relativePath = pathUtils.relative(webcontainer.workdir, path);
|
116 |
+
console.log('writeFile', { relativePath, data, encoding });
|
117 |
+
|
118 |
+
if (record.current) {
|
119 |
+
record.current[relativePath] = { data, encoding };
|
120 |
+
}
|
121 |
+
|
122 |
+
return await webcontainer.fs.writeFile(relativePath, data, { ...options, encoding });
|
123 |
+
},
|
124 |
+
mkdir: async (path: string, options: any) => {
|
125 |
+
const relativePath = pathUtils.relative(webcontainer.workdir, path);
|
126 |
+
console.log('mkdir', relativePath, options);
|
127 |
+
|
128 |
+
return await webcontainer.fs.mkdir(relativePath, { ...options, recursive: true });
|
129 |
+
},
|
130 |
+
readdir: async (path: string, options: any) => {
|
131 |
+
const relativePath = pathUtils.relative(webcontainer.workdir, path);
|
132 |
+
console.log('readdir', relativePath, options);
|
133 |
+
|
134 |
+
return await webcontainer.fs.readdir(relativePath, options);
|
135 |
+
},
|
136 |
+
rm: async (path: string, options: any) => {
|
137 |
+
const relativePath = pathUtils.relative(webcontainer.workdir, path);
|
138 |
+
console.log('rm', relativePath, options);
|
139 |
+
|
140 |
+
return await webcontainer.fs.rm(relativePath, { ...(options || {}) });
|
141 |
+
},
|
142 |
+
rmdir: async (path: string, options: any) => {
|
143 |
+
const relativePath = pathUtils.relative(webcontainer.workdir, path);
|
144 |
+
console.log('rmdir', relativePath, options);
|
145 |
+
|
146 |
+
return await webcontainer.fs.rm(relativePath, { recursive: true, ...options });
|
147 |
+
},
|
148 |
+
|
149 |
+
// Mock implementations for missing functions
|
150 |
+
unlink: async (path: string) => {
|
151 |
+
// unlink is just removing a single file
|
152 |
+
const relativePath = pathUtils.relative(webcontainer.workdir, path);
|
153 |
+
return await webcontainer.fs.rm(relativePath, { recursive: false });
|
154 |
+
},
|
155 |
+
|
156 |
+
stat: async (path: string) => {
|
157 |
+
try {
|
158 |
+
const relativePath = pathUtils.relative(webcontainer.workdir, path);
|
159 |
+
const resp = await webcontainer.fs.readdir(pathUtils.dirname(relativePath), { withFileTypes: true });
|
160 |
+
const name = pathUtils.basename(relativePath);
|
161 |
+
const fileInfo = resp.find((x) => x.name == name);
|
162 |
+
|
163 |
+
if (!fileInfo) {
|
164 |
+
throw new Error(`ENOENT: no such file or directory, stat '${path}'`);
|
165 |
+
}
|
166 |
+
|
167 |
+
return {
|
168 |
+
isFile: () => fileInfo.isFile(),
|
169 |
+
isDirectory: () => fileInfo.isDirectory(),
|
170 |
+
isSymbolicLink: () => false,
|
171 |
+
size: 1,
|
172 |
+
mode: 0o666, // Default permissions
|
173 |
+
mtimeMs: Date.now(),
|
174 |
+
uid: 1000,
|
175 |
+
gid: 1000,
|
176 |
+
};
|
177 |
+
} catch (error: any) {
|
178 |
+
console.log(error?.message);
|
179 |
+
|
180 |
+
const err = new Error(`ENOENT: no such file or directory, stat '${path}'`) as NodeJS.ErrnoException;
|
181 |
+
err.code = 'ENOENT';
|
182 |
+
err.errno = -2;
|
183 |
+
err.syscall = 'stat';
|
184 |
+
err.path = path;
|
185 |
+
throw err;
|
186 |
+
}
|
187 |
+
},
|
188 |
+
|
189 |
+
lstat: async (path: string) => {
|
190 |
+
/*
|
191 |
+
* For basic usage, lstat can return the same as stat
|
192 |
+
* since we're not handling symbolic links
|
193 |
+
*/
|
194 |
+
return await getFs(webcontainer, record).promises.stat(path);
|
195 |
+
},
|
196 |
+
|
197 |
+
readlink: async (path: string) => {
|
198 |
+
/*
|
199 |
+
* Since WebContainer doesn't support symlinks,
|
200 |
+
* we'll throw a "not a symbolic link" error
|
201 |
+
*/
|
202 |
+
throw new Error(`EINVAL: invalid argument, readlink '${path}'`);
|
203 |
+
},
|
204 |
+
|
205 |
+
symlink: async (target: string, path: string) => {
|
206 |
+
/*
|
207 |
+
* Since WebContainer doesn't support symlinks,
|
208 |
+
* we'll throw a "operation not supported" error
|
209 |
+
*/
|
210 |
+
throw new Error(`EPERM: operation not permitted, symlink '${target}' -> '${path}'`);
|
211 |
+
},
|
212 |
+
|
213 |
+
chmod: async (_path: string, _mode: number) => {
|
214 |
+
/*
|
215 |
+
* WebContainer doesn't support changing permissions,
|
216 |
+
* but we can pretend it succeeded for compatibility
|
217 |
+
*/
|
218 |
+
return await Promise.resolve();
|
219 |
+
},
|
220 |
+
},
|
221 |
+
});
|
222 |
+
|
223 |
+
const pathUtils = {
|
224 |
+
dirname: (path: string) => {
|
225 |
+
// Handle empty or just filename cases
|
226 |
+
if (!path || !path.includes('/')) {
|
227 |
+
return '.';
|
228 |
+
}
|
229 |
+
|
230 |
+
// Remove trailing slashes
|
231 |
+
path = path.replace(/\/+$/, '');
|
232 |
+
|
233 |
+
// Get directory part
|
234 |
+
return path.split('/').slice(0, -1).join('/') || '/';
|
235 |
+
},
|
236 |
+
|
237 |
+
basename: (path: string, ext?: string) => {
|
238 |
+
// Remove trailing slashes
|
239 |
+
path = path.replace(/\/+$/, '');
|
240 |
+
|
241 |
+
// Get the last part of the path
|
242 |
+
const base = path.split('/').pop() || '';
|
243 |
+
|
244 |
+
// If extension is provided, remove it from the result
|
245 |
+
if (ext && base.endsWith(ext)) {
|
246 |
+
return base.slice(0, -ext.length);
|
247 |
+
}
|
248 |
+
|
249 |
+
return base;
|
250 |
+
},
|
251 |
+
relative: (from: string, to: string): string => {
|
252 |
+
// Handle empty inputs
|
253 |
+
if (!from || !to) {
|
254 |
+
return '.';
|
255 |
+
}
|
256 |
+
|
257 |
+
// Normalize paths by removing trailing slashes and splitting
|
258 |
+
const normalizePathParts = (p: string) => p.replace(/\/+$/, '').split('/').filter(Boolean);
|
259 |
+
|
260 |
+
const fromParts = normalizePathParts(from);
|
261 |
+
const toParts = normalizePathParts(to);
|
262 |
+
|
263 |
+
// Find common parts at the start of both paths
|
264 |
+
let commonLength = 0;
|
265 |
+
const minLength = Math.min(fromParts.length, toParts.length);
|
266 |
+
|
267 |
+
for (let i = 0; i < minLength; i++) {
|
268 |
+
if (fromParts[i] !== toParts[i]) {
|
269 |
+
break;
|
270 |
+
}
|
271 |
+
|
272 |
+
commonLength++;
|
273 |
+
}
|
274 |
+
|
275 |
+
// Calculate the number of "../" needed
|
276 |
+
const upCount = fromParts.length - commonLength;
|
277 |
+
|
278 |
+
// Get the remaining path parts we need to append
|
279 |
+
const remainingPath = toParts.slice(commonLength);
|
280 |
+
|
281 |
+
// Construct the relative path
|
282 |
+
const relativeParts = [...Array(upCount).fill('..'), ...remainingPath];
|
283 |
+
|
284 |
+
// Handle empty result case
|
285 |
+
return relativeParts.length === 0 ? '.' : relativeParts.join('/');
|
286 |
+
},
|
287 |
+
};
|
app/lib/hooks/useSettings.tsx
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { useStore } from '@nanostores/react';
|
2 |
+
import {
|
3 |
+
isDebugMode,
|
4 |
+
isEventLogsEnabled,
|
5 |
+
isLocalModelsEnabled,
|
6 |
+
LOCAL_PROVIDERS,
|
7 |
+
providersStore,
|
8 |
+
} from '~/lib/stores/settings';
|
9 |
+
import { useCallback, useEffect, useState } from 'react';
|
10 |
+
import Cookies from 'js-cookie';
|
11 |
+
import type { IProviderSetting, ProviderInfo } from '~/types/model';
|
12 |
+
import { logStore } from '~/lib/stores/logs'; // assuming logStore is imported from this location
|
13 |
+
|
14 |
+
export function useSettings() {
|
15 |
+
const providers = useStore(providersStore);
|
16 |
+
const debug = useStore(isDebugMode);
|
17 |
+
const eventLogs = useStore(isEventLogsEnabled);
|
18 |
+
const isLocalModel = useStore(isLocalModelsEnabled);
|
19 |
+
const [activeProviders, setActiveProviders] = useState<ProviderInfo[]>([]);
|
20 |
+
|
21 |
+
// reading values from cookies on mount
|
22 |
+
useEffect(() => {
|
23 |
+
const savedProviders = Cookies.get('providers');
|
24 |
+
|
25 |
+
if (savedProviders) {
|
26 |
+
try {
|
27 |
+
const parsedProviders: Record<string, IProviderSetting> = JSON.parse(savedProviders);
|
28 |
+
Object.keys(parsedProviders).forEach((provider) => {
|
29 |
+
const currentProvider = providers[provider];
|
30 |
+
providersStore.setKey(provider, {
|
31 |
+
...currentProvider,
|
32 |
+
settings: {
|
33 |
+
...parsedProviders[provider],
|
34 |
+
enabled: parsedProviders[provider].enabled ?? true,
|
35 |
+
},
|
36 |
+
});
|
37 |
+
});
|
38 |
+
} catch (error) {
|
39 |
+
console.error('Failed to parse providers from cookies:', error);
|
40 |
+
}
|
41 |
+
}
|
42 |
+
|
43 |
+
// load debug mode from cookies
|
44 |
+
const savedDebugMode = Cookies.get('isDebugEnabled');
|
45 |
+
|
46 |
+
if (savedDebugMode) {
|
47 |
+
isDebugMode.set(savedDebugMode === 'true');
|
48 |
+
}
|
49 |
+
|
50 |
+
// load event logs from cookies
|
51 |
+
const savedEventLogs = Cookies.get('isEventLogsEnabled');
|
52 |
+
|
53 |
+
if (savedEventLogs) {
|
54 |
+
isEventLogsEnabled.set(savedEventLogs === 'true');
|
55 |
+
}
|
56 |
+
|
57 |
+
// load local models from cookies
|
58 |
+
const savedLocalModels = Cookies.get('isLocalModelsEnabled');
|
59 |
+
|
60 |
+
if (savedLocalModels) {
|
61 |
+
isLocalModelsEnabled.set(savedLocalModels === 'true');
|
62 |
+
}
|
63 |
+
}, []);
|
64 |
+
|
65 |
+
// writing values to cookies on change
|
66 |
+
useEffect(() => {
|
67 |
+
const providers = providersStore.get();
|
68 |
+
const providerSetting: Record<string, IProviderSetting> = {};
|
69 |
+
Object.keys(providers).forEach((provider) => {
|
70 |
+
providerSetting[provider] = providers[provider].settings;
|
71 |
+
});
|
72 |
+
Cookies.set('providers', JSON.stringify(providerSetting));
|
73 |
+
}, [providers]);
|
74 |
+
|
75 |
+
useEffect(() => {
|
76 |
+
let active = Object.entries(providers)
|
77 |
+
.filter(([_key, provider]) => provider.settings.enabled)
|
78 |
+
.map(([_k, p]) => p);
|
79 |
+
|
80 |
+
if (!isLocalModel) {
|
81 |
+
active = active.filter((p) => !LOCAL_PROVIDERS.includes(p.name));
|
82 |
+
}
|
83 |
+
|
84 |
+
setActiveProviders(active);
|
85 |
+
}, [providers, isLocalModel]);
|
86 |
+
|
87 |
+
// helper function to update settings
|
88 |
+
const updateProviderSettings = useCallback(
|
89 |
+
(provider: string, config: IProviderSetting) => {
|
90 |
+
const settings = providers[provider].settings;
|
91 |
+
providersStore.setKey(provider, { ...providers[provider], settings: { ...settings, ...config } });
|
92 |
+
},
|
93 |
+
[providers],
|
94 |
+
);
|
95 |
+
|
96 |
+
const enableDebugMode = useCallback((enabled: boolean) => {
|
97 |
+
isDebugMode.set(enabled);
|
98 |
+
logStore.logSystem(`Debug mode ${enabled ? 'enabled' : 'disabled'}`);
|
99 |
+
Cookies.set('isDebugEnabled', String(enabled));
|
100 |
+
}, []);
|
101 |
+
|
102 |
+
const enableEventLogs = useCallback((enabled: boolean) => {
|
103 |
+
isEventLogsEnabled.set(enabled);
|
104 |
+
logStore.logSystem(`Event logs ${enabled ? 'enabled' : 'disabled'}`);
|
105 |
+
Cookies.set('isEventLogsEnabled', String(enabled));
|
106 |
+
}, []);
|
107 |
+
|
108 |
+
const enableLocalModels = useCallback((enabled: boolean) => {
|
109 |
+
isLocalModelsEnabled.set(enabled);
|
110 |
+
logStore.logSystem(`Local models ${enabled ? 'enabled' : 'disabled'}`);
|
111 |
+
Cookies.set('isLocalModelsEnabled', String(enabled));
|
112 |
+
}, []);
|
113 |
+
|
114 |
+
return {
|
115 |
+
providers,
|
116 |
+
activeProviders,
|
117 |
+
updateProviderSettings,
|
118 |
+
debug,
|
119 |
+
enableDebugMode,
|
120 |
+
eventLogs,
|
121 |
+
enableEventLogs,
|
122 |
+
isLocalModel,
|
123 |
+
enableLocalModels,
|
124 |
+
};
|
125 |
+
}
|
app/lib/persistence/useChatHistory.ts
CHANGED
@@ -4,6 +4,7 @@ import { atom } from 'nanostores';
|
|
4 |
import type { Message } from 'ai';
|
5 |
import { toast } from 'react-toastify';
|
6 |
import { workbenchStore } from '~/lib/stores/workbench';
|
|
|
7 |
import {
|
8 |
getMessages,
|
9 |
getNextId,
|
@@ -43,6 +44,8 @@ export function useChatHistory() {
|
|
43 |
setReady(true);
|
44 |
|
45 |
if (persistenceEnabled) {
|
|
|
|
|
46 |
toast.error('Chat persistence is unavailable');
|
47 |
}
|
48 |
|
@@ -69,6 +72,7 @@ export function useChatHistory() {
|
|
69 |
setReady(true);
|
70 |
})
|
71 |
.catch((error) => {
|
|
|
72 |
toast.error(error.message);
|
73 |
});
|
74 |
}
|
|
|
4 |
import type { Message } from 'ai';
|
5 |
import { toast } from 'react-toastify';
|
6 |
import { workbenchStore } from '~/lib/stores/workbench';
|
7 |
+
import { logStore } from '~/lib/stores/logs'; // Import logStore
|
8 |
import {
|
9 |
getMessages,
|
10 |
getNextId,
|
|
|
44 |
setReady(true);
|
45 |
|
46 |
if (persistenceEnabled) {
|
47 |
+
const error = new Error('Chat persistence is unavailable');
|
48 |
+
logStore.logError('Chat persistence initialization failed', error);
|
49 |
toast.error('Chat persistence is unavailable');
|
50 |
}
|
51 |
|
|
|
72 |
setReady(true);
|
73 |
})
|
74 |
.catch((error) => {
|
75 |
+
logStore.logError('Failed to load chat messages', error);
|
76 |
toast.error(error.message);
|
77 |
});
|
78 |
}
|
app/lib/runtime/__snapshots__/message-parser.spec.ts.snap
CHANGED
@@ -29,6 +29,7 @@ exports[`StreamingMessageParser > valid artifacts with actions > should correctl
|
|
29 |
"id": "artifact_1",
|
30 |
"messageId": "message_1",
|
31 |
"title": "Some title",
|
|
|
32 |
}
|
33 |
`;
|
34 |
|
@@ -37,6 +38,7 @@ exports[`StreamingMessageParser > valid artifacts with actions > should correctl
|
|
37 |
"id": "artifact_1",
|
38 |
"messageId": "message_1",
|
39 |
"title": "Some title",
|
|
|
40 |
}
|
41 |
`;
|
42 |
|
@@ -96,6 +98,7 @@ exports[`StreamingMessageParser > valid artifacts with actions > should correctl
|
|
96 |
"id": "artifact_1",
|
97 |
"messageId": "message_1",
|
98 |
"title": "Some title",
|
|
|
99 |
}
|
100 |
`;
|
101 |
|
@@ -104,6 +107,7 @@ exports[`StreamingMessageParser > valid artifacts with actions > should correctl
|
|
104 |
"id": "artifact_1",
|
105 |
"messageId": "message_1",
|
106 |
"title": "Some title",
|
|
|
107 |
}
|
108 |
`;
|
109 |
|
@@ -112,6 +116,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|
112 |
"id": "artifact_1",
|
113 |
"messageId": "message_1",
|
114 |
"title": "Some title",
|
|
|
115 |
}
|
116 |
`;
|
117 |
|
@@ -120,6 +125,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|
120 |
"id": "artifact_1",
|
121 |
"messageId": "message_1",
|
122 |
"title": "Some title",
|
|
|
123 |
}
|
124 |
`;
|
125 |
|
@@ -128,6 +134,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|
128 |
"id": "artifact_1",
|
129 |
"messageId": "message_1",
|
130 |
"title": "Some title",
|
|
|
131 |
}
|
132 |
`;
|
133 |
|
@@ -136,6 +143,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|
136 |
"id": "artifact_1",
|
137 |
"messageId": "message_1",
|
138 |
"title": "Some title",
|
|
|
139 |
}
|
140 |
`;
|
141 |
|
@@ -144,6 +152,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|
144 |
"id": "artifact_1",
|
145 |
"messageId": "message_1",
|
146 |
"title": "Some title",
|
|
|
147 |
}
|
148 |
`;
|
149 |
|
@@ -152,6 +161,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|
152 |
"id": "artifact_1",
|
153 |
"messageId": "message_1",
|
154 |
"title": "Some title",
|
|
|
155 |
}
|
156 |
`;
|
157 |
|
@@ -160,6 +170,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|
160 |
"id": "artifact_1",
|
161 |
"messageId": "message_1",
|
162 |
"title": "Some title",
|
|
|
163 |
}
|
164 |
`;
|
165 |
|
@@ -168,6 +179,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|
168 |
"id": "artifact_1",
|
169 |
"messageId": "message_1",
|
170 |
"title": "Some title",
|
|
|
171 |
}
|
172 |
`;
|
173 |
|
@@ -176,6 +188,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|
176 |
"id": "artifact_1",
|
177 |
"messageId": "message_1",
|
178 |
"title": "Some title",
|
|
|
179 |
}
|
180 |
`;
|
181 |
|
@@ -184,6 +197,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|
184 |
"id": "artifact_1",
|
185 |
"messageId": "message_1",
|
186 |
"title": "Some title",
|
|
|
187 |
}
|
188 |
`;
|
189 |
|
@@ -192,6 +206,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|
192 |
"id": "artifact_1",
|
193 |
"messageId": "message_1",
|
194 |
"title": "Some title",
|
|
|
195 |
}
|
196 |
`;
|
197 |
|
@@ -200,6 +215,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|
200 |
"id": "artifact_1",
|
201 |
"messageId": "message_1",
|
202 |
"title": "Some title",
|
|
|
203 |
}
|
204 |
`;
|
205 |
|
@@ -208,6 +224,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|
208 |
"id": "artifact_1",
|
209 |
"messageId": "message_1",
|
210 |
"title": "Some title",
|
|
|
211 |
}
|
212 |
`;
|
213 |
|
@@ -216,5 +233,6 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|
216 |
"id": "artifact_1",
|
217 |
"messageId": "message_1",
|
218 |
"title": "Some title",
|
|
|
219 |
}
|
220 |
`;
|
|
|
29 |
"id": "artifact_1",
|
30 |
"messageId": "message_1",
|
31 |
"title": "Some title",
|
32 |
+
"type": undefined,
|
33 |
}
|
34 |
`;
|
35 |
|
|
|
38 |
"id": "artifact_1",
|
39 |
"messageId": "message_1",
|
40 |
"title": "Some title",
|
41 |
+
"type": undefined,
|
42 |
}
|
43 |
`;
|
44 |
|
|
|
98 |
"id": "artifact_1",
|
99 |
"messageId": "message_1",
|
100 |
"title": "Some title",
|
101 |
+
"type": undefined,
|
102 |
}
|
103 |
`;
|
104 |
|
|
|
107 |
"id": "artifact_1",
|
108 |
"messageId": "message_1",
|
109 |
"title": "Some title",
|
110 |
+
"type": undefined,
|
111 |
}
|
112 |
`;
|
113 |
|
|
|
116 |
"id": "artifact_1",
|
117 |
"messageId": "message_1",
|
118 |
"title": "Some title",
|
119 |
+
"type": undefined,
|
120 |
}
|
121 |
`;
|
122 |
|
|
|
125 |
"id": "artifact_1",
|
126 |
"messageId": "message_1",
|
127 |
"title": "Some title",
|
128 |
+
"type": undefined,
|
129 |
}
|
130 |
`;
|
131 |
|
|
|
134 |
"id": "artifact_1",
|
135 |
"messageId": "message_1",
|
136 |
"title": "Some title",
|
137 |
+
"type": "bundled",
|
138 |
}
|
139 |
`;
|
140 |
|
|
|
143 |
"id": "artifact_1",
|
144 |
"messageId": "message_1",
|
145 |
"title": "Some title",
|
146 |
+
"type": "bundled",
|
147 |
}
|
148 |
`;
|
149 |
|
|
|
152 |
"id": "artifact_1",
|
153 |
"messageId": "message_1",
|
154 |
"title": "Some title",
|
155 |
+
"type": undefined,
|
156 |
}
|
157 |
`;
|
158 |
|
|
|
161 |
"id": "artifact_1",
|
162 |
"messageId": "message_1",
|
163 |
"title": "Some title",
|
164 |
+
"type": undefined,
|
165 |
}
|
166 |
`;
|
167 |
|
|
|
170 |
"id": "artifact_1",
|
171 |
"messageId": "message_1",
|
172 |
"title": "Some title",
|
173 |
+
"type": undefined,
|
174 |
}
|
175 |
`;
|
176 |
|
|
|
179 |
"id": "artifact_1",
|
180 |
"messageId": "message_1",
|
181 |
"title": "Some title",
|
182 |
+
"type": undefined,
|
183 |
}
|
184 |
`;
|
185 |
|
|
|
188 |
"id": "artifact_1",
|
189 |
"messageId": "message_1",
|
190 |
"title": "Some title",
|
191 |
+
"type": undefined,
|
192 |
}
|
193 |
`;
|
194 |
|
|
|
197 |
"id": "artifact_1",
|
198 |
"messageId": "message_1",
|
199 |
"title": "Some title",
|
200 |
+
"type": undefined,
|
201 |
}
|
202 |
`;
|
203 |
|
|
|
206 |
"id": "artifact_1",
|
207 |
"messageId": "message_1",
|
208 |
"title": "Some title",
|
209 |
+
"type": undefined,
|
210 |
}
|
211 |
`;
|
212 |
|
|
|
215 |
"id": "artifact_1",
|
216 |
"messageId": "message_1",
|
217 |
"title": "Some title",
|
218 |
+
"type": undefined,
|
219 |
}
|
220 |
`;
|
221 |
|
|
|
224 |
"id": "artifact_1",
|
225 |
"messageId": "message_1",
|
226 |
"title": "Some title",
|
227 |
+
"type": undefined,
|
228 |
}
|
229 |
`;
|
230 |
|
|
|
233 |
"id": "artifact_1",
|
234 |
"messageId": "message_1",
|
235 |
"title": "Some title",
|
236 |
+
"type": undefined,
|
237 |
}
|
238 |
`;
|
app/lib/runtime/message-parser.spec.ts
CHANGED
@@ -59,7 +59,11 @@ describe('StreamingMessageParser', () => {
|
|
59 |
},
|
60 |
],
|
61 |
[
|
62 |
-
[
|
|
|
|
|
|
|
|
|
63 |
{
|
64 |
output: 'Some text before Some more text',
|
65 |
callbacks: { onArtifactOpen: 1, onArtifactClose: 1, onActionOpen: 0, onActionClose: 0 },
|
|
|
59 |
},
|
60 |
],
|
61 |
[
|
62 |
+
[
|
63 |
+
'Some text before <boltArti',
|
64 |
+
'fact',
|
65 |
+
' title="Some title" id="artifact_1" type="bundled" >foo</boltArtifact> Some more text',
|
66 |
+
],
|
67 |
{
|
68 |
output: 'Some text before Some more text',
|
69 |
callbacks: { onArtifactOpen: 1, onArtifactClose: 1, onActionOpen: 0, onActionClose: 0 },
|
app/lib/runtime/message-parser.ts
CHANGED
@@ -192,6 +192,7 @@ export class StreamingMessageParser {
|
|
192 |
const artifactTag = input.slice(i, openTagEnd + 1);
|
193 |
|
194 |
const artifactTitle = this.#extractAttribute(artifactTag, 'title') as string;
|
|
|
195 |
const artifactId = this.#extractAttribute(artifactTag, 'id') as string;
|
196 |
|
197 |
if (!artifactTitle) {
|
@@ -207,6 +208,7 @@ export class StreamingMessageParser {
|
|
207 |
const currentArtifact = {
|
208 |
id: artifactId,
|
209 |
title: artifactTitle,
|
|
|
210 |
} satisfies BoltArtifactData;
|
211 |
|
212 |
state.currentArtifact = currentArtifact;
|
|
|
192 |
const artifactTag = input.slice(i, openTagEnd + 1);
|
193 |
|
194 |
const artifactTitle = this.#extractAttribute(artifactTag, 'title') as string;
|
195 |
+
const type = this.#extractAttribute(artifactTag, 'type') as string;
|
196 |
const artifactId = this.#extractAttribute(artifactTag, 'id') as string;
|
197 |
|
198 |
if (!artifactTitle) {
|
|
|
208 |
const currentArtifact = {
|
209 |
id: artifactId,
|
210 |
title: artifactTitle,
|
211 |
+
type,
|
212 |
} satisfies BoltArtifactData;
|
213 |
|
214 |
state.currentArtifact = currentArtifact;
|
app/lib/stores/logs.ts
ADDED
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { atom, map } from 'nanostores';
|
2 |
+
import Cookies from 'js-cookie';
|
3 |
+
import { createScopedLogger } from '~/utils/logger';
|
4 |
+
|
5 |
+
const logger = createScopedLogger('LogStore');
|
6 |
+
|
7 |
+
export interface LogEntry {
|
8 |
+
id: string;
|
9 |
+
timestamp: string;
|
10 |
+
level: 'info' | 'warning' | 'error' | 'debug';
|
11 |
+
message: string;
|
12 |
+
details?: Record<string, any>;
|
13 |
+
category: 'system' | 'provider' | 'user' | 'error';
|
14 |
+
}
|
15 |
+
|
16 |
+
const MAX_LOGS = 1000; // Maximum number of logs to keep in memory
|
17 |
+
|
18 |
+
class LogStore {
|
19 |
+
private _logs = map<Record<string, LogEntry>>({});
|
20 |
+
showLogs = atom(true);
|
21 |
+
|
22 |
+
constructor() {
|
23 |
+
// Load saved logs from cookies on initialization
|
24 |
+
this._loadLogs();
|
25 |
+
}
|
26 |
+
|
27 |
+
private _loadLogs() {
|
28 |
+
const savedLogs = Cookies.get('eventLogs');
|
29 |
+
|
30 |
+
if (savedLogs) {
|
31 |
+
try {
|
32 |
+
const parsedLogs = JSON.parse(savedLogs);
|
33 |
+
this._logs.set(parsedLogs);
|
34 |
+
} catch (error) {
|
35 |
+
logger.error('Failed to parse logs from cookies:', error);
|
36 |
+
}
|
37 |
+
}
|
38 |
+
}
|
39 |
+
|
40 |
+
private _saveLogs() {
|
41 |
+
const currentLogs = this._logs.get();
|
42 |
+
Cookies.set('eventLogs', JSON.stringify(currentLogs));
|
43 |
+
}
|
44 |
+
|
45 |
+
private _generateId(): string {
|
46 |
+
return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
47 |
+
}
|
48 |
+
|
49 |
+
private _trimLogs() {
|
50 |
+
const currentLogs = Object.entries(this._logs.get());
|
51 |
+
|
52 |
+
if (currentLogs.length > MAX_LOGS) {
|
53 |
+
const sortedLogs = currentLogs.sort(
|
54 |
+
([, a], [, b]) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime(),
|
55 |
+
);
|
56 |
+
const newLogs = Object.fromEntries(sortedLogs.slice(0, MAX_LOGS));
|
57 |
+
this._logs.set(newLogs);
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
addLog(
|
62 |
+
message: string,
|
63 |
+
level: LogEntry['level'] = 'info',
|
64 |
+
category: LogEntry['category'] = 'system',
|
65 |
+
details?: Record<string, any>,
|
66 |
+
) {
|
67 |
+
const id = this._generateId();
|
68 |
+
const entry: LogEntry = {
|
69 |
+
id,
|
70 |
+
timestamp: new Date().toISOString(),
|
71 |
+
level,
|
72 |
+
message,
|
73 |
+
details,
|
74 |
+
category,
|
75 |
+
};
|
76 |
+
|
77 |
+
this._logs.setKey(id, entry);
|
78 |
+
this._trimLogs();
|
79 |
+
this._saveLogs();
|
80 |
+
|
81 |
+
return id;
|
82 |
+
}
|
83 |
+
|
84 |
+
// System events
|
85 |
+
logSystem(message: string, details?: Record<string, any>) {
|
86 |
+
return this.addLog(message, 'info', 'system', details);
|
87 |
+
}
|
88 |
+
|
89 |
+
// Provider events
|
90 |
+
logProvider(message: string, details?: Record<string, any>) {
|
91 |
+
return this.addLog(message, 'info', 'provider', details);
|
92 |
+
}
|
93 |
+
|
94 |
+
// User actions
|
95 |
+
logUserAction(message: string, details?: Record<string, any>) {
|
96 |
+
return this.addLog(message, 'info', 'user', details);
|
97 |
+
}
|
98 |
+
|
99 |
+
// Error events
|
100 |
+
logError(message: string, error?: Error | unknown, details?: Record<string, any>) {
|
101 |
+
const errorDetails = {
|
102 |
+
...(details || {}),
|
103 |
+
error:
|
104 |
+
error instanceof Error
|
105 |
+
? {
|
106 |
+
message: error.message,
|
107 |
+
stack: error.stack,
|
108 |
+
}
|
109 |
+
: error,
|
110 |
+
};
|
111 |
+
return this.addLog(message, 'error', 'error', errorDetails);
|
112 |
+
}
|
113 |
+
|
114 |
+
// Warning events
|
115 |
+
logWarning(message: string, details?: Record<string, any>) {
|
116 |
+
return this.addLog(message, 'warning', 'system', details);
|
117 |
+
}
|
118 |
+
|
119 |
+
// Debug events
|
120 |
+
logDebug(message: string, details?: Record<string, any>) {
|
121 |
+
return this.addLog(message, 'debug', 'system', details);
|
122 |
+
}
|
123 |
+
|
124 |
+
clearLogs() {
|
125 |
+
this._logs.set({});
|
126 |
+
this._saveLogs();
|
127 |
+
}
|
128 |
+
|
129 |
+
getLogs() {
|
130 |
+
return Object.values(this._logs.get()).sort(
|
131 |
+
(a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime(),
|
132 |
+
);
|
133 |
+
}
|
134 |
+
|
135 |
+
getFilteredLogs(level?: LogEntry['level'], category?: LogEntry['category'], searchQuery?: string) {
|
136 |
+
return this.getLogs().filter((log) => {
|
137 |
+
const matchesLevel = !level || level === 'debug' || log.level === level;
|
138 |
+
const matchesCategory = !category || log.category === category;
|
139 |
+
const matchesSearch =
|
140 |
+
!searchQuery ||
|
141 |
+
log.message.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
142 |
+
JSON.stringify(log.details).toLowerCase().includes(searchQuery.toLowerCase());
|
143 |
+
|
144 |
+
return matchesLevel && matchesCategory && matchesSearch;
|
145 |
+
});
|
146 |
+
}
|
147 |
+
}
|
148 |
+
|
149 |
+
export const logStore = new LogStore();
|
app/lib/stores/settings.ts
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
-
import { map } from 'nanostores';
|
2 |
import { workbenchStore } from './workbench';
|
|
|
|
|
3 |
|
4 |
export interface Shortcut {
|
5 |
key: string;
|
@@ -15,9 +17,10 @@ export interface Shortcuts {
|
|
15 |
toggleTerminal: Shortcut;
|
16 |
}
|
17 |
|
18 |
-
export
|
19 |
-
|
20 |
-
|
|
|
21 |
|
22 |
export const shortcutsStore = map<Shortcuts>({
|
23 |
toggleTerminal: {
|
@@ -27,13 +30,19 @@ export const shortcutsStore = map<Shortcuts>({
|
|
27 |
},
|
28 |
});
|
29 |
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
});
|
|
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
});
|
|
|
1 |
+
import { atom, map } from 'nanostores';
|
2 |
import { workbenchStore } from './workbench';
|
3 |
+
import { PROVIDER_LIST } from '~/utils/constants';
|
4 |
+
import type { IProviderConfig } from '~/types/model';
|
5 |
|
6 |
export interface Shortcut {
|
7 |
key: string;
|
|
|
17 |
toggleTerminal: Shortcut;
|
18 |
}
|
19 |
|
20 |
+
export const URL_CONFIGURABLE_PROVIDERS = ['Ollama', 'LMStudio', 'OpenAILike'];
|
21 |
+
export const LOCAL_PROVIDERS = ['OpenAILike', 'LMStudio', 'Ollama'];
|
22 |
+
|
23 |
+
export type ProviderSetting = Record<string, IProviderConfig>;
|
24 |
|
25 |
export const shortcutsStore = map<Shortcuts>({
|
26 |
toggleTerminal: {
|
|
|
30 |
},
|
31 |
});
|
32 |
|
33 |
+
const initialProviderSettings: ProviderSetting = {};
|
34 |
+
PROVIDER_LIST.forEach((provider) => {
|
35 |
+
initialProviderSettings[provider.name] = {
|
36 |
+
...provider,
|
37 |
+
settings: {
|
38 |
+
enabled: true,
|
39 |
+
},
|
40 |
+
};
|
41 |
});
|
42 |
+
export const providersStore = map<ProviderSetting>(initialProviderSettings);
|
43 |
|
44 |
+
export const isDebugMode = atom(false);
|
45 |
+
|
46 |
+
export const isEventLogsEnabled = atom(false);
|
47 |
+
|
48 |
+
export const isLocalModelsEnabled = atom(true);
|
|