Type definitions from lib/types.ts and related files.
Chat types
ChatMessage
Represents a message in the chat UI.
export type ChatMessage = UIMessage<
MessageMetadata,
CustomUIDataTypes,
ChatTools
>;
Extends UIMessage from the ai package with:
- Metadata:
MessageMetadata
- Data types:
CustomUIDataTypes
- Tools:
ChatTools
From lib/types.ts:47-51
Metadata attached to each message.
export const messageMetadataSchema = z.object({
createdAt: z.string(),
});
export type MessageMetadata = z.infer<typeof messageMetadataSchema>;
ISO 8601 timestamp string
From lib/types.ts:12-16
CustomUIDataTypes
Custom data events that can be sent during streaming.
export type CustomUIDataTypes = {
textDelta: string;
imageDelta: string;
sheetDelta: string;
codeDelta: string;
suggestion: Suggestion;
appendMessage: string;
id: string;
title: string;
kind: ArtifactKind;
clear: null;
finish: null;
"chat-title": string;
};
Streaming text content delta
Streaming image data delta
Streaming spreadsheet data delta
Streaming code content delta
A document editing suggestion
Message to append to current content
Identifier for the current artifact
Title for the current artifact
Type of artifact being created
Signal to clear current content
Signal that streaming is complete
From lib/types.ts:32-46
Available tools for the AI during chat.
type weatherTool = InferUITool<typeof getWeather>;
type createDocumentTool = InferUITool<ReturnType<typeof createDocument>>;
type updateDocumentTool = InferUITool<ReturnType<typeof updateDocument>>;
type requestSuggestionsTool = InferUITool<ReturnType<typeof requestSuggestions>>;
export type ChatTools = {
getWeather: weatherTool;
createDocument: createDocumentTool;
updateDocument: updateDocumentTool;
requestSuggestions: requestSuggestionsTool;
};
Fetch weather information for a location
Create a new document (text, code, image, or sheet)
Update an existing document’s content
Request AI-generated editing suggestions for a document
From lib/types.ts:18-30
Attachment
Represents a file attachment.
export type Attachment = {
name: string;
url: string;
contentType: string;
};
MIME type (e.g., "image/jpeg", "image/png")
From lib/types.ts:53-57
Database types
All database types are inferred from schema definitions in lib/db/schema.ts.
User
export type User = InferSelectModel<typeof user>;
Email address (max 64 characters)
Hashed password (nullable for OAuth users)
From lib/db/schema.ts:20
Chat
export type Chat = InferSelectModel<typeof chat>;
Chat visibility (default: "private")
From lib/db/schema.ts:34
DBMessage
export type DBMessage = InferSelectModel<typeof message>;
Message role: "user", "assistant", or "system"
Array of message parts (text or file objects)
Array of file attachments
From lib/db/schema.ts:61
Vote
export type Vote = InferSelectModel<typeof vote>;
true for upvote, false for downvote
From lib/db/schema.ts:103
Document
export type Document = InferSelectModel<typeof document>;
Creation timestamp (part of composite key)
kind
'text' | 'code' | 'image' | 'sheet'
Document type (default: "text")
From lib/db/schema.ts:126
Suggestion
export type Suggestion = InferSelectModel<typeof suggestion>;
Document version timestamp
Resolution status (default: false)
From lib/db/schema.ts:152
Stream
export type Stream = InferSelectModel<typeof stream>;
From lib/db/schema.ts:170
Request/Response schemas
PostRequestBody
Request body schema for POST /api/chat.
export const postRequestBodySchema = z.object({
id: z.string().uuid(),
message: userMessageSchema.optional(),
messages: z.array(messageSchema).optional(),
selectedChatModel: z.string(),
selectedVisibilityType: z.enum(["public", "private"]),
});
export type PostRequestBody = z.infer<typeof postRequestBodySchema>;
Single new user message (for new messages)
All messages (for tool approval flows)
selectedVisibilityType
'public' | 'private'
required
Chat visibility
From app/(chat)/api/chat/schema.ts:30-39
Message parts
TextPart
const textPartSchema = z.object({
type: z.enum(["text"]),
text: z.string().min(1).max(2000),
});
Text content (1-2000 characters)
From app/(chat)/api/chat/schema.ts:3-6
FilePart
const filePartSchema = z.object({
type: z.enum(["file"]),
mediaType: z.enum(["image/jpeg", "image/png"]),
name: z.string().min(1).max(100),
url: z.string().url(),
});
mediaType
'image/jpeg' | 'image/png'
required
MIME type (currently only images supported)
File name (1-100 characters)
From app/(chat)/api/chat/schema.ts:8-13
UserMessage
const userMessageSchema = z.object({
id: z.string().uuid(),
role: z.enum(["user"]),
parts: z.array(partSchema),
});
Array of text or file parts
From app/(chat)/api/chat/schema.ts:17-21
Artifact types
ArtifactKind
Type of document/artifact that can be created.
type ArtifactKind = "text" | "code" | "image" | "sheet";
Plain text documents, notes, articles
Source code, scripts, configuration files
SVG images, diagrams, graphics
Spreadsheets, data tables
From components/artifact.tsx
Visibility types
VisibilityType
Chat visibility setting.
type VisibilityType = "public" | "private";
Only visible to the chat owner (default)
Visible to anyone with the link
From components/visibility-selector.tsx
Utility types
DataPart
Custom data part for streaming.
export type DataPart = { type: "append-message"; message: string };
From lib/types.ts:10
Used for appending messages during streaming responses.