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(reasoning): apply the Mistral dialect to the agent streaming path
Alcahestce55fd723dfb
diff --git a/src/services/ReasoningService.ts b/src/services/ReasoningService.tsindex 20e0c1d3d..cc3a0d526 100644--- a/src/services/ReasoningService.ts+++ b/src/services/ReasoningService.ts@@ -20,6 +20,8 @@ import { createEnterpriseChatModel } from "./ai/enterpriseChatModel";import { PROVIDER_REGISTRY, type ProviderContext } from "./ai/inferenceProviders";import { getConfiguredOpenAIBase } from "./ai/openaiBase";import { applyThinkingSuppression } from "./ai/thinkingSuppression";+import { detectEndpointDialect } from "./ai/thinkingSuppressionDialects";+import { extractApiErrorMessage } from "./ai/apiErrorMessage";import { clearTinfoilClientCache } from "./ai/tinfoilClient";import { resolveChatRoute } from "../helpers/chatRouting";@@ -209,7 +211,7 @@ class ReasoningService extends BaseReasoningService {requestBody.reasoning_effort = "low";}- applyThinkingSuppression(requestBody, model, providerName, config);+ applyThinkingSuppression(requestBody, model, providerName, config, endpoint);logger.logReasoning(`${providerName.toUpperCase()}_REQUEST`, {endpoint,@@ -251,19 +253,18 @@ class ReasoningService extends BaseReasoningService {errorData = { error: errorText || res.statusText };}+ const errorMessage = extractApiErrorMessage(+ errorData,+ `${providerName} API error: ${res.status}`+ );+logger.logReasoning(`${providerName.toUpperCase()}_API_ERROR_DETAIL`, {status: res.status,statusText: res.statusText,error: errorData,- errorMessage: errorData.error?.message || errorData.message || errorData.error,+ errorMessage,fullResponse: errorText.substring(0, 500),});-- const errorMessage =- errorData.error?.message ||- errorData.message ||- errorData.error ||- `${providerName} API error: ${res.status}`;// Carry the status so the retry layer can tell a rejection from a network fault.const apiError = new Error(errorMessage) as Error & { status?: number };apiError.status = res.status;@@ -444,7 +445,15 @@ class ReasoningService extends BaseReasoningService {}}- const apiConfig = getOpenAiApiConfig(model, provider);+ // A known endpoint host knows its own request shape better than the model id does.+ const endpointDialect = detectEndpointDialect(endpoint);+ const registryConfig = getOpenAiApiConfig(model, provider);+ const apiConfig = endpointDialect+ ? {+ tokenParam: endpointDialect.tokenParam,+ supportsTemperature: endpointDialect.supportsTemperature,+ }+ : registryConfig;const useOldTokenParam = isLocalProvider || isLanChat || provider === "groq";const requestBody: Record<string, unknown> = {@@ -465,7 +474,7 @@ class ReasoningService extends BaseReasoningService {}}- applyThinkingSuppression(requestBody, model, isLanChat ? "lan" : provider, config);+ applyThinkingSuppression(requestBody, model, isLanChat ? "lan" : provider, config, endpoint);logger.logReasoning("AGENT_STREAM_REQUEST", {endpoint,@@ -513,11 +522,7 @@ class ReasoningService extends BaseReasoningService {let errorMessage: string;try {const errorData = JSON.parse(errorText);- errorMessage =- errorData.error?.message ||- errorData.message ||- errorData.error ||- `API error: ${response.status}`;+ errorMessage = extractApiErrorMessage(errorData, `API error: ${response.status}`);} catch {errorMessage = errorText || `API error: ${response.status}`;}diff --git a/src/services/ai/apiErrorMessage.ts b/src/services/ai/apiErrorMessage.tsindex 2eb6f9bdc..b09ae4a06 100644--- a/src/services/ai/apiErrorMessage.ts+++ b/src/services/ai/apiErrorMessage.ts@@ -62,5 +62,10 @@ export function extractApiErrorMessage(errorData: unknown, fallback: string): stif (stringified) return stringified;}+ if (isRecord(errorData.error) || Array.isArray(errorData.error)) {+ const stringified = stringify(errorData.error);+ if (stringified) return stringified;+ }+return safeFallback;}diff --git a/src/services/ai/inferenceProviders/openai.ts b/src/services/ai/inferenceProviders/openai.tsindex aacf52470..58a8e7fa8 100644--- a/src/services/ai/inferenceProviders/openai.ts+++ b/src/services/ai/inferenceProviders/openai.ts@@ -154,16 +154,16 @@ export const openaiProvider: InferenceProvider = {const openAiBase = isOpenRouter? API_ENDPOINTS.OPENROUTER_BASE: config.baseUrl?.trim() || getConfiguredOpenAIBase();- // OpenRouter speaks Chat Completions only — no /responses probe needed.+ const dialect = detectEndpointDialect(openAiBase);+ // OpenRouter and known dialect hosts speak Chat Completions only — no /responses probe needed.let endpointCandidates: Array<{ url: string; type: "responses" | "chat" }>;- if (isOpenRouter) {+ if (isOpenRouter || dialect) {endpointCandidates = [{ url: buildApiUrl(openAiBase, "/chat/completions"), type: "chat" }];} else {await detectServerType(openAiBase);endpointCandidates = getEndpointCandidates(openAiBase);}const isCustomEndpoint = openAiBase !== API_ENDPOINTS.OPENAI_BASE;- const dialect = detectEndpointDialect(openAiBase);logger.logReasoning("OPENAI_ENDPOINTS", {base: openAiBase,diff --git a/test/helpers/apiErrorMessage.test.js b/test/helpers/apiErrorMessage.test.jsindex d34525a20..23d1213b1 100644--- a/test/helpers/apiErrorMessage.test.js+++ b/test/helpers/apiErrorMessage.test.js@@ -99,6 +99,18 @@ test("a detail list with nothing usable still surfaces the raw body over [objectassert.equal(extractApiErrorMessage({ message: { detail: [] } }, "fallback"), '{"detail":[]}');});+test("an error object without a nested message is stringified rather than dropped", async () => {+ const { extractApiErrorMessage } = await load();++ const message = extractApiErrorMessage(+ { error: { code: "invalid_request_error", type: "bad_request" } },+ "fallback"+ );++ assert.equal(message, '{"code":"invalid_request_error","type":"bad_request"}');+ assert.ok(!message.includes("[object Object]"));+});+test("a bare error string is used when there is no message", async () => {const { extractApiErrorMessage } = await load();diff --git a/test/helpers/thinkingSuppressionDialects.test.js b/test/helpers/thinkingSuppressionDialects.test.jsindex 2be120613..c1ee4c6f9 100644--- a/test/helpers/thinkingSuppressionDialects.test.js+++ b/test/helpers/thinkingSuppressionDialects.test.js@@ -153,6 +153,7 @@ test("detectEndpointDialect matches mistral hosts regardless of scheme, case, poassert.equal(detectEndpointDialect("https://API.Mistral.AI/v1/")?.key, "mistral");assert.equal(detectEndpointDialect("https://api.mistral.ai:443/v1")?.key, "mistral");assert.equal(detectEndpointDialect("https://[email protected]/v1")?.key, "mistral");+ assert.equal(detectEndpointDialect("https://api.mistral.ai/v1/chat/completions")?.key, "mistral");});test("detectEndpointDialect rejects lookalike hosts", async () => {