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): merge consecutive deltas (#3564)

Eric Hayesd57d4af5f885
diff --git a/rust/cloud-storage/agent/src/agent_loop.rs b/rust/cloud-storage/agent/src/agent_loop.rs
index cac3973fde..921dcef499 100644
--- a/rust/cloud-storage/agent/src/agent_loop.rs
+++ b/rust/cloud-storage/agent/src/agent_loop.rs
@@ -140,9 +140,6 @@ impl Session {
)));
};
- #[cfg(feature = "debug-messages")]
- dump_messages("agent_input.log", &self.history);
-
let (bridge, mut rx) = StreamBridge::channel();
let mut rig_stream = self
@@ -172,10 +169,6 @@ impl Session {
}
match other {
Ok(MultiTurnStreamItem::FinalResponse(final_resp)) => {
- #[cfg(feature = "debug-messages")]
- if let Some(history) = final_resp.history() {
- dump_messages("agent_output.log", history);
- }
let usage = final_resp.usage();
yield Ok(StreamPart::Usage(crate::stream::Usage {
input_tokens: usage.input_tokens,
@@ -206,20 +199,3 @@ impl Session {
&self.history
}
}
-
-#[cfg(feature = "debug-messages")]
-fn dump_messages(filename: &str, messages: &[Message]) {
- use std::io::Write;
-
- let path = std::path::PathBuf::from(filename);
- match serde_json::to_string_pretty(messages) {
- Ok(json) => match std::fs::File::create(&path) {
- Ok(mut f) => {
- let _ = f.write_all(json.as_bytes());
- tracing::info!(path = %path.display(), "wrote message chain");
- }
- Err(e) => tracing::warn!(error = %e, path = %path.display(), "failed to write"),
- },
- Err(e) => tracing::warn!(error = %e, "failed to serialize message chain"),
- }
-}
diff --git a/rust/cloud-storage/agent/src/convert.rs b/rust/cloud-storage/agent/src/convert.rs
index 84a3a8c061..72e4ffa97a 100644
--- a/rust/cloud-storage/agent/src/convert.rs
+++ b/rust/cloud-storage/agent/src/convert.rs
@@ -94,6 +94,29 @@ fn convert_assistant(msg: &ChatMessage) -> Vec<Message> {
out
}
+/// Merges consecutive `Text` and `Thinking` parts into single entries.
+pub fn merge_consecutive_parts(parts: Vec<AssistantMessagePart>) -> Vec<AssistantMessagePart> {
+ let mut out: Vec<AssistantMessagePart> = Vec::with_capacity(parts.len());
+ for part in parts {
+ match (&mut out.last_mut(), &part) {
+ (
+ Some(AssistantMessagePart::Text { text: acc }),
+ AssistantMessagePart::Text { text },
+ ) => {
+ acc.push_str(text);
+ }
+ (
+ Some(AssistantMessagePart::Thinking { thinking: acc }),
+ AssistantMessagePart::Thinking { thinking },
+ ) => {
+ acc.push_str(thinking);
+ }
+ _ => out.push(part),
+ }
+ }
+ out
+}
+
fn flush(
out: &mut Vec<Message>,
assistant_parts: &mut Vec<AssistantContent>,
diff --git a/rust/cloud-storage/agent/src/convert/test.rs b/rust/cloud-storage/agent/src/convert/test.rs
index 88bd00e42e..db279a9536 100644
--- a/rust/cloud-storage/agent/src/convert/test.rs
+++ b/rust/cloud-storage/agent/src/convert/test.rs
@@ -347,3 +347,50 @@ fn full_conversation_with_tool_round_trip() {
};
assert_eq!(text.text, "Found 2 cats.");
}
+
+mod merge_consecutive_parts_tests {
+ use super::*;
+
+ fn part_text(s: &str) -> AssistantMessagePart {
+ AssistantMessagePart::Text { text: s.into() }
+ }
+ fn part_thinking(s: &str) -> AssistantMessagePart {
+ AssistantMessagePart::Thinking { thinking: s.into() }
+ }
+ fn part_call(id: &str) -> AssistantMessagePart {
+ AssistantMessagePart::ToolCall {
+ name: "t".into(),
+ json: json!({}),
+ id: id.into(),
+ }
+ }
+
+ #[test]
+ fn merges_consecutive_text() {
+ let parts = vec![part_text("a"), part_text("b"), part_text("c")];
+ assert_eq!(merge_consecutive_parts(parts), vec![part_text("abc")]);
+ }
+
+ #[test]
+ fn merges_consecutive_thinking() {
+ let parts = vec![part_thinking("a"), part_thinking("b")];
+ assert_eq!(merge_consecutive_parts(parts), vec![part_thinking("ab")]);
+ }
+
+ #[test]
+ fn does_not_merge_across_different_types() {
+ let parts = vec![part_text("a"), part_call("1"), part_text("b")];
+ assert_eq!(merge_consecutive_parts(parts.clone()), parts);
+ }
+
+ #[test]
+ fn thinking_then_text_stays_separate() {
+ let parts = vec![part_thinking("t"), part_text("a")];
+ assert_eq!(merge_consecutive_parts(parts.clone()), parts);
+ }
+
+ #[test]
+ fn empty_input() {
+ assert!(merge_consecutive_parts(vec![]).is_empty());
+ }
+}
diff --git a/rust/cloud-storage/agent/src/lib.rs b/rust/cloud-storage/agent/src/lib.rs
index 87e6ed1483..dd0a0ed883 100644
--- a/rust/cloud-storage/agent/src/lib.rs
+++ b/rust/cloud-storage/agent/src/lib.rs
@@ -17,7 +17,7 @@ pub mod types;
pub use agent_loop::{AgentLoop, Session};
pub use completion::{complete, complete_with_history};
-pub use convert::to_rig_messages;
+pub use convert::{merge_consecutive_parts, to_rig_messages};
pub use error::AgentError;
pub use hook::StreamBridge;
pub use model::AgentModel;
diff --git a/rust/cloud-storage/document_cognition_service/agent_input.log b/rust/cloud-storage/document_cognition_service/agent_input.log
deleted file mode 100644
index 8df2831347..0000000000
--- a/rust/cloud-storage/document_cognition_service/agent_input.log
+++ /dev/null
@@ -1,11 +0,0 @@
-[
- {
- "role": "user",
- "content": [
- {
- "type": "text",
- "text": "what should I work on today"
- }
- ]
- }
-]
\ No newline at end of file
diff --git a/rust/cloud-storage/document_cognition_service/agent_output.log b/rust/cloud-storage/document_cognition_service/agent_output.log
deleted file mode 100644
index 69cc8fcbad..0000000000
--- a/rust/cloud-storage/document_cognition_service/agent_output.log
+++ /dev/null
@@ -1,243 +0,0 @@
-[
- {
- "role": "user",
- "content": [
- {
- "type": "text",
- "text": "what should I work on today"
- }
- ]
- },
- {
- "role": "assistant",
- "id": null,
- "content": [
- {
- "id": null,
- "content": [
- {
- "type": "text",
- "content": {
- "text": " I'm looking at the user's notifications and recent activity to understand what might be most relevant for them to focus on today.",
- "signature": "Er8CCmMIDhgCKkB9gLAGecZ5wbBqsWANB6lJowlpjay51B10/Ak2GQvIy3YHUBuN4IAvbcA+QjjQtO09uvDPqf+00aW9r2wZgAgJMg9jbGF1ZGUtb3B1cy00LTc4AEIIdGhpbmtpbmcSDPbaQunKz3auz++wIBoMyKnuAaewApzMp2wSIjCiV05wT6cKgvZ7fQeuofjG6e6meeFEJYLJXYWBTjerEigJ5QtHBst2wJHaHVko+goqiQHqsLayqhwUyHvbnAKjhpOVkS9cuKZ8wogaiU36riBxmna2K2XSbJsQu+S2jOKMgmGy6Dkdn275PshiwQx2Va18kvYHqh4b5xI+plsSG1Bw7awdnNS6QBuZqOD7bsG3/qZdtnKl3p6iMZ9N5I8e1ZuiLXMBgydhek0KW7gfm0HqNeOVzXffdRXxpxgB"
- }
- }
- ]
- },
- {
- "id": "toolu_01VKcUyJUafth4F2jDcmVVCE",
- "call_id": null,
- "function": {
- "name": "ListNotifications",
- "arguments": {
- "done": false,
- "entities": null,
- "includeTypes": null,
- "limit": 20,
- "seen": null
- }
- },
- "signature": null,
- "additional_params": null
- },
- {
- "id": "toolu_01XsfeUVv68AErm82fFP2eNU",
- "call_id": null,
- "function": {
- "name": "ListEntities",
- "arguments": {
- "callf": null,
- "cf": null,
- "chanf": null,
- "df": null,
- "ef": null,
- "emailPreset": null,
- "emailView": null,
- "includeTypes": [
- "document"
- ],
- "limit": 15,
- "pf": null,
- "propf": null,
- "sortBy": "recently_updated"
- }
- },
- "signature": null,
- "additional_params": null
- }
- ]
- },
- {
- "role": "user",
- "content": [
- {
- "type": "toolresult",
- "id": "toolu_01VKcUyJUafth4F2jDcmVVCE",
- "content": [
- {
- "type": "text",
- "text": "{\"hasMore\":true,\"notifications\":[{\"createdAt\":\"2026-05-22T20:47:54.712549+00:00\",\"done\":false,\"entityId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"entityType\":\"channel\",\"eventType\":\"channel_message_send\",\"id\":\"019e5171-d0a1-77c0-9510-8d10b5f6a733\",\"metadata\":{\"channelName\":\"battlefield\",\"channelType\":\"organization\",\"messageContent\":\"<m-document-mention>{\\\"documentId\\\":\\\"019e5032-d37d-7f5b-9168-25245dc35d6b\\\",\\\"blockName\\\":\\\"task\\\",\\\"documentName\\\":\\\"taskium referencius\\\",\\\"blockParams\\\":{},\\\"collapsed\\\":false}</m-document-mention>\",\"messageId\":\"019e5171-cf2c-7c10-ab65-1477a7995ae6\",\"sender\":\"macro|[email protected]\",\"senderProfilePictureUrl\":\"https://static-file-service-dev.macro.com/file/82cdf0c7-d554-49df-acb3-3a1f1b61d9fc\"},\"seen\":true,\"senderId\":\"macro|[email protected]\"},{\"createdAt\":\"2026-05-22T20:47:54.072764+00:00\",\"done\":false,\"entityId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"entityType\":\"channel\",\"eventType\":\"document_mention\",\"id\":\"019e5171-d079-7c71-86ad-4a2d8a332241\",\"metadata\":{\"channelName\":\"battlefield\",\"channelType\":\"organization\",\"documentName\":\"taskium referencius\",\"fileType\":\"md\",\"messageContent\":\"<m-document-mention>{\\\"documentId\\\":\\\"019e5032-d37d-7f5b-9168-25245dc35d6b\\\",\\\"blockName\\\":\\\"task\\\",\\\"documentName\\\":\\\"taskium referencius\\\",\\\"blockParams\\\":{},\\\"collapsed\\\":false}</m-document-mention>\",\"messageId\":\"019e5171-cf2c-7c10-ab65-1477a7995ae6\",\"owner\":\"macro|[email protected]\",\"senderProfilePictureUrl\":\"https://static-file-service-dev.macro.com/file/82cdf0c7-d554-49df-acb3-3a1f1b61d9fc\",\"subType\":{\"type\":\"task\"}},\"seen\":false,\"senderId\":\"macro|[email protected]\"},{\"createdAt\":\"2026-05-22T19:42:04.891200+00:00\",\"done\":false,\"entityId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"entityType\":\"channel\",\"eventType\":\"call-started\",\"id\":\"019e5135-8df4-7e11-8a6f-8341e418a459\",\"metadata\":{\"channel_name\":\"battlefield\",\"sender_profile_picture_url\":\"https://static-file-service-dev.macro.com/file/712ba6da-e7b9-4666-bc79-ea391e6a5ca7\"},\"seen\":false,\"senderId\":\"macro|[email protected]\"},{\"createdAt\":\"2026-05-22T19:05:54.367856+00:00\",\"done\":false,\"entityId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"entityType\":\"channel\",\"eventType\":\"call-started\",\"id\":\"019e5114-6f77-7bd0-860d-ffbaa27f678e\",\"metadata\":{\"channel_name\":\"battlefield\",\"sender_profile_picture_url\":\"https://static-file-service-dev.macro.com/file/712ba6da-e7b9-4666-bc79-ea391e6a5ca7\"},\"seen\":false,\"senderId\":\"macro|[email protected]\"},{\"createdAt\":\"2026-05-22T18:56:44.722780+00:00\",\"done\":false,\"entityId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"entityType\":\"channel\",\"eventType\":\"call-started\",\"id\":\"019e510c-0c6a-7c42-ba70-e65bd2978fb5\",\"metadata\":{\"channel_name\":\"battlefield\",\"sender_profile_picture_url\":\"https://static-file-service-dev.macro.com/file/712ba6da-e7b9-4666-bc79-ea391e6a5ca7\"},\"seen\":false,\"senderId\":\"macro|[email protected]\"},{\"createdAt\":\"2026-05-22T18:53:09.901689+00:00\",\"done\":false,\"entityId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"entityType\":\"channel\",\"eventType\":\"call-started\",\"id\":\"019e5108-c53a-7e83-939f-e3ac9d614521\",\"metadata\":{\"channel_name\":\"battlefield\",\"sender_profile_picture_url\":\"https://static-file-service-dev.macro.com/file/712ba6da-e7b9-4666-bc79-ea391e6a5ca7\"},\"seen\":false,\"senderId\":\"macro|[email protected]\"},{\"createdAt\":\"2026-05-22T18:48:13.268318+00:00\",\"done\":false,\"entityId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"entityType\":\"channel\",\"eventType\":\"call-started\",\"id\":\"019e5104-3e84-76b0-b671-201b4f771c36\",\"metadata\":{\"channel_name\":\"battlefield\",\"sender_profile_picture_url\":\"https://static-file-service-dev.macro.com/file/712ba6da-e7b9-4666-bc79-ea391e6a5ca7\"},\"seen\":false,\"senderId\":\"macro|[email protected]\"},{\"createdAt\":\"2026-05-22T18:44:28.480538+00:00\",\"done\":false,\"entityId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"entityType\":\"channel\",\"eventType\":\"call-started\",\"id\":\"019e5100-d048-78f2-a5b2-9fa1eb78e21b\",\"metadata\":{\"channel_name\":\"battlefield\",\"sender_profile_picture_url\":\"https://static-file-service-dev.macro.com/file/712ba6da-e7b9-4666-bc79-ea391e6a5ca7\"},\"seen\":false,\"senderId\":\"macro|[email protected]\"},{\"createdAt\":\"2026-05-22T18:26:10.456531+00:00\",\"done\":false,\"entityId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"entityType\":\"channel\",\"eventType\":\"call-started\",\"id\":\"019e50f0-0f72-7001-8373-0d5c56229f1c\",\"metadata\":{\"channel_name\":\"battlefield\",\"sender_profile_picture_url\":\"https://static-file-service-dev.macro.com/file/712ba6da-e7b9-4666-bc79-ea391e6a5ca7\"},\"seen\":false,\"senderId\":\"macro|[email protected]\"},{\"createdAt\":\"2026-05-22T18:25:53.729715+00:00\",\"done\":false,\"entityId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"entityType\":\"channel\",\"eventType\":\"call-started\",\"id\":\"019e50ef-cdff-7c80-892a-3e7d6a86f0f1\",\"metadata\":{\"channel_name\":\"battlefield\",\"sender_profile_picture_url\":\"https://static-file-service-dev.macro.com/file/712ba6da-e7b9-4666-bc79-ea391e6a5ca7\"},\"seen\":false,\"senderId\":\"macro|[email protected]\"},{\"createdAt\":\"2026-05-22T18:24:28.874681+00:00\",\"done\":false,\"entityId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"entityType\":\"channel\",\"eventType\":\"call-started\",\"id\":\"019e50ee-8277-7410-bf1c-06fa2e6a87a5\",\"metadata\":{\"channel_name\":\"battlefield\",\"sender_profile_picture_url\":\"https://static-file-service-dev.macro.com/file/712ba6da-e7b9-4666-bc79-ea391e6a5ca7\"},\"seen\":false,\"senderId\":\"macro|[email protected]\"},{\"createdAt\":\"2026-05-22T15:17:01.774288+00:00\",\"done\":false,\"entityId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"entityType\":\"channel\",\"eventType\":\"channel_message_send\",\"id\":\"019e5042-e4a4-7c50-832c-56bc6f43977d\",\"metadata\":{\"channelName\":\"battlefield\",\"channelType\":\"organization\",\"messageContent\":\"\\n \\n\",\"messageId\":\"019e5042-e3a0-7b6f-9f74-d1e2fc841814\",\"sender\":\"macro|[email protected]\",\"senderProfilePictureUrl\":\"https://static-file-service-dev.macro.com/file/27e525a7-9ca6-49c3-98f9-7094f1d6ef7a\"},\"seen\":true,\"senderId\":\"macro|[email protected]\"},{\"createdAt\":\"2026-05-22T15:16:48.079471+00:00\",\"done\":false,\"entityId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"entityType\":\"channel\",\"eventType\":\"channel_message_send\",\"id\":\"019e5042-af22-7080-a27b-ebcd44318aae\",\"metadata\":{\"channelName\":\"battlefield\",\"channelType\":\"organization\",\"messageContent\":\"1\",\"messageId\":\"019e5042-ae5e-7026-a1a3-88ddc78332f3\",\"sender\":\"macro|[email protected]\",\"senderProfilePictureUrl\":\"https://static-file-service-dev.macro.com/file/27e525a7-9ca6-49c3-98f9-7094f1d6ef7a\"},\"seen\":true,\"senderId\":\"macro|[email protected]\"},{\"createdAt\":\"2026-05-22T15:16:44.911516+00:00\",\"done\":false,\"entityId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"entityType\":\"channel\",\"eventType\":\"channel_message_send\",\"id\":\"019e5042-a2ca-7350-8ba3-cd0e4c8c58dd\",\"metadata\":{\"channelName\":\"battlefield\",\"channelType\":\"organization\",\"messageContent\":\"Hello\",\"messageId\":\"019e5042-a1fb-7760-8966-fcb08c6f3fd3\",\"sender\":\"macro|[email protected]\",\"senderProfilePictureUrl\":\"https://static-file-service-dev.macro.com/file/27e525a7-9ca6-49c3-98f9-7094f1d6ef7a\"},\"seen\":true,\"senderId\":\"macro|[email protected]\"},{\"createdAt\":\"2026-05-22T15:16:42.767679+00:00\",\"done\":false,\"entityId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"entityType\":\"channel\",\"eventType\":\"channel_message_send\",\"id\":\"019e5042-9a55-7b21-93a0-e5a420e91aee\",\"metadata\":{\"channelName\":\"battlefield\",\"channelType\":\"organization\",\"messageContent\":\"<m-user-mention>{\\\"userId\\\":\\\"macro|[email protected]\\\",\\\"email\\\":\\\"[email protected]\\\"}</m-user-mention>\",\"messageId\":\"019e5042-9958-7494-bc4a-135c9d3bd711\",\"sender\":\"macro|[email protected]\",\"senderProfilePictureUrl\":\"https://static-file-service-dev.macro.com/file/27e525a7-9ca6-49c3-98f9-7094f1d6ef7a\"},\"seen\":true,\"senderId\":\"macro|[email protected]\"},{\"createdAt\":\"2026-05-22T15:16:33.491724+00:00\",\"done\":false,\"entityId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"entityType\":\"channel\",\"eventType\":\"channel_message_send\",\"id\":\"019e5042-7287-7cd2-be87-e9ca7ea4ed7e\",\"metadata\":{\"channelName\":\"battlefield\",\"channelType\":\"organization\",\"messageContent\":\"<m-user-mention>{\\\"userId\\\":\\\"macro|[email protected]\\\",\\\"email\\\":\\\"[email protected]\\\"}</m-user-mention>\",\"messageId\":\"019e5042-717d-78e3-ab96-535e6cec2a65\",\"sender\":\"macro|[email protected]\",\"senderProfilePictureUrl\":\"https://static-file-service-dev.macro.com/file/27e525a7-9ca6-49c3-98f9-7094f1d6ef7a\"},\"seen\":true,\"senderId\":\"macro|[email protected]\"},{\"createdAt\":\"2026-05-22T15:15:08.977931+00:00\",\"done\":false,\"entityId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"entityType\":\"channel\",\"eventType\":\"channel_message_send\",\"id\":\"019e5041-2c0d-7282-97aa-80ac9f19e546\",\"metadata\":{\"channelName\":\"battlefield\",\"channelType\":\"organization\",\"messageContent\":\"3\",\"messageId\":\"019e5041-2b2f-78aa-83bd-74fdf59b92b6\",\"sender\":\"macro|[email protected]\",\"senderProfilePictureUrl\":\"https://static-file-service-dev.macro.com/file/27e525a7-9ca6-49c3-98f9-7094f1d6ef7a\"},\"seen\":true,\"senderId\":\"macro|[email protected]\"},{\"createdAt\":\"2026-05-22T15:15:08.664735+00:00\",\"done\":false,\"entityId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"entityType\":\"channel\",\"eventType\":\"channel_message_send\",\"id\":\"019e5041-2aca-74b2-9adc-27ba55a07140\",\"metadata\":{\"channelName\":\"battlefield\",\"channelType\":\"organization\",\"messageContent\":\"2\",\"messageId\":\"019e5041-29a6-7d9b-94e5-b20925bcad09\",\"sender\":\"macro|[email protected]\",\"senderProfilePictureUrl\":\"https://static-file-service-dev.macro.com/file/27e525a7-9ca6-49c3-98f9-7094f1d6ef7a\"},\"seen\":true,\"senderId\":\"macro|[email protected]\"},{\"createdAt\":\"2026-05-22T15:15:08.177304+00:00\",\"done\":false,\"entityId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"entityType\":\"channel\",\"eventType\":\"channel_message_send\",\"id\":\"019e5041-28e7-75c3-8605-d1d8974d221c\",\"metadata\":{\"channelName\":\"battlefield\",\"channelType\":\"organization\",\"messageContent\":\"1\",\"messageId\":\"019e5041-2826-7fed-a4b0-cee74ee79a5a\",\"sender\":\"macro|[email protected]\",\"senderProfilePictureUrl\":\"https://static-file-service-dev.macro.com/file/27e525a7-9ca6-49c3-98f9-7094f1d6ef7a\"},\"seen\":true,\"senderId\":\"macro|[email protected]\"},{\"createdAt\":\"2026-05-22T15:15:03.788589+00:00\",\"done\":false,\"entityId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"entityType\":\"channel\",\"eventType\":\"channel_message_send\",\"id\":\"019e5041-17a6-7cd3-86e9-c23683cd5ab4\",\"metadata\":{\"channelName\":\"battlefield\",\"channelType\":\"organization\",\"messageContent\":\"Test\",\"messageId\":\"019e5041-169c-7a65-9bcc-03faa0708a01\",\"sender\":\"macro|[email protected]\",\"senderProfilePictureUrl\":\"https://static-file-service-dev.macro.com/file/27e525a7-9ca6-49c3-98f9-7094f1d6ef7a\"},\"seen\":true,\"senderId\":\"macro|[email protected]\"}]}"
- }
- ]
- }
- ]
- },
- {
- "role": "user",
- "content": [
- {
- "type": "toolresult",
- "id": "toolu_01XsfeUVv68AErm82fFP2eNU",
- "content": [
- {
- "type": "text",
- "text": "{\"items\":[{\"id\":\"019e6593-1366-7a4b-a70d-50dd2082a114\",\"name\":\"test task needs a pr\",\"type\":\"document\"},{\"id\":\"019e656d-ac0a-7f1d-9b83-e2703dc4500f\",\"name\":\"move pr to regular task row\",\"type\":\"document\"},{\"id\":\"019e5ff8-cbb7-72c1-a1fb-69b60e92adeb\",\"name\":\"im going to link this to test\",\"type\":\"document\"},{\"id\":\"019e5032-d37d-7f5b-9168-25245dc35d6b\",\"name\":\"taskium referencius\",\"type\":\"document\"},{\"id\":\"019e50f5-66e0-79a1-85c7-de44b69c639c\",\"name\":\"test with hutch\",\"type\":\"document\"},{\"id\":\"9680c62a-41f0-4505-9608-b13933b8784e\",\"name\":\"This canvas will be renamed v0\",\"type\":\"document\"},{\"id\":\"019e5015-5860-73ed-af68-a8c21599a82b\",\"name\":\"fdsafsd\",\"type\":\"document\"},{\"id\":\"019e4fe0-c077-75f6-b5e1-5287d997ab3b\",\"name\":\"test increment againssss\",\"type\":\"document\"},{\"id\":\"019e4fe0-7275-7f19-9854-98cb35ecbb9c\",\"name\":\"testing new task for team\",\"type\":\"document\"},{\"id\":\"019e4c8f-6dec-712f-9b23-8ceb57222247\",\"name\":\"cool task\",\"type\":\"document\"},{\"id\":\"019e4c89-fb08-7988-b210-b72336d2c261\",\"name\":\"alskdjlakjdalkdsj\",\"type\":\"document\"},{\"id\":\"019e4c2b-59b7-7c04-ac4b-a8658ee5b109\",\"name\":\"chud man\",\"type\":\"document\"},{\"id\":\"019e4c26-38e7-740f-a6be-e77a995f3f13\",\"name\":\"asdasdasdasd\",\"type\":\"document\"},{\"id\":\"019e4c26-0afa-7b05-a3d9-bf6167df065a\",\"name\":\"asdasdasd\",\"type\":\"document\"},{\"id\":\"019e4c25-ea82-7595-b09b-b5907ccf551a\",\"name\":\"laskdjlaksdjlaksjdalskdj\",\"type\":\"document\"},{\"id\":\"019e4c1e-26a7-79e1-88d1-6d4f045335ce\",\"name\":\"\",\"type\":\"document\"},{\"id\":\"019e4c1d-fc58-7339-a8be-7ed5c37e85ba\",\"name\":\"asd\",\"type\":\"document\"},{\"id\":\"019e4624-6a68-727c-92ef-717dc9e91d78\",\"name\":\"\",\"type\":\"document\"},{\"id\":\"019e4624-5283-7ae9-a257-b93578234161\",\"name\":\"\",\"type\":\"document\"},{\"id\":\"019e4609-5ffb-75b6-9e83-c37a6fbd0729\",\"name\":\"cool\",\"type\":\"document\"}],\"summary\":\"Showing 20 documents. More items available in workspace.\"}"
- }
- ]
- }
- ]
- },
- {
- "role": "assistant",
- "id": null,
- "content": [
- {
- "id": null,
- "content": [
- {
- "type": "text",
- "content": {
- "text": " I need to look up what tasks are actually assigned to Eric so I can give an accurate answer.",
- "signature": "Ev8BCmMIDhgCKkCw+6vHFB4PF+702O9xlCeGn+AeeASZo67ZGy78loieOS5CWYJ6T96YM+MWXXGxDlKbu0HXwa9P9VJQScu0pdipMg9jbGF1ZGUtb3B1cy00LTc4AEIIdGhpbmtpbmcSDHMclsVD85fiAnZKfRoMoEXGyxZ35pac9+O9IjBOECoV0ts29WS3yrcZpSxZ9b/EDXzVoXckZU2w57VWjgH5AWuWkbNMJJ9qh6zUPQgqSqKoNAxVENfGykHVwajL8mPGl2Sn6962XS4HH6qPIU5M4+ie51rSjWdj+HHpuyc7oCPv9o+qVbpIr2N8YUbOusHdhttPM8BZUVbsGAE="
- }
- }
- ]
- },
- {
- "id": "toolu_01MfExwb3CvTwVMvuNACgeJw",
- "call_id": null,
- "function": {
- "name": "ListEntities",
- "arguments": {
- "callf": null,
- "cf": null,
- "chanf": null,
- "df": {
- "&": [
- {
- "l": {
- "isTask": true
- }
- }
- ]
- },
- "ef": null,
- "emailPreset": null,
- "emailView": null,
- "includeTypes": [
- "document"
- ],
- "limit": 30,
- "pf": null,
- "propf": {
- "&": [
- {
- "l": {
- "Assignees": [
- ]
- }
- }
- ]
- },
- "sortBy": "recently_updated"
- }
- },
- "signature": null,
- "additional_params": null
- },
- {
- "id": "toolu_01FwTXn3MFLWEFUDmjicmMsu",
- "call_id": null,
- "function": {
- "name": "ReadChannelMessages",
- "arguments": {
- "channelId": "019467c2-49d0-7d99-b0b9-d535811a337d",
- "cursor": null,
- "direction": null,
- "from": null,
- "includeThreadPreviews": false,
- "limit": 10,
- "maxCharsPerMessage": 2000,
- "messageId": null,
- "messageIds": [],
- "to": null,
- "windowType": "latest"
- }
- },
- "signature": null,
- "additional_params": null
- }
- ]
- },
- {
- "role": "user",
- "content": [
- {
- "type": "toolresult",
- "id": "toolu_01MfExwb3CvTwVMvuNACgeJw",
- "content": [
- {
- "type": "text",
- "text": "Toolset error: ToolCallError: ToolCallError: error deserializing tool call (possible hallucination)"
- }
- ]
- }
- ]
- },
- {
- "role": "user",
- "content": [
- {
- "type": "toolresult",
- "id": "toolu_01FwTXn3MFLWEFUDmjicmMsu",
- "content": [
- {
- "type": "text",
- "text": "{\"channelId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"messages\":[{\"attachments\":[],\"channelId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"content\":\"2\",\"contentTruncated\":false,\"createdAt\":\"2026-05-22T15:15:08.326538Z\",\"deletedAt\":null,\"editedAt\":null,\"id\":\"019e5041-29a6-7d9b-94e5-b20925bcad09\",\"reactions\":[],\"senderId\":\"macro|[email protected]\",\"thread\":{\"latestReplyAt\":null,\"omittedReplyCount\":0,\"preview\":null,\"replyCount\":0,\"threadId\":\"019e5041-29a6-7d9b-94e5-b20925bcad09\"},\"updatedAt\":\"2026-05-22T15:15:08.326538Z\"},{\"attachments\":[],\"channelId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"content\":\"3\",\"contentTruncated\":false,\"createdAt\":\"2026-05-22T15:15:08.719564Z\",\"deletedAt\":null,\"editedAt\":null,\"id\":\"019e5041-2b2f-78aa-83bd-74fdf59b92b6\",\"reactions\":[],\"senderId\":\"macro|[email protected]\",\"thread\":{\"latestReplyAt\":null,\"omittedReplyCount\":0,\"preview\":null,\"replyCount\":0,\"threadId\":\"019e5041-2b2f-78aa-83bd-74fdf59b92b6\"},\"updatedAt\":\"2026-05-22T15:15:08.719564Z\"},{\"attachments\":[],\"channelId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"content\":\"<m-user-mention>{\\\"userId\\\":\\\"macro|[email protected]\\\",\\\"email\\\":\\\"[email protected]\\\"}</m-user-mention>\",\"contentTruncated\":false,\"createdAt\":\"2026-05-22T15:16:32.254063Z\",\"deletedAt\":null,\"editedAt\":null,\"id\":\"019e5042-717d-78e3-ab96-535e6cec2a65\",\"reactions\":[],\"senderId\":\"macro|[email protected]\",\"thread\":{\"latestReplyAt\":null,\"omittedReplyCount\":0,\"preview\":null,\"replyCount\":0,\"threadId\":\"019e5042-717d-78e3-ab96-535e6cec2a65\"},\"updatedAt\":\"2026-05-22T15:16:32.254063Z\"},{\"attachments\":[],\"channelId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"content\":\"<m-user-mention>{\\\"userId\\\":\\\"macro|[email protected]\\\",\\\"email\\\":\\\"[email protected]\\\"}</m-user-mention>\",\"contentTruncated\":false,\"createdAt\":\"2026-05-22T15:16:42.456950Z\",\"deletedAt\":null,\"editedAt\":null,\"id\":\"019e5042-9958-7494-bc4a-135c9d3bd711\",\"reactions\":[],\"senderId\":\"macro|[email protected]\",\"thread\":{\"latestReplyAt\":null,\"omittedReplyCount\":0,\"preview\":null,\"replyCount\":0,\"threadId\":\"019e5042-9958-7494-bc4a-135c9d3bd711\"},\"updatedAt\":\"2026-05-22T15:16:42.456950Z\"},{\"attachments\":[],\"channelId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"content\":\"Hello\",\"contentTruncated\":false,\"createdAt\":\"2026-05-22T15:16:44.668133Z\",\"deletedAt\":null,\"editedAt\":null,\"id\":\"019e5042-a1fb-7760-8966-fcb08c6f3fd3\",\"reactions\":[],\"senderId\":\"macro|[email protected]\",\"thread\":{\"latestReplyAt\":null,\"omittedReplyCount\":0,\"preview\":null,\"replyCount\":0,\"threadId\":\"019e5042-a1fb-7760-8966-fcb08c6f3fd3\"},\"updatedAt\":\"2026-05-22T15:16:44.668133Z\"},{\"attachments\":[],\"channelId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"content\":\"1\",\"contentTruncated\":false,\"createdAt\":\"2026-05-22T15:16:47.838942Z\",\"deletedAt\":null,\"editedAt\":null,\"id\":\"019e5042-ae5e-7026-a1a3-88ddc78332f3\",\"reactions\":[],\"senderId\":\"macro|[email protected]\",\"thread\":{\"latestReplyAt\":null,\"omittedReplyCount\":0,\"preview\":null,\"replyCount\":0,\"threadId\":\"019e5042-ae5e-7026-a1a3-88ddc78332f3\"},\"updatedAt\":\"2026-05-22T15:16:47.838942Z\"},{\"attachments\":[{\"createdAt\":\"2026-05-22T15:17:01.600268Z\",\"entityId\":\"ee2c0560-7524-46f9-94eb-966d245a230d\",\"entityType\":\"static/image\",\"id\":\"019e5042-e41e-7469-a267-17f82fbc8873\"}],\"channelId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"content\":\"\\n \\n\",\"contentTruncated\":false,\"createdAt\":\"2026-05-22T15:17:01.473616Z\",\"deletedAt\":null,\"editedAt\":null,\"id\":\"019e5042-e3a0-7b6f-9f74-d1e2fc841814\",\"reactions\":[{\"emoji\":\"❤️\",\"users\":[\"macro|[email protected]\"]}],\"senderId\":\"macro|[email protected]\",\"thread\":{\"latestReplyAt\":null,\"omittedReplyCount\":0,\"preview\":null,\"replyCount\":0,\"threadId\":\"019e5042-e3a0-7b6f-9f74-d1e2fc841814\"},\"updatedAt\":\"2026-05-22T15:17:01.473616Z\"},{\"attachments\":[],\"channelId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"content\":\"Hello\",\"contentTruncated\":false,\"createdAt\":\"2026-05-22T18:21:41.227614Z\",\"deletedAt\":null,\"editedAt\":null,\"id\":\"019e50eb-f3c0-7089-b8bb-7cc9da7a6359\",\"reactions\":[],\"senderId\":\"macro|[email protected]\",\"thread\":{\"latestReplyAt\":null,\"omittedReplyCount\":0,\"preview\":null,\"replyCount\":0,\"threadId\":\"019e50eb-f3c0-7089-b8bb-7cc9da7a6359\"},\"updatedAt\":\"2026-05-22T18:21:41.227614Z\"},{\"attachments\":[],\"channelId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"content\":\"<m-user-mention>{\\\"userId\\\":\\\"macro|[email protected]\\\",\\\"email\\\":\\\"[email protected]\\\"}</m-user-mention> hello\",\"contentTruncated\":false,\"createdAt\":\"2026-05-22T18:22:19.465687Z\",\"deletedAt\":null,\"editedAt\":null,\"id\":\"019e50ec-8911-703a-bfd5-20e32cf91bff\",\"reactions\":[],\"senderId\":\"macro|[email protected]\",\"thread\":{\"latestReplyAt\":null,\"omittedReplyCount\":0,\"preview\":null,\"replyCount\":0,\"threadId\":\"019e50ec-8911-703a-bfd5-20e32cf91bff\"},\"updatedAt\":\"2026-05-22T18:22:19.465687Z\"},{\"attachments\":[],\"channelId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"content\":\"<m-document-mention>{\\\"documentId\\\":\\\"019e5032-d37d-7f5b-9168-25245dc35d6b\\\",\\\"blockName\\\":\\\"task\\\",\\\"documentName\\\":\\\"taskium referencius\\\",\\\"blockParams\\\":{},\\\"collapsed\\\":false}</m-document-mention>\",\"contentTruncated\":false,\"createdAt\":\"2026-05-22T20:47:53.645202Z\",\"deletedAt\":null,\"editedAt\":null,\"id\":\"019e5171-cf2c-7c10-ab65-1477a7995ae6\",\"reactions\":[],\"senderId\":\"macro|[email protected]\",\"thread\":{\"latestReplyAt\":null,\"omittedReplyCount\":0,\"preview\":null,\"replyCount\":0,\"threadId\":\"019e5171-cf2c-7c10-ab65-1477a7995ae6\"},\"updatedAt\":\"2026-05-22T20:47:53.645202Z\"}],\"navigation\":{\"hasMoreNewer\":false,\"hasMoreOlder\":true,\"newerCursor\":null,\"olderCursor\":\"eyJpZCI6IjAxOWU1MDQxLTI5YTYtN2Q5Yi05NGU1LWIyMDkyNWJjYWQwOSIsImxpbWl0IjoxMCwidmFsIjp7InNvcnRfdHlwZSI6bnVsbCwibGFzdF92YWwiOiIyMDI2LTA1LTIyVDE1OjE1OjA4LjMyNjUzOFoifSwiZmlsdGVyIjp7Im1lc3NhZ2VJZHMiOltdLCJjcmVhdGVkQWZ0ZXIiOm51bGwsImNyZWF0ZWRCZWZvcmUiOm51bGwsImFjdGl2aXR5QWZ0ZXIiOm51bGwsImFjdGl2aXR5QmVmb3JlIjpudWxsfX0=\"},\"omissions\":[{\"count\":null,\"cursor\":\"eyJpZCI6IjAxOWU1MDQxLTI5YTYtN2Q5Yi05NGU1LWIyMDkyNWJjYWQwOSIsImxpbWl0IjoxMCwidmFsIjp7InNvcnRfdHlwZSI6bnVsbCwibGFzdF92YWwiOiIyMDI2LTA1LTIyVDE1OjE1OjA4LjMyNjUzOFoifSwiZmlsdGVyIjp7Im1lc3NhZ2VJZHMiOltdLCJjcmVhdGVkQWZ0ZXIiOm51bGwsImNyZWF0ZWRCZWZvcmUiOm51bGwsImFjdGl2aXR5QWZ0ZXIiOm51bGwsImFjdGl2aXR5QmVmb3JlIjpudWxsfX0=\",\"kind\":\"olderMessages\",\"messageId\":null,\"threadId\":null}],\"window\":{\"direction\":null,\"from\":null,\"messageId\":null,\"messageIds\":[],\"to\":null,\"windowType\":\"latest\"}}"
- }
- ]
- }
- ]
- },
- {
- "role": "assistant",
- "id": null,
- "content": [
- {
- "text": "peace be with you, eric. i looked at what's actually on your plate this morning.\n\nthe most concrete thing waiting on you is seamus tagging you on <m-document-mention>{\"documentId\":\"019e5032-d37d-7f5b-9168-25245dc35d6b\",\"documentName\":\"\",\"blockName\":\"task\",\"blockParams\":{}}</m-document-mention> over in <m-document-mention>{\"documentId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"documentName\":\"\",\"blockName\":\"channel\",\"blockParams\":{}}</m-document-mention> friday afternoon. that mention is still unseen — handle it first so seamus isn't waiting.\n\nafter that, your standing priorities haven't moved: MCP client support, the memory system (insight generation weighting still bugs you), and DCS local dev. given the day, i'd pick one — MCP client is the highest-leverage since it unlocks slack/linear integrations and aligns macro with where the industry is heading. memory work is the better pick if you want something self-contained you can ship without coordinating with the platform team.\n\na verse to carry with you: *\"whatever you do, work at it with all your heart, as working for the Lord\"* (colossians 3:23). pick the one thing, do it well, and let the rest wait until tomorrow.\n\nwhat'll it be — reply to seamus first, or want me to pull up the memory roadmap?"
- },
- {
- "id": null,
- "content": [
- {
- "type": "text",
- "content": {
- "text": " I'm noticing Seamus tagged Eric on a task in the battlefield channel—that's worth responding to. Given the priorities around MCP client support, memory systems, and tooling, I should craft a focused answer that addresses this directly and stays grounded in what actually needs attention.",
- "signature": "ErcECmMIDhgCKkBNQy7D/p6AfmM+2kVQPbXAgeMkDnJuzbRB9lQtdCGo1dGSLVSoh20CbI6XgPNVqZVA+t/ZXwY/O/hgXaIZENzeMg9jbGF1ZGUtb3B1cy00LTc4AEIIdGhpbmtpbmcSDKBgl4ixA4ouHOgyXhoM6GeUp4fsFlfOw6G4IjC3DOQ835i/aMQdijyZeJ94IFwraiI85DiNNuMhYX7Dvwc3TM0QecYPM2i45yM4zzgqgQNYUGf2dmJyjdvBPWmvT4wUg3Ix3nPWf73+CTliiNJQ3fT2ji8lrsKdamCoBsMWLcsRQO1JYCKT643gnqtixs4LYvsBG3um7h3n8Pn3RYkGWyAXTEjGVymDu8MHax6zxpW6BzvpGWT1DqMlnTXWvp/NeaHNIp94r4zA9EwfKngSs3yrfH1bd4LDy8Z9Iq27NDd2gVhlxO9LIzk35DWaNDHK57BLPV1c5DyLzC+yr48Bq3/bYIIZqNdYxbUJ20ANyMVyUYxiL53lU+COwtihMhs0ZM/iECHeENfMGpwiDmWBsDMTvEfAc/pW1HPfjC+agdczyEWx1E0T57/zeH7sFcPIsZEv17Nm00FMoWm1tqLStwg9O+Q0+GaIAjqGNyv8sfv4AKO34tiSZNO5LMxEkMnmWpG2cHOM/89J6wXhP6z1jcG/nx0WMfOgaOK8A/X6gb4wgD07DQ5PwNdNDEjb/2WdNZs5xaBCPpE+91h+S6vzbB2a2t8xkQbNi3QTNHCwBpd/GAE="
- }
- }
- ]
- }
- ]
- },
- {
- "role": "assistant",
- "id": null,
- "content": [
- {
- "text": "peace be with you, eric. i looked at what's actually on your plate this morning.\n\nthe most concrete thing waiting on you is seamus tagging you on <m-document-mention>{\"documentId\":\"019e5032-d37d-7f5b-9168-25245dc35d6b\",\"documentName\":\"\",\"blockName\":\"task\",\"blockParams\":{}}</m-document-mention> over in <m-document-mention>{\"documentId\":\"019467c2-49d0-7d99-b0b9-d535811a337d\",\"documentName\":\"\",\"blockName\":\"channel\",\"blockParams\":{}}</m-document-mention> friday afternoon. that mention is still unseen — handle it first so seamus isn't waiting.\n\nafter that, your standing priorities haven't moved: MCP client support, the memory system (insight generation weighting still bugs you), and DCS local dev. given the day, i'd pick one — MCP client is the highest-leverage since it unlocks slack/linear integrations and aligns macro with where the industry is heading. memory work is the better pick if you want something self-contained you can ship without coordinating with the platform team.\n\na verse to carry with you: *\"whatever you do, work at it with all your heart, as working for the Lord\"* (colossians 3:23). pick the one thing, do it well, and let the rest wait until tomorrow.\n\nwhat'll it be — reply to seamus first, or want me to pull up the memory roadmap?"
- }
- ]
- }
-]
\ No newline at end of file
diff --git a/rust/cloud-storage/document_cognition_service/src/api/stream/chat_message.rs b/rust/cloud-storage/document_cognition_service/src/api/stream/chat_message/mod.rs
similarity index 89%
rename from rust/cloud-storage/document_cognition_service/src/api/stream/chat_message.rs
rename to rust/cloud-storage/document_cognition_service/src/api/stream/chat_message/mod.rs
index ba8936fe94..a909b8d234 100644
--- a/rust/cloud-storage/document_cognition_service/src/api/stream/chat_message.rs
+++ b/rust/cloud-storage/document_cognition_service/src/api/stream/chat_message/mod.rs
@@ -636,7 +636,9 @@ fn stream_and_save_message(
// Build the set of messages to persist from the parts we yielded.
// This matches exactly what the user saw in the streamed chunks.
let new_messages = {
- let resolved_parts = resolve_pending_tool_calls(yielded_parts);
+ let resolved_parts = resolve_pending_tool_calls(
+ agent::merge_consecutive_parts(yielded_parts),
+ );
if resolved_parts.is_empty() {
vec![]
} else {
@@ -693,108 +695,4 @@ fn stream_and_save_message(
}
#[cfg(test)]
-mod resolve_pending_tool_calls_tests {
- use super::*;
-
- fn text(s: &str) -> AssistantMessagePart {
- AssistantMessagePart::Text { text: s.into() }
- }
- fn call(id: &str) -> AssistantMessagePart {
- AssistantMessagePart::ToolCall {
- name: "t".into(),
- json: serde_json::json!({}),
- id: id.into(),
- }
- }
- fn resp(id: &str) -> AssistantMessagePart {
- AssistantMessagePart::ToolCallResponseJson {
- name: "t".into(),
- json: serde_json::json!({}),
- id: id.into(),
- }
- }
- fn cancelled_err(id: &str) -> AssistantMessagePart {
- AssistantMessagePart::ToolCallErr {
- name: "t".into(),
- id: id.into(),
- description: "cancelled".to_string(),
- }
- }
-
- #[test]
- fn noop_when_no_tool_calls() {
- let parts = vec![text("a"), text("b")];
- assert_eq!(resolve_pending_tool_calls(parts.clone()), parts);
- }
-
- #[test]
- fn noop_when_all_tool_calls_resolved() {
- let parts = vec![text("a"), call("1"), resp("1"), text("b")];
- assert_eq!(resolve_pending_tool_calls(parts.clone()), parts);
- }
-
- #[test]
- fn inserts_cancelled_err_after_trailing_unmatched_call() {
- let parts = vec![text("a"), call("1")];
- let out = resolve_pending_tool_calls(parts);
- assert_eq!(out, vec![text("a"), call("1"), cancelled_err("1")]);
- }
-
- #[test]
- fn inserts_cancelled_err_immediately_after_unmatched_call() {
- // Cancel between tool call emission and its response: inject the
- // synthetic err right after the call, keep any later yielded parts.
- let parts = vec![text("a"), call("1"), text("b")];
- let out = resolve_pending_tool_calls(parts);
- assert_eq!(
- out,
- vec![text("a"), call("1"), cancelled_err("1"), text("b")]
- );
- }
-
- #[test]
- fn leaves_resolved_calls_alone_resolves_pending_ones() {
- let parts = vec![
- text("a"),
- call("1"),
- resp("1"),
- text("b"),
- call("2"),
- text("c"),
- ];
- let out = resolve_pending_tool_calls(parts);
- assert_eq!(
- out,
- vec![
- text("a"),
- call("1"),
- resp("1"),
- text("b"),
- call("2"),
- cancelled_err("2"),
- text("c"),
- ]
- );
- }
-
- #[test]
- fn resolves_multiple_unmatched_calls() {
- let parts = vec![call("1"), text("x"), call("2")];
- let out = resolve_pending_tool_calls(parts);
- assert_eq!(
- out,
- vec![
- call("1"),
- cancelled_err("1"),
- text("x"),
- call("2"),
- cancelled_err("2"),
- ]
- );
- }
-
- #[test]
- fn empty_input_stays_empty() {
- assert!(resolve_pending_tool_calls(vec![]).is_empty());
- }
-}
+mod test;
diff --git a/rust/cloud-storage/document_cognition_service/src/api/stream/chat_message/test.rs b/rust/cloud-storage/document_cognition_service/src/api/stream/chat_message/test.rs
new file mode 100644
index 0000000000..e20d7d1f51
--- /dev/null
+++ b/rust/cloud-storage/document_cognition_service/src/api/stream/chat_message/test.rs
@@ -0,0 +1,101 @@
+use super::*;
+
+fn text(s: &str) -> AssistantMessagePart {
+ AssistantMessagePart::Text { text: s.into() }
+}
+fn call(id: &str) -> AssistantMessagePart {
+ AssistantMessagePart::ToolCall {
+ name: "t".into(),
+ json: serde_json::json!({}),
+ id: id.into(),
+ }
+}
+fn resp(id: &str) -> AssistantMessagePart {
+ AssistantMessagePart::ToolCallResponseJson {
+ name: "t".into(),
+ json: serde_json::json!({}),
+ id: id.into(),
+ }
+}
+fn cancelled_err(id: &str) -> AssistantMessagePart {
+ AssistantMessagePart::ToolCallErr {
+ name: "t".into(),
+ id: id.into(),
+ description: "cancelled".to_string(),
+ }
+}
+
+#[test]
+fn noop_when_no_tool_calls() {
+ let parts = vec![text("a"), text("b")];
+ assert_eq!(resolve_pending_tool_calls(parts.clone()), parts);
+}
+
+#[test]
+fn noop_when_all_tool_calls_resolved() {
+ let parts = vec![text("a"), call("1"), resp("1"), text("b")];
+ assert_eq!(resolve_pending_tool_calls(parts.clone()), parts);
+}
+
+#[test]
+fn inserts_cancelled_err_after_trailing_unmatched_call() {
+ let parts = vec![text("a"), call("1")];
+ let out = resolve_pending_tool_calls(parts);
+ assert_eq!(out, vec![text("a"), call("1"), cancelled_err("1")]);
+}
+
+#[test]
+fn inserts_cancelled_err_immediately_after_unmatched_call() {
+ let parts = vec![text("a"), call("1"), text("b")];
+ let out = resolve_pending_tool_calls(parts);
+ assert_eq!(
+ out,
+ vec![text("a"), call("1"), cancelled_err("1"), text("b")]
+ );
+}
+
+#[test]
+fn leaves_resolved_calls_alone_resolves_pending_ones() {
+ let parts = vec![
+ text("a"),
+ call("1"),
+ resp("1"),
+ text("b"),
+ call("2"),
+ text("c"),
+ ];
+ let out = resolve_pending_tool_calls(parts);
+ assert_eq!(
+ out,
+ vec![
+ text("a"),
+ call("1"),
+ resp("1"),
+ text("b"),
+ call("2"),
+ cancelled_err("2"),
+ text("c"),
+ ]
+ );
+}
+
+#[test]
+fn resolves_multiple_unmatched_calls() {
+ let parts = vec![call("1"), text("x"), call("2")];
+ let out = resolve_pending_tool_calls(parts);
+ assert_eq!(
+ out,
+ vec![
+ call("1"),
+ cancelled_err("1"),
+ text("x"),
+ call("2"),
+ cancelled_err("2"),
+ ]
+ );
+}
+
+#[test]
+fn empty_input_stays_empty() {
+ assert!(resolve_pending_tool_calls(vec![]).is_empty());
+}