diff --git a/src/lib/components/chat/ChatTabs.svelte b/src/lib/components/chat/ChatTabs.svelte index 5b874a2948..5da2186a32 100644 --- a/src/lib/components/chat/ChatTabs.svelte +++ b/src/lib/components/chat/ChatTabs.svelte @@ -69,6 +69,7 @@ import { fileIconName } from './FileNav/fileIcon'; import UntitledFile from './ChatTabs/UntitledFile.svelte'; import QuickOpen from './ChatTabs/QuickOpen.svelte'; + import VoiceNote from './ChatTabs/VoiceNote.svelte'; import Browser from './ChatTabs/Browser.svelte'; import Desktop from './ChatTabs/Desktop.svelte'; import XTerminal from './XTerminal.svelte'; @@ -167,6 +168,29 @@ let navigationApproved = false; let selectedConnection: TerminalConnection | null = null; let showQuickOpen = false; + let voiceNote: VoiceNote; + let voiceNoteTarget: { + connection: TerminalConnection; + chatId: string | null; + directory?: string; + } | null = null; + $: canVoiceNote = terminalFilesAvailable && !!$user; + $: canTranscribeVoiceNote = $user?.role === 'admin' || ($user?.permissions?.chat?.stt ?? true); + const openVoiceNote = () => { + if (voiceNoteTarget) { + voiceNote?.finishRecording(); + return; + } + if (!canVoiceNote || !selectedConnection || !$user) return; + voiceNoteTarget = { + connection: selectedConnection, + chatId, + directory: + contextTab?.terminalId === selectedConnection.selector + ? terminalContext?.currentDirectory + : undefined + }; + }; $: if (!terminalFilesAvailable) showQuickOpen = false; let terminalEnabled = false; let desktopEnabled = false; @@ -740,6 +764,9 @@ const shortcut = matchKeybinding(event); let action: (() => void) | undefined; switch (shortcut) { + case Shortcut.VOICE_NOTE: + if (voiceNoteTarget || canVoiceNote) action = openVoiceNote; + break; case Shortcut.QUICK_OPEN: if (terminalFilesAvailable && selectedConnection) action = () => { @@ -839,20 +866,20 @@ chatId; pruneTabs(); } + $: selectedConnection = + terminalFilesAvailable && mounted + ? resolveTerminalConnection( + $selectedTerminalId, + $terminalServers ?? [], + directTerminals, + localStorage.token ?? '' + ) + : null; const checkTerminal = async () => { const version = ++featureVersion; terminalEnabled = false; desktopEnabled = false; browserEnabled = false; - selectedConnection = - terminalFilesAvailable && mounted - ? resolveTerminalConnection( - $selectedTerminalId, - $terminalServers ?? [], - directTerminals, - localStorage.token ?? '' - ) - : null; if (!selectedConnection) return; try { const result = await terminalRequest<{ @@ -868,11 +895,7 @@ } }; $: { - terminalFilesAvailable; - $selectedTerminalId; - $terminalServers; - $settings; - mounted; + selectedConnection; chatId; void checkTerminal(); } @@ -1077,6 +1100,19 @@ {/if} +{#if voiceNoteTarget} + {@const target = voiceNoteTarget} + { + voiceNoteTarget = null; + }} + onsaved={(path) => openFile(path, target.connection.selector)} + /> +{/if} + {#if showQuickOpen && terminalFilesAvailable && selectedConnection} {#key `${selectedConnection.selector}:${chatId}`} {$i18n.t('Desktop')}{/if} + {#if canVoiceNote} + + {/if} {#each newTabViews as view} + + {#if recording}{duration(elapsed)}{/if} + + {:else} +
+ {#if draft} +
+ + +
+

+ {draft.directory} +

+ + {#if draft.transcript}{/if} +
+ + {duration(draft.duration)} +
+ {#if transcriptionAvailable}{/if} + +
+
+ + +
+
+ {:else} +
+ + +
+ {/if} + {#if error}{/if} +
+ {/if} + + + diff --git a/src/lib/i18n/locales/en-US/translation.json b/src/lib/i18n/locales/en-US/translation.json index e60cbabe51..6bae5a7d8e 100644 --- a/src/lib/i18n/locales/en-US/translation.json +++ b/src/lib/i18n/locales/en-US/translation.json @@ -4543,5 +4543,17 @@ "Zoom in": "", "Zoom out": "", "Searching...": "Searching...", - "Type a file name or path to search.": "Type a file name or path to search." + "Type a file name or path to search.": "Type a file name or path to search.", + "Voice Note": "Voice Note", + "Use arrow keys to move.": "Use arrow keys to move.", + "Record again": "Record again", + "Transcribe": "Transcribe", + "Transcript": "Transcript", + "Processing...": "Processing...", + "Could not load the recording folder.": "Could not load the recording folder.", + "No audio was recorded.": "No audio was recorded.", + "Could not transcribe the recording.": "Could not transcribe the recording.", + "Could not save the voice note. Retry or download the recording.": "Could not save the voice note. Retry or download the recording.", + "settings.personal.shortcuts.voiceNote.label": "Voice Note", + "Stop recording": "Stop recording" } diff --git a/src/lib/shortcuts.ts b/src/lib/shortcuts.ts index 9e73d4beae..58c02a019a 100644 --- a/src/lib/shortcuts.ts +++ b/src/lib/shortcuts.ts @@ -19,6 +19,7 @@ type ShortcutRegistry = { export enum Shortcut { // Workspace tabs QUICK_OPEN = 'quickOpen', + VOICE_NOTE = 'voiceNote', OPEN_FILES = 'openFiles', OPEN_DESKTOP = 'openDesktop', NEW_CHAT_TAB = 'newChatTab', @@ -73,6 +74,7 @@ export enum Shortcut { export const CONFIGURABLE_SHORTCUTS = [ Shortcut.QUICK_OPEN, + Shortcut.VOICE_NOTE, Shortcut.OPEN_FILES, Shortcut.OPEN_DESKTOP, Shortcut.NEW_CHAT_TAB, @@ -114,6 +116,7 @@ export type KeybindingsMap = Record; export const DEFAULT_KEYBINDINGS: KeybindingsMap = { [Shortcut.QUICK_OPEN]: 'Cmd+P', + [Shortcut.VOICE_NOTE]: 'Cmd+Alt+M', [Shortcut.OPEN_FILES]: 'Cmd+Shift+E', [Shortcut.OPEN_DESKTOP]: 'Cmd+Alt+D', [Shortcut.NEW_CHAT_TAB]: 'Cmd+Alt+O', @@ -260,6 +263,12 @@ export function matchKeybinding(event: KeyboardEvent): ConfigurableShortcut | nu } export const shortcuts: ShortcutRegistry = { + [Shortcut.VOICE_NOTE]: { + name: (t) => t('settings.personal.shortcuts.voiceNote.label'), + keys: [], + category: 'Tabs', + configurable: true + }, [Shortcut.QUICK_OPEN]: { name: (t) => t('settings.personal.shortcuts.quickOpen.label'), keys: [],