Skip to main content
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

MessageMetadata

Metadata attached to each message.
export const messageMetadataSchema = z.object({
  createdAt: z.string(),
});

export type MessageMetadata = z.infer<typeof messageMetadataSchema>;
createdAt
string
required
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;
};
textDelta
string
Streaming text content delta
imageDelta
string
Streaming image data delta
sheetDelta
string
Streaming spreadsheet data delta
codeDelta
string
Streaming code content delta
suggestion
Suggestion
A document editing suggestion
appendMessage
string
Message to append to current content
id
string
Identifier for the current artifact
title
string
Title for the current artifact
kind
ArtifactKind
Type of artifact being created
clear
null
Signal to clear current content
finish
null
Signal that streaming is complete
chat-title
string
Generated chat title
From lib/types.ts:32-46

ChatTools

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;
};
getWeather
weatherTool
Fetch weather information for a location
createDocument
createDocumentTool
Create a new document (text, code, image, or sheet)
updateDocument
updateDocumentTool
Update an existing document’s content
requestSuggestions
requestSuggestionsTool
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;
};
name
string
required
File name
url
string
required
File URL
contentType
string
required
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>;
From lib/db/schema.ts:20

Chat

export type Chat = InferSelectModel<typeof chat>;
From lib/db/schema.ts:34

DBMessage

export type DBMessage = InferSelectModel<typeof message>;
From lib/db/schema.ts:61

Vote

export type Vote = InferSelectModel<typeof vote>;
From lib/db/schema.ts:103

Document

export type Document = InferSelectModel<typeof document>;
From lib/db/schema.ts:126

Suggestion

export type Suggestion = InferSelectModel<typeof suggestion>;
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>;
id
string
required
Chat UUID
message
object
Single new user message (for new messages)
messages
array
All messages (for tool approval flows)
selectedChatModel
string
required
AI model identifier
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),
});
type
'text'
required
Part type identifier
text
string
required
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(),
});
type
'file'
required
Part type identifier
mediaType
'image/jpeg' | 'image/png'
required
MIME type (currently only images supported)
name
string
required
File name (1-100 characters)
url
string
required
Valid URL to the file
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),
});
id
string
required
Message UUID
role
'user'
required
Must be "user"
parts
array
required
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
From components/artifact.tsx

Visibility types

VisibilityType

Chat visibility setting.
type VisibilityType = "public" | "private";
Only visible to the chat owner (default)
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.

Build docs developers (and LLMs) love