2026-02-12 21:09:30 +00:00
|
|
|
use crate::core::shared::models::UserSession;
|
|
|
|
|
use crate::core::shared::state::AppState;
|
2026-02-10 13:49:54 +00:00
|
|
|
use log::{debug, info};
|
|
|
|
|
use rhai::{Dynamic, Engine};
|
Add documentation and core BASIC language functions
- Add SET_SCHEDULE.md and TEMPLATE_VARIABLES.md documentation
- Implement array functions (CONTAINS, PUSH/POP, SLICE, SORT, UNIQUE)
- Implement math functions module structure
- Implement datetime functions module structure
- Implement validation functions (ISNULL, ISEMPTY, VAL, STR, TYPEOF)
- Implement error handling functions (THROW, ERROR, ASSERT)
- Add CRM lead scoring keywords (SCORE_LEAD, AI_SCORE_LEAD)
- Add messaging keywords (SEND_TEMPLATE, CREATE_TEMPLATE)
2025-11-30 11:09:16 -03:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
|
|
use super::arrays::register_array_functions;
|
|
|
|
|
use super::datetime::register_datetime_functions;
|
|
|
|
|
use super::errors::register_error_functions;
|
|
|
|
|
use super::math::register_math_functions;
|
|
|
|
|
use super::validation::register_validation_functions;
|
|
|
|
|
|
|
|
|
|
pub fn register_core_functions(state: Arc<AppState>, user: UserSession, engine: &mut Engine) {
|
|
|
|
|
debug!("Registering core BASIC functions...");
|
|
|
|
|
|
2025-12-24 09:50:30 -03:00
|
|
|
register_math_functions(&state, user.clone(), engine);
|
2025-12-09 07:55:11 -03:00
|
|
|
debug!(" * Math functions registered");
|
Add documentation and core BASIC language functions
- Add SET_SCHEDULE.md and TEMPLATE_VARIABLES.md documentation
- Implement array functions (CONTAINS, PUSH/POP, SLICE, SORT, UNIQUE)
- Implement math functions module structure
- Implement datetime functions module structure
- Implement validation functions (ISNULL, ISEMPTY, VAL, STR, TYPEOF)
- Implement error handling functions (THROW, ERROR, ASSERT)
- Add CRM lead scoring keywords (SCORE_LEAD, AI_SCORE_LEAD)
- Add messaging keywords (SEND_TEMPLATE, CREATE_TEMPLATE)
2025-11-30 11:09:16 -03:00
|
|
|
|
2025-12-24 09:50:30 -03:00
|
|
|
register_datetime_functions(&state, user.clone(), engine);
|
2025-12-09 07:55:11 -03:00
|
|
|
debug!(" * Date/Time functions registered");
|
Add documentation and core BASIC language functions
- Add SET_SCHEDULE.md and TEMPLATE_VARIABLES.md documentation
- Implement array functions (CONTAINS, PUSH/POP, SLICE, SORT, UNIQUE)
- Implement math functions module structure
- Implement datetime functions module structure
- Implement validation functions (ISNULL, ISEMPTY, VAL, STR, TYPEOF)
- Implement error handling functions (THROW, ERROR, ASSERT)
- Add CRM lead scoring keywords (SCORE_LEAD, AI_SCORE_LEAD)
- Add messaging keywords (SEND_TEMPLATE, CREATE_TEMPLATE)
2025-11-30 11:09:16 -03:00
|
|
|
|
2025-12-24 09:50:30 -03:00
|
|
|
register_validation_functions(&state, user.clone(), engine);
|
2025-12-09 07:55:11 -03:00
|
|
|
debug!(" * Validation functions registered");
|
Add documentation and core BASIC language functions
- Add SET_SCHEDULE.md and TEMPLATE_VARIABLES.md documentation
- Implement array functions (CONTAINS, PUSH/POP, SLICE, SORT, UNIQUE)
- Implement math functions module structure
- Implement datetime functions module structure
- Implement validation functions (ISNULL, ISEMPTY, VAL, STR, TYPEOF)
- Implement error handling functions (THROW, ERROR, ASSERT)
- Add CRM lead scoring keywords (SCORE_LEAD, AI_SCORE_LEAD)
- Add messaging keywords (SEND_TEMPLATE, CREATE_TEMPLATE)
2025-11-30 11:09:16 -03:00
|
|
|
|
|
|
|
|
register_array_functions(state.clone(), user.clone(), engine);
|
2025-12-09 07:55:11 -03:00
|
|
|
debug!(" * Array functions registered");
|
Add documentation and core BASIC language functions
- Add SET_SCHEDULE.md and TEMPLATE_VARIABLES.md documentation
- Implement array functions (CONTAINS, PUSH/POP, SLICE, SORT, UNIQUE)
- Implement math functions module structure
- Implement datetime functions module structure
- Implement validation functions (ISNULL, ISEMPTY, VAL, STR, TYPEOF)
- Implement error handling functions (THROW, ERROR, ASSERT)
- Add CRM lead scoring keywords (SCORE_LEAD, AI_SCORE_LEAD)
- Add messaging keywords (SEND_TEMPLATE, CREATE_TEMPLATE)
2025-11-30 11:09:16 -03:00
|
|
|
|
|
|
|
|
register_error_functions(state, user, engine);
|
2025-12-09 07:55:11 -03:00
|
|
|
debug!(" * Error handling functions registered");
|
Add documentation and core BASIC language functions
- Add SET_SCHEDULE.md and TEMPLATE_VARIABLES.md documentation
- Implement array functions (CONTAINS, PUSH/POP, SLICE, SORT, UNIQUE)
- Implement math functions module structure
- Implement datetime functions module structure
- Implement validation functions (ISNULL, ISEMPTY, VAL, STR, TYPEOF)
- Implement error handling functions (THROW, ERROR, ASSERT)
- Add CRM lead scoring keywords (SCORE_LEAD, AI_SCORE_LEAD)
- Add messaging keywords (SEND_TEMPLATE, CREATE_TEMPLATE)
2025-11-30 11:09:16 -03:00
|
|
|
|
2026-02-10 13:49:54 +00:00
|
|
|
// Register send_mail stub function for tools (traces when mail feature is not available)
|
|
|
|
|
engine.register_fn("send_mail", move |to: Dynamic, subject: Dynamic, body: Dynamic, _attachments: Dynamic| -> String {
|
|
|
|
|
let to_str = to.to_string();
|
|
|
|
|
let subject_str = subject.to_string();
|
|
|
|
|
let body_str = body.to_string();
|
|
|
|
|
info!(
|
|
|
|
|
"[TOOL] send_mail called (mail feature not enabled): to='{}', subject='{}', body_len={}",
|
|
|
|
|
to_str,
|
|
|
|
|
subject_str,
|
|
|
|
|
body_str.len()
|
|
|
|
|
);
|
|
|
|
|
// Return a fake message ID
|
|
|
|
|
format!("MSG-{:0X}", chrono::Utc::now().timestamp())
|
|
|
|
|
});
|
|
|
|
|
debug!(" * send_mail stub function registered");
|
|
|
|
|
|
Add documentation and core BASIC language functions
- Add SET_SCHEDULE.md and TEMPLATE_VARIABLES.md documentation
- Implement array functions (CONTAINS, PUSH/POP, SLICE, SORT, UNIQUE)
- Implement math functions module structure
- Implement datetime functions module structure
- Implement validation functions (ISNULL, ISEMPTY, VAL, STR, TYPEOF)
- Implement error handling functions (THROW, ERROR, ASSERT)
- Add CRM lead scoring keywords (SCORE_LEAD, AI_SCORE_LEAD)
- Add messaging keywords (SEND_TEMPLATE, CREATE_TEMPLATE)
2025-11-30 11:09:16 -03:00
|
|
|
debug!("All core BASIC functions registered successfully");
|
|
|
|
|
}
|