-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Open
Labels
Description
Description
Hey folks
I'm trying to extract the Chat
class into a Pinia store, to access it from everywhere, and load the current chat in the class when the user is viewing the current chat.
I won't go into the details, but I'd much rather edit an existing class instance than create one instance for every chat the user has.
The problem is chat.id is flagged as read-only by typescript, so modifying the existing class is out of the question...
Is there a reason for it to be read only?
some examples:
export const useChatStore = defineStore('chat', () => {
// some store other values ...
/** The chats stored */
const chats = ref(new Map<string, CustomChat>());
const chat = ref(
new Chat({
//.. a very long config
}),
);
// This is how I have to modify the chat instance today
async function loadChat({ chatID }: { chatID: string }): Promise<void> {
chat.value = new Chat({
//.. a very long config
});
chat.value.messages = chats.value.get(chatID)?.messages as UIMessage[];
}
// This would be much nicer
async function loadChat({ chatID }: { chatID: string }): Promise<void> {
chat.value.id = chatID;
chat.value.messages = chats.value.get(chatID)?.messages as UIMessage[];
}
return {
chat,
}
}
AI SDK Version
- @ai-sdk/vue: 2.0.0-beta.14
solidprinciples