Implement toggle thinking blocks with localStorage persistence

- Add preferences store to manage user preferences in localStorage
- Toggle thinking blocks visibility via command palette (default: hidden)
- Dynamic command label shows current state (Show/Hide Thinking Blocks)
- Filter reasoning parts based on preference in message-stream
- Conditionally render reasoning parts in message-part component
- Support function labels in Command interface for dynamic text
This commit is contained in:
Shantur Rathore
2025-10-24 18:24:35 +01:00
parent e58462b926
commit be3acd6724
6 changed files with 72 additions and 20 deletions

45
src/stores/preferences.ts Normal file
View File

@@ -0,0 +1,45 @@
import { createSignal } from "solid-js"
const STORAGE_KEY = "opencode-preferences"
interface Preferences {
showThinkingBlocks: boolean
}
const defaultPreferences: Preferences = {
showThinkingBlocks: false,
}
function loadPreferences(): Preferences {
try {
const stored = localStorage.getItem(STORAGE_KEY)
if (stored) {
return { ...defaultPreferences, ...JSON.parse(stored) }
}
} catch (error) {
console.error("Failed to load preferences:", error)
}
return defaultPreferences
}
function savePreferences(prefs: Preferences): void {
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(prefs))
} catch (error) {
console.error("Failed to save preferences:", error)
}
}
const [preferences, setPreferences] = createSignal<Preferences>(loadPreferences())
function updatePreferences(updates: Partial<Preferences>): void {
const updated = { ...preferences(), ...updates }
setPreferences(updated)
savePreferences(updated)
}
function toggleShowThinkingBlocks(): void {
updatePreferences({ showThinkingBlocks: !preferences().showThinkingBlocks })
}
export { preferences, updatePreferences, toggleShowThinkingBlocks }