feat #14740: merge speakers and name calls

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
hauke
2026-11-06 11:17:40 +01:00
co-authored by Claude Opus 5.5
parent 5dfe1d9357
commit 345dd01147
12 changed files with 1213 additions and 29 deletions
+9 -4
View File
@@ -9,6 +9,11 @@
onselect,
}: { calls: CallListItem[]; selectedId: CallId | null; onselect: (id: CallId) => void } =
$props()
/** "Microsoft Teams · 32 min" (no duration while recording). */
function appLine(call: CallListItem): string {
return call.status === 'recording' ? call.app : `${call.app} · ${formatMinutes(call.duration_secs)}`
}
</script>
{#if calls.length === 0}
@@ -23,11 +28,11 @@
aria-current={call.id === selectedId}
onclick={() => onselect(call.id)}
>
<span class="title">
{call.app}{#if call.status !== 'recording'}&nbsp;· {formatMinutes(call.duration_secs)}{/if}
</span>
<span class="title">{call.title ?? appLine(call)}</span>
<span class="meta">
<span class="muted">{formatListTime(call.started_at)}</span>
<span class="muted">
{call.title ? `${appLine(call)} · ` : ''}{formatListTime(call.started_at)}
</span>
<StatusPill status={call.status} interrupted={call.interrupted} />
</span>
</button>
+160 -2
View File
@@ -1,14 +1,23 @@
<script lang="ts">
import { errorText, type SegmentView } from './api'
import { errorText, type SegmentView, type SpeakerMerge } from './api'
import { formatOffset } from './format'
let {
segments,
merges,
onrename,
onmerge,
onunmerge,
}: {
/** The transcript with merges applied: merged speakers no longer appear. */
segments: SegmentView[]
merges: SpeakerMerge[]
/** Saves a speaker's name; an empty name restores the default label. */
onrename: (speakerKey: string, name: string) => Promise<void>
/** Merges remote speaker `fromKey` into `intoKey`. */
onmerge: (fromKey: string, intoKey: string) => Promise<void>
/** Undoes the merge of `fromKey`. */
onunmerge: (fromKey: string) => Promise<void>
} = $props()
// "Ich" is always the primary blue; remote speakers cycle through the rest.
@@ -36,15 +45,46 @@
.sort((a, b) => speakerOrder(a.key) - speakerOrder(b.key))
})
let remoteSpeakers = $derived(speakers.filter((s) => s.key !== 'me'))
let editing = $state<string | null>(null)
let draft = $state('')
let saving = $state(false)
let error = $state('')
/** The speaker whose "zusammenführen mit …" menu is open. */
let mergeMenu = $state<string | null>(null)
function startEdit(key: string, label: string) {
editing = key
draft = label
error = ''
mergeMenu = null
}
function toggleMergeMenu(event: MouseEvent, key: string) {
event.stopPropagation()
mergeMenu = mergeMenu === key ? null : key
editing = null
error = ''
}
/** Runs a merge or undo; its error is shown below the chips. */
async function save(action: () => Promise<void>) {
if (saving) return
mergeMenu = null
saving = true
error = ''
try {
await action()
} catch (err) {
error = errorText(err)
} finally {
saving = false
}
}
function onwindowkeydown(event: KeyboardEvent) {
if (event.key === 'Escape') mergeMenu = null
}
async function onkeydown(event: KeyboardEvent) {
@@ -70,6 +110,8 @@
}
</script>
<svelte:window onclick={() => (mergeMenu = null)} onkeydown={onwindowkeydown} />
{#if segments.length === 0}
<p class="muted">Keine Sprache erkannt.</p>
{:else}
@@ -90,6 +132,33 @@
<span class="dot"></span>
<span>{label}</span>
<button class="edit" title="Umbenennen" onclick={() => startEdit(key, label)}>✎</button>
{#if key !== 'me' && remoteSpeakers.length > 1}
<button
class="edit"
title="Zusammenführen mit …"
aria-label="{label} zusammenführen mit …"
aria-haspopup="menu"
aria-expanded={mergeMenu === key}
disabled={saving}
onclick={(event) => toggleMergeMenu(event, key)}>⇄</button
>
{/if}
{/if}
{#if mergeMenu === key}
<!-- Clicks inside the menu must not reach the window, which closes it. -->
<!-- svelte-ignore a11y_click_events_have_key_events -->
<div class="menu" role="menu" tabindex="-1" onclick={(event) => event.stopPropagation()}>
<div class="menu-title">{label} zusammenführen mit …</div>
{#each remoteSpeakers.filter((s) => s.key !== key) as target (target.key)}
<button
role="menuitem"
style:--speaker={speakerColor(target.key)}
onclick={() => save(() => onmerge(key, target.key))}
>
<span class="dot"></span>{target.label}
</button>
{/each}
</div>
{/if}
</span>
{/each}
@@ -100,6 +169,20 @@
{#if error}
<div class="error">{error}</div>
{/if}
{#if merges.length > 0}
<ul class="merges">
{#each merges as merge (merge.from_key)}
<li>
{merge.from_label} → {merge.into_label} zusammengeführt
<button
class="link"
disabled={saving}
onclick={() => save(() => onunmerge(merge.from_key))}>rückgängig</button
>
</li>
{/each}
</ul>
{/if}
<div class="lines">
{#each segments as segment, i (i)}
@@ -120,6 +203,7 @@
}
.chip {
position: relative;
display: inline-flex;
align-items: center;
gap: 6px;
@@ -147,10 +231,84 @@
padding: 0 4px;
}
.edit:hover {
.edit:hover:not(:disabled) {
color: var(--primary);
}
.edit:disabled {
cursor: default;
opacity: 0.5;
}
.menu {
position: absolute;
top: calc(100% + 4px);
left: 0;
z-index: 10;
display: flex;
flex-direction: column;
min-width: 180px;
padding: 4px;
border: 1px solid var(--border);
border-radius: 8px;
background: var(--surface);
box-shadow: 0 4px 14px rgb(0 0 0 / 0.12);
font-weight: 400;
}
.menu-title {
padding: 4px 8px 6px;
color: var(--muted);
white-space: nowrap;
}
.menu button {
display: flex;
align-items: center;
gap: 6px;
padding: 5px 8px;
border: none;
border-radius: 6px;
background: none;
font: inherit;
font-weight: 600;
color: inherit;
text-align: left;
cursor: pointer;
}
.menu button:hover {
background: var(--primary-soft);
}
.merges {
list-style: none;
margin: 10px 0 0;
padding: 0;
color: var(--muted);
font-size: 12px;
}
.merges li + li {
margin-top: 2px;
}
.link {
margin-left: 4px;
padding: 0;
border: none;
background: none;
font: inherit;
color: var(--primary);
text-decoration: underline;
cursor: pointer;
}
.link:disabled {
cursor: default;
opacity: 0.5;
}
.rename {
width: 160px;
padding: 1px 6px;
+19
View File
@@ -65,6 +65,8 @@ export interface CallListItem {
duration_secs: number
status: CallStatus
interrupted: boolean
/** The name the user gave the call, if any. */
title: string | null
}
/** A transcript line; `speaker_key` is "me" or "remote:<n>". */
@@ -76,11 +78,21 @@ export interface SegmentView {
text: string
}
/** A merged speaker: its lines now belong to `into_key`. */
export interface SpeakerMerge {
from_key: string
from_label: string
into_key: string
into_label: string
}
export interface CallDetail {
call: CallListItem & { error: string | null; account_id: string | null }
/** The transcript with speaker merges applied. */
segments: SegmentView[]
/** Renamed speakers by key. */
speaker_names: Record<string, string>
merges: SpeakerMerge[]
}
export interface Account {
@@ -115,6 +127,13 @@ export const getCall = (id: CallId) => invoke<CallDetail>('get_call', { id })
/** An empty name restores the default label. */
export const renameSpeaker = (id: CallId, speakerKey: string, name: string) =>
invoke<void>('rename_speaker', { id, speakerKey, name })
export const mergeSpeakers = (id: CallId, fromKey: string, intoKey: string) =>
invoke<void>('merge_speakers', { id, fromKey, intoKey })
export const unmergeSpeaker = (id: CallId, fromKey: string) =>
invoke<void>('unmerge_speaker', { id, fromKey })
/** `null` or an empty title restores the default heading. */
export const renameCall = (id: CallId, title: string | null) =>
invoke<void>('rename_call', { id, title })
export const listAccounts = () => invoke<Account[]>('list_accounts')
export const setAccount = (id: CallId, accountId: string | null) =>
invoke<void>('set_account', { id, accountId })
+114 -3
View File
@@ -6,14 +6,17 @@
getCall,
listAccounts,
listCalls,
mergeSpeakers,
onCallEnded,
onCallUpdated,
onPromptChanged,
onRecordingState,
renameCall,
renameSpeaker,
retryCall,
setAccount,
transcribeCall,
unmergeSpeaker,
type Account,
type CallDetail,
type CallId,
@@ -36,6 +39,11 @@
let busy = $state(false)
let tab = $state<'summary' | 'transcript'>('transcript')
let editingTitle = $state(false)
let titleDraft = $state('')
let savingTitle = $state(false)
let titleError = $state('')
// Answers can arrive out of order; only the newest request is applied.
let listRequest = 0
let detailRequest = 0
@@ -84,6 +92,8 @@
detail = null
detailError = ''
actionError = ''
editingTitle = false
titleError = ''
refreshDetail()
}
@@ -92,6 +102,8 @@
detail = null
detailError = ''
actionError = ''
editingTitle = false
titleError = ''
}
onMount(() => {
@@ -155,8 +167,51 @@
await refreshDetail()
}
async function merge(fromKey: string, intoKey: string) {
if (!detail) return
await mergeSpeakers(detail.call.id, fromKey, intoKey)
await refreshDetail()
}
async function unmerge(fromKey: string) {
if (!detail) return
await unmergeSpeaker(detail.call.id, fromKey)
await refreshDetail()
}
function startTitleEdit() {
titleDraft = detail?.call.title ?? ''
titleError = ''
editingTitle = true
}
/** Enter saves the title (empty restores the default), Esc cancels. */
async function titleKeydown(event: KeyboardEvent) {
if (event.key === 'Escape') {
editingTitle = false
titleError = ''
} else if (event.key === 'Enter' && detail && !savingTitle) {
savingTitle = true
titleError = ''
try {
await renameCall(detail.call.id, titleDraft.trim() || null)
editingTitle = false
await Promise.all([refreshList(), refreshDetail()])
} catch (err) {
titleError = errorText(err)
} finally {
savingTitle = false
}
}
}
function focus(node: HTMLInputElement) {
node.focus()
node.select()
}
/** "Microsoft Teams · heute 10:14 · 32 min" (no duration while recording). */
function title(call: CallListItem): string {
function defaultTitle(call: CallListItem): string {
const parts = [call.app, formatDetailTime(call.started_at)]
if (call.status !== 'recording') parts.push(formatMinutes(call.duration_secs))
return parts.join(' · ')
@@ -195,9 +250,32 @@
{@const call = detail.call}
<header class="detail-header">
<div class="heading">
<h1>{title(call)}</h1>
{#if editingTitle}
<input
class="title-input"
aria-label="Titel des Gesprächs"
placeholder={defaultTitle(call)}
disabled={savingTitle}
bind:value={titleDraft}
onkeydown={titleKeydown}
use:focus
/>
{:else}
<h1>
{call.title ?? defaultTitle(call)}
<button class="edit-title" title="Titel ändern" onclick={startTitleEdit}>✎</button>
</h1>
{/if}
<StatusPill status={call.status} interrupted={call.interrupted} />
</div>
{#if editingTitle}
<p class="muted subline">Enter speichert, Esc bricht ab. Leer = Standardtitel.</p>
{:else if call.title}
<p class="muted subline">{defaultTitle(call)}</p>
{/if}
{#if titleError}
<p class="error">{titleError}</p>
{/if}
<div class="toolbar">
<label class="customer">
<span>Kunde:</span>
@@ -262,7 +340,13 @@
{#if tab === 'summary'}
<p class="muted">Die Zusammenfassung kommt in einer späteren Version.</p>
{:else}
<TranscriptView segments={detail.segments} onrename={rename} />
<TranscriptView
segments={detail.segments}
merges={detail.merges}
onrename={rename}
onmerge={merge}
onunmerge={unmerge}
/>
{/if}
</div>
{/if}
@@ -348,6 +432,33 @@
.heading h1 {
font-size: 18px;
overflow-wrap: anywhere;
}
.edit-title {
border: none;
background: none;
color: var(--muted);
cursor: pointer;
font-size: 14px;
padding: 0 4px;
vertical-align: middle;
}
.edit-title:hover {
color: var(--primary);
}
.title-input {
flex: 1 1 260px;
max-width: 520px;
font-size: 16px;
font-weight: 600;
}
.subline {
margin: 4px 0 0;
font-size: 12px;
}
.toolbar {