ui icon indicating copy to clipboard operation
ui copied to clipboard

feat(ChatMessage/ChatMessages): add message generics

Open zAlweNy26 opened this issue 4 months ago โ€ข 5 comments

๐Ÿ”— Linked issue

โ“ Type of change

  • [ ] ๐Ÿ“– Documentation (updates to the documentation or readme)
  • [ ] ๐Ÿž Bug fix (a non-breaking change that fixes an issue)
  • [x] ๐Ÿ‘Œ Enhancement (improving an existing functionality)
  • [ ] โœจ New feature (a non-breaking change that adds functionality)
  • [ ] ๐Ÿงน Chore (updates to the build process or auxiliary tools and libraries)
  • [ ] โš ๏ธ Breaking change (fix or feature that would cause existing functionality to change)

๐Ÿ“š Description

With this PR, I wanted to add generics in both ChatMessage and ChatMessages so that the correct type can be inferred inside slots (like the metadata of every message)

๐Ÿ“ Checklist

  • [ ] I have linked an issue or discussion.
  • [ ] I have updated the documentation accordingly.

zAlweNy26 avatar Oct 19 '25 14:10 zAlweNy26

npm i https://pkg.pr.new/@nuxt/ui@5259

commit: 03f44b2

pkg-pr-new[bot] avatar Oct 19 '25 14:10 pkg-pr-new[bot]

Hi @benjamincanac, thanks for the response. I tested it, and it seems to work. I only have some doubts about the implementation I did. I could have probably used the UIMessage as a generic for the ChatMessages component instead of the split generics of the UIMessage interface, but for the ChatMessage component, it can't be done since the component props extend it.

zAlweNy26 avatar Oct 22 '25 15:10 zAlweNy26

I need to look more closely but I'm not sure the generic will work this way ๐Ÿค” @sandros94 do you have an opinion on this?

Somehow I've missed this notification.

UChatMessage implementation is mostly correct, the issue is with UChatMessages which if the generics are passed this way you endup with the same generics for all messages as well as it does not propagate to slots correctly.

@zAlweNy26 I will leave a couple of reviews with what should be the required changes (tho I'm on mobile, thus I cannot test them directly)

sandros94 avatar Oct 23 '25 12:10 sandros94

@benjamincanac @sandros94 should I open a PR also in the chat template to fix the error? Or this PR should be retro-compatible?

zAlweNy26 avatar Oct 23 '25 16:10 zAlweNy26

Also I noticed a missing prop in the ChatMessage default slot, I hope it's ok to add the fix in this PR.

zAlweNy26 avatar Oct 23 '25 16:10 zAlweNy26