The AI workspace uses the Vercel AI SDK for model calls, streaming, tool calls, message metadata, and generated output. The app keeps model options and tool behavior inside the AI chat feature.
Model Options
Model options live in src/features/ai/chat/constants/chat-model.constants.ts.
export const CHAT_MODEL_OPTIONS = [
{
id: "openai/gpt-5.4-nano",
label: "GPT 5.4 Nano",
shortLabel: "gpt-5.4-nano",
provider: "openai",
providerLabel: "OpenAI",
descriptionKey: "gptNano",
},
]
export const DEFAULT_CHAT_MODEL_ID = "openai/gpt-5.4-nano"The model picker uses this list for labels, provider names, short labels, and descriptions. The request schema also uses the generated model id list to reject unsupported model ids.
Adding A Model
To add a model:
- Add the model to
CHAT_MODEL_OPTIONS. - Update the translation copy for the model description.
- Make sure the model id is available through your Vercel AI Gateway setup.
- Test a normal chat request and a regenerated assistant response.
Keep the id value aligned with the provider id expected by the model gateway.
Tool Registry
The tool registry lives in src/features/ai/chat/tools/chat-tools.server.ts.
export function createChatTools(userId: string, requestOrigin: string, options: CreateChatToolsOptions = {}) {
return {
...createChatSupportTools(userId),
searchWeb: createChatWebSearchTool(userId, options),
generateImage: createChatGenerateImageTool(userId, { ...options, requestOrigin }),
}
}This is the place to add, remove, or rename model tools. Keep each tool in its own server file so validation, provider calls, and error logging stay focused.
Web Search Tool
Web search lives in src/features/ai/chat/tools/chat-web-search-tool.server.ts.
It uses:
perplexity/sonaras the search model.- A strict input schema for the query.
- Structured output with an answer and ordered source cards.
- Short source descriptions.
- Bracket citations such as
[1]and[2].
The UI renders citations through chat session components, so the assistant can answer with readable source markers while the interface shows source cards.
Image Generation Tool
Image generation lives in src/features/ai/chat/tools/chat-generate-image-tool.server.ts.
It uses:
openai/gpt-image-2as the image model.- One image per tool call.
1024x1024output size.- Vercel Blob private storage for generated files.
- UI rendered image cards instead of raw image URLs in assistant text.
The assistant should not print the image URL after the tool returns. The UI owns the generated image card, download action, and attachment display.
Support And Account Tools
Support and account tools live in src/features/ai/chat/tools/chat-support-tools.server.ts.
The included tools can:
- Fetch recent support tickets.
- Create a support ticket when the user explicitly asks for escalation.
- Read notification preferences.
- Update notification preferences.
These tools are intentionally scoped to the current authenticated user. Keep account tools narrow and human readable so tool status labels make sense in chat.
Tool Status UI
Tool rendering lives under src/features/ai/chat/components/chat-session.
The important files are:
chat-session-tool-status.tsxfor deciding how a tool result renders.chat-session-generated-image-tool.tsxfor image output cards.chat-session-citations.tsxfor cited web sources.chat-session-response-with-citations.tsxfor assistant text with source markers.
Tool statuses should use human readable labels. Do not show raw internal tool names as the user facing status.