refactor: apply named expressions, conditional expressions, and destructuring for improved conciseness and readability.
This commit is contained in:
@@ -22,7 +22,7 @@ import { errorLog } from '@/lib/debug';
|
||||
import { StreamingQueue } from '@/lib/async-utils';
|
||||
|
||||
const logError = errorLog('TauriTranscriptionStream');
|
||||
const DEFAULT_PROJECT_ID = IdentityDefaults.DEFAULT_PROJECT_ID;
|
||||
const {DEFAULT_PROJECT_ID} = IdentityDefaults;
|
||||
|
||||
function normalizeProjectId(projectId?: string): string | undefined {
|
||||
const trimmed = projectId?.trim();
|
||||
|
||||
@@ -22,7 +22,7 @@ addClientLog({
|
||||
level: 'debug',
|
||||
source: 'app',
|
||||
message: 'use-audio-devices.ts MODULE LOADED',
|
||||
metadata: { isTauri: isTauriEnvironment() },
|
||||
metadata: { isTauri: String(isTauriEnvironment()) },
|
||||
});
|
||||
|
||||
const log = debug('useAudioDevices');
|
||||
@@ -48,7 +48,7 @@ export function useAudioDevices(options: UseAudioDevicesOptions = {}): UseAudioD
|
||||
useEffect(() => {
|
||||
let mounted = true;
|
||||
|
||||
async function hydrateFromPreferences(): Promise<void> {
|
||||
const hydrateFromPreferences = async (): Promise<void> => {
|
||||
await waitForHydration();
|
||||
if (!mounted) {
|
||||
return;
|
||||
@@ -70,7 +70,7 @@ export function useAudioDevices(options: UseAudioDevicesOptions = {}): UseAudioD
|
||||
setMicGain(prefs.audio_devices.mic_gain ?? 1.0);
|
||||
setSystemGain(prefs.audio_devices.system_gain ?? 1.0);
|
||||
setIsHydratedState(true);
|
||||
}
|
||||
};
|
||||
|
||||
void hydrateFromPreferences();
|
||||
|
||||
@@ -138,7 +138,7 @@ export function useAudioDevices(options: UseAudioDevicesOptions = {}): UseAudioD
|
||||
level: 'debug',
|
||||
source: 'app',
|
||||
message: 'loadDevices: ENTRY',
|
||||
metadata: { isTauri: isTauriEnvironment() },
|
||||
metadata: { isTauri: String(isTauriEnvironment()) },
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -260,7 +260,7 @@ export function useAudioDevices(options: UseAudioDevicesOptions = {}): UseAudioD
|
||||
level: 'debug',
|
||||
source: 'app',
|
||||
message: 'Skipping output auto-select (user should choose manually)',
|
||||
metadata: { available_count: outputs.length },
|
||||
metadata: { available_count: String(outputs.length) },
|
||||
});
|
||||
}
|
||||
return;
|
||||
@@ -324,7 +324,7 @@ export function useAudioDevices(options: UseAudioDevicesOptions = {}): UseAudioD
|
||||
level: 'info',
|
||||
source: 'app',
|
||||
message: 'Audio device selected',
|
||||
metadata: { device_type: 'input', device_id: deviceId, device_name: deviceLabel },
|
||||
metadata: { device_type: 'input', device_id: deviceId, device_name: deviceLabel ?? '' },
|
||||
});
|
||||
if (isTauriEnvironment()) {
|
||||
try {
|
||||
@@ -356,7 +356,7 @@ export function useAudioDevices(options: UseAudioDevicesOptions = {}): UseAudioD
|
||||
level: 'info',
|
||||
source: 'app',
|
||||
message: 'Audio device selected',
|
||||
metadata: { device_type: 'output', device_id: deviceId, device_name: deviceLabel },
|
||||
metadata: { device_type: 'output', device_id: deviceId, device_name: deviceLabel ?? '' },
|
||||
});
|
||||
if (isTauriEnvironment()) {
|
||||
try {
|
||||
|
||||
@@ -169,7 +169,7 @@ export const clientLog = {
|
||||
},
|
||||
|
||||
// Audio Devices
|
||||
deviceSelectionFailed(deviceType: 'input' | 'output', deviceId: string, error?: string): void {
|
||||
deviceSelectionFailed(deviceType: 'input' | 'output' | 'system', deviceId: string, error?: string): void {
|
||||
emit('error', 'app', 'Device selection failed', {
|
||||
device_type: deviceType,
|
||||
device_id: deviceId,
|
||||
|
||||
@@ -92,7 +92,7 @@ class AsrConfigService:
|
||||
"""Check preconditions for ASR reconfiguration."""
|
||||
if has_active_recordings:
|
||||
return "Cannot reconfigure ASR while recordings are active"
|
||||
return "ASR engine is not available" if not self._engine_manager.engine_available else None
|
||||
return None if self._engine_manager.engine_available else "ASR engine is not available"
|
||||
|
||||
async def start_reconfiguration(
|
||||
self,
|
||||
|
||||
@@ -123,12 +123,11 @@ def _render_for_rich_handler(
|
||||
"""
|
||||
event = str(event_dict.get("event", ""))
|
||||
|
||||
# Include select user context keys if present
|
||||
context_parts = [
|
||||
f"{key}={event_dict[key]}" for key in _RICH_CONTEXT_KEYS if key in event_dict
|
||||
]
|
||||
|
||||
if context_parts:
|
||||
if context_parts := [
|
||||
f"{key}={event_dict[key]}"
|
||||
for key in _RICH_CONTEXT_KEYS
|
||||
if key in event_dict
|
||||
]:
|
||||
# Use pipe separator - brackets would be interpreted as Rich markup
|
||||
return f"{event} | {' '.join(context_parts)}"
|
||||
return event
|
||||
|
||||
@@ -93,9 +93,7 @@ def _extract_otel_context() -> tuple[int, int] | None:
|
||||
if not span.is_recording():
|
||||
return None
|
||||
ctx = span.get_span_context()
|
||||
if not ctx.is_valid:
|
||||
return None
|
||||
return ctx.trace_id, ctx.span_id
|
||||
return (ctx.trace_id, ctx.span_id) if ctx.is_valid else None
|
||||
except (AttributeError, TypeError):
|
||||
# Graceful degradation for edge cases
|
||||
return None
|
||||
|
||||
@@ -22,10 +22,14 @@ _PROJECT_ROOT_MARKERS: Final[tuple[str, ...]] = ("alembic.ini", "pyproject.toml"
|
||||
|
||||
def _find_marker_in_directory(directory: Path) -> str | None:
|
||||
"""Check if any project root marker exists in the directory."""
|
||||
for marker in _PROJECT_ROOT_MARKERS:
|
||||
if (directory / marker).exists():
|
||||
return marker
|
||||
return None
|
||||
return next(
|
||||
(
|
||||
marker
|
||||
for marker in _PROJECT_ROOT_MARKERS
|
||||
if (directory / marker).exists()
|
||||
),
|
||||
None,
|
||||
)
|
||||
|
||||
|
||||
def _get_project_root() -> Path:
|
||||
|
||||
@@ -123,8 +123,7 @@ class SqlAlchemyEntityRepository(
|
||||
NamedEntityModel.normalized_text,
|
||||
)
|
||||
result = await self._session.execute(stmt)
|
||||
rows = result.all()
|
||||
if rows:
|
||||
if rows := result.all():
|
||||
ids_by_key = {
|
||||
(str(row.meeting_id), row.normalized_text): row.id
|
||||
for row in rows
|
||||
|
||||
@@ -33,9 +33,7 @@ def _read_sysctl_features() -> str | None:
|
||||
)
|
||||
except (OSError, subprocess.SubprocessError):
|
||||
return None
|
||||
if result.returncode != 0:
|
||||
return None
|
||||
return result.stdout
|
||||
return None if result.returncode != 0 else result.stdout
|
||||
|
||||
|
||||
@cache
|
||||
@@ -53,11 +51,7 @@ def has_avx2_support() -> bool:
|
||||
return "avx2" in cpuinfo.lower()
|
||||
|
||||
features = _read_sysctl_features()
|
||||
if features is not None:
|
||||
return "avx2" in features.lower()
|
||||
|
||||
# Default to False (conservative - will disable NNPACK)
|
||||
return False
|
||||
return "avx2" in features.lower() if features is not None else False
|
||||
|
||||
|
||||
def configure_pytorch_for_platform() -> None:
|
||||
|
||||
Reference in New Issue
Block a user