Skip to main content

kcode_k1_chat_thread_actions/
lib.rs

1use serde_json::Value;
2
3const INVALID_CURRENT_TIME_ARGUMENTS: &str = "invalid CurrentTime arguments";
4const UNKNOWN_TOOL: &str = "unknown Ktool";
5
6pub fn launch(name: &str, arguments: &str) -> Result<String, String> {
7    match name {
8        "CurrentTime" if is_empty_object(arguments) => {
9            Ok(kcode_k1_ktool_current_time::current_time())
10        }
11        "CurrentTime" => Err(INVALID_CURRENT_TIME_ARGUMENTS.to_owned()),
12        _ => Err(UNKNOWN_TOOL.to_owned()),
13    }
14}
15
16fn is_empty_object(arguments: &str) -> bool {
17    matches!(
18        serde_json::from_str::<Value>(arguments),
19        Ok(Value::Object(fields)) if fields.is_empty()
20    )
21}
22
23#[cfg(test)]
24mod tests;