Skip to content

Commit 55a61bf

Browse files
authored
Merge pull request stackblitz-labs#755 from thecodacus/fix-variable-name
fix: Added auto detect branch name and version tag for Debug Tab
2 parents 899685e + e64da70 commit 55a61bf

File tree

11 files changed

+79
-65
lines changed

11 files changed

+79
-65
lines changed

.github/workflows/commit.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@ jobs:
2020
- name: Get the latest commit hash
2121
run: echo "COMMIT_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV
2222

23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: '20'
28+
29+
2330
- name: Update commit file
2431
run: |
25-
echo "{ \"commit\": \"$COMMIT_HASH\" }" > app/commit.json
32+
echo CURRENT_VERSION=$(node -p "require('./package.json').version") >> $GITHUB_ENV
33+
echo "{ \"commit\": \"$COMMIT_HASH\" , \"version\": \"$CURRENT_VERSION\" }" > app/commit.json
2634
2735
- name: Commit and push the update
2836
run: |

.github/workflows/update-stable.yml

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,7 @@ permissions:
99
contents: write
1010

1111
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
3412
prepare-release:
35-
needs: update-commit
3613
if: contains(github.event.head_commit.message, '#release')
3714
runs-on: ubuntu-latest
3815

@@ -183,8 +160,11 @@ jobs:
183160
184161
- name: Commit and Tag Release
185162
run: |
163+
echo "COMMIT_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV
164+
echo "CURRENT_VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV
186165
git pull
187-
git add package.json pnpm-lock.yaml changelog.md
166+
echo "{ \"commit\": \"$COMMIT_HASH\" , \"version\": \"$CURRENT_VERSION\" }" > app/commit.json
167+
git add package.json pnpm-lock.yaml changelog.md app/commit.json
188168
git commit -m "chore: release version ${{ steps.bump_version.outputs.new_version }}"
189169
git tag "v${{ steps.bump_version.outputs.new_version }}"
190170
git push

app/commit.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "commit": "6ba93974a02a98c83badf2f0002ff4812b8f75a9" }
1+
{ "commit": "6ba93974a02a98c83badf2f0002ff4812b8f75a9" }

app/components/chat/BaseChat.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
7777
input = '',
7878
enhancingPrompt,
7979
handleInputChange,
80-
promptEnhanced,
8180
enhancePrompt,
8281
sendMessage,
8382
handleStop,
@@ -490,10 +489,7 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
490489
<IconButton
491490
title="Enhance prompt"
492491
disabled={input.length === 0 || enhancingPrompt}
493-
className={classNames(
494-
'transition-all',
495-
enhancingPrompt ? 'opacity-100' : '',
496-
)}
492+
className={classNames('transition-all', enhancingPrompt ? 'opacity-100' : '')}
497493
onClick={() => {
498494
enhancePrompt?.();
499495
toast.success('Prompt enhanced!');

app/components/settings/chat-history/ChatHistoryTab.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export default function ChatHistoryTab() {
2222
};
2323

2424
const handleDeleteAllChats = async () => {
25-
const confirmDelete = window.confirm("Are you sure you want to delete all chats? This action cannot be undone.");
25+
const confirmDelete = window.confirm('Are you sure you want to delete all chats? This action cannot be undone.');
26+
2627
if (!confirmDelete) {
2728
return; // Exit if the user cancels
2829
}
@@ -31,11 +32,13 @@ export default function ChatHistoryTab() {
3132
const error = new Error('Database is not available');
3233
logStore.logError('Failed to delete chats - DB unavailable', error);
3334
toast.error('Database is not available');
35+
3436
return;
3537
}
3638

3739
try {
3840
setIsDeleting(true);
41+
3942
const allChats = await getAll(db);
4043
await Promise.all(allChats.map((chat) => deleteById(db!, chat.id)));
4144
logStore.logSystem('All chats deleted successfully', { count: allChats.length });
@@ -55,6 +58,7 @@ export default function ChatHistoryTab() {
5558
const error = new Error('Database is not available');
5659
logStore.logError('Failed to export chats - DB unavailable', error);
5760
toast.error('Database is not available');
61+
5862
return;
5963
}
6064

app/components/settings/debug/DebugTab.tsx

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,19 @@ interface IProviderConfig {
3434

3535
interface CommitData {
3636
commit: string;
37+
version?: string;
3738
}
3839

40+
const connitJson: CommitData = commit;
41+
3942
const LOCAL_PROVIDERS = ['Ollama', 'LMStudio', 'OpenAILike'];
40-
const versionHash = commit.commit;
43+
const versionHash = connitJson.commit;
44+
const versionTag = connitJson.version;
4145
const GITHUB_URLS = {
4246
original: 'https://api.github.com/repos/stackblitz-labs/bolt.diy/commits/main',
4347
fork: 'https://api.github.com/repos/Stijnus/bolt.new-any-llm/commits/main',
44-
commitJson: (branch: string) => `https://raw.githubusercontent.com/stackblitz-labs/bolt.diy/${branch}/app/commit.json`,
48+
commitJson: (branch: string) =>
49+
`https://raw.githubusercontent.com/stackblitz-labs/bolt.diy/${branch}/app/commit.json`,
4550
};
4651

4752
function getSystemInfo(): SystemInfo {
@@ -206,7 +211,7 @@ const checkProviderStatus = async (url: string | null, providerName: string): Pr
206211
};
207212

208213
export default function DebugTab() {
209-
const { providers, useLatestBranch } = useSettings();
214+
const { providers, latestBranch } = useSettings();
210215
const [activeProviders, setActiveProviders] = useState<ProviderStatus[]>([]);
211216
const [updateMessage, setUpdateMessage] = useState<string>('');
212217
const [systemInfo] = useState<SystemInfo>(getSystemInfo());
@@ -227,19 +232,20 @@ export default function DebugTab() {
227232
provider.name.toLowerCase() === 'ollama'
228233
? 'OLLAMA_API_BASE_URL'
229234
: provider.name.toLowerCase() === 'lmstudio'
230-
? 'LMSTUDIO_API_BASE_URL'
231-
: `REACT_APP_${provider.name.toUpperCase()}_URL`;
235+
? 'LMSTUDIO_API_BASE_URL'
236+
: `REACT_APP_${provider.name.toUpperCase()}_URL`;
232237

233238
// Access environment variables through import.meta.env
234239
const url = import.meta.env[envVarName] || provider.settings.baseUrl || null; // Ensure baseUrl is used
235240
console.log(`[Debug] Using URL for ${provider.name}:`, url, `(from ${envVarName})`);
236241

237242
const status = await checkProviderStatus(url, provider.name);
243+
238244
return {
239245
...status,
240246
enabled: provider.settings.enabled ?? false,
241247
};
242-
})
248+
}),
243249
);
244250

245251
setActiveProviders(statuses);
@@ -265,23 +271,24 @@ export default function DebugTab() {
265271
setIsCheckingUpdate(true);
266272
setUpdateMessage('Checking for updates...');
267273

268-
const branchToCheck = useLatestBranch ? 'main' : 'stable';
274+
const branchToCheck = latestBranch ? 'main' : 'stable';
269275
console.log(`[Debug] Checking for updates against ${branchToCheck} branch`);
270276

271277
const localCommitResponse = await fetch(GITHUB_URLS.commitJson(branchToCheck));
278+
272279
if (!localCommitResponse.ok) {
273280
throw new Error('Failed to fetch local commit info');
274281
}
275282

276-
const localCommitData = await localCommitResponse.json() as CommitData;
283+
const localCommitData = (await localCommitResponse.json()) as CommitData;
277284
const remoteCommitHash = localCommitData.commit;
278285
const currentCommitHash = versionHash;
279286

280287
if (remoteCommitHash !== currentCommitHash) {
281288
setUpdateMessage(
282289
`Update available from ${branchToCheck} branch!\n` +
283-
`Current: ${currentCommitHash.slice(0, 7)}\n` +
284-
`Latest: ${remoteCommitHash.slice(0, 7)}`
290+
`Current: ${currentCommitHash.slice(0, 7)}\n` +
291+
`Latest: ${remoteCommitHash.slice(0, 7)}`,
285292
);
286293
} else {
287294
setUpdateMessage(`You are on the latest version from the ${branchToCheck} branch`);
@@ -292,7 +299,7 @@ export default function DebugTab() {
292299
} finally {
293300
setIsCheckingUpdate(false);
294301
}
295-
}, [isCheckingUpdate, useLatestBranch]);
302+
}, [isCheckingUpdate, latestBranch]);
296303

297304
const handleCopyToClipboard = useCallback(() => {
298305
const debugInfo = {
@@ -309,15 +316,15 @@ export default function DebugTab() {
309316
})),
310317
Version: {
311318
hash: versionHash.slice(0, 7),
312-
branch: useLatestBranch ? 'main' : 'stable'
319+
branch: latestBranch ? 'main' : 'stable',
313320
},
314321
Timestamp: new Date().toISOString(),
315322
};
316323

317324
navigator.clipboard.writeText(JSON.stringify(debugInfo, null, 2)).then(() => {
318325
toast.success('Debug information copied to clipboard!');
319326
});
320-
}, [activeProviders, systemInfo, useLatestBranch]);
327+
}, [activeProviders, systemInfo, latestBranch]);
321328

322329
return (
323330
<div className="p-4 space-y-6">
@@ -403,7 +410,7 @@ export default function DebugTab() {
403410
<p className="text-sm font-medium text-bolt-elements-textPrimary font-mono">
404411
{versionHash.slice(0, 7)}
405412
<span className="ml-2 text-xs text-bolt-elements-textSecondary">
406-
({new Date().toLocaleDateString()})
413+
(v{versionTag || '0.0.1'}) - {latestBranch ? 'nightly' : 'stable'}
407414
</span>
408415
</p>
409416
</div>

app/components/settings/features/FeaturesTab.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { Switch } from '~/components/ui/Switch';
33
import { useSettings } from '~/lib/hooks/useSettings';
44

55
export default function FeaturesTab() {
6-
const { debug, enableDebugMode, isLocalModel, enableLocalModels, eventLogs, enableEventLogs, useLatestBranch, enableLatestBranch } = useSettings();
6+
const { debug, enableDebugMode, isLocalModel, enableLocalModels, enableEventLogs, latestBranch, enableLatestBranch } =
7+
useSettings();
78

89
const handleToggle = (enabled: boolean) => {
910
enableDebugMode(enabled);
@@ -22,9 +23,11 @@ export default function FeaturesTab() {
2223
<div className="flex items-center justify-between">
2324
<div>
2425
<span className="text-bolt-elements-textPrimary">Use Main Branch</span>
25-
<p className="text-sm text-bolt-elements-textSecondary">Check for updates against the main branch instead of stable</p>
26+
<p className="text-sm text-bolt-elements-textSecondary">
27+
Check for updates against the main branch instead of stable
28+
</p>
2629
</div>
27-
<Switch className="ml-auto" checked={useLatestBranch} onCheckedChange={enableLatestBranch} />
30+
<Switch className="ml-auto" checked={latestBranch} onCheckedChange={enableLatestBranch} />
2831
</div>
2932
</div>
3033
</div>

app/components/settings/providers/ProvidersTab.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ export default function ProvidersTab() {
5656
<div className="flex items-center gap-2">
5757
<img
5858
src={`/icons/${provider.name}.svg`} // Attempt to load the specific icon
59-
onError={(e) => { // Fallback to default icon on error
59+
onError={(e) => {
60+
// Fallback to default icon on error
6061
e.currentTarget.src = DefaultIcon;
6162
}}
6263
alt={`${provider.name} icon`}

app/lib/hooks/useSettings.tsx

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
isLocalModelsEnabled,
66
LOCAL_PROVIDERS,
77
providersStore,
8-
latestBranch,
8+
latestBranchStore,
99
} from '~/lib/stores/settings';
1010
import { useCallback, useEffect, useState } from 'react';
1111
import Cookies from 'js-cookie';
@@ -15,25 +15,33 @@ import commit from '~/commit.json';
1515

1616
interface CommitData {
1717
commit: string;
18+
version?: string;
1819
}
1920

21+
const commitJson: CommitData = commit;
22+
2023
export function useSettings() {
2124
const providers = useStore(providersStore);
2225
const debug = useStore(isDebugMode);
2326
const eventLogs = useStore(isEventLogsEnabled);
2427
const isLocalModel = useStore(isLocalModelsEnabled);
25-
const useLatest = useStore(latestBranch);
28+
const latestBranch = useStore(latestBranchStore);
2629
const [activeProviders, setActiveProviders] = useState<ProviderInfo[]>([]);
2730

2831
// Function to check if we're on stable version
2932
const checkIsStableVersion = async () => {
3033
try {
31-
const stableResponse = await fetch('https://raw.githubusercontent.com/stackblitz-labs/bolt.diy/stable/app/commit.json');
34+
const stableResponse = await fetch(
35+
`https://raw.githubusercontent.com/stackblitz-labs/bolt.diy/refs/tags/v${commitJson.version}/app/commit.json`,
36+
);
37+
3238
if (!stableResponse.ok) {
3339
console.warn('Failed to fetch stable commit info');
3440
return false;
3541
}
36-
const stableData = await stableResponse.json() as CommitData;
42+
43+
const stableData = (await stableResponse.json()) as CommitData;
44+
3745
return commit.commit === stableData.commit;
3846
} catch (error) {
3947
console.warn('Error checking stable version:', error);
@@ -85,16 +93,23 @@ export function useSettings() {
8593
}
8694

8795
// load latest branch setting from cookies or determine based on version
88-
const savedLatestBranch = Cookies.get('useLatestBranch');
89-
if (savedLatestBranch === undefined) {
96+
const savedLatestBranch = Cookies.get('latestBranch');
97+
let checkCommit = Cookies.get('commitHash');
98+
99+
if (checkCommit === undefined) {
100+
checkCommit = commit.commit;
101+
}
102+
103+
if (savedLatestBranch === undefined || checkCommit !== commit.commit) {
90104
// If setting hasn't been set by user, check version
91-
checkIsStableVersion().then(isStable => {
105+
checkIsStableVersion().then((isStable) => {
92106
const shouldUseLatest = !isStable;
93-
latestBranch.set(shouldUseLatest);
94-
Cookies.set('useLatestBranch', String(shouldUseLatest));
107+
latestBranchStore.set(shouldUseLatest);
108+
Cookies.set('latestBranch', String(shouldUseLatest));
109+
Cookies.set('commitHash', String(commit.commit));
95110
});
96111
} else {
97-
latestBranch.set(savedLatestBranch === 'true');
112+
latestBranchStore.set(savedLatestBranch === 'true');
98113
}
99114
}, []);
100115

@@ -148,9 +163,9 @@ export function useSettings() {
148163
}, []);
149164

150165
const enableLatestBranch = useCallback((enabled: boolean) => {
151-
latestBranch.set(enabled);
166+
latestBranchStore.set(enabled);
152167
logStore.logSystem(`Main branch updates ${enabled ? 'enabled' : 'disabled'}`);
153-
Cookies.set('useLatestBranch', String(enabled));
168+
Cookies.set('latestBranch', String(enabled));
154169
}, []);
155170

156171
return {
@@ -163,7 +178,7 @@ export function useSettings() {
163178
enableEventLogs,
164179
isLocalModel,
165180
enableLocalModels,
166-
useLatestBranch: useLatest,
181+
latestBranch,
167182
enableLatestBranch,
168183
};
169184
}

app/lib/stores/settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ export const isEventLogsEnabled = atom(false);
4747

4848
export const isLocalModelsEnabled = atom(true);
4949

50-
export const latestBranch = atom(false);
50+
export const latestBranchStore = atom(false);

0 commit comments

Comments
 (0)