♻️ 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:
@@ -8,16 +8,10 @@ const inputValue = ref('');
|
||||
const pendingMessage = ref<Message | null>(null);
|
||||
|
||||
const { createTopic, sendMessage, autoRename } = useChat(route.params.id as string);
|
||||
const { getAgent, unsubscribe: unsubscribeAgents } = await useAgents();
|
||||
const { providers, unsubscribe: unsubscribeModels } = await useModels();
|
||||
const { getAgent } = useAgents();
|
||||
const { providers } = useModels();
|
||||
|
||||
const agent = computed(() => {
|
||||
if (route.params.id === null || typeof route.params.id !== 'string') {
|
||||
throw new Error('Invalid agent ID');
|
||||
}
|
||||
|
||||
return getAgent(route.params.id)!;
|
||||
});
|
||||
const agent = getAgent(route.params.id as string);
|
||||
|
||||
if (!agent.value) navigateTo('/');
|
||||
|
||||
@@ -85,11 +79,6 @@ const handleSubmit = async (message: string, model: ModelWithProvider | null) =>
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
onUnmounted(() => {
|
||||
unsubscribeAgents?.();
|
||||
unsubscribeModels?.();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
const { getAgent, unsubscribe: unsubscribeAgents } = await useAgents();
|
||||
const { getAgent } = useAgents();
|
||||
const triplit = useTriplitClient();
|
||||
|
||||
const route = useRoute();
|
||||
|
||||
const agent = computed(() => {
|
||||
if (route.params.id === null || typeof route.params.id !== 'string') {
|
||||
throw new Error('Invalid agent ID');
|
||||
}
|
||||
const agent = getAgent(route.params.id as string);
|
||||
|
||||
return getAgent(route.params.id)!;
|
||||
});
|
||||
|
||||
// if (agent.value === undefined) navigateTo('/');
|
||||
if (agent.value === undefined) navigateTo('/');
|
||||
|
||||
const handleInput = async (e: Event) => {
|
||||
const target = e.target as HTMLInputElement;
|
||||
@@ -20,7 +14,7 @@ const handleInput = async (e: Event) => {
|
||||
return;
|
||||
}
|
||||
|
||||
await triplit.update('agents', agent.value.id, { name: target.value });
|
||||
await triplit.update('agents', agent.value!.id, { name: target.value });
|
||||
};
|
||||
|
||||
const changeSystemPrompt = async (e: Event) => {
|
||||
@@ -31,14 +25,10 @@ const changeSystemPrompt = async (e: Event) => {
|
||||
value = undefined;
|
||||
}
|
||||
|
||||
await triplit.update('agents', agent.value.id, {
|
||||
await triplit.update('agents', agent.value!.id, {
|
||||
systemPrompt: target.value,
|
||||
});
|
||||
};
|
||||
|
||||
onUnmounted(() => {
|
||||
unsubscribeAgents?.();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -10,16 +10,10 @@ const chatPaneWrapper = ref<HTMLElement | null>(null);
|
||||
const inputValue = ref('');
|
||||
const route = useRoute();
|
||||
const { sendMessage, regenerateMessage } = useChat(route.params.id as string);
|
||||
const { getAgent, unsubscribe: unsubscribeAgents } = await useAgents();
|
||||
const { providers, allModels, unsubscribe: unsubscribeModels } = await useModels();
|
||||
const { getAgent } = useAgents();
|
||||
const { providers, allModels } = useModels();
|
||||
|
||||
const agent = computed(() => {
|
||||
if (route.params.id === null || typeof route.params.id !== 'string') {
|
||||
throw new Error('Invalid agent ID');
|
||||
}
|
||||
|
||||
return getAgent(route.params.id)!;
|
||||
});
|
||||
const agent = getAgent(route.params.id as string);
|
||||
|
||||
const topicQuery = computed(() =>
|
||||
triplit
|
||||
@@ -273,8 +267,6 @@ onUnmounted(() => {
|
||||
unsubscribeMessages?.();
|
||||
unsubscribeParts?.();
|
||||
unsubscribeGenerations?.();
|
||||
unsubscribeAgents?.();
|
||||
unsubscribeModels?.();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
+5
-8
@@ -1,12 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import type schema from '#triplit/schema';
|
||||
import type { Entity } from '@triplit/client';
|
||||
import { assert } from '~~/utils/assert';
|
||||
import type { Agent } from '~/composables/useAgents';
|
||||
|
||||
const triplit = useTriplitClient();
|
||||
|
||||
const { agents, unsubscribe: unsubscribeAgents, createAgent } = await useAgents();
|
||||
const { providers, unsubscribe: unsubscribeModels, getFirstAvailableModel, allModels } = await useModels();
|
||||
const { agents, createAgent } = useAgents();
|
||||
const { providers, getFirstAvailableModel, allModels } = useModels();
|
||||
|
||||
const taglines = {
|
||||
morning: [
|
||||
@@ -74,12 +73,12 @@ const typeWriter = (time: 'morning' | 'afternoon' | 'evening') => {
|
||||
};
|
||||
|
||||
const agent = computed(() => {
|
||||
return agents.value?.[0];
|
||||
return agents.value?.[0] ?? null;
|
||||
});
|
||||
|
||||
const handleChatSubmit = async (message: string, model: ModelWithProvider | null) => {
|
||||
console.log('Message submitted:', message, agents);
|
||||
let agent: Entity<typeof schema, 'agents'> | null = agents.value?.[0] ?? null;
|
||||
let agent: Agent | null = agents.value?.[0] ?? null;
|
||||
if (!agent) {
|
||||
const triplit = useTriplitClient();
|
||||
assert('flush' in triplit);
|
||||
@@ -162,8 +161,6 @@ onUnmounted(() => {
|
||||
if (typeWriterInterval !== null) {
|
||||
clearTimeout(typeWriterInterval);
|
||||
}
|
||||
unsubscribeAgents?.();
|
||||
unsubscribeModels?.();
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<template>
|
||||
|
||||
</template>
|
||||
Reference in New Issue
Block a user