mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-23 14:10:42 -05:00
refac
This commit is contained in:
1 parent
f80331e08c
commit
6db63cddbe
8 files changed
+296
-421
No files matched your search
@@ -245,6 +245,7 @@
|
||||
export let onCollapseEmbedded: (() => void) | null = null;
|
||||
// Pads the header and messages when the host draws the composer flush to its frame.
|
||||
export let embeddedInset = false;
|
||||
export let onRecordedAudio: ((file: File) => unknown) | null = null;
|
||||
export let onNewEmbeddedChat: (() => void | Promise<void>) | null = null;
|
||||
export let onCreateEmbeddedChat:
|
||||
| ((chat: {
|
||||
@@ -6169,7 +6170,7 @@
|
||||
aria-labelledby={fullWidthTabs ? 'chat-panel-main-chat' : undefined}
|
||||
>
|
||||
{#if loading}
|
||||
{#if !fullWidthTabs}
|
||||
{#if !fullWidthTabs && !embeddedCollapsed}
|
||||
<div class="flex items-center justify-center h-full w-full">
|
||||
<Spinner className="size-5" />
|
||||
</div>
|
||||
@@ -6410,6 +6411,7 @@
|
||||
{contextCompactionEnabled}
|
||||
{embedded}
|
||||
autofocus={!embeddedCollapsed}
|
||||
{onRecordedAudio}
|
||||
compactHandler={handleManualCompact}
|
||||
statusHandler={handleStatusCommand}
|
||||
forkHandler={handleForkChat}
|
||||
@@ -6533,6 +6535,7 @@
|
||||
{contextCompactionEnabled}
|
||||
{embedded}
|
||||
autofocus={!embeddedCollapsed}
|
||||
{onRecordedAudio}
|
||||
compactHandler={handleManualCompact}
|
||||
statusHandler={handleStatusCommand}
|
||||
forkHandler={handleForkChat}
|
||||
|
||||
@@ -180,6 +180,8 @@
|
||||
export let contextCompactionEnabled = false;
|
||||
export let embedded = false;
|
||||
export let autofocus = true;
|
||||
// Recorded audio goes to the host when given (note chats), otherwise it is attached to the message.
|
||||
export let onRecordedAudio: ((file: File) => unknown) | null = null;
|
||||
export let callActive = false;
|
||||
export let callEnabled = true;
|
||||
|
||||
@@ -788,6 +790,8 @@
|
||||
|
||||
let loaded = false;
|
||||
let recording = false;
|
||||
let audioRecording = false;
|
||||
let audioRecordingDisplayMedia = false;
|
||||
|
||||
let isComposing = false;
|
||||
// Safari has a bug where compositionend is not triggered correctly #16615
|
||||
@@ -1139,6 +1143,46 @@
|
||||
return !files.some((item) => item.status === 'pending' && item.file instanceof File);
|
||||
};
|
||||
|
||||
const recordedAudioHandler = async (file: File) => {
|
||||
if (onRecordedAudio) await onRecordedAudio(file);
|
||||
else await uploadFileHandler(file);
|
||||
};
|
||||
|
||||
const recordActions = {
|
||||
record: async () => {
|
||||
try {
|
||||
let stream = await navigator.mediaDevices.getUserMedia({ audio: true }).catch((err) => {
|
||||
toast.error(
|
||||
$i18n.t(`Permission denied when accessing microphone: {{error}}`, { error: err })
|
||||
);
|
||||
return null;
|
||||
});
|
||||
if (stream) {
|
||||
stream.getTracks().forEach((track) => track.stop());
|
||||
audioRecordingDisplayMedia = false;
|
||||
audioRecording = true;
|
||||
}
|
||||
stream = null;
|
||||
} catch {
|
||||
toast.error($i18n.t('Permission denied when accessing microphone'));
|
||||
}
|
||||
},
|
||||
captureAudio: () => {
|
||||
audioRecordingDisplayMedia = true;
|
||||
audioRecording = true;
|
||||
},
|
||||
upload: () => {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
input.accept = 'audio/*';
|
||||
input.onchange = async () => {
|
||||
const file = input.files?.[0];
|
||||
if (file) await recordedAudioHandler(file);
|
||||
};
|
||||
input.click();
|
||||
}
|
||||
};
|
||||
|
||||
const uploadFileHandler = async (file, process = true, itemData = {}) => {
|
||||
if ($_user?.role !== 'admin' && !($_user?.permissions?.chat?.file_upload ?? true)) {
|
||||
toast.error($i18n.t('You do not have permission to upload files.'));
|
||||
@@ -1726,6 +1770,7 @@
|
||||
'fork',
|
||||
'status',
|
||||
'comments',
|
||||
'record',
|
||||
'side',
|
||||
'model',
|
||||
'compare',
|
||||
@@ -1773,6 +1818,7 @@
|
||||
onCompact: compactHandler,
|
||||
onStatus: statusHandler,
|
||||
onComments: openComments,
|
||||
onRecord: () => recordActions.record(),
|
||||
onSide: () => {
|
||||
if (!canSide) return;
|
||||
chatTabRequest.set({ parentChatId: chatId, prompt: '' });
|
||||
@@ -2086,36 +2132,56 @@
|
||||
}}
|
||||
/>
|
||||
|
||||
<div class={recording ? '' : 'hidden'}>
|
||||
<VoiceRecording
|
||||
confirmButtonId={inputId === 'chat-input'
|
||||
? 'confirm-recording-button'
|
||||
: `${inputId}-confirm-recording-button`}
|
||||
bind:recording
|
||||
onCancel={async () => {
|
||||
recording = false;
|
||||
<!-- pb-2 matches the form's gap-1.5 + mb-0.5 below the composer card. -->
|
||||
<div class={recording || audioRecording ? 'pb-2' : 'hidden'}>
|
||||
<div class={recording ? '' : 'hidden'}>
|
||||
<VoiceRecording
|
||||
confirmButtonId={inputId === 'chat-input'
|
||||
? 'confirm-recording-button'
|
||||
: `${inputId}-confirm-recording-button`}
|
||||
bind:recording
|
||||
onCancel={async () => {
|
||||
recording = false;
|
||||
|
||||
await tick();
|
||||
focus({ preventScroll: true });
|
||||
}}
|
||||
onConfirm={async (data) => {
|
||||
const { text, filename } = data;
|
||||
await tick();
|
||||
focus({ preventScroll: true });
|
||||
}}
|
||||
onConfirm={async (data) => {
|
||||
const { text, filename } = data;
|
||||
|
||||
recording = false;
|
||||
recording = false;
|
||||
|
||||
await tick();
|
||||
await insertTextAtCursor(`${text}`);
|
||||
await tick();
|
||||
focus({ preventScroll: true });
|
||||
await tick();
|
||||
await insertTextAtCursor(`${text}`);
|
||||
await tick();
|
||||
focus({ preventScroll: true });
|
||||
|
||||
if ($settings?.speechAutoSend ?? false) {
|
||||
dispatch('submit', prompt);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
if ($settings?.speechAutoSend ?? false) {
|
||||
dispatch('submit', prompt);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{#if audioRecording}
|
||||
<VoiceRecording
|
||||
confirmButtonId={`${inputId}-confirm-audio-recording-button`}
|
||||
bind:recording={audioRecording}
|
||||
transcribe={false}
|
||||
displayMedia={audioRecordingDisplayMedia}
|
||||
echoCancellation={false}
|
||||
noiseSuppression={false}
|
||||
onCancel={() => {
|
||||
audioRecording = false;
|
||||
}}
|
||||
onConfirm={async (data) => {
|
||||
audioRecording = false;
|
||||
if (data?.file) await recordedAudioHandler(data.file);
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
<form
|
||||
class="w-full flex flex-col gap-1.5 {recording ? 'hidden' : ''}"
|
||||
class="w-full flex flex-col gap-1.5 {recording || audioRecording ? 'hidden' : ''}"
|
||||
on:submit|preventDefault={() => {
|
||||
dispatch('submit', prompt);
|
||||
}}
|
||||
@@ -2616,6 +2682,7 @@
|
||||
{visionCapableModels}
|
||||
{toolApprovalMode}
|
||||
{onToolApprovalModeChange}
|
||||
{recordActions}
|
||||
{screenCaptureHandler}
|
||||
{inputFilesHandler}
|
||||
uploadFilesHandler={() => {
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
export let onCompact: () => void = () => {};
|
||||
export let onStatus: () => void = () => {};
|
||||
export let onComments: () => void = () => {};
|
||||
export let onRecord: (() => void) | null = null;
|
||||
export let onSide: () => void = () => {};
|
||||
export let onFork: () => void = () => {};
|
||||
export let onModel: () => void = () => {};
|
||||
@@ -127,6 +128,7 @@
|
||||
compactDisabled={isCompactDisabled}
|
||||
canStatus={statusAvailable}
|
||||
canComments={commentsAvailable}
|
||||
canRecord={onRecord !== null}
|
||||
canSide={sideAvailable}
|
||||
canFork={forkAvailable}
|
||||
forkDisabled={isForkDisabled}
|
||||
@@ -155,6 +157,9 @@
|
||||
} else if (type === 'command' && data.id === 'comments') {
|
||||
command({ id: data.id, label: data.id });
|
||||
onComments();
|
||||
} else if (type === 'command' && data.id === 'record') {
|
||||
command({ id: data.id, label: data.id });
|
||||
onRecord?.();
|
||||
} else if (type === 'command' && data.id === 'side') {
|
||||
command({ id: data.id, label: data.id });
|
||||
onSide();
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
import Icon from '$lib/components/chat/FileNav/Icon.svelte';
|
||||
import Plus from '$lib/components/icons/Plus.svelte';
|
||||
import Sparkles from '$lib/components/icons/Sparkles.svelte';
|
||||
import Mic from '$lib/components/icons/Mic.svelte';
|
||||
import { getChatContext } from '$lib/components/chat/context';
|
||||
|
||||
const { chatId } = getChatContext();
|
||||
@@ -35,6 +36,7 @@
|
||||
export let compactDisabled = false;
|
||||
export let canStatus = false;
|
||||
export let canComments = false;
|
||||
export let canRecord = false;
|
||||
export let canSide = false;
|
||||
export let canFork = false;
|
||||
export let forkDisabled = false;
|
||||
@@ -76,6 +78,9 @@
|
||||
...(canComments && 'comments'.startsWith(query.toLowerCase())
|
||||
? [{ type: 'command', data: { id: 'comments' } }]
|
||||
: []),
|
||||
...(canRecord && 'record'.startsWith(query.toLowerCase())
|
||||
? [{ type: 'command', data: { id: 'record' } }]
|
||||
: []),
|
||||
...($visibleControls['chat.model_command'] && 'model'.startsWith(query.toLowerCase())
|
||||
? [{ type: 'command', data: { id: 'model' } }]
|
||||
: []),
|
||||
@@ -377,10 +382,14 @@
|
||||
</span>
|
||||
</button>
|
||||
</Tooltip>
|
||||
{:else if item.data.id === 'comments' || item.data.id === 'side'}
|
||||
{:else if item.data.id === 'comments' || item.data.id === 'side' || item.data.id === 'record'}
|
||||
<button
|
||||
type="button"
|
||||
aria-label={item.data.id === 'side' ? $i18n.t('Side chat') : $i18n.t('Comments')}
|
||||
aria-label={item.data.id === 'side'
|
||||
? $i18n.t('Side chat')
|
||||
: item.data.id === 'record'
|
||||
? $i18n.t('Record')
|
||||
: $i18n.t('Comments')}
|
||||
class="slash-command-row flex items-center gap-2 w-full h-6 px-2 rounded-xl text-[0.8125rem] text-left transition-colors duration-75 hover:bg-base-50/40 dark:hover:bg-base-800/40
|
||||
{commandIdx === selectedIdx ? 'app-interactive-active selected-command-option-button' : ''}"
|
||||
on:mousedown={(e) => e.preventDefault()}
|
||||
@@ -392,13 +401,19 @@
|
||||
<span class="app-icon-muted flex items-center justify-center w-4 shrink-0">
|
||||
{#if item.data.id === 'side'}
|
||||
<Icon name="chat-lines" class="size-3.5" />
|
||||
{:else if item.data.id === 'record'}
|
||||
<Mic className="size-3.5" />
|
||||
{:else}
|
||||
<Annotation className="size-3.5" />
|
||||
{/if}
|
||||
</span>
|
||||
<span class="flex-1 min-w-0 flex items-center gap-2 overflow-hidden">
|
||||
<span class="min-w-0 flex-1 truncate"
|
||||
>{item.data.id === 'side' ? $i18n.t('Side chat') : $i18n.t('Comments')}</span
|
||||
>{item.data.id === 'side'
|
||||
? $i18n.t('Side chat')
|
||||
: item.data.id === 'record'
|
||||
? $i18n.t('Record')
|
||||
: $i18n.t('Comments')}</span
|
||||
>
|
||||
<span class="app-muted max-w-24 shrink-0 truncate text-[0.625rem]">/{item.data.id}</span>
|
||||
</span>
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
import Knowledge from './InputMenu/Knowledge.svelte';
|
||||
import AttachWebpageModal from './AttachWebpageModal.svelte';
|
||||
import GlobeAlt from '$lib/components/icons/GlobeAlt.svelte';
|
||||
import Mic from '$lib/components/icons/Mic.svelte';
|
||||
import CursorArrowRays from '$lib/components/icons/CursorArrowRays.svelte';
|
||||
import CloudArrowUp from '$lib/components/icons/CloudArrowUp.svelte';
|
||||
|
||||
const i18n: any = getContext('i18n');
|
||||
|
||||
@@ -49,6 +52,12 @@
|
||||
export let onClose: Function;
|
||||
export let toolApprovalMode = 'full';
|
||||
export let onToolApprovalModeChange: Function = () => {};
|
||||
// Audio recording actions; the composer decides where the recording goes.
|
||||
export let recordActions: {
|
||||
record: () => void;
|
||||
captureAudio: () => void;
|
||||
upload: () => void;
|
||||
} | null = null;
|
||||
|
||||
export let show = false;
|
||||
export let tab = '';
|
||||
@@ -297,6 +306,23 @@
|
||||
</Tooltip>
|
||||
{/if}
|
||||
|
||||
{#if recordActions}
|
||||
<button
|
||||
role="menuitem"
|
||||
type="button"
|
||||
class="flex w-full gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer hover:bg-base-50/40 dark:hover:bg-base-800/40 rounded-xl text-left"
|
||||
on:click={() => {
|
||||
tab = 'record';
|
||||
}}
|
||||
>
|
||||
<Mic />
|
||||
<div class="flex items-center w-full justify-between">
|
||||
<div>{$i18n.t('Record')}</div>
|
||||
<div class="text-base-500"><ChevronRight /></div>
|
||||
</div>
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
{#if showAddContext}
|
||||
<button
|
||||
role="menuitem"
|
||||
@@ -314,6 +340,35 @@
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
{:else if tab === 'record' && recordActions}
|
||||
<div in:fly={{ x: 20, duration: 150 }}>
|
||||
<button
|
||||
role="menuitem"
|
||||
type="button"
|
||||
class="flex w-full gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer hover:bg-base-50/40 dark:hover:bg-base-800/40 rounded-xl text-left"
|
||||
on:click={() => {
|
||||
tab = '';
|
||||
}}
|
||||
>
|
||||
<ChevronLeft />
|
||||
<div>{$i18n.t('Record')}</div>
|
||||
</button>
|
||||
|
||||
{#each [{ label: 'Record', icon: Mic, action: recordActions.record }, { label: 'Capture Audio', icon: CursorArrowRays, action: recordActions.captureAudio }, { label: 'Upload Audio', icon: CloudArrowUp, action: recordActions.upload }] as item}
|
||||
<button
|
||||
role="menuitem"
|
||||
type="button"
|
||||
class="flex w-full gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer hover:bg-base-50/40 dark:hover:bg-base-800/40 rounded-xl text-left"
|
||||
on:click={() => {
|
||||
show = false;
|
||||
item.action();
|
||||
}}
|
||||
>
|
||||
<svelte:component this={item.icon} className="size-4" />
|
||||
<div class="line-clamp-1">{$i18n.t(item.label)}</div>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{:else if tab === 'attachments'}
|
||||
<div in:fly={{ x: 20, duration: 150 }}>
|
||||
<button
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
import { transcribeAudio } from '$lib/apis/audio';
|
||||
import XMark from '$lib/components/icons/XMark.svelte';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
@@ -19,7 +20,7 @@
|
||||
export let noiseSuppression = true;
|
||||
export let autoGainControl = true;
|
||||
|
||||
export let className = ' p-2.5 w-full max-w-full';
|
||||
export let className = 'w-full max-w-full';
|
||||
|
||||
export let confirmButtonId = 'confirm-recording-button';
|
||||
export let onCancel = () => {};
|
||||
@@ -136,6 +137,10 @@
|
||||
const timeDomainData = new Uint8Array(analyser.fftSize);
|
||||
|
||||
let lastSoundTime = Date.now();
|
||||
// One bar per interval (the loudest frame in it) keeps the waveform scrolling calmly.
|
||||
const VISUALIZER_SAMPLE_MS = 40;
|
||||
let lastSampleTime = 0;
|
||||
let peakLevel = 0;
|
||||
|
||||
const detectSound = () => {
|
||||
const processFrame = () => {
|
||||
@@ -147,16 +152,22 @@
|
||||
|
||||
// Calculate RMS level from time domain data
|
||||
const rmsLevel = calculateRMS(timeDomainData);
|
||||
// Push the calculated decibel level to visualizerData
|
||||
visualizerData.push(normalizeRMS(rmsLevel));
|
||||
peakLevel = Math.max(peakLevel, normalizeRMS(rmsLevel));
|
||||
|
||||
// Ensure visualizerData array stays within the buffer length
|
||||
if (visualizerData.length >= VISUALIZER_BUFFER_LENGTH) {
|
||||
visualizerData.shift();
|
||||
const now = performance.now();
|
||||
if (now - lastSampleTime >= VISUALIZER_SAMPLE_MS) {
|
||||
lastSampleTime = now;
|
||||
visualizerData.push(peakLevel);
|
||||
peakLevel = 0;
|
||||
|
||||
// Ensure visualizerData array stays within the buffer length
|
||||
if (visualizerData.length >= VISUALIZER_BUFFER_LENGTH) {
|
||||
visualizerData.shift();
|
||||
}
|
||||
|
||||
visualizerData = visualizerData;
|
||||
}
|
||||
|
||||
visualizerData = visualizerData;
|
||||
|
||||
// if (domainData.some((value) => value > 0)) {
|
||||
// lastSoundTime = Date.now();
|
||||
// }
|
||||
@@ -257,7 +268,7 @@
|
||||
|
||||
if (document.activeElement === document.body || !document.activeElement?.checkVisibility()) {
|
||||
await tick();
|
||||
document.getElementById(confirmButtonId)?.focus();
|
||||
document.getElementById(confirmButtonId)?.focus({ preventScroll: true });
|
||||
}
|
||||
|
||||
await requestWakeLock();
|
||||
@@ -337,7 +348,7 @@
|
||||
}
|
||||
|
||||
await tick();
|
||||
document.getElementById('chat-input')?.focus();
|
||||
document.getElementById('chat-input')?.focus({ preventScroll: true });
|
||||
|
||||
// Restart the inactivity timeout
|
||||
timeoutId = setTimeout(() => {
|
||||
@@ -475,51 +486,46 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
<!-- Single-row card styled like the chat composer. -->
|
||||
<div
|
||||
bind:this={containerElement}
|
||||
bind:clientWidth={containerWidth}
|
||||
class="{loading
|
||||
? ' bg-base-100/50 dark:bg-base-850/50'
|
||||
: 'bg-indigo-300/10 dark:bg-indigo-500/10 '} rounded-full flex justify-between {className}"
|
||||
class="flex items-center gap-3 overflow-hidden rounded-3xl border border-base-200/60 bg-base-0/80 px-2 py-2 shadow-[0_6px_24px_-4px_rgba(0,0,0,0.1)] backdrop-blur-md dark:border-base-800/40 dark:bg-[oklch(0.24_0_0)]/90 {className}"
|
||||
>
|
||||
<div class="flex items-center mr-1">
|
||||
<button
|
||||
type="button"
|
||||
class="p-1.5
|
||||
<button
|
||||
type="button"
|
||||
class="flex size-[1.875rem] shrink-0 items-center justify-center rounded-full text-base-700 transition hover:bg-base-100/40 dark:text-base-0 dark:hover:bg-base-800/40"
|
||||
aria-label={$i18n.t('Cancel')}
|
||||
on:click={async () => {
|
||||
cancelRecording();
|
||||
onCancel();
|
||||
}}
|
||||
>
|
||||
<XMark className="size-4" />
|
||||
</button>
|
||||
|
||||
{loading
|
||||
? ' bg-base-200 dark:bg-base-700/50'
|
||||
: 'bg-indigo-400/20 text-indigo-600 dark:text-indigo-300 '}
|
||||
|
||||
|
||||
rounded-full"
|
||||
aria-label={$i18n.t('Cancel')}
|
||||
on:click={async () => {
|
||||
cancelRecording();
|
||||
onCancel();
|
||||
}}
|
||||
>
|
||||
<XMark className={'size-4'} />
|
||||
</button>
|
||||
<div class="flex shrink-0 items-center gap-1.5">
|
||||
<span
|
||||
aria-hidden="true"
|
||||
class="size-1.5 rounded-full {loading
|
||||
? 'bg-base-300 dark:bg-base-600'
|
||||
: 'animate-pulse bg-red-500'}"
|
||||
></span>
|
||||
<span class="text-[0.8125rem] tabular-nums text-base-600 dark:text-base-300">
|
||||
{loading ? $i18n.t('Processing...') : formatSeconds(durationSeconds)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="flex flex-1 self-center items-center justify-between ml-2 mx-1 overflow-hidden h-6"
|
||||
dir="rtl"
|
||||
>
|
||||
<div class="flex h-6 min-w-0 flex-1 items-center overflow-hidden" dir="rtl">
|
||||
<div
|
||||
class="flex items-center gap-0.5 h-6 w-full max-w-full overflow-hidden overflow-x-hidden flex-wrap"
|
||||
class="flex h-6 w-full max-w-full flex-wrap items-center gap-[3px] overflow-hidden transition-opacity {loading
|
||||
? 'opacity-30'
|
||||
: ''}"
|
||||
>
|
||||
{#each visualizerData.slice().reverse() as rms}
|
||||
<div class="flex items-center h-full">
|
||||
<div class="flex h-full items-center">
|
||||
<div
|
||||
class="w-[0.125rem] shrink-0
|
||||
|
||||
{loading
|
||||
? ' bg-base-500 dark:bg-base-400 '
|
||||
: 'bg-indigo-500 dark:bg-indigo-400 '}
|
||||
|
||||
inline-block h-full"
|
||||
class="inline-block h-full w-0.5 shrink-0 rounded-full bg-base-800 dark:bg-base-200"
|
||||
style="height: {Math.min(100, Math.max(14, rms * 100))}%;"
|
||||
/>
|
||||
</div>
|
||||
@@ -527,145 +533,30 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex">
|
||||
<div class=" mx-1.5 pr-1 flex justify-center items-center">
|
||||
<div
|
||||
class="text-sm
|
||||
|
||||
|
||||
{loading ? ' text-base-500 dark:text-base-400 ' : ' text-indigo-400 '}
|
||||
font-normal flex-1 mx-auto text-center"
|
||||
{#if loading}
|
||||
<div class="flex size-[1.875rem] shrink-0 items-center justify-center text-base-500">
|
||||
<Spinner className="size-4" />
|
||||
</div>
|
||||
{:else}
|
||||
<button
|
||||
id={confirmButtonId}
|
||||
type="button"
|
||||
aria-label={$i18n.t('Confirm recording')}
|
||||
class="shrink-0 rounded-full bg-base-1000 p-[0.3125rem] text-base-0 transition hover:bg-base-900 dark:bg-base-0 dark:text-base-1000 dark:hover:bg-base-100"
|
||||
on:click={async () => {
|
||||
await confirmRecording();
|
||||
}}
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="2.5"
|
||||
stroke="currentColor"
|
||||
class="size-5"
|
||||
>
|
||||
{formatSeconds(durationSeconds)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center">
|
||||
{#if loading}
|
||||
<div class=" text-base-500 rounded-full cursor-not-allowed">
|
||||
<svg
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="currentColor"
|
||||
><style>
|
||||
.spinner_OSmW {
|
||||
transform-origin: center;
|
||||
animation: spinner_T6mA 0.75s step-end infinite;
|
||||
}
|
||||
@keyframes spinner_T6mA {
|
||||
8.3% {
|
||||
transform: rotate(30deg);
|
||||
}
|
||||
16.6% {
|
||||
transform: rotate(60deg);
|
||||
}
|
||||
25% {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
33.3% {
|
||||
transform: rotate(120deg);
|
||||
}
|
||||
41.6% {
|
||||
transform: rotate(150deg);
|
||||
}
|
||||
50% {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
58.3% {
|
||||
transform: rotate(210deg);
|
||||
}
|
||||
66.6% {
|
||||
transform: rotate(240deg);
|
||||
}
|
||||
75% {
|
||||
transform: rotate(270deg);
|
||||
}
|
||||
83.3% {
|
||||
transform: rotate(300deg);
|
||||
}
|
||||
91.6% {
|
||||
transform: rotate(330deg);
|
||||
}
|
||||
100% {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
</style><g class="spinner_OSmW"
|
||||
><rect x="11" y="1" width="2" height="5" opacity=".14" /><rect
|
||||
x="11"
|
||||
y="1"
|
||||
width="2"
|
||||
height="5"
|
||||
transform="rotate(30 12 12)"
|
||||
opacity=".29"
|
||||
/><rect
|
||||
x="11"
|
||||
y="1"
|
||||
width="2"
|
||||
height="5"
|
||||
transform="rotate(60 12 12)"
|
||||
opacity=".43"
|
||||
/><rect
|
||||
x="11"
|
||||
y="1"
|
||||
width="2"
|
||||
height="5"
|
||||
transform="rotate(90 12 12)"
|
||||
opacity=".57"
|
||||
/><rect
|
||||
x="11"
|
||||
y="1"
|
||||
width="2"
|
||||
height="5"
|
||||
transform="rotate(120 12 12)"
|
||||
opacity=".71"
|
||||
/><rect
|
||||
x="11"
|
||||
y="1"
|
||||
width="2"
|
||||
height="5"
|
||||
transform="rotate(150 12 12)"
|
||||
opacity=".86"
|
||||
/><rect x="11" y="1" width="2" height="5" transform="rotate(180 12 12)" /></g
|
||||
></svg
|
||||
>
|
||||
</div>
|
||||
{:else}
|
||||
<button
|
||||
id={confirmButtonId}
|
||||
type="button"
|
||||
aria-label={$i18n.t('Confirm recording')}
|
||||
class="p-1.5 bg-indigo-500 text-white dark:bg-indigo-500 dark:text-blue-950 rounded-full"
|
||||
on:click={async () => {
|
||||
await confirmRecording();
|
||||
}}
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="2.5"
|
||||
stroke="currentColor"
|
||||
class="size-4"
|
||||
>
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="m4.5 12.75 6 6 9-13.5" />
|
||||
</svg>
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="m4.5 12.75 6 6 9-13.5" />
|
||||
</svg>
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.visualizer {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.visualizer-bar {
|
||||
width: 2px;
|
||||
background-color: #4a5aba; /* or whatever color you need */
|
||||
}
|
||||
</style>
|
||||
@@ -88,15 +88,12 @@
|
||||
import RichTextInput from '../common/RichTextInput.svelte';
|
||||
import { fileUploadsKey } from '../common/RichTextInput/FileAttachment';
|
||||
import Spinner from '../common/Spinner.svelte';
|
||||
import Mic from '../icons/Mic.svelte';
|
||||
import VoiceRecording from '../chat/MessageInput/VoiceRecording.svelte';
|
||||
import DeleteConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
|
||||
|
||||
import AccessButton from '../common/AccessButton.svelte';
|
||||
import ChatParticipants from '../common/ChatParticipants.svelte';
|
||||
|
||||
import FilesOverlay from '../chat/MessageInput/FilesOverlay.svelte';
|
||||
import RecordMenu from './RecordMenu.svelte';
|
||||
import NoteMenu from './Notes/NoteMenu.svelte';
|
||||
import EllipsisHorizontal from '../icons/EllipsisHorizontal.svelte';
|
||||
import Sparkles from '../icons/Sparkles.svelte';
|
||||
@@ -348,9 +345,6 @@
|
||||
let versionIdx = null;
|
||||
let selectedModelId = null;
|
||||
|
||||
let recording = false;
|
||||
let displayMediaRecord = false;
|
||||
|
||||
$: commentsEnabled = !!($config?.features?.enable_comments && $user && note?.id);
|
||||
let currentNoteComments: CommentsRequest | null = null;
|
||||
let linkedComment = '';
|
||||
@@ -381,6 +375,8 @@
|
||||
};
|
||||
let noteChatId = null;
|
||||
let noteChatExpanded = false;
|
||||
// The chat composer records audio; in a note chat it lands in the note instead of the message.
|
||||
$: noteAudioHandler = note?.write_access ? (file: File) => inputFileHandler(file) : null;
|
||||
// Opening a note lands in its body; the docked chat composer no longer takes focus.
|
||||
let focusedNoteId = '';
|
||||
const focusOpenedNote = (instance) => {
|
||||
@@ -1260,7 +1256,7 @@ ${content}
|
||||
show={!!currentNoteComments}
|
||||
align="end"
|
||||
maxHeight="min(36rem, calc(100dvh - 6rem))"
|
||||
contentClass="w-[min(24rem,calc(100vw-2rem))] h-[min(36rem,calc(100dvh-6rem))] rounded-2xl border border-base-100 dark:border-base-800 bg-base-0 dark:bg-base-900 shadow-lg overflow-hidden! z-50"
|
||||
contentClass="w-[min(24rem,calc(100vw-2rem))] h-[min(36rem,calc(100dvh-6rem))] rounded-3xl border border-base-100/50 dark:border-base-800/50 bg-base-0 dark:bg-base-900 shadow-lg overflow-hidden! z-50"
|
||||
onOpenChange={(open) => {
|
||||
if (!open) currentNoteComments = null;
|
||||
else currentNoteComments ??= { resource_type: 'note', resource_id: note.id };
|
||||
@@ -1285,66 +1281,6 @@ ${content}
|
||||
</Dropdown>
|
||||
{/if}
|
||||
|
||||
{#if note?.write_access}
|
||||
<RecordMenu
|
||||
onRecord={async () => {
|
||||
displayMediaRecord = false;
|
||||
|
||||
try {
|
||||
let stream = await navigator.mediaDevices
|
||||
.getUserMedia({ audio: true })
|
||||
.catch(function (err) {
|
||||
toast.error(
|
||||
$i18n.t(`Permission denied when accessing microphone: {{error}}`, {
|
||||
error: err
|
||||
})
|
||||
);
|
||||
return null;
|
||||
});
|
||||
|
||||
if (stream) {
|
||||
recording = true;
|
||||
const tracks = stream.getTracks();
|
||||
tracks.forEach((track) => track.stop());
|
||||
}
|
||||
stream = null;
|
||||
} catch {
|
||||
toast.error($i18n.t('Permission denied when accessing microphone'));
|
||||
}
|
||||
}}
|
||||
onCaptureAudio={async () => {
|
||||
displayMediaRecord = true;
|
||||
|
||||
recording = true;
|
||||
}}
|
||||
onUpload={async () => {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
input.accept = 'audio/*';
|
||||
input.multiple = false;
|
||||
input.click();
|
||||
|
||||
input.onchange = async (e) => {
|
||||
const files = e.target.files;
|
||||
|
||||
if (files && files.length > 0) {
|
||||
await inputFileHandler(files[0]);
|
||||
}
|
||||
};
|
||||
}}
|
||||
>
|
||||
<Tooltip content={$i18n.t('Record')} placement="top">
|
||||
<button
|
||||
type="button"
|
||||
class="p-1 bg-transparent hover:bg-base-0/5 transition rounded-lg"
|
||||
aria-label={$i18n.t('Record')}
|
||||
>
|
||||
<Mic className="size-4" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
</RecordMenu>
|
||||
{/if}
|
||||
|
||||
<NoteMenu
|
||||
bind:autoFormat
|
||||
showAutoFormat={note?.write_access ?? false}
|
||||
@@ -1667,7 +1603,7 @@ ${content}
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{#if note && !noteChatLoading && (noteChatId || noteChatDraftKey)}
|
||||
{#if note}
|
||||
<!-- The composer keeps its position; expanding only grows the conversation above it. -->
|
||||
<div class="pointer-events-none absolute inset-x-0 bottom-0 z-30 flex flex-col">
|
||||
{#if !noteChatExpanded}
|
||||
@@ -1702,48 +1638,51 @@ ${content}
|
||||
</button>
|
||||
{/if}
|
||||
<div class="flex min-h-0 flex-1 flex-col">
|
||||
{#key note.id}
|
||||
<Chat
|
||||
embedded={true}
|
||||
chatIdProp={noteChatId ?? ''}
|
||||
embeddedChats={noteChats}
|
||||
embeddedDraftKey={noteChatDraftKey}
|
||||
suggestedPrompts={noteChatSuggestedPrompts}
|
||||
selectedText={selectedContent?.text ?? ''}
|
||||
notePageId={activePageId}
|
||||
noteFiles={noteAttachmentFiles}
|
||||
embeddedCollapsed={!noteChatExpanded}
|
||||
embeddedInset
|
||||
onCollapseEmbedded={() => (noteChatExpanded = false)}
|
||||
onBeforeNoteSubmit={async () => {
|
||||
noteChatExpanded = true;
|
||||
await flushActivePage();
|
||||
}}
|
||||
onInsertToNote={note?.write_access ? insertHandler : null}
|
||||
onNewEmbeddedChat={createNoteChat}
|
||||
onCreateEmbeddedChat={createNoteChatOnFirstMessage}
|
||||
onSelectEmbeddedChat={(chatId) => {
|
||||
if (!chatId || chatId === noteChatId) return;
|
||||
noteChatId = chatId;
|
||||
noteChatDraftKey = '';
|
||||
}}
|
||||
onDeleteEmbeddedChat={deleteNoteChat}
|
||||
onEmbeddedChatTitle={(chatId, title) => {
|
||||
noteChats = noteChats.map((chat) =>
|
||||
chat.id === chatId
|
||||
? {
|
||||
...chat,
|
||||
title,
|
||||
chat: {
|
||||
...(chat.chat ?? {}),
|
||||
title
|
||||
{#if !noteChatLoading && (noteChatId || noteChatDraftKey)}
|
||||
{#key note.id}
|
||||
<Chat
|
||||
embedded={true}
|
||||
chatIdProp={noteChatId ?? ''}
|
||||
embeddedChats={noteChats}
|
||||
embeddedDraftKey={noteChatDraftKey}
|
||||
suggestedPrompts={noteChatSuggestedPrompts}
|
||||
selectedText={selectedContent?.text ?? ''}
|
||||
notePageId={activePageId}
|
||||
noteFiles={noteAttachmentFiles}
|
||||
embeddedCollapsed={!noteChatExpanded}
|
||||
embeddedInset
|
||||
onRecordedAudio={noteAudioHandler}
|
||||
onCollapseEmbedded={() => (noteChatExpanded = false)}
|
||||
onBeforeNoteSubmit={async () => {
|
||||
noteChatExpanded = true;
|
||||
await flushActivePage();
|
||||
}}
|
||||
onInsertToNote={note?.write_access ? insertHandler : null}
|
||||
onNewEmbeddedChat={createNoteChat}
|
||||
onCreateEmbeddedChat={createNoteChatOnFirstMessage}
|
||||
onSelectEmbeddedChat={(chatId) => {
|
||||
if (!chatId || chatId === noteChatId) return;
|
||||
noteChatId = chatId;
|
||||
noteChatDraftKey = '';
|
||||
}}
|
||||
onDeleteEmbeddedChat={deleteNoteChat}
|
||||
onEmbeddedChatTitle={(chatId, title) => {
|
||||
noteChats = noteChats.map((chat) =>
|
||||
chat.id === chatId
|
||||
? {
|
||||
...chat,
|
||||
title,
|
||||
chat: {
|
||||
...(chat.chat ?? {}),
|
||||
title
|
||||
}
|
||||
}
|
||||
}
|
||||
: chat
|
||||
);
|
||||
}}
|
||||
/>
|
||||
{/key}
|
||||
: chat
|
||||
);
|
||||
}}
|
||||
/>
|
||||
{/key}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1754,31 +1693,5 @@ ${content}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{#if recording}
|
||||
<div class="absolute z-50 bottom-0 right-0 p-3.5 flex select-none">
|
||||
<div class="flex-1 w-full">
|
||||
<VoiceRecording
|
||||
bind:recording
|
||||
className="p-1 w-full max-w-full"
|
||||
transcribe={false}
|
||||
displayMedia={displayMediaRecord}
|
||||
echoCancellation={false}
|
||||
noiseSuppression={false}
|
||||
onCancel={() => {
|
||||
recording = false;
|
||||
displayMediaRecord = false;
|
||||
}}
|
||||
onConfirm={(data) => {
|
||||
if (data?.file) {
|
||||
inputFileHandler(data?.file);
|
||||
}
|
||||
|
||||
recording = false;
|
||||
displayMediaRecord = false;
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,74 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { createEventDispatcher, getContext } from 'svelte';
|
||||
|
||||
import Dropdown from '$lib/components/common/Dropdown.svelte';
|
||||
import DropdownMenu from '$lib/components/common/DropdownMenu.svelte';
|
||||
import Mic from '../icons/Mic.svelte';
|
||||
import CursorArrowRays from '../icons/CursorArrowRays.svelte';
|
||||
import CloudArrowUp from '../icons/CloudArrowUp.svelte';
|
||||
|
||||
const i18n = getContext('i18n');
|
||||
|
||||
export let show = false;
|
||||
export let className = 'max-w-[10.625rem]';
|
||||
|
||||
export let onRecord = () => {};
|
||||
export let onCaptureAudio = () => {};
|
||||
export let onUpload = () => {};
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
</script>
|
||||
|
||||
<Dropdown
|
||||
bind:show
|
||||
align="end"
|
||||
sideOffset={8}
|
||||
onOpenChange={(state) => {
|
||||
dispatch('change', state);
|
||||
}}
|
||||
>
|
||||
<slot />
|
||||
|
||||
<div slot="content">
|
||||
<DropdownMenu className="min-w-[10.625rem] ">
|
||||
<button
|
||||
class="flex h-[1.6875rem] w-full items-center gap-2 rounded-xl bg-transparent px-2 text-[0.8125rem] transition hover:text-base-900 dark:hover:text-base-100"
|
||||
on:click={async () => {
|
||||
onRecord();
|
||||
show = false;
|
||||
}}
|
||||
>
|
||||
<div class="self-center">
|
||||
<Mic className="size-3.5" strokeWidth="2" />
|
||||
</div>
|
||||
<div class=" self-center truncate">{$i18n.t('Record')}</div>
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="flex h-[1.6875rem] w-full items-center gap-2 rounded-xl bg-transparent px-2 text-[0.8125rem] transition hover:text-base-900 dark:hover:text-base-100"
|
||||
on:click={() => {
|
||||
onCaptureAudio();
|
||||
show = false;
|
||||
}}
|
||||
>
|
||||
<div class="self-center">
|
||||
<CursorArrowRays className="size-3.5" strokeWidth="2" />
|
||||
</div>
|
||||
<div class=" self-center truncate">{$i18n.t('Capture Audio')}</div>
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="flex h-[1.6875rem] w-full items-center gap-2 rounded-xl bg-transparent px-2 text-[0.8125rem] transition hover:text-base-900 dark:hover:text-base-100"
|
||||
on:click={() => {
|
||||
onUpload();
|
||||
show = false;
|
||||
}}
|
||||
>
|
||||
<div class="self-center">
|
||||
<CloudArrowUp className="size-3.5" strokeWidth="2" />
|
||||
</div>
|
||||
<div class=" self-center truncate">{$i18n.t('Upload Audio')}</div>
|
||||
</button>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</Dropdown>
|
||||
Reference in new issue
Block a user