Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
fix: update anthropic model names and openAI migration to responses API
Gabriel Stein3b4197fe2ddb
diff --git a/preload.js b/preload.jsindex 4b5d47b57..1e67c09ae 100644--- a/preload.js+++ b/preload.js@@ -114,6 +114,10 @@ contextBridge.exposeInMainWorld("electronAPI", {checkLocalReasoningAvailable: () =>ipcRenderer.invoke("check-local-reasoning-available"),+ // Anthropic reasoning+ processAnthropicReasoning: (text, modelId, agentName, config) =>+ ipcRenderer.invoke("process-anthropic-reasoning", text, modelId, agentName, config),+// llama.cppllamaCppCheck: () => ipcRenderer.invoke("llama-cpp-check"),llamaCppInstall: () => ipcRenderer.invoke("llama-cpp-install"),diff --git a/src/config/constants.ts b/src/config/constants.tsindex b75d310ad..76f5b4caa 100644--- a/src/config/constants.ts+++ b/src/config/constants.ts@@ -1,6 +1,6 @@// API Configurationexport const API_ENDPOINTS = {- OPENAI: 'https://api.openai.com/v1/chat/completions',+ OPENAI: 'https://api.openai.com/v1/responses',ANTHROPIC: 'https://api.anthropic.com/v1/messages',GEMINI: 'https://generativelanguage.googleapis.com/v1beta',} as const;diff --git a/src/helpers/audioManager.js b/src/helpers/audioManager.jsindex cb91a1ae0..be8dbf88f 100644--- a/src/helpers/audioManager.js+++ b/src/helpers/audioManager.js@@ -186,8 +186,9 @@ class AudioManager {if (result.success && result.text) {const text = await this.processTranscription(result.text, "local");- if (text) {- return { success: true, text, source: "local" };+ // Allow empty strings as valid responses (reasoning service might return cleaned empty text)+ if (text !== null && text !== undefined) {+ return { success: true, text: text || result.text, source: "local" };} else {throw new Error("No text transcribed");}diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.jsindex 14ea1b3dc..527868d65 100644--- a/src/helpers/ipcHandlers.js+++ b/src/helpers/ipcHandlers.js@@ -387,6 +387,58 @@ class IPCHandlers {}});+ // Anthropic reasoning handler+ ipcMain.handle("process-anthropic-reasoning", async (event, text, modelId, agentName, config) => {+ try {+ const apiKey = this.environmentManager.getAnthropicKey();++ if (!apiKey) {+ throw new Error("Anthropic API key not configured");+ }++ const systemPrompt = "You are a dictation assistant. Clean up text by fixing grammar and punctuation. Output ONLY the cleaned text without any explanations, options, or commentary.";+ const userPrompt = agentName && text.toLowerCase().includes(agentName.toLowerCase())+ ? `You are ${agentName}, a helpful AI assistant. Clean up the following dictated text by fixing grammar, punctuation, and formatting. Remove any reference to your name. Output ONLY the cleaned text without explanations or options:\n\n${text}`+ : `Clean up the following dictated text by fixing grammar, punctuation, and formatting. Output ONLY the cleaned text without any explanations, options, or commentary:\n\n${text}`;++ const requestBody = {+ model: modelId || "claude-3-5-sonnet-20241022",+ messages: [{ role: "user", content: userPrompt }],+ system: systemPrompt,+ max_tokens: config?.maxTokens || Math.max(100, Math.min(text.length * 2, 4096)),+ temperature: config?.temperature || 0.3,+ };++ const response = await fetch("https://api.anthropic.com/v1/messages", {+ method: "POST",+ headers: {+ "Content-Type": "application/json",+ "X-API-Key": apiKey,+ "anthropic-version": "2023-06-01",+ },+ body: JSON.stringify(requestBody),+ });++ if (!response.ok) {+ const errorText = await response.text();+ let errorData = { error: response.statusText };+ try {+ errorData = JSON.parse(errorText);+ } catch {+ errorData = { error: errorText || response.statusText };+ }+ throw new Error(errorData.error?.message || errorData.error || `Anthropic API error: ${response.status}`);+ }++ const data = await response.json();+ return { success: true, text: data.content[0].text.trim() };+ } catch (error) {+ debugLogger.error("Anthropic reasoning error:", error);+ return { success: false, error: error.message };+ }+ });++// Check if local reasoning is availableipcMain.handle("check-local-reasoning-available", async () => {try {diff --git a/src/services/ReasoningService.ts b/src/services/ReasoningService.tsindex 8f2eedbaf..897403229 100644--- a/src/services/ReasoningService.ts+++ b/src/services/ReasoningService.ts@@ -172,24 +172,28 @@ class ReasoningService extends BaseReasoningService {const systemPrompt = "You are a dictation assistant. Clean up text by fixing grammar and punctuation. Output ONLY the cleaned text without any explanations, options, or commentary.";const userPrompt = this.getReasoningPrompt(text, agentName, config);- const requestBody = {+ // Build input array for Responses API+ const input = [+ { role: "system", content: systemPrompt },+ { role: "user", content: userPrompt }+ ];++ // Build request body for Responses API+ const requestBody: any = {model: model || "gpt-4o-mini",- messages: [- { role: "system", content: systemPrompt },- { role: "user", content: userPrompt }- ],- max_tokens: config.maxTokens || this.calculateMaxTokens(- text.length,- TOKEN_LIMITS.MIN_TOKENS,- TOKEN_LIMITS.MAX_TOKENS,- TOKEN_LIMITS.TOKEN_MULTIPLIER- ),- temperature: config.temperature || 0.3,+ input: input,+ store: false, // Don't store responses for privacy};+ // Add temperature for older models (GPT-4 and earlier)+ const isOlderModel = model && (model.startsWith('gpt-4') || model.startsWith('gpt-3'));+ if (isOlderModel) {+ requestBody.temperature = config.temperature || 0.3;+ }+const response = await withRetry(async () => {- const res = await fetch(`${API_ENDPOINTS.OPENAI}/chat/completions`, {+ const res = await fetch(API_ENDPOINTS.OPENAI, {method: "POST",headers: {"Content-Type": "application/json",@@ -208,15 +212,56 @@ class ReasoningService extends BaseReasoningService {createApiRetryStrategy("OpenAI"));- const responseText = response.choices[0].message.content.trim();+ // Log the raw response for debugging+ debugLogger.logReasoning("OPENAI_RAW_RESPONSE", {+ model,+ hasOutput: !!response.output,+ outputLength: response.output?.length || 0,+ outputTypes: response.output?.map((item: any) => item.type),+ usage: response.usage+ });++ // Extract text from the Responses API format+ // Response contains an array of output items, we need to find the message with output_text+ let responseText = "";++ if (response.output && Array.isArray(response.output)) {+ for (const item of response.output) {+ if (item.type === "message" && item.content) {+ for (const content of item.content) {+ if (content.type === "output_text" && content.text) {+ responseText = content.text.trim();+ break;+ }+ }+ if (responseText) break;+ }+ }+ }++ // Fallback to output_text helper if available+ if (!responseText && response.output_text) {+ responseText = response.output_text.trim();+ }debugLogger.logReasoning("OPENAI_RESPONSE", {model,responseLength: responseText.length,tokensUsed: response.usage?.total_tokens || 0,- success: true+ success: true,+ isEmpty: responseText.length === 0});+ // If we got an empty response, return the original text as fallback+ if (!responseText) {+ debugLogger.logReasoning("OPENAI_EMPTY_RESPONSE_FALLBACK", {+ model,+ originalTextLength: text.length,+ reason: "Empty response from API"+ });+ return text; // Return original text if API returns nothing+ }+return responseText;} catch (error) {debugLogger.logReasoning("OPENAI_ERROR", {@@ -239,80 +284,42 @@ class ReasoningService extends BaseReasoningService {debugLogger.logReasoning("ANTHROPIC_START", {model,agentName,- hasApiKey: false // Will update after fetching+ environment: typeof window !== 'undefined' ? 'browser' : 'node'});- if (this.isProcessing) {- throw new Error("Already processing a request");- }-- const apiKey = await this.getApiKey('anthropic');-- debugLogger.logReasoning("ANTHROPIC_API_KEY", {- hasApiKey: !!apiKey,- keyLength: apiKey?.length || 0- });-- this.isProcessing = true;-- try {- const systemPrompt = "You are a dictation assistant. Clean up text by fixing grammar and punctuation. Output ONLY the cleaned text without any explanations, options, or commentary.";- const userPrompt = this.getReasoningPrompt(text, agentName, config);-- const requestBody = {- model: model || "claude-sonnet-4-20250514",- messages: [{ role: "user", content: userPrompt }],- system: systemPrompt,- max_tokens: config.maxTokens || this.calculateMaxTokens(- text.length,- TOKEN_LIMITS.MIN_TOKENS_ANTHROPIC,- TOKEN_LIMITS.MAX_TOKENS_ANTHROPIC,- TOKEN_LIMITS.TOKEN_MULTIPLIER- ),- temperature: config.temperature || 0.3,- };-- const response = await withRetry(- async () => {- const res = await fetch(`${API_ENDPOINTS.ANTHROPIC}/messages`, {- method: "POST",- headers: {- "Content-Type": "application/json",- "X-API-Key": apiKey!,- "anthropic-version": API_VERSIONS.ANTHROPIC,- },- body: JSON.stringify(requestBody),- });-- if (!res.ok) {- const errorData = await res.json().catch(() => ({ error: res.statusText }));- throw new Error(errorData.error?.message || `Anthropic API error: ${res.status}`);- }-- return res.json();- },- createApiRetryStrategy("Anthropic")- );-- const responseText = response.content[0].text.trim();+ // Use IPC to communicate with main process for Anthropic API+ if (typeof window !== 'undefined' && window.electronAPI) {+ const startTime = Date.now();- debugLogger.logReasoning("ANTHROPIC_RESPONSE", {+ debugLogger.logReasoning("ANTHROPIC_IPC_CALL", {model,- responseLength: responseText.length,- tokensUsed: response.usage?.total_tokens || 0,- success: true+ textLength: text.length});- return responseText;- } catch (error) {- debugLogger.logReasoning("ANTHROPIC_ERROR", {- model,- error: (error as Error).message,- errorType: (error as Error).name+ const result = await window.electronAPI.processAnthropicReasoning(text, model, agentName, config);++ const processingTime = Date.now() - startTime;++ if (result.success) {+ debugLogger.logReasoning("ANTHROPIC_SUCCESS", {+ model,+ processingTimeMs: processingTime,+ resultLength: result.text.length+ });+ return result.text;+ } else {+ debugLogger.logReasoning("ANTHROPIC_ERROR", {+ model,+ processingTimeMs: processingTime,+ error: result.error+ });+ throw new Error(result.error);+ }+ } else {+ debugLogger.logReasoning("ANTHROPIC_UNAVAILABLE", {+ reason: 'Not in Electron environment'});- throw error;- } finally {- this.isProcessing = false;+ throw new Error('Anthropic reasoning is not available in this environment');}}@@ -374,7 +381,7 @@ class ReasoningService extends BaseReasoningService {debugLogger.logReasoning("GEMINI_START", {model,agentName,- hasApiKey: false // Will update after fetching+ hasApiKey: false});if (this.isProcessing) {@@ -402,69 +409,114 @@ class ReasoningService extends BaseReasoningService {}],generationConfig: {temperature: config.temperature || 0.3,- maxOutputTokens: config.maxTokens || this.calculateMaxTokens(- text.length,- TOKEN_LIMITS.MIN_TOKENS_GEMINI,- TOKEN_LIMITS.MAX_TOKENS_GEMINI,- TOKEN_LIMITS.TOKEN_MULTIPLIER+ maxOutputTokens: config.maxTokens || Math.max(+ 2000, // Gemini 2.5 Pro needs more tokens for its thinking process+ this.calculateMaxTokens(+ text.length,+ TOKEN_LIMITS.MIN_TOKENS_GEMINI,+ TOKEN_LIMITS.MAX_TOKENS_GEMINI,+ TOKEN_LIMITS.TOKEN_MULTIPLIER+ )),},};- const response = await withRetry(- async () => {- const res = await fetch(- `${API_ENDPOINTS.GEMINI}/models/${model}:generateContent?key=${apiKey}`,- {- method: "POST",- headers: {- "Content-Type": "application/json",- },- body: JSON.stringify(requestBody),- }- );-- if (!res.ok) {- const errorText = await res.text();- let errorData: any = { error: res.statusText };+ let response: any;+ try {+ response = await withRetry(+ async () => {+ debugLogger.logReasoning("GEMINI_REQUEST", {+ endpoint: `${API_ENDPOINTS.GEMINI}/models/${model}:generateContent`,+ model,+ hasApiKey: !!apiKey,+ requestBody: JSON.stringify(requestBody).substring(0, 200)+ });- try {- errorData = JSON.parse(errorText);- } catch {- errorData = { error: errorText || res.statusText };+ const res = await fetch(+ `${API_ENDPOINTS.GEMINI}/models/${model}:generateContent?key=${apiKey}`,+ {+ method: "POST",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify(requestBody),+ }+ );++ if (!res.ok) {+ const errorText = await res.text();+ let errorData: any = { error: res.statusText };++ try {+ errorData = JSON.parse(errorText);+ } catch {+ errorData = { error: errorText || res.statusText };+ }++ debugLogger.logReasoning("GEMINI_API_ERROR_DETAIL", {+ status: res.status,+ statusText: res.statusText,+ error: errorData,+ errorMessage: errorData.error?.message || errorData.message || errorData.error,+ fullResponse: errorText.substring(0, 500)+ });++ const errorMessage = errorData.error?.message || errorData.message || errorData.error || `Gemini API error: ${res.status}`;+ throw new Error(errorMessage);}++ const jsonResponse = await res.json();- debugLogger.logReasoning("GEMINI_API_ERROR_DETAIL", {- status: res.status,- statusText: res.statusText,- error: errorData,- errorMessage: errorData.error?.message || errorData.message || errorData.error,- errorCode: errorData.error?.code,- errorStatus: errorData.error?.status,- fullResponse: errorText.substring(0, 500),- headers: Object.fromEntries(res.headers.entries())+ debugLogger.logReasoning("GEMINI_RAW_RESPONSE", {+ hasResponse: !!jsonResponse,+ responseKeys: jsonResponse ? Object.keys(jsonResponse) : [],+ hasCandidates: !!jsonResponse?.candidates,+ candidatesLength: jsonResponse?.candidates?.length || 0,+ fullResponse: JSON.stringify(jsonResponse).substring(0, 500)});- // Check for common error patterns- const errorMessage = errorData.error?.message || errorData.message || errorData.error || `Gemini API error: ${res.status}`;-- if (res.status === 403 || errorMessage.includes('quota') || errorMessage.includes('billing')) {- throw new Error(`Gemini API quota/billing error: ${errorMessage}. Please check your Google Cloud billing account.`);- } else if (res.status === 401) {- throw new Error(`Gemini API authentication error: Invalid API key`);- } else if (res.status === 400) {- throw new Error(`Gemini API request error: ${errorMessage}`);- } else {- throw new Error(`Gemini API error (${res.status}): ${errorMessage}`);- }- }-- return res.json();- },- createApiRetryStrategy("Gemini")- );+ return jsonResponse;+ },+ createApiRetryStrategy("Gemini")+ );+ } catch (fetchError) {+ debugLogger.logReasoning("GEMINI_FETCH_ERROR", {+ error: (fetchError as Error).message,+ stack: (fetchError as Error).stack+ });+ throw fetchError;+ }- const responseText = response.candidates[0].content.parts[0].text.trim();+ // Check if response has the expected structure+ if (!response.candidates || !response.candidates[0]) {+ debugLogger.logReasoning("GEMINI_RESPONSE_ERROR", {+ model,+ response: JSON.stringify(response).substring(0, 500),+ hasCandidate: !!response.candidates,+ candidateCount: response.candidates?.length || 0+ });+ throw new Error("Invalid response structure from Gemini API");+ }++ // Check if the response has actual content+ const candidate = response.candidates[0];+ if (!candidate.content?.parts?.[0]?.text) {+ debugLogger.logReasoning("GEMINI_EMPTY_RESPONSE", {+ model,+ finishReason: candidate.finishReason,+ hasContent: !!candidate.content,+ hasParts: !!candidate.content?.parts,+ response: JSON.stringify(candidate).substring(0, 500)+ });++ // If finish reason is MAX_TOKENS, the model hit its limit+ if (candidate.finishReason === "MAX_TOKENS") {+ throw new Error("Gemini reached token limit before generating response. Try a shorter input or increase max tokens.");+ }+ throw new Error("Gemini returned empty response");+ }++ const responseText = candidate.content.parts[0].text.trim();debugLogger.logReasoning("GEMINI_RESPONSE", {model,@@ -478,10 +530,7 @@ class ReasoningService extends BaseReasoningService {debugLogger.logReasoning("GEMINI_ERROR", {model,error: (error as Error).message,- errorType: (error as Error).name,- stack: (error as Error).stack,- apiKey: apiKey ? `${apiKey.substring(0, 8)}...${apiKey.substring(apiKey.length - 4)}` : 'missing',- endpoint: `${API_ENDPOINTS.GEMINI}/models/${model}:generateContent`+ errorType: (error as Error).name});throw error;} finally {diff --git a/src/types/electron.ts b/src/types/electron.tsindex 5fdff344f..06fff41b5 100644--- a/src/types/electron.ts+++ b/src/types/electron.ts@@ -190,6 +190,9 @@ declare global {processLocalReasoning: (text: string, modelId: string, agentName: string | null, config: any) => Promise<{ success: boolean; text?: string; error?: string }>;checkLocalReasoningAvailable: () => Promise<boolean>;+ // Anthropic reasoning+ processAnthropicReasoning: (text: string, modelId: string, agentName: string | null, config: any) => Promise<{ success: boolean; text?: string; error?: string }>;+// llama.cpp managementllamaCppCheck: () => Promise<{ isInstalled: boolean; version?: string }>;llamaCppInstall: () => Promise<{ success: boolean; error?: string }>;diff --git a/src/utils/languages.ts b/src/utils/languages.tsindex 028f90618..86ba72500 100644--- a/src/utils/languages.ts+++ b/src/utils/languages.ts@@ -136,12 +136,12 @@ export const REASONING_PROVIDERS = {name: "Anthropic",models: [{- value: "claude-3.5-haiku-20241022",+ value: "claude-3-5-haiku-20241022",label: "Claude 3.5 Haiku",description: "Fast and efficient",},{- value: "claude-3.5-sonnet-20241022",+ value: "claude-3-5-sonnet-20241022",label: "Claude 3.5 Sonnet",description: "Balanced performance",},@@ -215,5 +215,14 @@ export const getReasoningModelLabel = (modelId: string): string => {export const getModelProvider = (modelId: string): string => {const allModels = getAllReasoningModels();const model = allModels.find((m) => m.value === modelId);++ // If model not found, try to infer from model name+ if (!model) {+ if (modelId.includes("claude")) return "anthropic";+ if (modelId.includes("gemini")) return "gemini";+ if (modelId.includes("gpt") || modelId.includes("o3") || modelId.includes("o4") || modelId.includes("o1")) return "openai";+ if (modelId.includes("qwen") || modelId.includes("llama") || modelId.includes("mistral")) return "local";+ }+return model?.provider || "openai";};\ No newline at end of file