bug fixes, and performance improvements, and drawer

This commit is contained in:
Zoe
2026-09-27 18:44:51 -05:00
parent d48d8163a7
commit 2b9f8d64d7
52 changed files with 4913 additions and 778 deletions
+151 -98
View File
@@ -4,11 +4,17 @@ import { computed, onMounted, ref, watch, onUnmounted, nextTick, type Ref } from
import type { ModelWithProvider, ProviderWithModels } from '~/composables/useModels';
import type { Agent } from '~/composables/useAgents';
import type FileSelector from './FileSelector.vue';
import { getComposerHeight } from '~/utils/composer-size';
const { allModels } = await useModels();
const { updateAgent, patchAgentLocally } = await useAgents();
const inputHeight: Ref<string> = ref('auto');
const isDrawerOpen = useCookie<boolean>("chat:tools-drawer", { default: () => false });
watch(isDrawerOpen, () => {
emit("resize");
});
const inputHeight: Ref<string> = ref('48px');
const fileSelectorRef = ref<InstanceType<typeof FileSelector> | null>(null);
const inputRef = ref<HTMLTextAreaElement | null>(null);
let tempInput = '';
@@ -303,47 +309,57 @@ const handleWindowKeyDown = async (event: KeyboardEvent) => {
};
const mirrorRef = ref<HTMLDivElement | null>(null);
const MIRROR_PROPERTIES = [
'box-sizing', 'font-family', 'font-size', 'font-weight', 'font-style',
'line-height', 'letter-spacing', 'word-spacing', 'text-align', 'text-indent',
'text-transform', 'tab-size', 'padding-top', 'padding-bottom', 'padding-left',
'padding-right', 'border-top-width', 'border-bottom-width', 'border-left-width',
'border-right-width', 'border-style', 'white-space', 'overflow-wrap', 'word-break',
] as const;
let sizingRaf: number | undefined;
let sizingObserver: ResizeObserver | undefined;
let typographyObserver: MutationObserver | undefined;
let sizingDirty = true;
let mirrorWidth = '';
let lineHeight = 24;
let padding = 0;
let borders = 0;
let borderBox = true;
const resizeTextArea = () => {
const textarea = inputRef.value;
const mirror = mirrorRef.value;
if (!textarea || !mirror) return;
if (import.meta.server || sizingRaf !== undefined) return;
sizingRaf = requestAnimationFrame(() => {
sizingRaf = undefined;
const textarea = inputRef.value;
const mirror = mirrorRef.value;
if (!textarea || !mirror) return;
emit('resize');
nextTick().then(() => {
mirror.textContent = (textarea.value || '\u200b') + '\n';
if (sizingDirty) {
// Finish style reads before changing the isolated measurement box.
const styles = getComputedStyle(textarea);
const values = MIRROR_PROPERTIES.map(property => styles.getPropertyValue(property));
mirrorWidth = styles.width;
lineHeight = Number.parseFloat(styles.lineHeight) || Number.parseFloat(styles.fontSize) * 1.2;
padding = Number.parseFloat(styles.paddingTop) + Number.parseFloat(styles.paddingBottom);
borders = Number.parseFloat(styles.borderTopWidth) + Number.parseFloat(styles.borderBottomWidth);
borderBox = styles.boxSizing === 'border-box';
MIRROR_PROPERTIES.forEach((property, index) => mirror.style.setProperty(property, values[index]!));
mirror.style.width = mirrorWidth;
sizingDirty = false;
}
const textareaStyles = getComputedStyle(textarea);
mirror.style.width = textareaStyles.width;
mirror.style.fontFamily = textareaStyles.fontFamily;
mirror.style.fontSize = textareaStyles.fontSize;
mirror.style.lineHeight = textareaStyles.lineHeight;
mirror.style.letterSpacing = textareaStyles.letterSpacing;
mirror.style.wordSpacing = textareaStyles.wordSpacing;
mirror.style.textAlign = textareaStyles.textAlign;
mirror.style.paddingTop = textareaStyles.paddingTop;
mirror.style.paddingBottom = textareaStyles.paddingBottom;
mirror.style.paddingLeft = textareaStyles.paddingLeft;
mirror.style.paddingRight = textareaStyles.paddingRight;
mirror.style.borderTopWidth = textareaStyles.borderTopWidth;
mirror.style.borderBottomWidth = textareaStyles.borderBottomWidth;
mirror.style.borderLeftWidth = textareaStyles.borderLeftWidth;
mirror.style.borderRightWidth = textareaStyles.borderRightWidth;
mirror.style.whiteSpace = 'pre-wrap';
mirror.style.wordWrap = 'break-word';
mirror.style.overflow = 'hidden';
// Preserve the final empty line without adding an extra line to ordinary text.
mirror.textContent = textarea.value + '\u200b';
const height = `${getComposerHeight(mirror.scrollHeight, lineHeight, padding, borders, borderBox)}px`;
if (height === inputHeight.value) return;
const lineHeight = 24;
const minLines = 2;
const maxLines = 10;
const minHeight = minLines * lineHeight;
const maxHeight = maxLines * lineHeight;
const height = Math.min(Math.max(mirror.scrollHeight, minHeight), maxHeight);
inputHeight.value = `${height}px`;
// Capture bottom-follow intent before applying the new height.
emit('resize');
inputHeight.value = height;
});
};
watch(textAreaValue, resizeTextArea, { immediate: true });
watch(textAreaValue, resizeTextArea, { flush: 'post' });
let hasCommandKey = false;
if (import.meta.server) {
@@ -357,41 +373,51 @@ onBeforeMount(() => {
tempInput = (document.getElementById('chat') as HTMLInputElement)?.value ?? '';
});
let resizeRafId: number | undefined;
const handleWindowResize = () => {
if (resizeRafId) return;
resizeRafId = requestAnimationFrame(() => {
resizeRafId = undefined;
resizeTextArea();
});
}
sizingDirty = true;
resizeTextArea();
};
onMounted(() => {
textAreaValue.value = tempInput;
document.addEventListener('keydown', handleWindowKeyDown);
window.addEventListener('resize', handleWindowResize);
inputRef.value?.addEventListener('paste', handlePaste);
let observedWidth: number | undefined;
sizingObserver = new ResizeObserver(([entry]) => {
if (!entry || entry.contentRect.width === observedWidth) return;
observedWidth = entry.contentRect.width;
handleWindowResize();
});
if (inputRef.value) sizingObserver.observe(inputRef.value);
typographyObserver = new MutationObserver(handleWindowResize);
typographyObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['class', 'style'] });
document.fonts.addEventListener('loadingdone', handleWindowResize);
handleWindowResize();
});
onUnmounted(() => {
document.removeEventListener('keydown', handleWindowKeyDown);
window.removeEventListener('resize', handleWindowResize);
if (resizeRafId !== undefined) cancelAnimationFrame(resizeRafId);
if (sizingRaf !== undefined) cancelAnimationFrame(sizingRaf);
sizingObserver?.disconnect();
typographyObserver?.disconnect();
document.fonts.removeEventListener('loadingdone', handleWindowResize);
inputRef.value?.removeEventListener('paste', handlePaste);
});
</script>
<template>
<div :class="['w-full flex max-h-full', $attrs.class]">
<div ref="mirrorRef" aria-hidden="true"
class="absolute top-0 left-0 pointer-events-none invisible overflow-hidden h-0"></div>
<div class="relative w-full flex flex-shrink-1 flex-col gap-3 p-2 rounded-2xl border transition-border ease-in-out duration-300 bg-[var(--bg-container)]
<div :class="['w-full flex flex-col max-h-full', $attrs.class]">
<div ref="mirrorRef" data-chat-measurement aria-hidden="true"
class="fixed top-0 left-0 pointer-events-none invisible overflow-hidden h-0 [contain:layout_style_paint]"></div>
<div class="relative z-10 w-full flex flex-shrink-1 flex-col gap-3 p-2 rounded-2xl border transition-border ease-in-out duration-300 bg-[var(--bg-container)]
border-[var(--color-border)] focus-within:border-[var(--color-border-active)]">
<div v-if="files.length > 0"
class="flex-shrink-0 flex flex-nowrap gap-2 pt-2 px-2 pb-1 overflow-x-auto overflow-y-hidden [scrollbar-width:thin]">
<!-- TODO: show attachment previews -->
<AttachmentPreview v-for="file in files" @delete="files = files.filter((f) => f.id !== file.id)"
@retry="fileSelectorRef?.retryFile(file.id)" :key="file.id" :file="file" />
@retry="fileSelectorRef?.retryFile(file.id)" :key="file.id" :file="file"></AttachmentPreview>
</div>
<div class="min-w-0 max-h-full">
<!-- Grammarly literally breaks everything, go fuck yourself -->
@@ -404,20 +430,76 @@ onUnmounted(() => {
<div class="flex items-center justify-between gap-2">
<!-- TODO: since we dont want to model selector dropdown to potentially overflow, it has max-width: 100%, so, we need to maake the trigger large enough to fit the entire width of the dropdown -->
<div class="flex flex-1 gap-1 min-w-0">
<div class="flex flex-1 items-center gap-1 min-w-0">
<button v-if="selectedModel?.capabilities.includes('tools')"
type="button"
@click="isDrawerOpen = !isDrawerOpen"
class="sm:hidden relative flex items-center justify-center h-8.5 w-8.5 shrink-0 @hover:bg-[var(--color-hover)] rounded-lg transition-colors duration-200"
:aria-label="isDrawerOpen ? 'Close tools drawer' : 'Open tools drawer'"
:aria-expanded="isDrawerOpen">
<span class="i-mynaui-chevron-down text-5 text-[var(--text-secondary)] transition-transform duration-200"
:class="{ 'rotate-180': isDrawerOpen }"></span>
<span v-if="!isDrawerOpen && (searchConfig.enabled || toolsConfig.python)"
class="absolute top-1.5 right-1.5 w-2 h-2 rounded-full bg-[var(--color-accent)]"></span>
</button>
<ModelSelector v-if="providers !== undefined" :add-hotkey="true" v-model="selectedModel"
:providers="providers" />
<SearchSelector v-if="selectedModel?.capabilities.includes('tools')" :enabled="searchConfig.enabled"
@update:enabled="(v: boolean) => { searchConfig.enabled = v; saveSearchConfig() }" />
<ToolSelector v-if="selectedModel?.capabilities.includes('tools')" :python="toolsConfig.python"
@update:python="(v: boolean) => { toolsConfig.python = v; saveToolsConfig() }" />
<FileSelector ref="fileSelectorRef" :selected-model="selectedModel" v-model="files" />
:providers="providers"></ModelSelector>
<div v-if="selectedModel?.capabilities.includes('tools')" class="hidden sm:flex items-center gap-1">
<SearchSelector :enabled="searchConfig.enabled"
@update:enabled="(v: boolean) => { searchConfig.enabled = v; saveSearchConfig(); }"></SearchSelector>
<ToolSelector :python="toolsConfig.python"
@update:python="(v: boolean) => { toolsConfig.python = v; saveToolsConfig(); }"></ToolSelector>
</div>
</div>
<div v-if="allowManualRole" class="flex items-center">
<button aria-label="Send message" @click="handleSubmit"
<div class="flex items-center gap-1 shrink-0">
<FileSelector ref="fileSelectorRef" :selected-model="selectedModel" v-model="files"></FileSelector>
<div v-if="allowManualRole" class="flex items-center">
<button aria-label="Send message" @click="handleSubmit"
:disabled="((!inputValue.content.trim() && files.length === 0) && !loading) || isUploading || hasFailedUploads"
:class="[
'h-8 w-8 rounded-l-lg rounded-r-none transition-all duration-200 flex items-center justify-center disabled:cursor-not-allowed disabled:bg-transparent',
(inputValue.content.trim() || files.length > 0) && !loading && !isUploading && !hasFailedUploads
? 'bg-[var(--color-accent)] text-[var(--color-accent-text)] @hover:bg-[var(--color-accent-hover)]'
: 'text-[var(--text-dim)]',
loading && 'bg-[var(--color-hover)] @hover:bg-[var(--color-active)]',
]">
<span v-if="loading" class="text-6.5 i-mynaui-stop-solid"></span>
<span v-else class="text-5 i-mynaui-send-solid"></span>
</button>
<Dropdown placement="bottom-end">
<template #default="{ setRef, isOpen, toggle }">
<button :ref="setRef" aria-label="Message options" @click="toggle"
:disabled="(!inputValue.content.trim() && files.length === 0) || loading || isUploading || hasFailedUploads"
:class="[
'h-8 w-6 rounded-r-lg rounded-l-none transition-all duration-200 flex items-center justify-center disabled:cursor-not-allowed border-l border-[var(--text-dim)] disabled:border-transparent',
(inputValue.content.trim() || files.length > 0) && !loading && !isUploading && !hasFailedUploads
? 'bg-[var(--color-accent)] text-[var(--color-accent-text)] @hover:bg-[var(--color-accent-hover)] disabled:bg-transparent'
: 'text-[var(--text-dim)]',
loading && 'bg-[var(--color-hover)] @hover:bg-[var(--color-active)]',
]">
<span class="text-4.5 i-mynaui-chevron-down" :class="{ 'rotate-180': isOpen }"></span>
</button>
</template>
<template #dropdown="{ close }">
<button
class="flex items-center gap-2 px-3 py-1.5 rounded-lg text-sm text-[var(--text-primary)] @hover:bg-[var(--color-hover)] transition-colors whitespace-nowrap"
@click="handleAddMessage('user'); close()">
<span class="text-4 i-mynaui-user"></span>
Add as User
</button>
<button
class="flex items-center gap-2 px-3 py-1.5 rounded-lg text-sm text-[var(--text-primary)] @hover:bg-[var(--color-hover)] transition-colors whitespace-nowrap"
@click="handleAddMessage('assistant'); close()">
<span class="text-4 i-mynaui-sparkles"></span>
Add as Assistant
</button>
</template>
</Dropdown>
</div>
<button v-else aria-label="Send message" @click="handleSubmit"
:disabled="((!inputValue.content.trim() && files.length === 0) && !loading) || isUploading || hasFailedUploads"
:class="[
'h-8 w-8 rounded-l-lg rounded-r-none transition-all duration-200 flex items-center justify-center disabled:cursor-not-allowed disabled:bg-transparent',
'h-8 w-8 rounded-xl transition-all duration-200 flex items-center justify-center disabled:cursor-not-allowed disabled:bg-transparent',
(inputValue.content.trim() || files.length > 0) && !loading && !isUploading && !hasFailedUploads
? 'bg-[var(--color-accent)] text-[var(--color-accent-text)] @hover:bg-[var(--color-accent-hover)]'
: 'text-[var(--text-dim)]',
@@ -426,48 +508,19 @@ onUnmounted(() => {
<span v-if="loading" class="text-6.5 i-mynaui-stop-solid"></span>
<span v-else class="text-5 i-mynaui-send-solid"></span>
</button>
<Dropdown placement="bottom-end">
<template #default="{ setRef, isOpen, toggle }">
<button :ref="setRef" aria-label="Message options" @click="toggle"
:disabled="(!inputValue.content.trim() && files.length === 0) || loading || isUploading || hasFailedUploads"
:class="[
'h-8 w-6 rounded-r-lg rounded-l-none transition-all duration-200 flex items-center justify-center disabled:cursor-not-allowed border-l border-[var(--text-dim)] disabled:border-transparent',
(inputValue.content.trim() || files.length > 0) && !loading && !isUploading && !hasFailedUploads
? 'bg-[var(--color-accent)] text-[var(--color-accent-text)] @hover:bg-[var(--color-accent-hover)] disabled:bg-transparent'
: 'text-[var(--text-dim)]',
loading && 'bg-[var(--color-hover)] @hover:bg-[var(--color-active)]',
]">
<span class="text-4.5 i-mynaui-chevron-down" :class="{ 'rotate-180': isOpen }"></span>
</button>
</template>
<template #dropdown="{ close }">
<button
class="flex items-center gap-2 px-3 py-1.5 rounded-lg text-sm text-[var(--text-primary)] @hover:bg-[var(--color-hover)] transition-colors whitespace-nowrap"
@click="handleAddMessage('user'); close()">
<span class="text-4 i-mynaui-user"></span>
Add as User
</button>
<button
class="flex items-center gap-2 px-3 py-1.5 rounded-lg text-sm text-[var(--text-primary)] @hover:bg-[var(--color-hover)] transition-colors whitespace-nowrap"
@click="handleAddMessage('assistant'); close()">
<span class="text-4 i-mynaui-sparkles"></span>
Add as Assistant
</button>
</template>
</Dropdown>
</div>
<button v-else aria-label="Send message" @click="handleSubmit"
:disabled="((!inputValue.content.trim() && files.length === 0) && !loading) || isUploading || hasFailedUploads"
:class="[
'h-8 w-8 rounded-xl transition-all duration-200 flex items-center justify-center disabled:cursor-not-allowed disabled:bg-transparent',
(inputValue.content.trim() || files.length > 0) && !loading && !isUploading && !hasFailedUploads
? 'bg-[var(--color-accent)] text-[var(--color-accent-text)] @hover:bg-[var(--color-accent-hover)]'
: 'text-[var(--text-dim)]',
loading && 'bg-[var(--color-hover)] @hover:bg-[var(--color-active)]',
]">
<span v-if="loading" class="text-6.5 i-mynaui-stop-solid"></span>
<span v-else class="text-5 i-mynaui-send-solid"></span>
</button>
</div>
</div>
<div v-if="selectedModel?.capabilities.includes('tools')"
class="sm:hidden relative z-0 mx-auto w-[calc(100%-4px)] transition-[height] duration-250 ease-[cubic-bezier(0.4,_0,_0.2,_1)]"
:class="isDrawerOpen ? 'h-[44px]' : 'h-0'">
<div class="absolute -top-4 left-0 right-0 pt-5 px-3 pb-1.5 rounded-b-2xl border-x border-b border-[var(--color-border)] bg-[var(--bg-surface)] flex items-center gap-1.5 transition-[transform,opacity] duration-250 ease-[cubic-bezier(0.4,_0,_0.2,_1)]"
:class="isDrawerOpen ? 'translate-y-0 opacity-100' : '-translate-y-[44px] opacity-0 pointer-events-none'">
<SearchSelector :enabled="searchConfig.enabled"
@update:enabled="(v: boolean) => { searchConfig.enabled = v; saveSearchConfig(); }"></SearchSelector>
<ToolSelector :python="toolsConfig.python"
@update:python="(v: boolean) => { toolsConfig.python = v; saveToolsConfig(); }"></ToolSelector>
</div>
</div>
</div>