File Upload & Processing
Relevant source files
The following files were used as context for generating this wiki page:
The File Upload & Processing system manages the ingestion and transformation of construction-related documents within the LV.AI platform. It allows users to upload various file formats, including PDF, GAEB XML, and Excel, which the AI then utilizes as a knowledge base or imports directly into project structures.
This system bridges the gap between raw external data and the internal structured representation of Bills of Quantities (LV), specifications, and project metadata. It consists of a multi-stage pipeline: frontend capture, secure API-based storage, and specialized server-side actions for parsing and database persistence.
Architecture and Data Flow
The system employs a dual-storage strategy and a specialized parsing engine. The following diagram illustrates the high-level flow from a user action to data persistence.
The diagram shows the logic for validating and routing files based on environment configuration and user permissions.
Sources: app/(chat)/api/files/upload/route.ts:43-112, app/(chat)/lv/import-actions.ts:48-75
Component Roles
- KnowledgePage: Serves as the primary management interface for the "Wissensbasis" (Knowledge Base). It supports drag-and-drop operations and displays uploaded document lists.
- Sources:
app/knowledge/page.tsx:28-112
- Sources:
- MultimodalInput: Handles file attachments directly within the chat interface, allowing the AI to process files in the context of a conversation.
- Sources:
components/chat/multimodal-input.tsx:242-302
- Sources:
- Upload API: Validates file types and sizes before persisting them to either Vercel Blob or the local file system.
- Sources:
app/(chat)/api/files/upload/route.ts:50-95
- Sources:
- Import Actions: Perform deep parsing of uploaded files, specifically targeting GAEB DA XML (X81-X89) and tabular LV text.
- Sources:
app/(chat)/lv/import-actions.ts:80-120
- Sources:
File Validation and Storage
The system enforces strict validation rules to ensure data integrity and security. Files are restricted to specific MIME types relevant to the construction industry (AVA).
Validation Rules
| Parameter | Limit / Requirement |
|---|---|
| Max File Size | 20 MB |
| Allowed Extensions | .pdf, .gaeb, .xml, .xlsx, .docx, .csv, .jpg, .png |
| MIME Types | application/pdf, application/xml, text/xml, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, etc. |
Sources: app/(chat)/api/files/upload/route.ts:10-38, app/knowledge/page.tsx:112
Storage Strategy
The system dynamically selects a storage provider based on environment variables:
- Production: Uses
vercel-blobfor scalable cloud storage whenBLOB_READ_WRITE_TOKENis present. - Development: Falls back to the local file system under
public/uploads/lv-ai/. - Naming: Filenames are sanitized and prefixed with a timestamp (
Date.now()) to prevent collisions.
Sources: app/(chat)/api/files/upload/route.ts:43-138
Document Processing and Import
Once a file is stored, it can be imported into a project. This process involves parsing the content into structured database entities like LvDocument and LvPosition.
This sequence illustrates the transformation of an uploaded file into a structured project document.
Sources: app/(chat)/lv/import-actions.ts:48-185
LV Data Normalization
During import, the system specifically handles GAEB-specific logic:
- OZ Normalization: Automatically converts invalid double-dot sequences in Ordnungszahlen (e.g.,
5..40) to single dots (5.40).- Sources:
app/(chat)/lv/import-actions.ts:133-134
- Sources:
- Format Detection: Identifies whether the content follows GAEB XML standards or tabular text formats.
- Sources:
app/(chat)/lv/import-actions.ts:92-99
- Sources:
- Truncation: Sanitizes inputs by slicing
kurztextto 500 characters andlangtextto 2000 characters to fit database constraints.- Sources:
app/(chat)/lv/import-actions.ts:145-146
- Sources:
Database Schema for Files and Documents
The system differentiates between general file attachments and structured LV documents.
| Table | Description | Key Fields |
|---|---|---|
FileProject | Metadata for files attached to a specific project. | projectId, filename, storageUrl, tags |
LvDocument | Represents a parsed GAEB/LV file. | projectId, gaebFormat, titel, storageUrl |
LvPosition | Individual items within an LV document. | lvDocumentId, oz, kurztext, menge, einheitspreis |
Document | Artifacts (text, code, sheets) created by the AI. | id, kind, content, userId |
Sources: lib/db/schema.ts:132-154, 187-230, 313-324
AI Artifact Integration
The processing system also supports the creation of "Artifacts"—AI-generated documents that can be edited or updated. Tools like createDocument allow the AI to generate spreadsheets (sheets) or text documents based on user prompts.
- createDocument: Used when the user asks to create a specification or Preisspiegel.
- Sources:
lib/ai/tools/create-document.ts:16-30
- Sources:
- updateDocument: Performs a full rewrite of an existing artifact for major changes.
- Sources:
lib/ai/tools/update-document.ts:25-30
- Sources:
- editDocument: Preferred for targeted changes, such as fixing prices or quantities in an LV.
- Sources:
lib/ai/prompts.ts:45-55
- Sources:
Summary of processing logic for LV creation:
// lib/ai/prompts.ts:85-93
export const sheetPrompt = `
You are a spreadsheet creation assistant specialized in construction industry documents.
Create spreadsheets in CSV format for Leistungsverzeichnisse, Preisspiegel, Kostenschätzungen, and other AVA documents.
Requirements:
- Use GAEB-compliant column headers (OZ, Kurztext, Langtext, ME, Menge, EP, GP)
- Include realistic construction industry data
`;
Conclusion
The File Upload & Processing module provides a robust pipeline for integrating construction data into LV.AI. By combining secure storage, industry-specific validation, and deep GAEB parsing, the system ensures that complex construction documents are accurately represented in the project database for further AI-assisted analysis and management.