- the backend URL is no longer a setting: one constant per build (release/dev) in src-tauri/src/backend.rs; Settings shows the server read-only; an old backend_url in settings.json is ignored - the stored key records the backend it was created for; a key of another backend is discarded before any use and never stored - a refused key is discarded only if it still is the stored one - the keyring is never called while the settings are locked - one upload per call at a time, also visible after a view switch - opener plugin without its link-click script (it also ran in the remote login page); a login error says to reload the login page Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
225 lines
8.8 KiB
TypeScript
225 lines
8.8 KiB
TypeScript
// Typed wrappers around the Tauri commands and events of the app shell.
|
|
|
|
import { invoke } from '@tauri-apps/api/core'
|
|
import { listen, type UnlistenFn } from '@tauri-apps/api/event'
|
|
|
|
export type CallId = number
|
|
|
|
export interface Settings {
|
|
allowlist: string[]
|
|
mic_device: string | null
|
|
output_device: string | null
|
|
language: string
|
|
deepscript_model: string
|
|
retention_days: number
|
|
autostart: boolean
|
|
start_after_secs: number
|
|
end_after_secs: number
|
|
/** Whose backend key is stored; set by the app at login. */
|
|
backend_username: string | null
|
|
/** When the stored backend key expires (RFC 3339); set by the app. */
|
|
backend_key_expires_at: string | null
|
|
/** The backend the stored key belongs to; set by the app. */
|
|
backend_key_base_url: string | null
|
|
}
|
|
|
|
/** The backend this build talks to (fixed per build, not a setting). */
|
|
export interface BackendServer {
|
|
base_url: string
|
|
/** Where the admin manages their keys. */
|
|
keys_url: string
|
|
}
|
|
|
|
/** Login status for the settings, checked with the backend. */
|
|
export interface BackendStatus {
|
|
logged_in: boolean
|
|
username: string | null
|
|
/** RFC 3339. */
|
|
expires_at: string | null
|
|
/** `false` if the key could not be checked; username and expiry are then the stored ones. */
|
|
reachable: boolean
|
|
}
|
|
|
|
export type Service = 'deepscript'
|
|
|
|
export interface DeviceInfo {
|
|
id: string
|
|
name: string
|
|
}
|
|
|
|
export interface Devices {
|
|
inputs: DeviceInfo[]
|
|
outputs: DeviceInfo[]
|
|
}
|
|
|
|
export interface DeviceLevels {
|
|
mic: number
|
|
out: number
|
|
}
|
|
|
|
export type Track = 'mic' | 'out'
|
|
|
|
export type RecordingState =
|
|
| { state: 'idle' }
|
|
| { state: 'recording'; call_id: CallId; app: string; started_at: string }
|
|
|
|
/** What the end-of-call prompt shows about a call. Times are RFC 3339. */
|
|
export interface CallBrief {
|
|
id: CallId
|
|
app: string
|
|
started_at: string
|
|
ended_at: string | null
|
|
duration_secs: number
|
|
}
|
|
|
|
/** The call the end-of-call prompt shows, and how many wait behind it. */
|
|
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
|
|
/** The name the user gave the call, if any. */
|
|
title: string | null
|
|
/** The CRM's id of the transcript, from its last upload. */
|
|
crm_transcript_id: string | null
|
|
/** When the transcript was last uploaded (RFC 3339). */
|
|
uploaded_at: string | null
|
|
}
|
|
|
|
/** A transcript line; `speaker_key` is "me" or "remote:<n>". */
|
|
export interface SegmentView {
|
|
speaker_key: string
|
|
label: string
|
|
start: number
|
|
end: number
|
|
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; transcribed_at: string | null }
|
|
/** The transcript with speaker merges applied. */
|
|
segments: SegmentView[]
|
|
/** Renamed speakers by key. */
|
|
speaker_names: Record<string, string>
|
|
merges: SpeakerMerge[]
|
|
/** The transcript is being uploaded right now. */
|
|
uploading: boolean
|
|
}
|
|
|
|
/** A newer version the release feed offers. */
|
|
export interface UpdateInfo {
|
|
version: string
|
|
/** `false` while a recording runs or a call is being processed. */
|
|
can_install: boolean
|
|
}
|
|
|
|
/** Download progress of an update; `total` is `null` if unknown. */
|
|
export interface UpdateProgress {
|
|
downloaded: number
|
|
total: number | null
|
|
}
|
|
|
|
export interface Levels {
|
|
mic: number
|
|
out: number
|
|
failed_tracks: Track[]
|
|
}
|
|
|
|
export const getSettings = () => invoke<Settings>('get_settings')
|
|
export const saveSettings = (settings: Settings) => invoke<void>('save_settings', { settings })
|
|
export const setApiKey = (service: Service, key: string) =>
|
|
invoke<void>('set_api_key', { service, key })
|
|
export const hasApiKey = (service: Service) => invoke<boolean>('has_api_key', { service })
|
|
export const listDevices = () => invoke<Devices>('list_devices')
|
|
export const testDevices = () => invoke<DeviceLevels>('test_devices')
|
|
export const getRecordingState = () => invoke<RecordingState>('get_recording_state')
|
|
export const startManualRecording = () => invoke<CallId>('start_manual_recording')
|
|
/** Shows/focuses the floating recorder window instead of starting another recording. */
|
|
export const showRecorder = () => invoke<void>('show_recorder')
|
|
export const stopRecording = () => invoke<void>('stop_recording')
|
|
export const discardCurrentRecording = () => invoke<void>('discard_current_recording')
|
|
export const getPendingPrompt = () => invoke<PendingPrompt | null>('get_pending_prompt')
|
|
export const getCallBrief = (id: CallId) => invoke<CallBrief>('get_call_brief', { id })
|
|
export const transcribeCall = (id: CallId) => invoke<void>('transcribe_call', { id })
|
|
export const retryCall = (id: CallId) => invoke<void>('retry_call', { id })
|
|
export const discardCall = (id: CallId) => invoke<void>('discard_call', { id })
|
|
export const listCalls = () => invoke<CallListItem[]>('list_calls')
|
|
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 backendServer = () => invoke<BackendServer>('backend_server')
|
|
export const backendStatus = () => invoke<BackendStatus>('backend_status')
|
|
/** Resolves once the login window created a key; rejects if it was closed or failed. */
|
|
export const backendLogin = () => invoke<void>('backend_login')
|
|
export const backendLogout = () => invoke<void>('backend_logout')
|
|
/** Opens the backend's key management page in the system browser. */
|
|
export const openBackendKeysPage = () => invoke<void>('open_backend_keys_page')
|
|
/** Logs in first if needed; resolves once the CRM has the transcript. */
|
|
export const uploadTranscript = (id: CallId) => invoke<void>('upload_transcript', { id })
|
|
export const getUpdate = () => invoke<UpdateInfo | null>('get_update')
|
|
/** Resolves only on failure: on success the app restarts. */
|
|
export const installUpdate = () => invoke<void>('install_update')
|
|
|
|
export const onRecordingState = (handler: (state: RecordingState) => void): Promise<UnlistenFn> =>
|
|
listen<RecordingState>('recording-state', (event) => handler(event.payload))
|
|
export const onCallEnded = (handler: (id: CallId) => void): Promise<UnlistenFn> =>
|
|
listen<{ id: CallId }>('call-ended', (event) => handler(event.payload.id))
|
|
/** The prompt queue changed (a call was decided elsewhere). */
|
|
export const onPromptChanged = (handler: () => void): Promise<UnlistenFn> =>
|
|
listen<null>('prompt-changed', () => handler())
|
|
/** A call's status changed (processing started, done or failed). */
|
|
export const onCallUpdated = (handler: (id: CallId) => void): Promise<UnlistenFn> =>
|
|
listen<{ id: CallId }>('call-updated', (event) => handler(event.payload.id))
|
|
/** The backend login changed (logged in, logged out, key discarded). */
|
|
export const onBackendChanged = (handler: () => void): Promise<UnlistenFn> =>
|
|
listen<null>('backend-changed', () => handler())
|
|
/** Creating the key failed; the login window stays open for another try. */
|
|
export const onBackendLoginError = (handler: (message: string) => void): Promise<UnlistenFn> =>
|
|
listen<{ message: string }>('backend-login-error', (event) => handler(event.payload.message))
|
|
export const onUpdateAvailable = (handler: (info: UpdateInfo) => void): Promise<UnlistenFn> =>
|
|
listen<UpdateInfo>('update-available', (event) => handler(event.payload))
|
|
export const onUpdateProgress = (
|
|
handler: (progress: UpdateProgress) => void,
|
|
): Promise<UnlistenFn> =>
|
|
listen<UpdateProgress>('update-progress', (event) => handler(event.payload))
|
|
export const onLevels = (handler: (levels: Levels) => void): Promise<UnlistenFn> =>
|
|
listen<Levels>('levels', (event) => handler(event.payload))
|
|
|
|
/** Maps an rms level (0..1) to a meter fill (0..1) on a -60..0 dB scale. */
|
|
export function meterFill(level: number): number {
|
|
if (level <= 0) return 0
|
|
const db = 20 * Math.log10(level)
|
|
return Math.min(1, Math.max(0, (db + 60) / 60))
|
|
}
|
|
|
|
/** Error text of a rejected command. */
|
|
export function errorText(err: unknown): string {
|
|
return typeof err === 'string' ? err : err instanceof Error ? err.message : String(err)
|
|
}
|