Artifacts
Integrate workspaces for activities that involve complex and persistent user interactions
Artifacts 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 and Claude's Artifacts.
The template already ships with the following artifacts:
- Text Artifact: Work with text content like drafting essays and emails.
- Code Artifact: Write and execute code snippets.
- Image Artifact: Work with images like editing, annotating, and processing images.
- Sheet Artifact: Work with tabular data like creating, editing, and analyzing data.
Adding a Custom Artifact
To add a custom artifact, you will need to create a folder in the artifacts
directory with the artifact name. The folder should contain the following files:
client.tsx
: The client-side code for the artifact.server.ts
: The server-side code for the artifact.
Here is an example of a custom artifact called CustomArtifact
:
Client-Side Example (client.tsx)
This file is responsible for rendering your custom artifact. 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:
Server-Side Example (server.ts)
The server file processes the document for the artifact. It streams updates (if applicable) and returns the final content. For example:
Once you have created the client and server files, you can import the artifact in the lib/artifacts/server.ts
file and add it to the documentHandlersByArtifactKind
array.
Specify it in document schema at lib/db/schema.ts
.
And also add the client-side artifact to the artifactDefinitions
array in the components/artifact.tsx
file.
You should now be able to see the custom artifact in the workspace!