Skip to content

V5 VueJS, pinia & updating the Chat id #7340

@Mael-Abgrall

Description

@Mael-Abgrall

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy