Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(ai): permissive date parsing (#1968)

Eric Hayes4137a3a158b7
diff --git a/js/app/packages/service-clients/service-cognition/generated/tools/schemas.ts b/js/app/packages/service-clients/service-cognition/generated/tools/schemas.ts
index cb0db94d96..aa3128d12a 100644
--- a/js/app/packages/service-clients/service-cognition/generated/tools/schemas.ts
+++ b/js/app/packages/service-clients/service-cognition/generated/tools/schemas.ts
@@ -482,7 +482,9 @@ export const ReadThread = z
'project',
]),
ids: z.array(z.string()),
- messagesSince: z.union([z.string().datetime({ offset: true }), z.null()]),
+ messagesSince: z
+ .union([z.string().datetime({ offset: true }), z.null()])
+ .default(null),
})
.strict();
diff --git a/js/app/packages/service-clients/service-cognition/generated/tools/types.ts b/js/app/packages/service-clients/service-cognition/generated/tools/types.ts
index 98f170a594..7358edc005 100644
--- a/js/app/packages/service-clients/service-cognition/generated/tools/types.ts
+++ b/js/app/packages/service-clients/service-cognition/generated/tools/types.ts
@@ -894,7 +894,7 @@ export interface ReadThread {
*/
ids: string[];
/**
- * A local datetime of the earliest message to include in a channel transcript ex: 2025-11-25 12:00:09 EST, only applicable to channels
+ * A local datetime of the earliest message to include in a channel transcript following ISO 8601 format, only applicable to channels
*/
messagesSince: string | null;
}
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index 9c6742ac67..7ef7d7fdda 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -98,6 +98,7 @@ dependencies = [
"comms",
"connection",
"cool_asserts",
+ "dateparser",
"documents",
"email",
"email_service_client",
@@ -2616,6 +2617,18 @@ dependencies = [
"tracing",
]
+[[package]]
+name = "dateparser"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c2ef451feee09ae5ecd8a02e738bd9adee9266b8fa9b44e22d3ce968d8694238"
+dependencies = [
+ "anyhow",
+ "chrono",
+ "lazy_static",
+ "regex",
+]
+
[[package]]
name = "deflate64"
version = "0.1.9"
@@ -5368,7 +5381,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
dependencies = [
"cfg-if",
- "windows-targets 0.48.5",
+ "windows-targets 0.52.6",
]
[[package]]
diff --git a/rust/cloud-storage/Cargo.toml b/rust/cloud-storage/Cargo.toml
index 4363138d74..dee00c8d58 100644
--- a/rust/cloud-storage/Cargo.toml
+++ b/rust/cloud-storage/Cargo.toml
@@ -153,6 +153,7 @@ clap = { version = "4.5.20", features = ["derive"] }
cloudfront_sign = "0.3.0"
cookie = "0.18.1"
csv = "1"
+dateparser = "0.2.1"
dashmap = "6.1.0"
dotenvy = "0.15.7"
ego-tree = "0.6.2"
diff --git a/rust/cloud-storage/ai_tools/Cargo.toml b/rust/cloud-storage/ai_tools/Cargo.toml
index c961244ff6..f17efd763a 100644
--- a/rust/cloud-storage/ai_tools/Cargo.toml
+++ b/rust/cloud-storage/ai_tools/Cargo.toml
@@ -13,6 +13,7 @@ anyhow.workspace = true
async-trait.workspace = true
axum = { workspace = true, features = ["macros"] }
chrono.workspace = true
+dateparser.workspace = true
comms = { path = "../comms", features = ["outbound"] }
connection = { path = "../connection", default-features = false, features = [
"ports",
diff --git a/rust/cloud-storage/ai_tools/src/lib.rs b/rust/cloud-storage/ai_tools/src/lib.rs
index 5c7ac7d62b..6af62c5714 100644
--- a/rust/cloud-storage/ai_tools/src/lib.rs
+++ b/rust/cloud-storage/ai_tools/src/lib.rs
@@ -8,6 +8,7 @@ pub mod read;
#[allow(dead_code)]
mod rewrite;
pub mod search;
+pub mod serde_utils;
mod tool_context;
pub mod web_fetch;
use code_execution::{
diff --git a/rust/cloud-storage/ai_tools/src/read.rs b/rust/cloud-storage/ai_tools/src/read.rs
index ec9a6f4ac5..4beda4c328 100644
--- a/rust/cloud-storage/ai_tools/src/read.rs
+++ b/rust/cloud-storage/ai_tools/src/read.rs
@@ -1,3 +1,4 @@
+use crate::serde_utils::deserialize_permissive_datetime_opt;
use crate::tool_context::ToolScribe;
use ai_toolset::{AsyncTool, RequestContext, ServiceContext, ToolCallError, ToolResult};
use anyhow::anyhow;
@@ -104,9 +105,10 @@ pub struct ReadThread {
)]
pub ids: Vec<String>,
#[schemars(
- description = "A local datetime of the earliest message to include in a channel transcript ex: 2025-11-25 12:00:09 EST, only applicable to channels"
+ description = "A local datetime of the earliest message to include in a channel transcript following ISO 8601 format, only applicable to channels"
)]
- pub messages_since: Option<chrono::DateTime<chrono::Local>>,
+ #[serde(default, deserialize_with = "deserialize_permissive_datetime_opt")]
+ pub messages_since: Option<DateTime<Utc>>,
}
#[derive(Debug, JsonSchema, Deserialize, Clone, strum::EnumString, strum::Display)]
@@ -210,7 +212,6 @@ impl ReadThread {
let since = self
.messages_since
- .map(DateTime::<Utc>::from)
.unwrap_or_else(|| chrono::Utc::now() - chrono::Duration::days(7));
// Get channel metadata
let metadata = scribe
diff --git a/rust/cloud-storage/ai_tools/src/serde_utils.rs b/rust/cloud-storage/ai_tools/src/serde_utils.rs
new file mode 100644
index 0000000000..488a6bd268
--- /dev/null
+++ b/rust/cloud-storage/ai_tools/src/serde_utils.rs
@@ -0,0 +1,19 @@
+use chrono::{DateTime, Utc};
+use serde::{Deserialize, Deserializer};
+
+/// Deserializes an optional datetime string permissively, accepting many common formats
+/// (e.g. "2025-11-25 12:00:09 EST", "March 5, 2025", "2025-01-01T00:00:00Z", etc.).
+pub fn deserialize_permissive_datetime_opt<'de, D>(
+ deserializer: D,
+) -> Result<Option<DateTime<Utc>>, D::Error>
+where
+ D: Deserializer<'de>,
+{
+ let s: Option<String> = Option::deserialize(deserializer)?;
+ match s {
+ Some(s) if !s.is_empty() => dateparser::parse(&s)
+ .map(Some)
+ .map_err(serde::de::Error::custom),
+ _ => Ok(None),
+ }
+}