Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ export default function ListenButton({ sessionId, isCompact = false }: { session
refetchInterval: 1500,
enabled: ongoingSessionStatus !== "running_active",
queryFn: async () => {
const currentModel = await localSttCommands.getCurrentModel();
const currentModel = await localSttCommands.getLocalModel();
const isDownloaded = await localSttCommands.isModelDownloaded(currentModel);
const servers = await localSttCommands.getServers();
const isServerAvailable = (servers.external === "ready") || (servers.internal === "ready");
const isServerAvailable = (servers.external === "ready") || (servers.internal === "ready")
|| (servers.custom === "ready");
return isDownloaded && isServerAvailable;
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const REFETCH_INTERVALS = {
interface STTViewProps extends SharedSTTProps {
isWerModalOpen: boolean;
setIsWerModalOpen: (open: boolean) => void;
provider: "Local" | "Custom";
setProviderToLocal: () => void;
}

interface ModelSectionProps {
Expand All @@ -37,6 +39,8 @@ interface ModelSectionProps {
setSelectedSTTModel: (model: string) => void;
downloadingModels: Set<string>;
handleModelDownload: (model: string) => void;
provider: "Local" | "Custom";
setProviderToLocal: () => void;
}

export function STTViewLocal({
Expand All @@ -46,22 +50,20 @@ export function STTViewLocal({
setSttModels,
downloadingModels,
handleModelDownload,
provider,
setProviderToLocal,
}: STTViewProps) {
const amAvailable = useMemo(() => platform() === "macos" && arch() === "aarch64", []);

const servers = useQuery({
queryKey: ["local-stt-servers"],
queryFn: async () => {
const servers = await localSttCommands.getServers();
console.log(servers);
return servers;
},
queryFn: async () => localSttCommands.getServers(),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add basic error handling to react-query calls.

Wrap queryFn bodies with try/catch or supply onError to surface failures (toast/log) per guidelines. Silent failures hurt UX and debugging.

Apply:

-  const servers = useQuery({
+  const servers = useQuery({
     queryKey: ["local-stt-servers"],
-    queryFn: async () => localSttCommands.getServers(),
+    queryFn: async () => {
+      try { return await localSttCommands.getServers(); }
+      catch (e) { console.error("getServers failed", e); throw e; }
+    },
     refetchInterval: REFETCH_INTERVALS.servers,
   });

-  const currentSTTModel = useQuery({
+  const currentSTTModel = useQuery({
     queryKey: ["current-stt-model"],
-    queryFn: () => localSttCommands.getLocalModel(),
+    queryFn: async () => {
+      try { return await localSttCommands.getLocalModel(); }
+      catch (e) { console.error("getLocalModel failed", e); throw e; }
+    },
   });

Also applies to: 66-66

🤖 Prompt for AI Agents
In apps/desktop/src/components/settings/components/ai/stt-view-local.tsx around
lines 60 and 66, the react-query queryFn calls are silent on failure; wrap each
queryFn body in try/catch and rethrow or add an onError handler to surface
failures (e.g., call the existing toast/logger with a clear message and the
error). Specifically, modify the queryFn to try { return await
localSttCommands.getServers() } catch (err) { toast.error("Failed to load STT
servers"); logger.error("getServers error", err); throw err } (or supply an
onError option that performs the same toast/logger actions) so errors are logged
and shown to the user. Ensure both query usages at lines 60 and 66 are updated
consistently.

refetchInterval: REFETCH_INTERVALS.servers,
});

const currentSTTModel = useQuery({
queryKey: ["current-stt-model"],
queryFn: () => localSttCommands.getCurrentModel(),
queryFn: () => localSttCommands.getLocalModel(),
});

const sttModelDownloadStatus = useQuery({
Expand Down Expand Up @@ -133,6 +135,8 @@ export function STTViewLocal({
setSelectedSTTModel={setSelectedSTTModel}
downloadingModels={downloadingModels}
handleModelDownload={handleModelDownload}
provider={provider}
setProviderToLocal={setProviderToLocal}
/>

{/* Divider - only show if pro models available */}
Expand All @@ -147,6 +151,8 @@ export function STTViewLocal({
setSelectedSTTModel={setSelectedSTTModel}
downloadingModels={downloadingModels}
handleModelDownload={handleModelDownload}
provider={provider}
setProviderToLocal={setProviderToLocal}
/>
</>
)}
Expand All @@ -164,6 +170,8 @@ function BasicModelsSection({
setSelectedSTTModel,
downloadingModels,
handleModelDownload,
provider,
setProviderToLocal,
}: ModelSectionProps) {
const handleShowFileLocation = async () => {
const path = await localSttCommands.modelsDir();
Expand Down Expand Up @@ -191,6 +199,8 @@ function BasicModelsSection({
downloadingModels={downloadingModels}
handleModelDownload={handleModelDownload}
handleShowFileLocation={handleShowFileLocation}
provider={provider}
setProviderToLocal={setProviderToLocal}
/>
))}
</div>
Expand All @@ -207,6 +217,8 @@ function ProModelsSection({
setSelectedSTTModel,
downloadingModels,
handleModelDownload,
provider,
setProviderToLocal,
}: Omit<ModelSectionProps, "modelsToShow">) {
const { getLicense } = useLicense();

Expand Down Expand Up @@ -258,6 +270,8 @@ function ProModelsSection({
downloadingModels={downloadingModels}
handleModelDownload={handleModelDownload}
handleShowFileLocation={handleShowFileLocation}
provider={provider}
setProviderToLocal={setProviderToLocal}
/>
))}
</div>
Expand Down Expand Up @@ -328,6 +342,8 @@ function ModelEntry({
downloadingModels,
handleModelDownload,
handleShowFileLocation,
provider,
setProviderToLocal,
disabled = false,
}: {
model: STTModel;
Expand All @@ -336,16 +352,20 @@ function ModelEntry({
downloadingModels: Set<string>;
handleModelDownload: (model: string) => void;
handleShowFileLocation: () => void;
provider: "Local" | "Custom";
setProviderToLocal: () => void;
disabled?: boolean;
}) {
const isSelected = selectedSTTModel === model.key && model.downloaded;
// only highlight if provider is Local and this is the selected model
const isSelected = provider === "Local" && selectedSTTModel === model.key && model.downloaded;
const isSelectable = model.downloaded && !disabled;
const isDownloading = downloadingModels.has(model.key);

const handleClick = () => {
if (isSelectable) {
setSelectedSTTModel(model.key as SupportedSttModel);
localSttCommands.setCurrentModel(model.key as SupportedSttModel);
localSttCommands.setLocalModel(model.key as SupportedSttModel);
setProviderToLocal();
localSttCommands.stopServer(null);
localSttCommands.startServer(null);
}
Expand Down
Loading
Loading