Commit graph

3613 commits

Author SHA1 Message Date
892572843c fix: remove trailing slash from default LLM URL configuration
The default LLM service URL was changed from `http://localhost:8081/` to `http://localhost:8081`.
Both the configuration lookup default and the fallback string are updated to omit the trailing slash. This prevents accidental double‑slashes when constructing request paths and aligns the default with expected endpoint formatting.
2025-11-07 16:52:21 -03:00
67eb58cc43 feat(config): update default LLM URL to root endpoint
Changed the fallback LLM service URL from `http://localhost:8081/v1` to `http://localhost:8081/`. This aligns the default endpoint with the updated API that no longer requires the `/v1` path, ensuring the application connects correctly when no custom configuration is provided.
2025-11-07 16:45:19 -03:00
9e1370c04f refactor(bot): limit lock scope for history and tidy progress output
- Reordered imports for clarity (chrono and tokio::time::Instant).
- Fixed comment indentation around compact automation note.
- Refactored session history retrieval to acquire the mutex only briefly, then process compacted message skipping and history limiting outside the lock.
- Added explanatory comments for the new lock handling logic.
- Cleaned up token progress calculation and display formatting, improving readability of GPU/CPU/TOKENS bars.
- Minor formatting adjustments throughout the file.
2025-11-07 16:43:49 -03:00
120d06a0db chore: point LLM client and default configs to local endpoint
Updated the 6.0.4 migration to use `http://localhost:8081/v1` for the default OpenAI model configurations (gpt‑4 and gpt‑3.5‑turbo) and the local embed service. Adjusted `OpenAIClient` to default to the same localhost base URL instead of the production OpenAI API.

Reorganized imports and module ordering in `src/main.rs` (moved `mod llm`, `mod nvidia`, and `BotOrchestrator` import), cleaned up formatting, and removed unused imports. These changes streamline development by directing LLM calls to a local server and improve code readability.
2025-11-07 16:40:19 -03:00
21355df0c8 refactor(bot): disable history retrieval and simplify LLM args
Removed the conversation history loading logic in `BotOrchestrator` and replaced it with a placeholder string, commenting out related prompt construction and tracing. This change streamlines prompt generation while debugging and prevents unnecessary history processing.

In the local LLM server setup, eliminated the `llm-server-ctx-size` configuration and its corresponding command‑line argument, as the context size parameter is no longer required. This simplifies server initialization and avoids passing an unused flag.
2025-11-07 16:35:48 -03:00
dca836a429 fix: redirect LLM server logs to local files instead of deep path
Adjusted the command strings used to start the LLM and embedding servers on both Windows and Unix.
- Replaced the previous log redirection `../../../../logs/llm/stdout.log` with simpler local files (`llm-stdout.log` and `stdout.log`).
- Updated both normal and embedding server launch commands to use the new paths.

This change simplifies log management, ensures logs are correctly written regardless of the working directory, and resolves issues where the previous relative path could be invalid or inaccessible.
2025-11-07 16:19:48 -03:00
e7e84c6cfc refactor: inject AppState into automation & bot, drop Default impl
- Updated `execute_compact_prompt` to accept an `Arc<AppState>` instead of creating a new default state, enabling proper state sharing across tasks.
- Adjusted bot orchestration to clone and pass the existing `AppState` to the automation task, ensuring the same connection and configuration are used.
- Removed the `Default` implementation for `AppState`, preventing accidental creation of a default state with hard‑coded DB connections and services.
- Modified `BotOrchestrator::default` to panic, enforcing explicit construction via `BotOrchestrator::new(state)` for clearer dependency injection.

These changes improve testability, avoid hidden side‑effects from default state initialization, and ensure consistent use of the application state throughout the system.
2025-11-07 16:13:47 -03:00
856e2f0252 feat(bot): persist user messages and refine session handling
Add logic to save user messages to session history for better traceability and context continuity. Simplify session creation error handling and remove redundant warning on closed response channel. Update README with guidance on maintaining production-ready source code.
2025-11-07 10:26:34 -03:00
ab7abacbe3 refactor(bootstrap): remove unused warn import from log module
Removed the unused `warn` import from the `log` module in `mod.rs` to clean up unused dependencies and improve code clarity.
2025-11-07 10:16:49 -03:00
8581927d97 refactor(logging): update component names and adjust log levels
Renamed PostgreSQL references to "Tables" for clarity in bootstrap logs, changed config sync logging from info to trace for reduced verbosity, and made session message clearing method private to limit external access.
2025-11-07 10:11:08 -03:00
9c3fde5eb7 feat(bot, web): improve progress display and simplify context indicator
Use `print!` with stdout flush for smoother in-place GPU/CPU/token progress updates in the bot module. Simplify context indicator logic in the web UI by always removing visibility class to streamline behavior.
2025-11-07 10:01:05 -03:00
053e76a0a2 feat(prompt-compaction): add compacted message handling and forced compaction
Refactored prompt compaction to use a special compacted message type (9) instead of clearing old messages. Added support for forced compaction when threshold is negative and updated history retrieval to skip messages before the last compacted marker. This improves efficiency and preserves summary continuity.
2025-11-07 09:54:04 -03:00
3f187feccb fix: add PostgreSQL auto-start and silence unused variable warnings
Added a check in `BootstrapManager` to detect if PostgreSQL is running and attempt to start the "tables" component automatically if not. Also prefixed unused variables and struct fields with underscores in compiler, session, and model modules to suppress warnings and improve code clarity.
2025-11-07 09:37:45 -03:00
1a4b56e312 feat(automation): add compaction lock and improve prompt summarization
Added `once_cell` and `scopeguard` dependencies to implement thread-safe compaction lock mechanism. Modified `compact_prompt_for_bot` to:
- Prevent concurrent compaction for the same bot using a global lock
- Add proper tracing and error handling
- Improve summarization with content filtering
- Clean up locks automatically using scopeguard
- Remove redundant threshold check and compact entire history

The changes ensure thread safety during prompt compaction and provide better observability through tracing.
2025-11-06 18:02:04 -03:00
4ce06daf75 feat(automation): improve prompt compaction with async LLM summarization
- Added initial 30s delay to compact prompt scheduler
- Implemented async LLM summarization for conversation history
- Reduced lock contention by minimizing critical sections
- Added fallback to original text if summarization fails
- Updated README with guidance for failed requirements
- Added new `summarize` method to LLMProvider trait
- Improved session manager query with proper DSL usage

The changes optimize the prompt compaction process by:
1. Reducing lock contention through better resource management
2. Adding LLM-based summarization for better conversation compression
3. Making the system more resilient with proper error handling
4. Improving documentation for development practices
2025-11-06 17:07:12 -03:00
df0536f739 feat(automation): add compact prompt scheduler and improve code formatting
Added new compact_prompt module and its scheduler initialization in AutomationService.
Refactored code for better readability:
- Improved import organization
- Fixed indentation in schedule checking logic
- Enhanced error handling with more descriptive messages
- Formatted long lines for better readability
- Added comments for clarity

The changes maintain existing functionality while making the code more maintainable.
2025-11-06 16:15:54 -03:00
b997548cf3 docs(readme): add platform overview and simplify setup steps
Expanded README with detailed feature matrix and enterprise capabilities for the self-host AI automation platform. Simplified setup instructions by removing redundant configuration and build steps to improve clarity and onboarding experience.
2025-11-06 11:49:52 -03:00
f2317d16c9 feat: update logging config and enable automation modules
- Update RUST_LOG configuration in launch.json to include trace level and additional module filters
- Uncomment and enable multiple directories in add-req.sh script
- Add execute_compact_prompt function to automation module
- Extend BasicCompiler comment detection to handle single quotes
- Modify BotOrchestrator system message prefix from "SYSTEM" to "SYS"
- Add placeholder for compact prompt automation in BotOrchestrator initialization

Changes improve debugging capabilities and enable previously commented-out automation features while maintaining existing functionality.
2025-11-05 22:48:55 -03:00
b614d2650a feat: add cron dependency and theme broadcast functionality
Add the `cron` crate (v0.15.0) to Cargo.toml and Cargo.lock to enable scheduling capabilities.
Introduce a new `broadcast_theme_change` helper in `src/automation/mod.rs` that parses CSV theme data and pushes JSON theme update events to all active response channels.
Clean up unused imports in the automation module and add `ConfigManager` import for future configuration handling.
Update `add-req.sh` to adjust the list of processed directories (comment out `auth`, enable `basic`, `config`, `context`, and `drive_monitor`).
These changes lay groundwork for scheduled tasks and dynamic theme updates across the application.
2025-11-05 21:10:03 -03:00
04c2d0d0ce feat: update botserver to v6.0.7 and adjust authors list
- Updated botserver version from 6.0.5 to 6.0.7 in Cargo.toml and Cargo.lock
- Removed old Rodrigo Rodriguez entry from authors list
- Added new Rodrigo Rodriguez entry with updated email
- Maintained all other existing authors in the list
2025-11-05 20:33:17 -03:00
9cc1c11d66 feat(bot): add configurable history limit for conversation prompts
Added support for configurable conversation history limits through bot configuration. The bot now reads 'prompt-history' from config (defaulting to -1 for unlimited) and trims the conversation history accordingly before generating prompts. Updated announcements bot template to use history limit of 2 messages instead of the previous compact setting.
2025-11-05 20:18:34 -03:00
b2760113af fix(migrations, ui): remove redundant constraint check and logo click handler
Removed `IF NOT EXISTS` from the unique constraint in `system_automations` to ensure proper enforcement, and deleted the unused `floatLogo` click event listener to clean up UI behavior.
2025-11-05 15:29:01 -03:00
7493c69fec feat(announcements): add theme colors and custom logo config
Added new configuration options for theme colors (green, yellow) and a custom logo URL to enhance branding and visual customization in announcement templates.
2025-11-05 15:23:02 -03:00
741d736715 feat: update deepseek_r3 regex and add test case
Updated the regex pattern in DeepseekR3Handler to use (?s) flag for dot-matches-newline behavior when removing <think> tags. Added comprehensive test case that verifies the handler correctly processes content with multiline think tags. Also made styling changes to the web interface, though the full diff was truncated.
2025-11-05 14:28:14 -03:00
cc741b378e feat: simplify LLM prompt and add debug logging
- Simplified build_llm_prompt by removing redundant formatting
- Added info logging for LLM model and processed content
- Updated README with development philosophy note
- Adjusted announcement schedule timing from 55 to 59 minutes past the hour
2025-11-05 14:15:12 -03:00
aac36afaba feat(nvidia): mark unused params in get_system_metrics
Mark current_tokens and max_tokens parameters as unused in get_system_metrics function by prefixing them with underscores. This change clarifies that these parameters are intentionally unused in the function implementation while maintaining the function signature for potential future use.
2025-11-05 13:47:19 -03:00
c7fbb46e49 feat: remove unused dependencies and clean up Cargo.lock
Removed several unused dependencies from Cargo.lock including:
- auto_generate_cdp
- headless_chrome
- scraper
- cssparser and related crates
- dtoa and dtoa-short
- string_cache and related crates
- tendril
- tungstenite 0.27.0

Also updated ureq dependency to single version (removed duplicate entry). This cleanup reduces the dependency tree and removes unused code.
2025-11-05 13:46:03 -03:00
45e4a5e735 feat: improve prompt formatting and system metrics
- Update prompt formatting in BotOrchestrator to use clearer labels (SYSTEM/CONTEXT) with emphasis markers
- Remove unused token_ratio field from SystemMetrics struct
- Increase default context size (2048->4096) and prediction length (512->1024) in config
- Clean up metrics calculation by removing redundant token ratio computation

The changes improve readability of system prompts and simplify metrics collection while increasing default model capacity.
2025-11-05 12:46:08 -03:00
dc0e0a9c51 feat: add sysinfo dependency and system metrics support
Added the sysinfo crate (v0.37.2) to gather system metrics. This includes:
- New dependencies: sysinfo, ntapi, objc2-core-foundation, objc2-io-kit
- Updated windows-core to specific version 0.62.2
- Initial system metrics integration in bot module

The change enables monitoring system resources which will be used for performance optimization and health monitoring.
2025-11-05 12:28:34 -03:00
ac9c1509d5 feat(llm): improve logging and content processing
- Add 'keyword' to LLM processing log message for better context
- Replace simple string replace with regex for removing <think> tags in DeepseekR3 model
- The changes provide more precise logging and more robust content processing
2025-11-05 10:35:54 -03:00
e3bd06ff54 feat(db): add unique constraint to system_automations and fix clicks PK
- Added migration 6.0.6 to enforce a unique constraint on `(bot_id, kind, param)` in `system_automations`, preventing “no unique or exclusion constraint matching the ON CONFLICT specification” errors, and created a supporting index.
- Added migration 6.0.7 to replace the `clicks` table with a correctly defined primary key and a unique `(campaign_id, email)` constraint, satisfying Diesel
2025-11-05 10:19:02 -03:00
7c69284f07 feat(compiler): clean up stale schedules on script recompilation
Added tracking of previously scheduled scripts using a `HashSet` and initialized it in `BasicCompiler::new`. Updated `compile_file` and `preprocess_basic` to require mutable access, allowing schedule cleanup before processing. Implemented logic to delete existing scheduled automations for a script using Diesel queries, ensuring old schedules are removed when a script is recompiled without a `SET_SCHEDULE`. Added necessary Diesel imports and `TriggerKind` reference. This prevents duplicate or orphaned scheduled tasks.
2025-11-05 10:15:36 -03:00
72f7081acb feat(schedule): optimize set_schedule with update-first approach
Changed the set_schedule function to first attempt updating existing records before inserting new ones. This improves efficiency by avoiding unnecessary insert conflicts and subsequent updates. The logic now:
1. Tries to update matching existing schedule first
2. Only performs insert if no matching record was found
3. Maintains same functionality but with better performance
2025-11-05 09:05:25 -03:00
02c36a8888 feat(db): add bot_id column, constraints, enforce DATABASE_URL
- Extend `system_automations` with a non‑null `bot_id` UUID column, create an index on it, and add a unique constraint on `(bot_id, kind, param)` to support upserts.
- Add a unique constraint on `bot_configuration.config_key` to prevent duplicate configuration keys.
- Include migration guards to ensure the new constraint is only created once.
- Remove automatic writing of drive configuration to a `.env` file, cleaning up side‑effects during config loading.
- Change database connection handling to require `DATABASE_URL` to be set (no fallback), making the environment initialization explicit.
2025-11-05 08:47:28 -03:00
f0b8902042 test: add test module declarations and cleanup unused code
- Introduced `#[cfg(test)] pub mod auth_test;` in `src/auth/mod.rs` to expose authentication tests.
- Added `pub mod tests;` declarations in `src/lib.rs` and `src/main.rs` for centralized test utilities.
- Removed unnecessary blank lines and a placeholder comment in `src/shared/models.rs` and `src/tests/test_util.rs`.
- Minor formatting adjustments to improve code readability and maintainability.
2025-11-05 08:06:18 -03:00
1f9100d3a5 feat: refactor auth and models, update LLM fallback strategy
- Simplified auth module by removing unused imports and code
- Cleaned up shared models by removing unused structs (Organization, User, Bot, etc.)
- Updated add-req.sh to comment out unused directories
- Modified LLM fallback strategy in README with additional notes about model behaviors

The changes focus on removing unused code and improving documentation while maintaining existing functionality. The auth module was significantly reduced by removing redundant code, and similar cleanup was applied to shared models. The build script was adjusted to reflect currently used directories.
2025-11-04 23:11:33 -03:00
423f9c3433 feat: remove test bucket creation code from main
Removed the test bucket creation code from the main function as it was only used for testing purposes. The production code should not include test functionality in the main execution path. This cleanup improves code quality and separation of concerns.
2025-11-04 10:21:07 -03:00
866aafcd76 feat: add new prompts and clean up bucket creation code
- Added CLI and IDE prompt files to the add-req.sh script
- Removed unused bucket creation code from BotOrchestrator
- Deleted unused create_bucket module from main.rs

The changes streamline the codebase by removing unused bucket creation functionality while expanding the prompt file inclusion for better LLM context handling.
2025-11-04 10:20:48 -03:00
0e62b601da feat: update directory list in add-req.sh
Updated the directory list in add-req.sh to include previously commented-out directories and added new ones. The changes reflect a more complete set of project modules, including newly added ones like 'bootstrap', 'llm_models', and 'ui'. This ensures the script will process requirements for all current project components.
2025-11-04 09:30:21 -03:00
4b1b68e74d feat(package_manager): add check_cmd to ComponentConfig and services
Added check_cmd field to ComponentConfig struct and implemented health check commands for all services including minio, postgres, valkey, stalwart, caddy, zitadel, forgejo, and forgejo-runner. This allows for proper health monitoring of each service. Also updated IDE guidelines to prohibit magic values and defaults.
2025-11-04 09:25:03 -03:00
854292bae5 feat(ide): update code generation guidelines and improve component startup
- Refine IDE prompt to clarify identifier/character requirements in English
- Add info and debug logging for component startup process in bootstrap
- Fix PostgreSQL command formatting and improve output redirection
- Standardize Valkey command formatting and fix execution command
- Remove LLM server execution command (now handled separately)
- Clean up unused PostgreSQL status check code for tables component
2025-11-04 07:58:43 -03:00
aec4411be8 feat: check bucket existence before uploading templates
Only upload templates to Drive buckets if the bucket was just created. Skip upload if bucket already exists to avoid overwriting existing content.

- Change from always uploading to conditionally uploading based on bucket existence
- Add info log when skipping upload for existing buckets
- Maintain same upload behavior for newly created buckets
2025-11-04 07:07:39 -03:00
c079d6e452 chore(add-req): update active directories list for requirement generation
Enable automation, basic, config, context, session, kb, and tools directories while disabling bootstrap, file, and drive_monitor to refine which modules are processed by add-req.sh.
2025-11-04 07:03:20 -03:00
191ff1a7d8 docs: expand session management and add authentication section
Enhanced Chapter 1 documentation with detailed session architecture, storage layers, and API endpoints. Added new Part XI on authentication and security to SUMMARY.md, introducing chapters on user and bot authentication, password security, and API endpoints. Improves clarity and coverage of system interaction and security concepts.
2025-11-03 20:42:38 -03:00
d2ba036791 feat(session): add interaction tracking and history management
Added interaction count tracking for sessions with Redis or in-memory fallback. Implemented conversation history replacement functionality to compact and update message history. The changes include:
- New AtomicUsize counter in SessionManager for interaction tracking
- increment_and_get_interaction_count method with Redis support
- replace_conversation_history to update and compact message history
- Maintains existing functionality while adding new features
2025-11-03 17:22:54 -03:00
c39af8b320 refactor(bot): remove legacy process_message method and its handling
The large `process_message` function was deleted from `src/bot/mod.rs`. Its responsibilities have been migrated to newer, more modular handlers, eliminating dead code and simplifying the BotOrchestrator. This refactor reduces complexity, improves maintainability, and aligns the codebase with the updated message processing architecture.
2025-11-03 15:22:08 -03:00
9840d0a406 refactor(bot): restructure message handling and context flow
- Reformatted `update_session_context` call for better readability.
- Moved context‑change (type 4) handling to a later stage in the processing pipeline and removed early return, ensuring proper flow.
- Adjusted deduplication logic formatting and clarified condition.
- Restored saving of user messages after context handling, preserving message history.
- Added detailed logging of the LLM prompt for debugging.
- Simplified JSON extraction for `message_type` and applied minor whitespace clean‑ups.
- Overall code refactor improves maintainability and corrects context‑change handling behavior.
2025-11-03 15:20:53 -03:00
41d7377ab7 feat: implement message deduplication and LLM config improvements
- Deduplicate consecutive messages with same role in conversation history
- Add n_predict configuration option for LLM server
- Prevent duplicate message storage in session manager
- Update announcement schedule timing from 37 to 55 minutes
- Add default n_predict value in default bot config
2025-11-03 14:13:22 -03:00
53b49ba616 feat(automation): improve cron matching and job locking
- Refactor cron matching to use individual variables for each time component with additional debug logging
- Replace SETEX with atomic SET NX EX for job locking in Redis
- Add better error handling and logging for job execution tracking
- Skip execution if Redis is unavailable or job is already held
- Add verbose flag to LLM server startup command for better logging
2025-11-03 13:52:28 -03:00
4c279d2a19 feat: optimize suggestions and LLM server configuration
- Added duplicate filtering for suggestions in both backend (Rust) and frontend (JavaScript)
- Changed announcement summary schedule from every 15 minutes to hourly at :37
- Simplified LLM prompt for document summarization
- Updated LLM server configuration with reduced GPU layers and increased context size
- Removed memory mapping and lock settings for LLM server
- Improved HTML formatting and added missing newline at EOF
2025-11-03 13:38:55 -03:00