♻️ refactor: optimize state management, switch to @tanstack/vue-virtual, and improve performance
- Centralize `useAgents` and `useModels` state within the Nuxt app context to prevent data leaks and improve initialization. - Migrate virtualization from `vue-virtual-scroller` to `@tanstack/vue-virtual` with new `RowVirtualizerFixed` and `RowVirtualizerDynamic` components. - Upgrade Nuxt to v4.3.1 and remove `@vue-macros/nuxt`. - Replace `big.js` with an optimized custom `lshDecimal` string manipulation logic for pricing calculations in the provider API. - Implement automatic focus redirection in `ChatInput` to capture standard keyboard input. - Refactor Sidenav and Settings components to utilize virtualization for long lists (topics, agents, models). - Enhance theme colors and mobile experience. More work to come on both of these.
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
import type { ModelWithProvider, ProviderWithModels } from '~/composables/useModels';
|
||||
import type { Entity } from '@triplit/client';
|
||||
import { schema } from '#triplit/schema';
|
||||
import type { Agent } from '~/composables/useAgents';
|
||||
|
||||
const { allModels } = await useModels();
|
||||
const { allModels } = useModels();
|
||||
|
||||
const inputHeight: Ref<string> = ref('auto');
|
||||
const inputRef = ref<HTMLTextAreaElement | null>(null);
|
||||
@@ -19,7 +18,7 @@ const emit = defineEmits<{
|
||||
|
||||
const props = defineProps<{
|
||||
loading?: boolean;
|
||||
agent?: Entity<typeof schema, 'agents'>;
|
||||
agent: Agent | null;
|
||||
providers?: ProviderWithModels[];
|
||||
}>();
|
||||
|
||||
@@ -107,6 +106,15 @@ const handleKeyDown = async (event: KeyboardEvent) => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleWindowKeyDown = async (event: KeyboardEvent) => {
|
||||
if (event.ctrlKey || event.metaKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
// redirect all standard keyboard input to the input field
|
||||
inputRef.value?.focus();
|
||||
};
|
||||
|
||||
watch(inputValue, async () => {
|
||||
const textarea = inputRef.value;
|
||||
if (!textarea) return;
|
||||
@@ -141,6 +149,11 @@ onBeforeMount(() => {
|
||||
|
||||
onMounted(() => {
|
||||
inputValue.value = tempInput;
|
||||
document.addEventListener('keydown', handleWindowKeyDown);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
document.removeEventListener('keydown', handleWindowKeyDown);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user