Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

feat: add connection test + editable model input for OpenAI-compatible STT

Louis Beaumontda52516623be
diff --git a/apps/screenpipe-app-tauri/components/settings/recording-settings.tsx b/apps/screenpipe-app-tauri/components/settings/recording-settings.tsx
index 7d747cb4d..f3a63343c 100644
--- a/apps/screenpipe-app-tauri/components/settings/recording-settings.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/recording-settings.tsx
@@ -41,6 +41,11 @@ import {
Zap,
User,
Users,
+ ChevronUp,
+ ChevronDown,
+ CheckCircle2,
+ XCircle,
+ Circle,
} from "lucide-react";
import { cn } from "@/lib/utils";
import {
@@ -189,6 +194,21 @@ const getAudioDeviceIcon = (name: string) => {
return Volume2;
};
+type TxDiagnosticStatus = "pass" | "fail" | "skip" | "pending" | "running";
+type TxDiagnosticStep = { status: TxDiagnosticStatus; message: string; latencyMs?: number };
+type TxDiagnostics = {
+ endpoint: TxDiagnosticStep;
+ auth: TxDiagnosticStep;
+ models: TxDiagnosticStep;
+ transcribe: TxDiagnosticStep;
+};
+const INITIAL_TX_DIAGNOSTICS: TxDiagnostics = {
+ endpoint: { status: "pending", message: "" },
+ auth: { status: "pending", message: "" },
+ models: { status: "pending", message: "" },
+ transcribe: { status: "pending", message: "" },
+};
+
export function RecordingSettings() {
const { settings, updateSettings, getDataDir, loadUser } = useSettings();
const [openLanguages, setOpenLanguages] = React.useState(false);
@@ -230,6 +250,13 @@ export function RecordingSettings() {
const [allOpenAIModels, setAllOpenAIModels] = useState<string[]>([]); // Store all models
const [isLoadingModels, setIsLoadingModels] = useState(false);
const [filterTranscriptionModels, setFilterTranscriptionModels] = useState(true); // Default to filtered
+
+ // Transcription diagnostics state
+ const [txTestStatus, setTxTestStatus] = useState<"idle" | "testing" | "done">("idle");
+ const [txTestResults, setTxTestResults] = useState<TxDiagnostics>(INITIAL_TX_DIAGNOSTICS);
+ const [txDiagnosticsOpen, setTxDiagnosticsOpen] = useState(false);
+ const txDiagnosticsAbortRef = useRef<AbortController | null>(null);
+
useEffect(() => {
commands.getHardwareCapability().then(setHwCapability).catch(() => {});
}, []);
@@ -468,29 +495,47 @@ export function RecordingSettings() {
}, []);
// Fetch OpenAI Compatible models when endpoint changes
+ // Tries /v1/models (OpenAI), then /api/tags (Ollama) as fallback
const fetchOpenAIModels = useCallback(async (endpoint: string, apiKey?: string) => {
setIsLoadingModels(true);
try {
- const headers: Record<string, string> = {
- 'Content-Type': 'application/json',
- };
+ const headers: Record<string, string> = {};
if (apiKey) {
headers['Authorization'] = `Bearer ${apiKey}`;
}
-
- const response = await fetch(`${endpoint}/v1/models`, {
- method: 'GET',
- headers,
- });
-
- if (!response.ok) {
- throw new Error('Failed to fetch models');
+
+ // Try OpenAI-style /v1/models first
+ let models: string[] = [];
+ try {
+ const response = await fetch(`${endpoint}/v1/models`, {
+ headers,
+ signal: AbortSignal.timeout(5000),
+ });
+ if (response.ok) {
+ const data = await response.json();
+ models = (data.data || []).map((m: any) => m.id).filter(Boolean);
+ }
+ } catch {
+ // endpoint may not support /v1/models — try Ollama fallback
}
-
- const data = await response.json();
- const models = data.data?.map((m: any) => m.id) || [];
- setAllOpenAIModels(models); // Store all models
- // Filtered models will be set by the useEffect below
+
+ // Fallback: try Ollama-style /api/tags
+ if (models.length === 0) {
+ try {
+ const ollamaResponse = await fetch(`${endpoint}/api/tags`, {
+ headers,
+ signal: AbortSignal.timeout(5000),
+ });
+ if (ollamaResponse.ok) {
+ const ollamaData = await ollamaResponse.json();
+ models = (ollamaData.models || []).map((m: any) => m.name).filter(Boolean);
+ }
+ } catch {
+ // Ollama endpoint also not available — models stays empty
+ }
+ }
+
+ setAllOpenAIModels(models);
} catch (error) {
console.error('Failed to fetch OpenAI models:', error);
setAllOpenAIModels(['!API_Error']);
@@ -526,6 +571,216 @@ export function RecordingSettings() {
}
}, [settings.audioTranscriptionEngine, settings.openaiCompatibleEndpoint, settings.openaiCompatibleApiKey, fetchOpenAIModels]);
+ // Run transcription diagnostics (endpoint → auth → models → transcription test)
+ const runTranscriptionDiagnostics = useCallback(async () => {
+ txDiagnosticsAbortRef.current?.abort();
+ const abort = new AbortController();
+ txDiagnosticsAbortRef.current = abort;
+
+ setTxTestStatus("testing");
+ setTxTestResults({
+ endpoint: { status: "pending", message: "" },
+ auth: { status: "pending", message: "" },
+ models: { status: "pending", message: "" },
+ transcribe: { status: "pending", message: "" },
+ });
+ setTxDiagnosticsOpen(true);
+
+ const endpoint = settings.openaiCompatibleEndpoint || "http://127.0.0.1:8080";
+ const apiKey = settings.openaiCompatibleApiKey;
+
+ const headers: Record<string, string> = {};
+ if (apiKey) {
+ headers["Authorization"] = `Bearer ${apiKey}`;
+ }
+
+ const skipRemaining = (failStep: string, message: string) => {
+ const steps = ["endpoint", "auth", "models", "transcribe"] as const;
+ const failIdx = steps.indexOf(failStep as any);
+ setTxTestResults((prev) => ({
+ ...prev,
+ [failStep]: { status: "fail" as const, message },
+ ...Object.fromEntries(
+ steps
+ .filter((_, i) => i > failIdx)
+ .map((k) => [k, { status: "skip" as const, message: "Skipped" }])
+ ),
+ }));
+ setTxTestStatus("done");
+ };
+
+ // Step 1: Endpoint connectivity — try root URL or /v1/models
+ setTxTestResults((prev) => ({
+ ...prev,
+ endpoint: { status: "running", message: "Connecting..." },
+ }));
+
+ let endpointReachable = false;
+ try {
+ await fetch(endpoint, { signal: abort.signal, method: "GET" });
+ endpointReachable = true;
+ } catch {
+ // root URL failed, try /v1/models as fallback
+ try {
+ await fetch(`${endpoint}/v1/models`, { headers, signal: abort.signal });
+ endpointReachable = true;
+ } catch {
+ // neither worked
+ }
+ }
+
+ if (abort.signal.aborted) return;
+
+ if (!endpointReachable) {
+ skipRemaining("endpoint", `Connection failed. Is the server running at ${endpoint}?`);
+ return;
+ }
+
+ setTxTestResults((prev) => ({
+ ...prev,
+ endpoint: { status: "pass", message: `Server reachable` },
+ auth: { status: "running", message: "Checking..." },
+ }));
+
+ // Step 2+3: Try to list models (also tests auth)
+ let modelCount = 0;
+ // Try OpenAI-style /v1/models
+ try {
+ const modelsResponse = await fetch(`${endpoint}/v1/models`, {
+ headers,
+ signal: abort.signal,
+ });
+ if (modelsResponse.status === 401 || modelsResponse.status === 403) {
+ skipRemaining("auth", `${modelsResponse.status} Unauthorized. Check your API key.`);
+ return;
+ }
+ if (modelsResponse.ok) {
+ const data = await modelsResponse.json();
+ modelCount = (data.data || []).filter((m: any) => m.id).length;
+ }
+ } catch {
+ // /v1/models not available, try Ollama fallback
+ }
+
+ // Fallback: try Ollama-style /api/tags
+ if (modelCount === 0) {
+ try {
+ const ollamaResponse = await fetch(`${endpoint}/api/tags`, {
+ headers,
+ signal: abort.signal,
+ });
+ if (ollamaResponse.ok) {
+ const ollamaData = await ollamaResponse.json();
+ modelCount = (ollamaData.models || []).filter((m: any) => m.name).length;
+ }
+ } catch {
+ // no models endpoint available
+ }
+ }
+
+ if (abort.signal.aborted) return;
+
+ setTxTestResults((prev) => ({
+ ...prev,
+ auth: { status: "pass", message: apiKey ? "API key accepted" : "No auth required" },
+ models: {
+ status: "pass",
+ message: modelCount > 0
+ ? `${modelCount} model${modelCount !== 1 ? "s" : ""} available`
+ : "No models listed (you can still type a model name)",
+ },
+ transcribe: { status: "running", message: "Sending test audio..." },
+ }));
+
+ // Step 4: Test transcription with a short silent WAV
+ const model = settings.openaiCompatibleModel || "";
+ const txStart = performance.now();
+ try {
+ // Generate a minimal 1-second silent 16kHz mono WAV
+ const sampleRate = 16000;
+ const numSamples = sampleRate; // 1 second
+ const dataSize = numSamples * 2; // 16-bit = 2 bytes per sample
+ const buffer = new ArrayBuffer(44 + dataSize);
+ const view = new DataView(buffer);
+ // WAV header
+ const writeStr = (offset: number, str: string) => {
+ for (let i = 0; i < str.length; i++) view.setUint8(offset + i, str.charCodeAt(i));
+ };
+ writeStr(0, "RIFF");
+ view.setUint32(4, 36 + dataSize, true);
+ writeStr(8, "WAVE");
+ writeStr(12, "fmt ");
+ view.setUint32(16, 16, true); // subchunk size
+ view.setUint16(20, 1, true); // PCM
+ view.setUint16(22, 1, true); // mono
+ view.setUint32(24, sampleRate, true);
+ view.setUint32(28, sampleRate * 2, true); // byte rate
+ view.setUint16(32, 2, true); // block align
+ view.setUint16(34, 16, true); // bits per sample
+ writeStr(36, "data");
+ view.setUint32(40, dataSize, true);
+ // samples are zero (silence)
+
+ const blob = new Blob([buffer], { type: "audio/wav" });
+ const formData = new FormData();
+ formData.append("file", blob, "test.wav");
+ formData.append("model", model);
+ formData.append("response_format", "json");
+
+ const txResponse = await fetch(`${endpoint}/v1/audio/transcriptions`, {
+ method: "POST",
+ headers: apiKey ? { Authorization: `Bearer ${apiKey}` } : {},
+ body: formData,
+ signal: abort.signal,
+ });
+
+ const latencyMs = Math.round(performance.now() - txStart);
+
+ if (!txResponse.ok) {
+ const errText = await txResponse.text().catch(() => "");
+ setTxTestResults((prev) => ({
+ ...prev,
+ transcribe: {
+ status: "fail",
+ message: `${txResponse.status}: ${errText.slice(0, 120) || "Request failed"}`,
+ latencyMs,
+ },
+ }));
+ setTxTestStatus("done");
+ return;
+ }
+
+ const txData = await txResponse.json();
+ const text = txData.text ?? "";
+
+ if (abort.signal.aborted) return;
+
+ setTxTestResults((prev) => ({
+ ...prev,
+ transcribe: {
+ status: "pass",
+ message: text
+ ? `OK (${latencyMs}ms): "${text.slice(0, 80)}"`
+ : `OK (${latencyMs}ms): empty transcription (silent audio)`,
+ latencyMs,
+ },
+ }));
+ } catch (err: any) {
+ if (abort.signal.aborted) return;
+ const latencyMs = Math.round(performance.now() - txStart);
+ setTxTestResults((prev) => ({
+ ...prev,
+ transcribe: {
+ status: "fail",
+ message: `Transcription failed: ${err.message || "Unknown error"}`,
+ latencyMs,
+ },
+ }));
+ }
+
+ setTxTestStatus("done");
+ }, [settings.openaiCompatibleEndpoint, settings.openaiCompatibleApiKey, settings.openaiCompatibleModel]);
+
// Enhanced validation for specific fields
const validateDeepgramApiKey = useCallback((apiKey: string): FieldValidationResult => {
if (!apiKey.trim()) {
@@ -1165,41 +1420,170 @@ Your screen is a pipe. Everything you see, hear, and type flows through it. Scre
</Button>
</div>
- {/* Model Filter Toggle */}
- <div className="flex items-center justify-between">
- <span className="text-xs text-muted-foreground">Show only transcription models</span>
- <Switch
- checked={filterTranscriptionModels}
- onCheckedChange={setFilterTranscriptionModels}
- className="data-[state=checked]:bg-primary"
- />
+ {/* Model Input — editable with dropdown suggestions */}
+ <div className="space-y-1.5">
+ <div className="relative">
+ <Input
+ value={settings.openaiCompatibleModel || ""}
+ onChange={(e) => handleSettingsChange({ openaiCompatibleModel: e.target.value }, true)}
+ placeholder={isLoadingModels ? "Loading models..." : "Model name (e.g., whisper-large-v3-turbo)"}
+ className="h-7 text-xs pr-8"
+ />
+ {isLoadingModels && (
+ <Loader2 className="h-3 w-3 animate-spin absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground" />
+ )}
+ </div>
+ {openAIModels.length > 0 && !openAIModels.includes('!API_Error') && (
+ <div className="space-y-1">
+ <div className="flex items-center justify-between">
+ <span className="text-xs text-muted-foreground">
+ Available models ({openAIModels.length})
+ </span>
+ {allOpenAIModels.length > 0 && (
+ <button
+ type="button"
+ className="text-xs text-muted-foreground hover:text-foreground transition-colors"
+ onClick={() => setFilterTranscriptionModels(!filterTranscriptionModels)}
+ >
+ {filterTranscriptionModels ? "show all" : "filter STT only"}
+ </button>
+ )}
+ </div>
+ <div className="flex flex-wrap gap-1">
+ {openAIModels.map((model) => (
+ <button
+ key={model}
+ type="button"
+ className={cn(
+ "px-2 py-0.5 rounded text-xs border transition-colors",
+ settings.openaiCompatibleModel === model
+ ? "bg-foreground text-background border-foreground"
+ : "hover:bg-accent border-border"
+ )}
+ onClick={() => handleSettingsChange({ openaiCompatibleModel: model }, true)}
+ >
+ {model}
+ </button>
+ ))}
+ </div>
+ </div>
+ )}
+ {openAIModels.includes('!API_Error') && (
+ <p className="text-xs text-muted-foreground">Could not list models from the API — type the model name manually.</p>
+ )}
+ {allOpenAIModels.length === 0 && !openAIModels.includes('!API_Error') && !isLoadingModels && (
+ <p className="text-xs text-muted-foreground">No models listed by the API — type the model name manually.</p>
+ )}
+ </div>
+
+ {/* Connection Test Panel */}
+ <div className="border rounded-lg">
+ <button
+ type="button"
+ className="flex items-center justify-between w-full px-3 py-2 text-xs font-medium text-left hover:bg-accent/50 transition-colors rounded-lg"
+ onClick={() => setTxDiagnosticsOpen(!txDiagnosticsOpen)}
+ >
+ <div className="flex items-center gap-2">
+ <Zap className="h-3.5 w-3.5" />
+ <span>Connection Test</span>
+ {txTestStatus === "done" && (
+ <span className="text-xs text-muted-foreground">
+ {txTestResults.transcribe.status === "pass"
+ ? "All checks passed"
+ : txTestResults.endpoint.status === "fail"
+ ? "Connection failed"
+ : txTestResults.auth.status === "fail"
+ ? "Auth failed"
+ : txTestResults.models.status === "fail"
+ ? "Models failed"
+ : txTestResults.transcribe.status === "fail"
+ ? "Transcription failed"
+ : ""}
+ </span>
+ )}
+ </div>
+ <div className="flex items-center gap-2">
+ {txTestStatus === "testing" && (
+ <Loader2 className="h-3 w-3 animate-spin text-muted-foreground" />
+ )}
+ {txDiagnosticsOpen ? (
+ <ChevronUp className="h-3.5 w-3.5 text-muted-foreground" />
+ ) : (
+ <ChevronDown className="h-3.5 w-3.5 text-muted-foreground" />
+ )}
+ </div>
+ </button>
+
+ {txDiagnosticsOpen && (
+ <div className="px-3 pb-3 space-y-2">
+ <Button
+ variant="outline"
+ size="sm"
+ onClick={runTranscriptionDiagnostics}
+ disabled={txTestStatus === "testing"}
+ className="flex items-center gap-2 h-7 text-xs"
+ >
+ {txTestStatus === "testing" ? (
+ <Loader2 className="h-3 w-3 animate-spin" />
+ ) : (
+ <Zap className="h-3 w-3" />
+ )}
+ {txTestStatus === "testing" ? "Testing..." : "Run diagnostics"}
+ </Button>
+
+ <div className="space-y-1.5 text-xs">
+ {(
+ [
+ ["endpoint", "1", "Endpoint reachable"],
+ ["auth", "2", "Auth valid"],
+ ["models", "3", "Models loaded"],
+ ["transcribe", "4", "Test transcription"],
+ ] as const
+ ).map(([key, num, label]) => {
+ const result = txTestResults[key];
+ return (
+ <div key={key} className="flex items-start gap-2">
+ <div className="flex items-center gap-1.5 min-w-[150px]">
+ {result.status === "pass" ? (
+ <CheckCircle2 className="h-3.5 w-3.5 text-foreground shrink-0" />
+ ) : result.status === "fail" ? (
+ <XCircle className="h-3.5 w-3.5 text-destructive shrink-0" />
+ ) : result.status === "running" ? (
+ <Loader2 className="h-3.5 w-3.5 animate-spin text-muted-foreground shrink-0" />
+ ) : (
+ <Circle className="h-3.5 w-3.5 text-muted-foreground/40 shrink-0" />
+ )}
+ <span
+ className={cn(
+ result.status === "skip" || result.status === "pending"
+ ? "text-muted-foreground/40"
+ : result.status === "fail"
+ ? "text-destructive"
+ : ""
+ )}
+ >
+ {num}. {label}
+ </span>
+ </div>
+ {result.message && (
+ <span
+ className={cn(
+ "text-xs",
+ result.status === "fail"
+ ? "text-destructive"
+ : "text-muted-foreground"
+ )}
+ >
+ {result.message}
+ </span>
+ )}
+ </div>
+ );
+ })}
+ </div>
+ </div>
+ )}
</div>
-
- {/* Model Selection */}
- <Select
- value={settings.openaiCompatibleModel || ""}
- onValueChange={(value) => handleSettingsChange({ openaiCompatibleModel: value }, true)}
- disabled={openAIModels.length === 0 || openAIModels.includes('!API_Error')}
- >
- <SelectTrigger className="w-full h-7 text-xs">
- <SelectValue placeholder={
- isLoadingModels ? "Loading models..." :
- openAIModels.includes('!API_Error') ? "Failed to connect to API" :
- "Select model"
- } />
- </SelectTrigger>
- <SelectContent>
- {openAIModels.filter(m => m !== '!API_Error').map((model) => (
- <SelectItem key={model} value={model}>{model}</SelectItem>
- ))}
- </SelectContent>
- </Select>
- {openAIModels.includes('!API_Error') && (
- <p className="text-xs text-destructive">Could not reach the API endpoint. Check the URL and try again.</p>
- )}
- {filterTranscriptionModels && openAIModels.length === 0 && allOpenAIModels.length > 0 && (
- <p className="text-xs text-muted-foreground">No transcription models found. Toggle off the filter to see all models.</p>
- )}
</div>
)}
</CardContent>