Convert Beams data structure
Right now the "Beams" are implemented with a data structure made of a CHandler that is backed by a global conversationId-indexed object which stores "Zustand stores", and each contains data for a Beam (all the rays and merges, etc.)
Instead, I want to have a different structure where Beams have all a UniqueId, and can be assumed to be of a conversation if inside they have some sort of read-only field that points to the conversationId. It's a weak pairing that should work well in all the instances where we have Beam displayed instead of the conversation. In practice, Beams receive even a detached copy of the history and instructions on how to then continue the conversation, but that's an aside.
Then, it's key that reactive Beam display and operations shall have a useMemo that takes the (new to be made) global Beam entities store (similar to the global chat or personas store) and the Beam Id (or other search parameter such as the conversation Id) and return a stable interface that's like the current Beam API and the rest of the app can use, ideally without even changing code in the Beam per se.
Now there's a Zustand slices pattern to take care of, as the API kind of confirms to the union of the slices but the "real" API must be a Beam Unique-Id-based CRUD of sorts, and something like the current slices must be the returned interface.
Could you ultrathink and explore many ways of doing this and then the one that makes the most sense?
Source: enricoros/big-AGI