fix: use single-token ADD_SUGG_TOOL to avoid ADD keyword conflicts
Some checks failed
BotServer CI/CD / build (push) Failing after 4m0s

- Replace ADD SUGGESTION TOOL with ADD_SUGG_TOOL (single token)
- Replace ADD SUGGESTION TEXT with ADD_SUGG_TEXT
- Replace ADD SUGGESTION with ADD_SUGG
- Keep ADD_SUGGESTION_TOOL as legacy alias for backward compat
- Preprocessor converts ADD SUGGESTION TOOL -> ADD_SUGG_TOOL automatically
- Eliminates collision with ADD BOT, ADD MEMBER in Rhai parser

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2026-04-12 14:14:03 -03:00
parent 2f3dd957e3
commit 74ac734253
3 changed files with 37 additions and 80 deletions

View file

@ -1,6 +1,6 @@
USE_WEBSITE("https://salesianos.br", "30d")
USE KB "carta"
USE KB "cartas"
USE KB "proc"

View file

@ -70,58 +70,21 @@ pub fn add_suggestion_keyword(
let cache = state.cache.clone();
let cache2 = state.cache.clone();
let cache3 = state.cache.clone();
let cache4 = state.cache.clone();
let cache5 = state.cache.clone();
let user_session2 = user_session.clone();
let user_session3 = user_session.clone();
let user_session4 = user_session.clone();
let user_session5 = user_session.clone();
// ADD SUGGESTION "context_name" AS "button text"
// ADD_SUGG_TOOL "tool_name" AS "button text" — single-token to avoid ADD conflicts
engine
.register_custom_syntax(
["ADD", "SUGGESTION", "$expr$", "AS", "$expr$"],
true,
move |context, inputs| {
let context_name = context.eval_expression_tree(&inputs[0])?.to_string();
let button_text = context.eval_expression_tree(&inputs[1])?.to_string();
add_context_suggestion(cache.as_ref(), &user_session, &context_name, &button_text)?;
Ok(Dynamic::UNIT)
},
)
.expect("valid syntax registration");
// ADD SUGGESTION TEXT "$expr$" AS "button text"
// Creates a suggestion that sends the text as a user message when clicked
engine
.register_custom_syntax(
["ADD", "SUGGESTION", "TEXT", "$expr$", "AS", "$expr$"],
true,
move |context, inputs| {
let text_value = context.eval_expression_tree(&inputs[0])?.to_string();
let button_text = context.eval_expression_tree(&inputs[1])?.to_string();
add_text_suggestion(cache4.as_ref(), &user_session4, &text_value, &button_text)?;
Ok(Dynamic::UNIT)
},
)
.expect("valid syntax registration");
// ADD_SUGGESTION_TOOL "tool_name" AS "button text" - underscore version to avoid syntax conflicts
engine
.register_custom_syntax(
["ADD_SUGGESTION_TOOL", "$expr$", "AS", "$expr$"],
["ADD_SUGG_TOOL", "$expr$", "AS", "$expr$"],
true,
move |context, inputs| {
let tool_name = context.eval_expression_tree(&inputs[0])?.to_string();
let button_text = context.eval_expression_tree(&inputs[1])?.to_string();
add_tool_suggestion(
cache5.as_ref(),
&user_session5,
cache.as_ref(),
&user_session,
&tool_name,
None,
&button_text,
@ -132,9 +95,10 @@ pub fn add_suggestion_keyword(
)
.expect("valid syntax registration");
// ADD_SUGGESTION_TOOL — legacy alias, same handler
engine
.register_custom_syntax(
["ADD", "SUGGESTION", "TOOL", "$expr$", "AS", "$expr$"],
["ADD_SUGGESTION_TOOL", "$expr$", "AS", "$expr$"],
true,
move |context, inputs| {
let tool_name = context.eval_expression_tree(&inputs[0])?.to_string();
@ -153,45 +117,32 @@ pub fn add_suggestion_keyword(
)
.expect("valid syntax registration");
// ADD_SUGG_TEXT "text_value" AS "button text" — single-token
engine
.register_custom_syntax(
[
"ADD",
"SUGGESTION",
"TOOL",
"$expr$",
"WITH",
"$expr$",
"AS",
"$expr$",
],
["ADD_SUGG_TEXT", "$expr$", "AS", "$expr$"],
true,
move |context, inputs| {
let tool_name = context.eval_expression_tree(&inputs[0])?.to_string();
let params_value = context.eval_expression_tree(&inputs[1])?;
let button_text = context.eval_expression_tree(&inputs[2])?.to_string();
let text_value = context.eval_expression_tree(&inputs[0])?.to_string();
let button_text = context.eval_expression_tree(&inputs[1])?.to_string();
let params = if params_value.is_array() {
params_value
.cast::<rhai::Array>()
.iter()
.map(|v| v.to_string())
.collect()
} else {
params_value
.to_string()
.split(',')
.map(|s| s.trim().to_string())
.collect()
};
add_text_suggestion(cache3.as_ref(), &user_session3, &text_value, &button_text)?;
add_tool_suggestion(
cache3.as_ref(),
&user_session3,
&tool_name,
Some(params),
&button_text,
)?;
Ok(Dynamic::UNIT)
},
)
.expect("valid syntax registration");
// ADD_SUGG "context_name" AS "button text" — single-token
engine
.register_custom_syntax(
["ADD_SUGG", "$expr$", "AS", "$expr$"],
true,
move |context, inputs| {
let context_name = context.eval_expression_tree(&inputs[0])?.to_string();
let button_text = context.eval_expression_tree(&inputs[1])?.to_string();
add_context_suggestion(cache4.as_ref(), &user_session4, &context_name, &button_text)?;
Ok(Dynamic::UNIT)
},

View file

@ -2013,10 +2013,13 @@ impl ScriptService {
(r#"CLEAR\s+TOOLS"#, 0, 0, vec![]),
(r#"CLEAR\s+WEBSITES"#, 0, 0, vec![]),
// ADD family - ADD_SUGGESTION_TOOL must come before ADD\s+SUGGESTION
// ADD family - single-token keywords to avoid ADD conflicts
(r#"ADD_SUGG_TOOL"#, 2, 2, vec!["tool", "text"]),
(r#"ADD_SUGG_TEXT"#, 2, 2, vec!["value", "text"]),
(r#"ADD_SUGG(?!\s+TOOL|\s+TEXT|_)"#, 2, 2, vec!["context", "text"]),
(r#"ADD_SUGGESTION_TOOL"#, 2, 2, vec!["tool", "text"]),
(r#"ADD\s+SUGGESTION\s+TEXT"#, 2, 2, vec!["value", "text"]),
(r#"ADD\s+SUGGESTION(?!\s*TEXT|\s*TOOL|_TOOL)"#, 2, 2, vec!["context", "text"]),
(r#"ADD_SUGGESTION_TEXT"#, 2, 2, vec!["value", "text"]),
(r#"ADD_SUGGESTION(?!\s+TOOL|\s+TEXT|_)"#, 2, 2, vec!["context", "text"]),
(r#"ADD\s+MEMBER"#, 2, 2, vec!["name", "role"]),
// CREATE family
@ -2045,8 +2048,11 @@ impl ScriptService {
// Skip lines that already use underscore-style custom syntax
// These are registered directly with Rhai and should not be converted
let trimmed_upper = trimmed.to_uppercase();
if trimmed_upper.contains("ADD_SUGGESTION_TOOL") ||
if trimmed_upper.contains("ADD_SUGG_TOOL") ||
trimmed_upper.contains("ADD_SUGG_TEXT") ||
trimmed_upper.contains("ADD_SUGGESTION_TOOL") ||
trimmed_upper.contains("ADD_SUGGESTION_TEXT") ||
trimmed_upper.starts_with("ADD_SUGG_") ||
trimmed_upper.starts_with("ADD_SUGGESTION_") ||
trimmed_upper.starts_with("ADD_MEMBER") ||
(trimmed_upper.starts_with("USE_") && trimmed.contains('(')) {