# AI-Assisted Forms (typdialog-ai) **Status**: πŸ”΄ Planned (Q2 2025 target) AI-Assisted Forms is a planned feature that integrates intelligent suggestions, context-aware assistance, and natural language understanding into the typdialog web UI. This enables users to configure infrastructure through interactive forms with real-time AI guidance. ## Feature Overview ### What It Does Enhance configuration forms with AI-powered assistance: ```text User typing in form field: "storage" ↓ AI analyzes context: - Current form (database configuration) - Field type (storage capacity) - Similar past configurations - Best practices for this workload ↓ Suggestions appear: βœ“ "100 GB (standard production size)" βœ“ "50 GB (development environment)" βœ“ "500 GB (large-scale analytics)" ``` ### Primary Use Cases 1. **Guided Configuration**: Step-by-step assistance filling complex forms 2. **Error Explanation**: AI explains validation failures in plain English 3. **Smart Autocomplete**: Suggestions based on context, not just keywords 4. **Learning**: New users learn patterns from AI explanations 5. **Efficiency**: Experienced users get quick suggestions ## Architecture ### User Interface Integration ```text β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Typdialog Web UI (React/TypeScript) β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ Form Fields β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ Database Engine: [postgresql β–Ό] β”‚ β”‚ β”‚ β”‚ Storage (GB): [100 GB ↓ ?] β”‚ β”‚ β”‚ β”‚ AI suggestions β”‚ β”‚ β”‚ β”‚ Encryption: [βœ“ enabled ] β”‚ β”‚ β”‚ β”‚ "Required for β”‚ β”‚ β”‚ β”‚ production" β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ [← Back] [Next β†’] β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ ↓ β”‚ β”‚ AI Assistance Panel β”‚ β”‚ (suggestions & explanations) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ↓ ↑ User Input AI Service (port 8083) ``` ### Suggestion Pipeline ```text User Event (typing, focusing field, validation error) ↓ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Context Extraction β”‚ β”‚ - Current field and value β”‚ β”‚ - Form schema and constraints β”‚ β”‚ - Other filled fields β”‚ β”‚ - User role and workspace β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ↓ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ RAG Retrieval β”‚ β”‚ - Find similar configs β”‚ β”‚ - Get examples for field type β”‚ β”‚ - Retrieve relevant documentation β”‚ β”‚ - Find validation rules β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ↓ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Suggestion Generation β”‚ β”‚ - AI generates suggestions β”‚ β”‚ - Rank by relevance β”‚ β”‚ - Format for display β”‚ β”‚ - Generate explanation β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ↓ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Response Formatting β”‚ β”‚ - Debounce (don't update too fast) β”‚ β”‚ - Cache identical results β”‚ β”‚ - Stream if long response β”‚ β”‚ - Display to user β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## Planned Features ### 1. Smart Field Suggestions Intelligent suggestions based on context: ```text Scenario: User filling database configuration form 1. Engine selection User types: "post" Suggestion: "postgresql" (99% match) Explanation: "PostgreSQL is the most popular open-source relational database" 2. Storage size User has selected: "postgresql", "production", "web-application" Suggestions appear: β€’ "100 GB" (standard production web app database) β€’ "500 GB" (if expected growth > 1000 connections) β€’ "1 TB" (high-traffic SaaS platform) Explanation: "For typical web applications with 1000s of concurrent users, 100 GB is recommended" 3. Backup frequency User has selected: "production", "critical-data" Suggestions appear: β€’ "Daily" (standard for critical databases) β€’ "Hourly" (for data warehouses with frequent updates) Explanation: "Critical production data requires daily or more frequent backups" ``` ### 2. Validation Error Explanation Human-readable error messages with fixes: ```text User enters: "storage = -100" Current behavior: βœ— Error: Expected positive integer Planned AI behavior: βœ— Storage must be positive (1-65535 GB) Why: Negative storage doesn't make sense. Storage capacity must be at least 1 GB. Fix suggestions: β€’ Use 100 GB (typical production size) β€’ Use 50 GB (development environment) β€’ Use your required size in GB ``` ### 3. Field-to-Field Context Awareness Suggestions change based on other fields: ```text Scenario: Multi-step configuration form Step 1: Select environment User: "production" β†’ Form shows constraints: (min storage 50GB, encryption required, backup required) Step 2: Select database engine User: "postgresql" β†’ Suggestions adapted: - PostgreSQL 15 recommended for production - Point-in-time recovery available - Replication options highlighted Step 3: Storage size β†’ Suggestions show: - Minimum 50 GB for production - Examples from similar production configs - Cost estimate updates in real-time Step 4: Encryption β†’ Suggestion appears: "Recommended: AES-256" β†’ Explanation: "Required for production environments" ``` ### 4. Inline Documentation Quick access to relevant docs: ```text Field: "Backup Retention Days" Suggestion popup: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Suggested value: 30 β”‚ β”‚ β”‚ β”‚ Why: 30 days is industry-standardβ”‚ β”‚ standard for compliance (PCI-DSS)β”‚ β”‚ β”‚ β”‚ Learn more: β”‚ β”‚ β†’ Backup best practices guide β”‚ β”‚ β†’ Your compliance requirements β”‚ β”‚ β†’ Cost vs retention trade-offs β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ### 5. Multi-Field Suggestions Suggest multiple related fields together: ```text User selects: environment = "production" AI suggests completing: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Complete Production Setup β”‚ β”‚ β”‚ β”‚ Based on production environment β”‚ β”‚ we recommend: β”‚ β”‚ β”‚ β”‚ Encryption: enabled β”‚ ← Auto-fill β”‚ Backups: daily β”‚ ← Auto-fill β”‚ Monitoring: enabled β”‚ ← Auto-fill β”‚ High availability: enabled β”‚ ← Auto-fill β”‚ Retention: 30 days β”‚ ← Auto-fill β”‚ β”‚ β”‚ [Accept All] [Review] [Skip] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## Implementation Components ### Frontend (typdialog-ai JavaScript/TypeScript) ```text // React component for field with AI assistance interface AIFieldProps { fieldName: string; fieldType: string; currentValue: string; formContext: Record; schema: FieldSchema; } function AIAssistedField({fieldName, formContext, schema}: AIFieldProps) { const [suggestions, setSuggestions] = useState([]); const [explanation, setExplanation] = useState(""); // Debounced suggestion generation useEffect(() => { const timer = setTimeout(async () => { const suggestions = await ai.suggestFieldValue({ field: fieldName, context: formContext, schema: schema, }); setSuggestions(suggestions); | setExplanation(suggestions[0]?.explanation | | ""); | }, 300); // Debounce 300ms return () => clearTimeout(timer); }, [formContext[fieldName]]); return (
handleChange(e.target.value)} /> {suggestions.length > 0 && (
{suggestions.map((s) => ( ))} {explanation && (

{explanation}

)}
)}
); } ``` ### Backend Service Integration ```text // In AI Service: field suggestion endpoint async fn suggest_field_value( req: SuggestFieldRequest, ) -> Result> { // Build context for the suggestion let context = build_field_context(&req.form_context, &req.field_name)?; // Retrieve relevant examples from RAG let examples = rag.search_by_field(&req.field_name, &context)?; // Generate suggestions via LLM let suggestions = llm.generate_suggestions( &req.field_name, &req.field_type, &context, &examples, ).await?; // Rank and format suggestions let ranked = rank_suggestions(suggestions, &context); Ok(ranked) } ``` ## Configuration ### Form Assistant Settings ```text # In provisioning/config/ai.toml [ai.forms] enabled = true # Suggestion delivery suggestions_enabled = true suggestions_debounce_ms = 300 max_suggestions_per_field = 3 # Error explanations error_explanations_enabled = true explain_validation_errors = true suggest_fixes = true # Field context awareness field_context_enabled = true cross_field_suggestions = true # Inline documentation inline_docs_enabled = true docs_link_type = "modal" # or "sidebar", "tooltip" # Performance cache_suggestions = true cache_ttl_seconds = 3600 # Learning track_accepted_suggestions = true track_rejected_suggestions = true ``` ## User Experience Flow ### Scenario: New User Configuring PostgreSQL ```text 1. User opens typdialog form - Form title: "Create Database" - First field: "Database Engine" - AI shows: "PostgreSQL recommended for relational data" 2. User types "post" - Autocomplete shows: "postgresql" - AI explains: "PostgreSQL is the most stable open-source database" 3. User selects "postgresql" - Form progresses - Next field: "Version" - AI suggests: "PostgreSQL 15 (latest stable)" - Explanation: "Version 15 is current stable, recommended for new deployments" 4. User selects version 15 - Next field: "Environment" - User selects "production" - AI note appears: "Production environment requires encryption and backups" 5. Next field: "Storage (GB)" - Form shows: Minimum 50 GB (production requirement) - AI suggestions: β€’ 100 GB (standard production) β€’ 250 GB (high-traffic site) - User accepts: 100 GB 6. Validation error on next field - Old behavior: "Invalid backup_days value" - New behavior: "Backup retention must be 1-35 days. Recommended: 30 days. 30-day retention meets compliance requirements for production systems." 7. User completes form - Summary shows all AI-assisted decisions - Generate button creates configuration ``` ## Integration with Natural Language Generation NLC and form assistance share the same backend: ```text Natural Language Generation AI-Assisted Forms ↓ ↓ "Create a PostgreSQL db" Select field values ↓ ↓ Intent Extraction Context Extraction ↓ ↓ RAG Search RAG Search (same results) ↓ ↓ LLM Generation LLM Suggestions ↓ ↓ Config Output Form Field Population ``` ## Success Criteria (Q2 2025) - βœ… Suggestions appear within 300ms of user action - βœ… 80% suggestion acceptance rate in user testing - βœ… Error explanations clearly explain issues and fixes - βœ… Cross-field context awareness works for 5+ database scenarios - βœ… Form completion time reduced by 40% with AI - βœ… User satisfaction > 8/10 in testing - βœ… No false suggestions (all suggestions are valid) - βœ… Offline mode works with cached suggestions ## Related Documentation - [Architecture](architecture.md) - AI system overview - [Natural Language Config](natural-language-config.md) - Related generation feature - [RAG System](rag-system.md) - Suggestion retrieval - [Configuration](configuration.md) - Setup guide - [ADR-015](../architecture/adr/adr-015-ai-integration-architecture.md) - Design decisions --- **Status**: πŸ”΄ Planned **Target Release**: Q2 2025 **Last Updated**: 2025-01-13 **Component**: typdialog-ai **Architecture**: Complete **Implementation**: In Design Phase