Commit graph

3590 commits

Author SHA1 Message Date
a2b091914f fix(bootstrap): start_all() must re-bootstrap when Vault unseal fails
When start_all() detects Vault init.json is missing (unseal fails),
it now:
1. Kills all stack processes
2. Cleans the stack directory
3. Runs full bootstrap()
4. Returns (bootstrap starts all services)

Also made SecretsManager init failure in start_all() a hard error
instead of a warning - if Vault is supposed to be working but
SecretsManager can't connect, that's a fatal error.
2025-12-09 08:56:58 -03:00
1e98083d13 fix(bootstrap): Write .env IMMEDIATELY after Vault unseal, re-init SecretsManager
The core issue was that .env was written at the END of setup_vault(),
but other components needed Vault credentials BEFORE that.

Now:
1. Unseal Vault
2. Write .env with VAULT_ADDR and VAULT_TOKEN immediately
3. Re-initialize SecretsManager so it connects to Vault
4. THEN store secrets in Vault

This ensures SecretsManager is properly configured before any
code tries to use create_conn() or other Vault-dependent functions.
2025-12-09 08:52:19 -03:00
87f4052b82 debug: Add explicit branch logging to trace bootstrap flow 2025-12-09 08:26:29 -03:00
4ea3b76adc fix(bootstrap): Skip early SecretsManager init if bootstrap incomplete, add logging
- Only initialize SecretsManager early if .env and init.json exist
- Fix error handling for bootstrap() - no longer silently ignores failures
- Add detailed logging to trace bootstrap flow
- Log component installation decisions (installed, needs_install flags)
2025-12-09 08:10:47 -03:00
715a60315e feat(console): Add scrolling support for System Logs and Editor panels
System Logs:
- Add scroll_offset tracking with auto-scroll to bottom on new logs
- Up/Down/j/k keys to scroll line by line
- PageUp/PageDown for page scrolling
- Home/End to jump to top/bottom
- Show scroll indicators in title: [^v], [SCROLL] when not auto-scrolling
- Display log count in title

Editor:
- Fix scroll_offset to follow cursor when moving up/down
- Add PageUp/PageDown for faster navigation
- Add Ctrl+Home/Ctrl+End to jump to start/end of file
- ensure_cursor_visible() keeps cursor in view

Tab Navigation:
- FileTree -> Editor (if open) or Logs -> Chat -> back to start
- Consistent cycling through all panels
2025-12-09 08:06:30 -03:00
824b12365b fix(bootstrap): Initialize SecretsManager after Vault starts in start_all/ensure_services_running
When services are already configured (bootstrap completed), the code
calls start_all() or ensure_services_running() which starts Vault
but didn't initialize SecretsManager. This caused create_conn() to
fail with 'Vault not configured' even though Vault was running.

Now both functions initialize SecretsManager after Vault is unsealed,
ensuring database connections can retrieve credentials from Vault.
2025-12-09 07:58:39 -03:00
583e764bb9 chore: Remove emoji icons from log messages and UI
Replace emoji icons with plain text/ASCII equivalents to prevent
encoding issues and improve console compatibility:
- Replace checkmarks with *
- Replace x marks with x
- Replace status indicators with text [OK], [ERR], etc.
- Remove decorative emojis from info/debug log messages
- Keep functional emojis in user-facing chat/sentiment features
2025-12-09 07:55:11 -03:00
b204aebd50 fix(bootstrap): Run migrations with direct password before Vault is set up
The bootstrap order is vault -> tables -> directory. When tables
component was processed, it tried to call establish_pg_connection()
which requires Vault, but Vault setup only happens when processing
the vault component (which is earlier in the loop but the if-block
for tables runs for the tables component, not vault).

Fix: Run migrations directly with the generated password during the
tables component setup, before Vault is configured. This avoids the
dependency on Vault being set up.
2025-12-09 07:49:01 -03:00
49d1d0cf2e fix(bootstrap): Suppress all subprocess output to prevent console UI corruption
- Redirect Vault exec_cmd output to logs/vault.log
- Add stdout/stderr null pipes to component spawn in installer.rs
- Suppress output in run_commands() in facade.rs
- All component output now goes to respective log files in logs/
2025-12-09 01:09:04 -03:00
ffdc39a6fd config: Enable llm-server by default for clean stack installs 2025-12-09 00:28:46 -03:00
21855fab99 fix(llm): Respect llm-server config flag to skip local server startup
When llm-server=false in bot_configuration, the code now skips
attempting to start local llama-server processes. This prevents
the 60-attempt timeout error when using external LLM endpoints
or when local LLM serving is intentionally disabled.
2025-12-08 23:39:01 -03:00
f3e38d8d8b feat(console): Show UI immediately with live system logs
- Add state_channel field to XtreeUI for receiving AppState updates
- Add set_state_channel() method to enable async state communication
- Poll for AppState in event loop to initialize panels when ready
- UI now shows loading state instantly, logs stream in real-time
- Transitions to full interactive mode when AppState is received
2025-12-08 23:35:33 -03:00
5f71614451 fix: remove duplicate logger init causing 'cannot set logger' error
Logger is already initialized in main.rs, cli.rs was trying to
initialize it again when CLI commands were run.
2025-12-08 17:59:43 -03:00
d73d782659 fix: preserve cached files in botserver-installers after extraction
- Don't delete archive files from cache after tar/zip extraction
- Copy binaries from cache instead of moving them
- Cached files are now preserved for offline installation reuse
2025-12-08 14:19:55 -03:00
89e92a4739 feat: add offline installer cache and health endpoints
- Add /health and /api/health endpoints for botui connectivity
- Create 3rdparty.toml with all download URLs for offline bundles
- Add botserver-installers/ cache directory for downloaded files
- Implement DownloadCache module with:
  - Automatic cache lookup before downloading
  - Support for pre-populated offline bundles
  - SHA256 checksum verification (optional)
  - Cache management utilities (list, clear, size)
- Update download_and_install to use cache system
- Data files (models) also cached for reuse

Cache behavior:
- First run: downloads to botserver-installers/
- Subsequent runs: uses cached files
- Delete botserver-stack/ without losing downloads
- Pre-populate cache for fully offline installation
2025-12-08 14:08:49 -03:00
89ff716bef Fix Vault CLI mTLS issue - unset client cert env vars before CLI commands 2025-12-08 09:14:31 -03:00
f7ccc95e60 Fix config.csv loading on startup
- Disable TLS on Vault for local development (HTTP instead of HTTPS)
- Fix bot_configuration id column type mismatch (TEXT -> UUID)
- Add migration 6.1.1 to convert config table id columns to UUID
- Fix sync_config_csv_to_db to use UUID binding for id column
- Make start_all async with proper Vault startup sequence
- Sync default.gbai config.csv to existing 'Default Bot' from migrations
- Add diagnostic logging for config loading
- Change default LLM/embedding URLs from https to http for local dev
2025-12-08 00:19:29 -03:00
59f3bb8c7e refactor: standardize component names for certificates and DNS
- Rename service names to component names:
  - postgres -> tables
  - minio -> drive
  - redis -> cache
  - qdrant -> vectordb
  - mail -> email

- Update bootstrap certificate generation with new hostnames
- Update CoreDNS zone file with component-based DNS entries
- Update CA service certificates to use component names
- Update CA directory creation to use component names

All certificates include 127.0.0.1 as SAN for IP-based mTLS access
2025-12-07 10:42:02 -03:00
b225d7e83c chore: Update secrets module and remove task files 2025-12-07 09:57:05 -03:00
cfa1a01bc9 feat(bootstrap): implement mTLS for Vault access
- Add create_vault_config() function to generate config.hcl with mTLS settings
- Configure Vault to require client certificate verification
- Generate client certificate for botserver in bootstrap
- Update .env to include mTLS paths (VAULT_CACERT, VAULT_CLIENT_CERT, VAULT_CLIENT_KEY)
- Remove unused import in tls.rs
2025-12-07 02:13:28 -03:00
41f5847f56 Add --stack-path CLI option for custom stack path
Allows overriding the default botserver-stack location via:
- --stack-path /path/to/stack CLI argument
- BOTSERVER_STACK_PATH environment variable

Useful for testing botserver bootstrap in isolated temp directories.
2025-12-06 14:55:42 -03:00
67c971557e Update: General project updates 2025-12-06 11:09:12 -03:00
38cb30276f Add test infrastructure: AppState::default(), mock providers, fix attendance tests
- Add Default impl for AppState with mock services for testing
- Add MockLLMProvider for tests that need LLM without real API
- Add create_mock_auth_service() for Zitadel testing
- Add test_utils.rs with TestAppStateBuilder, MockChannelAdapter
- Enable rhai 'sync' feature to fix Send+Sync for Dynamic types
- Fix attendance.rs tests to use pure functions (no DB required)
- Fix on_error.rs tests to use String instead of i32
- Remove unused imports in attendance.rs

All tests pass, 0 warnings, 0 errors.
2025-12-05 16:43:14 -03:00
1b669d4c11 feat(attendance): Multi-channel attendant config (email, phone, teams, google)
- Add email, teams, google columns to attendant.csv
- Add find_attendant_by_identifier() for multi-channel lookup
- Add find_attendants_by_channel() and find_attendants_by_department()
- Implement handle_status_command with database persistence
- Implement handle_transfer_command with actual transfer logic
- Update AttendantCSV struct with all new fields
2025-12-05 14:54:55 -03:00
bde3244ce9 feat(attendance): Add LLM-assisted attendant features
- Real-time tips when customer messages arrive
- Message polishing with one click
- Smart reply generation (3 contextual suggestions)
- Auto-summary when attendant takes conversation
- LLM-powered sentiment analysis with escalation warnings

WhatsApp Attendant Commands:
- /queue, /take, /status, /transfer, /resolve
- /tips, /polish, /replies, /summary, /help
- Portuguese versions: /fila, /pegar, /dicas, /polir, /respostas, /resumo

Config options (config.csv):
- attendant-llm-tips
- attendant-polish-message
- attendant-smart-replies
- attendant-auto-summary
- attendant-sentiment-analysis

API Endpoints:
- POST /api/attendance/llm/tips
- POST /api/attendance/llm/polish
- POST /api/attendance/llm/smart-replies
- GET /api/attendance/llm/summary/{session_id}
- POST /api/attendance/llm/sentiment
- GET /api/attendance/llm/config/{bot_id}

Uses bot's system prompt for consistency between bot and human-assisted responses.
2025-12-05 13:47:15 -03:00
415c7cce77 refactor: rename redis-cache feature to cache
- Simplified feature name from 'redis-cache' to 'cache'
- Updated Cargo.toml feature definitions
- Updated state.rs cfg attributes
- More concise naming
2025-12-05 12:09:02 -03:00
b1193afda2 feat: unified keywords with spaces, ON ERROR RESUME NEXT, unified DELETE
Keywords now use spaces instead of underscores:
- SEND MAIL (was SEND_MAIL)
- GENERATE PDF (was GENERATE_PDF)
- MERGE PDF (was MERGE_PDF)
- SET HEADER (was SET_HEADER)
- CLEAR HEADERS (was CLEAR_HEADERS)

New ON ERROR RESUME NEXT implementation:
- ON ERROR RESUME NEXT - enable error trapping
- ON ERROR GOTO 0 - disable error trapping
- CLEAR ERROR - clear error state
- ERROR MESSAGE - get last error message
- ERR - get error number

Unified DELETE keyword:
- DELETE url - HTTP DELETE (auto-detected)
- DELETE table, filter - Database DELETE
- DELETE path - File DELETE

Changes:
- errors/on_error.rs: New VB-style error handling
- errors/mod.rs: Include on_error module
- send_mail.rs: SEND MAIL with spaces
- file_operations.rs: GENERATE PDF, MERGE PDF with spaces
- data_operations.rs: Unified DELETE with auto-detection
- http_operations.rs: Cleaned up DELETE HTTP
- compiler/mod.rs: Removed underscore normalization
- mod.rs: Updated command list
2025-12-05 09:55:13 -03:00
2e2fc43454 Update sync endpoints as desktop-only, add documentation fields
- /files/sync/status now returns is_desktop=false for web users
- /files/sync/start|stop return helpful message about desktop app requirement
- Add detailed docstrings pointing to botapp/src/desktop/sync.rs
- SyncStatus struct extended with is_desktop and message fields
2025-12-05 06:50:45 -03:00
26f7643f5c feat(auth): Add OAuth login for Google, Discord, Reddit, Twitter, Microsoft, Facebook
- Create core/oauth module with OAuthProvider enum and shared types
- Implement providers.rs with auth URLs, token exchange, user info endpoints
- Add routes for /auth/oauth/providers, /auth/oauth/{provider}, and callbacks
- Update login.html with OAuth button grid and dynamic provider loading
- Add OAuth config settings to config.csv with setup documentation and links
- Uses HTMX for login form, minimal JS for OAuth provider visibility
2025-12-04 22:53:40 -03:00
0c11cf8d5c feat(email): implement email read tracking with pixel support
- Add email-read-pixel config parameter to enable/disable tracking
- Implement tracking pixel injection in HTML emails
- Add sent_email_tracking table with migration
- Create 4 new API endpoints:
  - GET /api/email/tracking/pixel/{id} - serve pixel & record read
  - GET /api/email/tracking/status/{id} - get email read status
  - GET /api/email/tracking/list - list all tracked emails
  - GET /api/email/tracking/stats - get aggregate statistics
- Store tracking data: read_at, read_count, IP, user_agent
- Integrate with send_email() to auto-inject pixel when enabled
2025-12-04 18:15:09 -03:00
896156609b Update PROMPT.md with new LLM workflow and coding rules
New rules added:
- Two LLM work modes: Execution (fazer) vs Review (conferir)
- Rust code only in architecture.md (gbapp chapter)
- Scan and delete misplaced ALL_CAPS.md files
- HTMX-first: minimize JS, delegate to server
- Local assets only: no CDN references
- Documentation validation process for chapters
- No dead code: implement real code, never use _ prefix
- cargo audit must pass with 0 warnings
- diesel only, remove sqlx references
- Library consolidation guidance
2025-12-04 13:55:19 -03:00
d1301c9cd8 Add balanced documentation structure
Documentation organized with equilibrium:
- Small (50-100 lines): Index files
- Medium (250-400 lines): Guides
- Large (450-600 lines): Complete references

Structure:
- docs/api/ - REST endpoints, WebSocket
- docs/guides/ - Getting started, deployment, templates
- docs/reference/ - BASIC language, configuration, architecture

Updated README.md to point to new docs location.
2025-12-04 12:44:18 -03:00
78b359ab06 Remove obsolete CAPS.md documentation files
Deleted planning/tracking documents that are no longer needed:
- MISSING_IMPLEMENTATIONS.md (all 5 apps now implemented)
- GAP_ANALYSIS.md (analysis complete, implemented)
- IMPLEMENTATION_SUMMARY.md (implementations done)
- LIBRARY_MIGRATION.md (migration guide)
- ROADMAP.md (feature planning)
- START_CODING_PROMPT.md (coding guide)
- CHANGELOG.md (version history)
- templates/TEMPLATE_PLAN.md (template planning)
- templates/integration/public-apis.gbai/KEYWORDS_CHECKLIST.md
- templates/integration/public-apis.gbai/QUICKSTART.md
- botlib/VERSION.md (version history)

Kept: README.md, PROMPT.md, and SUMMARY.md (mdbook structure)
2025-12-04 12:28:05 -03:00
5b8b1cf7aa Implement real database functions, remove TODOs and placeholders
- CRM Lead Scoring: Implement get_lead_score_from_db and update_lead_score_in_db
  using bot_memories table with diesel queries
- Bot Manager: Implement real org lookup from database and template loading from filesystem
- KB Manager: Implement get_collection_info to query Qdrant for real statistics
- Analytics: Replace placeholder metrics with actual database queries for users,
  sessions, and storage stats
- Email Setup: Implement Stalwart admin account creation via management API
- Add CollectionInfo struct for Qdrant collection metadata

All implementations use diesel for database operations, no sqlx.
2025-12-03 22:23:30 -03:00
afbffeb934 - botbook extracted from. 2025-12-03 19:59:27 -03:00
7a5e369402 Add comprehensive documentation for GB templates and configuration
modules

Add detailed README documentation for 15+ bot templates including:
- Platform analytics, BI reporting, and web crawler templates
- CRM, contacts, and marketing automation templates
- Legal document processing and office productivity templates
- LLM tools, LLM server, and API client integration templates
- Reminder management and meta-template for creating new templates

Add new Rust configuration modules:
- BM25 config for Tantivy-based sparse
2025-12-03 16:05:50 -03:00
ad311944b8 Update dependencies and remove problematic crates
Drop image (with ravif/paste), sqlx, zitadel, and related dependencies
that were causing compilation issues. Replace image processing with
direct png crate usage. Update rcgen to 0.14 with new API changes.
Refactor CA certificate generation to use Issuer pattern.
2025-12-03 16:05:30 -03:00
e8d171ea40 - New templates. 2025-12-03 07:15:54 -03:00
b7975497aa - Split into botui. 2025-12-02 21:09:43 -03:00
e7fe4e5526 Add documentation infrastructure and certificate pinning
- Add mdBook configuration (book.toml) for documentation
- Create new docs style guide appendix for conversation examples
- Add WhatsApp-style chat CSS for consistent doc formatting
- Replace flow diagram references with screen mockup SVGs
- Create comprehensive SVG interface mockups for all Suite apps:
  - Main suite layout and individual app screens
  - Analytics, Calendar, Chat, Compliance, Designer
  - Drive, Mail, Meet, Paper, Player, Research
  - Sources, Tasks interfaces
- Implement certificate pinning module (cert_pinning.rs) with:
  - SPKI fingerprint validation using SHA-256
  - Support for primary and backup pins
  - Pin rotation with expiration tracking
  - Report-only mode for testing
  - Validation caching for performance
- Add ring crate dependency for cryptographic operations
2025-12-01 16:15:52 -03:00
55d092472b Add monitoring dashboard with live system visualization
Introduce an interactive SVG-based monitoring dashboard that displays:
- Central BotServer node with animated status indicators
- Service nodes for PostgreSQL, Qdrant, MinIO, BotModels, Cache, and
  Vault
- Animated data flow connections between services
- Real-time metrics panels (sessions, messages, response time)
- Resource utilization bars (CPU, memory, GPU, disk)
- Live activity ticker

The HTML version includes
2025-12-01 08:35:47 -03:00
09ccb5e0dd Update monitoring dashboard with animated SVG visualization
Replace static grid layout with interactive live system view featuring:
- Animated data packets flowing between service nodes
- Real-time metrics panels with HTMX polling
- Service status dots with pulse animations
- Resource utilization bars
- Live activity ticker
- Toggle between Live and Grid views (V key)

Documentation updated to reflect new visualization and API endpoints.
2025-12-01 08:35:28 -03:00
2d0c00cd71 - SVG UI. 2025-12-01 02:22:35 -03:00
ffd492a75f Add toml dependency for Askama custom filters config 2025-11-30 23:48:08 -03:00
fd764709fc Add template samples and compliance API documentation
- Add template-samples.md with ready-to-use bot examples and sample
  conversations for CRM, FAQ, calendar, HR, sales, IT helpdesk,
  compliance, broadcast, and analytics templates
- Add compliance-api.md with full REST API reference for data subject
  requests, consent management, scanning
2025-11-30 22:39:24 -03:00
ab98cfd82e Add template samples and compliance API docs to summary 2025-11-30 22:39:00 -03:00
c414a99d58 - Screen manuals. 2025-11-30 22:33:54 -03:00
e68a12176d Add Suite app documentation, templates, and Askama config
- Add askama.toml for template configuration (ui/ directory)
- Add Suite app documentation with flow diagrams (SVG)
  - App launcher, chat flow, drive flow, tasks flow
  - Individual app docs: chat, drive, tasks, mail, etc.
- Add HTML templates for Suite apps
  - Base template with header and app launcher
  - Auth login page
  - Chat, Drive, Mail, Meet, Tasks templates
  - Partial templates for messages, sessions, notifications
- Add Extensions type to AppState for type-erased storage
- Add mTLS module for service-to-service authentication
- Update web handlers to use new template paths (suite/)
- Fix auth module to avoid axum-extra TypedHeader dependency
2025-11-30 21:00:48 -03:00
36d5f3838c Add Suite user manual and HTMX architecture documentation
- Add comprehensive user manual covering all Suite applications
- Document HTMX architecture patterns used throughout the UI
- Complete designer.html JavaScript implementation
- Complete sources/index.html with remaining UI and event handlers
- Update SUMMARY.md with new documentation entries
2025-11-30 19:50:47 -03:00
5edb45133f Add docs, UI pages, code scanner, and Docker deployment guide
- Add CRM contacts template documentation
- Add Docker deployment documentation with compose examples
- Add BASIC code scanner for security compliance checking
- Add visual dialog designer UI (designer.html)
- Add drive file manager UI (drive/index.html)
- Add sources browser UI (sources/index.html)
- Add compliance report tool UI (tools/compliance.html)
2025-11-30 19:36:50 -03:00