Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix: bundle llama-server shared libraries and add STT/reasoning debug logging

Gabriel Steinfa3488984319
diff --git a/electron-builder.json b/electron-builder.json
index 8081e911e..108175036 100644
--- a/electron-builder.json
+++ b/electron-builder.json
@@ -88,7 +88,7 @@
{
"from": "resources/bin/",
"to": "bin/",
- "filter": ["whisper-cpp-*", "whisper-server-*", "llama-server-*"]
+ "filter": ["whisper-cpp-*", "whisper-server-*", "llama-server-*", "*.dylib", "*.dll", "*.so*"]
}
],
"mac": {
diff --git a/scripts/download-llama-server.js b/scripts/download-llama-server.js
index e96fa5702..d80605584 100644
--- a/scripts/download-llama-server.js
+++ b/scripts/download-llama-server.js
@@ -18,21 +18,29 @@ const BINARIES = {
zipName: `llama-${LLAMA_CPP_VERSION}-bin-macos-arm64.zip`,
binaryPath: "build/bin/llama-server",
outputName: "llama-server-darwin-arm64",
+ libPattern: "*.dylib",
+ libDir: "build/bin",
},
"darwin-x64": {
zipName: `llama-${LLAMA_CPP_VERSION}-bin-macos-x64.zip`,
binaryPath: "build/bin/llama-server",
outputName: "llama-server-darwin-x64",
+ libPattern: "*.dylib",
+ libDir: "build/bin",
},
"win32-x64": {
zipName: `llama-${LLAMA_CPP_VERSION}-bin-win-avx2-x64.zip`,
binaryPath: "build/bin/llama-server.exe",
outputName: "llama-server-win32-x64.exe",
+ libPattern: "*.dll",
+ libDir: "build/bin",
},
"linux-x64": {
zipName: `llama-${LLAMA_CPP_VERSION}-bin-ubuntu-x64.zip`,
binaryPath: "build/bin/llama-server",
outputName: "llama-server-linux-x64",
+ libPattern: "*.so*",
+ libDir: "build/bin",
},
};
@@ -42,6 +50,38 @@ function getDownloadUrl(zipName) {
return `https://github.com/${LLAMA_CPP_REPO}/releases/download/${LLAMA_CPP_VERSION}/${zipName}`;
}
+function findLibrariesInDir(dir, pattern, maxDepth = 5, currentDepth = 0) {
+ if (currentDepth >= maxDepth) return [];
+
+ const results = [];
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
+
+ for (const entry of entries) {
+ const fullPath = path.join(dir, entry.name);
+
+ if (entry.isDirectory()) {
+ results.push(...findLibrariesInDir(fullPath, pattern, maxDepth, currentDepth + 1));
+ } else if (matchesPattern(entry.name, pattern)) {
+ results.push(fullPath);
+ }
+ }
+
+ return results;
+}
+
+function matchesPattern(filename, pattern) {
+ // Handle patterns like "*.dylib", "*.dll", "*.so*"
+ if (pattern === "*.dylib") {
+ return filename.endsWith(".dylib");
+ } else if (pattern === "*.dll") {
+ return filename.endsWith(".dll");
+ } else if (pattern === "*.so*") {
+ // Match .so files with optional version suffix (e.g., libfoo.so, libfoo.so.1, libfoo.so.1.2.3)
+ return /\.so(\.\d+)*$/.test(filename) || filename.endsWith(".so");
+ }
+ return false;
+}
+
async function downloadBinary(platformArch, config) {
if (!config) {
console.log(` ${platformArch}: Not supported`);
@@ -78,6 +118,24 @@ async function downloadBinary(platformArch, config) {
fs.copyFileSync(binaryPath, outputPath);
setExecutable(outputPath);
console.log(` ${platformArch}: Extracted to ${config.outputName}`);
+
+ // Copy shared libraries (dylib/dll/so files)
+ if (config.libPattern) {
+ const libDir = path.join(extractDir, config.libDir);
+ const libraries = findLibrariesInDir(libDir, config.libPattern);
+
+ for (const libPath of libraries) {
+ const libName = path.basename(libPath);
+ const destPath = path.join(BIN_DIR, libName);
+
+ // Only copy if not already exists (libraries are shared across architectures on same OS)
+ if (!fs.existsSync(destPath)) {
+ fs.copyFileSync(libPath, destPath);
+ setExecutable(destPath);
+ console.log(` ${platformArch}: Copied library ${libName}`);
+ }
+ }
+ }
} else {
console.error(` ${platformArch}: Binary '${binaryName}' not found in archive`);
return false;
diff --git a/src/components/ui/PromptStudio.tsx b/src/components/ui/PromptStudio.tsx
index b3b6f7939..fddeb53f4 100644
--- a/src/components/ui/PromptStudio.tsx
+++ b/src/components/ui/PromptStudio.tsx
@@ -19,6 +19,7 @@ import { useDialogs } from "../../hooks/useDialogs";
import { useAgentName } from "../../utils/agentName";
import ReasoningService from "../../services/ReasoningService";
import { getModelProvider } from "../../models/ModelRegistry";
+import logger from "../../utils/logger";
import { UNIFIED_SYSTEM_PROMPT, LEGACY_PROMPTS } from "../../config/prompts";
interface PromptStudioProps {
@@ -127,8 +128,23 @@ export default function PromptStudio({ className = "" }: PromptStudioProps) {
const useReasoningModel = localStorage.getItem("useReasoningModel") === "true";
const reasoningModel = localStorage.getItem("reasoningModel") || "";
const reasoningProvider = reasoningModel ? getModelProvider(reasoningModel) : "openai";
+ const customBaseUrl = localStorage.getItem("cloudReasoningBaseUrl") || "";
+
+ logger.debug(
+ "PromptStudio test starting",
+ {
+ useReasoningModel,
+ reasoningModel,
+ reasoningProvider,
+ customBaseUrl: customBaseUrl ? `${customBaseUrl.substring(0, 50)}...` : "(none)",
+ testTextLength: testText.length,
+ agentName,
+ },
+ "prompt-studio"
+ );
if (!useReasoningModel) {
+ logger.debug("PromptStudio test aborted: AI enhancement disabled", {}, "prompt-studio");
setTestResult(
"AI text enhancement is disabled. Enable it in AI Text Cleanup settings to test prompts."
);
@@ -136,6 +152,7 @@ export default function PromptStudio({ className = "" }: PromptStudioProps) {
}
if (!reasoningModel) {
+ logger.debug("PromptStudio test aborted: no model selected", {}, "prompt-studio");
setTestResult("No reasoning model selected. Choose one in AI Text Cleanup settings.");
return;
}
@@ -148,6 +165,11 @@ export default function PromptStudio({ className = "" }: PromptStudioProps) {
if (providerConfig.baseStorageKey) {
const baseUrl = (localStorage.getItem(providerConfig.baseStorageKey) || "").trim();
if (!baseUrl) {
+ logger.debug(
+ "PromptStudio test aborted: missing base URL for custom endpoint",
+ { provider: reasoningProvider },
+ "prompt-studio"
+ );
setTestResult(`${providerLabel} base URL missing. Add it in AI Text Cleanup settings.`);
return;
}
@@ -157,8 +179,16 @@ export default function PromptStudio({ className = "" }: PromptStudioProps) {
const currentCustomPrompt = localStorage.getItem("customUnifiedPrompt");
localStorage.setItem("customUnifiedPrompt", JSON.stringify(editedPrompt));
+ const startTime = Date.now();
+
try {
if (reasoningProvider === "local") {
+ logger.debug(
+ "PromptStudio: sending to local model",
+ { model: reasoningModel, textLength: testText.length },
+ "prompt-studio"
+ );
+
const result = await window.electronAPI.processLocalReasoning(
testText,
reasoningModel,
@@ -166,18 +196,61 @@ export default function PromptStudio({ className = "" }: PromptStudioProps) {
{}
);
+ const processingTime = Date.now() - startTime;
+
if (result.success) {
- setTestResult(result.text);
+ const resultText = result.text || "";
+ logger.debug(
+ "PromptStudio: local model success",
+ {
+ processingTimeMs: processingTime,
+ resultLength: resultText.length,
+ resultPreview: resultText.substring(0, 100),
+ },
+ "prompt-studio"
+ );
+ setTestResult(resultText);
} else {
+ logger.debug(
+ "PromptStudio: local model error",
+ { processingTimeMs: processingTime, error: result.error },
+ "prompt-studio"
+ );
setTestResult(`Local model error: ${result.error}`);
}
} else {
+ logger.debug(
+ "PromptStudio: sending to cloud provider",
+ {
+ provider: reasoningProvider,
+ model: reasoningModel,
+ textLength: testText.length,
+ isCustomEndpoint: reasoningProvider === "custom",
+ customBaseUrl: customBaseUrl || "(default)",
+ },
+ "prompt-studio"
+ );
+
const result = await ReasoningService.processText(
testText,
reasoningModel,
agentName,
{}
);
+
+ const processingTime = Date.now() - startTime;
+
+ logger.debug(
+ "PromptStudio: cloud provider success",
+ {
+ provider: reasoningProvider,
+ processingTimeMs: processingTime,
+ resultLength: result.length,
+ resultPreview: result.substring(0, 100),
+ },
+ "prompt-studio"
+ );
+
setTestResult(result);
}
} finally {
@@ -189,8 +262,16 @@ export default function PromptStudio({ className = "" }: PromptStudioProps) {
}
}
} catch (error) {
- console.error("Test failed:", error);
- setTestResult(`Test failed: ${error.message}`);
+ const errorMessage = error instanceof Error ? error.message : String(error);
+ logger.error(
+ "PromptStudio test failed",
+ {
+ error: errorMessage,
+ stack: error instanceof Error ? error.stack : undefined,
+ },
+ "prompt-studio"
+ );
+ setTestResult(`Test failed: ${errorMessage}`);
} finally {
setIsLoading(false);
}
diff --git a/src/helpers/audioManager.js b/src/helpers/audioManager.js
index 98a4bbff6..a2e64f521 100644
--- a/src/helpers/audioManager.js
+++ b/src/helpers/audioManager.js
@@ -859,6 +859,9 @@ class AudioManager {
}
const endpoint = this.getTranscriptionEndpoint();
+ const isCustomEndpoint =
+ provider === "custom" ||
+ (!endpoint.includes("api.openai.com") && !endpoint.includes("api.groq.com"));
logger.debug(
"Making transcription API request",
@@ -866,6 +869,10 @@ class AudioManager {
endpoint,
shouldStream,
model,
+ provider,
+ isCustomEndpoint,
+ hasApiKey: !!apiKey,
+ apiKeyPreview: apiKey ? `${apiKey.substring(0, 8)}...` : "(none)",
},
"transcription"
);
@@ -876,6 +883,17 @@ class AudioManager {
headers.Authorization = `Bearer ${apiKey}`;
}
+ logger.debug(
+ "STT request details",
+ {
+ endpoint,
+ method: "POST",
+ hasAuthHeader: !!apiKey,
+ formDataFields: ["file", "model", language && language !== "auto" ? "language" : null, shouldStream ? "stream" : null].filter(Boolean),
+ },
+ "transcription"
+ );
+
const apiCallStart = performance.now();
const response = await fetch(endpoint, {
method: "POST",
@@ -1093,12 +1111,25 @@ class AudioManager {
? localStorage.getItem("cloudTranscriptionBaseUrl") || ""
: "";
+ const isCustomEndpoint = currentProvider === "custom" ||
+ (currentBaseUrl && currentBaseUrl !== API_ENDPOINTS.TRANSCRIPTION_BASE);
+
// Invalidate cache if provider or base URL changed
if (
this.cachedTranscriptionEndpoint &&
(this.cachedEndpointProvider !== currentProvider ||
this.cachedEndpointBaseUrl !== currentBaseUrl)
) {
+ logger.debug(
+ "STT endpoint cache invalidated",
+ {
+ previousProvider: this.cachedEndpointProvider,
+ newProvider: currentProvider,
+ previousBaseUrl: this.cachedEndpointBaseUrl,
+ newBaseUrl: currentBaseUrl,
+ },
+ "transcription"
+ );
this.cachedTranscriptionEndpoint = null;
}
@@ -1110,32 +1141,79 @@ class AudioManager {
const base = currentBaseUrl.trim() || API_ENDPOINTS.TRANSCRIPTION_BASE;
const normalizedBase = normalizeBaseUrl(base);
+ logger.debug(
+ "STT endpoint resolution",
+ {
+ provider: currentProvider,
+ isCustomEndpoint,
+ rawBaseUrl: currentBaseUrl,
+ normalizedBase,
+ defaultBase: API_ENDPOINTS.TRANSCRIPTION_BASE,
+ },
+ "transcription"
+ );
+
const cacheResult = (endpoint) => {
this.cachedTranscriptionEndpoint = endpoint;
this.cachedEndpointProvider = currentProvider;
this.cachedEndpointBaseUrl = currentBaseUrl;
+
+ logger.debug(
+ "STT endpoint resolved",
+ {
+ endpoint,
+ provider: currentProvider,
+ isCustomEndpoint,
+ usingDefault: endpoint === API_ENDPOINTS.TRANSCRIPTION,
+ },
+ "transcription"
+ );
+
return endpoint;
};
if (!normalizedBase) {
+ logger.debug(
+ "STT endpoint: using default (normalization failed)",
+ { rawBase: base },
+ "transcription"
+ );
return cacheResult(API_ENDPOINTS.TRANSCRIPTION);
}
if (!isSecureEndpoint(normalizedBase)) {
- console.warn("HTTPS required (HTTP allowed for local network only). Using default.");
+ logger.warn(
+ "STT endpoint: HTTPS required, falling back to default",
+ { attemptedUrl: normalizedBase },
+ "transcription"
+ );
return cacheResult(API_ENDPOINTS.TRANSCRIPTION);
}
let endpoint;
if (/\/audio\/(transcriptions|translations)$/i.test(normalizedBase)) {
endpoint = normalizedBase;
+ logger.debug(
+ "STT endpoint: using full path from config",
+ { endpoint },
+ "transcription"
+ );
} else {
endpoint = buildApiUrl(normalizedBase, "/audio/transcriptions");
+ logger.debug(
+ "STT endpoint: appending /audio/transcriptions to base",
+ { base: normalizedBase, endpoint },
+ "transcription"
+ );
}
return cacheResult(endpoint);
} catch (error) {
- console.warn("Failed to resolve transcription endpoint:", error);
+ logger.error(
+ "STT endpoint resolution failed",
+ { error: error.message, stack: error.stack },
+ "transcription"
+ );
this.cachedTranscriptionEndpoint = API_ENDPOINTS.TRANSCRIPTION;
this.cachedEndpointProvider = currentProvider;
this.cachedEndpointBaseUrl = currentBaseUrl;
diff --git a/src/helpers/llamaServer.js b/src/helpers/llamaServer.js
index a262c713f..d5ddaf169 100644
--- a/src/helpers/llamaServer.js
+++ b/src/helpers/llamaServer.js
@@ -138,10 +138,23 @@ class LlamaServerManager {
debugLogger.debug("Starting llama-server", { port: this.port, modelPath, args });
+ // Set library path for dynamic library loading
+ const binDir = path.dirname(serverBinary);
+ const env = { ...process.env };
+
+ if (process.platform === "darwin") {
+ // macOS: Set DYLD_LIBRARY_PATH to find .dylib files
+ env.DYLD_LIBRARY_PATH = binDir + (env.DYLD_LIBRARY_PATH ? `:${env.DYLD_LIBRARY_PATH}` : "");
+ } else if (process.platform === "linux") {
+ // Linux: Set LD_LIBRARY_PATH to find .so files
+ env.LD_LIBRARY_PATH = binDir + (env.LD_LIBRARY_PATH ? `:${env.LD_LIBRARY_PATH}` : "");
+ }
+
this.process = spawn(serverBinary, args, {
stdio: ["ignore", "pipe", "pipe"],
windowsHide: true,
cwd: os.tmpdir(),
+ env,
});
let stderrBuffer = "";
diff --git a/src/services/ReasoningService.ts b/src/services/ReasoningService.ts
index 954ff6fbd..7e9758122 100644
--- a/src/services/ReasoningService.ts
+++ b/src/services/ReasoningService.ts
@@ -36,11 +36,23 @@ class ReasoningService extends BaseReasoningService {
// If no custom URL is stored, use the default
if (!trimmed) {
+ logger.logReasoning("CUSTOM_REASONING_ENDPOINT_CHECK", {
+ hasCustomUrl: false,
+ usingDefault: true,
+ defaultEndpoint: API_ENDPOINTS.OPENAI_BASE,
+ });
return API_ENDPOINTS.OPENAI_BASE;
}
const normalized = normalizeBaseUrl(trimmed) || API_ENDPOINTS.OPENAI_BASE;
+ logger.logReasoning("CUSTOM_REASONING_ENDPOINT_CHECK", {
+ hasCustomUrl: true,
+ rawUrl: trimmed,
+ normalizedUrl: normalized,
+ defaultEndpoint: API_ENDPOINTS.OPENAI_BASE,
+ });
+
// Don't use the custom URL if it's a known non-OpenAI provider URL
// These should be handled by their dedicated provider methods
const knownNonOpenAIUrls = [
@@ -66,8 +78,17 @@ class ReasoningService extends BaseReasoningService {
return API_ENDPOINTS.OPENAI_BASE;
}
+ logger.logReasoning("CUSTOM_REASONING_ENDPOINT_RESOLVED", {
+ customEndpoint: normalized,
+ isCustom: normalized !== API_ENDPOINTS.OPENAI_BASE,
+ });
+
return normalized;
- } catch {
+ } catch (error) {
+ logger.logReasoning("CUSTOM_REASONING_ENDPOINT_ERROR", {
+ error: (error as Error).message,
+ fallbackTo: API_ENDPOINTS.OPENAI_BASE,
+ });
return API_ENDPOINTS.OPENAI_BASE;
}
}
@@ -235,8 +256,9 @@ class ReasoningService extends BaseReasoningService {
};
// Check model registry for provider-specific options
+ // Note: chat_template_kwargs is not supported by Groq's API
const modelDef = getCloudModel(model);
- if (modelDef?.disableThinking) {
+ if (modelDef?.disableThinking && providerName.toLowerCase() !== "groq") {
requestBody.chat_template_kwargs = { enable_thinking: false };
logger.logReasoning("THINKING_DISABLED", { model, provider: providerName });
}
@@ -444,13 +466,25 @@ class ReasoningService extends BaseReasoningService {
const openAiBase = this.getConfiguredOpenAIBase();
const endpointCandidates = this.getOpenAIEndpointCandidates(openAiBase);
+ const isCustomEndpoint = openAiBase !== API_ENDPOINTS.OPENAI_BASE;
logger.logReasoning("OPENAI_ENDPOINTS", {
base: openAiBase,
+ isCustomEndpoint,
candidates: endpointCandidates.map((candidate) => candidate.url),
preference: this.getStoredOpenAiPreference(openAiBase) || null,
});
+ if (isCustomEndpoint) {
+ logger.logReasoning("CUSTOM_TEXT_CLEANUP_REQUEST", {
+ customBase: openAiBase,
+ model,
+ textLength: text.length,
+ hasApiKey: !!apiKey,
+ apiKeyPreview: apiKey ? `${apiKey.substring(0, 8)}...` : "(none)",
+ });
+ }
+
const response = await withRetry(async () => {
let lastError: Error | null = null;