d3ro-voice/packages/core/src/voice-error-message.ts
Yun Chan ba9ef9741e fix: red-team round 3 hardening across desktop, mobile, core and server
Batch of red-team r3 fixes that were in the working tree before the
2026-09-28 design overhaul, committed as one unit with their tests.

- desktop main: STT timeouts and sidecar, voice recording store, sync
  (credentials, audio, knowledge reindex, push gates), runtime
  provisioner, update policy, AltGr keybindings, voice-command policy,
  dictionary file codec/limits, meeting transcript condensing and a
  local recording ledger so interrupted-session recovery only closes
  meetings this device recorded (a phone's live meeting is left alone).
- mobile: login CSRF via implicit token callbacks rejected, account
  deletion/retention, durable queue retention, knowledge realtime
  without unfiltered DELETE, meeting re-record failure paths, cloud STT
  client, preferences store/resync.
- core: text chunking splits long unbroken transcripts to fit, template
  field policy, dictionary limits, meeting markdown inline handling.
- server: payple webhook policy and cancellation order scope, meeting
  document generation quota, team RPC null-role guard, unified LLM
  quota in-flight accounting, knowledge chunk vector index, meeting
  re-record failure paths (migrations 20260929*).
- ci: portable/runtime feed gates, update-policy schema, Forgejo file
  delete and alias planning.

Four older tests are updated to the new contracts rather than the old
behavior: token-pair auth callbacks are rejected, knowledge realtime no
longer subscribes to DELETE, long transcript lines are split, and
meeting recovery requires the local recording ledger for empty rows.
2026-09-28 20:45:52 +09:00

67 lines
2.4 KiB
TypeScript

// packages/core/src/voice-error-message.ts
// 받아쓰기 오류 코드 → 사용자 문구 종류의 단일 분류(순수 함수, i18n 의존 없음).
//
// VoiceModeService 의 D3ROError.message 는 로그용 영문("Audio capture failed: …")이다. 이 분류가 없으면
// 녹음 팁·메인 창 알림이 각자 코드를 해석하거나 영문 원문을 그대로 보인다(2026-09-28 감사: 팁 분기가
// 오류 코드를 받지 못해 한 번도 타지 않았다). 문구 종류(VoiceErrorMessageId)를 여기서 한 번 정하고,
// 표면(main 팁 / 렌더러 알림)은 종류 → 번역 키를 Record 로 매핑한다 — 종류가 늘면 매핑 누락이 타입 오류가 된다.
import { ErrorCode } from './errors'
export type VoiceErrorMessageId =
| 'modelMissing'
| 'engine'
| 'micOpen'
| 'micLost'
| 'noSpeech'
| 'tooShort'
| 'transcription'
| 'captionActive'
| 'quota'
| 'llmFailed'
export function classifyVoiceError(code: number | undefined | null): VoiceErrorMessageId | null {
switch (code) {
case ErrorCode.STTModelNotFound:
return 'modelMissing'
case ErrorCode.STTEngineNotInstalled:
case ErrorCode.STTModelLoadFailed:
case ErrorCode.STTModelNotLoaded:
case ErrorCode.STTSidecarSpawnFailed:
case ErrorCode.STTSidecarCrashed:
case ErrorCode.STTSidecarCommunicationFailed:
return 'engine'
case ErrorCode.AudioDeviceNotFound:
case ErrorCode.AudioDeviceAccessDenied:
case ErrorCode.AudioDeviceBusy:
case ErrorCode.AudioCaptureStartFailed:
case ErrorCode.AudioNoPermission:
return 'micOpen'
case ErrorCode.AudioCaptureFailed:
case ErrorCode.AudioStreamError:
return 'micLost'
case ErrorCode.STTNoAudioData:
return 'noSpeech'
case ErrorCode.STTAudioTooShort:
return 'tooShort'
case ErrorCode.STTTranscriptionFailed:
case ErrorCode.STTTranscriptionTimeout:
return 'transcription'
case ErrorCode.CaptionAlreadyActive:
return 'captionActive'
case ErrorCode.QuotaExceeded:
return 'quota'
case ErrorCode.LLMProcessingFailed:
case ErrorCode.ChainExecutionFailed:
return 'llmFailed'
default:
return null
}
}
/** 이 종류의 오류를 사용자가 설정에서 고칠 수 있으면 그 탭 */
export function voiceErrorSettingsTab(id: VoiceErrorMessageId | null): 'stt' | 'audio' | null {
if (id === 'modelMissing') return 'stt'
if (id === 'micOpen') return 'audio'
return null
}