SQLR-70 — Desktop playground: in-app Settings for Anthropic API key#146
Merged
Conversation
The SQL playground (`sqlrite-desktop`) read its `ask` config exclusively from `SQLRITE_LLM_API_KEY`. Launched from Finder/the Dock — which don't inherit a shell's env — the Ask… button just errored. Port the in-app settings pattern from the journal example (SQLR-41, #145) so the key can be pasted in a ⚙ dialog and persists across restarts. - settings.rs: AskSettings (JSON at $APP_DATA/com.sqlrite.desktop/ settings.json), scrubbed AskSettingsDto (has_api_key bool — the raw key never crosses to the webview), three-valued AskSettingsUpdate, build_ask_config (saved key, env var fallback). 5 unit tests. - main.rs: AppState gains settings_path; ask_sql builds config from saved settings instead of from_env; add get_ask_settings / update_ask_settings commands. - SettingsPanel.svelte (plain-CSS, matches the playground) + ⚙ header button + lib/api.ts wrappers. - README: Configuring `ask` + security note. Deviation from the journal port: build_ask_config is unconditional (the desktop crate has no `ask` feature gate) and tempdir() in tests uses an atomic counter, not subsec-nanos, to avoid a parallel-run collision. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
The SQL playground (
sqlrite-desktop) read itsaskconfig exclusively fromSQLRITE_LLM_API_KEYin the environment. Launched from Finder / the Dock — which don't inherit a shell's env — the Ask… button just errored. This ports the in-app settings pattern we shipped for the journal example app (SQLR-41 / #145) into the playground, so a user can paste a key in a ⚙ dialog and it persists across restarts. Env var still works as a fallback for existing dev workflows.Changes
Rust (
desktop/src-tauri/)src/settings.rs(new) —AskSettingspersisted as JSON to$APP_DATA/com.sqlrite.desktop/settings.json; scrubbedAskSettingsDto(has_api_key: bool— the raw key never crosses to the webview); three-valuedAskSettingsUpdate;build_ask_config()(prefers saved key, falls back toSQLRITE_LLM_API_KEY);settings_path(). 5 unit tests.src/main.rs—AppStategainssettings_path(resolved fromapp_data_dir()insetup);ask_sqlbuilds config from saved settings instead ofAskConfig::from_env(); newget_ask_settings/update_ask_settingscommands registered.Frontend (
desktop/src/)lib/SettingsPanel.svelte(new) — gear-modal, rewritten in the playground's plain-CSS idiom (the playground uses globalapp.cssvars, not Tailwind like the journal). Password field, model, max-tokens, "Clear saved key", status line, Esc-to-close, security note.lib/api.ts(new) —getAskSettings/updateAskSettingswrappers with null→absent normalisation.App.svelte— ⚙ header button mounts the panel.app.css—.settings-buttonrule.desktop/README.md(new) — "Configuringask" section + security note (no README existed).Deviations from the journal port
build_ask_configis unconditional — the desktop crate has noaskfeature gate and always builds the engine withaskon (matching the existing unconditionalask_sql). So all 5 tests always run.tempdir()in tests uses a process-wideAtomicU64counter instead ofsubsec_nanos()— the journal's version has a latent parallel-run collision that surfaced here (fixed; see follow-up).Test plan — all green locally
npm install+npm run build(vite) +npm run check(svelte-check: 0 errors/warnings)cargo test -p sqlrite-desktop→ 5/5 pass, stable across 3 runscargo build -p sqlrite-desktop --all-targets,cargo fmt --check,cargo clippy→ new code has 0 warnings (remaining clippy hits are pre-existing)Not verified: live end-to-end LLM call (needs a real key + network) and the literal Finder-launch scenario (headless run). Both are covered indirectly by unit tests + the binary compiling against the embedded
dist/.Follow-up
The journal app's
examples/desktop-journal/src-tauri/src/settings.rshas the identical flakytempdir()— worth a small ticket to port this fix back.🤖 Generated with Claude Code