-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: a new API design to allow customizations #15
Conversation
@himself65 Could help me to check why test cases "setData" and "onFinish" cannot pass correctly. I'm not an expert on React and jotai. My bad 🥲. |
Thanks for your contribution! I will check |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, what we can do more in the next steps:
- combine
makeChatAtoms
andchatAtoms
- align with vercel ai latest version
- add, update examples, docs
Love you 😍 |
I think ui test failed? |
In where, CI or local env? |
I see, you haven't fixed
Yeah, I can't understand why they failed before |
Hi,
I'm switching to very similar solutions like
jotai-ai
(ai sdk to unified api call + jotai for client-side state management) fromai/rsc
recently.Thanks for providing excellent reference implementations. But when try to use it in my case, I feel it's not that easy to adapt widely. I have implemented extended types based
CoreMessage
(which also could be seen as DB message or server state), but both originaluseChat
and currentchatAtoms
are all difficult to customize client side message state, I almost need to write almost everything. Actually, the latest reference exampleai-chatbot
has been usingCoreMessage
for server state,Message
(from@ai/ui-utils
) for client state (which should be better to name asUIMessage
). I hope the new design would achieve that easier.This PR implements some basic MVP to demonstrate my ideas:
Split main user interface to two functions
makeChatAtoms
anduseChat
. LetuseChat
expose useful and similar handlers/states like upstreamuseChat
(ai/react
), and leftmakeChatAtoms
contains low level atoms for advanced users. Indeed,makeChatAtoms
only controls how client interactive with remote stream data (append and receive new messages), and left all others intouseChat
in order that advanced users could implement theirsinputAtoms
,sumbitAtoms
. Built-inuseChat
could be just an official reference implementation has the same features with upstream projects.Accept a user defined
messagesAtom
from outside. LikeIn this way, users could decide how to prepare their UI messages, whatever derived from other states or initialed from fetch or even SSR.
firstTokenReceived
or action likedeleteAtom
in the future without breaking up signatures ofuseChat
.Also, there are several issues I haven't confirmed and figured out clearly:
In current implements, all deprecated API and parameters are literally deprecated. And the
ai
project has already released alpha candidates of the nextv4
version.Current callback handler like
onErrorAtom
, ...,onResponseAtom
is initialed bymakeChatAtoms
and cloud be updated byuseChat
. I'm not sure whether it's a correct design or proper usage of atoms. For now, it's just implemented to fit upstream UI test cases easily.I hope we could add a generic type interface for
Body
intomakeChatAtoms
. This data type can be shared between server endpoint and user client. It's more safe and ergonomic to make sure correct data being sent and parsed.That's all. Thanks for your efforts!
Reject or feedback is all appreciate :). Have a nice day 🎉.
Sincerely,
Lanqing