Cotton code
26 lines · 935 B · RustRaw
//! The same deterministic phrase engine called by the app and assistants.use crate::mcp::dispatch::{Ctx, HandlerGroup, ToolResult};use crate::mcp::protocol::ToolFailure;use serde::Deserialize;use serde_json::{Map, Value};pub fn handlers() -> HandlerGroup {    &[("parse_phrase", parse_phrase)]}#[derive(Deserialize)]#[serde(deny_unknown_fields)]struct Args {    text: String,    now: String,    time_zone: String,    projects: Vec<String>,    people: Vec<String>,}fn parse_phrase(_: &mut Ctx<'_>, args: &Map<String, Value>) -> ToolResult {    let a: Args = serde_json::from_value(Value::Object(args.clone()))        .map_err(|e| ToolFailure::new(format!("parse_phrase: {e}")))?;    let parsed =        cotton_core::phrase::parse_phrase(&a.text, &a.now, &a.time_zone, &a.projects, &a.people)            .map_err(ToolFailure::new)?;    serde_json::to_value(parsed).map_err(|e| ToolFailure::new(e.to_string()))}