feat #14740: main window with call list and transcript
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,424 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte'
|
||||
import {
|
||||
discardCall,
|
||||
errorText,
|
||||
getCall,
|
||||
listAccounts,
|
||||
listCalls,
|
||||
onCallEnded,
|
||||
onCallUpdated,
|
||||
onPromptChanged,
|
||||
onRecordingState,
|
||||
renameSpeaker,
|
||||
retryCall,
|
||||
setAccount,
|
||||
transcribeCall,
|
||||
type Account,
|
||||
type CallDetail,
|
||||
type CallId,
|
||||
type CallListItem,
|
||||
} from '../lib/api'
|
||||
import CallList from '../lib/CallList.svelte'
|
||||
import { formatDetailTime, formatMinutes } from '../lib/format'
|
||||
import StatusPill from '../lib/StatusPill.svelte'
|
||||
import TranscriptView from '../lib/TranscriptView.svelte'
|
||||
|
||||
let calls = $state<CallListItem[]>([])
|
||||
let loaded = $state(false)
|
||||
let listError = $state('')
|
||||
let accounts = $state<Account[]>([])
|
||||
|
||||
let selectedId = $state<CallId | null>(null)
|
||||
let detail = $state<CallDetail | null>(null)
|
||||
let detailError = $state('')
|
||||
let actionError = $state('')
|
||||
let busy = $state(false)
|
||||
let tab = $state<'summary' | 'transcript'>('transcript')
|
||||
|
||||
// Answers can arrive out of order; only the newest request is applied.
|
||||
let listRequest = 0
|
||||
let detailRequest = 0
|
||||
|
||||
async function refreshList() {
|
||||
const request = ++listRequest
|
||||
try {
|
||||
const next = await listCalls()
|
||||
if (request !== listRequest) return
|
||||
const before = calls.find((c) => c.id === selectedId)
|
||||
const after = next.find((c) => c.id === selectedId)
|
||||
const firstLoad = !loaded
|
||||
calls = next
|
||||
loaded = true
|
||||
listError = ''
|
||||
if (firstLoad && selectedId === null && next.length > 0) {
|
||||
select(next[0].id)
|
||||
} else if (selectedId !== null && !after) {
|
||||
clearSelection() // discarded or deleted elsewhere
|
||||
} else if (JSON.stringify(before) !== JSON.stringify(after)) {
|
||||
refreshDetail()
|
||||
}
|
||||
} catch (err) {
|
||||
listError = errorText(err)
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshDetail() {
|
||||
const id = selectedId
|
||||
if (id === null) return
|
||||
const request = ++detailRequest
|
||||
try {
|
||||
const next = await getCall(id)
|
||||
if (request === detailRequest && id === selectedId) {
|
||||
detail = next
|
||||
detailError = ''
|
||||
}
|
||||
} catch (err) {
|
||||
if (request === detailRequest && id === selectedId) detailError = errorText(err)
|
||||
}
|
||||
}
|
||||
|
||||
function select(id: CallId) {
|
||||
if (id === selectedId) return
|
||||
selectedId = id
|
||||
detail = null
|
||||
detailError = ''
|
||||
actionError = ''
|
||||
refreshDetail()
|
||||
}
|
||||
|
||||
function clearSelection() {
|
||||
selectedId = null
|
||||
detail = null
|
||||
detailError = ''
|
||||
actionError = ''
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
const unlisten = [
|
||||
onCallUpdated((id) => {
|
||||
refreshList()
|
||||
if (id === selectedId) refreshDetail()
|
||||
}),
|
||||
onCallEnded(refreshList),
|
||||
onPromptChanged(refreshList),
|
||||
onRecordingState(refreshList),
|
||||
]
|
||||
refreshList()
|
||||
listAccounts()
|
||||
.then((list) => (accounts = list))
|
||||
.catch((err) => (listError = errorText(err)))
|
||||
return () => unlisten.forEach((u) => u.then((off) => off()))
|
||||
})
|
||||
|
||||
/** Runs a command on the shown call; its error is shown inline. */
|
||||
async function run(action: (id: CallId) => Promise<void>, done?: () => void) {
|
||||
if (!detail) return
|
||||
const id = detail.call.id
|
||||
busy = true
|
||||
actionError = ''
|
||||
try {
|
||||
await action(id)
|
||||
done?.()
|
||||
} catch (err) {
|
||||
if (id === selectedId) actionError = errorText(err)
|
||||
} finally {
|
||||
busy = false
|
||||
}
|
||||
}
|
||||
|
||||
const transcribe = () => run(transcribeCall)
|
||||
const retry = () => run(retryCall)
|
||||
const discard = () =>
|
||||
run(discardCall, () => {
|
||||
clearSelection()
|
||||
refreshList()
|
||||
})
|
||||
|
||||
function changeAccount(event: Event) {
|
||||
const select = event.currentTarget as HTMLSelectElement
|
||||
const previous = detail?.call.account_id ?? ''
|
||||
run(async (id) => {
|
||||
try {
|
||||
await setAccount(id, select.value || null)
|
||||
} catch (err) {
|
||||
select.value = previous
|
||||
throw err
|
||||
}
|
||||
await refreshDetail()
|
||||
})
|
||||
}
|
||||
|
||||
async function rename(speakerKey: string, name: string) {
|
||||
if (!detail) return
|
||||
await renameSpeaker(detail.call.id, speakerKey, name)
|
||||
await refreshDetail()
|
||||
}
|
||||
|
||||
/** "Microsoft Teams · heute 10:14 · 32 min" (no duration while recording). */
|
||||
function title(call: CallListItem): string {
|
||||
const parts = [call.app, formatDetailTime(call.started_at)]
|
||||
if (call.status !== 'recording') parts.push(formatMinutes(call.duration_secs))
|
||||
return parts.join(' · ')
|
||||
}
|
||||
|
||||
/** The account list plus the stored account if it is no longer listed. */
|
||||
let accountOptions = $derived.by(() => {
|
||||
const stored = detail?.call.account_id
|
||||
if (!stored || accounts.some((a) => a.id === stored)) return accounts
|
||||
return [...accounts, { id: stored, name: `${stored} (unbekannt)` }]
|
||||
})
|
||||
|
||||
// A failed start (e.g. missing key) also marks the call failed; its
|
||||
// error is then shown once, in the failure box.
|
||||
let shownActionError = $derived(actionError !== detail?.call.error ? actionError : '')
|
||||
</script>
|
||||
|
||||
<main class="main">
|
||||
<aside class="sidebar">
|
||||
<header class="sidebar-header">
|
||||
<h1>Gespräche</h1>
|
||||
<a class="gear" href="#/settings" title="Einstellungen" aria-label="Einstellungen">⚙</a>
|
||||
</header>
|
||||
<div class="list">
|
||||
{#if listError}
|
||||
<p class="error pad">{listError}</p>
|
||||
{/if}
|
||||
{#if loaded}
|
||||
<CallList {calls} {selectedId} onselect={select} />
|
||||
{/if}
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<section class="detail">
|
||||
{#if detail}
|
||||
{@const call = detail.call}
|
||||
<header class="detail-header">
|
||||
<div class="heading">
|
||||
<h1>{title(call)}</h1>
|
||||
<StatusPill status={call.status} interrupted={call.interrupted} />
|
||||
</div>
|
||||
<div class="toolbar">
|
||||
<label class="customer">
|
||||
<span>Kunde:</span>
|
||||
<select value={call.account_id ?? ''} disabled={busy} onchange={changeAccount}>
|
||||
<option value="">— kein Kunde —</option>
|
||||
{#each accountOptions as account (account.id)}
|
||||
<option value={account.id}>{account.name}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</label>
|
||||
<span class="actions">
|
||||
{#if call.status === 'awaiting_decision'}
|
||||
<button class="btn primary" disabled={busy} onclick={transcribe}>Transkribieren</button>
|
||||
<button class="btn danger" disabled={busy} onclick={discard}>Verwerfen</button>
|
||||
{:else if call.status === 'failed'}
|
||||
<button class="btn primary" disabled={busy} onclick={retry}>Erneut versuchen</button>
|
||||
<button class="btn danger" disabled={busy} onclick={discard}>Verwerfen</button>
|
||||
{:else if call.status === 'done'}
|
||||
<span title="Kommt in einer späteren Version">
|
||||
<button class="btn" disabled>In Kundenakte speichern</button>
|
||||
</span>
|
||||
{/if}
|
||||
</span>
|
||||
</div>
|
||||
{#if shownActionError}
|
||||
<p class="error">{shownActionError}</p>
|
||||
{/if}
|
||||
</header>
|
||||
|
||||
<div class="body">
|
||||
{#if call.status === 'recording'}
|
||||
<p class="state rec">● Aufnahme läuft</p>
|
||||
{:else if call.status === 'processing'}
|
||||
<p class="state">wird verarbeitet…</p>
|
||||
{:else if call.status === 'awaiting_decision'}
|
||||
<p class="state">
|
||||
{call.interrupted
|
||||
? 'Noch nicht transkribiert. Die Aufnahme wurde unterbrochen.'
|
||||
: 'Noch nicht transkribiert.'}
|
||||
</p>
|
||||
{:else if call.status === 'failed'}
|
||||
<div class="failure">
|
||||
<strong>Verarbeitung fehlgeschlagen</strong>
|
||||
<div>{call.error ?? 'Unbekannter Fehler'}</div>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="tabs" role="tablist">
|
||||
<button
|
||||
role="tab"
|
||||
aria-selected={tab === 'summary'}
|
||||
class:active={tab === 'summary'}
|
||||
onclick={() => (tab = 'summary')}>Zusammenfassung</button
|
||||
>
|
||||
<button
|
||||
role="tab"
|
||||
aria-selected={tab === 'transcript'}
|
||||
class:active={tab === 'transcript'}
|
||||
onclick={() => (tab = 'transcript')}>Transkript</button
|
||||
>
|
||||
</div>
|
||||
<div class="tab-panel" role="tabpanel">
|
||||
{#if tab === 'summary'}
|
||||
<p class="muted">Die Zusammenfassung kommt in einer späteren Version.</p>
|
||||
{:else}
|
||||
<TranscriptView segments={detail.segments} onrename={rename} />
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{:else if detailError}
|
||||
<p class="error pad">{detailError}</p>
|
||||
{:else if loaded && selectedId === null && calls.length > 0}
|
||||
<p class="muted pad">Gespräch links auswählen.</p>
|
||||
{/if}
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<style>
|
||||
:global(body:has(.main)) {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.main {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(260px, 30%) 1fr;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
background: var(--surface);
|
||||
border-right: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.sidebar-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 14px 12px 10px 16px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.sidebar-header h1 {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.gear {
|
||||
color: var(--muted);
|
||||
font-size: 18px;
|
||||
line-height: 1;
|
||||
padding: 4px 6px;
|
||||
border-radius: 6px;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.gear:hover {
|
||||
color: var(--primary);
|
||||
background: var(--primary-soft);
|
||||
}
|
||||
|
||||
.list {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.detail {
|
||||
min-width: 0;
|
||||
overflow-y: auto;
|
||||
padding: 18px 24px 28px;
|
||||
}
|
||||
|
||||
.pad {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.detail-header {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.heading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px 12px;
|
||||
}
|
||||
|
||||
.heading h1 {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px 16px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.customer {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.customer select {
|
||||
max-width: 260px;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: inline-flex;
|
||||
gap: 8px;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.detail-header .error {
|
||||
margin: 10px 0 0;
|
||||
}
|
||||
|
||||
.state {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.state.rec {
|
||||
color: var(--rec);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.failure {
|
||||
padding: 10px 12px;
|
||||
border-radius: 8px;
|
||||
background: var(--rec-soft);
|
||||
color: var(--rec);
|
||||
}
|
||||
|
||||
.tabs {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.tabs button {
|
||||
padding: 8px 14px;
|
||||
border: none;
|
||||
border-bottom: 2px solid transparent;
|
||||
margin-bottom: -1px;
|
||||
background: none;
|
||||
font: inherit;
|
||||
font-weight: 600;
|
||||
color: var(--muted);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.tabs button.active {
|
||||
color: var(--primary);
|
||||
border-bottom-color: var(--primary);
|
||||
}
|
||||
|
||||
.tab-panel {
|
||||
padding-top: 14px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user