In this article, we review useChat hook in Chef codebase. We will look at:
What is Chef?
useChat hook.
AI SDK.
I study patterns used in an open source project found on Github Trending. For this week, I reviewed some parts of Chef codebase and wrote this article.
What is Chef?
Chef is open-source, check out the GitHub repo here.
This is the only AI app builder that knows backend. By applying Convex primitives directly to your code generation, your apps are automatically equipped with optimal backend patterns and best practices. Your full-stack apps come with a built-in database, zero config auth, file uploads, real-time UIs, and background workflows. If you want to check out the secret sauce that powers Chef, you can view or download the system prompt here.
As mentioned above, Chef’s capabilities are enabled by being built on top of Convex, the open-source reactive database designed to make life easy for web app developers. The “magic” in Chef is just the fact that it’s using Convex’s APIs, which are an ideal fit for codegen.
This project is a fork of the stable branch of bolt.diy.
Learn more about Chef.
useChat hook
You will find the following code in Chat.tsx component.
const { messages, status, stop, append, setMessages, reload, error } = useChat({
initialMessages,
api: '/api/chat',
sendExtraMessageFields: true,
experimental_prepareRequestBody: ({ messages }) => {
...
},
maxSteps: 64,
async onToolCall({ toolCall }) {
...
},
onError: async (e: Error) => {
...
},
onFinish: async (message, response) => {
...
},
});
useChat is imported at the top of file:
import { useChat } from '@ai-sdk/react';
ai-sdk
AI SDK is the AI toolkit for TypeScript. From the creators of Next.js, the AI SDK is a free open-source library that gives you the tools you need to build AI-powered products.
The AI SDK standardizes integrating artificial intelligence (AI) models across supported providers. This enables developers to focus on building great AI applications, not waste time on technical details.
Learn more about ai-sk.
About me:
Hey, my name is Ramu Narasinga. I study codebase architecture in large open-source projects.
Email: ramu.narasinga@gmail.com
I spent 200+ hours analyzing Supabase, shadcn/ui, LobeChat. Found the patterns that separate AI slop from production code. Stop refactoring AI slop. Start with proven patterns. Check out production-grade projects at thinkthroo.com

Top comments (0)