Commit graph

3535 commits

Author SHA1 Message Date
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
78543b5223 feat(announcements): add scheduled updates every 15 minutes
Added SET_SCHEDULE directive to run the update-summary script every 15 minutes. This ensures the announcements summary stays current by regularly fetching and processing the latest news document.
2025-11-03 13:18:40 -03:00
f299dc4dbf feat(llm): add model selection and response processing
Added support for selecting an LLM model based on configuration and processing the raw response. The execute_llm_generation function now:
1. Fetches the configured model using ConfigManager
2. Gets the appropriate handler for the model
3. Processes the raw response through the handler before returning

This provides more flexibility in model selection and allows for model-specific response handling.
2025-11-03 13:12:05 -03:00
8aeb6f31ea feat(bot): add semantic caching and improve message handling
Enhances BotOrchestrator by integrating optional semantic caching via LangCache for faster LLM responses. Also refactors message saving to occur before and after direct mode handling, and simplifies context change logic for better clarity and flow.
2025-11-03 12:54:21 -03:00
b5e1501454 feat: add trace logging, refactor bot streaming, add config fallback
- Added `trace!` logging in `bot_memory.rs` to record retrieved memory values for easier debugging.
- Refactored `BotOrchestrator` in `bot/mod.rs`:
  - Removed duplicate session save block and consolidated message persistence.
  - Replaced low‑level LLM streaming with a structured `UserMessage` and `stream_response` workflow, improving error handling and readability.
- Updated configuration loading in `config/mod.rs`:
  - Imported `get_default_bot` and enhanced `get_config` to fall back to the default bot configuration when the primary query fails.
  - Established a fresh DB connection for the fallback path to avoid borrowing issues.
2025-11-03 10:13:39 -03:00
b3415a3db4 feat(ui): remove redundant styles and adjust theme toggle position
- Remove redundant background and filter properties from logo-icon and assistant-avatar
- Remove redundant filter property from light theme logo-icon
- Invert assistant-avatar image in light theme for better visibility
- Move theme-toggle button further right (60px to 160px) to prevent overlap
2025-11-03 08:34:32 -03:00
b033be3e64 refactor(automation, llm): simplify service init and prompt handling
- Remove `scripts_dir` from `AutomationService` and its constructor, as it was unused.
- Drop LLM and embedding server readiness checks; the service now only schedules periodic tasks.
- Increase the health‑check interval from 5 seconds to 15 seconds for reduced load.
- Streamline the LLM keyword prompt to a concise `"User: {}"` format, removing verbose boilerplate.
- Remove unnecessary logging and LLM cache handling code from the bot orchestrator, cleaning up unused environment variable checks and cache queries.
2025-11-03 08:23:03 -03:00
a5bfda4d09 feat(automation): add LLM server readiness check and improve user session handling
- Added LLM server readiness check in AutomationService before starting tasks
- Renamed `user` parameter to `user_session` in execute_talk for clarity
- Updated BotResponse fields to use user_session data instead of hardcoded values
- Improved Redis key generation in execute_talk to use user_session fields
- Removed commented Redis code in set_current_context_keyword

The changes ensure proper initialization of automation tasks by checking LLM server availability first, and improve code clarity by using more descriptive variable names for user session data.
2025-11-02 23:54:14 -03:00
1d7d0e10c0 feat(automation): add unique constraint and refactor action execution
- Added UNIQUE constraint on system_automations (bot_id, kind, param) to prevent duplicate automations
- Refactored execute_action to accept full Automation struct instead of just param
- Simplified bot name resolution by using automation.bot_id directly
- Improved error handling in action execution with proper error propagation
- Removed redundant bot name lookup logic by leveraging existing bot_id
2025-11-02 20:57:53 -03:00
d2ee695d8b feat: add bot_id to system_automations and enhance schedule handling
- Introduced `bot_id` column in `system_automations` table (migration 6.0.0.sql) and updated the Diesel schema/model to include it.
- Adjusted migrations to remove the hard‑coded “Update Summary” automation and only create an index on the `name` column.
- Extended the `SET_SCHEDULE` keyword:
  - Added a second string argument for the script name.
  - Passed the invoking user's `bot_id` to the database layer.
  - Updated function signature to accept a full `UserSession` instead of discarding it.
- Modified `execute_set_schedule` to store `bot_id`, script name, and activation flag; added conflict handling on `(bot_id, param)` to update schedule and reset trigger state.
- Updated imports and logging to reflect new parameters.

These changes enable per‑bot automation management, allow specifying the script to run, and improve idempotent schedule updates.
2025-11-02 19:32:25 -03:00
0f842adf69 feat(automation): update logging and script handling
- Update RUST_LOG environment variable in launch.json to exclude more verbose crates
- Change automation kind from 3 to 0 in migrations/6.0.5.sql
- Replace debug with trace logging for schedule evaluation in automation service
- Modify script path resolution to use .ast extension instead of .bas
- Improve error message when script reading fails
- Remove MinIO download fallback for scripts (simplifying script handling)

These changes improve logging verbosity control and simplify script handling by removing the MinIO fallback mechanism. The trace-level
2025-11-02 19:03:52 -03:00
fea1574518 feat: enforce config load errors and add dynamic LLM model handling
- Updated `BootstrapManager` to use `AppConfig::from_env().expect(...)` and `AppConfig::from_database(...).expect(...)` ensuring failures are explicit rather than silently ignored.
- Refactored error propagation in bootstrap flow to use `?` where appropriate, improving reliability of configuration loading.
- Added import of `llm_models` in `bot` module and introduced `ConfigManager` usage to fetch the LLM model identifier at runtime.
- Integrated dynamic LLM model handler selection via `llm_models::get_handler(&model)`.
- Replaced static environment variable retrieval for embedding configuration with runtime
2025-11-02 18:36:21 -03:00
e7fa2f7bdb feat(llm): add cancel_job support and integrate session cleanup
Introduce a new `cancel_job` method in the `LLMProvider` trait to allow cancellation of ongoing LLM tasks. Implement no-op versions for OpenAI, Anthropic, and Mock providers. Update the WebSocket handler to invoke job cancellation when a session closes, ensuring better resource management and preventing orphaned tasks. Also, fix unused variable warning in `add_suggestion.rs`.
2025-11-02 15:13:47 -03:00
87fc13b08a feat(keywords): add CLEAR_SUGGESTIONS command and implement in dialog
Added new CLEAR_SUGGESTIONS keyword command that clears user suggestions from Redis cache. Implemented the command in the announcements dialog start script to prevent duplicate suggestions. The command handles Redis connection errors gracefully and logs appropriate debug information.
2025-11-02 14:21:38 -03:00
f2beef5d86 feat(logging): replace debug with trace for verbose operations
Changed debug logging to trace level for Redis suggestion operations and drive monitor object listings. This better reflects the verbosity level of these operations since they are more detailed debugging information. Also updated "Redis client" to "Cache client" in a debug message for consistency with the broader cache abstraction.
2025-11-02 14:16:35 -03:00
4bb3664dfd feat(automation): improve logging and bot path resolution
- Updated RUST_LOG environment variable in launch.json to include more detailed debug logging configuration
- Changed trace! logs to debug! in AutomationService for better visibility
- Replaced environment variable usage with get_default_bot helper function
- Improved bot path resolution by using bot name from database
- Added error handling for bot name query
- Simplified S3 bucket name generation using get_default_bot
- Removed unused imports and environment variable dependencies
2025-11-02 14:08:49 -03:00
6244c99854 feat: include context length info in BotResponse messages
Add `context_length` and `context_max_length` fields to the `BotResponse` struct across the codebase.
Initialize these fields with default values (0) for existing response constructions and populate them using `ConfigManager` to retrieve the configured maximum context size for each bot.
Import `ConfigManager` in `bot/mod.rs` to access configuration.
These changes enable tracking of the current and maximum context sizes in bot responses, supporting future features that rely on context management.
2025-11-02 12:46:37 -03:00
6e36384f45 feat: simplify message content in hear_talk function
Removed the redundant "I heard: " prefix from the message content in the execute_talk function. The message is now stored as-is without additional formatting, making it more straightforward and consistent with other message handling.
2025-11-02 12:28:07 -03:00
a5d3343c09 feat(ui): update design system with new theme and visual enhancements
- Replace Orbitron/Inter fonts with Space Grotesk/JetBrains Mono
- Implement new color scheme with primary, secondary, and accent variables
- Add radial gradient background with animated glow effects
- Introduce grain overlay for texture
- Redesign sidebar with improved transitions and blur effects
- Update empty state styling and remove neon effects
- Optimize layout spacing and shadows
- Streamline API call in chat initialization

The changes modernize the UI with a more cohesive design language, better visual hierarchy, and improved readability while maintaining functionality. The new theme features a dark color palette with vibrant accents and subtle textures for depth.
2025-11-02 11:13:40 -03:00
9673f41195 feat: add styled suggestion buttons and move them from messages to footer
Added new CSS classes for suggestion buttons and container, moving them from message content to footer. Removed inline styles in favor of CSS classes for better maintainability. The suggestions now appear at the top of the footer with consistent styling and hover effects.
2025-11-02 11:01:36 -03:00
9010396a87 feat(ui): improve suggestion handling and input clearing
Enhanced suggestion handling to include empty state in message selection and improved UX by:
- Clearing input field after selecting a suggestion
- Adding selected suggestion as user message to chat
- Maintaining all existing functionality while simplifying the flow

Changes ensure more intuitive user interaction with suggestions while keeping the chat interface clean.
2025-11-02 10:51:42 -03:00
888bfc859d feat: refactor Redis operations to synchronous in add_suggestion
Changed async Redis operations to synchronous in add_suggestion_keyword function. Removed unnecessary async/await and tokio::spawn since the operations are now blocking. This simplifies the code while maintaining the same functionality of storing suggestions and context state in Redis. Error handling remains robust with proper early returns.
2025-11-02 10:45:57 -03:00
acca68493f feat: simplify Redis key format and clean up code
- Remove comments from launch.json configuration
- Simplify Redis key format in set_current_context_keyword by removing context_name
- Remove unused /api/start endpoint and related session start logic
- Change log level from info to trace for config sync messages
- Add trace logging to drive_monitor module

The changes focus on code cleanup and simplification, particularly around session handling and logging. The Redis key format was simplified as the context_name was deemed unnecessary for uniqueness.
2025-11-02 07:50:57 -03:00
0342e1cac9 refactor(state): rename resource clients and improve keyword syntax
Updated references from `redis_client`, `s3_client`, and `custom_conn` to unified names `cache`, `drive`, and `conn` for consistency across modules. Adjusted `add_suggestion_keyword` to use clearer parameter naming and enhanced custom syntax registration for better readability and maintainability.
2025-11-01 20:53:45 -03:00
fda0b0c9e8 feat(auth): add bot name lookup and suggestion support in bot responses
Implemented a new `bot_from_name` method in `AuthService` to retrieve a bot's UUID by its name, enabling explicit bot selection via a `bot_name` query parameter in the authentication endpoint. Updated `auth_handler` to prioritize this parameter, fall back to the first active bot when necessary, and handle cases where no active bots exist.

Extended `BotOrchestrator` to import the `Suggestion` model and fetch suggestion data from Redis for each user session. Integrated these suggestions into the `BotResponse` payload, ensuring clients receive relevant suggestions alongside bot messages.

These changes improve bot selection flexibility and enrich the response data with contextual suggestions.
2025-11-01 17:56:53 -03:00
d6fcc346fc refactor(bot): reorganize imports, improve logging and formatting
- Reordered and deduplicated `use` statements, adding missing imports for `langcache`, `DriveMonitor`, `generate_embeddings`, `Qdrant` client, and `chrono::Utc`.
- Moved Diesel prelude import into the function scope where it is used to limit its visibility.
- Refactored async task spawning to handle errors more clearly and consistently.
- Enhanced string formatting for bucket names and log messages, introducing multiline `warn!` and `error!` calls for better readability.
- Applied consistent code style (spacing, line breaks) across the module to improve maintainability.
2025-11-01 15:16:43 -03:00
4e781b1815 feat(drive_monitor): restart LLaMA servers on llm- config changes
Add logic to detect changes in llm-related configuration properties when syncing gbot configs. If any llm- keys differ from stored values, automatically restart LLaMA servers to apply updates. This ensures model servers stay in sync with configuration changes without unnecessary restarts.
2025-11-01 14:23:40 -03:00
6d68585c71 refactor(config): replace raw SQL with Diesel query for bot config
Updated `ConfigManager::get_config` to use Diesel query builder instead of raw SQL for improved safety and maintainability. Adjusted parameter naming and integrated schema references. Also refactored `ensure_llama_servers_running` to fetch configuration from the database using `AppState` and `ConfigManager`. Removed unused imports in bootstrap module.
2025-11-01 11:48:46 -03:00
7170663b6f feat: remove unused bot config update logic from bootstrap
The commit removes the unused bot configuration update functionality from the bootstrap manager. This includes:
1. Removing the fallback logic in component installation that would update bot configs
2. Removing the entire update_bot_config method which was used to insert/update configuration values

The code was likely removed because this functionality is no longer needed or has been moved elsewhere in the codebase. The removal simplifies the bootstrap process by eliminating unused database operations.
2025-11-01 09:50:28 -03:00