Skip to content

Commit 4016f54

Browse files
ui-ux: debug-tab
debug tab check for update is now branch specific. fixed bug with getting URLs for experimental models
2 parents 4caae9c + b5c8d43 commit 4016f54

File tree

4 files changed

+104
-45
lines changed

4 files changed

+104
-45
lines changed

app/components/settings/debug/DebugTab.tsx

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,20 @@ interface IProviderConfig {
2828
name: string;
2929
settings: {
3030
enabled: boolean;
31+
baseUrl?: string;
3132
};
3233
}
3334

35+
interface CommitData {
36+
commit: string;
37+
}
38+
3439
const LOCAL_PROVIDERS = ['Ollama', 'LMStudio', 'OpenAILike'];
3540
const versionHash = commit.commit;
3641
const GITHUB_URLS = {
3742
original: 'https://api.github.com/repos/stackblitz-labs/bolt.diy/commits/main',
3843
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`,
3945
};
4046

4147
function getSystemInfo(): SystemInfo {
@@ -200,7 +206,7 @@ const checkProviderStatus = async (url: string | null, providerName: string): Pr
200206
};
201207

202208
export default function DebugTab() {
203-
const { providers } = useSettings();
209+
const { providers, useLatestBranch } = useSettings();
204210
const [activeProviders, setActiveProviders] = useState<ProviderStatus[]>([]);
205211
const [updateMessage, setUpdateMessage] = useState<string>('');
206212
const [systemInfo] = useState<SystemInfo>(getSystemInfo());
@@ -213,29 +219,30 @@ export default function DebugTab() {
213219

214220
try {
215221
const entries = Object.entries(providers) as [string, IProviderConfig][];
216-
const statuses = entries
217-
.filter(([, provider]) => LOCAL_PROVIDERS.includes(provider.name))
218-
.map(async ([, provider]) => {
219-
const envVarName =
220-
provider.name.toLowerCase() === 'ollama'
221-
? 'OLLAMA_API_BASE_URL'
222-
: provider.name.toLowerCase() === 'lmstudio'
222+
const statuses = await Promise.all(
223+
entries
224+
.filter(([, provider]) => LOCAL_PROVIDERS.includes(provider.name))
225+
.map(async ([, provider]) => {
226+
const envVarName =
227+
provider.name.toLowerCase() === 'ollama'
228+
? 'OLLAMA_API_BASE_URL'
229+
: provider.name.toLowerCase() === 'lmstudio'
223230
? 'LMSTUDIO_API_BASE_URL'
224231
: `REACT_APP_${provider.name.toUpperCase()}_URL`;
225232

226-
// Access environment variables through import.meta.env
227-
const url = import.meta.env[envVarName] || null;
228-
console.log(`[Debug] Using URL for ${provider.name}:`, url, `(from ${envVarName})`);
233+
// Access environment variables through import.meta.env
234+
const url = import.meta.env[envVarName] || provider.settings.baseUrl || null; // Ensure baseUrl is used
235+
console.log(`[Debug] Using URL for ${provider.name}:`, url, `(from ${envVarName})`);
229236

230-
const status = await checkProviderStatus(url, provider.name);
237+
const status = await checkProviderStatus(url, provider.name);
238+
return {
239+
...status,
240+
enabled: provider.settings.enabled ?? false,
241+
};
242+
})
243+
);
231244

232-
return {
233-
...status,
234-
enabled: provider.settings.enabled ?? false,
235-
};
236-
});
237-
238-
Promise.all(statuses).then(setActiveProviders);
245+
setActiveProviders(statuses);
239246
} catch (error) {
240247
console.error('[Debug] Failed to update provider statuses:', error);
241248
}
@@ -258,40 +265,34 @@ export default function DebugTab() {
258265
setIsCheckingUpdate(true);
259266
setUpdateMessage('Checking for updates...');
260267

261-
const [originalResponse, forkResponse] = await Promise.all([
262-
fetch(GITHUB_URLS.original),
263-
fetch(GITHUB_URLS.fork),
264-
]);
268+
const branchToCheck = useLatestBranch ? 'main' : 'stable';
269+
console.log(`[Debug] Checking for updates against ${branchToCheck} branch`);
265270

266-
if (!originalResponse.ok || !forkResponse.ok) {
267-
throw new Error('Failed to fetch repository information');
271+
const localCommitResponse = await fetch(GITHUB_URLS.commitJson(branchToCheck));
272+
if (!localCommitResponse.ok) {
273+
throw new Error('Failed to fetch local commit info');
268274
}
269275

270-
const [originalData, forkData] = await Promise.all([
271-
originalResponse.json() as Promise<{ sha: string }>,
272-
forkResponse.json() as Promise<{ sha: string }>,
273-
]);
274-
275-
const originalCommitHash = originalData.sha;
276-
const forkCommitHash = forkData.sha;
277-
const isForked = versionHash === forkCommitHash && forkCommitHash !== originalCommitHash;
276+
const localCommitData = await localCommitResponse.json() as CommitData;
277+
const remoteCommitHash = localCommitData.commit;
278+
const currentCommitHash = versionHash;
278279

279-
if (originalCommitHash !== versionHash) {
280+
if (remoteCommitHash !== currentCommitHash) {
280281
setUpdateMessage(
281-
`Update available from original repository!\n` +
282-
`Current: ${versionHash.slice(0, 7)}${isForked ? ' (forked)' : ''}\n` +
283-
`Latest: ${originalCommitHash.slice(0, 7)}`,
282+
`Update available from ${branchToCheck} branch!\n` +
283+
`Current: ${currentCommitHash.slice(0, 7)}\n` +
284+
`Latest: ${remoteCommitHash.slice(0, 7)}`
284285
);
285286
} else {
286-
setUpdateMessage('You are on the latest version from the original repository');
287+
setUpdateMessage(`You are on the latest version from the ${branchToCheck} branch`);
287288
}
288289
} catch (error) {
289290
setUpdateMessage('Failed to check for updates');
290291
console.error('[Debug] Failed to check for updates:', error);
291292
} finally {
292293
setIsCheckingUpdate(false);
293294
}
294-
}, [isCheckingUpdate]);
295+
}, [isCheckingUpdate, useLatestBranch]);
295296

296297
const handleCopyToClipboard = useCallback(() => {
297298
const debugInfo = {
@@ -306,14 +307,17 @@ export default function DebugTab() {
306307
responseTime: provider.responseTime,
307308
url: provider.url,
308309
})),
309-
Version: versionHash,
310+
Version: {
311+
hash: versionHash.slice(0, 7),
312+
branch: useLatestBranch ? 'main' : 'stable'
313+
},
310314
Timestamp: new Date().toISOString(),
311315
};
312316

313317
navigator.clipboard.writeText(JSON.stringify(debugInfo, null, 2)).then(() => {
314318
toast.success('Debug information copied to clipboard!');
315319
});
316-
}, [activeProviders, systemInfo]);
320+
}, [activeProviders, systemInfo, useLatestBranch]);
317321

318322
return (
319323
<div className="p-4 space-y-6">

app/components/settings/features/FeaturesTab.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ 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 } = useSettings();
6+
const { debug, enableDebugMode, isLocalModel, enableLocalModels, eventLogs, enableEventLogs, useLatestBranch, enableLatestBranch } = useSettings();
77

88
const handleToggle = (enabled: boolean) => {
99
enableDebugMode(enabled);
@@ -14,9 +14,18 @@ export default function FeaturesTab() {
1414
<div className="p-4 bg-bolt-elements-bg-depth-2 border border-bolt-elements-borderColor rounded-lg mb-4">
1515
<div className="mb-6">
1616
<h3 className="text-lg font-medium text-bolt-elements-textPrimary mb-4">Optional Features</h3>
17-
<div className="flex items-center justify-between mb-2">
18-
<span className="text-bolt-elements-textPrimary">Debug Features</span>
19-
<Switch className="ml-auto" checked={debug} onCheckedChange={handleToggle} />
17+
<div className="space-y-4">
18+
<div className="flex items-center justify-between">
19+
<span className="text-bolt-elements-textPrimary">Debug Features</span>
20+
<Switch className="ml-auto" checked={debug} onCheckedChange={handleToggle} />
21+
</div>
22+
<div className="flex items-center justify-between">
23+
<div>
24+
<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+
</div>
27+
<Switch className="ml-auto" checked={useLatestBranch} onCheckedChange={enableLatestBranch} />
28+
</div>
2029
</div>
2130
</div>
2231

app/lib/hooks/useSettings.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,42 @@ import {
55
isLocalModelsEnabled,
66
LOCAL_PROVIDERS,
77
providersStore,
8+
latestBranch,
89
} from '~/lib/stores/settings';
910
import { useCallback, useEffect, useState } from 'react';
1011
import Cookies from 'js-cookie';
1112
import type { IProviderSetting, ProviderInfo } from '~/types/model';
1213
import { logStore } from '~/lib/stores/logs'; // assuming logStore is imported from this location
14+
import commit from '~/commit.json';
15+
16+
interface CommitData {
17+
commit: string;
18+
}
1319

1420
export function useSettings() {
1521
const providers = useStore(providersStore);
1622
const debug = useStore(isDebugMode);
1723
const eventLogs = useStore(isEventLogsEnabled);
1824
const isLocalModel = useStore(isLocalModelsEnabled);
25+
const useLatest = useStore(latestBranch);
1926
const [activeProviders, setActiveProviders] = useState<ProviderInfo[]>([]);
2027

28+
// Function to check if we're on stable version
29+
const checkIsStableVersion = async () => {
30+
try {
31+
const stableResponse = await fetch('https://raw.githubusercontent.com/stackblitz-labs/bolt.diy/stable/app/commit.json');
32+
if (!stableResponse.ok) {
33+
console.warn('Failed to fetch stable commit info');
34+
return false;
35+
}
36+
const stableData = await stableResponse.json() as CommitData;
37+
return commit.commit === stableData.commit;
38+
} catch (error) {
39+
console.warn('Error checking stable version:', error);
40+
return false;
41+
}
42+
};
43+
2144
// reading values from cookies on mount
2245
useEffect(() => {
2346
const savedProviders = Cookies.get('providers');
@@ -60,6 +83,19 @@ export function useSettings() {
6083
if (savedLocalModels) {
6184
isLocalModelsEnabled.set(savedLocalModels === 'true');
6285
}
86+
87+
// load latest branch setting from cookies or determine based on version
88+
const savedLatestBranch = Cookies.get('useLatestBranch');
89+
if (savedLatestBranch === undefined) {
90+
// If setting hasn't been set by user, check version
91+
checkIsStableVersion().then(isStable => {
92+
const shouldUseLatest = !isStable;
93+
latestBranch.set(shouldUseLatest);
94+
Cookies.set('useLatestBranch', String(shouldUseLatest));
95+
});
96+
} else {
97+
latestBranch.set(savedLatestBranch === 'true');
98+
}
6399
}, []);
64100

65101
// writing values to cookies on change
@@ -111,6 +147,12 @@ export function useSettings() {
111147
Cookies.set('isLocalModelsEnabled', String(enabled));
112148
}, []);
113149

150+
const enableLatestBranch = useCallback((enabled: boolean) => {
151+
latestBranch.set(enabled);
152+
logStore.logSystem(`Main branch updates ${enabled ? 'enabled' : 'disabled'}`);
153+
Cookies.set('useLatestBranch', String(enabled));
154+
}, []);
155+
114156
return {
115157
providers,
116158
activeProviders,
@@ -121,5 +163,7 @@ export function useSettings() {
121163
enableEventLogs,
122164
isLocalModel,
123165
enableLocalModels,
166+
useLatestBranch: useLatest,
167+
enableLatestBranch,
124168
};
125169
}

app/lib/stores/settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,5 @@ export const isDebugMode = atom(false);
4646
export const isEventLogsEnabled = atom(false);
4747

4848
export const isLocalModelsEnabled = atom(true);
49+
50+
export const latestBranch = atom(false);

0 commit comments

Comments
 (0)