Blocks is a special user interface mode that allows you to have a workspace like interface along with the chat interface. This is similar to [ChatGPT's Canvas](https://openai.com/index/introducing-canvas) and [Claude's Artifacts](https://www.anthropic.com/news/artifacts).
The template already ships with the following blocks:
- **Text Block**: A block that allows you to work with text content like drafting essays and emails.
- **Code Block**: A block that allows you to write and execute code (Python).
- **Image Block**: A block that allows you to work with images like editing, annotating, and processing images.
- **Sheet Block**: A block that allows you to work with tabular data like creating, editing, and analyzing data.
## Adding a Custom Block
To add a custom block, you will need to create a folder in the `blocks` directory with the block name. The folder should contain the following files:
-`client.tsx`: The client-side code for the block.
-`server.ts`: The server-side code for the block.
Here is an example of a custom block called `CustomBlock`:
```bash
blocks/
custom/
client.tsx
server.ts
```
### Client-Side Example (client.tsx)
This file is responsible for rendering your custom block. You might replace the inner UI with your own components, but the overall pattern (initialization, handling streamed data, and rendering content) remains the same. For instance:
```tsx
import { Block } from "@/components/create-block";
import { ExampleComponent } from "@/components/example-component";
import { toast } from "sonner";
interface CustomBlockMetadata {
// Define metadata your custom block might need—the example below is minimal.
info: string;
}
export const customBlock = new Block<"custom", CustomBlockMetadata>({
kind: "custom",
description: "A custom block for demonstrating custom functionality.",
// Initialization can fetch any extra data or perform side effects
Once you have created the client and server files, you can import the block in the `lib/blocks/server.ts` file and add it to the `documentHandlersByBlockKind` array.