From d1658f5d9ed9e0f4657908336814b93a07b95eea Mon Sep 17 00:00:00 2001 From: hauke Date: Fri, 6 Nov 2026 09:38:55 +0100 Subject: [PATCH] feat #14740: main window with call list and transcript Co-Authored-By: Claude Opus 5.5 (1M context) --- crates/core/src/accounts.rs | 82 ++++++ crates/core/src/call_view.rs | 226 ++++++++++++++++ crates/core/src/lib.rs | 2 + crates/core/src/store.rs | 29 +++ src-tauri/src/commands.rs | 43 ++++ src-tauri/src/lib.rs | 5 + src-tauri/src/processing.rs | 3 +- src-tauri/src/state.rs | 170 ++++++++++++- ui/src/App.svelte | 8 +- ui/src/lib/CallList.svelte | 92 +++++++ ui/src/lib/StatusPill.svelte | 51 ++++ ui/src/lib/TranscriptView.svelte | 196 ++++++++++++++ ui/src/lib/api.ts | 42 +++ ui/src/lib/format.ts | 33 +++ ui/src/routes/Main.svelte | 424 +++++++++++++++++++++++++++++++ 15 files changed, 1391 insertions(+), 15 deletions(-) create mode 100644 crates/core/src/accounts.rs create mode 100644 crates/core/src/call_view.rs create mode 100644 ui/src/lib/CallList.svelte create mode 100644 ui/src/lib/StatusPill.svelte create mode 100644 ui/src/lib/TranscriptView.svelte create mode 100644 ui/src/routes/Main.svelte diff --git a/crates/core/src/accounts.rs b/crates/core/src/accounts.rs new file mode 100644 index 0000000..6e7025d --- /dev/null +++ b/crates/core/src/accounts.rs @@ -0,0 +1,82 @@ +//! Customer accounts a call can be assigned to (the "Kunde" dropdown). +//! +//! A static mock for now: the names are clearly fictional placeholders +//! until the account system is connected. + +use serde::Serialize; + +/// A customer account. `id` is what a call stores as its `account_id`. +#[derive(Serialize, Clone, Copy, Debug, PartialEq, Eq)] +pub struct Account { + pub id: &'static str, + pub name: &'static str, +} + +const MOCK_ACCOUNTS: [Account; 5] = [ + Account { + id: "mock-1", + name: "Weingut Beispiel GmbH", + }, + Account { + id: "mock-2", + name: "Weinhandel Muster KG", + }, + Account { + id: "mock-3", + name: "Vinothek Probe", + }, + Account { + id: "mock-4", + name: "Kellerei Test eG", + }, + Account { + id: "mock-5", + name: "Restaurant Platzhalter", + }, +]; + +/// All accounts, in display order. +pub fn list() -> Vec { + MOCK_ACCOUNTS.to_vec() +} + +/// Whether `id` names one of the accounts. +pub fn exists(id: &str) -> bool { + MOCK_ACCOUNTS.iter().any(|account| account.id == id) +} + +#[cfg(test)] +mod tests { + use std::collections::HashSet; + + use super::*; + + #[test] + fn mock_accounts_are_stable_and_unique() { + let accounts = list(); + let names: Vec<_> = accounts.iter().map(|a| a.name).collect(); + assert_eq!( + names, + [ + "Weingut Beispiel GmbH", + "Weinhandel Muster KG", + "Vinothek Probe", + "Kellerei Test eG", + "Restaurant Platzhalter", + ] + ); + let ids: HashSet<_> = accounts.iter().map(|a| a.id).collect(); + assert_eq!(ids.len(), 5); + // Stored with the calls, so they must never change. + assert_eq!(accounts[0].id, "mock-1"); + assert_eq!(accounts[4].id, "mock-5"); + assert_eq!(list(), accounts); + } + + #[test] + fn only_listed_accounts_exist() { + assert!(exists("mock-3")); + assert!(!exists("mock-6")); + assert!(!exists("")); + } +} diff --git a/crates/core/src/call_view.rs b/crates/core/src/call_view.rs new file mode 100644 index 0000000..0dda02d --- /dev/null +++ b/crates/core/src/call_view.rs @@ -0,0 +1,226 @@ +//! What the main window shows about calls: the rows of the call list and +//! the detail of the selected call, shaped from the stored data. + +use std::collections::BTreeMap; + +use chrono::{DateTime, Local}; +use serde::Serialize; + +use crate::merge; +use crate::model::{Call, CallId, CallStatus, Segment}; + +/// A row of the call list. +#[derive(Serialize, Clone, Debug, PartialEq)] +pub struct CallListItem { + pub id: CallId, + pub app: String, + pub started_at: DateTime, + /// Whole seconds from start to end; 0 while recording. + pub duration_secs: i64, + pub status: CallStatus, + pub interrupted: bool, +} + +impl CallListItem { + pub fn of(call: &Call) -> Self { + Self { + id: call.id, + app: call.app.clone(), + started_at: call.started_at, + duration_secs: duration_secs(call), + status: call.status, + interrupted: call.interrupted, + } + } +} + +/// Whole seconds from `started_at` to `ended_at`; 0 while the call has not +/// ended (and never negative). +pub fn duration_secs(call: &Call) -> i64 { + call.ended_at + .map_or(0, |end| (end - call.started_at).num_seconds().max(0)) +} + +/// The selected call's header data: its list row plus the error of a +/// failed run and the assigned account. +#[derive(Serialize, Clone, Debug, PartialEq)] +pub struct CallHeader { + #[serde(flatten)] + pub item: CallListItem, + pub error: Option, + pub account_id: Option, +} + +/// A transcript line with the speaker's display label. +#[derive(Serialize, Clone, Debug, PartialEq)] +pub struct SegmentView { + /// [`crate::model::Speaker::key`], stable across renames. + pub speaker_key: String, + pub label: String, + pub start: f64, + pub end: f64, + pub text: String, +} + +/// Everything the detail pane shows about one call. +#[derive(Serialize, Clone, Debug, PartialEq)] +pub struct CallDetail { + pub call: CallHeader, + pub segments: Vec, + /// Renamed speakers by key; speakers not in here keep their default + /// label. + pub speaker_names: BTreeMap, +} + +impl CallDetail { + pub fn of(call: &Call, segments: &[Segment], speaker_names: BTreeMap) -> Self { + let segments = segments + .iter() + .map(|segment| SegmentView { + speaker_key: segment.speaker.key(), + label: merge::label(&segment.speaker, &speaker_names), + start: segment.start, + end: segment.end, + text: segment.text.clone(), + }) + .collect(); + Self { + call: CallHeader { + item: CallListItem::of(call), + error: call.error.clone(), + account_id: call.account_id.clone(), + }, + segments, + speaker_names, + } + } +} + +#[cfg(test)] +mod tests { + use std::path::PathBuf; + + use chrono::TimeZone; + use serde_json::json; + + use super::*; + use crate::model::Speaker; + + fn at(h: u32, m: u32, s: u32) -> DateTime { + Local.with_ymd_and_hms(2026, 11, 5, h, m, s).unwrap() + } + + fn call(ended_at: Option>) -> Call { + Call { + id: 7, + app: "Microsoft Teams".into(), + started_at: at(10, 14, 0), + ended_at, + status: CallStatus::Done, + interrupted: false, + error: None, + mic_path: PathBuf::from("7-mic.wav"), + out_path: PathBuf::from("7-out.wav"), + transcribed_at: None, + audio_deleted: false, + account_id: None, + } + } + + fn segment(speaker: Speaker, start: f64, text: &str) -> Segment { + Segment { + speaker, + start, + end: start + 2.0, + text: text.into(), + } + } + + #[test] + fn duration_runs_from_start_to_end() { + assert_eq!(duration_secs(&call(Some(at(10, 46, 30)))), 32 * 60 + 30); + } + + #[test] + fn duration_is_zero_while_recording_and_never_negative() { + assert_eq!(duration_secs(&call(None)), 0); + assert_eq!(duration_secs(&call(Some(at(10, 13, 0)))), 0); + } + + #[test] + fn list_item_carries_the_row_fields() { + let mut c = call(Some(at(10, 15, 0))); + c.status = CallStatus::AwaitingDecision; + c.interrupted = true; + assert_eq!( + CallListItem::of(&c), + CallListItem { + id: 7, + app: "Microsoft Teams".into(), + started_at: at(10, 14, 0), + duration_secs: 60, + status: CallStatus::AwaitingDecision, + interrupted: true, + } + ); + } + + #[test] + fn detail_labels_segments_with_renames_and_defaults() { + let segments = [ + segment(Speaker::Me, 0.0, "Guten Tag."), + segment(Speaker::Remote(1), 2.5, "Hallo."), + segment(Speaker::Remote(2), 5.0, "Moin."), + ]; + let mut names = BTreeMap::new(); + names.insert("remote:1".to_string(), "Frau Beispiel".to_string()); + names.insert("remote:2".to_string(), " ".to_string()); + + let detail = CallDetail::of(&call(Some(at(10, 15, 0))), &segments, names.clone()); + + let lines: Vec<_> = detail + .segments + .iter() + .map(|s| (s.speaker_key.as_str(), s.label.as_str(), s.text.as_str())) + .collect(); + assert_eq!( + lines, + [ + ("me", "Ich", "Guten Tag."), + ("remote:1", "Frau Beispiel", "Hallo."), + ("remote:2", "Sprecher 2", "Moin."), + ] + ); + assert_eq!(detail.segments[1].start, 2.5); + assert_eq!(detail.segments[1].end, 4.5); + assert_eq!(detail.speaker_names, names); + } + + #[test] + fn detail_serializes_the_call_header_flat() { + let mut c = call(Some(at(10, 15, 0))); + c.status = CallStatus::Failed; + c.error = Some("Netzwerkfehler".into()); + c.account_id = Some("mock-2".into()); + + let value = serde_json::to_value(CallDetail::of(&c, &[], BTreeMap::new())).unwrap(); + + assert_eq!( + value, + json!({ + "call": { + "id": 7, + "app": "Microsoft Teams", + "started_at": serde_json::to_value(at(10, 14, 0)).unwrap(), + "duration_secs": 60, + "status": "failed", + "interrupted": false, + "error": "Netzwerkfehler", + "account_id": "mock-2", + }, + "segments": [], + "speaker_names": {}, + }) + ); + } +} diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 415b7eb..82f789f 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -4,7 +4,9 @@ //! transcription and summarization logic, kept independent of the Tauri //! application shell so it can be unit-tested without a GUI or network. +pub mod accounts; pub mod audio; +pub mod call_view; pub mod capture; pub mod detect; pub mod http; diff --git a/crates/core/src/store.rs b/crates/core/src/store.rs index 60d4268..b5c0497 100644 --- a/crates/core/src/store.rs +++ b/crates/core/src/store.rs @@ -286,6 +286,17 @@ impl Store { Ok(()) } + /// Drops the rename of `speaker_key`, so it shows its default label + /// again. Not an error if it was never renamed. + pub fn remove_speaker_name(&self, id: CallId, speaker_key: &str) -> Result<()> { + let conn = self.conn.lock().unwrap(); + conn.execute( + "DELETE FROM speaker_names WHERE call_id = ?1 AND speaker_key = ?2", + params![id, speaker_key], + )?; + Ok(()) + } + pub fn speaker_names(&self, id: CallId) -> Result> { let conn = self.conn.lock().unwrap(); let mut stmt = @@ -661,6 +672,24 @@ mod tests { assert_eq!(names.get("remote:1").unwrap(), "Frau Mueller"); } + #[test] + fn a_removed_speaker_name_is_gone() { + let store = Store::open_in_memory().unwrap(); + let id = store + .create_call("teams.exe", Local::now(), Path::new(""), Path::new("")) + .unwrap(); + store + .set_speaker_name(id, "remote:1", "Frau Probe") + .unwrap(); + store.set_speaker_name(id, "remote:2", "Herr Test").unwrap(); + + store.remove_speaker_name(id, "remote:1").unwrap(); + store.remove_speaker_name(id, "remote:3").unwrap(); // never renamed + + let names = store.speaker_names(id).unwrap(); + assert_eq!(names.keys().collect::>(), ["remote:2"]); + } + #[test] fn list_newest_first() { let store = Store::open_in_memory().unwrap(); diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 8ff1821..0b29e82 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -8,6 +8,8 @@ use std::thread; use std::time::Duration; +use recorder_core::accounts::{self, Account}; +use recorder_core::call_view::{CallDetail, CallListItem}; use recorder_core::capture::Devices; use recorder_core::model::CallId; use recorder_core::secrets::Service; @@ -118,6 +120,47 @@ pub fn get_call_brief(state: State<'_, AppState>, id: CallId) -> CmdResult) -> CmdResult> { + state.call_list() +} + +/// The selected call with its transcript. +#[tauri::command] +pub fn get_call(state: State<'_, AppState>, id: CallId) -> CmdResult { + state.call_detail(id) +} + +/// Renames a speaker of a call (an empty name restores the default label). +#[tauri::command] +pub fn rename_speaker( + app: AppHandle, + state: State<'_, AppState>, + id: CallId, + speaker_key: String, + name: String, +) -> CmdResult<()> { + state.rename_speaker(id, &speaker_key, &name)?; + processing::emit_updated(&app, id); + Ok(()) +} + +#[tauri::command] +pub fn list_accounts() -> Vec { + accounts::list() +} + +/// Assigns a call to a customer account, or to none. +#[tauri::command] +pub fn set_account( + state: State<'_, AppState>, + id: CallId, + account_id: Option, +) -> CmdResult<()> { + state.set_account(id, account_id.as_deref()) +} + /// Deletes a finished call's audio and row. Closes the prompt if no call /// waits for it any more; otherwise the prompt reloads and shows the next. /// While its DeepScript jobs are still on record, nothing is deleted and a diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index bc39bdc..b0b58f1 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -104,6 +104,11 @@ pub fn run() { commands::discard_call, commands::transcribe_call, commands::retry_call, + commands::list_calls, + commands::get_call, + commands::rename_speaker, + commands::list_accounts, + commands::set_account, ]) .run(tauri::generate_context!()) .expect("error while building tauri application"); diff --git a/src-tauri/src/processing.rs b/src-tauri/src/processing.rs index 2e507eb..4c8a079 100644 --- a/src-tauri/src/processing.rs +++ b/src-tauri/src/processing.rs @@ -165,7 +165,8 @@ fn deepscript_key(state: &AppState) -> Option { .filter(|key| !key.trim().is_empty()) } -fn emit_updated(app: &AppHandle, id: CallId) { +/// Tells the UI that call `id` changed (`call-updated`). +pub fn emit_updated(app: &AppHandle, id: CallId) { if let Err(e) = app.emit("call-updated", CallUpdated { id }) { log::error!("could not emit call-updated: {e}"); } diff --git a/src-tauri/src/state.rs b/src-tauri/src/state.rs index a442349..a4cf3e8 100644 --- a/src-tauri/src/state.rs +++ b/src-tauri/src/state.rs @@ -16,10 +16,12 @@ use std::thread; use std::time::{Duration, Instant}; use chrono::{DateTime, Local}; +use recorder_core::accounts; +use recorder_core::call_view::{self, CallDetail, CallListItem}; use recorder_core::capture::{CaptureSource, OutputTarget}; use recorder_core::detect::{CallDetector, DetectorEvent, MicSession}; use recorder_core::http::{HttpTransport, ReqwestTransport}; -use recorder_core::model::{Call, CallId, CallStatus}; +use recorder_core::model::{Call, CallId, CallStatus, Speaker}; use recorder_core::recorder::Recorder; use recorder_core::secrets::SecretStore; use recorder_core::settings::Settings; @@ -105,9 +107,7 @@ impl CallBrief { app: call.app.clone(), started_at: call.started_at, ended_at: call.ended_at, - duration_secs: call - .ended_at - .map_or(0, |end| (end - call.started_at).num_seconds().max(0)), + duration_secs: call_view::duration_secs(call), } } } @@ -416,12 +416,55 @@ impl AppState { } pub fn call_brief(&self, id: CallId) -> Result { - let call = self - .store + Ok(CallBrief::of(&self.find_call(id)?)) + } + + /// All calls for the main window's list, newest first. + pub fn call_list(&self) -> Result, String> { + let calls = self.store.list_calls().map_err(|e| e.to_string())?; + Ok(calls.iter().map(CallListItem::of).collect()) + } + + /// The selected call with its transcript and speaker names. + pub fn call_detail(&self, id: CallId) -> Result { + let call = self.find_call(id)?; + let segments = self.store.segments(id).map_err(|e| e.to_string())?; + let names = self.store.speaker_names(id).map_err(|e| e.to_string())?; + Ok(CallDetail::of(&call, &segments, names)) + } + + /// Renames a speaker of call `id`; a blank `name` restores the default + /// label ("Ich", "Sprecher N"). + pub fn rename_speaker(&self, id: CallId, speaker_key: &str, name: &str) -> Result<(), String> { + if Speaker::from_key(speaker_key).is_none() { + return Err(format!("Unbekannter Sprecher: {speaker_key}")); + } + self.find_call(id)?; + let name = name.trim(); + let result = if name.is_empty() { + self.store.remove_speaker_name(id, speaker_key) + } else { + self.store.set_speaker_name(id, speaker_key, name) + }; + result.map_err(|e| format!("Name konnte nicht gespeichert werden: {e}")) + } + + /// Assigns call `id` to one of the [`accounts`], or to none. + pub fn set_account(&self, id: CallId, account_id: Option<&str>) -> Result<(), String> { + if account_id.is_some_and(|account| !accounts::exists(account)) { + return Err("Unbekannter Kunde".to_string()); + } + self.find_call(id)?; + self.store + .set_account(id, account_id) + .map_err(|e| format!("Kunde konnte nicht gespeichert werden: {e}")) + } + + fn find_call(&self, id: CallId) -> Result { + self.store .get_call(id) .map_err(|e| e.to_string())? - .ok_or_else(|| "Gespräch nicht gefunden".to_string())?; - Ok(CallBrief::of(&call)) + .ok_or_else(|| "Gespräch nicht gefunden".to_string()) } /// Deletes a finished call: both audio files and the row, and takes it @@ -595,6 +638,7 @@ fn lock(mutex: &Mutex) -> MutexGuard<'_, T> { #[cfg(test)] mod tests { use chrono::TimeZone; + use recorder_core::model::{Segment, Speaker}; use recorder_core::secrets::MemorySecrets; use super::*; @@ -895,6 +939,116 @@ mod tests { assert!(f.state.claim_processing(recording + 1, true).is_err()); } + #[test] + fn call_list_is_newest_first_with_durations() { + let f = fixture(); + let (older, _, _) = finished_call(&f, "a"); + let newer = f + .state + .store + .create_call("Manuell", at(11, 0, 0), Path::new(""), Path::new("")) + .unwrap(); + + let list = f.state.call_list().unwrap(); + let rows: Vec<_> = list + .iter() + .map(|item| (item.id, item.status, item.duration_secs)) + .collect(); + assert_eq!( + rows, + [ + (newer, CallStatus::Recording, 0), + (older, CallStatus::AwaitingDecision, 32 * 60 + 30), + ] + ); + } + + #[test] + fn call_detail_shows_the_transcript_with_renamed_speakers() { + let f = fixture(); + let (id, _, _) = finished_call(&f, "a"); + f.state + .store + .save_segments( + id, + &[ + Segment { + speaker: Speaker::Me, + start: 0.0, + end: 1.5, + text: "Guten Tag.".into(), + }, + Segment { + speaker: Speaker::Remote(1), + start: 2.0, + end: 3.0, + text: "Hallo.".into(), + }, + ], + ) + .unwrap(); + f.state + .rename_speaker(id, "remote:1", "Frau Probe") + .unwrap(); + + let detail = f.state.call_detail(id).unwrap(); + assert_eq!(detail.call.item.id, id); + let labels: Vec<_> = detail.segments.iter().map(|s| s.label.as_str()).collect(); + assert_eq!(labels, ["Ich", "Frau Probe"]); + assert!(f.state.call_detail(id + 1).is_err()); + } + + #[test] + fn renaming_a_speaker_trims_and_an_empty_name_restores_the_default() { + let f = fixture(); + let (id, _, _) = finished_call(&f, "a"); + let names = |f: &Fixture| f.state.store.speaker_names(id).unwrap(); + + f.state + .rename_speaker(id, "remote:2", " Herr Test ") + .unwrap(); + assert_eq!( + names(&f).get("remote:2").map(String::as_str), + Some("Herr Test") + ); + + f.state.rename_speaker(id, "remote:2", " ").unwrap(); + assert!(names(&f).is_empty()); + } + + #[test] + fn renaming_needs_a_known_speaker_and_call() { + let f = fixture(); + let (id, _, _) = finished_call(&f, "a"); + assert!(f.state.rename_speaker(id, "remote:x", "Name").is_err()); + assert!(f.state.rename_speaker(id + 1, "me", "Name").is_err()); + assert!(f.state.store.speaker_names(id).unwrap().is_empty()); + } + + #[test] + fn the_account_is_set_and_cleared() { + let f = fixture(); + let (id, _, _) = finished_call(&f, "a"); + let account = |f: &Fixture| f.state.store.get_call(id).unwrap().unwrap().account_id; + + f.state.set_account(id, Some("mock-2")).unwrap(); + assert_eq!(account(&f).as_deref(), Some("mock-2")); + f.state.set_account(id, None).unwrap(); + assert_eq!(account(&f), None); + } + + #[test] + fn only_known_accounts_and_calls_are_assigned() { + let f = fixture(); + let (id, _, _) = finished_call(&f, "a"); + assert!(f.state.set_account(id, Some("mock-99")).is_err()); + assert!(f.state.set_account(id + 1, Some("mock-1")).is_err()); + assert_eq!( + f.state.store.get_call(id).unwrap().unwrap().account_id, + None + ); + } + #[test] fn invalid_detection_delays_are_not_saved() { let f = fixture(); diff --git a/ui/src/App.svelte b/ui/src/App.svelte index d195419..8627f95 100644 --- a/ui/src/App.svelte +++ b/ui/src/App.svelte @@ -1,5 +1,6 @@ + +{#if calls.length === 0} +

Noch keine Gespräche aufgezeichnet.

+{:else} +
    + {#each calls as call (call.id)} +
  • + +
  • + {/each} +
+{/if} + + diff --git a/ui/src/lib/StatusPill.svelte b/ui/src/lib/StatusPill.svelte new file mode 100644 index 0000000..752a900 --- /dev/null +++ b/ui/src/lib/StatusPill.svelte @@ -0,0 +1,51 @@ + + + + {pill.text}{#if interrupted && status === 'awaiting_decision'}, unterbrochen{/if} + + + diff --git a/ui/src/lib/TranscriptView.svelte b/ui/src/lib/TranscriptView.svelte new file mode 100644 index 0000000..858d15d --- /dev/null +++ b/ui/src/lib/TranscriptView.svelte @@ -0,0 +1,196 @@ + + +{#if segments.length === 0} +

Keine Sprache erkannt.

+{:else} +
+ {#each speakers as { key, label } (key)} + + {#if editing === key} + + {:else} + + {label} + + {/if} + + {/each} +
+ {#if editing} +
Enter speichert, Esc bricht ab.
+ {/if} + {#if error} +
{error}
+ {/if} + +
+ {#each segments as segment, i (i)} +
+ {formatOffset(segment.start)} + {segment.label} + {segment.text} +
+ {/each} +
+{/if} + + diff --git a/ui/src/lib/api.ts b/ui/src/lib/api.ts index 17d5637..7701ee6 100644 --- a/ui/src/lib/api.ts +++ b/ui/src/lib/api.ts @@ -54,6 +54,40 @@ export interface PendingPrompt extends CallBrief { more_waiting: number } +export type CallStatus = 'recording' | 'awaiting_decision' | 'processing' | 'done' | 'failed' + +/** A row of the main window's call list. Times are RFC 3339. */ +export interface CallListItem { + id: CallId + app: string + started_at: string + /** 0 while recording. */ + duration_secs: number + status: CallStatus + interrupted: boolean +} + +/** A transcript line; `speaker_key` is "me" or "remote:". */ +export interface SegmentView { + speaker_key: string + label: string + start: number + end: number + text: string +} + +export interface CallDetail { + call: CallListItem & { error: string | null; account_id: string | null } + segments: SegmentView[] + /** Renamed speakers by key. */ + speaker_names: Record +} + +export interface Account { + id: string + name: string +} + export interface Levels { mic: number out: number @@ -76,6 +110,14 @@ export const getCallBrief = (id: CallId) => invoke('get_call_brief', export const transcribeCall = (id: CallId) => invoke('transcribe_call', { id }) export const retryCall = (id: CallId) => invoke('retry_call', { id }) export const discardCall = (id: CallId) => invoke('discard_call', { id }) +export const listCalls = () => invoke('list_calls') +export const getCall = (id: CallId) => invoke('get_call', { id }) +/** An empty name restores the default label. */ +export const renameSpeaker = (id: CallId, speakerKey: string, name: string) => + invoke('rename_speaker', { id, speakerKey, name }) +export const listAccounts = () => invoke('list_accounts') +export const setAccount = (id: CallId, accountId: string | null) => + invoke('set_account', { id, accountId }) export const onRecordingState = (handler: (state: RecordingState) => void): Promise => listen('recording-state', (event) => handler(event.payload)) diff --git a/ui/src/lib/format.ts b/ui/src/lib/format.ts index ed29c6d..77d52d8 100644 --- a/ui/src/lib/format.ts +++ b/ui/src/lib/format.ts @@ -20,3 +20,36 @@ export function formatTimeRange(startedAt: string, endedAt: string | null, now = const range = endedAt ? `${clock(start)} – ${clock(new Date(endedAt))}` : clock(start) return `${day}, ${range}` } + +const weekdays = ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'] + +/** "heute", "gestern", or `other(date)` for an older day. */ +function dayName(d: Date, now: Date, other: (d: Date) => string): string { + if (sameDay(d, now)) return 'heute' + const yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1) + return sameDay(d, yesterday) ? 'gestern' : other(d) +} + +const dayMonth = (d: Date) => `${pad(d.getDate())}.${pad(d.getMonth() + 1)}.` + +/** Call list: "heute 10:14", "gestern 10:14" or "04.11. 10:14". */ +export function formatListTime(startedAt: string, now = new Date()): string { + const start = new Date(startedAt) + return `${dayName(start, now, dayMonth)} ${clock(start)}` +} + +/** Detail header: "heute 10:14", "gestern 10:14" or "Mi 04.11. 10:14". */ +export function formatDetailTime(startedAt: string, now = new Date()): string { + const start = new Date(startedAt) + const other = (d: Date) => `${weekdays[d.getDay()]} ${dayMonth(d)}` + return `${dayName(start, now, other)} ${clock(start)}` +} + +/** Position in the recording: "04:07", or "1:02:07" from one hour on. */ +export function formatOffset(secs: number): string { + const total = Math.max(0, Math.floor(secs)) + const h = Math.floor(total / 3600) + const mm = pad(Math.floor((total % 3600) / 60)) + const ss = pad(total % 60) + return h > 0 ? `${h}:${mm}:${ss}` : `${mm}:${ss}` +} diff --git a/ui/src/routes/Main.svelte b/ui/src/routes/Main.svelte new file mode 100644 index 0000000..b02f923 --- /dev/null +++ b/ui/src/routes/Main.svelte @@ -0,0 +1,424 @@ + + +
+ + +
+ {#if detail} + {@const call = detail.call} +
+
+

{title(call)}

+ +
+
+ + + {#if call.status === 'awaiting_decision'} + + + {:else if call.status === 'failed'} + + + {:else if call.status === 'done'} + + + + {/if} + +
+ {#if shownActionError} +

{shownActionError}

+ {/if} +
+ +
+ {#if call.status === 'recording'} +

● Aufnahme läuft

+ {:else if call.status === 'processing'} +

wird verarbeitet…

+ {:else if call.status === 'awaiting_decision'} +

+ {call.interrupted + ? 'Noch nicht transkribiert. Die Aufnahme wurde unterbrochen.' + : 'Noch nicht transkribiert.'} +

+ {:else if call.status === 'failed'} +
+ Verarbeitung fehlgeschlagen +
{call.error ?? 'Unbekannter Fehler'}
+
+ {:else} +
+ + +
+
+ {#if tab === 'summary'} +

Die Zusammenfassung kommt in einer späteren Version.

+ {:else} + + {/if} +
+ {/if} +
+ {:else if detailError} +

{detailError}

+ {:else if loaded && selectedId === null && calls.length > 0} +

Gespräch links auswählen.

+ {/if} +
+
+ +