Chat Interface & AI Copilot
Relevant source files
The following files were used as context for generating this wiki page:
The Chat Interface provides a specialized environment for construction industry professionals to interact with LV.AI, an autonomous AI expert. It supports tendering, procurement, and billing (AVA) workflows specifically for the D/A/CH region (Germany, Austria, Switzerland).
This module manages real-time messaging, multimodal inputs, and an integrated side panel called Artifacts that displays generated documents, code, or spreadsheets.
Core Chat Architecture
The chat interface utilizes a split-pane layout managed by the ChatShell component. It divides the screen between the message history and the artifact display area.
Primary UI Components
| Component | Function | Source |
|---|---|---|
ChatShell | Orchestrates the high-level layout and state synchronization between chat and artifacts. | components/chat/shell.tsx |
Messages | Renders the chronological list of user and assistant messages, including tool outputs. | components/chat/shell.tsx:75 |
MultimodalInput | Handles text input, file attachments, slash commands, and model selection. | components/chat/multimodal-input.tsx |
Artifact | A side panel that displays real-time updates for documents, code, or sheets. | components/chat/artifact.tsx |
Layout Management
The interface dynamically adjusts its width. When an artifact is visible, the chat pane occupies 40% of the screen; otherwise, it takes the full width. On mobile devices, the artifact transitions to a full-screen overlay.
Sources: components/chat/shell.tsx:64-70, components/chat/artifact.tsx:327-345
AI Copilot Logic & Persona
The AI Copilot operates under a strict system prompt that defines its persona as LV.AI, an expert for GAEB DA XML, VOB, ÖNORM, and SIA standards.
System Instructions
The system prompt enforces several operational rules:
- Language: Responses must always be in German.
- Expertise: It covers GAEB (X81-X86), VOB/A, DIN 276, and electronic invoicing (XRechnung, ZUGFeRD).
- Tool Usage: The AI must only call one tool per response and stop immediately after creating or editing an artifact.
- Artifact Suppression: The AI must not repeat artifact content in the chat text after generation.
Sources: lib/ai/prompts.ts:11-30, lib/ai/prompts.ts:40-44
Model Configuration
The interface allows users to select between different LLM models. Capabilities such as tool usage, vision, and reasoning are dynamically detected per model via API.
Sources: components/chat/multimodal-input.tsx:550-610, app/(chat)/api/chat/route.ts:162-167
Data Flow & Messaging
Messaging follows a structured flow from the user interface through the API to the AI provider.
Message Lifecycle Diagram
The following diagram illustrates how a user message results in a streaming AI response with tool execution.
Diagram showing the flow of data from UI submission to AI response and database persistence.
Sources: hooks/use-active-chat.tsx:115-160, app/(chat)/api/chat/route.ts:182-255
Context Window Optimization
To manage performance and costs, the system truncates the message history sent to the model. While the UI displays the full history from the database, the API only sends the last 8 messages to the AI provider.
Sources: app/(chat)/api/chat/route.ts:176-180
Multimodal Interaction
The MultimodalInput component supports various interaction types beyond standard text.
Features
- File Attachments: Users can upload PDF, GAEB XML, Excel, and image files. Files are handled via a preview list before submission.
- Slash Commands: Typing
/triggers a command menu for actions like clearing chat, renaming, or deleting history. - Suggested Actions: On empty chats, the interface provides clickable suggestions for common construction tasks (e.g., "Create a bill of quantities").
- Draft Persistence: Input text is saved to local storage to prevent data loss during page refreshes.
Sources: components/chat/multimodal-input.tsx:109-170, components/chat/multimodal-input.tsx:215-225, components/chat/multimodal-input.tsx:372-385
Tool Integration & Artifacts
The Copilot utilizes specific tools to generate and modify structured content in the side panel.
| Tool | Purpose | Output |
|---|---|---|
createDocument | Generates a new LV, cost estimate, or report. | Artifact Kind: text, code, or sheet. |
editDocument | Modifies existing content using find-and-replace. | Updated Artifact Version. |
requestSuggestions | Analyzes a document and provides improvement tips. | Interactive suggestions list. |
updateDocument | Performs a full rewrite of an artifact. | New Artifact Version. |
Sources: lib/ai/prompts.ts:46-75, lib/ai/tools/create-document.ts:24-34
Artifact Versioning
Every modification to an artifact creates a new version in the database. The UI provides a version footer and toolbar to navigate between history versions (prev, next, latest) and toggle "diff" views to see changes between versions.
Sources: components/chat/artifact.tsx:240-265, lib/db/schema.ts:153-166
Error Handling
The system implements several layers of error management:
- Rate Limiting: IP-based rate limits and user-type message quotas (messages per hour).
- Tool Denials: Users can manually allow or deny specific tool calls (e.g., weather lookup) within the message stream.
- Connection Resilience: An
AlertDialogappears if the AI service connection fails, allowing the user to retry or return home.
Sources: app/(chat)/api/chat/route.ts:68-80, components/chat/message.tsx:165-180, components/chat/shell.tsx:156-180
Conclusion
The Chat Interface & AI Copilot system serves as a specialized workbench for construction workflows. By combining a multimodal chat input with a version-controlled artifact system and construction-specific system prompts, it enables complex AVA tasks within a conversational interface. It maintains compliance with D/A/CH standards while ensuring data integrity through truncation, versioning, and real-time database persistence.