Allows package users to define data fetching functions, or "tools", for each component with parameters.
Updates registerComponent to store the function definitions.
Updates generateComponent to let AI decide when to use the tools.
To enable this, generateComponent is split into two parts:
1: choose component (or decide no component should be used)
2: hydrate component
hydrate component passes the chosen component and any of its tools to AI, and lets AI either create props, or request that one of the tools be called to collect more data.
Currently, the tool needs to be called clientside where it is defined. So if AI decides to run a tool, that decision is passed back to the client, the client runs the tool to get the extra context data, and then calls hydrate component, passing the tool run results, so the AI can finally generate props for the chosen component, and return it back to the client.
This also means that we should be using fewer tokens and generation should be faster, since each component's context function doesn't need to be run each time we generate a component.
Some things to note:
Currently assumes that a tool's definition defines its parameters in the order they are used in the actual function
Because the tool needs to run on the client, the tool results are not passed to openai in the usual way (in the following message of the same conversation openai requested a tool call)
There is no way to define an action that is not associated with a component, so we don't yet have the possibility of having the AI take "actions" without showing a component (creating, updating, deleting)
Allows package users to define data fetching functions, or "tools", for each component with parameters.
Updates registerComponent to store the function definitions. Updates generateComponent to let AI decide when to use the tools.
To enable this, generateComponent is split into two parts: 1: choose component (or decide no component should be used) 2: hydrate component
hydrate component passes the chosen component and any of its tools to AI, and lets AI either create props, or request that one of the tools be called to collect more data.
Currently, the tool needs to be called clientside where it is defined. So if AI decides to run a tool, that decision is passed back to the client, the client runs the tool to get the extra context data, and then calls hydrate component, passing the tool run results, so the AI can finally generate props for the chosen component, and return it back to the client.
This also means that we should be using fewer tokens and generation should be faster, since each component's context function doesn't need to be run each time we generate a component.
Some things to note: